stable
This commit is contained in:
@ -58,6 +58,8 @@ static ir_node_t* gen_ir_term(ast_node_t* node) {
|
||||
Panic("gen_ir_expr: unknown node type");
|
||||
}
|
||||
}
|
||||
TODO();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ir_node_t* gen_ir_expr(ast_node_t* node) {
|
||||
@ -239,8 +241,11 @@ void gen_ir_jmp(ast_node_t* node) {
|
||||
switch (node->type) {
|
||||
case NT_STMT_IF: {
|
||||
ir_bblock_t* trueb = bblocks[0];
|
||||
trueb->label = "if_true";
|
||||
ir_bblock_t* falseb = bblocks[1];
|
||||
falseb->label = "if_false";
|
||||
ir_bblock_t* endb = bblocks[2];
|
||||
endb->label = "if_end";
|
||||
ir_node_t* jmp;
|
||||
|
||||
// cond
|
||||
@ -248,19 +253,16 @@ void gen_ir_jmp(ast_node_t* node) {
|
||||
emit_br(cond, trueb, falseb);
|
||||
|
||||
// true block
|
||||
vector_push(ctx.cur_func->bblocks, trueb);
|
||||
ctx.cur_block = trueb;
|
||||
_gen_ir_from_ast(node->if_stmt.if_stmt);
|
||||
|
||||
// else block
|
||||
if (node->if_stmt.else_stmt != NULL) {
|
||||
vector_push(ctx.cur_func->bblocks, falseb);
|
||||
ctx.cur_block = falseb;
|
||||
_gen_ir_from_ast(node->if_stmt.else_stmt);
|
||||
ir_node_t* jmp;
|
||||
|
||||
ctx.cur_block = endb;
|
||||
vector_push(ctx.cur_func->bblocks, ctx.cur_block);
|
||||
NEW_IR_JMP(jmp, ctx.cur_block);
|
||||
emit_instr(falseb, jmp);
|
||||
} else {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __IR_AST_H__
|
||||
|
||||
#include "ir.h"
|
||||
typedef struct ast_node ast_node_t;
|
||||
ir_prog_t* gen_ir_from_ast(ast_node_t* node);
|
||||
|
||||
#endif //
|
||||
|
Reference in New Issue
Block a user