虚拟机 |带有命令行选项的程序入口函数的代码生成器
LLVM | codegen for program entry function with command line options
对于我的编程语言,程序的入口就像C/C++ main
函数:
int main(int argc, char **argv) {
return 0
}
假设:
main
的 IR 代码生成到 llvm::Function
,使用 llvm::IRBuilder
- 我创建了
llvm::LLVMContext
和 llvm::Module
问题:
如果我想将此代码编译成二进制 prog
,如何使用 llvm 生成将命令行参数传递给 argc
和 argv
然后调用 main
, 运行 prog
?
时由用户提供
感谢 arnt 的评论:
If that function actually is called main() and actually has those arguments, then it should just work. If it isn't, then you'll need to generate a bridge function that actually is called main() and calls the function you want to be called, in the way you want it to be called. – arnt
有效!
对于我的编程语言,程序的入口就像C/C++ main
函数:
int main(int argc, char **argv) {
return 0
}
假设:
main
的 IR 代码生成到llvm::Function
,使用llvm::IRBuilder
- 我创建了
llvm::LLVMContext
和llvm::Module
问题:
如果我想将此代码编译成二进制 prog
,如何使用 llvm 生成将命令行参数传递给 argc
和 argv
然后调用 main
, 运行 prog
?
感谢 arnt 的评论:
If that function actually is called main() and actually has those arguments, then it should just work. If it isn't, then you'll need to generate a bridge function that actually is called main() and calls the function you want to be called, in the way you want it to be called. – arnt
有效!