mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-17 08:21:25 -07:00
Win32 test
This commit is contained in:
@@ -91,6 +91,8 @@ void ssa_gen_code(ssaGen *s) {
|
||||
name = pd->foreign_name;
|
||||
}
|
||||
ssaValue *p = ssa_make_value_procedure(a, m, e->type, decl->type_expr, body, name);
|
||||
p->proc.tags = pd->tags;
|
||||
|
||||
map_set(&m->values, hash_pointer(e), p);
|
||||
map_set(&m->members, hash_string(name), p);
|
||||
} break;
|
||||
|
||||
+53
-29
@@ -174,21 +174,22 @@ void ssa_print_type(gbFile *f, BaseTypeSizes s, Type *t) {
|
||||
ssa_fprintf(f, "}");
|
||||
}
|
||||
break;
|
||||
case Type_Proc:
|
||||
case Type_Proc: {
|
||||
if (t->proc.result_count == 0) {
|
||||
ssa_fprintf(f, "void");
|
||||
} else {
|
||||
ssa_print_type(f, s, t->proc.results);
|
||||
}
|
||||
ssa_fprintf(f, " (");
|
||||
auto *params = &t->proc.params->tuple;
|
||||
for (isize i = 0; i < t->proc.param_count; i++) {
|
||||
if (i > 0) {
|
||||
ssa_fprintf(f, ", ");
|
||||
}
|
||||
ssa_print_type(f, s, &t->proc.params[i]);
|
||||
ssa_print_type(f, s, params->variables[i]->type);
|
||||
}
|
||||
ssa_fprintf(f, ")*");
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,7 +507,7 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
|
||||
|
||||
case ssaInstr_Call: {
|
||||
auto *call = &instr->call;
|
||||
Type *result_type = call->type->proc.results;
|
||||
Type *result_type = call->type;
|
||||
if (result_type) {
|
||||
ssa_fprintf(f, "%%%d = ", value->id);
|
||||
}
|
||||
@@ -521,18 +522,22 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
|
||||
|
||||
|
||||
ssa_fprintf(f, "(");
|
||||
auto *params = &call->type->proc.params->tuple;
|
||||
for (isize i = 0; i < call->arg_count; i++) {
|
||||
Entity *e = params->variables[i];
|
||||
GB_ASSERT(e != NULL);
|
||||
Type *t = e->type;
|
||||
if (i > 0) {
|
||||
ssa_fprintf(f, ", ");
|
||||
if (call->arg_count > 0) {
|
||||
Type *proc_type = get_base_type(ssa_value_type(call->value));
|
||||
GB_ASSERT(proc_type->kind == Type_Proc);
|
||||
auto *params = &proc_type->proc.params->tuple;
|
||||
for (isize i = 0; i < call->arg_count; i++) {
|
||||
Entity *e = params->variables[i];
|
||||
GB_ASSERT(e != NULL);
|
||||
Type *t = e->type;
|
||||
if (i > 0) {
|
||||
ssa_fprintf(f, ", ");
|
||||
}
|
||||
ssa_print_type(f, m->sizes, t);
|
||||
ssa_fprintf(f, " ");
|
||||
ssaValue *arg = call->args[i];
|
||||
ssa_print_value(f, m, arg, t);
|
||||
}
|
||||
ssa_print_type(f, m->sizes, t);
|
||||
ssa_fprintf(f, " ");
|
||||
ssaValue *arg = call->args[i];
|
||||
ssa_print_value(f, m, arg, t);
|
||||
}
|
||||
ssa_fprintf(f, ")\n");
|
||||
|
||||
@@ -650,9 +655,18 @@ void ssa_print_proc(gbFile *f, ssaModule *m, ssaProcedure *proc) {
|
||||
|
||||
ssa_fprintf(f, ") ");
|
||||
|
||||
if (proc->body == NULL) {
|
||||
ssa_fprintf(f, "; foreign procedure\n\n");
|
||||
} else {
|
||||
if (proc->tags != 0) {
|
||||
if (proc->tags & ProcTag_inline)
|
||||
ssa_fprintf(f, "alwaysinline ");
|
||||
if (proc->tags & ProcTag_no_inline)
|
||||
ssa_fprintf(f, "noinline ");
|
||||
|
||||
|
||||
if (proc->tags & ProcTag_foreign)
|
||||
ssa_fprintf(f, "; foreign\n");
|
||||
}
|
||||
|
||||
if (proc->body != NULL) {
|
||||
ssa_fprintf(f, "{\n");
|
||||
gb_for_array(i, proc->blocks) {
|
||||
ssaBlock *block = proc->blocks[i];
|
||||
@@ -682,6 +696,7 @@ void ssa_print_type_name(gbFile *f, ssaModule *m, ssaValue *v) {
|
||||
ssa_fprintf(f, "\n");
|
||||
}
|
||||
|
||||
|
||||
void ssa_print_llvm_ir(gbFile *f, ssaModule *m) {
|
||||
if (m->layout.len > 0) {
|
||||
ssa_fprintf(f, "target datalayout = \"%.*s\"\n", LIT(m->layout));
|
||||
@@ -695,17 +710,6 @@ void ssa_print_llvm_ir(gbFile *f, ssaModule *m) {
|
||||
ssa_print_encoded_local(f, make_string(".rawptr"));
|
||||
ssa_fprintf(f, " = type i8* ; Basic_rawptr\n\n");
|
||||
|
||||
ssa_fprintf(f, "declare void @llvm.memmove.p0i8.p0i8.");
|
||||
ssa_print_type(f, m->sizes, t_int);
|
||||
ssa_fprintf(f, "(i8*, i8*, ");
|
||||
ssa_print_type(f, m->sizes, t_int);
|
||||
ssa_fprintf(f, ", i32, i1) argmemonly nounwind \n\n");
|
||||
|
||||
gb_for_array(i, m->nested_type_names) {
|
||||
ssaValue *v = m->nested_type_names[i];
|
||||
ssa_print_type_name(f, m, v);
|
||||
}
|
||||
|
||||
gb_for_array(member_index, m->members.entries) {
|
||||
auto *entry = &m->members.entries[member_index];
|
||||
ssaValue *v = entry->value;
|
||||
@@ -716,7 +720,27 @@ void ssa_print_llvm_ir(gbFile *f, ssaModule *m) {
|
||||
ssa_print_type(f, m->sizes, get_base_type(v->type_name.type));
|
||||
ssa_fprintf(f, "\n");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
gb_for_array(i, m->nested_type_names) {
|
||||
ssaValue *v = m->nested_type_names[i];
|
||||
ssa_print_type_name(f, m, v);
|
||||
}
|
||||
|
||||
|
||||
ssa_fprintf(f, "declare void @llvm.memmove.p0i8.p0i8.");
|
||||
ssa_print_type(f, m->sizes, t_int);
|
||||
ssa_fprintf(f, "(i8*, i8*, ");
|
||||
ssa_print_type(f, m->sizes, t_int);
|
||||
ssa_fprintf(f, ", i32, i1) argmemonly nounwind \n\n");
|
||||
|
||||
|
||||
|
||||
gb_for_array(member_index, m->members.entries) {
|
||||
auto *entry = &m->members.entries[member_index];
|
||||
ssaValue *v = entry->value;
|
||||
switch (v->kind) {
|
||||
case ssaValue_Global: {
|
||||
auto *g = &v->global;
|
||||
ssa_print_encoded_global(f, g->entity->token.string);
|
||||
|
||||
+17
-12
@@ -46,6 +46,7 @@ struct ssaProcedure {
|
||||
Type * type;
|
||||
AstNode * type_expr;
|
||||
AstNode * body;
|
||||
u64 tags;
|
||||
|
||||
gbArray(ssaBlock *) blocks;
|
||||
ssaBlock * curr_block;
|
||||
@@ -318,13 +319,13 @@ Type *ssa_instr_type(ssaInstr *instr) {
|
||||
case ssaInstr_Select:
|
||||
return ssa_value_type(instr->select.true_value);
|
||||
case ssaInstr_Call: {
|
||||
Type *pt = instr->call.type;
|
||||
GB_ASSERT(pt->kind == Type_Proc);
|
||||
auto *tuple = &pt->proc.results->tuple;
|
||||
if (tuple->variable_count != 1)
|
||||
return pt->proc.results;
|
||||
else
|
||||
return tuple->variables[0]->type;
|
||||
Type *pt = get_base_type(instr->call.type);
|
||||
if (pt != NULL) {
|
||||
if (pt->kind == Type_Tuple && pt->tuple.variable_count == 1)
|
||||
return pt->tuple.variables[0]->type;
|
||||
return pt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
case ssaInstr_CopyMemory:
|
||||
return t_int;
|
||||
@@ -891,7 +892,7 @@ void ssa_end_procedure_body(ssaProcedure *proc) {
|
||||
case ssaInstr_CopyMemory:
|
||||
continue;
|
||||
case ssaInstr_Call:
|
||||
if (instr->call.type->proc.results == NULL) {
|
||||
if (instr->call.type == NULL) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -1459,6 +1460,8 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssaValue *value = ssa_make_value_procedure(proc->module->allocator,
|
||||
proc->module, type, pl->type, pl->body, name);
|
||||
|
||||
value->proc.tags = pl->tags;
|
||||
|
||||
gb_array_append(proc->children, &value->proc);
|
||||
ssa_build_proc(value, proc);
|
||||
|
||||
@@ -1693,8 +1696,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
}
|
||||
}
|
||||
|
||||
ssaValue *call = ssa_make_instr_call(proc, value, args, arg_count, tv->type);
|
||||
ssa_value_set_type(call, proc_type_);
|
||||
ssaValue *call = ssa_make_instr_call(proc, value, args, arg_count, type->results);
|
||||
return ssa_emit(proc, call);
|
||||
case_end;
|
||||
|
||||
@@ -2043,6 +2045,8 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
if (proc->children == NULL) {
|
||||
gb_array_init(proc->children, gb_heap_allocator());
|
||||
}
|
||||
|
||||
|
||||
if (pd->body != NULL) {
|
||||
// NOTE(bill): Generate a new name
|
||||
// parent$name-guid
|
||||
@@ -2059,6 +2063,8 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
ssaValue *value = ssa_make_value_procedure(proc->module->allocator,
|
||||
proc->module, e->type, pd->type, pd->body, name);
|
||||
|
||||
value->proc.tags = pd->tags;
|
||||
|
||||
ssa_module_add_value(proc->module, e, value);
|
||||
gb_array_append(proc->children, &value->proc);
|
||||
ssa_build_proc(value, proc);
|
||||
@@ -2273,7 +2279,7 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
proc->curr_block = init;
|
||||
ssa_build_stmt(proc, fs->init);
|
||||
}
|
||||
ssaBlock *body = ssa__make_block(proc, node, make_string("for.body"));
|
||||
ssaBlock *body = ssa_add_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;
|
||||
@@ -2289,7 +2295,6 @@ 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