我正在尝试在主函数中插入函数调用,以便运行生成的二进制文件时函数会自动执行。由于我正在尝试“编译”的语言看起来像是一种“脚本”语言:
function foo () begin 3 end;
function boo () begin 4 end;
writeln (foo()+boo()) ;
writeln (8) ;
writeln (9) ;
writeln是默认可用的函数,执行二进制文件后,我期望看到7 8 9。有没有一种方法可以在主函数的return语句之前插入最后一个函数调用? 目前我的代码是
define i32 @main() {
entry:
ret i32 0
}
我希望你能为我提供类似以下这样的内容:
define i32 @main() {
entry:
%calltmp = call double @writeln(double 7.000000e+00)
%calltmp = call double @writeln(double 8.000000e+00)
%calltmp = call double @writeln(double 9.000000e+00)
ret i32 0
}
手动编辑IR文件并编译成功了,但我想在代码生成部分自动完成这个过程。
编辑
目前我生成的是:
define double @__anon_expr() {
entry:
%main = call double @writeln(double 3.000000e+00)
ret double %main
}
define i32 @main() {
entry:
ret i32 0
}
当我执行二进制文件时,什么都没有发生。
c++
有什么关系? - superopt
中运行它。 - SK-logicdefine double @__anon_expr() { entry: %main = call double @writeln(double 3.000000e+00) ret double %main } define i32 @main() { entry: ret i32 0 }
所以没有任何执行。 - John Galt