私はかなりllvmを初めて使いました。ここではオンラインチュートリアルのみでした:http://llvm.org/docs/tutorial/LangImpl1.html 私は自分の小さな言語を使いたいと思っていましたが、少し問題がありました。それは二つのことをすべきllvmで生成されたベーシックブロックターミネーター
(def i 1)
: は、私はこれを解析する
- は、それが表現として使用することができますので、1
- 戻り値を返す新しい関数を定義し
関数は正しく作成されますが、式として使用する際に問題があります。
Value *DefExprAST::Codegen() {
if (Body->Codegen() == 0) return 0;
return ConstantFP::get(getGlobalContext(), APFloat(0.0));
}
verifyFunction
が得られます。このような
Function *FunctionAST::Codegen() {
NamedValues.clear();
Function *TheFunction = Proto->Codegen();
if (TheFunction == 0) return 0;
BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
Builder.SetInsertPoint(BB);
if (Value *RetVal = Body->Codegen()) {
Builder.CreateRet(RetVal);
verifyFunction(*TheFunction);
return TheFunction;
}
return 0;
}
そしてDefExprAST:このようになります関数のコードを作成するための
FunctionAST // the whole statement
- Prototype // is an nameless statement
- Body // contains the definition expression
- DefExprAST
- Body // contains the Function definition
- FunctionAST
- Prototype // named i
- Body // the value 1
コード:ASTはこのようになります次のエラー:
Basic Block in function '' does not have terminator!
label %entry
LLVM ERROR: Broken module, no Basic Block terminator!
実際、生成された関数にはretエントリはありません。その空:
define double @0() {
entry:
}
しかしRetVal
が正しくダブルで満たされているとBuilder.CreateRet(RetVal)
がRETステートメントをバック与えるが、それはエントリに挿入されません。