#define MAGIC_DEFAULT_PN_NUMBER (long) -314159265
+/* some idents needed for name mangling */
+static ident *id_underscore;
+static ident *id_imp;
+
static ir_type *ir_type_const_char;
static ir_type *ir_type_wchar_t;
static ir_type *ir_type_void;
return (dbg_info*) pos;
}
-static unsigned unique_id = 0;
-
-static ident *unique_ident(const char *tag)
-{
- char buf[256];
-
- snprintf(buf, sizeof(buf), "%s.%u", tag, unique_id);
- unique_id++;
- return new_id_from_str(buf);
-}
-
static ir_mode *_atomic_modes[ATOMIC_TYPE_LAST+1];
static ir_mode *mode_int, *mode_uint;
panic("error type occured");
case TYPE_ATOMIC:
return get_atomic_type_size(type->atomic.akind);
+ case TYPE_COMPLEX:
+ return 2 * get_atomic_type_size(type->complex.akind);
+ case TYPE_IMAGINARY:
+ return get_atomic_type_size(type->imaginary.akind);
case TYPE_ENUM:
return get_mode_size_bytes(mode_int);
case TYPE_COMPOUND_UNION:
return count;
}
+/**
+ * Creates a Firm type for an atomic type
+ */
static ir_type *create_atomic_type(const atomic_type_t *type)
{
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
atomic_type_kind_t kind = type->akind;
ir_mode *mode = _atomic_modes[kind];
- unsigned alignment = get_atomic_type_alignment(kind);
ident *id = get_mode_ident(mode);
ir_type *irtype = new_d_type_primitive(id, mode, dbgi);
- if(type->base.alignment > alignment)
- alignment = type->base.alignment;
+ set_type_alignment_bytes(irtype, type->base.alignment);
+
+ return irtype;
+}
+
+/**
+ * Creates a Firm type for a complex type
+ */
+static ir_type *create_complex_type(const complex_type_t *type)
+{
+ dbg_info *dbgi = get_dbg_info(&type->base.source_position);
+ atomic_type_kind_t kind = type->akind;
+ ir_mode *mode = _atomic_modes[kind];
+ ident *id = get_mode_ident(mode);
- set_type_alignment_bytes(irtype, alignment);
+ (void) id;
+ (void) dbgi;
+
+ /* FIXME: finish the array */
+ return NULL;
+}
+
+/**
+ * Creates a Firm type for an imaginary type
+ */
+static ir_type *create_imaginary_type(const imaginary_type_t *type)
+{
+ dbg_info *dbgi = get_dbg_info(&type->base.source_position);
+ atomic_type_kind_t kind = type->akind;
+ ir_mode *mode = _atomic_modes[kind];
+ ident *id = get_mode_ident(mode);
+ ir_type *irtype = new_d_type_primitive(id, mode, dbgi);
+
+ set_type_alignment_bytes(irtype, type->base.alignment);
return irtype;
}
{
type_t *return_type = function_type->return_type;
- ident *id = unique_ident("functiontype");
+ ident *id = id_unique("functiontype.%u");
int n_parameters = count_parameters(function_type);
int n_results = return_type == type_void ? 0 : 1;
dbg_info *dbgi = get_dbg_info(&function_type->base.source_position);
* and then set the real points_to type
*/
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
- ir_type *ir_type = new_d_type_pointer(unique_ident("pointer"),
+ ir_type *ir_type = new_d_type_pointer(id_unique("pointer.%u"),
ir_type_void, mode_P_data, dbgi);
type->base.firm_type = ir_type;
type_t *element_type = type->element_type;
ir_type *ir_element_type = get_ir_type(element_type);
- ident *id = unique_ident("array");
+ ident *id = id_unique("array.%u");
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
ir_type *ir_type = new_d_type_array(id, 1, ir_element_type, dbgi);
symbol_t *symbol = declaration->symbol;
ident *id;
if(symbol != NULL) {
- id = unique_ident(symbol->string);
+ id = new_id_from_str(symbol->string);
} else {
- id = unique_ident("__anonymous_struct");
+ id = id_unique("__anonymous_struct.%u");
}
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
} else {
assert(entry_type->kind == TYPE_BITFIELD);
}
- ident = unique_ident("anon");
+ ident = id_unique("anon.%u");
}
ir_type *base_irtype;
symbol_t *symbol = declaration->symbol;
ident *id;
if(symbol != NULL) {
- id = unique_ident(symbol->string);
+ id = new_id_from_str(symbol->string);
} else {
- id = unique_ident("__anonymous_union");
+ id = id_unique("__anonymous_union.%u");
}
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
if(entry_size > size) {
size = entry_size;
}
- ident = unique_ident("anon");
+ ident = id_unique("anon.%u");
}
size_t entry_size = get_type_size_bytes(entry_ir_type);
ir_type *firm_type = NULL;
switch(type->kind) {
case TYPE_ERROR:
- panic("error type occured");
+ panic("error type occurred");
case TYPE_ATOMIC:
firm_type = create_atomic_type(&type->atomic);
break;
+ case TYPE_COMPLEX:
+ firm_type = create_complex_type(&type->complex);
+ break;
+ case TYPE_IMAGINARY:
+ firm_type = create_imaginary_type(&type->imaginary);
+ break;
case TYPE_FUNCTION:
firm_type = create_method_type(&type->function);
break;
{ rts_strncmp, 1, "strncmp", 3, _C89 }
};
+/**
+ * Mangles an entity linker (ld) name for win32 usage.
+ *
+ * @param ent the entity to be mangled
+ * @param declaration the declaration
+ */
+static ident *create_ld_ident_win32(ir_entity *ent, declaration_t *declaration)
+{
+ ident *id;
+
+ if (is_Method_type(get_entity_type(ent)))
+ id = decorate_win32_c_fkt(ent, get_entity_ident(ent));
+ else {
+ /* always add an underscore in win32 */
+ id = mangle(id_underscore, get_entity_ident(ent));
+ }
+
+ decl_modifiers_t decl_modifiers = declaration->decl_modifiers;
+ if (decl_modifiers & DM_DLLIMPORT) {
+ /* add prefix for imported symbols */
+ id = mangle(id_imp, id);
+ }
+ return id;
+}
+
+/**
+ * Mangles an entity linker (ld) name for Linux ELF usage.
+ *
+ * @param ent the entity to be mangled
+ * @param declaration the declaration
+ */
+static ident *create_ld_ident_linux_elf(ir_entity *entity,
+ declaration_t *declaration)
+{
+ (void) declaration;
+ return get_entity_ident(entity);
+}
+
+/**
+ * Mangles an entity linker (ld) name for Mach-O usage.
+ *
+ * @param ent the entity to be mangled
+ * @param declaration the declaration
+ */
+static ident *create_ld_ident_macho(ir_entity *ent, declaration_t *declaration)
+{
+ (void) declaration;
+ ident *id = mangle(id_underscore, get_entity_ident(ent));
+ return id;
+}
+
+typedef ident* (*create_ld_ident_func)(ir_entity *entity,
+ declaration_t *declaration);
+create_ld_ident_func create_ld_ident = create_ld_ident_linux_elf;
+
static ir_entity* get_function_entity(declaration_t *declaration)
{
if(declaration->declaration_kind == DECLARATION_KIND_FUNCTION)
dbg_info *const dbgi = get_dbg_info(&declaration->source_position);
ir_entity *const entity = new_d_entity(global_type, id, ir_type_method, dbgi);
- set_entity_ld_ident(entity, id);
+ set_entity_ld_ident(entity, create_ld_ident(entity, declaration));
if(declaration->storage_class == STORAGE_CLASS_STATIC
|| declaration->is_inline) {
set_entity_visibility(entity, visibility_local);
}
static ir_node *create_symconst(dbg_info *dbgi, ir_mode *mode,
- ir_entity *entity)
+ ir_entity *entity)
{
assert(entity != NULL);
union symconst_symbol sym;
{
ir_type *const global_type = get_glob_type();
dbg_info *const dbgi = get_dbg_info(src_pos);
- ir_type *const type = new_d_type_array(unique_ident("strtype"), 1,
+ ir_type *const type = new_d_type_array(id_unique("strtype.%u"), 1,
ir_type_const_char, dbgi);
- ident *const id = unique_ident(id_prefix);
+ ident *const id = id_unique(id_prefix);
ir_entity *const entity = new_d_entity(global_type, id, type, dbgi);
set_entity_ld_ident(entity, id);
set_entity_variability(entity, variability_constant);
static ir_node *string_literal_to_firm(
const string_literal_expression_t* literal)
{
- return string_to_firm(&literal->base.source_position, "Lstr",
+ return string_to_firm(&literal->base.source_position, "Lstr.%u",
&literal->value);
}
ir_type *const global_type = get_glob_type();
ir_type *const elem_type = ir_type_wchar_t;
dbg_info *const dbgi = get_dbg_info(&literal->base.source_position);
- ir_type *const type = new_d_type_array(unique_ident("strtype"), 1,
+ ir_type *const type = new_d_type_array(id_unique("strtype.%u"), 1,
elem_type, dbgi);
- ident *const id = unique_ident("Lstr");
+ ident *const id = id_unique("Lstr.%u");
ir_entity *const entity = new_d_entity(global_type, id, type, dbgi);
set_entity_ld_ident(entity, id);
set_entity_variability(entity, variability_constant);
* arguments... */
int n_res = get_method_n_ress(ir_method_type);
dbg_info *dbgi = get_dbg_info(&call->base.source_position);
- new_method_type = new_d_type_method(unique_ident("calltype"),
+ new_method_type = new_d_type_method(id_unique("calltype.%u"),
n_parameters, n_res, dbgi);
set_method_calling_convention(new_method_type,
get_method_calling_convention(ir_method_type));
/* create an entity on the stack */
ir_type *frame_type = get_irg_frame_type(current_ir_graph);
- ident *const id = unique_ident("CompLit");
+ ident *const id = id_unique("CompLit.%u");
ir_type *const irtype = get_ir_type(type);
dbg_info *const dbgi = get_dbg_info(&expression->base.source_position);
ir_entity *const entity = new_d_entity(frame_type, id, irtype, dbgi);
{
case TYPE_ATOMIC: {
const atomic_type_t *const atomic_type = &type->atomic;
- switch ((atomic_type_kind_t) atomic_type->akind) {
+ switch (atomic_type->akind) {
/* should not be reached */
case ATOMIC_TYPE_INVALID:
tc = no_type_class;
case ATOMIC_TYPE_LONG_DOUBLE:
tc = real_type_class;
goto make_const;
-
- case ATOMIC_TYPE_FLOAT_COMPLEX:
- case ATOMIC_TYPE_DOUBLE_COMPLEX:
- case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
- tc = complex_type_class;
- goto make_const;
- case ATOMIC_TYPE_FLOAT_IMAGINARY:
- case ATOMIC_TYPE_DOUBLE_IMAGINARY:
- case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
- tc = complex_type_class;
- goto make_const;
}
panic("Unexpected atomic type in classify_type_to_firm().");
}
+ case TYPE_COMPLEX: tc = complex_type_class; goto make_const;
+ case TYPE_IMAGINARY: tc = complex_type_class; goto make_const;
case TYPE_BITFIELD: tc = integer_type_class; goto make_const;
case TYPE_ARRAY: /* gcc handles this as pointer */
case TYPE_FUNCTION: /* gcc handles this as pointer */
const source_position_t *const src_pos = &expr->base.source_position;
const char *const name = current_function_decl->symbol->string;
const string_t string = { name, strlen(name) + 1 };
- current_function_name = string_to_firm(src_pos, "__func__", &string);
+ current_function_name = string_to_firm(src_pos, "__func__.%u", &string);
}
return current_function_name;
case FUNCNAME_FUNCSIG:
ir_entity *ent = get_irg_entity(current_ir_graph);
const char *const name = get_entity_ld_name(ent);
const string_t string = { name, strlen(name) + 1 };
- current_funcsig = string_to_firm(src_pos, "__FUNCSIG__", &string);
+ current_funcsig = string_to_firm(src_pos, "__FUNCSIG__.%u", &string);
}
return current_funcsig;
}
ir_type *const irtype = get_ir_type(type);
dbg_info *const dbgi = get_dbg_info(&declaration->source_position);
ir_entity *const entity = new_d_entity(parent_type, id, irtype, dbgi);
- set_entity_ld_ident(entity, id);
declaration->declaration_kind = (unsigned char) declaration_kind;
declaration->v.entity = entity;
set_entity_variability(entity, variability_uninitialized);
+ set_entity_ld_ident(entity, create_ld_ident(entity, declaration));
if(parent_type == get_tls_type())
set_entity_allocation(entity, allocation_automatic);
else if(declaration_kind == DECLARATION_KIND_GLOBAL_VARIABLE)
if(i < string_len)
c = string[i];
- tarval *tv = new_tarval_from_long(string[i], mode);
+ tarval *tv = new_tarval_from_long(c, mode);
ir_initializer_t *char_initializer = create_initializer_tarval(tv);
set_initializer_compound_value(irinitializer, i, char_initializer);
if(i < string_len) {
c = string[i];
}
- tarval *tv = new_tarval_from_long(string[i], mode);
+ tarval *tv = new_tarval_from_long(c, mode);
ir_initializer_t *char_initializer = create_initializer_tarval(tv);
set_initializer_compound_value(irinitializer, i, char_initializer);
panic("unknown initializer");
}
+#if 0
+static void create_dynamic_null_initializer(ir_type *type, dbg_info *dbgi,
+ ir_node *base_addr)
+{
+ ir_mode *mode = get_type_mode(type);
+ tarval *zero = get_mode_null(mode);
+ ir_node *cnst = new_d_Const(dbgi, mode, zero);
+
+ /* TODO: bitfields */
+ ir_node *mem = get_store();
+ ir_node *store = new_d_Store(dbgi, mem, base_addr, cnst);
+ ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M);
+ set_store(proj_m);
+}
+#endif
+
static void create_dynamic_initializer_sub(ir_initializer_t *initializer,
ir_type *type, dbg_info *dbgi, ir_node *base_addr)
{
current_ir_graph = old_current_ir_graph;
/* create a "template" entity which is copied to the entity on the stack */
- ident *const id = unique_ident("initializer");
+ ident *const id = id_unique("initializer.%u");
ir_type *const irtype = get_ir_type(type);
ir_type *const global_type = get_glob_type();
ir_entity *const init_entity = new_d_entity(global_type, id, irtype, dbgi);
type_t *const type = skip_typeref(declaration->type);
ir_type *const global_type = get_glob_type();
- ident *const id = unique_ident(declaration->symbol->string);
+ ident *const id = new_id_from_str(declaration->symbol->string);
ir_type *const irtype = get_ir_type(type);
dbg_info *const dbgi = get_dbg_info(&declaration->source_position);
ir_entity *const entity = new_d_entity(global_type, id, irtype, dbgi);
- set_entity_ld_ident(entity, id);
if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
set_entity_volatility(entity, volatility_is_volatile);
declaration->declaration_kind = DECLARATION_KIND_GLOBAL_VARIABLE;
declaration->v.entity = entity;
+ set_entity_ld_ident(entity, create_ld_ident(entity, declaration));
set_entity_variability(entity, variability_uninitialized);
set_entity_visibility(entity, visibility_local);
set_entity_allocation(entity, allocation_static);
/* set inline flags */
if (declaration->is_inline)
set_irg_inline_property(irg, irg_inline_recomended);
- handle_decl_modifier_irg(irg, declaration->modifiers);
+ handle_decl_modifier_irg(irg, declaration->decl_modifiers);
next_value_number_function = 0;
initialize_function_parameters(declaration);
obstack_init(&asm_obst);
init_atomic_modes();
+ id_underscore = new_id_from_chars("_", 1);
+ id_imp = new_id_from_chars("__imp_", 6);
+
+ /* OS option must be set to the backend */
+ const char *s = "ia32-gasmode=linux";
+ switch (firm_opt.os_support) {
+ case OS_SUPPORT_WIN32:
+ create_ld_ident = create_ld_ident_win32;
+ s = "ia32-gasmode=mingw";
+ break;
+ case OS_SUPPORT_LINUX:
+ create_ld_ident = create_ld_ident_linux_elf;
+ s = "ia32-gasmode=linux"; break;
+ break;
+ case OS_SUPPORT_MACHO:
+ create_ld_ident = create_ld_ident_macho;
+ s = "ia32-gasmode=macho"; break;
+ break;
+ }
+ firm_be_option(s);
+
/* create idents for all known runtime functions */
for (size_t i = 0; i < sizeof(rts_data) / sizeof(rts_data[0]); ++i) {
predef_idents[rts_data[i].id] = new_id_from_str(rts_data[i].name);