added missing include
[libfirm] / ir / common / firm_common.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/firm_common.c
4  * Purpose:
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
17
18 #include "firm_common_t.h"
19 #include "irgraph.h"
20 #include "irloop.h"
21 #include "tv.h"
22
23 /**
24  * Ideally, this macro would check if size bytes could be read at
25  * pointer p. No generic solution.
26  */
27 #define POINTER_READ(p, size) (p)
28
29 /* returns the kind of the thing */
30 firm_kind
31 get_kind (const void *firm_thing) {
32   return POINTER_READ(firm_thing, sizeof(firm_kind)) ? *(firm_kind *)firm_thing : k_BAD;
33 }
34
35
36 const char* print_firm_kind(void *firm_thing) {
37   if (! firm_thing)
38     return "(NULL)";
39
40   switch (*(firm_kind *)firm_thing) {
41   case k_entity                 : return "k_entity";
42   case k_type                   : return "k_type";
43   case k_ir_graph               : return "k_ir_graph";
44   case k_ir_node                : return "k_ir_node";
45   case k_ir_mode                : return "k_ir_mode";
46   case k_ir_op                  : return "k_ir_op";
47   case k_tarval                 : return "k_tarval";
48   case k_ir_loop                : return "k_ir_loop";
49   case k_ir_compound_graph_path : return "k_ir_compound_graph_path";
50   default: return "";
51   }
52 }
53
54 /*
55  * identify a firm thing
56  */
57 void firm_identify_thing(void *X)
58 {
59   firm_kind *p = X;
60
61   if (! p) {
62     printf("(NULL)\n");
63     return;
64   }
65
66   switch (*p) {
67   case k_BAD:
68     printf("BAD: (%p)\n", X);
69     break;
70   case k_entity:
71     printf("entity: %s: %ld (%p)\n", get_entity_name(X), get_entity_nr(X), X);
72     break;
73   case k_type:
74     printf("type: %s %s: %ld (%p)\n", get_type_tpop_name(X), get_type_name(X), get_type_nr(X), X);
75     break;
76   case k_ir_graph:
77     printf("graph: %s: %ld (%p)\n", get_entity_name(get_irg_entity(X)), get_irg_graph_nr(X), X);
78     break;
79   case k_ir_node:
80     printf("irnode: %s%s %ld (%p)\n", get_irn_opname(X), get_mode_name(get_irn_mode(X)), get_irn_node_nr(X), X);
81     break;
82   case k_ir_mode:
83     printf("mode %s: (%p)\n", get_mode_name(X),X);
84     break;
85   case k_tarval:
86     printf("tarval : "); tarval_printf(X); printf(" (%p)\n", X);
87     break;
88   case k_ir_loop:
89     printf("loop: with depth %d: (%p)\n", get_loop_depth(X), X);
90     break;
91   case k_ir_op:
92   case k_ir_compound_graph_path:
93   default:
94     printf("Cannot identify thing at (%p).\n", X);
95   }
96 }