-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenum.c
84 lines (73 loc) · 2.85 KB
/
enum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
//#include "gcc-plugin.h"
#include "gcc-plugin.h"
#include "tree.h"
#include "plugin-version.h"
#include "tm.h"
#include "cp/cp-tree.h"
#include "ggc.h"
//#define ENTER fprintf( code_outputfile,"Enter at %s:%d\n", __FILE__, __LINE__);
#define ENTER
#define PREFIX "field type :"
extern _IO_FILE * code_outputfile;
void process_enum_name_value(const char * p, int val)
{
//IDENTIFIER_POINTER (TREE_PURPOSE (tv))),value);
fprintf( code_outputfile,"ENUM : %s %d",p,val);
}
void process_enum_emit ( tree enumeral_type) {
fprintf( code_outputfile,"ENUM(\n");
tree tv;
/* Output the list of possible values for the enumeration type. */
for (tv = TYPE_VALUES (enumeral_type); tv ; tv = TREE_CHAIN (tv))
{
tree v = TREE_VALUE (tv);
// GCC 4.4 switched to consts for enum values
if (TREE_CODE (v) == CONST_DECL)
v = DECL_INITIAL (v);
int value = TREE_INT_CST_LOW (v);
fprintf( code_outputfile,"ENUMVALUE(\"%s\",%d),\n",IDENTIFIER_POINTER (TREE_PURPOSE (tv)),value);
//process_enum_name_value(IDENTIFIER_POINTER (TREE_PURPOSE (tv)),value);
}
fprintf( code_outputfile,"0),/*enum*/\n");
// if we want to generate code for the enum :
// process_enum_tree_code(enumeral_type);
}
void process_enum_tree_code_imp ( tree enumeral_type);
void process_enum_tree_code_generate_gcc ( tree enumeral_type) {
process_enum_tree_code_imp(enumeral_type); // declare the callbacks first
fprintf( code_outputfile,"process_enum_tree_code(tree t) { ");
fprintf( code_outputfile,"\tswitch(TREE_CODE(t))\n{\n");
tree tv;
/* Output the list of possible values for the enumeration type. */
for (tv = TYPE_VALUES (enumeral_type); tv ; tv = TREE_CHAIN (tv))
{
// fprintf( code_outputfile,"ENUM VALUE\n");
tree v = TREE_VALUE (tv);
// GCC 4.4 switched to consts for enum values
if (TREE_CODE (v) == CONST_DECL)
v = DECL_INITIAL (v);
int value = TREE_INT_CST_LOW (v);
const char * p = IDENTIFIER_POINTER (TREE_PURPOSE (tv));
//process_enum_name_value(),value);
fprintf( code_outputfile,"case %s:\n\tfield_type_%s(t);\n\tbreak;\n",p,p);
}
fprintf( code_outputfile,"\tdefault : ;\n");
fprintf( code_outputfile,"};\n");
fprintf( code_outputfile,"};\n");
}
void process_enum_tree_code_imp ( tree enumeral_type) {
tree tv;
/* Output the list of possible values for the enumeration type. */
for (tv = TYPE_VALUES (enumeral_type); tv ; tv = TREE_CHAIN (tv))
{
tree v = TREE_VALUE (tv);
// GCC 4.4 switched to consts for enum values
if (TREE_CODE (v) == CONST_DECL)
v = DECL_INITIAL (v);
int value = TREE_INT_CST_LOW (v);
const char * p = IDENTIFIER_POINTER (TREE_PURPOSE (tv));
//process_enum_name_value(),value);
fprintf( code_outputfile,"void field_type_%s(tree t){emit_tree_code(\"%s\");\n};\n",p,p);
}
}