Compiler compiles for x86 (doesn't work properly)

This commit is contained in:
Ginger Bill
2017-06-19 18:49:11 +01:00
parent 5427d14416
commit 35c102137f
9 changed files with 205 additions and 158 deletions
+17 -8
View File
@@ -1276,9 +1276,14 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
// SEE: https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
Type *bt = core_type(original_type);
switch (bt->kind) {
// Okay to pass by value
// Okay to pass by value (usually)
// Especially the only Odin types
case Type_Basic: break;
case Type_Basic: {
i64 sz = bt->Basic.size;
if (sz > 8 && build_context.word_size < 8) {
new_type = make_type_pointer(a, original_type);
}
} break;
case Type_Pointer: break;
case Type_Proc: break; // NOTE(bill): Just a pointer
@@ -1306,12 +1311,18 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
}
} break;
}
} else if (build_context.ODIN_OS == "linux") {
} else if (build_context.ODIN_OS == "linux" ||
build_context.ODIN_OS == "osx") {
Type *bt = core_type(original_type);
switch (bt->kind) {
// Okay to pass by value
// Okay to pass by value (usually)
// Especially the only Odin types
case Type_Basic: break;
case Type_Basic: {
i64 sz = bt->Basic.size;
if (sz > 8 && build_context.word_size < 8) {
new_type = make_type_pointer(a, original_type);
}
} break;
case Type_Pointer: break;
case Type_Proc: break; // NOTE(bill): Just a pointer
@@ -1735,9 +1746,7 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
{
// NOTE(bill): The preload types may have not been set yet
if (t_map_key == NULL) {
init_preload(c);
}
init_preload(c);
GB_ASSERT(t_map_key != NULL);
Type *entry_type = make_type_struct(a);
-4
View File
@@ -1206,10 +1206,6 @@ Entity *find_core_entity(Checker *c, String name) {
}
void init_preload(Checker *c) {
if (c->done_preload) {
return;
}
if (t_type_info == NULL) {
Entity *type_info_entity = find_core_entity(c, str_lit("TypeInfo"));
+54 -37
View File
@@ -198,7 +198,7 @@ struct irProcedure {
irValue *true_value; \
irValue *false_value; \
}) \
IR_INSTR_KIND(Phi, struct { Array<irValue *> edges; Type *type; }) \
IR_INSTR_KIND(Phi, struct { Array<irValue *> edges; Type *type; })\
IR_INSTR_KIND(Unreachable, i32) \
IR_INSTR_KIND(UnaryOp, struct { \
Type * type; \
@@ -218,26 +218,26 @@ struct irProcedure {
isize arg_count; \
}) \
IR_INSTR_KIND(StartupRuntime, i32) \
IR_INSTR_KIND(BoundsCheck, struct { \
TokenPos pos; \
irValue *index; \
irValue *len; \
IR_INSTR_KIND(DebugDeclare, struct { \
irDebugInfo *debug_info; \
AstNode * expr; \
Entity * entity; \
bool is_addr; \
irValue * value; \
}) \
IR_INSTR_KIND(SliceBoundsCheck, struct { \
TokenPos pos; \
irValue *low; \
irValue *high; \
irValue *max; \
bool is_substring; \
}) \
IR_INSTR_KIND(DebugDeclare, struct { \
irDebugInfo *debug_info; \
AstNode * expr; \
Entity * entity; \
bool is_addr; \
irValue * value; \
}) \
// IR_INSTR_KIND(BoundsCheck, struct { \
// TokenPos pos; \
// irValue *index; \
// irValue *len; \
// }) \
// IR_INSTR_KIND(SliceBoundsCheck, struct { \
// TokenPos pos; \
// irValue *low; \
// irValue *high; \
// irValue *max; \
// bool is_substring; \
// }) \
#define IR_CONV_KINDS \
@@ -1011,22 +1011,6 @@ irValue *ir_instr_comment(irProcedure *p, String text) {
return v;
}
irValue *ir_instr_bounds_check(irProcedure *p, TokenPos pos, irValue *index, irValue *len) {
irValue *v = ir_alloc_instr(p, irInstr_BoundsCheck);
v->Instr.BoundsCheck.pos = pos;
v->Instr.BoundsCheck.index = index;
v->Instr.BoundsCheck.len = len;
return v;
}
irValue *ir_instr_slice_bounds_check(irProcedure *p, TokenPos pos, irValue *low, irValue *high, irValue *max, bool is_substring) {
irValue *v = ir_alloc_instr(p, irInstr_SliceBoundsCheck);
v->Instr.SliceBoundsCheck.pos = pos;
v->Instr.SliceBoundsCheck.low = low;
v->Instr.SliceBoundsCheck.high = high;
v->Instr.SliceBoundsCheck.max = max;
v->Instr.SliceBoundsCheck.is_substring = is_substring;
return v;
}
irValue *ir_instr_debug_declare(irProcedure *p, irDebugInfo *debug_info, AstNode *expr, Entity *entity, bool is_addr, irValue *value) {
irValue *v = ir_alloc_instr(p, irInstr_DebugDeclare);
v->Instr.DebugDeclare.debug_info = debug_info;
@@ -3443,7 +3427,21 @@ void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValu
index = ir_emit_conv(proc, index, t_int);
len = ir_emit_conv(proc, len, t_int);
ir_emit(proc, ir_instr_bounds_check(proc, token.pos, index, len));
gbAllocator a = proc->module->allocator;
irValue *file = ir_find_or_add_entity_string(proc->module, token.pos.file);
irValue *line = ir_const_int(a, token.pos.line);
irValue *column = ir_const_int(a, token.pos.column);
irValue **args = gb_alloc_array(a, irValue *, 5);
args[0] = file;
args[1] = line;
args[2] = column;
args[3] = index;
args[4] = len;
ir_emit_global_call(proc, "__bounds_check_error", args, 5);
// ir_emit(proc, ir_instr_bounds_check(proc, token.pos, index, len));
}
void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, irValue *max, bool is_substring) {
@@ -3451,10 +3449,29 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir
return;
}
gbAllocator a = proc->module->allocator;
irValue *file = ir_find_or_add_entity_string(proc->module, token.pos.file);
irValue *line = ir_const_int(a, token.pos.line);
irValue *column = ir_const_int(a, token.pos.column);
low = ir_emit_conv(proc, low, t_int);
high = ir_emit_conv(proc, high, t_int);
ir_emit(proc, ir_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring));
irValue **args = gb_alloc_array(a, irValue *, 6);
args[0] = file;
args[1] = line;
args[2] = column;
args[3] = low;
args[4] = high;
args[5] = max;
if (is_substring) {
ir_emit_global_call(proc, "__substring_expr_error", args, 5);
} else {
ir_emit_global_call(proc, "__slice_expr_error", args, 6);
}
// ir_emit(proc, ir_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring));
}
+3
View File
@@ -80,6 +80,8 @@ void ir_opt_add_operands(Array<irValue *> *ops, irInstr *i) {
// break;
case irInstr_StartupRuntime:
break;
#if 0
case irInstr_BoundsCheck:
array_add(ops, i->BoundsCheck.index);
array_add(ops, i->BoundsCheck.len);
@@ -88,6 +90,7 @@ void ir_opt_add_operands(Array<irValue *> *ops, irInstr *i) {
array_add(ops, i->SliceBoundsCheck.low);
array_add(ops, i->SliceBoundsCheck.high);
break;
#endif
}
}
+2
View File
@@ -1391,6 +1391,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
// ir_fprintf(f, "\n");
// } break;
#if 0
case irInstr_BoundsCheck: {
irInstrBoundsCheck *bc = &instr->BoundsCheck;
ir_fprintf(f, "call void ");
@@ -1462,6 +1463,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
ir_fprintf(f, ")\n");
} break;
#endif
case irInstr_DebugDeclare: {
/* irInstrDebugDeclare *dd = &instr->DebugDeclare;