动态代码编译 [英] dynamic code compilation

查看:142
本文介绍了动态代码编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个渲染迭代分形系统的程序。我想添加的功能,有人可以定义自己的迭代过程,并编译该代码,以便它可以有效地运行。

I'm working on a program that renders iterated fractal systems. I wanted to add the functionality where someone could define their own iteration process, and compile that code so that it would run efficiently.

我目前不知道如何做

主程序用C ++编写,我熟悉C ++。事实上,在大多数情况下,我知道如何将其转换为将实现目标的汇编代码,但我不知道如何采取额外的步骤将其转换为机器代码。如果可能,我想动态编译代码,就像我相信许多游戏系统模拟器的工作。

The main program is written in C++ and I'm familiar with C++. In fact given most of the scenarios I know how to convert it to assembly code that would accomplish the goal, but I don't know how to take the extra step to convert it to machine code. If possible I'd like to dynamically compile the code like how I believe many game system emulators work.

如果不清楚我在问什么,告诉我,所以我可以澄清。

If it is unclear what I'm asking, tell me so I can clarify.

谢谢!

推荐答案

有些CPU模拟器将机器代码视为如果它是字节码,他们做一个JIT编译,几乎就像是Java。这是非常高效的,但这意味着开发人员需要为每个CPU模拟器运行时为每个CPU编写一个版本的编译器。

Some CPU emulators treat the machine code as if it was byte code and they do a JIT compile, almost as if it was Java. This is very efficient, but it means that the developers need to write a version of the compiler for each CPU their emulator runs on and for each CPU emulated.

这通常意味着它只能在x86上工作,并且对任何想要使用不同的东西很恼人。

That usually means it only works on x86 and is annoying to anyone who would like to use something different.

他们也可以将其翻译为LLVM或Java字节代码或.Net CIL,然后编译它,这也将工作。

They could also translate it to LLVM or Java byte code or .Net CIL and then compile it, which would also work.

在你的情况下,我不知道那种事情是最好的方式去。我想我会通过使用动态库来做到这一点。创建一个应该包含plugins的目录,并让用户自己编译。让你的程序扫描目录并加载每个DLL或.so它发现。

In your case I am not sure that sort of thing is the best way to go. I think that I would do this by using dynamic libraries. Make a directory that is supposed to contain "plugins" and let the user compile their own. Make your program scan the directory and load each DLL or .so it finds.

这样做意味着你花更少的时间编写代码编译器和更多的时间。

Doing it this way means you spend less time writing code compilers and more time actually getting stuff done.

这篇关于动态代码编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆