From 95901f3a5fa0ec18128030c915d1d94bade5de94 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 20 Jun 2024 18:01:48 -0400 Subject: global env; alloca locals kinda messy --- llvm.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'llvm.cpp') diff --git a/llvm.cpp b/llvm.cpp index f1ee27a..51d4706 100644 --- a/llvm.cpp +++ b/llvm.cpp @@ -22,8 +22,8 @@ LLVMState::LLVMState(): modul("forsp", ctx), builder(ctx), inttype(llvm::Type::getInt32Ty(ctx)), - stacktype(llvm::VectorType::get(inttype, 12, false)), - ftype(llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), {}, false)), + stacktype(llvm::VectorType::get(inttype, 16, false)), + ftype(llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), llvm::ArrayRef {inttype->getPointerTo()}, false)), one(llvm::ConstantInt::get(inttype, 1)), zero(llvm::ConstantInt::get(inttype, 0)) { @@ -34,13 +34,14 @@ LLVMState::LLVMState(): llvm::GlobalValue::ExternalLinkage, zerovec, "stack"); } -llvm::Value *LLVMState::createPush() +llvm::Value *LLVMState::createPush(llvm::Value *var) { auto dspval = builder.CreateLoad(inttype, llvmSp); auto inc = builder.CreateAdd(dspval, one); builder.CreateStore(inc, llvmSp, false); - return builder.CreateGEP(stacktype, llvmStack, {zero, dspval}); + auto gep = builder.CreateGEP(stacktype, llvmStack, {zero, dspval}); + return builder.CreateStore(var, gep); } llvm::Value *LLVMState::createPop() @@ -49,13 +50,16 @@ llvm::Value *LLVMState::createPop() auto dec = builder.CreateSub(dspval, one); builder.CreateStore(dec, llvmSp, false); - return builder.CreateGEP(stacktype, llvmStack, {zero, dec}); + auto gep = builder.CreateGEP(stacktype, llvmStack, {zero, dec}); + return builder.CreateLoad(inttype, gep); } llvm::Function *LLVMState::createFunction(const std::string& name) { - return llvm::Function::Create(ftype, llvm::Function::ExternalLinkage, + auto func = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage, name.c_str(), modul); + func->getArg(0)->setName("penv"); + return func; } llvm::BasicBlock *LLVMState::createEntry(llvm::Function *func) -- cgit v1.2.3