fe119c7c9aec771c2df08cc13de8cb6cfd81619d
[libfirm] / ir / be / ia32 / dump_support.inl
1 static void fprintf_tv(FILE *F, tarval *tv, int brackets) {
2   char buf[1024];
3   tarval_snprintf(buf, sizeof(buf), tv);
4
5   if (brackets)
6     fprintf(F, "[%s]", buf);
7   else
8     fprintf(F, "%s", buf);
9 }
10
11 const char *get_sc_name(ir_node *symc) {
12   if (get_irn_opcode(symc) != iro_SymConst)
13     return "NONE";
14
15   switch (get_SymConst_kind(symc)) {
16     case symconst_addr_name:
17       return get_id_str(get_SymConst_name(symc));
18
19     case symconst_addr_ent:
20       return get_entity_ld_name(get_SymConst_entity(symc));
21
22     default:
23       assert(!"Unsupported SymConst");
24   }
25 }
26
27 static int dump_node_ia32(ir_node *n, FILE *F, dump_reason_t reason) {
28   const char *name, *p;
29   ir_mode    *mode = NULL;
30   int        bad   = 0;
31
32   switch (reason) {
33     case dump_node_opcode_txt:
34       name = get_irn_opname(n);
35       fprintf(F, "%s", name);
36       break;
37
38     case dump_node_mode_txt:
39       mode = get_irn_mode(n);
40
41       if (mode == mode_BB || mode == mode_ANY || mode == mode_BAD || mode == mode_T) {
42         mode = NULL;
43       }
44       else if (is_ia32_Load(n)) {
45         mode = get_irn_mode(get_irn_n(n, 1));
46       }
47       else if (is_ia32_Store(n)) {
48         mode = get_irn_mode(get_irn_n(n, 2));
49       }
50
51       if (mode)
52         fprintf(F, "[%s]", get_mode_name(mode));
53       break;
54
55     case dump_node_nodeattr_txt:
56       name = get_irn_opname(n);
57       p = name + strlen(name) - 2;
58       if (p[0] == '_' && p[1] == 'i') {
59         tarval *tv = get_Immop_tarval(n);
60         if (tv)
61           fprintf_tv(F, tv, 1);
62         else {
63           fprintf(F, "[SymC &%s]", get_sc_name(get_old_ir(n)));
64         }
65       }
66       else if (is_ia32_Call(n)) {
67         ir_node *old_call = get_old_ir(n);
68         ir_node *old_imm  = get_Call_ptr(old_call);
69
70         fprintf(F, "&%s ", get_sc_name(get_Imm_sc(old_imm)));
71       }
72       break;
73
74     case dump_node_info_txt:
75       if (is_ia32_Lea(n)) {
76         tarval *o  = get_ia32_Lea_offs(n);
77         tarval *tv = get_Immop_tarval(n);
78
79         fprintf(F, "LEA ");
80         if (o)
81           fprintf_tv(F, o, 0);
82         fprintf(F, "(%s, %s", get_irn_opname(get_irn_n(n, 0)), get_irn_opname(get_irn_n(n, 1)));
83         if (tv) {
84           fprintf(F, ", ");
85           fprintf_tv(F, tv, 0);
86         }
87         fprintf(F, ")\n");
88       }
89       break;
90   }
91
92   return bad;
93 }