duanmao2774 2019-05-05 17:23
浏览 551
已采纳

我正在使用Antlr4创建一种语言,然后使用该语言生成LLVM IR。 我是否需要为访客事件手写LLVM IR?

While learning Antlr4, I used Golang as a target language, so a statement in my toy language like:

$myVar = 10
$myVar + 5

Would translate to some Golang code that generates "15" for the result

However, as far as I can see, there isn't an LLVM IR target for ANTLR, so the question is: what are my options?

1) Generate C/C++ and then use it to emit LLVM IR?
2) Try to find a Golang LLVM IR emitter?
3) Keep using the generated Go lexer/parser but hand-write LLVM IR?

I tried to go through the LLVM documentation and watched a few videos on LLVM< but they all seem to generate C/C++ and then communicate with the API that way. Not sure if they do that because that's what they know or if it's because that's the only way.

Thanks in advance for any insights!

  • 写回答

1条回答 默认 最新

  • duanlin1933 2019-05-05 17:45
    关注

    While learning Antlr4, I used Golang as a target language, so a statement in my toy language like:

    $myVar = 10
    $myVar + 5
    

    Would translate to some Golang code that generates "15" for the result

    That's not accurate. Your grammar is translated into Go code that parses your language. Your own code can then use that generated parser to translate the above into whatever you want.

    there isn't an LLVM IR target for ANTLR

    Nor would it help you if there were one. All that would do would be to create a parser written in LLVM instead of Go. You'd still have to write the code to translate your language into LLVM yourself (just like you'd have to write your own code into translate your language to Go).


    As to whether to use the LLVM-API to generate LLVM or to generate it as strings, either option would work. There are Go bindings for LLVM, but it's also perfectly possible to just write LLVM assembly into an .ll file and then run that through llc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格