9 #include <libfirm/firm.h>
10 #include <libfirm/adt/obst.h>
14 #include "adt/error.h"
19 #define MAGIC_DEFAULT_PN_NUMBER (long) -314159265
21 static ir_type *ir_type_const_char;
22 static ir_type *ir_type_void;
23 static ir_type *ir_type_int;
24 static ir_type *ir_type_void_ptr;
26 static type_t *type_const_char;
27 static type_t *type_void;
28 static type_t *type_int;
30 static int next_value_number_function;
31 static ir_node *continue_label;
32 static ir_node *break_label;
33 static ir_node *current_switch_cond;
35 typedef enum declaration_type_t {
36 DECLARATION_TYPE_UNKNOWN,
37 DECLARATION_TYPE_FUNCTION,
38 DECLARATION_TYPE_GLOBAL_VARIABLE,
39 DECLARATION_TYPE_LOCAL_VARIABLE,
40 DECLARATION_TYPE_LOCAL_VARIABLE_ENTITY,
41 DECLARATION_TYPE_COMPOUND_MEMBER
44 typedef struct type2firm_env_t type2firm_env_t;
45 struct type2firm_env_t {
46 int can_cache; /* nonzero if type can safely be cached because
47 no typevariables are in the hierarchy */
50 static ir_type *_get_ir_type(type2firm_env_t *env, type_t *type);
51 static ir_type *get_ir_type(type_t *type);
53 ir_node *uninitialized_local_var(ir_graph *irg, ir_mode *mode, int pos)
57 const declaration_t *declaration = & value_numbers[pos]->declaration;
59 print_warning_prefix(declaration->source_position);
60 fprintf(stderr, "variable '%s' might be used uninitialized\n",
61 declaration->symbol->string);
63 fprintf(stderr, "Some variable might be used uninitialized\n");
64 return new_r_Unknown(irg, mode);
67 unsigned dbg_snprint(char *buf, unsigned len, const dbg_info *dbg)
69 const source_position_t *pos = (const source_position_t*) dbg;
72 return (unsigned) snprintf(buf, len, "%s:%u", pos->input_name,
76 const char *retrieve_dbg(const dbg_info *dbg, unsigned *line)
78 const source_position_t *pos = (const source_position_t*) dbg;
83 return pos->input_name;
86 void init_ast2firm(void)
88 type_const_char = make_atomic_type(ATOMIC_TYPE_CHAR, TYPE_QUALIFIER_CONST);
89 type_void = make_atomic_type(ATOMIC_TYPE_VOID, 0);
90 type_int = make_atomic_type(ATOMIC_TYPE_INT, 0);
92 ir_type_int = get_ir_type(type_int);
93 ir_type_const_char = get_ir_type(type_const_char);
94 ir_type_void = get_ir_type(type_int); /* we don't have a real void
96 ir_type_void_ptr = new_type_pointer(new_id_from_str("void_ptr"),
97 ir_type_void, mode_P_data);
99 type_void->firm_type = ir_type_void;
102 void exit_ast2firm(void)
106 static unsigned unique_id = 0;
108 static ident *unique_ident(const char *tag)
112 snprintf(buf, sizeof(buf), "%s.%d", tag, unique_id);
114 return new_id_from_str(buf);
117 static ir_mode *get_atomic_mode(const atomic_type_t* atomic_type)
119 switch(atomic_type->atype) {
120 case ATOMIC_TYPE_SCHAR:
121 case ATOMIC_TYPE_CHAR:
123 case ATOMIC_TYPE_UCHAR:
125 case ATOMIC_TYPE_SHORT:
127 case ATOMIC_TYPE_USHORT:
129 case ATOMIC_TYPE_LONG:
130 case ATOMIC_TYPE_INT:
132 case ATOMIC_TYPE_ULONG:
133 case ATOMIC_TYPE_UINT:
135 case ATOMIC_TYPE_LONGLONG:
137 case ATOMIC_TYPE_ULONGLONG:
139 case ATOMIC_TYPE_FLOAT:
141 case ATOMIC_TYPE_DOUBLE:
143 case ATOMIC_TYPE_LONG_DOUBLE:
145 case ATOMIC_TYPE_BOOL:
147 #ifdef PROVIDE_COMPLEX
148 case ATOMIC_TYPE_FLOAT_COMPLEX:
149 case ATOMIC_TYPE_DOUBLE_COMPLEX:
150 case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
151 panic("complex lowering not implemented yet");
153 case ATOMIC_TYPE_FLOAT_IMAGINARY:
154 case ATOMIC_TYPE_DOUBLE_IMAGINARY:
155 case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
156 panic("imaginary lowering not implemented yet");
159 case ATOMIC_TYPE_VOID:
160 /* firm has no real void... */
162 case ATOMIC_TYPE_INVALID:
165 panic("Encountered unknown atomic type");
169 static unsigned get_type_size(type_t *type);
171 static unsigned get_atomic_type_size(const atomic_type_t *type)
173 switch(type->atype) {
174 case ATOMIC_TYPE_CHAR:
175 case ATOMIC_TYPE_SCHAR:
176 case ATOMIC_TYPE_UCHAR:
179 case ATOMIC_TYPE_SHORT:
180 case ATOMIC_TYPE_USHORT:
183 case ATOMIC_TYPE_BOOL:
184 case ATOMIC_TYPE_INT:
185 case ATOMIC_TYPE_UINT:
186 case ATOMIC_TYPE_LONG:
187 case ATOMIC_TYPE_ULONG:
188 case ATOMIC_TYPE_FLOAT:
191 case ATOMIC_TYPE_LONGLONG:
192 case ATOMIC_TYPE_ULONGLONG:
193 case ATOMIC_TYPE_DOUBLE:
196 case ATOMIC_TYPE_LONG_DOUBLE:
199 case ATOMIC_TYPE_VOID:
202 case ATOMIC_TYPE_INVALID:
205 panic("Trying to determine size of invalid atomic type");
208 static unsigned get_compound_type_size(compound_type_t *type)
210 ir_type *irtype = get_ir_type(&type->type);
211 return get_type_size_bytes(irtype);
214 static unsigned get_array_type_size(array_type_t *type)
216 ir_type *irtype = get_ir_type(&type->type);
217 return get_type_size_bytes(irtype);
220 static unsigned get_type_size(type_t *type)
222 type = skip_typeref(type);
226 return get_atomic_type_size((const atomic_type_t*) type);
228 return get_mode_size_bytes(mode_Is);
229 case TYPE_COMPOUND_UNION:
230 case TYPE_COMPOUND_STRUCT:
231 return get_compound_type_size((compound_type_t*) type);
233 /* just a pointer to the function */
234 return get_mode_size_bytes(mode_P_code);
236 return get_mode_size_bytes(mode_P_data);
238 return get_array_type_size((array_type_t*) type);
245 panic("Trying to determine size of invalid type");
248 static unsigned count_parameters(const function_type_t *function_type)
252 function_parameter_t *parameter = function_type->parameters;
253 for ( ; parameter != NULL; parameter = parameter->next) {
263 static ir_type *create_atomic_type(type2firm_env_t *env,
264 const atomic_type_t *type)
267 ir_mode *mode = get_atomic_mode(type);
268 ident *id = get_mode_ident(mode);
269 ir_type *irtype = new_type_primitive(id, mode);
274 static ir_type *create_method_type(type2firm_env_t *env,
275 const function_type_t *function_type)
277 type_t *result_type = function_type->result_type;
279 ident *id = unique_ident("functiontype");
280 int n_parameters = count_parameters(function_type);
281 int n_results = result_type == type_void ? 0 : 1;
282 ir_type *irtype = new_type_method(id, n_parameters, n_results);
284 if(result_type != type_void) {
285 ir_type *restype = _get_ir_type(env, result_type);
286 set_method_res_type(irtype, 0, restype);
289 function_parameter_t *parameter = function_type->parameters;
291 for( ; parameter != NULL; parameter = parameter->next) {
292 ir_type *p_irtype = _get_ir_type(env, parameter->type);
293 set_method_param_type(irtype, n, p_irtype);
297 if(function_type->variadic) {
298 set_method_variadicity(irtype, variadicity_variadic);
304 static ir_type *create_pointer_type(type2firm_env_t *env, pointer_type_t *type)
306 type_t *points_to = type->points_to;
307 ir_type *ir_points_to;
308 /* Avoid endless recursion if the points_to type contains this poiner type
309 * again (might be a struct). We therefore first create a void* pointer
310 * and then set the real points_to type
312 ir_type *ir_type = new_type_pointer(unique_ident("pointer"),
313 ir_type_void, mode_P_data);
314 type->type.firm_type = ir_type;
316 ir_points_to = _get_ir_type(env, points_to);
317 set_pointer_points_to_type(ir_type, ir_points_to);
322 static ir_type *create_array_type(type2firm_env_t *env, array_type_t *type)
324 type_t *element_type = type->element_type;
325 ir_type *ir_element_type = _get_ir_type(env, element_type);
329 panic("TODO arraytpye size not implemented yet");
331 ir_type *ir_type = new_type_array(unique_ident("array"), 1, ir_element_type);
332 set_array_bounds_int(ir_type, 0, 0, n_elements);
334 size_t elemsize = get_type_size_bytes(ir_element_type);
335 int align = get_type_alignment_bytes(ir_element_type);
336 if(elemsize % align > 0) {
337 elemsize += align - (elemsize % align);
339 set_type_size_bytes(ir_type, n_elements * elemsize);
340 set_type_alignment_bytes(ir_type, align);
341 set_type_state(ir_type, layout_fixed);
346 #define INVALID_TYPE ((ir_type_ptr)-1)
348 static ir_type *create_struct_type(type2firm_env_t *env, compound_type_t *type)
350 symbol_t *symbol = type->declaration->symbol;
353 id = unique_ident(symbol->string);
355 id = unique_ident("__anonymous_struct");
357 ir_type *ir_type = new_type_struct(id);
359 type->type.firm_type = ir_type;
363 declaration_t *entry = type->declaration->context.declarations;
364 for( ; entry != NULL; entry = entry->next) {
365 if(entry->namespace != NAMESPACE_NORMAL)
368 ident *ident = new_id_from_str(entry->symbol->string);
369 ir_type_ptr entry_ir_type = _get_ir_type(env, entry->type);
371 int entry_size = get_type_size_bytes(entry_ir_type);
372 int entry_alignment = get_type_alignment_bytes(entry_ir_type);
373 int misalign = offset % entry_alignment;
376 ir_entity *entity = new_entity(ir_type, ident, entry_ir_type);
377 set_entity_offset(entity, offset);
378 add_struct_member(ir_type, entity);
379 entry->declaration_type = DECLARATION_TYPE_COMPOUND_MEMBER;
380 entry->v.entity = entity;
382 offset += entry_size;
383 if(entry_alignment > align_all) {
384 if(entry_alignment % align_all != 0) {
385 panic("Uneven alignments not supported yet");
387 align_all = entry_alignment;
391 int misalign = offset % align_all;
393 set_type_alignment_bytes(ir_type, align_all);
394 set_type_size_bytes(ir_type, offset);
395 set_type_state(ir_type, layout_fixed);
400 static ir_type *create_union_type(type2firm_env_t *env, compound_type_t *type)
402 declaration_t *declaration = type->declaration;
403 symbol_t *symbol = declaration->symbol;
406 id = unique_ident(symbol->string);
408 id = unique_ident("__anonymous_union");
410 ir_type *ir_type = new_type_union(id);
412 type->type.firm_type = ir_type;
416 declaration_t *entry = declaration->context.declarations;
417 for( ; entry != NULL; entry = entry->next) {
418 if(entry->namespace != NAMESPACE_NORMAL)
421 ident *ident = new_id_from_str(entry->symbol->string);
422 ir_type_ptr entry_ir_type = _get_ir_type(env, entry->type);
424 int entry_size = get_type_size_bytes(entry_ir_type);
425 int entry_alignment = get_type_alignment_bytes(entry_ir_type);
427 ir_entity *entity = new_entity(ir_type, ident, entry_ir_type);
428 add_union_member(ir_type, entity);
429 set_entity_offset(entity, 0);
430 entry->declaration_type = DECLARATION_TYPE_COMPOUND_MEMBER;
431 entry->v.entity = entity;
433 if(entry_size > size) {
436 if(entry_alignment > align_all) {
437 if(entry_alignment % align_all != 0) {
438 panic("Uneven alignments not supported yet");
440 align_all = entry_alignment;
444 set_type_alignment_bytes(ir_type, align_all);
445 set_type_size_bytes(ir_type, size);
446 set_type_state(ir_type, layout_fixed);
451 static ir_type *_get_ir_type(type2firm_env_t *env, type_t *type)
453 assert(type != NULL);
455 type = skip_typeref(type);
457 if(type->firm_type != NULL) {
458 assert(type->firm_type != INVALID_TYPE);
459 return type->firm_type;
462 ir_type *firm_type = NULL;
465 firm_type = create_atomic_type(env, (atomic_type_t*) type);
468 firm_type = create_method_type(env, (function_type_t*) type);
471 firm_type = create_pointer_type(env, (pointer_type_t*) type);
474 firm_type = create_array_type(env, (array_type_t*) type);
476 case TYPE_COMPOUND_STRUCT:
477 firm_type = create_struct_type(env, (compound_type_t*) type);
479 case TYPE_COMPOUND_UNION:
480 firm_type = create_union_type(env, (compound_type_t*) type);
483 firm_type = ir_type_int;
491 if(firm_type == NULL)
492 panic("unknown type found");
495 type->firm_type = firm_type;
501 static ir_type *get_ir_type(type_t *type)
506 return _get_ir_type(&env, type);
509 static inline ir_mode *get_ir_mode(type_t *type)
511 ir_type *irtype = get_ir_type(type);
512 ir_mode *mode = get_type_mode(irtype);
513 assert(mode != NULL);
517 static ir_entity* get_function_entity(declaration_t *declaration)
519 if(declaration->declaration_type == DECLARATION_TYPE_FUNCTION)
520 return declaration->v.entity;
521 assert(declaration->declaration_type == DECLARATION_TYPE_UNKNOWN);
523 symbol_t *symbol = declaration->symbol;
524 ident *id = new_id_from_str(symbol->string);
526 ir_type *global_type = get_glob_type();
527 ir_type *ir_type_method = get_ir_type(declaration->type);
528 assert(is_Method_type(ir_type_method));
530 type_t *type = declaration->type;
531 ir_entity *entity = new_entity(global_type, id, ir_type_method);
532 set_entity_ld_ident(entity, id);
533 if(declaration->storage_class & STORAGE_CLASS_STATIC
534 || type->qualifiers & TYPE_QUALIFIER_INLINE) {
535 set_entity_visibility(entity, visibility_local);
536 } else if(declaration->init.statement != NULL) {
537 set_entity_visibility(entity, visibility_external_visible);
539 set_entity_visibility(entity, visibility_external_allocated);
542 declaration->declaration_type = DECLARATION_TYPE_FUNCTION;
543 declaration->v.entity = entity;
550 static ir_node *expression_to_firm(const expression_t *expression);
551 static ir_node *_expression_to_firm(const expression_t *expression);
553 static dbg_info *get_dbg_info(const source_position_t *pos)
555 return (dbg_info*) pos;
558 static ir_node *const_to_firm(const const_t *cnst)
560 dbg_info *dbgi = get_dbg_info(&cnst->expression.source_position);
561 ir_mode *mode = get_ir_mode(cnst->expression.datatype);
564 if(mode_is_float(mode)) {
565 tv = new_tarval_from_double(cnst->v.float_value, mode);
567 tv = new_tarval_from_long(cnst->v.int_value, mode);
570 return new_d_Const(dbgi, mode, tv);
573 static ir_node *create_symconst(dbg_info *dbgi, ir_entity *entity)
575 assert(entity != NULL);
576 union symconst_symbol sym;
577 sym.entity_p = entity;
578 return new_d_SymConst(dbgi, sym, symconst_addr_ent);
581 static ir_node *string_literal_to_firm(const string_literal_t* literal)
583 ir_type *global_type = get_glob_type();
584 ir_type *type = new_type_array(unique_ident("strtype"), 1,
587 ident *id = unique_ident("Lstr");
588 ir_entity *entity = new_entity(global_type, id, type);
589 set_entity_ld_ident(entity, id);
590 set_entity_variability(entity, variability_constant);
592 ir_type *elem_type = ir_type_const_char;
593 ir_mode *mode = get_type_mode(elem_type);
595 const char *string = literal->value;
596 size_t slen = strlen(string) + 1;
598 set_array_lower_bound_int(type, 0, 0);
599 set_array_upper_bound_int(type, 0, slen);
600 set_type_size_bytes(type, slen);
601 set_type_state(type, layout_fixed);
603 tarval **tvs = xmalloc(slen * sizeof(tvs[0]));
604 for(size_t i = 0; i < slen; ++i) {
605 tvs[i] = new_tarval_from_long(string[i], mode);
608 set_array_entity_values(entity, tvs, slen);
611 dbg_info *dbgi = get_dbg_info(&literal->expression.source_position);
613 return create_symconst(dbgi, entity);
616 static ir_node *reference_expression_to_firm(const reference_expression_t *ref)
618 dbg_info *dbgi = get_dbg_info(&ref->expression.source_position);
619 declaration_t *declaration = ref->declaration;
620 type_t *type = declaration->type;
621 ir_mode *mode = get_ir_mode(type);
623 switch((declaration_type_t) declaration->declaration_type) {
624 case DECLARATION_TYPE_UNKNOWN:
626 case DECLARATION_TYPE_LOCAL_VARIABLE:
627 return get_value(declaration->v.value_number, mode);
628 case DECLARATION_TYPE_FUNCTION: {
629 return create_symconst(dbgi, declaration->v.entity);
631 case DECLARATION_TYPE_LOCAL_VARIABLE_ENTITY:
632 case DECLARATION_TYPE_GLOBAL_VARIABLE:
633 case DECLARATION_TYPE_COMPOUND_MEMBER:
634 panic("not implemented reference type");
637 panic("reference to declaration with unknown type found");
640 static ir_node *call_expression_to_firm(const call_expression_t *call)
642 assert(get_cur_block() != NULL);
644 expression_t *function = call->function;
645 ir_node *callee = expression_to_firm(function);
647 assert(function->datatype->type == TYPE_FUNCTION);
648 function_type_t *function_type = (function_type_t*) function->datatype;
650 int n_parameters = 0;
651 call_argument_t *argument = call->arguments;
652 for( ; argument != NULL; argument = argument->next) {
656 ir_type *ir_method_type = get_ir_type((type_t*) function_type);
657 ir_type *new_method_type = NULL;
658 if(function_type->variadic) {
659 /* we need to construct a new method type matching the call
661 int n_res = get_method_n_ress(ir_method_type);
662 new_method_type = new_type_method(unique_ident("calltype"),
663 n_parameters, n_res);
664 set_method_calling_convention(new_method_type,
665 get_method_calling_convention(ir_method_type));
666 set_method_additional_properties(new_method_type,
667 get_method_additional_properties(ir_method_type));
669 for(int i = 0; i < n_res; ++i) {
670 set_method_res_type(new_method_type, i,
671 get_method_res_type(ir_method_type, i));
674 ir_node *in[n_parameters];
676 argument = call->arguments;
678 for( ; argument != NULL; argument = argument->next) {
679 expression_t *expression = argument->expression;
680 ir_node *arg_node = expression_to_firm(expression);
683 if(new_method_type != NULL) {
684 ir_type *irtype = get_ir_type(expression->datatype);
685 set_method_param_type(new_method_type, n, irtype);
690 assert(n == n_parameters);
692 if(new_method_type != NULL)
693 ir_method_type = new_method_type;
695 dbg_info *dbgi = get_dbg_info(&call->expression.source_position);
696 ir_node *store = get_store();
697 ir_node *node = new_d_Call(dbgi, store, callee, n_parameters, in,
699 ir_node *mem = new_d_Proj(dbgi, node, mode_M, pn_Call_M_regular);
702 type_t *result_type = function_type->result_type;
703 ir_node *result = NULL;
704 if(result_type != type_void) {
705 ir_mode *mode = get_ir_mode(result_type);
706 ir_node *resproj = new_d_Proj(dbgi, node, mode_T, pn_Call_T_result);
707 result = new_d_Proj(dbgi, resproj, mode, 0);
713 static ir_node *load_from_expression_addr(type_t *type, ir_node *addr,
716 ir_mode *mode = get_ir_mode(type);
717 ir_node *memory = get_store();
718 ir_node *load = new_d_Load(dbgi, memory, addr, mode);
719 ir_node *load_mem = new_d_Proj(dbgi, load, mode_M, pn_Load_M);
720 ir_node *load_res = new_d_Proj(dbgi, load, mode, pn_Load_res);
726 static ir_node *expression_to_addr(const expression_t *expression);
728 static void set_value_for_expression(const expression_t *expression,
731 if(expression->type == EXPR_REFERENCE) {
732 reference_expression_t *ref = (reference_expression_t*) expression;
734 declaration_t *declaration = ref->declaration;
735 assert(declaration->declaration_type != DECLARATION_TYPE_UNKNOWN);
736 if(declaration->declaration_type == DECLARATION_TYPE_LOCAL_VARIABLE) {
737 set_value(declaration->v.value_number, value);
742 dbg_info *dbgi = get_dbg_info(&expression->source_position);
743 ir_node *addr = expression_to_addr(expression);
744 assert(get_irn_mode(value) == get_ir_mode(expression->datatype));
745 ir_node *memory = get_store();
746 ir_node *store = new_d_Store(dbgi, memory, addr, value);
747 ir_node *store_mem = new_d_Proj(dbgi, store, mode_M, pn_Store_M);
748 set_store(store_mem);
751 static ir_node *create_conv(dbg_info *dbgi, ir_node *value, ir_mode *dest_mode)
753 ir_mode *value_mode = get_irn_mode(value);
755 if(value_mode == dest_mode)
758 if(dest_mode == mode_b) {
759 ir_node *zero = new_Const(value_mode, get_mode_null(value_mode));
760 ir_node *cmp = new_d_Cmp(dbgi, value, zero);
761 ir_node *proj = new_d_Proj(dbgi, cmp, mode_b, pn_Cmp_Lg);
765 return new_d_Conv(dbgi, value, dest_mode);
768 static ir_node *unary_expression_to_firm(const unary_expression_t *expression)
770 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
771 type_t *type = expression->expression.datatype;
772 ir_mode *mode = get_ir_mode(type);
774 if(expression->type == UNEXPR_TAKE_ADDRESS)
775 return expression_to_addr(expression->value);
777 const expression_t *value = expression->value;
778 ir_node *value_node = expression_to_firm(value);
780 switch(expression->type) {
782 return new_d_Minus(dbgi, value_node, mode);
785 case UNEXPR_BITWISE_NEGATE:
786 return new_d_Not(dbgi, value_node, mode);
788 if(get_irn_mode(value_node) != mode_b) {
789 value_node = create_conv(dbgi, value_node, mode_b);
791 value_node = new_d_Not(dbgi, value_node, mode_b);
793 value_node = create_conv(dbgi, value_node, mode);
796 case UNEXPR_DEREFERENCE:
797 return load_from_expression_addr(type, value_node, dbgi);
798 case UNEXPR_POSTFIX_INCREMENT: {
799 ir_node *one = new_Const(mode, get_mode_one(mode));
800 ir_node *new_value = new_d_Add(dbgi, value_node, one, mode);
801 set_value_for_expression(value, new_value);
804 case UNEXPR_POSTFIX_DECREMENT: {
805 ir_node *one = new_Const(mode, get_mode_one(mode));
806 ir_node *new_value = new_d_Sub(dbgi, value_node, one, mode);
807 set_value_for_expression(value, new_value);
810 case UNEXPR_PREFIX_INCREMENT: {
811 ir_node *one = new_Const(mode, get_mode_one(mode));
812 ir_node *new_value = new_d_Add(dbgi, value_node, one, mode);
813 set_value_for_expression(value, new_value);
816 case UNEXPR_PREFIX_DECREMENT: {
817 ir_node *one = new_Const(mode, get_mode_one(mode));
818 ir_node *new_value = new_d_Sub(dbgi, value_node, one, mode);
819 set_value_for_expression(value, new_value);
823 return create_conv(dbgi, value_node, mode);
825 case UNEXPR_TAKE_ADDRESS:
829 panic("invalid UNEXPR type found");
832 static long get_pnc(binary_expression_type_t type)
835 case BINEXPR_EQUAL: return pn_Cmp_Eq;
836 case BINEXPR_NOTEQUAL: return pn_Cmp_Lg;
837 case BINEXPR_LESS: return pn_Cmp_Lt;
838 case BINEXPR_LESSEQUAL: return pn_Cmp_Le;
839 case BINEXPR_GREATER: return pn_Cmp_Gt;
840 case BINEXPR_GREATEREQUAL: return pn_Cmp_Ge;
844 panic("trying to get pn_Cmp from non-comparison binexpr type");
847 static ir_node *create_lazy_op(const binary_expression_t *expression)
849 bool is_or = (expression->type == BINEXPR_LOGICAL_OR);
850 assert(is_or || expression->type == BINEXPR_LOGICAL_AND);
852 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
853 ir_node *val1 = expression_to_firm(expression->left);
854 val1 = create_conv(dbgi, val1, mode_b);
856 ir_node *cond = new_d_Cond(dbgi, val1);
857 ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
858 ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
860 ir_node *fallthrough_block = new_immBlock();
863 ir_node *calc_val2_block = new_immBlock();
865 add_immBlock_pred(calc_val2_block, false_proj);
867 add_immBlock_pred(calc_val2_block, true_proj);
870 mature_immBlock(calc_val2_block);
872 ir_node *val2 = expression_to_firm(expression->right);
873 val2 = create_conv(dbgi, val2, mode_b);
874 if(get_cur_block() != NULL) {
875 ir_node *jmp = new_d_Jmp(dbgi);
876 add_immBlock_pred(fallthrough_block, jmp);
882 constb = new_d_Const(dbgi, mode_b, get_tarval_b_true());
883 add_immBlock_pred(fallthrough_block, true_proj);
885 constb = new_d_Const(dbgi, mode_b, get_tarval_b_false());
886 add_immBlock_pred(fallthrough_block, false_proj);
888 mature_immBlock(fallthrough_block);
890 set_cur_block(fallthrough_block);
892 ir_node *in[2] = { val2, constb };
893 ir_node *val = new_d_Phi(dbgi, 2, in, mode_b);
898 typedef ir_node * (*create_arithmetic_func)(dbg_info *dbgi, ir_node *left,
899 ir_node *right, ir_mode *mode);
901 static ir_node *create_arithmetic_binop(const binary_expression_t *expression,
902 create_arithmetic_func func)
904 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
905 ir_node *left = expression_to_firm(expression->left);
906 ir_node *right = expression_to_firm(expression->right);
907 type_t *type = expression->expression.datatype;
908 ir_mode *mode = get_ir_mode(type);
909 /* TODO FIXME Hack for now */
910 right = create_conv(dbgi, right, get_irn_mode(left));
912 ir_node *res = func(dbgi, left, right, mode);
917 static ir_node *binary_expression_to_firm(const binary_expression_t *expression)
919 binary_expression_type_t type = expression->type;
922 case BINEXPR_NOTEQUAL:
924 case BINEXPR_LESSEQUAL:
925 case BINEXPR_GREATER:
926 case BINEXPR_GREATEREQUAL: {
927 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
928 ir_node *left = expression_to_firm(expression->left);
929 ir_node *right = expression_to_firm(expression->right);
930 ir_node *cmp = new_d_Cmp(dbgi, left, right);
931 long pnc = get_pnc(type);
932 ir_node *proj = new_d_Proj(dbgi, cmp, mode_b, pnc);
935 case BINEXPR_ASSIGN: {
936 ir_node *right = expression_to_firm(expression->right);
937 set_value_for_expression(expression->left, right);
941 return create_arithmetic_binop(expression, new_d_Add);
943 return create_arithmetic_binop(expression, new_d_Sub);
945 return create_arithmetic_binop(expression, new_d_Mul);
946 case BINEXPR_BITWISE_AND:
947 return create_arithmetic_binop(expression, new_d_And);
948 case BINEXPR_BITWISE_OR:
949 return create_arithmetic_binop(expression, new_d_Or);
950 case BINEXPR_BITWISE_XOR:
951 return create_arithmetic_binop(expression, new_d_Eor);
952 case BINEXPR_SHIFTLEFT:
953 return create_arithmetic_binop(expression, new_d_Shl);
954 case BINEXPR_SHIFTRIGHT:
955 return create_arithmetic_binop(expression, new_d_Shr);
956 case BINEXPR_LOGICAL_AND:
957 case BINEXPR_LOGICAL_OR:
958 return create_lazy_op(expression);
960 panic("TODO binexpr type");
964 static ir_node *array_access_addr(const array_access_expression_t *expression)
966 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
968 ir_node *base_addr = expression_to_firm(expression->array_ref);
969 ir_node *offset = expression_to_firm(expression->index);
970 offset = create_conv(dbgi, offset, mode_Iu);
972 unsigned elem_size = get_type_size(expression->expression.datatype);
973 ir_node *elem_size_const = new_Const_long(mode_Iu, elem_size);
974 ir_node *real_offset = new_d_Mul(dbgi, offset, elem_size_const,
976 ir_node *result = new_d_Add(dbgi, base_addr, real_offset, mode_P);
981 static ir_node *array_access_to_firm(
982 const array_access_expression_t *expression)
985 dbg_info *dbgi = get_dbg_info(&expression->expression.source_position);
986 ir_node *addr = array_access_addr(expression);
987 type_t *type = expression->expression.datatype;
989 return load_from_expression_addr(type, addr, dbgi);
992 static ir_node *sizeof_to_firm(const sizeof_expression_t *expression)
994 type_t *type = expression->type;
996 type = expression->size_expression->datatype;
997 assert(type != NULL);
1000 ir_mode *mode = get_ir_mode(expression->expression.datatype);
1001 unsigned size = get_type_size(type);
1002 ir_node *size_node = new_Const_long(mode, size);
1007 static ir_node *expression_to_addr(const expression_t *expression)
1009 switch(expression->type) {
1010 case EXPR_ARRAY_ACCESS:
1011 return array_access_addr((const array_access_expression_t*) expression);
1015 panic("trying to get address of non-lvalue");
1018 static ir_node *_expression_to_firm(const expression_t *expression)
1020 switch(expression->type) {
1022 return const_to_firm((const const_t*) expression);
1023 case EXPR_STRING_LITERAL:
1024 return string_literal_to_firm((const string_literal_t*) expression);
1025 case EXPR_REFERENCE:
1026 return reference_expression_to_firm(
1027 (const reference_expression_t*) expression);
1029 return call_expression_to_firm((const call_expression_t*) expression);
1031 return unary_expression_to_firm((const unary_expression_t*) expression);
1033 return binary_expression_to_firm(
1034 (const binary_expression_t*) expression);
1035 case EXPR_ARRAY_ACCESS:
1036 return array_access_to_firm(
1037 (const array_access_expression_t*) expression);
1039 return sizeof_to_firm((const sizeof_expression_t*) expression);
1043 panic("unsupported expression found");
1046 static ir_node *expression_to_firm(const expression_t *expression)
1048 ir_node *res = _expression_to_firm(expression);
1050 if(expression->datatype == type_void)
1053 ir_mode *mode = get_ir_mode(expression->datatype);
1054 res = create_conv(NULL, res, mode);
1059 static void statement_to_firm(statement_t *statement);
1061 static void return_statement_to_firm(return_statement_t *statement)
1063 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1066 if(statement->return_value != NULL) {
1067 ir_node *retval = expression_to_firm(statement->return_value);
1071 ret = new_d_Return(dbgi, get_store(), 1, in);
1073 ret = new_d_Return(dbgi, get_store(), 0, NULL);
1075 ir_node *end_block = get_irg_end_block(current_ir_graph);
1076 add_immBlock_pred(end_block, ret);
1078 set_cur_block(NULL);
1081 static void compound_statement_to_firm(compound_statement_t *compound)
1083 statement_t *statement = compound->statements;
1084 for( ; statement != NULL; statement = statement->next) {
1085 //context2firm(&statement->context);
1086 statement_to_firm(statement);
1090 static void expression_statement_to_firm(expression_statement_t *statement)
1092 expression_to_firm(statement->expression);
1095 static void if_statement_to_firm(if_statement_t *statement)
1097 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1098 ir_node *condition = _expression_to_firm(statement->condition);
1099 assert(condition != NULL);
1101 /* make sure we have a mode_b condition */
1102 condition = create_conv(dbgi, condition, mode_b);
1104 ir_node *cond = new_d_Cond(dbgi, condition);
1105 ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
1106 ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
1108 ir_node *fallthrough_block = new_immBlock();
1110 /* the true (blocks) */
1111 ir_node *true_block = new_immBlock();
1112 add_immBlock_pred(true_block, true_proj);
1113 mature_immBlock(true_block);
1115 statement_to_firm(statement->true_statement);
1116 if(get_cur_block() != NULL) {
1117 ir_node *jmp = new_Jmp();
1118 add_immBlock_pred(fallthrough_block, jmp);
1121 /* the false (blocks) */
1122 if(statement->false_statement != NULL) {
1123 ir_node *false_block = new_immBlock();
1124 add_immBlock_pred(false_block, false_proj);
1125 mature_immBlock(false_block);
1127 statement_to_firm(statement->false_statement);
1128 if(get_cur_block() != NULL) {
1129 ir_node *jmp = new_Jmp();
1130 add_immBlock_pred(fallthrough_block, jmp);
1133 add_immBlock_pred(fallthrough_block, false_proj);
1135 mature_immBlock(fallthrough_block);
1137 set_cur_block(fallthrough_block);
1140 static void while_statement_to_firm(while_statement_t *statement)
1142 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1144 ir_node *jmp = NULL;
1145 if(get_cur_block() != NULL) {
1149 /* create the header block */
1150 ir_node *header_block = new_immBlock();
1152 add_immBlock_pred(header_block, jmp);
1155 /* create the condition */
1156 ir_node *condition = _expression_to_firm(statement->condition);
1157 condition = create_conv(dbgi, condition, mode_b);
1159 ir_node *cond = new_d_Cond(dbgi, condition);
1160 ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
1161 ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
1163 /* the false block */
1164 ir_node *false_block = new_immBlock();
1165 add_immBlock_pred(false_block, false_proj);
1168 ir_node *body_block = new_immBlock();
1169 add_immBlock_pred(body_block, true_proj);
1170 mature_immBlock(body_block);
1172 ir_node *old_continue_label = continue_label;
1173 ir_node *old_break_label = break_label;
1174 continue_label = header_block;
1175 break_label = false_block;
1177 statement_to_firm(statement->body);
1179 assert(continue_label == header_block);
1180 assert(break_label == false_block);
1181 continue_label = old_continue_label;
1182 break_label = old_break_label;
1184 if(get_cur_block() != NULL) {
1185 ir_node *jmp = new_Jmp();
1186 add_immBlock_pred(header_block, jmp);
1189 mature_immBlock(header_block);
1190 mature_immBlock(false_block);
1192 set_cur_block(false_block);
1195 static void do_while_statement_to_firm(do_while_statement_t *statement)
1197 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1199 ir_node *jmp = NULL;
1200 if(get_cur_block() != NULL) {
1204 /* create the header block */
1205 ir_node *header_block = new_immBlock();
1207 /* the false block */
1208 ir_node *false_block = new_immBlock();
1211 ir_node *body_block = new_immBlock();
1213 add_immBlock_pred(body_block, jmp);
1216 ir_node *old_continue_label = continue_label;
1217 ir_node *old_break_label = break_label;
1218 continue_label = header_block;
1219 break_label = false_block;
1221 statement_to_firm(statement->body);
1223 assert(continue_label == header_block);
1224 assert(break_label == false_block);
1225 continue_label = old_continue_label;
1226 break_label = old_break_label;
1228 if(get_cur_block() == NULL) {
1229 mature_immBlock(header_block);
1230 mature_immBlock(body_block);
1234 ir_node *body_jmp = new_Jmp();
1235 add_immBlock_pred(header_block, body_jmp);
1236 mature_immBlock(header_block);
1238 /* create the condition */
1239 ir_node *condition = _expression_to_firm(statement->condition);
1240 condition = create_conv(dbgi, condition, mode_b);
1242 ir_node *cond = new_d_Cond(dbgi, condition);
1243 ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
1244 ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
1246 add_immBlock_pred(body_block, true_proj);
1247 mature_immBlock(body_block);
1249 add_immBlock_pred(false_block, false_proj);
1250 mature_immBlock(false_block);
1252 set_cur_block(false_block);
1255 static void for_statement_to_firm(for_statement_t *statement)
1257 dbg_info *const dbgi = get_dbg_info(&statement->statement.source_position);
1259 ir_node *jmp = NULL;
1260 if (get_cur_block() != NULL) {
1261 expression_to_firm(statement->initialisation);
1265 /* create the step block */
1266 ir_node *const step_block = new_immBlock();
1267 expression_to_firm(statement->step);
1268 ir_node *const step_jmp = new_Jmp();
1270 /* create the header block */
1271 ir_node *const header_block = new_immBlock();
1273 add_immBlock_pred(header_block, jmp);
1275 add_immBlock_pred(header_block, step_jmp);
1277 /* create the condition */
1278 ir_node *const cond_expr = _expression_to_firm(statement->condition);
1279 ir_node *const condition = create_conv(dbgi, cond_expr, mode_b);
1281 ir_node *const cond = new_d_Cond(dbgi, condition);
1282 ir_node *const true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
1283 ir_node *const false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
1285 /* the false block */
1286 ir_node *const false_block = new_immBlock();
1287 add_immBlock_pred(false_block, false_proj);
1290 ir_node *const body_block = new_immBlock();
1291 add_immBlock_pred(body_block, true_proj);
1292 mature_immBlock(body_block);
1294 ir_node *const old_continue_label = continue_label;
1295 ir_node *const old_break_label = break_label;
1296 continue_label = step_block;
1297 break_label = false_block;
1299 statement_to_firm(statement->body);
1301 assert(continue_label == step_block);
1302 assert(break_label == false_block);
1303 continue_label = old_continue_label;
1304 break_label = old_break_label;
1306 if (get_cur_block() != NULL) {
1307 ir_node *const jmp = new_Jmp();
1308 add_immBlock_pred(step_block, jmp);
1311 mature_immBlock(step_block);
1312 mature_immBlock(header_block);
1313 mature_immBlock(false_block);
1315 set_cur_block(false_block);
1318 static void create_declaration_entity(declaration_t *declaration,
1319 declaration_type_t declaration_type,
1320 ir_type *parent_type)
1322 ident *id = new_id_from_str(declaration->symbol->string);
1323 ir_type *irtype = get_ir_type(declaration->type);
1324 ir_entity *entity = new_entity(parent_type, id, irtype);
1325 set_entity_ld_ident(entity, id);
1327 declaration->declaration_type = declaration_type;
1328 declaration->v.entity = entity;
1329 set_entity_variability(entity, variability_uninitialized);
1330 /* TODO: visibility? */
1333 static void create_initializer(declaration_t *declaration)
1335 initializer_t *initializer = declaration->init.initializer;
1336 if(initializer == NULL)
1339 if(initializer->type == INITIALIZER_VALUE) {
1340 assert(initializer->designator == NULL);
1341 assert(initializer->next == NULL);
1342 ir_node *init_node = expression_to_firm(initializer->v.value);
1344 if(declaration->declaration_type == DECLARATION_TYPE_LOCAL_VARIABLE) {
1345 set_value(declaration->v.value_number, init_node);
1347 panic("initializer not completely implemented yet");
1350 assert(initializer->type == INITIALIZER_LIST);
1351 panic("list initializer not supported yet");
1355 static void create_local_variable(declaration_t *declaration)
1357 bool needs_entity = declaration->address_taken;
1359 assert(declaration->declaration_type == DECLARATION_TYPE_UNKNOWN);
1362 ir_type *frame_type = get_irg_frame_type(current_ir_graph);
1363 create_declaration_entity(declaration,
1364 DECLARATION_TYPE_LOCAL_VARIABLE_ENTITY,
1367 declaration->declaration_type = DECLARATION_TYPE_LOCAL_VARIABLE;
1368 declaration->v.value_number = next_value_number_function;
1369 ++next_value_number_function;
1372 create_initializer(declaration);
1375 static void declaration_statement_to_firm(declaration_statement_t *statement)
1377 declaration_t *declaration = statement->declarations_begin;
1378 declaration_t *end = statement->declarations_end->next;
1379 for( ; declaration != end; declaration = declaration->next) {
1380 type_t *type = declaration->type;
1382 switch(declaration->storage_class) {
1383 case STORAGE_CLASS_TYPEDEF:
1385 case STORAGE_CLASS_STATIC:
1386 panic("static local vars not implemented yet");
1387 case STORAGE_CLASS_ENUM_ENTRY:
1388 panic("enum entry declaration in local block found");
1389 case STORAGE_CLASS_EXTERN:
1390 panic("extern declaration in local block found");
1391 case STORAGE_CLASS_NONE:
1392 case STORAGE_CLASS_AUTO:
1393 case STORAGE_CLASS_REGISTER:
1394 if(type->type == TYPE_FUNCTION) {
1395 panic("nested functions not supported yet");
1397 create_local_variable(declaration);
1401 panic("invalid storage class found");
1405 static void create_jump_statement(const statement_t *statement,
1406 ir_node *target_block)
1408 dbg_info *dbgi = get_dbg_info(&statement->source_position);
1409 ir_node *jump = new_d_Jmp(dbgi);
1410 add_immBlock_pred(target_block, jump);
1412 set_cur_block(NULL);
1415 static void switch_statement_to_firm(const switch_statement_t *statement)
1417 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1419 ir_node *expression = expression_to_firm(statement->expression);
1420 ir_node *cond = new_d_Cond(dbgi, expression);
1421 ir_node *break_block = new_immBlock();
1423 set_cur_block(NULL);
1425 ir_node *old_switch_cond = current_switch_cond;
1426 ir_node *old_break_label = break_label;
1427 current_switch_cond = cond;
1428 break_label = break_block;
1430 statement_to_firm(statement->body);
1432 if(get_cur_block() != NULL) {
1433 ir_node *jmp = new_Jmp();
1434 add_immBlock_pred(break_block, jmp);
1437 assert(current_switch_cond == cond);
1438 assert(break_label == break_block);
1439 current_switch_cond = old_switch_cond;
1440 break_label = old_break_label;
1442 mature_immBlock(break_block);
1443 set_cur_block(break_block);
1446 static void case_label_to_firm(const case_label_statement_t *statement)
1448 dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
1450 /* let's create a node and hope firm constant folding creates a Const
1453 set_cur_block(get_nodes_block(current_switch_cond));
1454 if(statement->expression) {
1455 ir_node *cnst = expression_to_firm(statement->expression);
1456 if(!is_Const(cnst)) {
1457 panic("couldn't fold constant for case label");
1459 tarval *tv = get_Const_tarval(cnst);
1460 if(!mode_is_int(get_tarval_mode(tv))) {
1461 panic("case label not an integer");
1464 long pn = get_tarval_long(tv);
1465 if(pn == MAGIC_DEFAULT_PN_NUMBER) {
1466 /* oops someone detected our cheating... */
1467 panic("magic default pn used");
1469 proj = new_d_Proj(dbgi, current_switch_cond, mode_X, pn);
1471 proj = new_d_defaultProj(dbgi, current_switch_cond,
1472 MAGIC_DEFAULT_PN_NUMBER);
1475 ir_node *block = new_immBlock();
1476 add_immBlock_pred(block, proj);
1477 mature_immBlock(block);
1480 static void statement_to_firm(statement_t *statement)
1482 switch(statement->type) {
1483 case STATEMENT_COMPOUND:
1484 compound_statement_to_firm((compound_statement_t*) statement);
1486 case STATEMENT_RETURN:
1487 return_statement_to_firm((return_statement_t*) statement);
1489 case STATEMENT_EXPRESSION:
1490 expression_statement_to_firm((expression_statement_t*) statement);
1493 if_statement_to_firm((if_statement_t*) statement);
1495 case STATEMENT_WHILE:
1496 while_statement_to_firm((while_statement_t*) statement);
1498 case STATEMENT_DO_WHILE:
1499 do_while_statement_to_firm((do_while_statement_t*) statement);
1501 case STATEMENT_DECLARATION:
1502 declaration_statement_to_firm((declaration_statement_t*) statement);
1504 case STATEMENT_BREAK:
1505 create_jump_statement(statement, break_label);
1507 case STATEMENT_CONTINUE:
1508 create_jump_statement(statement, continue_label);
1510 case STATEMENT_SWITCH:
1511 switch_statement_to_firm((switch_statement_t*) statement);
1513 case STATEMENT_CASE_LABEL:
1514 case_label_to_firm((case_label_statement_t*) statement);
1517 for_statement_to_firm((for_statement_t*) statement);
1522 panic("Statement not implemented\n");
1525 static int get_function_n_local_vars(declaration_t *declaration)
1532 static void initialize_function_parameters(declaration_t *declaration)
1534 ir_graph *irg = current_ir_graph;
1535 ir_node *args = get_irg_args(irg);
1536 ir_node *start_block = get_irg_start_block(irg);
1539 declaration_t *parameter = declaration->context.declarations;
1540 for( ; parameter != NULL; parameter = parameter->next) {
1541 assert(parameter->declaration_type == DECLARATION_TYPE_UNKNOWN);
1543 if(parameter->address_taken) {
1544 panic("address take from parameter not implemented yet");
1547 ir_mode *mode = get_ir_mode(parameter->type);
1549 ir_node *proj = new_r_Proj(irg, start_block, args, mode, pn);
1552 parameter->declaration_type = DECLARATION_TYPE_LOCAL_VARIABLE;
1553 parameter->v.value_number = next_value_number_function;
1554 ++next_value_number_function;
1556 set_value(parameter->v.value_number, proj);
1560 static void create_function(declaration_t *declaration)
1562 ir_entity *entity = get_function_entity(declaration);
1564 if(declaration->init.statement == NULL)
1567 int n_local_vars = get_function_n_local_vars(declaration);
1568 ir_graph *irg = new_ir_graph(entity, n_local_vars);
1569 ir_node *first_block = get_cur_block();
1571 next_value_number_function = 0;
1572 initialize_function_parameters(declaration);
1574 statement_to_firm(declaration->init.statement);
1576 ir_node *end_block = get_irg_end_block(irg);
1578 /* do we have a return statement yet? */
1579 if(get_cur_block() != NULL) {
1580 assert(declaration->type->type == TYPE_FUNCTION);
1581 const function_type_t* const func_type = (const function_type_t*)declaration->type;
1583 if (func_type->result_type == type_void) {
1584 ret = new_Return(get_store(), 0, NULL);
1586 ir_mode *const mode = get_ir_mode(func_type->result_type);
1588 // ยง5.1.2.2.3 main implicitly returns 0
1589 if (strcmp(declaration->symbol->string, "main") == 0) {
1590 in[0] = new_Const(mode, get_mode_null(mode));
1592 in[0] = new_Unknown(mode);
1594 ret = new_Return(get_store(), 1, in);
1596 add_immBlock_pred(end_block, ret);
1599 mature_immBlock(first_block);
1600 mature_immBlock(end_block);
1602 irg_finalize_cons(irg);
1604 /* finalize the frame type */
1605 ir_type *frame_type = get_irg_frame_type(irg);
1606 int n = get_compound_n_members(frame_type);
1609 for(int i = 0; i < n; ++i) {
1610 ir_entity *entity = get_compound_member(frame_type, i);
1611 ir_type *entity_type = get_entity_type(entity);
1613 int align = get_type_alignment_bytes(entity_type);
1614 if(align > align_all)
1618 misalign = offset % align;
1622 set_entity_offset(entity, offset);
1623 offset += get_type_size_bytes(entity_type);
1625 set_type_size_bytes(frame_type, offset);
1626 set_type_alignment_bytes(frame_type, align_all);
1627 set_type_state(frame_type, layout_fixed);
1632 static void context_to_firm(context_t *context)
1634 declaration_t *declaration = context->declarations;
1635 for( ; declaration != NULL; declaration = declaration->next) {
1636 if(declaration->namespace != NAMESPACE_NORMAL)
1638 if(declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY
1639 || declaration->storage_class == STORAGE_CLASS_TYPEDEF)
1642 type_t *type = declaration->type;
1643 if(type->type == TYPE_FUNCTION) {
1644 create_function(declaration);
1651 void translation_unit_to_firm(translation_unit_t *unit)
1653 /* remove me later TODO FIXME */
1654 (void) get_type_size;
1656 /* just to be sure */
1657 continue_label = NULL;
1659 current_switch_cond = NULL;
1661 context_to_firm(& unit->context);