mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 03:12:22 -07:00
#foreign "custom_name"; <N x i1> bugs (see test.ll and test2.ll)
This commit is contained in:
+12
-2
@@ -18,6 +18,11 @@ b32 ssa_gen_init(ssaGen *s, Checker *c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
isize tc = c->parser->total_token_count;
|
||||
if (tc < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ssa_module_init(&s->module, c);
|
||||
|
||||
// TODO(bill): generate appropriate output name
|
||||
@@ -79,8 +84,13 @@ void ssa_gen_code(ssaGen *s) {
|
||||
} break;
|
||||
|
||||
case Entity_Procedure: {
|
||||
AstNode *body = decl->proc_decl->ProcDecl.body;
|
||||
ssaValue *p = ssa_make_value_procedure(a, m, e->type, decl->type_expr, body, e->token.string);
|
||||
auto *pd = &decl->proc_decl->ProcDecl;
|
||||
String name = e->token.string;
|
||||
AstNode *body = pd->body;
|
||||
if (pd->foreign_name.len > 0) {
|
||||
name = pd->foreign_name;
|
||||
}
|
||||
ssaValue *p = ssa_make_value_procedure(a, m, e->type, decl->type_expr, body, name);
|
||||
map_set(&m->values, hash_pointer(e), p);
|
||||
map_set(&m->members, hash_string(name), p);
|
||||
} break;
|
||||
|
||||
@@ -269,7 +269,7 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
|
||||
Type *type = instr->local.entity->type;
|
||||
ssa_fprintf(f, "%%%d = alloca ", value->id);
|
||||
ssa_print_type(f, m->sizes, type);
|
||||
ssa_fprintf(f, ", align %lld ", type_align_of(m->sizes, gb_heap_allocator(), type));
|
||||
ssa_fprintf(f, ", align %lld ", type_align_of(m->sizes, m->allocator, type));
|
||||
{
|
||||
String str = instr->local.entity->token.string;
|
||||
if (str.len > 0)
|
||||
@@ -304,7 +304,7 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
|
||||
ssa_print_type(f, m->sizes, type);
|
||||
ssa_fprintf(f, "* ");
|
||||
ssa_print_value(f, m, instr->load.address, type);
|
||||
ssa_fprintf(f, "\n");
|
||||
ssa_fprintf(f, ", align %lld\n", type_align_of(m->sizes, m->allocator, type));
|
||||
} break;
|
||||
|
||||
case ssaInstr_GetElementPtr: {
|
||||
@@ -616,7 +616,7 @@ void ssa_print_proc(gbFile *f, ssaModule *m, ssaProcedure *proc) {
|
||||
ssa_fprintf(f, ") ");
|
||||
|
||||
if (proc->body == NULL) {
|
||||
ssa_fprintf(f, "\t; foreign procedure\n\n");
|
||||
ssa_fprintf(f, "; foreign procedure\n\n");
|
||||
} else {
|
||||
ssa_fprintf(f, "{\n");
|
||||
gb_for_array(i, proc->blocks) {
|
||||
|
||||
+11
-1
@@ -2067,6 +2067,9 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
ssa_build_proc(value, proc);
|
||||
} else {
|
||||
String name = pd->name->Ident.token.string;
|
||||
if (pd->foreign_name.len > 0) {
|
||||
name = pd->foreign_name;
|
||||
}
|
||||
|
||||
Entity **found = map_get(&proc->module->info->definitions, hash_pointer(pd->name));
|
||||
GB_ASSERT(found != NULL);
|
||||
@@ -2240,6 +2243,9 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
case_ast_node(is, IfStmt, node);
|
||||
if (is->init != NULL) {
|
||||
ssaBlock *init = ssa_add_block(proc, node, make_string("if.init"));
|
||||
ssa_emit_jump(proc, init);
|
||||
proc->curr_block = init;
|
||||
ssa_build_stmt(proc, is->init);
|
||||
}
|
||||
ssaBlock *then = ssa_add_block(proc, node, make_string("if.then"));
|
||||
@@ -2265,9 +2271,12 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
case_ast_node(fs, ForStmt, node);
|
||||
if (fs->init != NULL) {
|
||||
ssaBlock *init = ssa_add_block(proc, node, make_string("for.init"));
|
||||
ssa_emit_jump(proc, init);
|
||||
proc->curr_block = init;
|
||||
ssa_build_stmt(proc, fs->init);
|
||||
}
|
||||
ssaBlock *body = ssa_add_block(proc, node, make_string("for.body"));
|
||||
ssaBlock *body = ssa__make_block(proc, node, make_string("for.body"));
|
||||
ssaBlock *done = ssa__make_block(proc, node, make_string("for.done")); // NOTE(bill): Append later
|
||||
|
||||
ssaBlock *loop = body;
|
||||
@@ -2283,6 +2292,7 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
proc->curr_block = loop;
|
||||
if (loop != body) {
|
||||
ssa_build_cond(proc, fs->cond, body, done);
|
||||
gb_array_append(proc->blocks, body);
|
||||
proc->curr_block = body;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user