de0ba2be1c91f2e6a9811f8823bc2ca182edbdab
[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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "firm_common_t.h"
30 #include "irgraph.h"
31 #include "irloop.h"
32 #include "tv.h"
33
34 /**
35  * Ideally, this macro would check if size bytes could be read at
36  * pointer p. No generic solution.
37  */
38 #define POINTER_READ(p, size) (p)
39
40 /* returns the kind of the thing */
41 firm_kind get_kind(const void *firm_thing) {
42         return POINTER_READ(firm_thing, sizeof(firm_kind)) ? *(firm_kind *)firm_thing : k_BAD;
43 }  /* get_kind */
44
45 const char *print_firm_kind(void *firm_thing) {
46         if (! firm_thing)
47                 return "(NULL)";
48
49         switch (*(firm_kind *)firm_thing) {
50         case k_entity                 : return "k_entity";
51         case k_type                   : return "k_type";
52         case k_ir_graph               : return "k_ir_graph";
53         case k_ir_node                : return "k_ir_node";
54         case k_ir_mode                : return "k_ir_mode";
55         case k_ir_op                  : return "k_ir_op";
56         case k_tarval                 : return "k_tarval";
57         case k_ir_loop                : return "k_ir_loop";
58         case k_ir_compound_graph_path : return "k_ir_compound_graph_path";
59         case k_ir_extblk              : return "k_ir_extblk";
60         case k_ir_prog                : return "k_ir_prog";
61         case k_ir_region              : return "k_ir_region";
62
63         default: return "";
64         }
65 }  /* print_firm_kind */
66
67 /*
68  * identify a firm thing
69  */
70 void firm_identify_thing(void *X) {
71         if (! X) {
72                 printf("(NULL)\n");
73                 return;
74         }
75
76         switch (get_kind(X)) {
77         case k_BAD:
78                 printf("BAD: (%p)\n", X);
79                 break;
80         case k_entity:
81                 printf("entity: %s: %ld (%p)\n", get_entity_name(X), get_entity_nr(X), X);
82                 break;
83         case k_type:
84                 printf("type: %s %s: %ld (%p)\n", get_type_tpop_name(X), get_type_name(X), get_type_nr(X), X);
85                 break;
86         case k_ir_graph:
87                 printf("graph: %s: %ld (%p)\n", get_entity_name(get_irg_entity(X)), get_irg_graph_nr(X), X);
88                 break;
89         case k_ir_node:
90                 printf("irnode: %s%s %ld (%p)\n", get_irn_opname(X), get_mode_name(get_irn_mode(X)), get_irn_node_nr(X), X);
91                 break;
92         case k_ir_mode:
93                 printf("mode %s: (%p)\n", get_mode_name(X), X);
94                 break;
95         case k_ir_op:
96                 printf("op %s: (%p)\n", get_op_name(X), X);
97                 break;
98         case k_tarval:
99                 printf("tarval : "); tarval_printf(X); printf(" (%p)\n", X);
100                 break;
101         case k_ir_loop:
102                 printf("loop: with depth %d: (%p)\n", get_loop_depth(X), X);
103                 break;
104         case k_ir_compound_graph_path:
105                 printf("compound_graph_path: (%p)\n", X);
106                 break;
107         case k_ir_extblk:
108                 printf("extended block: (%p)\n", X);
109                 break;
110         case k_ir_prog:
111                 printf("irp: (%p)\n", X);
112                 break;
113         case k_ir_region:
114                 printf("region: (%p)\n", X);
115                 break;
116         default:
117                 printf("Cannot identify thing at (%p).\n", X);
118         }
119 }  /* firm_identify_thing */