Switch to single stack in runtime for Compiler Series

This commit is contained in:
Danila Fedorin 2020-01-31 15:29:12 -08:00
parent 28e81cc9bd
commit ecc1091c0a
3 changed files with 13 additions and 1 deletions

View File

@ -155,7 +155,7 @@ void instruction_eval::print(int indent, std::ostream& to) const {
} }
void instruction_eval::gen_llvm(llvm_context& ctx, Function* f) const { void instruction_eval::gen_llvm(llvm_context& ctx, Function* f) const {
ctx.create_push(f, ctx.create_eval(ctx.create_pop(f))); ctx.create_unwind(f);
} }
void instruction_alloc::print(int indent, std::ostream& to) const { void instruction_alloc::print(int indent, std::ostream& to) const {

View File

@ -145,6 +145,12 @@ void llvm_context::create_functions() {
"eval", "eval",
&module &module
); );
functions["unwind"] = Function::Create(
FunctionType::get(void_type, { stack_ptr_type }, false),
Function::LinkageTypes::ExternalLinkage,
"unwind",
&module
);
} }
ConstantInt* llvm_context::create_i8(int8_t i) { ConstantInt* llvm_context::create_i8(int8_t i) {
@ -199,6 +205,11 @@ Value* llvm_context::create_eval(Value* e) {
return builder.CreateCall(eval_f, { e }); return builder.CreateCall(eval_f, { e });
} }
void llvm_context::create_unwind(Function* f) {
auto unwind_f = functions.at("unwind");
builder.CreateCall(unwind_f, { f->args().begin() });
}
Value* llvm_context::unwrap_num(Value* v) { Value* llvm_context::unwrap_num(Value* v) {
auto num_ptr_type = PointerType::getUnqual(struct_types.at("node_num")); auto num_ptr_type = PointerType::getUnqual(struct_types.at("node_num"));
auto cast = builder.CreatePointerCast(v, num_ptr_type); auto cast = builder.CreatePointerCast(v, num_ptr_type);

View File

@ -52,6 +52,7 @@ struct llvm_context {
void create_alloc(llvm::Function*, llvm::Value*); void create_alloc(llvm::Function*, llvm::Value*);
llvm::Value* create_eval(llvm::Value*); llvm::Value* create_eval(llvm::Value*);
void create_unwind(llvm::Function*);
llvm::Value* unwrap_num(llvm::Value*); llvm::Value* unwrap_num(llvm::Value*);
llvm::Value* create_num(llvm::Value*); llvm::Value* create_num(llvm::Value*);