Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //original idea by fedor
- void print_tree_obj(tree node)
- {
- if (node == NULL_TREE) return;
- switch (TREE_CODE (node)) {
- case IDENTIFIER_NODE:
- printf("%s", IDENTIFIER_POINTER (node));
- break;
- case VAR_DECL:
- printf("%s", IDENTIFIER_POINTER (DECL_NAME (node)));
- break;
- case CONST_DECL:
- printf("%s", IDENTIFIER_POINTER (DECL_NAME (node)));
- break;
- case INTEGER_CST:
- printf("%d", TREE_INT_CST_LOW(node));
- break;
- case STRING_CST:
- printf("\"%s\"", TREE_STRING_POINTER (node));
- break;
- case SSA_NAME:
- if (SSA_NAME_IDENTIFIER (node)) {
- print_tree_obj (SSA_NAME_IDENTIFIER (node));
- }
- printf("_%d", SSA_NAME_VERSION (node));
- break;
- default:
- break;
- }
- }
- #define PRINT_CASE(c) case c:printf(#c); break
- void print_stmt(gimple stmt)
- {
- int i;
- switch (gimple_code(stmt)) {
- case GIMPLE_ASM:
- printf("asm code\n");
- break;
- case GIMPLE_CALL: {
- printf("-------CALL-------\n");
- tree callee = gimple_call_fndecl (stmt);
- for (i = 0; i < gimple_call_num_args(stmt); i++) {
- tree arg = gimple_call_arg(stmt, i);
- printf(" [%d]: ", i);
- print_tree_obj(arg);
- }
- } break;
- case GIMPLE_ASSIGN: {
- tree lhs = gimple_assign_lhs(stmt);
- tree rhs1, rhs2;
- int count = gimple_num_ops(stmt);
- printf("------ASSIGN------\n");
- printf("assign with %d argument(s)\n", count-1);
- switch (gimple_num_ops (stmt))
- {
- case 0:
- case 1: break;
- case 2:
- rhs1 = gimple_assign_rhs1 (stmt);
- print_tree_obj(lhs);
- printf(" = ");
- print_tree_obj(rhs1);
- break;
- case 3:
- rhs1 = gimple_assign_rhs1 (stmt);
- rhs2 = gimple_assign_rhs2 (stmt);
- print_tree_obj(lhs);
- printf(" = ");
- print_tree_obj(rhs1);
- printf(", ");
- print_tree_obj(rhs2);
- break;
- }
- } break;
- case GIMPLE_RESX: {
- printf("-------RESX-------\n");
- } break;
- case GIMPLE_RETURN: {
- printf("------RETURN------\n");
- } break;
- case GIMPLE_SWITCH: {
- printf("------SWITCH------\n");
- } break;
- case GIMPLE_TRY: {
- printf("-------TRY--------\n");
- } break;
- case GIMPLE_GOTO: {
- printf("-------GOTO-------\n");
- } break;
- case GIMPLE_COND: {
- printf("-------COND-------\n");
- } break;
- default: {
- printf("default case %d\n", gimple_code(stmt));
- }
- }
- printf("\n");
- }
- void print_tree()
- {
- basic_block bb;
- gimple_stmt_iterator gsi;
- edge e;
- gimple phi, stmt;
- int flags;
- printf("===%s===\n", function_name(cfun));
- FOR_EACH_BB_FN (bb, cfun)
- {
- for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- {
- stmt = gsi_stmt (gsi);
- print_stmt(stmt);
- }
- }
- printf("=====================\n\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment