Switch to single stack in runtime for Compiler Series
This commit is contained in:
parent
c1b030ee97
commit
8d22acfe78
|
@ -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 {
|
||||
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 {
|
||||
|
|
|
@ -145,6 +145,12 @@ void llvm_context::create_functions() {
|
|||
"eval",
|
||||
&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) {
|
||||
|
@ -199,6 +205,11 @@ Value* llvm_context::create_eval(Value* 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) {
|
||||
auto num_ptr_type = PointerType::getUnqual(struct_types.at("node_num"));
|
||||
auto cast = builder.CreatePointerCast(v, num_ptr_type);
|
||||
|
|
|
@ -52,6 +52,7 @@ struct llvm_context {
|
|||
void create_alloc(llvm::Function*, llvm::Value*);
|
||||
|
||||
llvm::Value* create_eval(llvm::Value*);
|
||||
void create_unwind(llvm::Function*);
|
||||
|
||||
llvm::Value* unwrap_num(llvm::Value*);
|
||||
llvm::Value* create_num(llvm::Value*);
|
||||
|
|
Loading…
Reference in New Issue
Block a user