|
|
|
@ -21,7 +21,7 @@ LLVMState::LLVMState():
|
|
|
|
|
ctx(),
|
|
|
|
|
modul("forsp", ctx),
|
|
|
|
|
builder(ctx),
|
|
|
|
|
inttype(llvm::Type::getInt32Ty(ctx)),
|
|
|
|
|
inttype(llvm::Type::getInt64Ty(ctx)),
|
|
|
|
|
stacktype(llvm::VectorType::get(inttype, 16, false)),
|
|
|
|
|
ftype(llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), llvm::ArrayRef<llvm::Type *> {inttype->getPointerTo()}, false)),
|
|
|
|
|
one(llvm::ConstantInt::get(inttype, 1)),
|
|
|
|
@ -38,7 +38,7 @@ llvm::Value *LLVMState::createPush(llvm::Value *var)
|
|
|
|
|
{
|
|
|
|
|
auto dspval = builder.CreateLoad(inttype, llvmSp);
|
|
|
|
|
auto inc = builder.CreateAdd(dspval, one);
|
|
|
|
|
builder.CreateStore(inc, llvmSp, false);
|
|
|
|
|
builder.CreateStore(inc, llvmSp);
|
|
|
|
|
|
|
|
|
|
auto gep = builder.CreateGEP(stacktype, llvmStack, {zero, dspval});
|
|
|
|
|
return builder.CreateStore(var, gep);
|
|
|
|
@ -48,7 +48,7 @@ llvm::Value *LLVMState::createPop()
|
|
|
|
|
{
|
|
|
|
|
auto dspval = builder.CreateLoad(inttype, llvmSp);
|
|
|
|
|
auto dec = builder.CreateSub(dspval, one);
|
|
|
|
|
builder.CreateStore(dec, llvmSp, false);
|
|
|
|
|
builder.CreateStore(dec, llvmSp);
|
|
|
|
|
|
|
|
|
|
auto gep = builder.CreateGEP(stacktype, llvmStack, {zero, dec});
|
|
|
|
|
return builder.CreateLoad(inttype, gep);
|
|
|
|
@ -75,7 +75,7 @@ llvm::Value *LLVMState::createVariable(const std::string& name)
|
|
|
|
|
|
|
|
|
|
llvm::Constant *LLVMState::createInt(int n)
|
|
|
|
|
{
|
|
|
|
|
return llvm::ConstantInt::get(ctx, llvm::APInt(32, n, true));
|
|
|
|
|
return llvm::ConstantInt::get(ctx, llvm::APInt(64, n, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LLVMState::output()
|
|
|
|
|