-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfe1.c
259 lines (203 loc) · 6.36 KB
/
sfe1.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "toplev.h"
#include "diagnostic-core.h"
#include "tm.h"
#include "tree.h"
#include "tree-dump.h"
#include "tree-iterator.h"
#include "tree-ssa-operands.h"
#include "tree-pass.h"
#include "tree-ssa-alias.h"
#include "bitmap.h"
#include "ipa-prop.h"
#include "debug.h"
#include "function.h"
#include "flags.h"
#include "output.h"
#include "ggc.h"
#include "toplev.h"
#include "langhooks-def.h"
#include "langhooks.h"
#include "target.h"
#include "stringpool.h"
#include "is-a.h"
#include "internal-fn.h"
#include "gimple-expr.h"
#include "gimple.h"
#include "gimplify.h"
#include "cgraph.h"
#include "opts.h"
#include "input.h"
#include "print-tree.h"
#include "dumpfile.h"
#include "tree-cfg.h"
#include "sfe-lang.h"
#include "sfe1.h"
struct GTY(()) lang_identifier {
struct tree_identifier common;
};
union GTY((desc("TREE_CODE(&%h.node)"))) lang_tree_node {
union GTY((tag ("1"))) tree_node node;
};
struct GTY(()) lang_type {
char dummy;
};
/* Language-specific declaration information. */
struct GTY(()) lang_decl {
char dummy;
};
struct GTY(()) language_function {
char dummy;
};
vec<tree, va_gc> * sfe_global_decls_vec = NULL;
/* language hooks */
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
/* Initialization routine for the sfe1 (compiler) options */
void sfe_init_options (unsigned int, struct cl_decoded_option *) {
/* CL_sfe is automatically generated by the GCC build process */
return;
}
/* handle specific option - called by opts.c */
bool sfe_handle_option (size_t scode, const char *arg,
int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
location_t loc ATTRIBUTE_UNUSED,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) {
enum opt_code code = (enum opt_code) scode;
printf("Option: %s\n", arg); //zde by se měly řešit argumenty. Viz gcc/c-family/c-opts.c
return true;
}
/* The language hooks gets called whenever all options and arguments are
* parsed/read in the by options sub-component. This might be used for
* further validation checks
*
* If this function returns NOT 0, the middle-end/back-end of GCC WON'T
* be called (this is for example used to emit pre-processing code only in
* the C/C++ front-end)
*/
bool sfe_post_options (const char **) {
flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
return 0;
}
/* This language hook gets called in decode_options to determine the front-end language mask.
* It should return the corresponding CL_*, in this case CL_sfe.
*/
unsigned int sfe_option_lang_mask(void) {
return CL_sfe;
}
/* language dependent parser setup */
bool sfe_init (void) {
build_common_tree_nodes (flag_signed_char, false);
return true;
}
// copy of c_genericize function from c-family/c-gimplify.c
void tree_dump_original (tree fndecl) {
FILE *dump_orig;
int local_dump_flags;
struct cgraph_node *cgn;
/* Dump the C-specific tree IR. */
dump_orig = dump_begin (TDI_original, &local_dump_flags);
if (dump_orig) {
fprintf (dump_orig, "\n;; Function %s", lang_hooks.decl_printable_name (fndecl, 2));
fprintf (dump_orig, " (%s)\n", (!DECL_ASSEMBLER_NAME_SET_P (fndecl) ? "null" : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))));
fprintf (dump_orig, ";; enabled by -%s\n", dump_flag_name (TDI_original));
fprintf (dump_orig, "\n");
if (local_dump_flags & TDF_RAW) dump_node (DECL_SAVED_TREE (fndecl), TDF_SLIM | local_dump_flags, dump_orig);
else {
struct function fn;
fn.decl = fndecl;
fn.curr_properties = 0;
fn.cfg = NULL;
DECL_STRUCT_FUNCTION(fndecl) = &fn;
dump_function_to_file(fndecl, dump_orig, 0);
DECL_STRUCT_FUNCTION(fndecl) = NULL;
}
fprintf (dump_orig, "\n");
dump_end (TDI_original, dump_orig);
}
/* Dump all nested functions now. */
cgn = cgraph_get_create_node (fndecl);
for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) tree_dump_original (cgn->decl);
}
void register_global_function_declaration(tree functionDecl) {
vec_safe_push( sfe_global_decls_vec, functionDecl );
tree_dump_original(functionDecl);
gimplify_function_tree(functionDecl);
cgraph_finalize_function(functionDecl, false);
}
void register_global_variable_declaration( tree variable ) {
vec_safe_push( sfe_global_decls_vec, variable );
}
void sfe_parse_input_files(const char** filenames, unsigned filename_count) {
FILE* file;
AstNode* ast;
for(unsigned i = 0; i < filename_count; i++) {
printf("Processing file `%s'\n", filenames[i]);
if( !(file = fopen( filenames[i], "r" )) )
{
perror( "fopen" );
continue;
}
LexAnalyzer lexan( file );
Parser parser( lexan );
if( !parser.parse( ast ) )
{
printf( "Failed to parse file `%s'\n", filenames[i] );
continue;
}
printf( "File `%s' parsed successfully\n", filenames[i] );
// ast->print( 1, stdout );
if( !ast->translate() )
{
printf( "Failed to translate file `%s'\n", filenames[i] );
delete ast;
continue;
}
printf( "File `%s' translated successfully\n", filenames[i] );
delete ast;
}
/* if(flag_aaa) printf("Flag aaa is on\n"); */
/* else printf("Flag aaa is off\n"); */
/* execute parser from sfe-lang.c here */
}
/* parsing language hook */
void sfe_parse_file () {
sfe_parse_input_files (in_fnames, num_in_fnames);
}
/* language dependent wrapup */
void sfe_finish (void) {
}
static bool sfe_mark_addressable (tree exp) {
gcc_unreachable ();
}
static tree sfe_type_for_size (unsigned precision, int unsignedp) {
gcc_unreachable ();
}
static tree sfe_type_for_mode (enum machine_mode mode, int unsignedp) {
gcc_unreachable ();
}
static tree pushdecl (tree decl) {
gcc_unreachable ();
}
static tree getdecls (void) {
return NULL;
}
/* flush global declarations */
void sfe_write_globals (void) {
tree *vec = vec_safe_address(sfe_global_decls_vec);
int len = vec_safe_length(sfe_global_decls_vec);
wrapup_global_declarations (vec, len);
emit_debug_global_declarations (vec, len);
vec_free (sfe_global_decls_vec);
finalize_compilation_unit( );
}
static bool global_bindings_p (void) {
gcc_unreachable ();
}
tree convert (tree type, tree expr) {
return NULL;
}
#include "debug.h"
#include "gt-sfe-sfe1.h"
#include "gtype-sfe.h"