diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-03-05 15:03:01 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-03-05 15:03:01 +0000 |
| commit | 5adfbec847a2253392b14043a82d5fbf56122ce5 (patch) | |
| tree | a725504164525bed536bfe1f2044bc4fc69f3510 /src | |
| parent | 4ef4605d6d41495646f3b9e9ebb2558a1f363eb5 (diff) | |
Refactoring of code: remove `make` prefix on many procedures
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_expr.c | 50 | ||||
| -rw-r--r-- | src/check_stmt.c | 2 | ||||
| -rw-r--r-- | src/checker.c | 42 | ||||
| -rw-r--r-- | src/exact_value.c | 62 | ||||
| -rw-r--r-- | src/ir.c | 631 | ||||
| -rw-r--r-- | src/ir_print.c | 18 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/types.c | 4 |
8 files changed, 405 insertions, 410 deletions
diff --git a/src/check_expr.c b/src/check_expr.c index 7e273fba4..d2796611d 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -746,9 +746,9 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod constant_type = named_type; } - ExactValue iota = make_exact_value_integer(-1); - ExactValue min_value = make_exact_value_integer(0); - ExactValue max_value = make_exact_value_integer(0); + ExactValue iota = exact_value_integer(-1); + ExactValue min_value = exact_value_integer(0); + ExactValue max_value = exact_value_integer(0); for_array(i, et->fields) { AstNode *field = et->fields.e[i]; @@ -783,10 +783,10 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod if (o.mode != Addressing_Invalid) { iota = o.value; } else { - iota = exact_binary_operator_value(Token_Add, iota, make_exact_value_integer(1)); + iota = exact_binary_operator_value(Token_Add, iota, exact_value_integer(1)); } } else { - iota = exact_binary_operator_value(Token_Add, iota, make_exact_value_integer(1)); + iota = exact_binary_operator_value(Token_Add, iota, exact_value_integer(1)); } @@ -839,7 +839,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod enum_type->Record.field_count = field_count; enum_type->Record.enum_count = make_entity_constant(c->allocator, c->context.scope, - make_token_ident(str_lit("count")), t_int, make_exact_value_integer(field_count)); + make_token_ident(str_lit("count")), t_int, exact_value_integer(field_count)); enum_type->Record.enum_min_value = make_entity_constant(c->allocator, c->context.scope, make_token_ident(str_lit("min_value")), constant_type, min_value); enum_type->Record.enum_max_value = make_entity_constant(c->allocator, c->context.scope, @@ -1860,7 +1860,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) { } x->mode = Addressing_Constant; x->type = t_untyped_bool; - x->value = make_exact_value_bool(comp); + x->value = exact_value_bool(comp); return; } @@ -1913,7 +1913,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) { } else { if (x->mode == Addressing_Constant && y->mode == Addressing_Constant) { - x->value = make_exact_value_bool(compare_exact_values(op, x->value, y->value)); + x->value = exact_value_bool(compare_exact_values(op, x->value, y->value)); } else { x->mode = Addressing_Value; @@ -1995,7 +1995,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { x->type = t_untyped_integer; } - x->value = exact_value_shift(be->op.kind, x_val, make_exact_value_integer(amount)); + x->value = exact_value_shift(be->op.kind, x_val, exact_value_integer(amount)); if (is_type_typed(x->type)) { check_is_expressible(c, x, base_type(x->type)); @@ -2094,7 +2094,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs new_ptr_val -= elem_size*offset_val; } operand.mode = Addressing_Constant; - operand.value = make_exact_value_pointer(new_ptr_val); + operand.value = exact_value_pointer(new_ptr_val); } return operand; @@ -2372,7 +2372,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { GB_ASSERT(op.kind == Token_Sub); i64 bytes = a.value_pointer - b.value_pointer; i64 diff = bytes/type_size_of(c->allocator, type); - x->value = make_exact_value_pointer(diff); + x->value = exact_value_pointer(diff); return; } @@ -2832,7 +2832,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h operand->type != NULL && is_type_untyped(operand->type) && is_type_string(operand->type)) { String s = operand->value.value_string; operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(s.len); + operand->value = exact_value_integer(s.len); operand->type = t_untyped_integer; return NULL; } @@ -3158,7 +3158,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(type_size_of(c->allocator, type)); + operand->value = exact_value_integer(type_size_of(c->allocator, type)); operand->type = t_untyped_integer; } break; @@ -3171,7 +3171,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(type_size_of(c->allocator, operand->type)); + operand->value = exact_value_integer(type_size_of(c->allocator, operand->type)); operand->type = t_untyped_integer; break; @@ -3183,7 +3183,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(type_align_of(c->allocator, type)); + operand->value = exact_value_integer(type_align_of(c->allocator, type)); operand->type = t_untyped_integer; } break; @@ -3195,7 +3195,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(type_align_of(c->allocator, operand->type)); + operand->value = exact_value_integer(type_align_of(c->allocator, operand->type)); operand->type = t_untyped_integer; break; @@ -3239,7 +3239,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } operand->mode = Addressing_Constant; - operand->value = make_exact_value_integer(type_offset_of_from_selection(c->allocator, type, sel)); + operand->value = exact_value_integer(type_offset_of_from_selection(c->allocator, type, sel)); operand->type = t_untyped_integer; } break; @@ -3288,7 +3288,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id operand->mode = Addressing_Constant; // IMPORTANT TODO(bill): Fix for anonymous fields - operand->value = make_exact_value_integer(type_offset_of_from_selection(c->allocator, type, sel)); + operand->value = exact_value_integer(type_offset_of_from_selection(c->allocator, type, sel)); operand->type = t_untyped_integer; } break; @@ -3584,7 +3584,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id u8 *ptr_a = cast(u8 *)operand->value.value_pointer; u8 *ptr_b = cast(u8 *)op.value.value_pointer; isize elem_size = type_size_of(c->allocator, ptr_type->Pointer.elem); - operand->value = make_exact_value_integer((ptr_a - ptr_b) / elem_size); + operand->value = exact_value_integer((ptr_a - ptr_b) / elem_size); } else { operand->mode = Addressing_Value; } @@ -4426,24 +4426,24 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint } o->mode = Addressing_Constant; o->type = t; - o->value = make_exact_value_from_basic_literal(*bl); + o->value = exact_value_from_basic_literal(*bl); case_end; case_ast_node(bd, BasicDirective, node); if (str_eq(bd->name, str_lit("file"))) { o->type = t_untyped_string; - o->value = make_exact_value_string(bd->token.pos.file); + o->value = exact_value_string(bd->token.pos.file); } else if (str_eq(bd->name, str_lit("line"))) { o->type = t_untyped_integer; - o->value = make_exact_value_integer(bd->token.pos.line); + o->value = exact_value_integer(bd->token.pos.line); } else if (str_eq(bd->name, str_lit("procedure"))) { if (c->proc_stack.count == 0) { error_node(node, "#procedure may only be used within procedures"); o->type = t_untyped_string; - o->value = make_exact_value_string(str_lit("")); + o->value = exact_value_string(str_lit("")); } else { o->type = t_untyped_string; - o->value = make_exact_value_string(c->context.proc_name); + o->value = exact_value_string(c->context.proc_name); } } else { @@ -4850,7 +4850,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint if (is_constant) { o->mode = Addressing_Constant; - o->value = make_exact_value_compound(node); + o->value = exact_value_compound(node); } else { o->mode = Addressing_Value; } diff --git a/src/check_stmt.c b/src/check_stmt.c index 768410803..1837dd404 100644 --- a/src/check_stmt.c +++ b/src/check_stmt.c @@ -850,7 +850,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } else { x.mode = Addressing_Constant; x.type = t_bool; - x.value = make_exact_value_bool(true); + x.value = exact_value_bool(true); Token token = {0}; token.pos = ast_node_token(ms->body).pos; diff --git a/src/checker.c b/src/checker.c index 3acefdccd..2e2eceefc 100644 --- a/src/checker.c +++ b/src/checker.c @@ -208,21 +208,21 @@ ExprInfo make_expr_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue #include "map.c" typedef struct Scope { - Scope * parent; - Scope * prev, *next; - Scope * first_child; - Scope * last_child; - MapEntity elements; // Key: String - MapBool implicit; // Key: Entity * - - Array(Scope *) shared; - Array(Scope *) imported; - bool is_proc; - bool is_global; - bool is_file; - bool is_init; - bool has_been_imported; // This is only applicable to file scopes - AstFile * file; + Scope * parent; + Scope * prev, *next; + Scope * first_child; + Scope * last_child; + MapEntity elements; // Key: String + MapBool implicit; // Key: Entity * + + Array(Scope *) shared; + Array(Scope *) imported; + bool is_proc; + bool is_global; + bool is_file; + bool is_init; + bool has_been_imported; // This is only applicable to file scopes + AstFile * file; } Scope; gb_global Scope *universal_scope = NULL; @@ -357,9 +357,9 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) { Scope *s = gb_alloc_item(allocator, Scope); s->parent = parent; map_entity_init(&s->elements, heap_allocator()); - map_bool_init(&s->implicit, heap_allocator()); - array_init(&s->shared, heap_allocator()); - array_init(&s->imported, heap_allocator()); + map_bool_init(&s->implicit, heap_allocator()); + array_init(&s->shared, heap_allocator()); + array_init(&s->imported, heap_allocator()); if (parent != NULL && parent != universal_scope) { DLIST_APPEND(parent->first_child, parent->last_child, s); @@ -596,7 +596,7 @@ void add_global_constant(gbAllocator a, String name, Type *type, ExactValue valu void add_global_string_constant(gbAllocator a, String name, String value) { - add_global_constant(a, name, t_untyped_string, make_exact_value_string(value)); + add_global_constant(a, name, t_untyped_string, exact_value_string(value)); } @@ -616,8 +616,8 @@ void init_universal_scope(void) { } // Constants - add_global_constant(a, str_lit("true"), t_untyped_bool, make_exact_value_bool(true)); - add_global_constant(a, str_lit("false"), t_untyped_bool, make_exact_value_bool(false)); + add_global_constant(a, str_lit("true"), t_untyped_bool, exact_value_bool(true)); + add_global_constant(a, str_lit("false"), t_untyped_bool, exact_value_bool(false)); add_global_entity(make_entity_nil(a, str_lit("nil"), t_untyped_nil)); add_global_entity(make_entity_library_name(a, universal_scope, diff --git a/src/exact_value.c b/src/exact_value.c index 57c8ae81d..88e3352f3 100644 --- a/src/exact_value.c +++ b/src/exact_value.c @@ -35,45 +35,45 @@ HashKey hash_exact_value(ExactValue v) { } -ExactValue make_exact_value_compound(AstNode *node) { +ExactValue exact_value_compound(AstNode *node) { ExactValue result = {ExactValue_Compound}; result.value_compound = node; return result; } -ExactValue make_exact_value_bool(bool b) { +ExactValue exact_value_bool(bool b) { ExactValue result = {ExactValue_Bool}; result.value_bool = (b != 0); return result; } -ExactValue make_exact_value_string(String string) { +ExactValue exact_value_string(String string) { // TODO(bill): Allow for numbers with underscores in them ExactValue result = {ExactValue_String}; result.value_string = string; return result; } -ExactValue make_exact_value_integer(i64 i) { +ExactValue exact_value_integer(i64 i) { ExactValue result = {ExactValue_Integer}; result.value_integer = i; return result; } -ExactValue make_exact_value_float(f64 f) { +ExactValue exact_value_float(f64 f) { ExactValue result = {ExactValue_Float}; result.value_float = f; return result; } -ExactValue make_exact_value_pointer(i64 ptr) { +ExactValue exact_value_pointer(i64 ptr) { ExactValue result = {ExactValue_Pointer}; result.value_pointer = ptr; return result; } -ExactValue make_exact_value_integer_from_string(String string) { +ExactValue exact_value_integer_from_string(String string) { // TODO(bill): Allow for numbers with underscores in them i32 base = 10; bool has_prefix = false; @@ -113,12 +113,12 @@ ExactValue make_exact_value_integer_from_string(String string) { } - return make_exact_value_integer(result); + return exact_value_integer(result); } -ExactValue make_exact_value_float_from_string(String string) { +ExactValue exact_value_float_from_string(String string) { isize i = 0; u8 *str = string.text; isize len = string.len; @@ -185,20 +185,20 @@ ExactValue make_exact_value_float_from_string(String string) { } f64 result = sign * (frac ? (value / scale) : (value * scale)); - return make_exact_value_float(result); + return exact_value_float(result); } -ExactValue make_exact_value_from_basic_literal(Token token) { +ExactValue exact_value_from_basic_literal(Token token) { switch (token.kind) { - case Token_String: return make_exact_value_string(token.string); - case Token_Integer: return make_exact_value_integer_from_string(token.string); - case Token_Float: return make_exact_value_float_from_string(token.string); + case Token_String: return exact_value_string(token.string); + case Token_Integer: return exact_value_integer_from_string(token.string); + case Token_Float: return exact_value_float_from_string(token.string); case Token_Rune: { Rune r = GB_RUNE_INVALID; gb_utf8_decode(token.string.text, token.string.len, &r); // gb_printf("%.*s rune: %d\n", LIT(token.string), r); - return make_exact_value_integer(r); + return exact_value_integer(r); } default: GB_PANIC("Invalid token for basic literal"); @@ -217,12 +217,12 @@ ExactValue exact_value_to_integer(ExactValue v) { i64 i = cast(i64)v.value_float; f64 f = cast(f64)i; if (f == v.value_float) { - return make_exact_value_integer(i); + return exact_value_integer(i); } } break; case ExactValue_Pointer: - return make_exact_value_integer(cast(i64)cast(intptr)v.value_pointer); + return exact_value_integer(cast(i64)cast(intptr)v.value_pointer); } ExactValue r = {ExactValue_Invalid}; return r; @@ -231,7 +231,7 @@ ExactValue exact_value_to_integer(ExactValue v) { ExactValue exact_value_to_float(ExactValue v) { switch (v.kind) { case ExactValue_Integer: - return make_exact_value_float(cast(i64)v.value_integer); + return exact_value_float(cast(i64)v.value_integer); case ExactValue_Float: return v; } @@ -287,14 +287,14 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision) i &= ~((~0ll)<<precision); } - return make_exact_value_integer(i); + return exact_value_integer(i); } break; case Token_Not: { switch (v.kind) { case ExactValue_Invalid: return v; case ExactValue_Bool: - return make_exact_value_bool(!v.value_bool); + return exact_value_bool(!v.value_bool); } } break; } @@ -348,7 +348,7 @@ void match_exact_values(ExactValue *x, ExactValue *y) { return; case ExactValue_Float: // TODO(bill): Is this good enough? - *x = make_exact_value_float(cast(f64)x->value_integer); + *x = exact_value_float(cast(f64)x->value_integer); return; } break; @@ -372,10 +372,10 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) case ExactValue_Bool: switch (op) { - case Token_CmpAnd: return make_exact_value_bool(x.value_bool && y.value_bool); - case Token_CmpOr: return make_exact_value_bool(x.value_bool || y.value_bool); - case Token_And: return make_exact_value_bool(x.value_bool & y.value_bool); - case Token_Or: return make_exact_value_bool(x.value_bool | y.value_bool); + case Token_CmpAnd: return exact_value_bool(x.value_bool && y.value_bool); + case Token_CmpOr: return exact_value_bool(x.value_bool || y.value_bool); + case Token_And: return exact_value_bool(x.value_bool & y.value_bool); + case Token_Or: return exact_value_bool(x.value_bool | y.value_bool); default: goto error; } break; @@ -388,7 +388,7 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) case Token_Add: c = a + b; break; case Token_Sub: c = a - b; break; case Token_Mul: c = a * b; break; - case Token_Quo: return make_exact_value_float(fmod(cast(f64)a, cast(f64)b)); + case Token_Quo: return exact_value_float(fmod(cast(f64)a, cast(f64)b)); case Token_QuoEq: c = a / b; break; // NOTE(bill): Integer division case Token_Mod: c = a % b; break; case Token_And: c = a & b; break; @@ -400,17 +400,17 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) default: goto error; } - return make_exact_value_integer(c); + return exact_value_integer(c); } break; case ExactValue_Float: { f64 a = x.value_float; f64 b = y.value_float; switch (op) { - case Token_Add: return make_exact_value_float(a + b); - case Token_Sub: return make_exact_value_float(a - b); - case Token_Mul: return make_exact_value_float(a * b); - case Token_Quo: return make_exact_value_float(a / b); + case Token_Add: return exact_value_float(a + b); + case Token_Sub: return exact_value_float(a - b); + case Token_Mul: return exact_value_float(a * b); + case Token_Quo: return exact_value_float(a / b); default: goto error; } } break; @@ -394,12 +394,12 @@ typedef struct irAddr { // }; } irAddr; -irAddr ir_make_addr(irValue *addr) { +irAddr ir_addr(irValue *addr) { irAddr v = {irAddr_Default, addr}; return v; } -irAddr ir_make_addr_map(irValue *addr, irValue *map_key, Type *map_type, Type *map_result) { +irAddr ir_addr_map(irValue *addr, irValue *map_key, Type *map_type, Type *map_result) { irAddr v = {irAddr_Map, addr}; v.map_key = map_key; v.map_type = map_type; @@ -727,14 +727,14 @@ irDebugInfo *ir_alloc_debug_info(gbAllocator a, irDebugInfoKind kind) { -irValue *ir_make_value_type_name(gbAllocator a, String name, Type *type) { +irValue *ir_value_type_name(gbAllocator a, String name, Type *type) { irValue *v = ir_alloc_value(a, irValue_TypeName); v->TypeName.name = name; v->TypeName.type = type; return v; } -irValue *ir_make_value_global(gbAllocator a, Entity *e, irValue *value) { +irValue *ir_value_global(gbAllocator a, Entity *e, irValue *value) { irValue *v = ir_alloc_value(a, irValue_Global); v->Global.entity = e; v->Global.type = make_type_pointer(a, e->type); @@ -742,7 +742,7 @@ irValue *ir_make_value_global(gbAllocator a, Entity *e, irValue *value) { array_init(&v->Global.referrers, heap_allocator()); // TODO(bill): Replace heap allocator here return v; } -irValue *ir_make_value_param(gbAllocator a, irProcedure *parent, Entity *e) { +irValue *ir_value_param(gbAllocator a, irProcedure *parent, Entity *e) { irValue *v = ir_alloc_value(a, irValue_Param); v->Param.parent = parent; v->Param.entity = e; @@ -750,7 +750,7 @@ irValue *ir_make_value_param(gbAllocator a, irProcedure *parent, Entity *e) { array_init(&v->Param.referrers, heap_allocator()); // TODO(bill): Replace heap allocator here return v; } -irValue *ir_make_value_nil(gbAllocator a, Type *type) { +irValue *ir_value_nil(gbAllocator a, Type *type) { irValue *v = ir_alloc_value(a, irValue_Nil); v->Nil.type = type; return v; @@ -758,7 +758,7 @@ irValue *ir_make_value_nil(gbAllocator a, Type *type) { -irValue *ir_make_instr_local(irProcedure *p, Entity *e, bool zero_initialized) { +irValue *ir_instr_local(irProcedure *p, Entity *e, bool zero_initialized) { irValue *v = ir_alloc_instr(p, irInstr_Local); irInstr *i = &v->Instr; i->Local.entity = e; @@ -770,7 +770,7 @@ irValue *ir_make_instr_local(irProcedure *p, Entity *e, bool zero_initialized) { } -irValue *ir_make_instr_store(irProcedure *p, irValue *address, irValue *value) { +irValue *ir_instr_store(irProcedure *p, irValue *address, irValue *value) { irValue *v = ir_alloc_instr(p, irInstr_Store); irInstr *i = &v->Instr; i->Store.address = address; @@ -778,14 +778,14 @@ irValue *ir_make_instr_store(irProcedure *p, irValue *address, irValue *value) { return v; } -irValue *ir_make_instr_zero_init(irProcedure *p, irValue *address) { +irValue *ir_instr_zero_init(irProcedure *p, irValue *address) { irValue *v = ir_alloc_instr(p, irInstr_ZeroInit); irInstr *i = &v->Instr; i->ZeroInit.address = address; return v; } -irValue *ir_make_instr_load(irProcedure *p, irValue *address) { +irValue *ir_instr_load(irProcedure *p, irValue *address) { irValue *v = ir_alloc_instr(p, irInstr_Load); irInstr *i = &v->Instr; i->Load.address = address; @@ -793,7 +793,7 @@ irValue *ir_make_instr_load(irProcedure *p, irValue *address) { return v; } -irValue *ir_make_instr_array_element_ptr(irProcedure *p, irValue *address, irValue *elem_index) { +irValue *ir_instr_array_element_ptr(irProcedure *p, irValue *address, irValue *elem_index) { irValue *v = ir_alloc_instr(p, irInstr_ArrayElementPtr); irInstr *i = &v->Instr; Type *t = ir_type(address); @@ -811,7 +811,7 @@ irValue *ir_make_instr_array_element_ptr(irProcedure *p, irValue *address, irVal "%s", type_to_string(ir_type(address))); return v; } -irValue *ir_make_instr_struct_element_ptr(irProcedure *p, irValue *address, i32 elem_index, Type *result_type) { +irValue *ir_instr_struct_element_ptr(irProcedure *p, irValue *address, i32 elem_index, Type *result_type) { irValue *v = ir_alloc_instr(p, irInstr_StructElementPtr); irInstr *i = &v->Instr; i->StructElementPtr.address = address; @@ -822,7 +822,7 @@ irValue *ir_make_instr_struct_element_ptr(irProcedure *p, irValue *address, i32 "%s", type_to_string(ir_type(address))); return v; } -irValue *ir_make_instr_ptr_offset(irProcedure *p, irValue *address, irValue *offset) { +irValue *ir_instr_ptr_offset(irProcedure *p, irValue *address, irValue *offset) { irValue *v = ir_alloc_instr(p, irInstr_PtrOffset); irInstr *i = &v->Instr; i->PtrOffset.address = address; @@ -838,7 +838,7 @@ irValue *ir_make_instr_ptr_offset(irProcedure *p, irValue *address, irValue *off -irValue *ir_make_instr_struct_extract_value(irProcedure *p, irValue *address, i32 index, Type *result_type) { +irValue *ir_instr_struct_extract_value(irProcedure *p, irValue *address, i32 index, Type *result_type) { irValue *v = ir_alloc_instr(p, irInstr_StructExtractValue); irInstr *i = &v->Instr; i->StructExtractValue.address = address; @@ -847,7 +847,7 @@ irValue *ir_make_instr_struct_extract_value(irProcedure *p, irValue *address, i3 return v; } -irValue *ir_make_instr_union_tag_ptr(irProcedure *p, irValue *address) { +irValue *ir_instr_union_tag_ptr(irProcedure *p, irValue *address) { irValue *v = ir_alloc_instr(p, irInstr_UnionTagPtr); irInstr *i = &v->Instr; i->UnionTagPtr.address = address; @@ -855,7 +855,7 @@ irValue *ir_make_instr_union_tag_ptr(irProcedure *p, irValue *address) { return v; } -irValue *ir_make_instr_union_tag_value(irProcedure *p, irValue *address) { +irValue *ir_instr_union_tag_value(irProcedure *p, irValue *address) { irValue *v = ir_alloc_instr(p, irInstr_UnionTagValue); irInstr *i = &v->Instr; i->UnionTagValue.address = address; @@ -863,7 +863,7 @@ irValue *ir_make_instr_union_tag_value(irProcedure *p, irValue *address) { return v; } -irValue *ir_make_instr_unary_op(irProcedure *p, TokenKind op, irValue *expr, Type *type) { +irValue *ir_instr_unary_op(irProcedure *p, TokenKind op, irValue *expr, Type *type) { irValue *v = ir_alloc_instr(p, irInstr_UnaryOp); irInstr *i = &v->Instr; i->UnaryOp.op = op; @@ -873,7 +873,7 @@ irValue *ir_make_instr_unary_op(irProcedure *p, TokenKind op, irValue *expr, Typ } -irValue *ir_make_instr_binary_op(irProcedure *p, TokenKind op, irValue *left, irValue *right, Type *type) { +irValue *ir_instr_binary_op(irProcedure *p, TokenKind op, irValue *left, irValue *right, Type *type) { irValue *v = ir_alloc_instr(p, irInstr_BinaryOp); irInstr *i = &v->Instr; i->BinaryOp.op = op; @@ -883,13 +883,13 @@ irValue *ir_make_instr_binary_op(irProcedure *p, TokenKind op, irValue *left, ir return v; } -irValue *ir_make_instr_jump(irProcedure *p, irBlock *block) { +irValue *ir_instr_jump(irProcedure *p, irBlock *block) { irValue *v = ir_alloc_instr(p, irInstr_Jump); irInstr *i = &v->Instr; i->Jump.block = block; return v; } -irValue *ir_make_instr_if(irProcedure *p, irValue *cond, irBlock *true_block, irBlock *false_block) { +irValue *ir_instr_if(irProcedure *p, irValue *cond, irBlock *true_block, irBlock *false_block) { irValue *v = ir_alloc_instr(p, irInstr_If); irInstr *i = &v->Instr; i->If.cond = cond; @@ -899,7 +899,7 @@ irValue *ir_make_instr_if(irProcedure *p, irValue *cond, irBlock *true_block, ir } -irValue *ir_make_instr_phi(irProcedure *p, irValueArray edges, Type *type) { +irValue *ir_instr_phi(irProcedure *p, irValueArray edges, Type *type) { irValue *v = ir_alloc_instr(p, irInstr_Phi); irInstr *i = &v->Instr; i->Phi.edges = edges; @@ -907,18 +907,18 @@ irValue *ir_make_instr_phi(irProcedure *p, irValueArray edges, Type *type) { return v; } -irValue *ir_make_instr_unreachable(irProcedure *p) { +irValue *ir_instr_unreachable(irProcedure *p) { irValue *v = ir_alloc_instr(p, irInstr_Unreachable); return v; } -irValue *ir_make_instr_return(irProcedure *p, irValue *value) { +irValue *ir_instr_return(irProcedure *p, irValue *value) { irValue *v = ir_alloc_instr(p, irInstr_Return); v->Instr.Return.value = value; return v; } -irValue *ir_make_instr_select(irProcedure *p, irValue *cond, irValue *t, irValue *f) { +irValue *ir_instr_select(irProcedure *p, irValue *cond, irValue *t, irValue *f) { irValue *v = ir_alloc_instr(p, irInstr_Select); v->Instr.Select.cond = cond; v->Instr.Select.true_value = t; @@ -926,7 +926,7 @@ irValue *ir_make_instr_select(irProcedure *p, irValue *cond, irValue *t, irValue return v; } -irValue *ir_make_instr_call(irProcedure *p, irValue *value, irValue **args, isize arg_count, Type *result_type) { +irValue *ir_instr_call(irProcedure *p, irValue *value, irValue **args, isize arg_count, Type *result_type) { irValue *v = ir_alloc_instr(p, irInstr_Call); v->Instr.Call.value = value; v->Instr.Call.args = args; @@ -935,7 +935,7 @@ irValue *ir_make_instr_call(irProcedure *p, irValue *value, irValue **args, isiz return v; } -irValue *ir_make_instr_conv(irProcedure *p, irConvKind kind, irValue *value, Type *from, Type *to) { +irValue *ir_instr_conv(irProcedure *p, irConvKind kind, irValue *value, Type *from, Type *to) { irValue *v = ir_alloc_instr(p, irInstr_Conv); v->Instr.Conv.kind = kind; v->Instr.Conv.value = value; @@ -944,20 +944,20 @@ irValue *ir_make_instr_conv(irProcedure *p, irConvKind kind, irValue *value, Typ return v; } -irValue *ir_make_instr_comment(irProcedure *p, String text) { +irValue *ir_instr_comment(irProcedure *p, String text) { irValue *v = ir_alloc_instr(p, irInstr_Comment); v->Instr.Comment.text = text; return v; } -irValue *ir_make_instr_bounds_check(irProcedure *p, TokenPos pos, irValue *index, irValue *len) { +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_make_instr_slice_bounds_check(irProcedure *p, TokenPos pos, irValue *low, irValue *high, irValue *max, bool is_substring) { +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; @@ -966,7 +966,7 @@ irValue *ir_make_instr_slice_bounds_check(irProcedure *p, TokenPos pos, irValue v->Instr.SliceBoundsCheck.is_substring = is_substring; return v; } -irValue *ir_make_instr_debug_declare(irProcedure *p, irDebugInfo *debug_info, AstNode *expr, Entity *entity, bool is_addr, irValue *value) { +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; v->Instr.DebugDeclare.expr = expr; @@ -979,7 +979,7 @@ irValue *ir_make_instr_debug_declare(irProcedure *p, irDebugInfo *debug_info, As -irValue *ir_make_value_constant(gbAllocator a, Type *type, ExactValue value) { +irValue *ir_value_constant(gbAllocator a, Type *type, ExactValue value) { irValue *v = ir_alloc_value(a, irValue_Constant); v->Constant.type = type; v->Constant.value = value; @@ -987,7 +987,7 @@ irValue *ir_make_value_constant(gbAllocator a, Type *type, ExactValue value) { } -irValue *ir_make_value_constant_slice(gbAllocator a, Type *type, irValue *backing_array, i64 count) { +irValue *ir_value_constant_slice(gbAllocator a, Type *type, irValue *backing_array, i64 count) { irValue *v = ir_alloc_value(a, irValue_ConstantSlice); v->ConstantSlice.type = type; v->ConstantSlice.backing_array = backing_array; @@ -1012,32 +1012,32 @@ irValue *ir_emit(irProcedure *proc, irValue *instr) { -irValue *ir_make_const_int(gbAllocator a, i64 i) { - return ir_make_value_constant(a, t_int, make_exact_value_integer(i)); +irValue *ir_const_int(gbAllocator a, i64 i) { + return ir_value_constant(a, t_int, exact_value_integer(i)); } -irValue *ir_make_const_i32(gbAllocator a, i64 i) { - return ir_make_value_constant(a, t_i32, make_exact_value_integer(i)); +irValue *ir_const_i32(gbAllocator a, i64 i) { + return ir_value_constant(a, t_i32, exact_value_integer(i)); } -irValue *ir_make_const_i64(gbAllocator a, i64 i) { - return ir_make_value_constant(a, t_i64, make_exact_value_integer(i)); +irValue *ir_const_i64(gbAllocator a, i64 i) { + return ir_value_constant(a, t_i64, exact_value_integer(i)); } -irValue *ir_make_const_u64(gbAllocator a, u64 i) { - return ir_make_value_constant(a, t_u64, make_exact_value_integer(i)); +irValue *ir_const_u64(gbAllocator a, u64 i) { + return ir_value_constant(a, t_u64, exact_value_integer(i)); } -irValue *ir_make_const_f32(gbAllocator a, f32 f) { - return ir_make_value_constant(a, t_f32, make_exact_value_float(f)); +irValue *ir_const_f32(gbAllocator a, f32 f) { + return ir_value_constant(a, t_f32, exact_value_float(f)); } -irValue *ir_make_const_f64(gbAllocator a, f64 f) { - return ir_make_value_constant(a, t_f64, make_exact_value_float(f)); +irValue *ir_const_f64(gbAllocator a, f64 f) { + return ir_value_constant(a, t_f64, exact_value_float(f)); } -irValue *ir_make_const_bool(gbAllocator a, bool b) { - return ir_make_value_constant(a, t_bool, make_exact_value_bool(b != 0)); +irValue *ir_const_bool(gbAllocator a, bool b) { + return ir_value_constant(a, t_bool, exact_value_bool(b != 0)); } -irValue *ir_make_const_string(gbAllocator a, String s) { - return ir_make_value_constant(a, t_string, make_exact_value_string(s)); +irValue *ir_const_string(gbAllocator a, String s) { + return ir_value_constant(a, t_string, exact_value_string(s)); } -irValue *ir_make_value_procedure(gbAllocator a, irModule *m, Entity *entity, Type *type, AstNode *type_expr, AstNode *body, String name) { +irValue *ir_value_procedure(gbAllocator a, irModule *m, Entity *entity, Type *type, AstNode *type_expr, AstNode *body, String name) { irValue *v = ir_alloc_value(a, irValue_Proc); v->Proc.module = m; v->Proc.entity = entity; @@ -1063,7 +1063,7 @@ irValue *ir_generate_array(irModule *m, Type *elem_type, i64 count, String prefi token.string.len = gb_snprintf(cast(char *)token.string.text, name_len, "%.*s-%llx", LIT(prefix), id)-1; Entity *e = make_entity_variable(a, NULL, token, make_type_array(a, elem_type, count), false); - irValue *value = ir_make_value_global(a, e, NULL); + irValue *value = ir_value_global(a, e, NULL); value->Global.is_private = true; ir_module_add_value(m, e, value); map_ir_value_set(&m->members, hash_string(token.string), value); @@ -1148,7 +1148,7 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) { isize count = cl->elems.count; if (count == 0) { - return ir_make_value_nil(a, type); + return ir_value_nil(a, type); } Type *elem = base_type(type)->Slice.elem; Type *t = make_type_array(a, elem, count); @@ -1163,14 +1163,14 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) { String name = make_string(str, len-1); Entity *e = make_entity_constant(a, NULL, make_token_ident(name), t, value); - irValue *g = ir_make_value_global(a, e, backing_array); + irValue *g = ir_value_global(a, e, backing_array); ir_module_add_value(m, e, g); map_ir_value_set(&m->members, hash_string(name), g); - return ir_make_value_constant_slice(a, type, g, count); + return ir_value_constant_slice(a, type, g, count); } - return ir_make_value_constant(a, type, value); + return ir_value_constant(a, type, value); } irValue *ir_add_global_string_array(irModule *m, String string) { @@ -1188,9 +1188,9 @@ irValue *ir_add_global_string_array(irModule *m, String string) { Token token = {Token_String}; token.string = name; Type *type = make_type_array(a, t_u8, string.len); - ExactValue ev = make_exact_value_string(string); + ExactValue ev = exact_value_string(string); Entity *entity = make_entity_constant(a, NULL, token, type, ev); - irValue *g = ir_make_value_global(a, entity, ir_add_module_constant(m, type, ev)); + irValue *g = ir_value_global(a, entity, ir_add_module_constant(m, type, ev)); g->Global.is_private = true; // g->Global.is_unnamed_addr = true; // g->Global.is_constant = true; @@ -1206,7 +1206,7 @@ irValue *ir_add_global_string_array(irModule *m, String string) { irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr) { irBlock *b = proc->decl_block; // all variables must be in the first block - irValue *instr = ir_make_instr_local(proc, e, true); + irValue *instr = ir_instr_local(proc, e, true); instr->Instr.parent = b; array_add(&b->instrs, instr); array_add(&b->locals, instr); @@ -1218,7 +1218,7 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr) { if (expr != NULL) { irDebugInfo *di = *map_ir_debug_info_get(&proc->module->debug_info, hash_pointer(proc->entity)); - ir_emit(proc, ir_make_instr_debug_declare(proc, di, expr, e, true, instr)); + ir_emit(proc, ir_instr_debug_declare(proc, di, expr, e, true, instr)); } return instr; @@ -1250,7 +1250,7 @@ irValue *ir_add_local_generated(irProcedure *proc, Type *type) { irValue *ir_add_param(irProcedure *proc, Entity *e, AstNode *expr) { - irValue *v = ir_make_value_param(proc->module->allocator, proc, e); + irValue *v = ir_value_param(proc->module->allocator, proc, e); #if 1 irValue *l = ir_add_local(proc, e, expr); ir_emit_store(proc, l, v); @@ -1334,21 +1334,21 @@ irValue *ir_emit_store(irProcedure *p, irValue *address, irValue *value) { GB_ASSERT_MSG(are_types_identical(a, b), "%s %s", type_to_string(a), type_to_string(b)); } #endif - return ir_emit(p, ir_make_instr_store(p, address, value)); + return ir_emit(p, ir_instr_store(p, address, value)); } irValue *ir_emit_load(irProcedure *p, irValue *address) { - return ir_emit(p, ir_make_instr_load(p, address)); + return ir_emit(p, ir_instr_load(p, address)); } irValue *ir_emit_select(irProcedure *p, irValue *cond, irValue *t, irValue *f) { - return ir_emit(p, ir_make_instr_select(p, cond, t, f)); + return ir_emit(p, ir_instr_select(p, cond, t, f)); } irValue *ir_emit_zero_init(irProcedure *p, irValue *address) { - return ir_emit(p, ir_make_instr_zero_init(p, address)); + return ir_emit(p, ir_instr_zero_init(p, address)); } irValue *ir_emit_comment(irProcedure *p, String text) { - return ir_emit(p, ir_make_instr_comment(p, text)); + return ir_emit(p, ir_instr_comment(p, text)); } @@ -1356,7 +1356,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, irValue **args, isize arg_ Type *pt = base_type(ir_type(value)); GB_ASSERT(pt->kind == Type_Proc); Type *results = pt->Proc.results; - return ir_emit(p, ir_make_instr_call(p, value, args, arg_count, results)); + return ir_emit(p, ir_instr_call(p, value, args, arg_count, results)); } irValue *ir_emit_global_call(irProcedure *proc, char *name_, irValue **args, isize arg_count) { @@ -1409,12 +1409,12 @@ void ir_close_scope(irProcedure *proc, irDeferExitKind kind, irBlock *block) { void ir_emit_unreachable(irProcedure *proc) { - ir_emit(proc, ir_make_instr_unreachable(proc)); + ir_emit(proc, ir_instr_unreachable(proc)); } void ir_emit_return(irProcedure *proc, irValue *v) { ir_emit_defer_stmts(proc, irDeferExit_Return, NULL); - ir_emit(proc, ir_make_instr_return(proc, v)); + ir_emit(proc, ir_instr_return(proc, v)); } void ir_emit_jump(irProcedure *proc, irBlock *target_block) { @@ -1422,7 +1422,7 @@ void ir_emit_jump(irProcedure *proc, irBlock *target_block) { if (b == NULL) { return; } - ir_emit(proc, ir_make_instr_jump(proc, target_block)); + ir_emit(proc, ir_instr_jump(proc, target_block)); ir_add_edge(b, target_block); ir_start_block(proc, NULL); } @@ -1432,7 +1432,7 @@ void ir_emit_if(irProcedure *proc, irValue *cond, irBlock *true_block, irBlock * if (b == NULL) { return; } - ir_emit(proc, ir_make_instr_if(proc, cond, true_block, false_block)); + ir_emit(proc, ir_instr_if(proc, cond, true_block, false_block)); ir_add_edge(b, true_block); ir_add_edge(b, false_block); ir_start_block(proc, NULL); @@ -1444,7 +1444,7 @@ void ir_emit_startup_runtime(irProcedure *proc) { } irValue *ir_emit_bitcast(irProcedure *proc, irValue *data, Type *type) { - return ir_emit(proc, ir_make_instr_conv(proc, irConv_bitcast, data, ir_type(data), type)); + return ir_emit(proc, ir_instr_conv(proc, irConv_bitcast, data, ir_type(data), type)); } @@ -1472,9 +1472,9 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val, Type *map_type) i64 entry_size = type_size_of(a, map_type->Map.entry_type); i64 entry_align = type_align_of(a, map_type->Map.entry_type); i64 value_offset = type_offset_of(a, map_type->Map.entry_type, 2); - ir_emit_store(proc, ir_emit_struct_ep(proc, h, 2), ir_make_const_int(a, entry_size)); - ir_emit_store(proc, ir_emit_struct_ep(proc, h, 3), ir_make_const_int(a, entry_align)); - ir_emit_store(proc, ir_emit_struct_ep(proc, h, 4), ir_make_const_int(a, value_offset)); + ir_emit_store(proc, ir_emit_struct_ep(proc, h, 2), ir_const_int(a, entry_size)); + ir_emit_store(proc, ir_emit_struct_ep(proc, h, 3), ir_const_int(a, entry_align)); + ir_emit_store(proc, ir_emit_struct_ep(proc, h, 4), ir_const_int(a, value_offset)); return ir_emit_load(proc, h); @@ -1507,7 +1507,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) { ExactValue ev = str->Constant.value; GB_ASSERT(ev.kind == ExactValue_String); u64 hs = gb_fnv64a(ev.value_string.text, ev.value_string.len); - hashed_str = ir_make_const_u64(proc->module->allocator, hs); + hashed_str = ir_const_u64(proc->module->allocator, hs); } else { irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 1); args[0] = str; @@ -1628,7 +1628,7 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) { // if (addr.kind == irAddr_Vector) { // irValue *v = ir_emit_load(proc, addr.addr); - // return ir_emit(proc, ir_make_instr_extract_element(proc, v, addr.Vector.index)); + // return ir_emit(proc, ir_instr_extract_element(proc, v, addr.Vector.index)); // } Type *t = base_type(ir_type(addr.addr)); if (t->kind == Type_Proc) { @@ -1642,7 +1642,7 @@ irValue *ir_emit_array_epi(irProcedure *proc, irValue *s, i32 index); irValue *ir_emit_ptr_offset(irProcedure *proc, irValue *ptr, irValue *offset) { offset = ir_emit_conv(proc, offset, t_int); - return ir_emit(proc, ir_make_instr_ptr_offset(proc, ptr, offset)); + return ir_emit(proc, ir_instr_ptr_offset(proc, ptr, offset)); } irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *right, Type *type) { @@ -1691,7 +1691,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * irModule *m = proc->module; Type *ptr_type = base_type(t_left); GB_ASSERT(!is_type_rawptr(ptr_type)); - irValue *elem_size = ir_make_const_int(m->allocator, type_size_of(m->allocator, ptr_type->Pointer.elem)); + irValue *elem_size = ir_const_int(m->allocator, type_size_of(m->allocator, ptr_type->Pointer.elem)); irValue *x = ir_emit_conv(proc, left, type); irValue *y = ir_emit_conv(proc, right, type); irValue *diff = ir_emit_arith(proc, op, x, y, type); @@ -1716,7 +1716,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * case Token_AndNot: { // NOTE(bill): x &~ y == x & (~y) == x & (y ~ -1) // NOTE(bill): "not" `x` == `x` "xor" `-1` - irValue *neg = ir_add_module_constant(proc->module, type, make_exact_value_integer(-1)); + irValue *neg = ir_add_module_constant(proc->module, type, exact_value_integer(-1)); op = Token_Xor; right = ir_emit_arith(proc, op, right, neg, type); GB_ASSERT(right->Instr.kind == irInstr_BinaryOp); @@ -1736,7 +1736,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * break; } - return ir_emit(proc, ir_make_instr_binary_op(proc, op, left, right, type)); + return ir_emit(proc, ir_instr_binary_op(proc, op, left, right, type)); } irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irValue *right) { @@ -1780,7 +1780,7 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal } - return ir_emit(proc, ir_make_instr_binary_op(proc, op_kind, left, right, result)); + return ir_emit(proc, ir_instr_binary_op(proc, op_kind, left, right, result)); } irValue *ir_emit_array_ep(irProcedure *proc, irValue *s, irValue *index) { @@ -1792,18 +1792,18 @@ irValue *ir_emit_array_ep(irProcedure *proc, irValue *s, irValue *index) { // NOTE(bill): For some weird legacy reason in LLVM, structure elements must be accessed as an i32 index = ir_emit_conv(proc, index, t_i32); - return ir_emit(proc, ir_make_instr_array_element_ptr(proc, s, index)); + return ir_emit(proc, ir_instr_array_element_ptr(proc, s, index)); } irValue *ir_emit_array_epi(irProcedure *proc, irValue *s, i32 index) { - return ir_emit_array_ep(proc, s, ir_make_const_i32(proc->module->allocator, index)); + return ir_emit_array_ep(proc, s, ir_const_i32(proc->module->allocator, index)); } irValue *ir_emit_union_tag_ptr(irProcedure *proc, irValue *u) { Type *t = ir_type(u); GB_ASSERT(is_type_pointer(t) && is_type_union(type_deref(t))); - irValue *tag_ptr = ir_emit(proc, ir_make_instr_union_tag_ptr(proc, u)); + irValue *tag_ptr = ir_emit(proc, ir_instr_union_tag_ptr(proc, u)); Type *tpt = ir_type(tag_ptr); GB_ASSERT(is_type_pointer(tpt)); tpt = base_type(type_deref(tpt)); @@ -1815,7 +1815,7 @@ irValue *ir_emit_union_tag_value(irProcedure *proc, irValue *u) { Type *t = ir_type(u); GB_ASSERT(is_type_union(t)); GB_ASSERT(are_types_identical(t, ir_type(u))); - return ir_emit(proc, ir_make_instr_union_tag_value(proc, u)); + return ir_emit(proc, ir_instr_union_tag_value(proc, u)); } @@ -1837,7 +1837,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { result_type = make_type_pointer(a, t->Record.fields[index]->type); i64 offset = t->Record.offsets[index]; irValue *ptr = ir_emit_conv(proc, s, t_u8_ptr); - ptr = ir_emit_ptr_offset(proc, ptr, ir_make_const_int(a, offset)); + ptr = ir_emit_ptr_offset(proc, ptr, ir_const_int(a, offset)); return ir_emit_conv(proc, ptr, result_type); } else if (is_type_tuple(t)) { GB_ASSERT(t->Tuple.variable_count > 0); @@ -1878,7 +1878,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { GB_ASSERT(result_type != NULL); - gep = ir_make_instr_struct_element_ptr(proc, s, index, result_type); + gep = ir_instr_struct_element_ptr(proc, s, index, result_type); return ir_emit(proc, gep); } @@ -1902,7 +1902,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) { i64 offset = t->Record.offsets[index]; irValue *ptr = ir_address_from_load_or_generate_local(proc, s); ptr = ir_emit_conv(proc, s, t_u8_ptr); - ptr = ir_emit_ptr_offset(proc, ptr, ir_make_const_int(a, offset)); + ptr = ir_emit_ptr_offset(proc, ptr, ir_const_int(a, offset)); ptr = ir_emit_conv(proc, ptr, ptr_type); return ir_emit_load(proc, ptr); } else if (is_type_tuple(t)) { @@ -1944,7 +1944,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) { GB_ASSERT(result_type != NULL); - return ir_emit(proc, ir_make_instr_struct_extract_value(proc, s, index, result_type)); + return ir_emit(proc, ir_instr_struct_extract_value(proc, s, index, result_type)); } @@ -2055,7 +2055,7 @@ irValue *ir_array_elem(irProcedure *proc, irValue *array) { irValue *ir_array_len(irProcedure *proc, irValue *array) { Type *t = base_type(ir_type(array)); GB_ASSERT(t->kind == Type_Array); - return ir_make_const_int(proc->module->allocator, t->Array.count); + return ir_const_int(proc->module->allocator, t->Array.count); } irValue *ir_vector_elem(irProcedure *proc, irValue *vector) { @@ -2224,7 +2224,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { // if (is_type_untyped_nil(src) && type_has_nil(dst)) { if (is_type_untyped_nil(src)) { - return ir_make_value_nil(proc->module->allocator, t); + return ir_value_nil(proc->module->allocator, t); } if (value->kind == irValue_Constant) { @@ -2244,7 +2244,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { } else if (is_type_pointer(dst)) { // IMPORTANT NOTE(bill): LLVM doesn't support pointer constants expect `null` irValue *i = ir_add_module_constant(proc->module, t_uint, ev); - return ir_emit(proc, ir_make_instr_conv(proc, irConv_inttoptr, i, t_uint, dst)); + return ir_emit(proc, ir_instr_conv(proc, irConv_inttoptr, i, t_uint, dst)); } return ir_add_module_constant(proc->module, t, ev); } @@ -2280,12 +2280,12 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { } } - return ir_emit(proc, ir_make_instr_conv(proc, kind, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, kind, value, src, dst)); } // boolean -> integer if (is_type_boolean(src) && is_type_integer(dst)) { - return ir_emit(proc, ir_make_instr_conv(proc, irConv_zext, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, irConv_zext, value, src, dst)); } // integer -> boolean @@ -2302,7 +2302,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { if (dz >= sz) { kind = irConv_fpext; } - return ir_emit(proc, ir_make_instr_conv(proc, kind, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, kind, value, src, dst)); } // float <-> integer @@ -2311,22 +2311,22 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { if (is_type_unsigned(dst)) { kind = irConv_fptoui; } - return ir_emit(proc, ir_make_instr_conv(proc, kind, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, kind, value, src, dst)); } if (is_type_integer(src) && is_type_float(dst)) { irConvKind kind = irConv_sitofp; if (is_type_unsigned(src)) { kind = irConv_uitofp; } - return ir_emit(proc, ir_make_instr_conv(proc, kind, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, kind, value, src, dst)); } // Pointer <-> int if (is_type_pointer(src) && is_type_int_or_uint(dst)) { - return ir_emit(proc, ir_make_instr_conv(proc, irConv_ptrtoint, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, irConv_ptrtoint, value, src, dst)); } if (is_type_int_or_uint(src) && is_type_pointer(dst)) { - return ir_emit(proc, ir_make_instr_conv(proc, irConv_inttoptr, value, src, dst)); + return ir_emit(proc, ir_instr_conv(proc, irConv_inttoptr, value, src, dst)); } if (is_type_union(dst)) { @@ -2337,7 +2337,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { gbAllocator allocator = proc->module->allocator; irValue *parent = ir_add_local_generated(proc, t); irValue *tag_ptr = ir_emit_union_tag_ptr(proc, parent); - ir_emit_store(proc, tag_ptr, ir_make_const_int(allocator, i)); + ir_emit_store(proc, tag_ptr, ir_const_int(allocator, i)); irValue *underlying = ir_emit_conv(proc, parent, make_type_pointer(allocator, src_type)); ir_emit_store(proc, underlying, value); @@ -2535,7 +2535,7 @@ irValue *ir_emit_down_cast(irProcedure *proc, irValue *value, Type *t) { irValue *bytes = ir_emit_conv(proc, value, t_u8_ptr); i64 offset_ = type_offset_of_from_selection(allocator, type_deref(t), sel); - irValue *offset = ir_make_const_int(allocator, -offset_); + irValue *offset = ir_const_int(allocator, -offset_); irValue *head = ir_emit_ptr_offset(proc, bytes, offset); return ir_emit_conv(proc, head, t); } @@ -2567,7 +2567,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token for (isize i = 1; i < src->Record.variant_count; i++) { Entity *f = src->Record.variants[i]; if (are_types_identical(f->type, dst)) { - dst_tag = ir_make_const_int(a, i); + dst_tag = ir_const_int(a, i); break; } } @@ -2602,7 +2602,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token for (isize i = 1; i < src->Record.variant_count; i++) { Entity *f = src->Record.variants[i]; if (are_types_identical(f->type, dst)) { - dst_tag = ir_make_const_int(a, i); + dst_tag = ir_const_int(a, i); break; } } @@ -2633,9 +2633,9 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token irValue **args = gb_alloc_array(a, irValue *, 6); args[0] = ok; - args[1] = ir_make_const_string(a, pos.file); - args[2] = ir_make_const_int(a, pos.line); - args[3] = ir_make_const_int(a, pos.column); + args[1] = ir_const_string(a, pos.file); + args[2] = ir_const_int(a, pos.line); + args[3] = ir_const_int(a, pos.column); args[4] = ir_type_info(proc, src_type); args[5] = ir_type_info(proc, dst_type); @@ -2699,7 +2699,7 @@ irValue *ir_type_info(irProcedure *proc, Type *type) { // gb_printf_err("%d %s\n", entry_index, type_to_string(type)); - return ir_emit_array_ep(proc, ir_global_type_info_data, ir_make_const_i32(proc->module->allocator, entry_index)); + return ir_emit_array_ep(proc, ir_global_type_info_data, ir_const_i32(proc->module->allocator, entry_index)); } @@ -2762,7 +2762,7 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) { ir_emit_jump(proc, done); ir_start_block(proc, done); - return ir_emit(proc, ir_make_instr_phi(proc, edges, type)); + return ir_emit(proc, ir_instr_phi(proc, edges, type)); #endif } @@ -2775,7 +2775,7 @@ 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_make_instr_bounds_check(proc, token.pos, index, len)); + 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) { @@ -2786,7 +2786,7 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir low = ir_emit_conv(proc, low, t_int); high = ir_emit_conv(proc, high, t_int); - ir_emit(proc, ir_make_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring)); + ir_emit(proc, ir_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring)); } @@ -2797,6 +2797,69 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir // //////////////////////////////////////////////////////////////// +String ir_mangle_name(irGen *s, String path, Entity *e) { + // NOTE(bill): prefix names not in the init scope + // TODO(bill): make robust and not just rely on the file's name + String name = e->token.string; + irModule *m = &s->module; + CheckerInfo *info = m->info; + gbAllocator a = m->allocator; + AstFile *file = *map_ast_file_get(&info->files, hash_string(path)); + + char *str = gb_alloc_array(a, char, path.len+1); + gb_memmove(str, path.text, path.len); + str[path.len] = 0; + for (isize i = 0; i < path.len; i++) { + if (str[i] == '\\') { + str[i] = '/'; + } + } + + char const *base = gb_path_base_name(str); + char const *ext = gb_path_extension(base); + isize base_len = ext-1-base; + + isize max_len = base_len + 1 + 10 + 1 + name.len; + bool is_overloaded = check_is_entity_overloaded(e); + if (is_overloaded) { + max_len += 21; + } + + u8 *new_name = gb_alloc_array(a, u8, max_len); + isize new_name_len = gb_snprintf( + cast(char *)new_name, max_len, + "%.*s-%u.%.*s", + cast(int)base_len, base, + file->id, + LIT(name)); + if (is_overloaded) { + char *str = cast(char *)new_name + new_name_len-1; + isize len = max_len-new_name_len; + isize extra = gb_snprintf(str, len, "-%tu", cast(usize)cast(uintptr)e); + new_name_len += extra-1; + } + + return make_string(new_name, new_name_len-1); +} + + +void ir_mangle_add_sub_type_name(irModule *m, Entity *field, String parent) { + if (field->kind != Entity_TypeName) { + return; + } + + String cn = field->token.string; + isize len = parent.len + 1 + 16 + 1 + cn.len; + u8 *text = gb_alloc_array(m->allocator, u8, len); + isize new_name_len = gb_snprintf(cast(char *)text, len, + "%.*s.%.*s", LIT(parent), LIT(cn)); + + String child = {text, new_name_len-1}; + map_string_set(&m->type_names, hash_pointer(field->type), child); + ir_gen_global_type_name(m, field, child); +} + + void ir_push_target_list(irProcedure *proc, irBlock *break_, irBlock *continue_, irBlock *fallthrough_) { irTargetList *tl = gb_alloc_item(proc->module->allocator, irTargetList); @@ -2812,28 +2875,8 @@ void ir_pop_target_list(irProcedure *proc) { } -void ir_mangle_sub_type_name(irModule *m, Entity *field, String parent) { - if (field->kind != Entity_TypeName) { - return; - } - String cn = field->token.string; - - isize len = parent.len + 1 + cn.len; - String child = {NULL, len}; - child.text = gb_alloc_array(m->allocator, u8, len); - - isize i = 0; - gb_memmove(child.text+i, parent.text, parent.len); - i += parent.len; - child.text[i++] = '.'; - gb_memmove(child.text+i, cn.text, cn.len); - - map_string_set(&m->type_names, hash_pointer(field->type), child); - ir_gen_global_type_name(m, field, child); -} - void ir_gen_global_type_name(irModule *m, Entity *e, String name) { - irValue *t = ir_make_value_type_name(m->allocator, name, e->type); + irValue *t = ir_value_type_name(m->allocator, name, e->type); ir_module_add_value(m, e, t); map_ir_value_set(&m->members, hash_string(name), t); @@ -2841,7 +2884,7 @@ void ir_gen_global_type_name(irModule *m, Entity *e, String name) { Type *bt = base_type(e->type); // NOTE(bill): Zeroth entry is null (for `match type` stmts) for (isize j = 1; j < bt->Record.variant_count; j++) { - ir_mangle_sub_type_name(m, bt->Record.variants[j], name); + ir_mangle_add_sub_type_name(m, bt->Record.variants[j], name); } } } @@ -2903,7 +2946,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv LIT(token.pos.file), token.pos.line, token.pos.column); return NULL; } else if (e->kind == Entity_Nil) { - return ir_make_value_nil(proc->module->allocator, tv->type); + return ir_value_nil(proc->module->allocator, tv->type); } irValue **found = map_ir_value_get(&proc->module->values, hash_pointer(e)); @@ -2968,7 +3011,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv Type *type = type_of_expr(proc->module->info, expr); - return ir_emit(proc, ir_make_instr_phi(proc, edges, type)); + return ir_emit(proc, ir_instr_phi(proc, edges, type)); case_end; #if 0 @@ -3008,7 +3051,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv Type *type = type_of_expr(proc->module->info, expr); - return ir_emit(proc, ir_make_instr_phi(proc, edges, type)); + return ir_emit(proc, ir_instr_phi(proc, edges, type)); case_end; #endif @@ -3051,7 +3094,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv case Token_Not: // Boolean not case Token_Xor: // Bitwise not case Token_Sub: // Bitwise not - return ir_emit(proc, ir_make_instr_unary_op(proc, ue->op.kind, ir_build_expr(proc, ue->expr), tv->type)); + return ir_emit(proc, ir_instr_unary_op(proc, ue->op.kind, ir_build_expr(proc, ue->expr), tv->type)); } case_end; @@ -3106,7 +3149,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv String name = make_string(name_text, name_len-1); Type *type = type_of_expr(proc->module->info, expr); - irValue *value = ir_make_value_procedure(proc->module->allocator, + irValue *value = ir_value_procedure(proc->module->allocator, proc->module, NULL, type, pl->type, pl->body, name); value->Proc.tags = pl->tags; @@ -3159,8 +3202,8 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv i64 a = type_align_of(allocator, type); irValue **args = gb_alloc_array(allocator, irValue *, 2); - args[0] = ir_make_const_int(allocator, s); - args[1] = ir_make_const_int(allocator, a); + args[0] = ir_const_int(allocator, s); + args[1] = ir_const_int(allocator, a); irValue *call = ir_emit_global_call(proc, "alloc_align", args, 2); irValue *v = ir_emit_conv(proc, call, ptr_type); return v; @@ -3179,8 +3222,8 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv i64 s = type_size_of(allocator, type); i64 a = type_align_of(allocator, type); - irValue *elem_size = ir_make_const_int(allocator, s); - irValue *elem_align = ir_make_const_int(allocator, a); + irValue *elem_size = ir_const_int(allocator, s); + irValue *elem_align = ir_const_int(allocator, a); irValue *count = ir_emit_conv(proc, ir_build_expr(proc, ce->args.e[1]), t_int); irValue *capacity = count; @@ -3293,8 +3336,8 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv if (is_type_dynamic_array(type)) { Type *elem = type->DynamicArray.elem; - irValue *elem_size = ir_make_const_int(a, type_size_of(a, elem)); - irValue *elem_align = ir_make_const_int(a, type_align_of(a, elem)); + irValue *elem_size = ir_const_int(a, type_size_of(a, elem)); + irValue *elem_align = ir_const_int(a, type_align_of(a, elem)); ptr = ir_emit_conv(proc, ptr, t_rawptr); @@ -3356,8 +3399,8 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv GB_PANIC("Invalid type to append"); } - irValue *elem_size = ir_make_const_int(a, type_size_of(a, elem_type)); - irValue *elem_align = ir_make_const_int(a, type_align_of(a, elem_type)); + irValue *elem_size = ir_const_int(a, type_size_of(a, elem_type)); + irValue *elem_align = ir_const_int(a, type_align_of(a, elem_type)); array_ptr = ir_emit_conv(proc, array_ptr, t_rawptr); @@ -3411,7 +3454,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv } irValue *base_elem = ir_emit_array_epi(proc, base_array, 0); - irValue *len = ir_make_const_int(a, slice_len); + irValue *len = ir_const_int(a, slice_len); ir_fill_slice(proc, slice, base_elem, len, len); } @@ -3478,10 +3521,10 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 4); - args[0] = ir_make_const_string(proc->module->allocator, pos.file); - args[1] = ir_make_const_int(proc->module->allocator, pos.line); - args[2] = ir_make_const_int(proc->module->allocator, pos.column); - args[3] = ir_make_const_string(proc->module->allocator, expr_str); + args[0] = ir_const_string(proc->module->allocator, pos.file); + args[1] = ir_const_int(proc->module->allocator, pos.line); + args[2] = ir_const_int(proc->module->allocator, pos.column); + args[3] = ir_const_string(proc->module->allocator, expr_str); ir_emit_global_call(proc, "__assert", args, 4); ir_emit_jump(proc, done); @@ -3499,9 +3542,9 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv TokenPos pos = token.pos; irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 4); - args[0] = ir_make_const_string(proc->module->allocator, pos.file); - args[1] = ir_make_const_int(proc->module->allocator, pos.line); - args[2] = ir_make_const_int(proc->module->allocator, pos.column); + args[0] = ir_const_string(proc->module->allocator, pos.file); + args[1] = ir_const_int(proc->module->allocator, pos.line); + args[2] = ir_const_int(proc->module->allocator, pos.column); args[3] = msg; ir_emit_global_call(proc, "__panic", args, 4); @@ -3530,7 +3573,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv irValue *cond = ir_emit_comp(proc, Token_Lt, len_dst, len_src); irValue *len = ir_emit_select(proc, cond, len_dst, len_src); - irValue *elem_size = ir_make_const_int(proc->module->allocator, size_of_elem); + irValue *elem_size = ir_const_int(proc->module->allocator, size_of_elem); irValue *byte_count = ir_emit_arith(proc, Token_Mul, len, elem_size, t_int); irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 3); @@ -3567,7 +3610,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv } ir_emit_comment(proc, str_lit("swizzle.end")); return ir_emit_load(proc, dst); - // return ir_emit(proc, ir_make_instr_vector_shuffle(proc, vector, indices, index_count)); + // return ir_emit(proc, ir_instr_vector_shuffle(proc, vector, indices, index_count)); } break; case BuiltinProc_slice_ptr: { @@ -3594,7 +3637,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv irValue *ptr = ir_emit_conv(proc, ir_slice_elem(proc, s), t_u8_ptr); irValue *count = ir_slice_count(proc, s); - count = ir_emit_arith(proc, Token_Mul, count, ir_make_const_int(proc->module->allocator, elem_size), t_int); + count = ir_emit_arith(proc, Token_Mul, count, ir_const_int(proc->module->allocator, elem_size), t_int); ir_fill_slice(proc, slice, ptr, count, count); return ir_emit_load(proc, slice); } break; @@ -3623,7 +3666,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv Type *t = ir_type(x); irValue *zero = ir_emit_conv(proc, v_zero, t); irValue *cond = ir_emit_comp(proc, Token_Lt, x, zero); - irValue *neg = ir_emit(proc, ir_make_instr_unary_op(proc, Token_Sub, x, t)); + irValue *neg = ir_emit(proc, ir_instr_unary_op(proc, Token_Sub, x, t)); return ir_emit_select(proc, cond, neg, x); } break; @@ -3719,7 +3762,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv } irValue *base_elem = ir_emit_array_epi(proc, base_array, 0); - irValue *len = ir_make_const_int(allocator, slice_len); + irValue *len = ir_const_int(allocator, slice_len); ir_fill_slice(proc, slice, base_elem, len, len); } @@ -3817,7 +3860,7 @@ irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { GB_PANIC("Unknown value: %.*s, entity: %p %.*s\n", LIT(e->token.string), e, LIT(entity_strings[e->kind])); } - return ir_make_addr(v); + return ir_addr(v); } irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { @@ -3831,7 +3874,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } GB_ASSERT(v != NULL); - return ir_make_addr(v); + return ir_addr(v); case_end; case_ast_node(i, Ident, expr); @@ -3883,7 +3926,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *record_info = ir_emit_conv(proc, ti_ptr, t_type_info_record_ptr); names_ptr = ir_emit_struct_ep(proc, record_info, 1); } - return ir_make_addr(names_ptr); + return ir_addr(names_ptr); } else { GB_PANIC("Unhandled TypeField %.*s", LIT(name)); } @@ -3895,7 +3938,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *a = ir_build_addr(proc, se->expr).addr; a = ir_emit_deep_field_gep(proc, type, a, sel); - return ir_make_addr(a); + return ir_addr(a); } else { Type *type = base_type(type_of_expr(proc->module->info, se->expr)); GB_ASSERT(is_type_integer(type)); @@ -3907,7 +3950,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *a = ir_build_addr(proc, se->expr).addr; a = ir_emit_deep_field_gep(proc, type, a, sel); - return ir_make_addr(a); + return ir_addr(a); } case_end; @@ -3919,7 +3962,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *type = type_of_expr(proc->module->info, expr); irValue *v = ir_add_local_generated(proc, type); ir_emit_store(proc, v, ir_emit_conv(proc, ir_build_expr(proc, ce->expr), type)); - return ir_make_addr(v); + return ir_addr(v); } case Token_transmute: { ir_emit_comment(proc, str_lit("Cast - transmute")); @@ -3927,7 +3970,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *type = type_of_expr(proc->module->info, expr); irValue *v = ir_add_local_generated(proc, type); ir_emit_store(proc, v, ir_emit_transmute(proc, ir_build_expr(proc, ce->expr), type)); - return ir_make_addr(v); + return ir_addr(v); } case Token_down_cast: { ir_emit_comment(proc, str_lit("Cast - down_cast")); @@ -3935,7 +3978,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *type = type_of_expr(proc->module->info, expr); irValue *v = ir_add_local_generated(proc, type); ir_emit_store(proc, v, ir_emit_down_cast(proc, ir_build_expr(proc, ce->expr), type)); - return ir_make_addr(v); + return ir_addr(v); } default: GB_PANIC("Unknown cast expression"); @@ -3960,7 +4003,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { // Type *type = type_of_expr(proc->module->info, expr); // irValue *v = ir_add_local_generated(proc, type); // ir_emit_store(proc, v, ir_emit_conv(proc, ir_build_expr(proc, be->left), type)); - // return ir_make_addr(v); + // return ir_addr(v); // } // case Token_transmute: { // ir_emit_comment(proc, str_lit("Cast - transmute")); @@ -3968,7 +4011,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { // Type *type = type_of_expr(proc->module->info, expr); // irValue *v = ir_add_local_generated(proc, type); // ir_emit_store(proc, v, ir_emit_transmute(proc, ir_build_expr(proc, be->left), type)); - // return ir_make_addr(v); + // return ir_addr(v); // } default: GB_PANIC("Invalid binary expression for ir_build_addr: %.*s\n", LIT(be->op.string)); @@ -3991,7 +4034,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { key = ir_emit_conv(proc, key, t->Map.key); Type *result_type = type_of_expr(proc->module->info, expr); - return ir_make_addr_map(map_val, key, t, result_type); + return ir_addr_map(map_val, key, t, result_type); } irValue *using_addr = NULL; @@ -4021,9 +4064,9 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); irValue *elem = ir_emit_array_ep(proc, vector, index); - irValue *len = ir_make_const_int(a, t->Vector.count); + irValue *len = ir_const_int(a, t->Vector.count); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); - return ir_make_addr(elem); + return ir_addr(elem); } break; case Type_Array: { @@ -4038,9 +4081,9 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); irValue *elem = ir_emit_array_ep(proc, array, index); - irValue *len = ir_make_const_int(a, t->Vector.count); + irValue *len = ir_const_int(a, t->Vector.count); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); - return ir_make_addr(elem); + return ir_addr(elem); } break; case Type_Slice: { @@ -4058,7 +4101,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); irValue *v = ir_emit_ptr_offset(proc, elem, index); - return ir_make_addr(v); + return ir_addr(v); } break; case Type_DynamicArray: { @@ -4076,7 +4119,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); irValue *v = ir_emit_ptr_offset(proc, elem, index); - return ir_make_addr(v); + return ir_addr(v); } break; @@ -4101,7 +4144,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); - return ir_make_addr(ir_emit_ptr_offset(proc, elem, index)); + return ir_addr(ir_emit_ptr_offset(proc, elem, index)); } break; } case_end; @@ -4142,7 +4185,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int); irValue *slice = ir_add_local_generated(proc, slice_type); ir_fill_slice(proc, slice, elem, len, cap); - return ir_make_addr(slice); + return ir_addr(slice); } case Type_DynamicArray: { @@ -4158,7 +4201,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int); irValue *slice = ir_add_local_generated(proc, dynamic_array); ir_fill_slice(proc, slice, elem, len, cap); - return ir_make_addr(slice); + return ir_addr(slice); } @@ -4175,7 +4218,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int); irValue *slice = ir_add_local_generated(proc, slice_type); ir_fill_slice(proc, slice, elem, len, cap); - return ir_make_addr(slice); + return ir_addr(slice); } case Type_Basic: { @@ -4192,7 +4235,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { ir_emit_store(proc, ir_emit_struct_ep(proc, str, 0), elem); ir_emit_store(proc, ir_emit_struct_ep(proc, str, 1), len); - return ir_make_addr(str); + return ir_addr(str); } break; } @@ -4203,7 +4246,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { // TODO(bill): Is a ptr copy needed? irValue *addr = ir_build_expr(proc, de->expr); addr = ir_emit_ptr_offset(proc, addr, v_zero); - return ir_make_addr(addr); + return ir_addr(addr); case_end; case_ast_node(ce, CallExpr, expr); @@ -4211,7 +4254,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *e = ir_build_expr(proc, expr); irValue *v = ir_add_local_generated(proc, ir_type(e)); ir_emit_store(proc, v, e); - return ir_make_addr(v); + return ir_addr(v); case_end; case_ast_node(cl, CompoundLit, expr); @@ -4238,7 +4281,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { ir_emit_store(proc, ir_emit_array_epi(proc, v, i), elem_val); } } else if (cl->elems.count > 0) { - ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, make_exact_value_compound(expr))); + ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); for_array(i, cl->elems) { AstNode *elem = cl->elems.e[i]; if (ir_is_elem_const(proc->module, elem, et)) { @@ -4261,7 +4304,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { GB_ASSERT(is_type_struct(bt) || is_type_union(bt)); TypeRecord *st = &bt->Record; if (cl->elems.count > 0) { - ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, make_exact_value_compound(expr))); + ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); for_array(field_index, cl->elems) { AstNode *elem = cl->elems.e[field_index]; @@ -4303,14 +4346,14 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } Type *elem = bt->DynamicArray.elem; gbAllocator a = proc->module->allocator; - irValue *size = ir_make_const_int(a, type_size_of(a, elem)); - irValue *align = ir_make_const_int(a, type_align_of(a, elem)); + irValue *size = ir_const_int(a, type_size_of(a, elem)); + irValue *align = ir_const_int(a, type_align_of(a, elem)); { irValue **args = gb_alloc_array(a, irValue *, 4); args[0] = ir_emit_conv(proc, v, t_rawptr); args[1] = size; args[2] = align; - args[3] = ir_make_const_int(a, 2*cl->elems.count); + args[3] = ir_const_int(a, 2*cl->elems.count); ir_emit_global_call(proc, "__dynamic_array_reserve", args, 4); } @@ -4330,7 +4373,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { args[1] = size; args[2] = align; args[3] = ir_emit_conv(proc, items, t_rawptr); - args[4] = ir_make_const_int(a, item_count); + args[4] = ir_const_int(a, item_count); ir_emit_global_call(proc, "__dynamic_array_append", args, 5); } } break; @@ -4343,7 +4386,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { { irValue **args = gb_alloc_array(a, irValue *, 2); args[0] = ir_gen_map_header(proc, v, type); - args[1] = ir_make_const_int(a, 2*cl->elems.count); + args[1] = ir_const_int(a, 2*cl->elems.count); ir_emit_global_call(proc, "__dynamic_map_reserve", args, 2); } for_array(field_index, cl->elems) { @@ -4358,7 +4401,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case Type_Array: { if (cl->elems.count > 0) { - ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, make_exact_value_compound(expr))); + ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); for_array(i, cl->elems) { AstNode *elem = cl->elems.e[i]; if (ir_is_elem_const(proc->module, elem, et)) { @@ -4378,7 +4421,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *elem_type = bt->Slice.elem; Type *elem_ptr_type = make_type_pointer(proc->module->allocator, elem_type); Type *elem_ptr_ptr_type = make_type_pointer(proc->module->allocator, elem_ptr_type); - irValue *slice = ir_add_module_constant(proc->module, type, make_exact_value_compound(expr)); + irValue *slice = ir_add_module_constant(proc->module, type, exact_value_compound(expr)); GB_ASSERT(slice->kind == irValue_ConstantSlice); irValue *data = ir_emit_array_ep(proc, slice->ConstantSlice.backing_array, v_zero32); @@ -4393,11 +4436,11 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *t = ir_type(field_expr); GB_ASSERT(t->kind != Type_Tuple); irValue *ev = ir_emit_conv(proc, field_expr, elem_type); - irValue *offset = ir_emit_ptr_offset(proc, data, ir_make_const_int(proc->module->allocator, i)); + irValue *offset = ir_emit_ptr_offset(proc, data, ir_const_int(proc->module->allocator, i)); ir_emit_store(proc, offset, ev); } - irValue *count = ir_make_const_int(proc->module->allocator, slice->ConstantSlice.count); + irValue *count = ir_const_int(proc->module->allocator, slice->ConstantSlice.count); ir_fill_slice(proc, v, data, count, count); } } break; @@ -4405,7 +4448,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case Type_Basic: { GB_ASSERT(is_type_any(bt)); if (cl->elems.count > 0) { - ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, make_exact_value_compound(expr))); + ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); String field_names[2] = { str_lit("type_info"), str_lit("data"), @@ -4445,7 +4488,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } } - return ir_make_addr(v); + return ir_addr(v); case_end; } @@ -4457,7 +4500,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { LIT(token_pos.file), token_pos.line, token_pos.column); - return ir_make_addr(NULL); + return ir_addr(NULL); } void ir_build_assign_op(irProcedure *proc, irAddr lhs, irValue *value, TokenKind op) { @@ -4577,10 +4620,10 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir Type *expr_type = base_type(type_deref(ir_type(expr))); switch (expr_type->kind) { case Type_Array: - count = ir_make_const_int(proc->module->allocator, expr_type->Array.count); + count = ir_const_int(proc->module->allocator, expr_type->Array.count); break; case Type_Vector: - count = ir_make_const_int(proc->module->allocator, expr_type->Vector.count); + count = ir_const_int(proc->module->allocator, expr_type->Vector.count); break; } @@ -4596,7 +4639,7 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir } irValue *index = ir_add_local_generated(proc, t_int); - ir_emit_store(proc, index, ir_make_const_int(proc->module->allocator, -1)); + ir_emit_store(proc, index, ir_const_int(proc->module->allocator, -1)); loop = ir_new_block(proc, NULL, "for.index.loop"); ir_emit_jump(proc, loop); @@ -4752,7 +4795,7 @@ void ir_build_range_interval(irProcedure *proc, AstNodeIntervalExpr *node, Type ir_emit_store(proc, value, lower); irValue *index = ir_add_local_generated(proc, t_int); - ir_emit_store(proc, index, ir_make_const_int(proc->module->allocator, 0)); + ir_emit_store(proc, index, ir_const_int(proc->module->allocator, 0)); loop = ir_new_block(proc, NULL, "for.interval.loop"); ir_emit_jump(proc, loop); @@ -4832,7 +4875,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { for_array(i, vd->names) { AstNode *name = vd->names.e[i]; - irAddr lval = ir_make_addr(NULL); + irAddr lval = ir_addr(NULL); if (!ir_is_blank_ident(name)) { ir_add_local_for_identifier(proc, name, false); lval = ir_build_addr(proc, name); @@ -4882,7 +4925,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(ts_name), guid); String name = make_string(name_text, name_len-1); - irValue *value = ir_make_value_type_name(proc->module->allocator, + irValue *value = ir_value_type_name(proc->module->allocator, name, e->type); map_string_set(&proc->module->type_names, hash_pointer(e->type), name); ir_gen_global_type_name(proc->module, e, name); @@ -4915,7 +4958,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { String name = make_string(name_text, name_len-1); - irValue *value = ir_make_value_procedure(proc->module->allocator, + irValue *value = ir_value_procedure(proc->module->allocator, proc->module, e, e->type, pd->type, pd->body, name); value->Proc.tags = pd->tags; @@ -4934,7 +4977,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { name = pd->foreign_name; } - irValue *value = ir_make_value_procedure(proc->module->allocator, + irValue *value = ir_value_procedure(proc->module->allocator, proc->module, e, e->type, pd->type, pd->body, name); value->Proc.tags = pd->tags; @@ -5235,7 +5278,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { array = ir_emit_load(proc, array); } count_ptr = ir_add_local_generated(proc, t_int); - ir_emit_store(proc, count_ptr, ir_make_const_int(proc->module->allocator, et->Array.count)); + ir_emit_store(proc, count_ptr, ir_const_int(proc->module->allocator, et->Array.count)); ir_build_range_indexed(proc, array, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_Vector: { @@ -5245,7 +5288,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { vector = ir_emit_load(proc, vector); } count_ptr = ir_add_local_generated(proc, t_int); - ir_emit_store(proc, count_ptr, ir_make_const_int(proc->module->allocator, et->Vector.count)); + ir_emit_store(proc, count_ptr, ir_const_int(proc->module->allocator, et->Vector.count)); ir_build_range_indexed(proc, vector, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_DynamicArray: { @@ -5493,7 +5536,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { for (isize variant_index = 1; variant_index < ut->Record.variant_count; variant_index++) { Entity *f = ut->Record.variants[variant_index]; if (are_types_identical(f->type, bt)) { - index = ir_make_const_int(allocator, variant_index); + index = ir_const_int(allocator, variant_index); break; } } @@ -5599,7 +5642,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irValue *prev_context = ir_add_local_generated(proc, t_context); ir_emit_store(proc, prev_context, ir_emit_load(proc, context_ptr)); - ir_add_defer_instr(proc, proc->scope_index, ir_make_instr_store(proc, context_ptr, ir_emit_load(proc, prev_context))); + ir_add_defer_instr(proc, proc->scope_index, ir_instr_store(proc, context_ptr, ir_emit_load(proc, prev_context))); irValue *gep = ir_emit_struct_ep(proc, context_ptr, 1); ir_emit_store(proc, gep, ir_build_expr(proc, pa->expr)); @@ -5618,7 +5661,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irValue *prev_context = ir_add_local_generated(proc, t_context); ir_emit_store(proc, prev_context, ir_emit_load(proc, context_ptr)); - ir_add_defer_instr(proc, proc->scope_index, ir_make_instr_store(proc, context_ptr, ir_emit_load(proc, prev_context))); + ir_add_defer_instr(proc, proc->scope_index, ir_instr_store(proc, context_ptr, ir_emit_load(proc, prev_context))); ir_emit_store(proc, context_ptr, ir_build_expr(proc, pa->expr)); @@ -5835,7 +5878,7 @@ void ir_init_module(irModule *m, Checker *c) { String name = str_lit(IR_TYPE_INFO_DATA_NAME); Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_type_info, max_type_info_count), false); - irValue *g = ir_make_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, NULL); g->Global.is_private = true; ir_module_add_value(m, e, g); map_ir_value_set(&m->members, hash_string(name), g); @@ -5874,7 +5917,7 @@ void ir_init_module(irModule *m, Checker *c) { String name = str_lit(IR_TYPE_INFO_TYPES_NAME); Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_type_info_ptr, count), false); - irValue *g = ir_make_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, NULL); ir_module_add_value(m, e, g); map_ir_value_set(&m->members, hash_string(name), g); ir_global_type_info_member_types = g; @@ -5883,7 +5926,7 @@ void ir_init_module(irModule *m, Checker *c) { String name = str_lit(IR_TYPE_INFO_NAMES_NAME); Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_string, count), false); - irValue *g = ir_make_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, NULL); ir_module_add_value(m, e, g); map_ir_value_set(&m->members, hash_string(name), g); ir_global_type_info_member_names = g; @@ -5892,7 +5935,7 @@ void ir_init_module(irModule *m, Checker *c) { String name = str_lit(IR_TYPE_INFO_OFFSETS_NAME); Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_int, count), false); - irValue *g = ir_make_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, NULL); ir_module_add_value(m, e, g); map_ir_value_set(&m->members, hash_string(name), g); ir_global_type_info_member_offsets = g; @@ -5957,50 +6000,6 @@ void ir_gen_destroy(irGen *s) { gb_file_close(&s->output_file); } -String ir_mangle_name(irGen *s, String path, Entity *e) { - // NOTE(bill): prefix names not in the init scope - // TODO(bill): make robust and not just rely on the file's name - String name = e->token.string; - irModule *m = &s->module; - CheckerInfo *info = m->info; - gbAllocator a = m->allocator; - AstFile *file = *map_ast_file_get(&info->files, hash_string(path)); - - char *str = gb_alloc_array(a, char, path.len+1); - gb_memmove(str, path.text, path.len); - str[path.len] = 0; - for (isize i = 0; i < path.len; i++) { - if (str[i] == '\\') { - str[i] = '/'; - } - } - - char const *base = gb_path_base_name(str); - char const *ext = gb_path_extension(base); - isize base_len = ext-1-base; - - isize max_len = base_len + 1 + 10 + 1 + name.len; - bool is_overloaded = check_is_entity_overloaded(e); - if (is_overloaded) { - max_len += 21; - } - - u8 *new_name = gb_alloc_array(a, u8, max_len); - isize new_name_len = gb_snprintf( - cast(char *)new_name, max_len, - "%.*s-%u.%.*s", - cast(int)base_len, base, - file->id, - LIT(name)); - if (is_overloaded) { - char *str = cast(char *)new_name + new_name_len-1; - isize len = max_len-new_name_len; - isize extra = gb_snprintf(str, len, "-%tu", cast(usize)cast(uintptr)e); - new_name_len += extra-1; - } - - return make_string(new_name, new_name_len-1); -} // @@ -6060,14 +6059,14 @@ void ir_gen_tree(irGen *s) { gbAllocator a = m->allocator; if (v_zero == NULL) { - v_zero = ir_make_const_int (m->allocator, 0); - v_one = ir_make_const_int (m->allocator, 1); - v_zero32 = ir_make_const_i32 (m->allocator, 0); - v_one32 = ir_make_const_i32 (m->allocator, 1); - v_two32 = ir_make_const_i32 (m->allocator, 2); - v_false = ir_make_const_bool(m->allocator, false); - v_true = ir_make_const_bool(m->allocator, true); - v_raw_nil = ir_make_value_constant(m->allocator, t_rawptr, make_exact_value_pointer(0)); + v_zero = ir_const_int (m->allocator, 0); + v_one = ir_const_int (m->allocator, 1); + v_zero32 = ir_const_i32 (m->allocator, 0); + v_one32 = ir_const_i32 (m->allocator, 1); + v_two32 = ir_const_i32 (m->allocator, 2); + v_false = ir_const_bool(m->allocator, false); + v_true = ir_const_bool(m->allocator, true); + v_raw_nil = ir_value_constant(m->allocator, t_rawptr, exact_value_pointer(0)); } isize global_variable_max_count = 0; @@ -6142,7 +6141,7 @@ void ir_gen_tree(irGen *s) { break; case Entity_Variable: { - irValue *g = ir_make_value_global(a, e, NULL); + irValue *g = ir_value_global(a, e, NULL); g->Global.is_thread_local = e->Variable.is_thread_local; irGlobalVariable var = {0}; @@ -6185,7 +6184,7 @@ void ir_gen_tree(irGen *s) { AstNode *type_expr = decl->proc_lit->ProcLit.type; - irValue *p = ir_make_value_procedure(a, m, e, e->type, type_expr, body, name); + irValue *p = ir_value_procedure(a, m, e, e->type, type_expr, body, name); p->Proc.tags = pd->tags; ir_module_add_value(m, e, p); @@ -6260,7 +6259,7 @@ void ir_gen_tree(irGen *s) { AstNode *body = gb_alloc_item(a, AstNode); Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_make_value_procedure(a, m, e, proc_type, NULL, body, name); + irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); map_ir_value_set(&m->values, hash_pointer(e), p); map_ir_value_set(&m->members, hash_string(name), p); @@ -6319,7 +6318,7 @@ void ir_gen_tree(irGen *s) { AstNode *body = gb_alloc_item(a, AstNode); Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_make_value_procedure(a, m, e, proc_type, NULL, body, name); + irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); m->entry_point_entity = e; @@ -6344,7 +6343,7 @@ void ir_gen_tree(irGen *s) { NULL, 0, false, ProcCC_Odin); AstNode *body = gb_alloc_item(a, AstNode); Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_make_value_procedure(a, m, e, proc_type, NULL, body, name); + irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); map_ir_value_set(&m->values, hash_pointer(e), p); map_ir_value_set(&m->members, hash_string(name), p); @@ -6389,7 +6388,7 @@ void ir_gen_tree(irGen *s) { irValue *global_type_table = ir_find_global_variable(proc, str_lit("__type_table")); Type *type = base_type(type_deref(ir_type(ir_global_type_info_data))); GB_ASSERT(is_type_array(type)); - irValue *len = ir_make_const_int(proc->module->allocator, type->Array.count); + irValue *len = ir_const_int(proc->module->allocator, type->Array.count); ir_fill_slice(proc, global_type_table, ir_emit_array_epi(proc, ir_global_type_info_data, 0), len, len); @@ -6420,7 +6419,7 @@ void ir_gen_tree(irGen *s) { tag = ir_emit_conv(proc, ti_ptr, t_type_info_named_ptr); // TODO(bill): Which is better? The mangled name or actual name? - irValue *name = ir_make_const_string(a, t->Named.type_name->token.string); + irValue *name = ir_const_string(a, t->Named.type_name->token.string); irValue *gtip = ir_get_type_info_ptr(proc, t->Named.base); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), name); @@ -6447,8 +6446,8 @@ void ir_gen_tree(irGen *s) { case Basic_uint: { tag = ir_emit_conv(proc, ti_ptr, t_type_info_integer_ptr); bool is_unsigned = (t->Basic.flags & BasicFlag_Unsigned) != 0; - irValue *bits = ir_make_const_int(a, type_size_of(a, t)); - irValue *is_signed = ir_make_const_bool(a, !is_unsigned); + irValue *bits = ir_const_int(a, type_size_of(a, t)); + irValue *is_signed = ir_const_bool(a, !is_unsigned); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), bits); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), is_signed); } break; @@ -6459,7 +6458,7 @@ void ir_gen_tree(irGen *s) { // case Basic_f128: { tag = ir_emit_conv(proc, ti_ptr, t_type_info_float_ptr); - irValue *bits = ir_make_const_int(a, type_size_of(a, t)); + irValue *bits = ir_const_int(a, type_size_of(a, t)); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), bits); } break; @@ -6491,10 +6490,10 @@ void ir_gen_tree(irGen *s) { isize ez = type_size_of(a, t->Array.elem); irValue *elem_size = ir_emit_struct_ep(proc, tag, 1); - ir_emit_store(proc, elem_size, ir_make_const_int(a, ez)); + ir_emit_store(proc, elem_size, ir_const_int(a, ez)); irValue *count = ir_emit_struct_ep(proc, tag, 2); - ir_emit_store(proc, count, ir_make_const_int(a, t->Array.count)); + ir_emit_store(proc, count, ir_const_int(a, t->Array.count)); } break; case Type_DynamicArray: { @@ -6505,7 +6504,7 @@ void ir_gen_tree(irGen *s) { isize ez = type_size_of(a, t->DynamicArray.elem); irValue *elem_size = ir_emit_struct_ep(proc, tag, 1); - ir_emit_store(proc, elem_size, ir_make_const_int(a, ez)); + ir_emit_store(proc, elem_size, ir_const_int(a, ez)); } break; case Type_Slice: { ir_emit_comment(proc, str_lit("Type_Info_Slice")); @@ -6515,7 +6514,7 @@ void ir_gen_tree(irGen *s) { isize ez = type_size_of(a, t->Slice.elem); irValue *elem_size = ir_emit_struct_ep(proc, tag, 1); - ir_emit_store(proc, elem_size, ir_make_const_int(a, ez)); + ir_emit_store(proc, elem_size, ir_const_int(a, ez)); } break; case Type_Vector: { ir_emit_comment(proc, str_lit("Type_Info_Vector")); @@ -6524,9 +6523,9 @@ void ir_gen_tree(irGen *s) { ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep); isize ez = type_size_of(a, t->Vector.elem); - ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), ir_make_const_int(a, ez)); - ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), ir_make_const_int(a, t->Vector.count)); - ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), ir_make_const_int(a, type_align_of(a, t))); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), ir_const_int(a, ez)); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), ir_const_int(a, t->Vector.count)); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), ir_const_int(a, type_align_of(a, t))); } break; case Type_Proc: { @@ -6544,8 +6543,8 @@ void ir_gen_tree(irGen *s) { if (t->Proc.results != NULL) { ir_emit_store(proc, results, ir_get_type_info_ptr(proc, t->Proc.results)); } - ir_emit_store(proc, variadic, ir_make_const_bool(a, t->Proc.variadic)); - ir_emit_store(proc, convention, ir_make_const_int(a, t->Proc.calling_convention)); + ir_emit_store(proc, variadic, ir_const_bool(a, t->Proc.variadic)); + ir_emit_store(proc, convention, ir_const_int(a, t->Proc.calling_convention)); // TODO(bill): Type_Info for procedures } break; @@ -6555,7 +6554,7 @@ void ir_gen_tree(irGen *s) { irValue *record = ir_emit_struct_ep(proc, tag, 0); { - irValue *align = ir_make_const_int(a, type_align_of(a, t)); + irValue *align = ir_const_int(a, type_align_of(a, t)); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align); } @@ -6566,17 +6565,17 @@ void ir_gen_tree(irGen *s) { // NOTE(bill): offset is not used for tuples Entity *f = t->Tuple.variables[i]; - irValue *index = ir_make_const_int(a, i); + irValue *index = ir_const_int(a, i); irValue *type_info = ir_emit_ptr_offset(proc, memory_types, index); ir_emit_store(proc, type_info, ir_type_info(proc, f->type)); if (f->token.string.len > 0) { irValue *name = ir_emit_ptr_offset(proc, memory_names, index); - ir_emit_store(proc, name, ir_make_const_string(a, f->token.string)); + ir_emit_store(proc, name, ir_const_string(a, f->token.string)); } } - irValue *count = ir_make_const_int(a, t->Tuple.variable_count); + irValue *count = ir_const_int(a, t->Tuple.variable_count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 0), memory_types, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 1), memory_names, count, count); } break; @@ -6588,11 +6587,11 @@ void ir_gen_tree(irGen *s) { irValue *record = ir_emit_struct_ep(proc, tag, 0); { - irValue *size = ir_make_const_int(a, type_size_of(a, t)); - irValue *align = ir_make_const_int(a, type_align_of(a, t)); - irValue *packed = ir_make_const_bool(a, t->Record.is_packed); - irValue *ordered = ir_make_const_bool(a, t->Record.is_ordered); - irValue *custom_align = ir_make_const_bool(a, t->Record.custom_align); + irValue *size = ir_const_int(a, type_size_of(a, t)); + irValue *align = ir_const_int(a, type_align_of(a, t)); + irValue *packed = ir_const_bool(a, t->Record.is_packed); + irValue *ordered = ir_const_bool(a, t->Record.is_ordered); + irValue *custom_align = ir_const_bool(a, t->Record.custom_align); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), size); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 5), packed); @@ -6612,19 +6611,19 @@ void ir_gen_tree(irGen *s) { i64 foffset = t->Record.offsets[f->Variable.field_index]; GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field); - irValue *index = ir_make_const_int(a, source_index); + irValue *index = ir_const_int(a, source_index); irValue *type_info = ir_emit_ptr_offset(proc, memory_types, index); irValue *offset = ir_emit_ptr_offset(proc, memory_offsets, index); ir_emit_store(proc, type_info, ir_type_info(proc, f->type)); if (f->token.string.len > 0) { irValue *name = ir_emit_ptr_offset(proc, memory_names, index); - ir_emit_store(proc, name, ir_make_const_string(a, f->token.string)); + ir_emit_store(proc, name, ir_const_string(a, f->token.string)); } - ir_emit_store(proc, offset, ir_make_const_int(a, foffset)); + ir_emit_store(proc, offset, ir_const_int(a, foffset)); } - irValue *count = ir_make_const_int(a, t->Record.field_count); + irValue *count = ir_const_int(a, t->Record.field_count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 0), memory_types, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 1), memory_names, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 2), memory_offsets, count, count); @@ -6633,8 +6632,8 @@ void ir_gen_tree(irGen *s) { ir_emit_comment(proc, str_lit("Type_Info_Union")); tag = ir_emit_conv(proc, ti_ptr, t_type_info_union_ptr); { - irValue *size = ir_make_const_int(a, type_size_of(a, t)); - irValue *align = ir_make_const_int(a, type_align_of(a, t)); + irValue *size = ir_const_int(a, type_size_of(a, t)); + irValue *align = ir_const_int(a, type_align_of(a, t)); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), size); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 4), align); } @@ -6655,20 +6654,20 @@ void ir_gen_tree(irGen *s) { i64 foffset = t->Record.offsets[f->Variable.field_index]; GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field); - irValue *index = ir_make_const_int(a, field_index); + irValue *index = ir_const_int(a, field_index); irValue *type_info = ir_emit_ptr_offset(proc, memory_types, index); irValue *offset = ir_emit_ptr_offset(proc, memory_offsets, index); ir_emit_store(proc, type_info, ir_type_info(proc, f->type)); if (f->token.string.len > 0) { irValue *name = ir_emit_ptr_offset(proc, memory_names, index); - ir_emit_store(proc, name, ir_make_const_string(a, f->token.string)); + ir_emit_store(proc, name, ir_const_string(a, f->token.string)); } - ir_emit_store(proc, offset, ir_make_const_int(a, foffset)); + ir_emit_store(proc, offset, ir_const_int(a, foffset)); } - irValue *count = ir_make_const_int(a, field_count); + irValue *count = ir_const_int(a, field_count); ir_fill_slice(proc, ir_emit_struct_ep(proc, common_fields, 0), memory_types, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, common_fields, 1), memory_names, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, common_fields, 2), memory_offsets, count, count); @@ -6687,17 +6686,17 @@ void ir_gen_tree(irGen *s) { Entity *f = t->Record.variants[variant_index+1]; // Skip zeroth irValue *tip = ir_get_type_info_ptr(proc, f->type); - irValue *index = ir_make_const_int(a, variant_index); + irValue *index = ir_const_int(a, variant_index); irValue *type_info = ir_emit_ptr_offset(proc, memory_types, index); ir_emit_store(proc, type_info, ir_type_info(proc, f->type)); if (f->token.string.len > 0) { irValue *name = ir_emit_ptr_offset(proc, memory_names, index); - ir_emit_store(proc, name, ir_make_const_string(a, f->token.string)); + ir_emit_store(proc, name, ir_const_string(a, f->token.string)); } } - irValue *count = ir_make_const_int(a, variant_count); + irValue *count = ir_const_int(a, variant_count); ir_fill_slice(proc, variant_names, memory_names, count, count); ir_fill_slice(proc, variant_types, memory_types, count, count); } @@ -6709,8 +6708,8 @@ void ir_gen_tree(irGen *s) { irValue *record = ir_emit_struct_ep(proc, tag, 0); { - irValue *size = ir_make_const_int(a, type_size_of(a, t)); - irValue *align = ir_make_const_int(a, type_align_of(a, t)); + irValue *size = ir_const_int(a, type_size_of(a, t)); + irValue *align = ir_const_int(a, type_align_of(a, t)); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), size); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align); } @@ -6721,18 +6720,18 @@ void ir_gen_tree(irGen *s) { for (isize i = 0; i < t->Record.field_count; i++) { Entity *f = t->Record.fields[i]; - irValue *index = ir_make_const_int(a, i); + irValue *index = ir_const_int(a, i); irValue *type_info = ir_emit_ptr_offset(proc, memory_types, index); // NOTE(bill): Offsets are always 0 ir_emit_store(proc, type_info, ir_type_info(proc, f->type)); if (f->token.string.len > 0) { irValue *name = ir_emit_ptr_offset(proc, memory_names, index); - ir_emit_store(proc, name, ir_make_const_string(a, f->token.string)); + ir_emit_store(proc, name, ir_const_string(a, f->token.string)); } } - irValue *count = ir_make_const_int(a, t->Record.field_count); + irValue *count = ir_const_int(a, t->Record.field_count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 0), memory_types, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 1), memory_names, count, count); ir_fill_slice(proc, ir_emit_struct_ep(proc, record, 2), memory_offsets, count, count); @@ -6764,18 +6763,18 @@ void ir_gen_tree(irGen *s) { if (is_value_int) { i64 i = value.value_integer; value_ep = ir_emit_conv(proc, value_ep, t_i64_ptr); - ir_emit_store(proc, value_ep, ir_make_const_i64(a, i)); + ir_emit_store(proc, value_ep, ir_const_i64(a, i)); } else { GB_ASSERT(is_type_float(t->Record.enum_base_type)); f64 f = value.value_float; value_ep = ir_emit_conv(proc, value_ep, t_f64_ptr); - ir_emit_store(proc, value_ep, ir_make_const_f64(a, f)); + ir_emit_store(proc, value_ep, ir_const_f64(a, f)); } - ir_emit_store(proc, name_ep, ir_make_const_string(a, fields[i]->token.string)); + ir_emit_store(proc, name_ep, ir_const_string(a, fields[i]->token.string)); } - irValue *v_count = ir_make_const_int(a, count); + irValue *v_count = ir_const_int(a, count); irValue *names = ir_emit_struct_ep(proc, tag, 1); irValue *name_array_elem = ir_array_elem(proc, name_array); @@ -6805,7 +6804,7 @@ void ir_gen_tree(irGen *s) { ir_emit_store(proc, key, ir_get_type_info_ptr(proc, t->Map.key)); ir_emit_store(proc, value, ir_get_type_info_ptr(proc, t->Map.value)); ir_emit_store(proc, generated_struct, ir_get_type_info_ptr(proc, t->Map.generated_struct_type)); - ir_emit_store(proc, count, ir_make_const_int(a, t->Map.count)); + ir_emit_store(proc, count, ir_const_int(a, t->Map.count)); } break; } @@ -6819,7 +6818,7 @@ void ir_gen_tree(irGen *s) { Entity *f = ti->Record.variants[i]; if (are_types_identical(f->type, tag_type)) { found = true; - irValue *tag = ir_make_const_int(a, i); + irValue *tag = ir_const_int(a, i); irValue *ptr = ir_emit_union_tag_ptr(proc, ti_ptr); ir_emit_store(proc, ptr, tag); break; diff --git a/src/ir_print.c b/src/ir_print.c index cca26b925..a25eef288 100644 --- a/src/ir_print.c +++ b/src/ir_print.c @@ -942,7 +942,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { switch (uo->op) { case Token_Sub: if (is_type_float(elem_type)) { - ir_print_exact_value(f, m, make_exact_value_float(0), type); + ir_print_exact_value(f, m, exact_value_float(0), type); } else { ir_fprintf(f, "0"); } @@ -1197,17 +1197,17 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { ir_fprintf(f, "call void "); ir_print_encoded_global(f, str_lit("__bounds_check_error"), false); ir_fprintf(f, "("); - ir_print_compound_element(f, m, make_exact_value_string(bc->pos.file), t_string); + ir_print_compound_element(f, m, exact_value_string(bc->pos.file), t_string); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); ir_fprintf(f, " "); - ir_print_exact_value(f, m, make_exact_value_integer(bc->pos.line), t_int); + ir_print_exact_value(f, m, exact_value_integer(bc->pos.line), t_int); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); ir_fprintf(f, " "); - ir_print_exact_value(f, m, make_exact_value_integer(bc->pos.column), t_int); + ir_print_exact_value(f, m, exact_value_integer(bc->pos.column), t_int); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); @@ -1232,17 +1232,17 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { } ir_fprintf(f, "("); - ir_print_compound_element(f, m, make_exact_value_string(bc->pos.file), t_string); + ir_print_compound_element(f, m, exact_value_string(bc->pos.file), t_string); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); ir_fprintf(f, " "); - ir_print_exact_value(f, m, make_exact_value_integer(bc->pos.line), t_int); + ir_print_exact_value(f, m, exact_value_integer(bc->pos.line), t_int); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); ir_fprintf(f, " "); - ir_print_exact_value(f, m, make_exact_value_integer(bc->pos.column), t_int); + ir_print_exact_value(f, m, exact_value_integer(bc->pos.column), t_int); ir_fprintf(f, ", "); ir_print_type(f, m, t_int); @@ -1408,10 +1408,6 @@ void print_llvm_ir(irGen *ir) { irFileBuffer buf = {0}, *f = &buf; ir_file_buffer_init(f, &ir->output_file); - if (m->layout.len > 0) { - ir_fprintf(f, "target datalayout = \"%.*s\"\n", LIT(m->layout)); - } - ir_print_encoded_local(f, str_lit("..string")); ir_fprintf(f, " = type {i8*, "); ir_print_type(f, m, t_int); diff --git a/src/main.c b/src/main.c index 233f6ba93..6ccd47cf5 100644 --- a/src/main.c +++ b/src/main.c @@ -8,9 +8,8 @@ extern "C" { #include "build_settings.c" #include "tokenizer.c" #include "parser.c" -// #include "printer.c" #include "checker.c" -// #include "ssa.c" +// #include "bytecode.c" #include "ir.c" #include "ir_opt.c" #include "ir_print.c" @@ -144,6 +143,7 @@ int main(int argc, char **argv) { init_scratch_memory(gb_megabytes(10)); init_global_error_collector(); + #if 1 init_build_context(); @@ -217,7 +217,7 @@ int main(int argc, char **argv) { return 1; } - if (!ssa_generate(&checker.info)) { + if (!bc_generate(&checker.info)) { return 1; } #else diff --git a/src/types.c b/src/types.c index 362e949fb..0d986ea1b 100644 --- a/src/types.c +++ b/src/types.c @@ -1215,7 +1215,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n // NOTE(bill): Underlying memory address cannot be changed if (str_eq(field_name, count_str)) { // HACK(bill): Memory leak - sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, make_exact_value_integer(type->Array.count)); + sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, exact_value_integer(type->Array.count)); return sel; } } else if (type->kind == Type_Vector) { @@ -1223,7 +1223,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n // NOTE(bill): Vectors are not addressable if (str_eq(field_name, count_str)) { // HACK(bill): Memory leak - sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, make_exact_value_integer(type->Vector.count)); + sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, exact_value_integer(type->Vector.count)); return sel; } |