LLVM,通过引用调用
我正在为一种语言编写一个编译器,用户可以在其中选择按值调用或引用调用
最后阶段是生成 llvm 程序集。我读到数组/向量通过引用传递,但我不知道如何通过引用传递整数。
我想过创建一个指针,然后传递指针,类似于:
foo(ref var1) { var1 = var1 + 1 }
main { a=1; foo(a); }
被翻译成
foo(int* var1) { (*var1) = (*var1) + 1 }
main {a=1; foo(&a ); }
但我找不到如何在llvm中做到这一点。
任何关于指针或如何通过引用调用参数的想法都很棒(我希望这不是一个太多的 RTFM 问题:/)
I am writing a compiler for a language in which the user can choose between call by value or reference
The final stage is to produce llvm assembly. I read that arrays/vectors pass by reference but I cant figure out how to pass integers by reference.
I thought about creating a pointer and then pass the pointer, something like:
foo(ref var1) { var1 = var1 + 1 }
main { a=1; foo(a); }
being translated into
foo(int* var1) { (*var1) = (*var1) + 1 }
main {a=1; foo(&a ); }
but I cannot find how to do it in llvm.
Any ideas, either about the pointers or how to call an argument by reference would be awesome (I hope that it's not too much of a RTFM question:/)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过 http://llvm.org/demo/ 运行以下代码,并将优化级别设置为“无”:
答案本质上就是您需要通过 alloca 指令分配内存。
Try running the following code through http://llvm.org/demo/ with the optimization level set to None:
The answer is essentially just that you need to allocate memory via the alloca instruction.