diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -60,20 +60,22 @@ int main() } // 3. Create main() which initiate global vars and calls the top-level thunk. - auto func = llvmState.createFunction("main"); - auto entry = llvmState.createEntry(func); - auto envtype = llvm::VectorType::get(llvmState.inttype, ThunkAST::envidx, false); - auto [t0, _] = Var::lookup("__t0"); - llvmState.builder.SetInsertPoint(entry); + auto envtype = llvm::ArrayType::get(llvmState.inttype, llvmState.envidx); auto zerovec = llvm::ConstantVector::get(llvm::ArrayRef(llvmState.zero)); auto env = new llvm::GlobalVariable(llvmState.modul, envtype, false, llvm::GlobalValue::InternalLinkage, zerovec, "env"); + + auto func = llvmState.createFunction("main"); + auto entry = llvmState.createEntry(func); + llvmState.builder.SetInsertPoint(entry); + + auto [t0, _] = Var::lookup("__t0"); llvmState.builder.CreateCall(llvmState.ftype, t0, llvm::ArrayRef<llvm::Value *> {env}); llvmState.builder.CreateRetVoid(); // 4. Output the IR to stdout. llvmState.output(); - std::cerr << "envidx: " << ThunkAST::envidx << std::endl; + std::cerr << "envidx: " << llvmState.envidx << std::endl; return 0; } @@ -142,12 +144,15 @@ std::list<ThunkAST>::iterator buildThunk(std::list<ThunkAST>::iterator it) curFunc = it->func; curEnv = it->env; + llvmState.lastSp = it->lastSp; for (auto& a : it->ast) { if (a->name.starts_with("__t")) { + it->lastSp = llvmState.lastSp; next = buildThunk(next); curFunc = it->func; curEnv = it->env; + llvmState.lastSp = it->lastSp; } if (a->codegen(llvmState) == nullptr) { |