08ae5dd6b38d0563e8c434ac1d345809fd18138d
[libfirm] / ir / common / firm_common.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @author    Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
23  * @version   $Id$
24  */
25 #include "config.h"
26
27 #include "firm_common_t.h"
28 #include "irgraph.h"
29 #include "irloop.h"
30 #include "tv.h"
31
32 /**
33  * Ideally, this macro would check if size bytes could be read at
34  * pointer p. No generic solution.
35  */
36 #define POINTER_READ(p, size) (p)
37
38 /* returns the kind of the thing */
39 firm_kind get_kind(const void *firm_thing) {
40         return POINTER_READ(firm_thing, sizeof(firm_kind)) ? *(firm_kind *)firm_thing : k_BAD;
41 }  /* get_kind */
42
43 const char *print_firm_kind(void *firm_thing) {
44         if (! firm_thing)
45                 return "(NULL)";
46
47         switch (*(firm_kind *)firm_thing) {
48         case k_entity                 : return "k_entity";
49         case k_type                   : return "k_type";
50         case k_ir_graph               : return "k_ir_graph";
51         case k_ir_node                : return "k_ir_node";
52         case k_ir_mode                : return "k_ir_mode";
53         case k_ir_op                  : return "k_ir_op";
54         case k_tarval                 : return "k_tarval";
55         case k_ir_loop                : return "k_ir_loop";
56         case k_ir_compound_graph_path : return "k_ir_compound_graph_path";
57         case k_ir_extblk              : return "k_ir_extblk";
58         case k_ir_prog                : return "k_ir_prog";
59         case k_ir_region              : return "k_ir_region";
60
61         default: return "";
62         }
63 }  /* print_firm_kind */
64
65 /*
66  * identify a firm thing
67  */
68 void firm_identify_thing(void *X) {
69         if (! X) {
70                 printf("(NULL)\n");
71                 return;
72         }
73
74         switch (get_kind(X)) {
75         case k_BAD:
76                 printf("BAD: (%p)\n", X);
77                 break;
78         case k_entity:
79                 printf("entity: %s: %ld (%p)\n", get_entity_name(X), get_entity_nr(X), X);
80                 break;
81         case k_type:
82                 printf("type: %s %s: %ld (%p)\n", get_type_tpop_name(X), get_type_name(X), get_type_nr(X), X);
83                 break;
84         case k_ir_graph:
85                 printf("graph: %s: %ld (%p)\n", get_entity_name(get_irg_entity(X)), get_irg_graph_nr(X), X);
86                 break;
87         case k_ir_node:
88                 printf("irnode: %s%s %ld (%p)\n", get_irn_opname(X), get_mode_name(get_irn_mode(X)), get_irn_node_nr(X), X);
89                 break;
90         case k_ir_mode:
91                 printf("mode %s: (%p)\n", get_mode_name(X), X);
92                 break;
93         case k_ir_op:
94                 printf("op %s: (%p)\n", get_op_name(X), X);
95                 break;
96         case k_tarval:
97                 printf("tarval : "); tarval_printf(X); printf(" (%p)\n", X);
98                 break;
99         case k_ir_loop:
100                 printf("loop: with depth %d: (%p)\n", get_loop_depth(X), X);
101                 break;
102         case k_ir_compound_graph_path:
103                 printf("compound_graph_path: (%p)\n", X);
104                 break;
105         case k_ir_extblk:
106                 printf("extended block: (%p)\n", X);
107                 break;
108         case k_ir_prog:
109                 printf("irp: (%p)\n", X);
110                 break;
111         case k_ir_region:
112                 printf("region: (%p)\n", X);
113                 break;
114         default:
115                 printf("Cannot identify thing at (%p).\n", X);
116         }
117 }  /* firm_identify_thing */