irio: Map id of body block of const irg to new const irg
[libfirm] / ir / ir / irio.c
1 /*
2  * Copyright (C) 1995-2009 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  * @brief   Write textual representation of firm to file.
23  * @author  Moritz Kroll
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include <string.h>
29
30 #include "irio.h"
31
32 #include "irnode_t.h"
33 #include "irprog.h"
34 #include "irgraph_t.h"
35 #include "ircons.h"
36 #include "irgmod.h"
37 #include "irflag_t.h"
38 #include "irgwalk.h"
39 #include "tv.h"
40 #include "array.h"
41 #include "error.h"
42 #include "adt/set.h"
43
44 #define SYMERROR ((unsigned) ~0)
45
46 typedef struct io_env_t
47 {
48         FILE *file;
49         set *idset;               /**< id_entry set, which maps from file ids to new Firm elements */
50         int ignoreblocks;
51         int line, col;
52         ir_type **fixedtypes;
53 } io_env_t;
54
55 typedef struct lex_state_t
56 {
57         long offs;
58         int line, col;
59 } lex_state_t;
60
61 typedef enum typetag_t
62 {
63         tt_align,
64         tt_allocation,
65         tt_builtin,
66         tt_initializer,
67         tt_iro,
68         tt_keyword,
69         tt_peculiarity,
70         tt_pin_state,
71         tt_tpo,
72         tt_type_state,
73         tt_variability,
74         tt_visibility,
75         tt_volatility
76 } typetag_t;
77
78 typedef enum keyword_t
79 {
80         kw_constirg,
81         kw_entity,
82         kw_frametype,
83         kw_irg,
84         kw_valuetype,
85         kw_type,
86         kw_typegraph
87 } keyword_t;
88
89 typedef struct symbol_t
90 {
91         const char *str;      /**< The name of this symbol. */
92         typetag_t   typetag;  /**< The type tag of this symbol. */
93         unsigned    code;     /**< The value of this symbol. */
94 } symbol_t;
95
96 typedef struct id_entry
97 {
98         long id;
99         void *elem;
100 } id_entry;
101
102 /** The symbol table, a set of symbol_t elements. */
103 static set *symtbl;
104
105
106 /**
107  * Calculate a hash value for a string.
108  */
109 static unsigned string_hash(const char *str, int len)
110 {
111         return str[0] * 27893 ^ str[len-1] * 81 ^ str[len >> 1];
112 }
113
114 /**
115  * Compare two symbol table entries.
116  */
117 static int symbol_cmp(const void *elt, const void *key, size_t size)
118 {
119         int res;
120         const symbol_t *entry = (const symbol_t *) elt;
121         const symbol_t *keyentry = (const symbol_t *) key;
122         (void) size;
123         res = entry->typetag - keyentry->typetag;
124         if(res) return res;
125         return strcmp(entry->str, keyentry->str);
126 }
127
128 static int id_cmp(const void *elt, const void *key, size_t size)
129 {
130         const id_entry *entry = (const id_entry *) elt;
131         const id_entry *keyentry = (const id_entry *) key;
132         (void) size;
133         return entry->id - keyentry->id;
134 }
135
136 /** Initializes the symbol table. May be called more than once without problems. */
137 static void symtbl_init(void)
138 {
139         symbol_t key;
140
141         /* Only initialize once */
142         if(symtbl != NULL)
143                 return;
144
145         symtbl = new_set(symbol_cmp, 256);
146
147 #define INSERT(s, tt, cod)                                       \
148         key.str = (s);                                               \
149         key.typetag = (tt);                                          \
150         key.code = (cod);                                            \
151         set_insert(symtbl, &key, sizeof(key), string_hash(s, sizeof(s)-1) + tt * 17)
152
153 #define INSERTENUM(tt, e) INSERT(#e, tt, e)
154 #define INSERTKEYWORD(k) INSERT(#k, tt_keyword, kw_##k)
155
156         INSERT("array", tt_tpo, tpo_array);
157         INSERT("class", tt_tpo, tpo_class);
158         INSERT("method", tt_tpo, tpo_method);
159         INSERT("pointer", tt_tpo, tpo_pointer);
160         INSERT("primitive", tt_tpo, tpo_primitive);
161         INSERT("struct", tt_tpo, tpo_struct);
162         INSERT("union", tt_tpo, tpo_union);
163         INSERT("Unknown", tt_tpo, tpo_unknown);
164
165         INSERTKEYWORD(constirg);
166         INSERTKEYWORD(entity);
167         INSERTKEYWORD(frametype);
168         INSERTKEYWORD(irg);
169         INSERTKEYWORD(valuetype);
170         INSERTKEYWORD(type);
171         INSERTKEYWORD(typegraph);
172
173 #include "gen_irio_lex.inl"
174
175         INSERTENUM(tt_align, align_non_aligned);
176         INSERTENUM(tt_align, align_is_aligned);
177
178         INSERTENUM(tt_allocation, allocation_automatic);
179         INSERTENUM(tt_allocation, allocation_parameter);
180         INSERTENUM(tt_allocation, allocation_dynamic);
181         INSERTENUM(tt_allocation, allocation_static);
182
183         INSERTENUM(tt_pin_state, op_pin_state_floats);
184         INSERTENUM(tt_pin_state, op_pin_state_pinned);
185         INSERTENUM(tt_pin_state, op_pin_state_exc_pinned);
186         INSERTENUM(tt_pin_state, op_pin_state_mem_pinned);
187
188         INSERTENUM(tt_type_state, layout_undefined);
189         INSERTENUM(tt_type_state, layout_fixed);
190
191         INSERTENUM(tt_variability, variability_uninitialized);
192         INSERTENUM(tt_variability, variability_initialized);
193         INSERTENUM(tt_variability, variability_part_constant);
194         INSERTENUM(tt_variability, variability_constant);
195
196         INSERTENUM(tt_visibility, visibility_local);
197         INSERTENUM(tt_visibility, visibility_external_visible);
198         INSERTENUM(tt_visibility, visibility_external_allocated);
199
200         INSERTENUM(tt_volatility, volatility_non_volatile);
201         INSERTENUM(tt_volatility, volatility_is_volatile);
202
203         INSERTENUM(tt_peculiarity, peculiarity_description);
204         INSERTENUM(tt_peculiarity, peculiarity_inherited);
205         INSERTENUM(tt_peculiarity, peculiarity_existent);
206
207         INSERTENUM(tt_initializer, IR_INITIALIZER_CONST);
208         INSERTENUM(tt_initializer, IR_INITIALIZER_TARVAL);
209         INSERTENUM(tt_initializer, IR_INITIALIZER_NULL);
210         INSERTENUM(tt_initializer, IR_INITIALIZER_COMPOUND);
211
212         INSERTENUM(tt_builtin, ir_bk_trap);
213         INSERTENUM(tt_builtin, ir_bk_debugbreak);
214         INSERTENUM(tt_builtin, ir_bk_return_address);
215         INSERTENUM(tt_builtin, ir_bk_frame_addess);
216         INSERTENUM(tt_builtin, ir_bk_prefetch);
217         INSERTENUM(tt_builtin, ir_bk_ffs);
218         INSERTENUM(tt_builtin, ir_bk_clz);
219         INSERTENUM(tt_builtin, ir_bk_ctz);
220         INSERTENUM(tt_builtin, ir_bk_popcount);
221         INSERTENUM(tt_builtin, ir_bk_parity);
222         INSERTENUM(tt_builtin, ir_bk_bswap);
223         INSERTENUM(tt_builtin, ir_bk_inport);
224         INSERTENUM(tt_builtin, ir_bk_outport);
225         INSERTENUM(tt_builtin, ir_bk_inner_trampoline);
226
227 #undef INSERTENUM
228 #undef INSERT
229 }
230
231 /** Returns the according symbol value for the given string and tag, or SYMERROR if none was found. */
232 static unsigned symbol(const char *str, typetag_t typetag)
233 {
234         symbol_t key, *entry;
235
236         key.str = str;
237         key.typetag = typetag;
238
239         entry = set_find(symtbl, &key, sizeof(key), string_hash(str, strlen(str)) + typetag * 17);
240         return entry ? entry->code : SYMERROR;
241 }
242
243 static void *get_id(io_env_t *env, long id)
244 {
245         id_entry key, *entry;
246         key.id = id;
247
248         entry = set_find(env->idset, &key, sizeof(key), (unsigned) id);
249         return entry ? entry->elem : NULL;
250 }
251
252 static void set_id(io_env_t *env, long id, void *elem)
253 {
254         id_entry key;
255         key.id = id;
256         key.elem = elem;
257         set_insert(env->idset, &key, sizeof(key), (unsigned) id);
258 }
259
260 static void write_mode(io_env_t *env, ir_mode *mode)
261 {
262         fputs(get_mode_name(mode), env->file);
263         fputc(' ', env->file);
264 }
265
266 static void write_tarval(io_env_t *env, tarval *tv)
267 {
268         char buf[1024];
269         write_mode(env, get_tarval_mode(tv));
270         tarval_snprintf(buf, sizeof(buf), tv);
271         fputs(buf, env->file);
272         fputc(' ', env->file);
273 }
274
275 static void write_pin_state(io_env_t *env, ir_node *irn)
276 {
277         fputs(get_op_pin_state_name(get_irn_pinned(irn)), env->file);
278         fputc(' ', env->file);
279 }
280
281 static void write_volatility(io_env_t *env, ir_node *irn)
282 {
283         ir_volatility vol;
284
285         if(is_Load(irn)) vol = get_Load_volatility(irn);
286         else if(is_Store(irn)) vol = get_Store_volatility(irn);
287         else assert(0 && "Invalid optype for write_volatility");
288
289         fputs(get_volatility_name(vol), env->file);
290         fputc(' ', env->file);
291 }
292
293 static void write_align(io_env_t *env, ir_node *irn)
294 {
295         ir_align align;
296
297         if(is_Load(irn)) align = get_Load_align(irn);
298         else if(is_Store(irn)) align = get_Store_align(irn);
299         else assert(0 && "Invalid optype for write_align");
300
301         fputs(get_align_name(align), env->file);
302         fputc(' ', env->file);
303 }
304
305 static void write_builtin_kind(io_env_t *env, ir_node *irn)
306 {
307         fputs(get_builtin_kind_name(get_Builtin_kind(irn)), env->file);
308         fputc(' ', env->file);
309 }
310
311 static void write_initializer(io_env_t *env, ir_initializer_t *ini)
312 {
313         FILE *f = env->file;
314         ir_initializer_kind_t ini_kind = get_initializer_kind(ini);
315
316         fputs(get_initializer_kind_name(ini_kind), f);
317         fputc(' ', f);
318
319         switch(ini_kind)
320         {
321                 case IR_INITIALIZER_CONST:
322                         fprintf(f, "%ld ", get_irn_node_nr(get_initializer_const_value(ini)));
323                         break;
324
325                 case IR_INITIALIZER_TARVAL:
326                         write_tarval(env, get_initializer_tarval_value(ini));
327                         break;
328
329                 case IR_INITIALIZER_NULL:
330                         break;
331
332                 case IR_INITIALIZER_COMPOUND:
333                 {
334                         unsigned i, n = get_initializer_compound_n_entries(ini);
335                         fprintf(f, "%d ", n);
336                         for(i = 0; i < n; i++)
337                                 write_initializer(env, get_initializer_compound_value(ini, i));
338                         break;
339                 }
340
341                 default:
342                         panic("Unknown initializer kind");
343         }
344 }
345
346 static void export_type_common(io_env_t *env, ir_type *tp)
347 {
348         fprintf(env->file, "\t%s %ld %s \"%s\" %u %u %s %s ",
349                         is_frame_type(tp) ? "frametype" : is_value_param_type(tp) ? "valuetype" : "type",
350                         get_type_nr(tp),
351                         get_type_tpop_name(tp),
352                         get_type_name(tp),
353                         get_type_size_bytes(tp),
354                         get_type_alignment_bytes(tp),
355                         get_type_state_name(get_type_state(tp)),
356                         get_visibility_name(get_type_visibility(tp)));
357 }
358
359 static void export_type_pre(io_env_t *env, ir_type *tp)
360 {
361         FILE *f = env->file;
362         int i;
363
364         // skip types to be handled by post walker
365         switch(get_type_tpop_code(tp))
366         {
367                 case tpo_array:
368                 case tpo_method:
369                 case tpo_pointer:
370                         return;
371         }
372
373         export_type_common(env, tp);
374
375         switch(get_type_tpop_code(tp))
376         {
377                 case tpo_class:
378                         /* TODO: inheritance stuff not supported yet */
379                         printf("Inheritance of classes not supported yet!\n");
380                         break;
381
382                 case tpo_primitive:
383                         write_mode(env, get_type_mode(tp));
384                         break;
385
386                 case tpo_struct:
387                         break;
388
389                 case tpo_union:
390                         break;
391
392                 case tpo_unknown:
393                         break;
394
395                 default:
396                         printf("export_type_pre: Unknown type code \"%s\".\n", get_type_tpop_name(tp));
397                         break;
398         }
399         fputc('\n', f);
400 }
401
402 static void export_type_post(io_env_t *env, ir_type *tp)
403 {
404         FILE *f = env->file;
405         int i;
406
407         // skip types already handled by pre walker
408         switch(get_type_tpop_code(tp))
409         {
410                 case tpo_class:
411                 case tpo_primitive:
412                 case tpo_struct:
413                 case tpo_union:
414                 case tpo_unknown:
415                         return;
416         }
417
418         export_type_common(env, tp);
419
420         switch(get_type_tpop_code(tp))
421         {
422                 case tpo_array:
423                 {
424                         int n = get_array_n_dimensions(tp);
425                         fprintf(f, "%i %ld ", n, get_type_nr(get_array_element_type(tp)));
426                         for(i = 0; i < n; i++)
427                         {
428                                 ir_node *lower = get_array_lower_bound(tp, i);
429                                 ir_node *upper = get_array_upper_bound(tp, i);
430
431                                 if(is_Const(lower)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(lower)));
432                                 else panic("Lower array bound is not constant");
433
434                                 if(is_Const(upper)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(upper)));
435                                 else if(is_Unknown(upper)) fputs("unknown ", f);
436                                 else panic("Upper array bound is not constant");
437                         }
438                         break;
439                 }
440
441                 case tpo_method:
442                 {
443                         int nparams = get_method_n_params(tp);
444                         int nresults = get_method_n_ress(tp);
445                         fprintf(f, "0x%X 0x%X %i %i ", get_method_calling_convention(tp),
446                                 get_method_additional_properties(tp), nparams, nresults);
447                         for(i = 0; i < nparams; i++)
448                                 fprintf(f, "%ld ", get_type_nr(get_method_param_type(tp, i)));
449                         for(i = 0; i < nresults; i++)
450                                 fprintf(f, "%ld ", get_type_nr(get_method_res_type(tp, i)));
451                         fprintf(f, "%d ", get_method_first_variadic_param_index(tp));
452                         break;
453                 }
454
455                 case tpo_pointer:
456                         write_mode(env, get_type_mode(tp));
457                         fprintf(f, "%ld ", get_type_nr(get_pointer_points_to_type(tp)));
458                         break;
459
460                 default:
461                         printf("export_type: Unknown type code \"%s\".\n", get_type_tpop_name(tp));
462                         break;
463         }
464         fputc('\n', f);
465 }
466
467 static void export_entity(io_env_t *env, ir_entity *ent)
468 {
469         ir_type *owner = get_entity_owner(ent);
470         fprintf(env->file, "\tentity %ld \"%s\" \"%s\" %ld %ld %d %u %s %s %s %s %s ",
471                         get_entity_nr(ent),
472                         get_entity_name(ent),
473                         ent->ld_name ? get_id_str(ent->ld_name) : "",
474                         get_type_nr(get_entity_type(ent)),
475                         get_type_nr(owner),
476                         get_entity_offset(ent),
477                         (unsigned) get_entity_offset_bits_remainder(ent),
478                         get_allocation_name(get_entity_allocation(ent)),
479                         get_visibility_name(get_entity_visibility(ent)),
480                         get_variability_name(get_entity_variability(ent)),
481                         get_peculiarity_name(get_entity_peculiarity(ent)),
482                         get_volatility_name(get_entity_volatility(ent)));
483
484         // TODO: inheritance stuff for class entities not supported yet
485         if(is_Class_type(owner) && owner != get_glob_type())
486                 printf("Inheritance of class entities not supported yet!\n");
487
488         if(get_entity_variability(ent) != variability_uninitialized
489                 && get_entity_visibility(ent) != visibility_external_allocated)
490         {
491                 if(is_compound_entity(ent))
492                 {
493                         if(has_entity_initializer(ent))
494                         {
495                                 fputs("initializer ", env->file);
496                                 write_initializer(env, get_entity_initializer(ent));
497                         }
498                         else
499                         {
500                                 int i, n = get_compound_ent_n_values(ent);
501                                 fputs("noninitializer ", env->file);
502                                 fprintf(env->file, "%d ", n);
503                                 for(i = 0; i < n; i++)
504                                 {
505                                         ir_entity *member = get_compound_ent_value_member(ent, i);
506                                         ir_node   *irn    = get_compound_ent_value(ent, i);
507                                         fprintf(env->file, "%ld %ld ", get_entity_nr(member), get_irn_node_nr(irn));
508                                 }
509                         }
510                 }
511                 else
512                 {
513                         ir_node *irn = get_atomic_ent_value(ent);
514                         fprintf(env->file, "%ld ", get_irn_node_nr(irn));
515                 }
516         }
517
518         fputc('\n', env->file);
519 }
520
521 static void export_type_or_ent_pre(type_or_ent tore, void *ctx)
522 {
523         io_env_t *env = (io_env_t *) ctx;
524         if(get_kind(tore.typ) == k_type)
525                 export_type_pre(env, tore.typ);
526 }
527
528 static void export_type_or_ent_post(type_or_ent tore, void *ctx)
529 {
530         io_env_t *env = (io_env_t *) ctx;
531
532         switch(get_kind(tore.ent))
533         {
534                 case k_entity:
535                         export_entity(env, tore.ent);
536                         break;
537
538                 case k_type:
539                         export_type_post(env, tore.typ);
540                         break;
541
542                 default:
543                         printf("export_type_or_ent_post: Unknown type or entity.\n");
544                         break;
545         }
546 }
547
548 static void export_node(ir_node *irn, void *ctx)
549 {
550         io_env_t *env = (io_env_t *) ctx;
551         int i, n;
552         unsigned opcode = get_irn_opcode(irn);
553
554         if(env->ignoreblocks && opcode == iro_Block)
555                 return;
556
557         n = get_irn_arity(irn);
558
559         fprintf(env->file, "\t%s %ld [ ", get_irn_opname(irn), get_irn_node_nr(irn));
560
561         for(i = -1; i < n; i++)
562         {
563                 ir_node *pred = get_irn_n(irn, i);
564                 if(pred == NULL) {
565                         /* Anchor node may have NULL predecessors */
566                         assert(is_Anchor(irn));
567                         fputs("-1 ", env->file);
568                 } else {
569                         fprintf(env->file, "%ld ", get_irn_node_nr(pred));
570                 }
571         }
572
573         fprintf(env->file, "] { ");
574
575         switch(opcode)
576         {
577                 #include "gen_irio_export.inl"
578         }
579         fputs("}\n", env->file);
580 }
581
582 /** Exports the whole irp to the given file in a textual form. */
583 void ir_export(const char *filename)
584 {
585         io_env_t env;
586         int i, n_irgs = get_irp_n_irgs(), n_pseudoirgs = get_irp_n_pseudo_irgs();
587
588         env.file = fopen(filename, "wt");
589         if(!env.file)
590         {
591                 perror(filename);
592                 return;
593         }
594
595         fputs("typegraph {\n", env.file);
596
597         type_walk_plus_frames(export_type_or_ent_pre, export_type_or_ent_post, &env);
598         /* TODO: Visit frame types and "types for value params"? */
599
600         for(i = 0; i < n_irgs; i++)
601         {
602                 ir_graph *irg = get_irp_irg(i);
603                 ir_type *valuetype = get_irg_value_param_type(irg);
604
605                 fprintf(env.file, "}\n\nirg %ld %ld %ld {\n", get_entity_nr(get_irg_entity(irg)),
606                         get_type_nr(get_irg_frame_type(irg)),
607                         valuetype == NULL ? -1 : get_type_nr(valuetype));
608
609                 env.ignoreblocks = 0;
610                 irg_block_walk_graph(irg, NULL, export_node, &env);
611
612                 env.ignoreblocks = 1;
613                 irg_walk_anchors(irg, NULL, export_node, &env);
614         }
615
616         fprintf(env.file, "}\n\nconstirg %ld {\n", get_irn_node_nr(get_const_code_irg()->current_block));
617
618         walk_const_code(NULL, export_node, &env);
619         fputs("}\n", env.file);
620
621         fclose(env.file);
622 }
623
624 /** Exports the given irg to the given file. */
625 void ir_export_irg(ir_graph *irg, const char *filename)
626 {
627         io_env_t env;
628
629         env.file = fopen(filename, "wt");
630         if(!env.file)
631         {
632                 perror(filename);
633                 return;
634         }
635
636         fputs("typegraph {\n", env.file);
637
638         type_walk_irg(irg, export_type_or_ent_pre, export_type_or_ent_post, &env);
639
640         fprintf(env.file, "}\n\nirg %ld {\n", get_entity_nr(get_irg_entity(irg)));
641
642         env.ignoreblocks = 0;
643         irg_block_walk_graph(irg, NULL, export_node, &env);
644
645         env.ignoreblocks = 1;
646         irg_walk_anchors(irg, NULL, export_node, &env);
647
648         /* TODO: Only output needed constants */
649         fputs("}\n\nconstirg {\n", env.file);
650         walk_const_code(NULL, export_node, &env);
651         fputs("}\n", env.file);
652
653         fclose(env.file);
654 }
655
656 static void save_lex_state(io_env_t *env, lex_state_t *state)
657 {
658         state->offs = ftell(env->file);
659         state->line = env->line;
660         state->col  = env->col;
661 }
662
663 static void restore_lex_state(io_env_t *env, lex_state_t *state)
664 {
665         fseek(env->file, state->offs, SEEK_SET);
666         env->line = state->line;
667         env->col  = state->col;
668 }
669
670 static int read_c(io_env_t *env)
671 {
672         int ch = fgetc(env->file);
673         switch(ch)
674         {
675                 case '\t':
676                         env->col += 4;
677                         break;
678
679                 case '\n':
680                         env->col = 0;
681                         env->line++;
682                         break;
683
684                 default:
685                         env->col++;
686                         break;
687         }
688         return ch;
689 }
690
691 /** Returns the first non-whitespace character or EOF. **/
692 static int skip_ws(io_env_t *env)
693 {
694         while(1)
695         {
696                 int ch = read_c(env);
697                 switch(ch)
698                 {
699                         case ' ':
700                         case '\t':
701                         case '\n':
702                         case '\r':
703                                 break;
704
705                         default:
706                                 return ch;
707                 }
708         }
709 }
710
711 static void skip_to(io_env_t *env, char to_ch)
712 {
713         int ch;
714         do
715         {
716                 ch = read_c(env);
717         }
718         while(ch != to_ch && ch != EOF);
719 }
720
721 static int expect_char(io_env_t *env, char ch)
722 {
723         int curch = skip_ws(env);
724         if(curch != ch)
725         {
726                 printf("Unexpected char '%c', expected '%c' in line %i:%i\n", curch, ch, env->line, env->col);
727                 return 0;
728         }
729         return 1;
730 }
731
732 #define EXPECT(c) if(expect_char(env, (c))) {} else return 0
733 #define EXPECT_OR_EXIT(c) if(expect_char(env, (c))) {} else exit(1)
734
735 inline static const char *read_str_to(io_env_t *env, char *buf, size_t bufsize)
736 {
737         size_t i;
738         for(i = 0; i < bufsize - 1; i++)
739         {
740                 int ch = read_c(env);
741                 if(ch == EOF) break;
742                 switch(ch)
743                 {
744                         case ' ':
745                         case '\t':
746                         case '\n':
747                         case '\r':
748                                 if(i != 0)
749                                         goto endofword;
750                                 i--;    // skip whitespace
751                                 break;
752
753                         default:
754                                 buf[i] = ch;
755                                 break;
756                 }
757         }
758 endofword:
759         buf[i] = 0;
760         return buf;
761 }
762
763 static const char *read_str(io_env_t *env)
764 {
765         static char buf[1024];
766         return read_str_to(env, buf, sizeof(buf));
767 }
768
769 static const char *read_qstr_to(io_env_t *env, char *buf, size_t bufsize)
770 {
771         size_t i;
772         EXPECT_OR_EXIT('\"');
773         for(i = 0; i < bufsize - 1; i++)
774         {
775                 int ch = read_c(env);
776                 if(ch == EOF)
777                 {
778                         printf("Unexpected end of quoted string!\n");
779                         exit(1);
780                 }
781                 if(ch == '\"') break;
782
783                 buf[i] = ch;
784         }
785         if(i == bufsize - 1)
786         {
787                 printf("Quoted string too long!\n");
788                 exit(1);
789         }
790         buf[i] = 0;
791         return buf;
792 }
793
794 static long read_long2(io_env_t *env, char **endptr)
795 {
796         static char buf[1024];
797         return strtol(read_str_to(env, buf, sizeof(buf)), endptr, 0);
798 }
799
800 static long read_long(io_env_t *env)
801 {
802         return read_long2(env, NULL);
803 }
804
805 static ir_node *get_node_or_null(io_env_t *env, long nodenr)
806 {
807         ir_node *node = (ir_node *) get_id(env, nodenr);
808         if(node && node->kind != k_ir_node)
809         {
810                 panic("Irn ID %ld collides with something else in line %i:%i\n", nodenr, env->line, env->col);
811         }
812         return node;
813 }
814
815 static ir_node *get_node(io_env_t *env, long nodenr)
816 {
817         ir_node *node = get_node_or_null(env, nodenr);
818         if(!node)
819                 panic("Unknown node: %ld in line %i:%i\n", nodenr, env->line, env->col);
820
821         return node;
822 }
823
824 static ir_node *get_node_or_dummy(io_env_t *env, long nodenr)
825 {
826         ir_node *node = get_node_or_null(env, nodenr);
827         if(!node)
828         {
829                 node = new_Dummy(mode_X);
830                 set_id(env, nodenr, node);
831         }
832         return node;
833 }
834
835 static ir_type *get_type(io_env_t *env, long typenr)
836 {
837         ir_type *type = (ir_type *) get_id(env, typenr);
838         if(!type)
839         {
840                 panic("Unknown type: %ld in line %i:%i\n", typenr, env->line, env->col);
841         }
842         else if(type->kind != k_type)
843         {
844                 panic("Type ID %ld collides with something else in line %i:%i\n", typenr, env->line, env->col);
845         }
846         return type;
847 }
848
849 static ir_type *read_type(io_env_t *env)
850 {
851         return get_type(env, read_long(env));
852 }
853
854 static ir_entity *get_entity(io_env_t *env, long entnr)
855 {
856         ir_entity *entity = (ir_entity *) get_id(env, entnr);
857         if(!entity)
858         {
859                 printf("Unknown entity: %ld in line %i:%i\n", entnr, env->line, env->col);
860                 exit(1);
861         }
862         else if(entity->kind != k_entity)
863         {
864                 panic("Entity ID %ld collides with something else in line %i:%i\n", entnr, env->line, env->col);
865         }
866         return entity;
867 }
868
869 static ir_entity *read_entity(io_env_t *env)
870 {
871         return get_entity(env, read_long(env));
872 }
873
874 static ir_mode *read_mode(io_env_t *env)
875 {
876         static char buf[128];
877         int i, n;
878
879         read_str_to(env, buf, sizeof(buf));
880
881         n = get_irp_n_modes();
882         for(i = 0; i < n; i++)
883         {
884                 ir_mode *mode = get_irp_mode(i);
885                 if(!strcmp(buf, get_mode_name(mode)))
886                         return mode;
887         }
888
889         printf("Unknown mode \"%s\" in line %i:%i\n", buf, env->line, env->col);
890         return mode_ANY;
891 }
892
893 static const char *get_typetag_name(typetag_t typetag)
894 {
895         switch(typetag)
896         {
897                 case tt_align:       return "align";
898                 case tt_allocation:  return "allocation";
899                 case tt_builtin:     return "builtin kind";
900                 case tt_initializer: return "initializer kind";
901                 case tt_iro:         return "opcode";
902                 case tt_peculiarity: return "peculiarity";
903                 case tt_pin_state:   return "pin state";
904                 case tt_tpo:         return "type";
905                 case tt_type_state:  return "type state";
906                 case tt_variability: return "variability";
907                 case tt_visibility:  return "visibility";
908                 case tt_volatility:  return "volatility";
909                 default: return "<UNKNOWN>";
910         }
911 }
912
913 /**
914  * Read and decode an enum constant.
915  */
916 static unsigned read_enum(io_env_t *env, typetag_t typetag)
917 {
918         static char buf[128];
919         unsigned code = symbol(read_str_to(env, buf, sizeof(buf)), typetag);
920         if(code != SYMERROR)
921                 return code;
922
923         printf("Invalid %s: \"%s\" in %i:%i\n", get_typetag_name(typetag), buf, env->line, env->col);
924         return 0;
925 }
926
927 #define read_align(env)            ((ir_align)              read_enum(env, tt_align))
928 #define read_allocation(env)       ((ir_allocation)         read_enum(env, tt_allocation))
929 #define read_peculiarity(env)      ((ir_peculiarity)        read_enum(env, tt_peculiarity))
930 #define read_pin_state(env)        ((op_pin_state)          read_enum(env, tt_pin_state))
931 #define read_type_state(env)       ((ir_type_state)         read_enum(env, tt_type_state))
932 #define read_variability(env)      ((ir_variability)        read_enum(env, tt_variability))
933 #define read_visibility(env)       ((ir_visibility)         read_enum(env, tt_visibility))
934 #define read_volatility(env)       ((ir_volatility)         read_enum(env, tt_volatility))
935 #define read_initializer_kind(env) ((ir_initializer_kind_t) read_enum(env, tt_initializer))
936 #define read_builtin_kind(env)     ((ir_builtin_kind)       read_enum(env, tt_builtin))
937
938 static ir_cons_flags get_cons_flags(io_env_t *env)
939 {
940         ir_cons_flags flags = cons_none;
941
942         op_pin_state pinstate = read_pin_state(env);
943         switch(pinstate)
944         {
945                 case op_pin_state_floats: flags |= cons_floats; break;
946                 case op_pin_state_pinned: break;
947                 default:
948                         panic("Error in %i:%i: Invalid pinstate: %s", env->line, env->col, get_op_pin_state_name(pinstate));
949         }
950
951         if(read_volatility(env) == volatility_is_volatile) flags |= cons_volatile;
952         if(read_align(env) == align_non_aligned) flags |= cons_unaligned;
953
954         return flags;
955 }
956
957 static tarval *read_tv(io_env_t *env)
958 {
959         static char buf[128];
960         ir_mode *tvmode = read_mode(env);
961         read_str_to(env, buf, sizeof(buf));
962         return new_tarval_from_str(buf, strlen(buf), tvmode);
963 }
964
965 static ir_initializer_t *read_initializer(io_env_t *env)
966 {
967         FILE *f = env->file;
968         ir_initializer_kind_t ini_kind = read_initializer_kind(env);
969
970         switch(ini_kind)
971         {
972                 case IR_INITIALIZER_CONST:
973                 {
974                         ir_node *irn = get_node_or_dummy(env, read_long(env));
975                         return create_initializer_const(irn);
976                 }
977
978                 case IR_INITIALIZER_TARVAL:
979                         return create_initializer_tarval(read_tv(env));
980
981                 case IR_INITIALIZER_NULL:
982                         return get_initializer_null();
983
984                 case IR_INITIALIZER_COMPOUND:
985                 {
986                         unsigned i, n = (unsigned) read_long(env);
987                         ir_initializer_t *ini = create_initializer_compound(n);
988                         for(i = 0; i < n; i++)
989                         {
990                                 ir_initializer_t *curini = read_initializer(env);
991                                 set_initializer_compound_value(ini, i, curini);
992                         }
993                         return ini;
994                 }
995
996                 default:
997                         panic("Unknown initializer kind");
998         }
999 }
1000
1001
1002 /** Reads a type description and remembers it by its id. */
1003 static void import_type(io_env_t *env, keyword_t kwkind)
1004 {
1005         char           buf[1024];
1006         int            i;
1007         ir_type       *type;
1008         long           typenr = read_long(env);
1009         const char    *tpop   = read_str(env);
1010         const char    *name   = read_qstr_to(env, buf, sizeof(buf));
1011         unsigned       size   = (unsigned) read_long(env);
1012         unsigned       align  = (unsigned) read_long(env);
1013         ir_type_state  state  = read_type_state(env);
1014         ir_visibility  vis    = read_visibility(env);
1015
1016         ident         *id     = new_id_from_str(name);
1017
1018         const char    *kindstr;
1019
1020         if(kwkind == kw_frametype)
1021         {
1022                 if(symbol(tpop, tt_tpo) != tpo_class)
1023                 {
1024                         printf("Frame type must be a class type in line %i:%i\n", env->line, env->col);
1025                         skip_to(env, '\n');
1026                         return;
1027                 }
1028
1029                 type = new_type_frame(id);
1030                 set_type_size_bytes(type, size);
1031
1032                 kindstr = "frametype";
1033         }
1034         else if(kwkind == kw_valuetype)
1035         {
1036                 if(symbol(tpop, tt_tpo) != tpo_struct)
1037                 {
1038                         printf("Value type must be a struct type in line %i:%i\n", env->line, env->col);
1039                         skip_to(env, '\n');
1040                         return;
1041                 }
1042
1043                 type = new_type_value(id);
1044                 set_type_size_bytes(type, size);
1045
1046                 kindstr = "valuetype";
1047         }
1048         else
1049         {
1050                 switch(symbol(tpop, tt_tpo))
1051                 {
1052                         case tpo_array:
1053                         {
1054                                 int ndims = (int) read_long(env);
1055                                 long elemtypenr = read_long(env);
1056                                 ir_type *elemtype = get_type(env, elemtypenr);
1057
1058                                 type = new_type_array(id, ndims, elemtype);
1059                                 for(i = 0; i < ndims; i++)
1060                                 {
1061                                         const char *str = read_str(env);
1062                                         if(strcmp(str, "unknown"))
1063                                         {
1064                                                 long lowerbound = strtol(str, NULL, 0);
1065                                                 set_array_lower_bound_int(type, i, lowerbound);
1066                                         }
1067                                         str = read_str(env);
1068                                         if(strcmp(str, "unknown"))
1069                                         {
1070                                                 long upperbound = strtol(str, NULL, 0);
1071                                                 set_array_upper_bound_int(type, i, upperbound);
1072                                         }
1073                                 }
1074                                 set_type_size_bytes(type, size);
1075                                 break;
1076                         }
1077
1078                         case tpo_class:
1079                                 type = new_type_class(id);
1080                                 set_type_size_bytes(type, size);
1081                                 break;
1082
1083                         case tpo_method:
1084                         {
1085                                 unsigned callingconv = (unsigned) read_long(env);
1086                                 unsigned addprops    = (unsigned) read_long(env);
1087                                 int nparams          = (int)      read_long(env);
1088                                 int nresults         = (int)      read_long(env);
1089                                 int variaindex;
1090
1091                                 type = new_type_method(id, nparams, nresults);
1092
1093                                 for(i = 0; i < nparams; i++)
1094                                 {
1095                                         long     typenr = read_long(env);
1096                                         ir_type *paramtype = get_type(env, typenr);
1097
1098                                         set_method_param_type(type, i, paramtype);
1099                                 }
1100                                 for(i = 0; i < nresults; i++)
1101                                 {
1102                                         long typenr = read_long(env);
1103                                         ir_type *restype = get_type(env, typenr);
1104
1105                                         set_method_res_type(type, i, restype);
1106                                 }
1107
1108                                 variaindex = (int) read_long(env);
1109                                 if(variaindex != -1)
1110                                 {
1111                                         set_method_variadicity(type, variadicity_variadic);
1112                                         if(variaindex != nparams)
1113                                                 set_method_first_variadic_param_index(type, variaindex);
1114                                 }
1115
1116                                 set_method_calling_convention(type, callingconv);
1117                                 set_method_additional_properties(type, addprops);
1118                                 break;
1119                         }
1120
1121                         case tpo_pointer:
1122                         {
1123                                 ir_mode *mode = read_mode(env);
1124                                 ir_type *pointsto = get_type(env, read_long(env));
1125                                 type = new_type_pointer(id, pointsto, mode);
1126                                 break;
1127                         }
1128
1129                         case tpo_primitive:
1130                         {
1131                                 ir_mode *mode = read_mode(env);
1132                                 type = new_type_primitive(id, mode);
1133                                 break;
1134                         }
1135
1136                         case tpo_struct:
1137                                 type = new_type_struct(id);
1138                                 set_type_size_bytes(type, size);
1139                                 break;
1140
1141                         case tpo_union:
1142                                 type = new_type_union(id);
1143                                 set_type_size_bytes(type, size);
1144                                 break;
1145
1146                         case tpo_unknown:
1147                                 return;   // ignore unknown type
1148
1149                         default:
1150                                 if(typenr != 0)  // ignore global type
1151                                         printf("Unknown type kind: \"%s\" in line %i:%i\n", tpop, env->line, env->col);
1152                                 skip_to(env, '\n');
1153                                 return;
1154                 }
1155                 kindstr = "type";
1156         }
1157
1158         set_type_alignment_bytes(type, align);
1159         set_type_visibility(type, vis);
1160
1161         if(state == layout_fixed)
1162                 ARR_APP1(ir_type *, env->fixedtypes, type);
1163
1164         set_id(env, typenr, type);
1165         printf("Insert %s %s %ld\n", kindstr, name, typenr);
1166 }
1167
1168 /** Reads an entity description and remembers it by its id. */
1169 static void import_entity(io_env_t *env)
1170 {
1171         char          buf[1024], buf2[1024];
1172         long          entnr       = read_long(env);
1173         const char   *name        = read_qstr_to(env, buf, sizeof(buf));
1174         const char   *ld_name     = read_qstr_to(env, buf2, sizeof(buf2));
1175         long          typenr      = read_long(env);
1176         long          ownertypenr = read_long(env);
1177
1178         ir_type   *type      = get_type(env, typenr);
1179         ir_type   *ownertype = !ownertypenr ? get_glob_type() : get_type(env, ownertypenr);
1180         ir_entity *entity    = new_entity(ownertype, new_id_from_str(name), type);
1181
1182         if(*ld_name) set_entity_ld_ident(entity, new_id_from_str(ld_name));
1183         set_entity_offset     (entity, (int) read_long(env));
1184         set_entity_offset_bits_remainder(entity, (unsigned char) read_long(env));
1185         set_entity_allocation (entity, read_allocation(env));
1186         set_entity_visibility (entity, read_visibility(env));
1187         set_entity_variability(entity, read_variability(env));
1188         set_entity_peculiarity(entity, read_peculiarity(env));
1189         set_entity_volatility (entity, read_volatility(env));
1190
1191         if(get_entity_variability(entity) != variability_uninitialized
1192                 && get_entity_visibility(entity) != visibility_external_allocated)
1193         {
1194                 if(is_compound_entity(entity))
1195                 {
1196                         if(!strcmp(read_str_to(env, buf2, sizeof(buf2)), "initializer"))
1197                         {
1198                                 set_entity_initializer(entity, read_initializer(env));
1199                         }
1200                         else
1201                         {
1202                                 int i, n = (int) read_long(env);
1203                                 for(i = 0; i < n; i++)
1204                                 {
1205                                         ir_entity *member = get_entity(env, read_long(env));
1206                                         ir_node   *irn    = get_node_or_dummy(env, read_long(env));
1207                                         add_compound_ent_value(entity, irn, member);
1208                                 }
1209                         }
1210                 }
1211                 else
1212                 {
1213                         ir_node *irn = get_node_or_dummy(env, read_long(env));
1214                         set_atomic_ent_value(entity, irn);
1215                 }
1216         }
1217
1218         set_id(env, entnr, entity);
1219         printf("Insert entity %s %ld\n", name, entnr);
1220 }
1221
1222 /** Parses the whole type graph. */
1223 static int parse_typegraph(io_env_t *env)
1224 {
1225         const char *kind;
1226         lex_state_t oldstate;
1227
1228         EXPECT('{');
1229
1230         save_lex_state(env, &oldstate);
1231
1232         current_ir_graph = get_const_code_irg();
1233
1234         // parse all types first
1235         while(1)
1236         {
1237                 int isframetype = 0;
1238
1239                 kind = read_str(env);
1240                 if(kind[0] == '}' && !kind[1]) break;
1241
1242                 keyword_t kwkind = (keyword_t) symbol(kind, tt_keyword);
1243                 switch(kwkind)
1244                 {
1245                         case kw_type:
1246                         case kw_frametype:
1247                         case kw_valuetype:
1248                                 import_type(env, kwkind);
1249                                 break;
1250
1251                         default:
1252                                 skip_to(env, '\n');
1253                                 break;
1254                 }
1255         }
1256
1257         // now parse rest
1258         restore_lex_state(env, &oldstate);
1259
1260         while(1)
1261         {
1262                 kind = read_str(env);
1263                 if(kind[0] == '}' && !kind[1]) break;
1264
1265                 switch(symbol(kind, tt_keyword))
1266                 {
1267                         case kw_type:
1268                         case kw_frametype:
1269                         case kw_valuetype:
1270                                 skip_to(env, '\n');
1271                                 break;
1272
1273                         case kw_entity:
1274                                 import_entity(env);
1275                                 break;
1276
1277                         default:
1278                                 printf("Type graph element not supported yet: \"%s\"\n", kind);
1279                                 skip_to(env, '\n');
1280                                 break;
1281                 }
1282         }
1283         return 1;
1284 }
1285
1286 static int read_node_header(io_env_t *env, long *nodenr, long **preds, const char **nodename)
1287 {
1288         int numpreds;
1289         *nodename = read_str(env);
1290         if((*nodename)[0] == '}' && !(*nodename)[1]) return -1;  // end-of-graph
1291
1292         *nodenr = read_long(env);
1293
1294         ARR_RESIZE(ir_node *, *preds, 0);
1295
1296         EXPECT('[');
1297         for(numpreds = 0; !feof(env->file); numpreds++)
1298         {
1299                 char *endptr;
1300                 ARR_APP1(long, *preds, read_long2(env, &endptr));
1301                 if(*endptr == ']') break;
1302         }
1303         return numpreds;
1304 }
1305
1306 /** Parses an IRG. */
1307 static int parse_graph(io_env_t *env, ir_graph *irg)
1308 {
1309         long       *preds = NEW_ARR_F(long, 16);
1310         ir_node   **prednodes = NEW_ARR_F(ir_node *, 16);
1311         int         i, numpreds, ret = 1;
1312         long        nodenr;
1313         const char *nodename;
1314         ir_node    *node, *newnode;
1315
1316         current_ir_graph = irg;
1317
1318         EXPECT('{');
1319
1320         while(1)
1321         {
1322                 numpreds = read_node_header(env, &nodenr, &preds, &nodename);
1323                 if(numpreds == -1) break;  // end-of-graph
1324                 if(!numpreds)
1325                 {
1326                         printf("Node %s %ld is missing predecessors!", nodename, nodenr);
1327                         ret = 0;
1328                         break;
1329                 }
1330
1331                 ARR_RESIZE(ir_node *, prednodes, numpreds);
1332                 for(i = 0; i < numpreds - 1; i++)
1333                         prednodes[i] = get_node_or_dummy(env, preds[i + 1]);
1334
1335                 node = get_node_or_null(env, nodenr);
1336                 newnode = NULL;
1337
1338                 EXPECT('{');
1339
1340                 switch(symbol(nodename, tt_iro))
1341                 {
1342                         case iro_End:
1343                         {
1344                                 ir_node *newendblock = get_node(env, preds[0]);
1345                                 newnode = get_irg_end(current_ir_graph);
1346                                 exchange(get_nodes_block(newnode), newendblock);
1347                                 for(i = 0; i < numpreds - 1; i++)
1348                                         add_irn_n(newnode, prednodes[i]);
1349                                 break;
1350                         }
1351
1352                         case iro_Start:
1353                         {
1354                                 ir_node *newstartblock = get_node(env, preds[0]);
1355                                 newnode = get_irg_start(current_ir_graph);
1356                                 exchange(get_nodes_block(newnode), newstartblock);
1357                                 break;
1358                         }
1359
1360                         case iro_Block:
1361                         {
1362                                 if(preds[0] != nodenr)
1363                                 {
1364                                         printf("Invalid block: preds[0] != nodenr (%ld != %ld)\n",
1365                                                 preds[0], nodenr);
1366                                         ret = 0;
1367                                         goto endloop;
1368                                 }
1369
1370                                 newnode = new_Block(numpreds - 1, prednodes);
1371                                 break;
1372                         }
1373
1374                         case iro_Anchor:
1375                                 newnode = current_ir_graph->anchor;
1376                                 for(i = 0; i < numpreds - 1; i++)
1377                                         set_irn_n(newnode, i, prednodes[i]);
1378                                 set_irn_n(newnode, -1, get_node(env, preds[0]));
1379                                 break;
1380
1381                         case iro_SymConst:
1382                         {
1383                                 long entnr = read_long(env);
1384                                 union symconst_symbol sym;
1385                                 sym.entity_p = get_entity(env, entnr);
1386                                 newnode = new_SymConst(mode_P, sym, symconst_addr_ent);
1387                                 break;
1388                         }
1389
1390                         #include "gen_irio_import.inl"
1391
1392                         default:
1393                                 goto notsupported;
1394                 }
1395
1396                 EXPECT('}');
1397
1398                 if(!newnode)
1399                 {
1400 notsupported:
1401                         panic("Node type not supported yet: %s in line %i:%i\n", nodename, env->line, env->col);
1402                 }
1403
1404                 if(node)
1405                         exchange(node, newnode);
1406                 /* Always update hash entry to avoid more uses of id nodes */
1407                 set_id(env, nodenr, newnode);
1408                 //printf("Insert %s %ld\n", nodename, nodenr);
1409         }
1410
1411 endloop:
1412         DEL_ARR_F(preds);
1413         DEL_ARR_F(prednodes);
1414
1415         return ret;
1416 }
1417
1418 /** Imports an previously exported textual representation of an (maybe partial) irp */
1419 void ir_import(const char *filename)
1420 {
1421         int oldoptimize = get_optimize();
1422         firm_verification_t oldver = get_node_verification_mode();
1423         io_env_t ioenv;
1424         io_env_t *env = &ioenv;
1425         int i, n;
1426
1427         symtbl_init();
1428
1429         memset(env, 0, sizeof(*env));
1430         env->idset = new_set(id_cmp, 128);
1431         env->fixedtypes = NEW_ARR_F(ir_type *, 0);
1432
1433         env->file = fopen(filename, "rt");
1434         if(!env->file)
1435         {
1436                 perror(filename);
1437                 exit(1);
1438         }
1439
1440         set_optimize(0);
1441         do_node_verification(FIRM_VERIFICATION_OFF);
1442
1443         while(1)
1444         {
1445                 const char *str = read_str(env);
1446                 if(!*str) break;
1447                 switch(symbol(str, tt_keyword))
1448                 {
1449                         case kw_typegraph:
1450                                 if(!parse_typegraph(env)) goto end;
1451                                 break;
1452
1453                         case kw_irg:
1454                         {
1455                                 ir_entity *irgent = get_entity(env, read_long(env));
1456                                 long valuetypeid;
1457                                 ir_graph *irg = new_ir_graph(irgent, 0);
1458                                 set_irg_frame_type(irg, get_type(env, read_long(env)));
1459                                 valuetypeid = read_long(env);
1460                                 if(valuetypeid != -1)
1461                                         set_method_value_param_type(get_entity_type(irgent),
1462                                                         get_type(env, valuetypeid));
1463
1464                                 if(!parse_graph(env, irg)) goto end;
1465                                 break;
1466                         }
1467
1468                         case kw_constirg:
1469                         {
1470                                 ir_graph *constirg = get_const_code_irg();
1471                                 long bodyblockid = read_long(env);
1472                                 set_id(env, bodyblockid, constirg->current_block);
1473                                 if(!parse_graph(env, constirg)) goto end;
1474                                 break;
1475                         }
1476                 }
1477         }
1478
1479 end:
1480         n = ARR_LEN(env->fixedtypes);
1481         for(i = 0; i < n; i++)
1482                 set_type_state(env->fixedtypes[i], layout_fixed);
1483
1484         DEL_ARR_F(env->fixedtypes);
1485
1486         del_set(env->idset);
1487
1488         irp_finalize_cons();
1489
1490         do_node_verification(oldver);
1491         set_optimize(oldoptimize);
1492
1493         fclose(env->file);
1494 }