mie: implement comparison and branch instruction generation
This commit is contained in:
219
mie/builder.c
219
mie/builder.c
@@ -478,7 +478,33 @@ struct mie_value *mie_builder_br_if(
|
||||
struct mie_builder *builder, struct mie_value *cond,
|
||||
struct mie_block *if_true, struct mie_block *if_false)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_branch_if *br = malloc(sizeof *br);
|
||||
if (!br) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(br, 0x0, sizeof *br);
|
||||
|
||||
mie_instr_init(&br->b_base, MIE_INSTR_BR_IF);
|
||||
|
||||
br->b_cond = cond;
|
||||
br->b_true_block = if_true;
|
||||
br->b_false_block = if_false;
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &br->b_base)) {
|
||||
free(br);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return MIE_VALUE(br);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_msg(
|
||||
@@ -533,35 +559,216 @@ struct mie_value *mie_builder_cmp_eq(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_EQ);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_cmp_neq(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_NEQ);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_cmp_lt(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_LT);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_cmp_gt(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_GT);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_cmp_leq(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_LEQ);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_cmp_geq(
|
||||
struct mie_builder *builder, struct mie_value *left,
|
||||
struct mie_value *right, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
if (!builder->b_current_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (builder->b_current_block->b_terminator) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_binary_op *sub = malloc(sizeof *sub);
|
||||
if (!sub) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sub, 0x0, sizeof *sub);
|
||||
|
||||
mie_instr_init(&sub->op_base, MIE_INSTR_CMP_GEQ);
|
||||
|
||||
sub->op_left = left;
|
||||
sub->op_right = right;
|
||||
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||
free(sub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(sub), name);
|
||||
|
||||
return MIE_VALUE(sub);
|
||||
}
|
||||
|
||||
struct mie_value *mie_builder_getelementptr(
|
||||
|
||||
Reference in New Issue
Block a user