Clumsily add equality checking.
This commit is contained in:
@@ -62,6 +62,11 @@ namespace lily {
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& instruction_eq::to_stream(std::ostream& os) {
|
||||
os << "eq";
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& instruction_cond::to_stream(std::ostream& os) {
|
||||
os << "cond";
|
||||
return os;
|
||||
@@ -166,6 +171,39 @@ namespace lily {
|
||||
builder.CreateCall(stack_push_func, { stack, new_node });
|
||||
}
|
||||
|
||||
void instruction_eq::gen_llvm(llvm_context& ctx) {
|
||||
llvm::Value* stack = ctx.get_current_function()->arg_begin();
|
||||
llvm::Value* param2 = builder.CreateCall(stack_pop_func, { stack }, "temp");
|
||||
llvm::Value* param1 = builder.CreateCall(stack_pop_func, { stack }, "temp");
|
||||
llvm::Value* param1_node_num = builder.CreatePointerCast(param1, llvm::PointerType::getUnqual(node_num_type), "temp");
|
||||
llvm::Value* param2_node_num = builder.CreatePointerCast(param2, llvm::PointerType::getUnqual(node_num_type), "temp");
|
||||
llvm::Value* param1_intptr = builder.CreateGEP(param1_node_num, { get_int32_constant(0), get_int32_constant(1) }, "temp");
|
||||
llvm::Value* param2_intptr = builder.CreateGEP(param2_node_num, { get_int32_constant(0), get_int32_constant(1) }, "temp");
|
||||
llvm::Value* param1_int = builder.CreateLoad(llvm::IntegerType::get(context, 32), param1_intptr, "temp");
|
||||
llvm::Value* param2_int = builder.CreateLoad(llvm::IntegerType::get(context, 32), param2_intptr, "temp");
|
||||
llvm::Value* compare_result = builder.CreateICmpEQ(param1_int, param2_int, "temp");
|
||||
|
||||
llvm::BasicBlock* false_block = llvm::BasicBlock::Create(context, "false", ctx.get_current_function());
|
||||
llvm::BasicBlock* true_block = llvm::BasicBlock::Create(context, "true", ctx.get_current_function());
|
||||
builder.CreateCondBr(compare_result, true_block, false_block);
|
||||
|
||||
llvm::BasicBlock* after = llvm::BasicBlock::Create(context, "after", ctx.get_current_function());
|
||||
|
||||
builder.SetInsertPoint(false_block);
|
||||
llvm::Value* false_node = builder.CreateCall(malloc_node_global_func,
|
||||
{ get_int8_constant(0), ctx.get_supercombinator_function("False") }, "temp");
|
||||
builder.CreateCall(stack_push_func, { stack, false_node });
|
||||
builder.CreateBr(after);
|
||||
|
||||
builder.SetInsertPoint(true_block);
|
||||
llvm::Value* true_node = builder.CreateCall(malloc_node_global_func,
|
||||
{ get_int8_constant(0), ctx.get_supercombinator_function("True") }, "temp");
|
||||
builder.CreateCall(stack_push_func, { stack, true_node });
|
||||
builder.CreateBr(after);
|
||||
|
||||
builder.SetInsertPoint(after);
|
||||
}
|
||||
|
||||
void instruction_cond::gen_llvm(llvm_context& ctx) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user