0
我跟着LLVM教程万花筒。现在我试图在这个前端编译器中使用类似于Pascal的语言。我有这样的代码:LLVM'ret'指令
program main;
function rett(): integer;
begin
rett := 1;
exit;
rett := 5;
end;
var a: integer;
begin
a := rett();
writeln(a);
end.
该程序的输出应是一个单一的整数“1”,因为退出命令(所以线rett := 5;
should'n是执行)的。然而输出是'5'。对于这个输入我生成这个LLVM IR:
define i32 @rett() {
entry:
%rett = alloca i32
store i32 0, i32* %rett
store i32 1, i32* %rett
%rett1 = load i32, i32* %rett
ret i32 %rett1
store i32 5, i32* %rett
%rett2 = load i32, i32* %rett
ret i32 %rett2
}
define i32 @main() {
entry:
%a = alloca i32
%main = alloca i32
store i32 0, i32* %main
store i32 0, i32* %a
%calltmp = call i32 @rett()
store i32 %calltmp, i32* %a
%a1 = load i32, i32* %a
%calltmp2 = call i32 (i8*, ...) @printf([4 x i8]* @.str, i32 %a1)
%main3 = load i32, i32* %main
ret i32 %main3
}
为什么不执行第一“RET”命令?有什么我错过了什么?
更新: 在单证写的是:
每个基本块,可以任选一个标签开始(给予基本块一个符号表项),包含一系列指令,并以结束符指令结束(如分支或函数返回)。
是意味着一个“终结者”指令只能由在基本块的结束?如果是的话,我应该如何执行我的语言的返回和中断命令?
非常感谢。 –