Delphi 的 x86 代码生成器框架
有人遇到过 Delphi 的框架或库来简化 x86 代码的生成吗? 我不是在寻找汇编器,而是在寻找一个将低级位和字节之上的代码生成过程抽象化的框架。 理想情况下,我想在现有的库或框架之上构建,而不是根据具体情况对逻辑进行硬编码。
最初的用途是在运行时生成小型代码存根,类似于 Delphi 调度 SOAP 请求的方式。 如果我找不到东西,我可能会自己动手,但我不想重新发明轮子。 如果许可证允许在商业和开源项目中进行翻译和使用,“C”中的某些内容可能会让我感兴趣。
更新:
这里有更多上下文:我正在努力将接口和/或类的运行时实现作为持久性框架的一部分。 有点像 Java 注释驱动的持久性 (JPA/EJB3),只不过具有明显的 Delphi 风格。 调用目标是一个模块化/可扩展的框架,它将实现通用的持久性模型。 我需要以非常动态和流畅的方式基于 RTTI 和注释/属性模型(类似于 InstantObjects 元数据)来调度和挂钩方法调用。
谢谢, 大卫
Has anyone come across a framework or library for Delphi to simplify the generation of x86 code? I am not looking for an assembler, but rather a framework that abstracts the code generation process above the low level bits and bytes. Ideally I would like to build on top of an existing library or framework rather than hardcode the logic on a case by case basis.
The initial usage will be to generate small code stubs at runtime similar to the way Delphi dispatches SOAP requests. If I cannot find something I will likely roll my own, but I would hate to reinvent the wheel. Something in "C" might me interesting provided the license will permit translation and use in commercial and open source projects.
Update:
Here is some more context: What I am working toward is runtime implementation of interfaces and/or classes as part of a persistence framework. Something sort of like Java annotation driven persistence (JPA/EJB3) except with a distinctly Delphi flavor. The invocation target is a modular/extensible framework which will implement a generalized persistence model. I need to dispatch and hook method calls based on RTTI and an annotation/attribute model (something similar to InstantObjects metadata) in a very dynamic and fluid manner.
Thanks,
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我对你的问题思考得越多。 我不确定你们是否只是想进行动态方法调用。 即使您询问有关生成 x86 代码的问题。
有几种技术可以做到这一点。
如果您知道相关方法的签名,则可以使用
TMethod并设置方法地址和数据。
如果您不知道方法签名,可以使用 {$METHODINFO ON} 编写类
然后使用 ObjAuto.pas 中的功能来调用该方法。
我在 DelphiLive 的 RTTI 演示代码中有一个关于如何执行此操作的示例。
The more I have thought about your question. I am not sure if all you trying to just do Dynamic Method Invocation. Even though your asking about generating x86 code.
There are several techiniques that do this.
If you know the signature of the method in question you can do it easily by using a
TMethod and setting the method address and data.
If you don't know the method signature you can write the class with {$METHODINFO ON}
Then use the functionality in ObjAuto.pas to invoke the method.
I have an example in my RTTI Presentation code from DelphiLive on how to do that.
根据PaxCompiler的功能,您可以创建独立的可执行文件。
According to features of PaxCompiler, you can create stand alone executable files.
非常推测性的答案:
像LLVM之类的东西? 我不确定它是否可以从delphi使用,但你应该能够用它创建dll。
Very spectulative answer:
Something like LLVM? I am not sure if it can be used from delphi or not, but you should be able to create dll's wth it.
从逻辑上讲,您只需生成delphi代码,通过cmdline编译器编译为DLL/BPL,然后动态加载该代码?
不幸的是,Delphi Explorer 没有附带 cmdline 编译器。 并且您的主要二进制文件也必须位于 Delphi Explorer 中(或者至少在 D2006 中,如果二进制文件足够兼容的话)
任何 Delphi 版本(或 Free Pascal)的混合可能无法在包或 HLL 级别上工作,只能在基本程序上工作DLL 级别。
Logically you would simply generate delphi code, compile to a DLL/BPL by cmdline compiler and then dyn load that one?
Unfortunately Delphi Explorer doesn't come with the cmdline compiler though. And your main binary would also have to be in Delphi Explorer (or at least in D2006 if that is binary compatible enough)
Any mix of Delphi versions (or Free Pascal) will probably not work on the package or HLL level, only at basic procedural DLL level.
我刚刚发现了一个有趣的框架,它可以完成我最初发布问题时所寻找的大部分功能。 对于我的目的来说有点晚了,但我认为其他人可能会发现这很有用:
DAsmJit asmjit 项目 的 Delphi 端口
I just found an interesting framework that does much of what I was looking for when I originally posted the question. A little late for my purposes, but thought someone else might find this useful:
DAsmJit a Delphi port of the asmjit project