我对llvm很新,只在这里做了在线教程:http://llvm.org/docs/tutorial/LangImpl1.html 现在我想做自己的小语言并遇到一些问题.我想解析一下:
(def i 1)
Run Code Online (Sandbox Code Playgroud)
它应该做两件事:
该函数已正确创建,但我将其用作表达式时遇到问题.AST看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
该函数的代码创建代码如下所示:
Function *FunctionAST::Codegen() {
NamedValues.clear();
Function *TheFunction = Proto->Codegen();
if ( TheFunction == 0 ) return 0;
BasicBlock *BB = BasicBlock::Create( getGlobalContext(), "entry", TheFunction );
Builder.SetInsertPoint( BB …Run Code Online (Sandbox Code Playgroud)