2 * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Write textual representation of firm to file.
23 * @author Moritz Kroll
34 #include "irgraph_t.h"
44 #define SYMERROR ((unsigned) ~0)
49 set *idset; /**< id_entry set, which maps from file ids to new Firm elements */
55 typedef enum typetag_t
69 typedef struct symbol_t
71 const char *str; /**< The name of this symbol. */
72 typetag_t typetag; /**< The type tag of this symbol. */
73 unsigned code; /**< The value of this symbol. */
76 typedef struct id_entry
82 /** The symbol table, a set of symbol_t elements. */
87 * Calculate a hash value for a string.
89 static unsigned string_hash(const char *str, int len)
91 return str[0] * 27893 ^ str[len-1] * 81 ^ str[len >> 1];
95 * Compare two symbol table entries.
97 static int symbol_cmp(const void *elt, const void *key, size_t size)
99 const symbol_t *entry = (const symbol_t *) elt;
100 const symbol_t *keyentry = (const symbol_t *) key;
102 return strcmp(entry->str, keyentry->str);
105 static int id_cmp(const void *elt, const void *key, size_t size)
107 const id_entry *entry = (const id_entry *) elt;
108 const id_entry *keyentry = (const id_entry *) key;
110 return entry->id - keyentry->id;
113 /** Initializes the symbol table. May be called more than once without problems. */
114 static void symtbl_init(void)
118 /* Only initialize once */
122 symtbl = new_set(symbol_cmp, 32);
124 #define INSERT(s, tt, cod) \
126 key.typetag = (tt); \
128 set_insert(symtbl, &key, sizeof(key), string_hash(s, sizeof(s)-1))
130 #define INSERTENUM(tt, e) INSERT(#e, tt, e)
132 INSERT("array", tt_tpo, tpo_array);
133 INSERT("class", tt_tpo, tpo_class);
134 INSERT("method", tt_tpo, tpo_method);
135 INSERT("pointer", tt_tpo, tpo_pointer);
136 INSERT("primitive", tt_tpo, tpo_primitive);
137 INSERT("struct", tt_tpo, tpo_struct);
138 INSERT("Unknown", tt_tpo, tpo_unknown);
140 #include "gen_irio_lex.inl"
142 INSERTENUM(tt_align, align_non_aligned);
143 INSERTENUM(tt_align, align_is_aligned);
145 INSERTENUM(tt_allocation, allocation_automatic);
146 INSERTENUM(tt_allocation, allocation_parameter);
147 INSERTENUM(tt_allocation, allocation_dynamic);
148 INSERTENUM(tt_allocation, allocation_static);
150 INSERTENUM(tt_pin_state, op_pin_state_floats);
151 INSERTENUM(tt_pin_state, op_pin_state_pinned);
152 INSERTENUM(tt_pin_state, op_pin_state_exc_pinned);
153 INSERTENUM(tt_pin_state, op_pin_state_mem_pinned);
155 INSERTENUM(tt_type_state, layout_undefined);
156 INSERTENUM(tt_type_state, layout_fixed);
158 INSERTENUM(tt_variability, variability_uninitialized);
159 INSERTENUM(tt_variability, variability_initialized);
160 INSERTENUM(tt_variability, variability_part_constant);
161 INSERTENUM(tt_variability, variability_constant);
163 INSERTENUM(tt_visibility, visibility_local);
164 INSERTENUM(tt_visibility, visibility_external_visible);
165 INSERTENUM(tt_visibility, visibility_external_allocated);
167 INSERTENUM(tt_volatility, volatility_non_volatile);
168 INSERTENUM(tt_volatility, volatility_is_volatile);
170 INSERTENUM(tt_peculiarity, peculiarity_description);
171 INSERTENUM(tt_peculiarity, peculiarity_inherited);
172 INSERTENUM(tt_peculiarity, peculiarity_existent);
178 /** Returns the according symbol value for the given string and tag, or SYMERROR if none was found. */
179 static unsigned symbol(const char *str, typetag_t typetag)
181 symbol_t key, *entry;
185 entry = set_find(symtbl, &key, sizeof(key), string_hash(str, strlen(str)));
186 if (entry && entry->typetag == typetag) {
192 static void *get_id(io_env_t *env, long id)
194 id_entry key, *entry;
197 entry = set_find(env->idset, &key, sizeof(key), (unsigned) id);
198 return entry ? entry->elem : NULL;
201 static void set_id(io_env_t *env, long id, void *elem)
206 set_insert(env->idset, &key, sizeof(key), (unsigned) id);
209 static void write_mode(io_env_t *env, ir_mode *mode)
211 fputs(get_mode_name(mode), env->file);
212 fputc(' ', env->file);
215 static void write_pin_state(io_env_t *env, ir_node *irn)
217 fputs(get_op_pin_state_name(get_irn_pinned(irn)), env->file);
218 fputc(' ', env->file);
221 static void write_volatility(io_env_t *env, ir_node *irn)
225 if(is_Load(irn)) vol = get_Load_volatility(irn);
226 else if(is_Store(irn)) vol = get_Store_volatility(irn);
227 else assert(0 && "Invalid optype for write_volatility");
229 fputs(get_volatility_name(vol), env->file);
230 fputc(' ', env->file);
233 static void write_align(io_env_t *env, ir_node *irn)
237 if(is_Load(irn)) align = get_Load_align(irn);
238 else if(is_Store(irn)) align = get_Store_align(irn);
239 else assert(0 && "Invalid optype for write_align");
241 fputs(get_align_name(align), env->file);
242 fputc(' ', env->file);
245 static void export_type(io_env_t *env, ir_type *tp)
249 fprintf(f, "\ttype %ld %s \"%s\" %u %u %s %s ",
251 get_type_tpop_name(tp),
253 get_type_size_bytes(tp),
254 get_type_alignment_bytes(tp),
255 get_type_state_name(get_type_state(tp)),
256 get_visibility_name(get_type_visibility(tp)));
258 switch(get_type_tpop_code(tp))
262 int n = get_array_n_dimensions(tp);
263 fprintf(f, "%i %ld ", n, get_type_nr(get_array_element_type(tp)));
264 for(i = 0; i < n; i++)
266 ir_node *lower = get_array_lower_bound(tp, i);
267 ir_node *upper = get_array_upper_bound(tp, i);
269 if(is_Const(lower)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(lower)));
270 else panic("Lower array bound is not constant");
272 if(is_Const(upper)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(upper)));
273 else panic("Upper array bound is not constant");
279 /* TODO: inheritance stuff not supported yet */
280 printf("Inheritance of classes not supported yet!\n");
285 int nparams = get_method_n_params(tp);
286 int nresults = get_method_n_ress(tp);
287 fprintf(f, "%i %i ", nparams, nresults);
288 for(i = 0; i < nparams; i++)
289 fprintf(f, "%ld ", get_type_nr(get_method_param_type(tp, i)));
290 for(i = 0; i < nresults; i++)
291 fprintf(f, "%ld ", get_type_nr(get_method_res_type(tp, i)));
296 write_mode(env, get_type_mode(tp));
297 fprintf(f, "%ld ", get_type_nr(get_pointer_points_to_type(tp)));
301 write_mode(env, get_type_mode(tp));
311 printf("export_type: Unknown type code \"%s\".\n", get_type_tpop_name(tp));
317 static void export_entity(io_env_t *env, ir_entity *ent)
319 ir_type *owner = get_entity_owner(ent);
320 fprintf(env->file, "\tentity %ld \"%s\" \"%s\" %ld %ld %d %u %s %s %s %s %s ",
322 get_entity_name(ent),
323 ent->ld_name ? get_id_str(ent->ld_name) : "",
324 get_type_nr(get_entity_type(ent)),
326 get_entity_offset(ent),
327 (unsigned) get_entity_offset_bits_remainder(ent),
328 get_allocation_name(get_entity_allocation(ent)),
329 get_visibility_name(get_entity_visibility(ent)),
330 get_variability_name(get_entity_variability(ent)),
331 get_peculiarity_name(get_entity_peculiarity(ent)),
332 get_volatility_name(get_entity_volatility(ent)));
334 // TODO: inheritance stuff for class entities not supported yet
335 if(is_Class_type(owner) && owner != get_glob_type())
336 printf("Inheritance of class entities not supported yet!\n");
338 if(get_entity_variability(ent) != variability_uninitialized
339 && get_entity_visibility(ent) != visibility_external_allocated)
341 if(is_compound_entity(ent))
343 int i, n = get_compound_ent_n_values(ent);
344 fprintf(env->file, "%d ", n);
345 for(i = 0; i < n; i++)
347 ir_entity *member = get_compound_ent_value_member(ent, i);
348 ir_node *irn = get_compound_ent_value(ent, i);
349 fprintf(env->file, "%ld %ld ", get_entity_nr(member), get_irn_node_nr(irn));
354 ir_node *irn = get_atomic_ent_value(ent);
355 fprintf(env->file, "%ld ", get_irn_node_nr(irn));
359 fputc('\n', env->file);
362 static void export_type_or_ent(type_or_ent tore, void *ctx)
364 io_env_t *env = (io_env_t *) ctx;
366 switch(get_kind(tore.ent))
369 export_entity(env, tore.ent);
373 export_type(env, tore.typ);
377 printf("export_type_or_ent: Unknown type or entity.\n");
382 static void export_node(ir_node *irn, void *ctx)
384 io_env_t *env = (io_env_t *) ctx;
386 unsigned opcode = get_irn_opcode(irn);
389 if(env->ignoreblocks && opcode == iro_Block)
392 n = get_irn_arity(irn);
394 fprintf(env->file, "\t%s %ld [ ", get_irn_opname(irn), get_irn_node_nr(irn));
396 for(i = -1; i < n; i++)
398 ir_node *pred = get_irn_n(irn, i);
400 /* Anchor node may have NULL predecessors */
401 assert(is_Anchor(irn));
402 fputs("-1 ", env->file);
404 fprintf(env->file, "%ld ", get_irn_node_nr(pred));
408 fprintf(env->file, "] { ");
412 #include "gen_irio_export.inl"
414 fputs("}\n", env->file);
417 /** Exports the whole irp to the given file in a textual form. */
418 void ir_export(const char *filename)
421 int i, n_irgs = get_irp_n_irgs(), n_pseudoirgs = get_irp_n_pseudo_irgs();
423 env.file = fopen(filename, "wt");
430 fputs("typegraph {\n", env.file);
432 type_walk(NULL, export_type_or_ent, &env);
433 /* TODO: Visit frame types and "types for value params"? */
435 for(i = 0; i < n_irgs; i++)
437 ir_graph *irg = get_irp_irg(i);
439 fprintf(env.file, "}\n\nirg %ld {\n", get_entity_nr(get_irg_entity(irg)));
441 env.ignoreblocks = 0;
442 irg_block_walk_graph(irg, NULL, export_node, &env);
444 env.ignoreblocks = 1;
445 irg_walk_anchors(irg, NULL, export_node, &env);
448 fputs("}\n\nconstirg {\n", env.file);
449 walk_const_code(NULL, export_node, &env);
450 fputs("}\n", env.file);
455 /** Exports the given irg to the given file. */
456 void ir_export_irg(ir_graph *irg, const char *filename)
460 env.file = fopen(filename, "wt");
467 fputs("typegraph {\n", env.file);
469 type_walk_irg(irg, NULL, export_type_or_ent, &env);
471 fprintf(env.file, "}\n\nirg %ld {\n", get_entity_nr(get_irg_entity(irg)));
473 env.ignoreblocks = 0;
474 irg_block_walk_graph(irg, NULL, export_node, &env);
476 env.ignoreblocks = 1;
477 irg_walk_anchors(irg, NULL, export_node, &env);
479 /* TODO: Only output needed constants */
480 fputs("}\n\nconstirg {\n", env.file);
481 walk_const_code(NULL, export_node, &env);
482 fputs("}\n", env.file);
487 static int read_c(io_env_t *env)
489 int ch = fgetc(env->file);
508 /** Returns the first non-whitespace character or EOF. **/
509 static int skip_ws(io_env_t *env)
513 int ch = read_c(env);
528 static void skip_to(io_env_t *env, char to_ch)
535 while(ch != to_ch && ch != EOF);
538 static int expect_char(io_env_t *env, char ch)
540 int curch = skip_ws(env);
543 printf("Unexpected char '%c', expected '%c' in line %i:%i\n", curch, ch, env->line, env->col);
549 #define EXPECT(c) if(expect_char(env, (c))) {} else return 0
550 #define EXPECT_OR_EXIT(c) if(expect_char(env, (c))) {} else exit(1)
552 inline static const char *read_str_to(io_env_t *env, char *buf, size_t bufsize)
555 for(i = 0; i < bufsize - 1; i++)
557 int ch = read_c(env);
567 i--; // skip whitespace
580 static const char *read_str(io_env_t *env)
582 static char buf[1024];
583 return read_str_to(env, buf, sizeof(buf));
586 static const char *read_qstr_to(io_env_t *env, char *buf, size_t bufsize)
589 EXPECT_OR_EXIT('\"');
590 for(i = 0; i < bufsize - 1; i++)
592 int ch = read_c(env);
595 printf("Unexpected end of quoted string!\n");
598 if(ch == '\"') break;
604 printf("Quoted string too long!\n");
611 static long read_long2(io_env_t *env, char **endptr)
613 static char buf[1024];
614 return strtol(read_str_to(env, buf, sizeof(buf)), endptr, 0);
617 static long read_long(io_env_t *env)
619 return read_long2(env, NULL);
622 static ir_node *get_node_or_null(io_env_t *env, long nodenr)
624 ir_node *node = (ir_node *) get_id(env, nodenr);
625 if(node && node->kind != k_ir_node)
627 panic("Irn ID %ld collides with something else in line %i:%i\n", nodenr, env->line, env->col);
632 static ir_node *get_node(io_env_t *env, long nodenr)
634 ir_node *node = get_node_or_null(env, nodenr);
636 panic("Unknown node: %ld in line %i:%i\n", nodenr, env->line, env->col);
641 static ir_node *get_node_or_dummy(io_env_t *env, long nodenr)
643 ir_node *node = get_node_or_null(env, nodenr);
646 node = new_Dummy(mode_X);
647 set_id(env, nodenr, node);
652 static ir_type *get_type(io_env_t *env, long typenr)
654 ir_type *type = (ir_type *) get_id(env, typenr);
657 panic("Unknown type: %ld in line %i:%i\n", typenr, env->line, env->col);
659 else if(type->kind != k_type)
661 panic("Type ID %ld collides with something else in line %i:%i\n", typenr, env->line, env->col);
666 static ir_type *read_type(io_env_t *env)
668 return get_type(env, read_long(env));
671 static ir_entity *get_entity(io_env_t *env, long entnr)
673 ir_entity *entity = (ir_entity *) get_id(env, entnr);
676 printf("Unknown entity: %ld in line %i:%i\n", entnr, env->line, env->col);
679 else if(entity->kind != k_entity)
681 panic("Entity ID %ld collides with something else in line %i:%i\n", entnr, env->line, env->col);
686 static ir_entity *read_entity(io_env_t *env)
688 return get_entity(env, read_long(env));
691 static ir_mode *read_mode(io_env_t *env)
693 static char buf[128];
696 read_str_to(env, buf, sizeof(buf));
698 n = get_irp_n_modes();
699 for(i = 0; i < n; i++)
701 ir_mode *mode = get_irp_mode(i);
702 if(!strcmp(buf, get_mode_name(mode)))
706 printf("Unknown mode \"%s\" in line %i:%i\n", buf, env->line, env->col);
710 static const char *get_typetag_name(typetag_t typetag)
714 case tt_iro: return "opcode";
715 case tt_tpo: return "type";
716 case tt_align: return "align";
717 case tt_allocation: return "allocation";
718 case tt_peculiarity: return "peculiarity";
719 case tt_pin_state: return "pin state";
720 case tt_type_state: return "type state";
721 case tt_variability: return "variability";
722 case tt_visibility: return "visibility";
723 case tt_volatility: return "volatility";
724 default: return "<UNKNOWN>";
729 * Read and decode an enum constant.
731 static unsigned read_enum(io_env_t *env, typetag_t typetag)
733 static char buf[128];
734 unsigned code = symbol(read_str_to(env, buf, sizeof(buf)), typetag);
738 printf("Invalid %s: \"%s\" in %i:%i\n", get_typetag_name(typetag), buf, env->line, env->col);
742 #define read_align(env) ((ir_align) read_enum(env, tt_align))
743 #define read_allocation(env) ((ir_allocation) read_enum(env, tt_allocation))
744 #define read_peculiarity(env) ((ir_peculiarity) read_enum(env, tt_peculiarity))
745 #define read_pin_state(env) ((op_pin_state) read_enum(env, tt_pin_state))
746 #define read_type_state(env) ((ir_type_state) read_enum(env, tt_type_state))
747 #define read_variability(env) ((ir_variability) read_enum(env, tt_variability))
748 #define read_visibility(env) ((ir_visibility) read_enum(env, tt_visibility))
749 #define read_volatility(env) ((ir_volatility) read_enum(env, tt_volatility))
751 static ir_cons_flags get_cons_flags(io_env_t *env)
753 ir_cons_flags flags = cons_none;
755 op_pin_state pinstate = read_pin_state(env);
758 case op_pin_state_floats: flags |= cons_floats; break;
759 case op_pin_state_pinned: break;
761 panic("Error in %i:%i: Invalid pinstate: %s", env->line, env->col, get_op_pin_state_name(pinstate));
764 if(read_volatility(env) == volatility_is_volatile) flags |= cons_volatile;
765 if(read_align(env) == align_non_aligned) flags |= cons_unaligned;
770 static tarval *read_tv(io_env_t *env)
772 static char buf[128];
773 ir_mode *tvmode = read_mode(env);
774 read_str_to(env, buf, sizeof(buf));
775 return new_tarval_from_str(buf, strlen(buf), tvmode);
778 /** Reads a type description and remembers it by its id. */
779 static void import_type(io_env_t *env)
784 long typenr = read_long(env);
785 const char *tpop = read_str(env);
786 const char *name = read_qstr_to(env, buf, sizeof(buf));
787 unsigned size = (unsigned) read_long(env);
788 unsigned align = (unsigned) read_long(env);
789 ir_type_state state = read_type_state(env);
790 ir_visibility vis = read_visibility(env);
792 ident *id = new_id_from_str(name);
794 switch(symbol(tpop, tt_tpo))
798 int ndims = (int) read_long(env);
799 long elemtypenr = read_long(env);
800 ir_type *elemtype = get_type(env, elemtypenr);
802 type = new_type_array(id, ndims, elemtype);
803 for(i = 0; i < ndims; i++)
805 long lowerbound = read_long(env);
806 long upperbound = read_long(env);
807 set_array_bounds_int(type, i, lowerbound, upperbound);
809 set_type_size_bytes(type, size);
814 type = new_type_class(id);
815 set_type_size_bytes(type, size);
820 int nparams = (int) read_long(env);
821 int nresults = (int) read_long(env);
823 type = new_type_method(id, nparams, nresults);
825 for(i = 0; i < nparams; i++)
827 long typenr = read_long(env);
828 ir_type *paramtype = get_type(env, typenr);
830 set_method_param_type(type, i, paramtype);
832 for(i = 0; i < nresults; i++)
834 long typenr = read_long(env);
835 ir_type *restype = get_type(env, typenr);
837 set_method_res_type(type, i, restype);
844 ir_mode *mode = read_mode(env);
845 ir_type *pointsto = get_type(env, read_long(env));
846 type = new_type_pointer(id, pointsto, mode);
852 ir_mode *mode = read_mode(env);
853 type = new_type_primitive(id, mode);
858 type = new_type_struct(id);
859 set_type_size_bytes(type, size);
863 type = new_type_union(id);
864 set_type_size_bytes(type, size);
868 return; // ignore unknown type
871 if(typenr != 0) // ignore global type
872 printf("Unknown type kind: \"%s\" in line %i:%i\n", tpop, env->line, env->col);
877 set_type_alignment_bytes(type, align);
878 set_type_visibility(type, vis);
880 if(state == layout_fixed)
881 ARR_APP1(ir_type *, env->fixedtypes, type);
883 set_id(env, typenr, type);
884 printf("Insert type %s %ld\n", name, typenr);
887 /** Reads an entity description and remembers it by its id. */
888 static void import_entity(io_env_t *env)
890 char buf[1024], buf2[1024];
891 long entnr = read_long(env);
892 const char *name = read_qstr_to(env, buf, sizeof(buf));
893 const char *ld_name = read_qstr_to(env, buf, sizeof(buf2));
894 long typenr = read_long(env);
895 long ownertypenr = read_long(env);
897 ir_type *type = get_type(env, typenr);
898 ir_type *ownertype = !ownertypenr ? get_glob_type() : get_type(env, ownertypenr);
899 ir_entity *entity = new_entity(ownertype, new_id_from_str(name), type);
901 if(*ld_name) set_entity_ld_ident(entity, new_id_from_str(ld_name));
902 set_entity_offset (entity, (int) read_long(env));
903 set_entity_offset_bits_remainder(entity, (unsigned char) read_long(env));
904 set_entity_allocation (entity, read_allocation(env));
905 set_entity_visibility (entity, read_visibility(env));
906 set_entity_variability(entity, read_variability(env));
907 set_entity_peculiarity(entity, read_peculiarity(env));
908 set_entity_volatility (entity, read_volatility(env));
910 if(get_entity_variability(entity) != variability_uninitialized
911 && get_entity_visibility(entity) != visibility_external_allocated)
913 if(is_compound_entity(entity))
915 int i, n = (int) read_long(env);
916 for(i = 0; i < n; i++)
918 ir_entity *member = get_entity(env, read_long(env));
919 ir_node *irn = get_node_or_dummy(env, read_long(env));
920 add_compound_ent_value(entity, irn, member);
925 ir_node *irn = get_node_or_dummy(env, read_long(env));
926 set_atomic_ent_value(entity, irn);
930 set_id(env, entnr, entity);
931 printf("Insert entity %s %ld\n", name, entnr);
934 /** Parses the whole type graph. */
935 static int parse_typegraph(io_env_t *env)
942 curfpos = ftell(env->file);
944 // parse all types first
947 kind = read_str(env);
948 if(kind[0] == '}' && !kind[1]) break;
950 if(!strcmp(kind, "type"))
957 fseek(env->file, curfpos, SEEK_SET);
960 kind = read_str(env);
961 if(kind[0] == '}' && !kind[1]) break;
963 if(!strcmp(kind, "type"))
965 else if(!strcmp(kind, "entity"))
969 printf("Type graph element not supported yet: \"%s\"\n", kind);
976 static int read_node_header(io_env_t *env, long *nodenr, long **preds, const char **nodename)
979 *nodename = read_str(env);
980 if((*nodename)[0] == '}' && !(*nodename)[1]) return -1; // end-of-graph
982 *nodenr = read_long(env);
984 ARR_RESIZE(ir_node *, *preds, 0);
987 for(numpreds = 0; !feof(env->file); numpreds++)
990 ARR_APP1(long, *preds, read_long2(env, &endptr));
991 if(*endptr == ']') break;
996 /** Parses an IRG. */
997 static int parse_graph(io_env_t *env, ir_graph *irg)
999 long *preds = NEW_ARR_F(long, 16);
1000 ir_node **prednodes = NEW_ARR_F(ir_node *, 16);
1001 int i, numpreds, ret = 1;
1003 const char *nodename;
1004 ir_node *node, *newnode;
1006 current_ir_graph = irg;
1012 numpreds = read_node_header(env, &nodenr, &preds, &nodename);
1013 if(numpreds == -1) break; // end-of-graph
1016 printf("Node %s %ld is missing predecessors!", nodename, nodenr);
1021 ARR_RESIZE(ir_node *, prednodes, numpreds);
1022 for(i = 0; i < numpreds - 1; i++)
1023 prednodes[i] = get_node_or_dummy(env, preds[i + 1]);
1025 node = get_node_or_null(env, nodenr);
1030 switch(symbol(nodename, tt_iro))
1034 ir_node *newendblock = get_node(env, preds[0]);
1035 newnode = get_irg_end(current_ir_graph);
1036 exchange(get_nodes_block(newnode), newendblock);
1037 for(i = 0; i < numpreds - 1; i++)
1038 add_irn_n(newnode, prednodes[i]);
1044 ir_node *newstartblock = get_node(env, preds[0]);
1045 newnode = get_irg_start(current_ir_graph);
1046 exchange(get_nodes_block(newnode), newstartblock);
1052 if(preds[0] != nodenr)
1054 printf("Invalid block: preds[0] != nodenr (%ld != %ld)\n",
1060 newnode = new_Block(numpreds - 1, prednodes);
1065 newnode = current_ir_graph->anchor;
1066 for(i = 0; i < numpreds - 1; i++)
1067 set_irn_n(newnode, i, prednodes[i]);
1068 set_irn_n(newnode, -1, get_node(env, preds[0]));
1073 long entnr = read_long(env);
1074 union symconst_symbol sym;
1075 sym.entity_p = get_entity(env, entnr);
1076 newnode = new_SymConst(mode_P, sym, symconst_addr_ent);
1080 #include "gen_irio_import.inl"
1091 panic("Node type not supported yet: %s in line %i:%i\n", nodename, env->line, env->col);
1095 exchange(node, newnode);
1096 /* Always update hash entry to avoid more uses of id nodes */
1097 set_id(env, nodenr, newnode);
1098 //printf("Insert %s %ld\n", nodename, nodenr);
1103 DEL_ARR_F(prednodes);
1108 /** Imports an previously exported textual representation of an (maybe partial) irp */
1109 void ir_import(const char *filename)
1111 int oldoptimize = get_optimize();
1112 firm_verification_t oldver = get_node_verification_mode();
1114 io_env_t *env = &ioenv;
1119 memset(env, 0, sizeof(*env));
1120 env->idset = new_set(id_cmp, 128);
1121 env->fixedtypes = NEW_ARR_F(ir_type *, 0);
1123 env->file = fopen(filename, "rt");
1131 do_node_verification(FIRM_VERIFICATION_OFF);
1135 const char *str = read_str(env);
1137 if(!strcmp(str, "typegraph"))
1139 if(!parse_typegraph(env)) break;
1141 else if(!strcmp(str, "irg"))
1143 ir_graph *irg = new_ir_graph(get_entity(env, read_long(env)), 0);
1144 if(!parse_graph(env, irg)) break;
1146 else if(!strcmp(str, "constirg"))
1148 if(!parse_graph(env, get_const_code_irg())) break;
1152 n = ARR_LEN(env->fixedtypes);
1153 for(i = 0; i < n; i++)
1154 set_type_state(env->fixedtypes[i], layout_fixed);
1156 DEL_ARR_F(env->fixedtypes);
1158 del_set(env->idset);
1160 irp_finalize_cons();
1162 do_node_verification(oldver);
1163 set_optimize(oldoptimize);