|
|
|
|
@@ -31,13 +31,16 @@ static const char *get_node_type_str(scc_ir_node_tag_t tag) {
|
|
|
|
|
// 获取操作符字符串
|
|
|
|
|
static const char *get_op_str(scc_ir_op_type_t op) {
|
|
|
|
|
static const char *ops[] = {
|
|
|
|
|
[IR_OP_EMPTY] = "empty", [IR_OP_NEQ] = "!=", [IR_OP_EQ] = "==",
|
|
|
|
|
[IR_OP_GT] = ">", [IR_OP_LT] = "<", [IR_OP_GE] = ">=",
|
|
|
|
|
[IR_OP_LE] = "<=", [IR_OP_ADD] = "+", [IR_OP_SUB] = "-",
|
|
|
|
|
[IR_OP_MUL] = "*", [IR_OP_DIV] = "/", [IR_OP_MOD] = "%",
|
|
|
|
|
[IR_OP_AND] = "&", [IR_OP_OR] = "|", [IR_OP_XOR] = "^",
|
|
|
|
|
[IR_OP_NOT] = "~", [IR_OP_SHL] = "<<", [IR_OP_SHR] = ">>",
|
|
|
|
|
[IR_OP_SAR] = ">>a", // Arithmetic shift right
|
|
|
|
|
[SCC_IR_OP_EMPTY] = "empty", [SCC_IR_OP_NEQ] = "!=",
|
|
|
|
|
[SCC_IR_OP_EQ] = "==", [SCC_IR_OP_GT] = ">",
|
|
|
|
|
[SCC_IR_OP_LT] = "<", [SCC_IR_OP_GE] = ">=",
|
|
|
|
|
[SCC_IR_OP_LE] = "<=", [SCC_IR_OP_ADD] = "+",
|
|
|
|
|
[SCC_IR_OP_SUB] = "-", [SCC_IR_OP_MUL] = "*",
|
|
|
|
|
[SCC_IR_OP_DIV] = "/", [SCC_IR_OP_MOD] = "%",
|
|
|
|
|
[SCC_IR_OP_AND] = "&", [SCC_IR_OP_OR] = "|",
|
|
|
|
|
[SCC_IR_OP_XOR] = "^", [SCC_IR_OP_NOT] = "~",
|
|
|
|
|
[SCC_IR_OP_SHL] = "<<", [SCC_IR_OP_SHR] = ">>",
|
|
|
|
|
[SCC_IR_OP_SAR] = ">>a", // Arithmetic shift right
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (op >= 0 && op < sizeof(ops) / sizeof(ops[0]) && ops[op] != NULL) {
|
|
|
|
|
@@ -49,7 +52,9 @@ static const char *get_op_str(scc_ir_op_type_t op) {
|
|
|
|
|
// 获取类型标签字符串
|
|
|
|
|
static const char *get_type_tag_str(scc_ir_type_tag_t tag) {
|
|
|
|
|
static const char *type_tags[] = {
|
|
|
|
|
[SCC_IR_TYPE_VOID] = "void", [SCC_IR_TYPE_I1] = "i1",
|
|
|
|
|
[SCC_IR_TYPE_VOID] = "void", [SCC_IR_TYPE_U8] = "u8",
|
|
|
|
|
[SCC_IR_TYPE_U16] = "u16", [SCC_IR_TYPE_U32] = "u32",
|
|
|
|
|
[SCC_IR_TYPE_U64] = "u64", [SCC_IR_TYPE_U128] = "u128",
|
|
|
|
|
[SCC_IR_TYPE_I8] = "i8", [SCC_IR_TYPE_I16] = "i16",
|
|
|
|
|
[SCC_IR_TYPE_I32] = "i32", [SCC_IR_TYPE_I64] = "i64",
|
|
|
|
|
[SCC_IR_TYPE_I128] = "i128", [SCC_IR_TYPE_F16] = "f16",
|
|
|
|
|
@@ -82,7 +87,7 @@ static void dump_const_int_node(scc_ir_dump_ctx_t *ctx,
|
|
|
|
|
const scc_ir_node_t *node) {
|
|
|
|
|
scc_tree_dump_push_level(ctx->dump_ctx, true);
|
|
|
|
|
scc_tree_print_indent(ctx->dump_ctx);
|
|
|
|
|
scc_printf("%d\n", node->data.const_int.int32);
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "%d\n", node->data.const_int.int32);
|
|
|
|
|
scc_tree_dump_pop_level(ctx->dump_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -189,13 +194,14 @@ static void dump_jump_node(scc_ir_dump_ctx_t *ctx, const scc_ir_node_t *node) {
|
|
|
|
|
scc_ir_bblock_t *target_bblock =
|
|
|
|
|
scc_ir_ctx_get_bblock(ctx->ir_ctx, node->data.jump.target_bblock);
|
|
|
|
|
if (target_bblock) {
|
|
|
|
|
scc_printf("to '%s'", target_bblock->label ? target_bblock->label
|
|
|
|
|
: "<unnamed>");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "to '%s'",
|
|
|
|
|
target_bblock->label ? target_bblock->label
|
|
|
|
|
: "<unnamed>");
|
|
|
|
|
} else {
|
|
|
|
|
scc_printf("to invalid block");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "to invalid block");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scc_printf("to NULL");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "to NULL");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -206,16 +212,17 @@ static void dump_call_node(scc_ir_dump_ctx_t *ctx, const scc_ir_node_t *node) {
|
|
|
|
|
scc_ir_func_t *callee =
|
|
|
|
|
scc_ir_ctx_get_func(ctx->ir_ctx, node->data.call.callee);
|
|
|
|
|
if (callee) {
|
|
|
|
|
scc_printf("func='%s'", callee->name ? callee->name : "<unnamed>");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "func='%s'",
|
|
|
|
|
callee->name ? callee->name : "<unnamed>");
|
|
|
|
|
} else {
|
|
|
|
|
scc_printf("func=<invalid>");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "func=<invalid>");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scc_printf("func=NULL");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "func=NULL");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scc_vec_size(node->data.call.args) > 0) {
|
|
|
|
|
scc_printf("\n");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 输出参数
|
|
|
|
|
@@ -261,14 +268,14 @@ void scc_ir_dump_node(scc_ir_dump_ctx_t *ctx, scc_ir_node_ref_t node_ref) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node->type) {
|
|
|
|
|
scc_printf(" : ");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, " : ");
|
|
|
|
|
scc_ir_type_t *type = scc_ir_ctx_get_type(ctx->ir_ctx, node->type);
|
|
|
|
|
if (type) {
|
|
|
|
|
PRINT_VALUE(ctx->dump_ctx, "%s", get_type_tag_str(type->tag));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scc_printf("\n");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "\n");
|
|
|
|
|
|
|
|
|
|
// 根据节点类型输出特定信息
|
|
|
|
|
switch (node->tag) {
|
|
|
|
|
@@ -305,7 +312,7 @@ void scc_ir_dump_node(scc_ir_dump_ctx_t *ctx, scc_ir_node_ref_t node_ref) {
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
PRINT_QUOTED_VALUE(ctx->dump_ctx, "unknown");
|
|
|
|
|
scc_printf("tag(%d)", node->tag);
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "tag(%d)", node->tag);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -325,7 +332,7 @@ void scc_ir_dump_type(scc_ir_dump_ctx_t *ctx, scc_ir_type_ref_t type_ref) {
|
|
|
|
|
scc_tree_print_indent(ctx->dump_ctx);
|
|
|
|
|
PRINT_NODE(ctx->dump_ctx, "Type: ");
|
|
|
|
|
PRINT_QUOTED_VALUE(ctx->dump_ctx, get_type_tag_str(type->tag));
|
|
|
|
|
scc_printf("\n");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "\n");
|
|
|
|
|
|
|
|
|
|
// 递归转储子类型
|
|
|
|
|
switch (type->tag) {
|
|
|
|
|
@@ -398,7 +405,7 @@ void scc_ir_dump_bblock(scc_ir_dump_ctx_t *ctx,
|
|
|
|
|
PRINT_NODE(ctx->dump_ctx, "BasicBlock: ");
|
|
|
|
|
PRINT_QUOTED_VALUE(ctx->dump_ctx,
|
|
|
|
|
bblock->label ? bblock->label : "<unnamed>");
|
|
|
|
|
scc_printf("\n");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "\n");
|
|
|
|
|
|
|
|
|
|
// 转储基本块中的指令
|
|
|
|
|
for (usize i = 0; i < scc_vec_size(bblock->instrs); i++) {
|
|
|
|
|
@@ -422,7 +429,7 @@ void scc_ir_dump_func(scc_ir_dump_ctx_t *ctx, scc_ir_func_ref_t func_ref) {
|
|
|
|
|
scc_tree_print_indent(ctx->dump_ctx);
|
|
|
|
|
PRINT_NODE(ctx->dump_ctx, "Function: ");
|
|
|
|
|
PRINT_QUOTED_VALUE(ctx->dump_ctx, func->name ? func->name : "<unnamed>");
|
|
|
|
|
scc_printf("\n");
|
|
|
|
|
scc_tree_dump_printf(ctx->dump_ctx, "\n");
|
|
|
|
|
|
|
|
|
|
// 输出函数类型
|
|
|
|
|
if (func->type) {
|
|
|
|
|
@@ -546,6 +553,7 @@ void scc_ir_dump_type_linear(scc_ir_dump_ctx_t *ctx,
|
|
|
|
|
} else {
|
|
|
|
|
PRINT_TYPE(ctx->dump_ctx, ")");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
LOG_ERROR("invalid type tag");
|
|
|
|
|
break;
|
|
|
|
|
|