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」命令?有什麼我錯過了什麼?
更新: 在單證寫的是:
每個基本塊,可以任選一個標籤開始(給予基本塊一個符號表項),包含一系列指令,並以結束符指令結束(如分支或函數返回)。
是意味着一個「終結者」指令只能由在基本塊的結束?如果是的話,我應該如何執行我的語言的返回和中斷命令?
非常感謝。 –