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