Refactoring of code: remove make prefix on many procedures

This commit is contained in:
Ginger Bill
2017-03-05 15:03:01 +00:00
parent 4ef4605d6d
commit 5adfbec847
8 changed files with 404 additions and 409 deletions
+25 -25
View File
@@ -746,9 +746,9 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
constant_type = named_type; constant_type = named_type;
} }
ExactValue iota = make_exact_value_integer(-1); ExactValue iota = exact_value_integer(-1);
ExactValue min_value = make_exact_value_integer(0); ExactValue min_value = exact_value_integer(0);
ExactValue max_value = make_exact_value_integer(0); ExactValue max_value = exact_value_integer(0);
for_array(i, et->fields) { for_array(i, et->fields) {
AstNode *field = et->fields.e[i]; 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) { if (o.mode != Addressing_Invalid) {
iota = o.value; iota = o.value;
} else { } 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 { } 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.field_count = field_count;
enum_type->Record.enum_count = make_entity_constant(c->allocator, c->context.scope, 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, 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); 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, 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->mode = Addressing_Constant;
x->type = t_untyped_bool; x->type = t_untyped_bool;
x->value = make_exact_value_bool(comp); x->value = exact_value_bool(comp);
return; return;
} }
@@ -1913,7 +1913,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) {
} else { } else {
if (x->mode == Addressing_Constant && if (x->mode == Addressing_Constant &&
y->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 { } else {
x->mode = Addressing_Value; 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->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)) { if (is_type_typed(x->type)) {
check_is_expressible(c, x, base_type(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; new_ptr_val -= elem_size*offset_val;
} }
operand.mode = Addressing_Constant; operand.mode = Addressing_Constant;
operand.value = make_exact_value_pointer(new_ptr_val); operand.value = exact_value_pointer(new_ptr_val);
} }
return operand; return operand;
@@ -2372,7 +2372,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
GB_ASSERT(op.kind == Token_Sub); GB_ASSERT(op.kind == Token_Sub);
i64 bytes = a.value_pointer - b.value_pointer; i64 bytes = a.value_pointer - b.value_pointer;
i64 diff = bytes/type_size_of(c->allocator, type); i64 diff = bytes/type_size_of(c->allocator, type);
x->value = make_exact_value_pointer(diff); x->value = exact_value_pointer(diff);
return; 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)) { operand->type != NULL && is_type_untyped(operand->type) && is_type_string(operand->type)) {
String s = operand->value.value_string; String s = operand->value.value_string;
operand->mode = Addressing_Constant; operand->mode = Addressing_Constant;
operand->value = make_exact_value_integer(s.len); operand->value = exact_value_integer(s.len);
operand->type = t_untyped_integer; operand->type = t_untyped_integer;
return NULL; return NULL;
} }
@@ -3158,7 +3158,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
operand->mode = Addressing_Constant; 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; operand->type = t_untyped_integer;
} break; } break;
@@ -3171,7 +3171,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
operand->mode = Addressing_Constant; 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; operand->type = t_untyped_integer;
break; break;
@@ -3183,7 +3183,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
return false; return false;
} }
operand->mode = Addressing_Constant; 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; operand->type = t_untyped_integer;
} break; } break;
@@ -3195,7 +3195,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
operand->mode = Addressing_Constant; 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; operand->type = t_untyped_integer;
break; break;
@@ -3239,7 +3239,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
operand->mode = Addressing_Constant; 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; operand->type = t_untyped_integer;
} break; } break;
@@ -3288,7 +3288,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->mode = Addressing_Constant; operand->mode = Addressing_Constant;
// IMPORTANT TODO(bill): Fix for anonymous fields // 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; operand->type = t_untyped_integer;
} break; } 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_a = cast(u8 *)operand->value.value_pointer;
u8 *ptr_b = cast(u8 *)op.value.value_pointer; u8 *ptr_b = cast(u8 *)op.value.value_pointer;
isize elem_size = type_size_of(c->allocator, ptr_type->Pointer.elem); 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 { } else {
operand->mode = Addressing_Value; 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->mode = Addressing_Constant;
o->type = t; o->type = t;
o->value = make_exact_value_from_basic_literal(*bl); o->value = exact_value_from_basic_literal(*bl);
case_end; case_end;
case_ast_node(bd, BasicDirective, node); case_ast_node(bd, BasicDirective, node);
if (str_eq(bd->name, str_lit("file"))) { if (str_eq(bd->name, str_lit("file"))) {
o->type = t_untyped_string; 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"))) { } else if (str_eq(bd->name, str_lit("line"))) {
o->type = t_untyped_integer; 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"))) { } else if (str_eq(bd->name, str_lit("procedure"))) {
if (c->proc_stack.count == 0) { if (c->proc_stack.count == 0) {
error_node(node, "#procedure may only be used within procedures"); error_node(node, "#procedure may only be used within procedures");
o->type = t_untyped_string; o->type = t_untyped_string;
o->value = make_exact_value_string(str_lit("")); o->value = exact_value_string(str_lit(""));
} else { } else {
o->type = t_untyped_string; 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 { } else {
@@ -4850,7 +4850,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
if (is_constant) { if (is_constant) {
o->mode = Addressing_Constant; o->mode = Addressing_Constant;
o->value = make_exact_value_compound(node); o->value = exact_value_compound(node);
} else { } else {
o->mode = Addressing_Value; o->mode = Addressing_Value;
} }
+1 -1
View File
@@ -850,7 +850,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} else { } else {
x.mode = Addressing_Constant; x.mode = Addressing_Constant;
x.type = t_bool; x.type = t_bool;
x.value = make_exact_value_bool(true); x.value = exact_value_bool(true);
Token token = {0}; Token token = {0};
token.pos = ast_node_token(ms->body).pos; token.pos = ast_node_token(ms->body).pos;
+20 -20
View File
@@ -208,21 +208,21 @@ ExprInfo make_expr_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue
#include "map.c" #include "map.c"
typedef struct Scope { typedef struct Scope {
Scope * parent; Scope * parent;
Scope * prev, *next; Scope * prev, *next;
Scope * first_child; Scope * first_child;
Scope * last_child; Scope * last_child;
MapEntity elements; // Key: String MapEntity elements; // Key: String
MapBool implicit; // Key: Entity * MapBool implicit; // Key: Entity *
Array(Scope *) shared; Array(Scope *) shared;
Array(Scope *) imported; Array(Scope *) imported;
bool is_proc; bool is_proc;
bool is_global; bool is_global;
bool is_file; bool is_file;
bool is_init; bool is_init;
bool has_been_imported; // This is only applicable to file scopes bool has_been_imported; // This is only applicable to file scopes
AstFile * file; AstFile * file;
} Scope; } Scope;
gb_global Scope *universal_scope = NULL; gb_global Scope *universal_scope = NULL;
@@ -357,9 +357,9 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) {
Scope *s = gb_alloc_item(allocator, Scope); Scope *s = gb_alloc_item(allocator, Scope);
s->parent = parent; s->parent = parent;
map_entity_init(&s->elements, heap_allocator()); map_entity_init(&s->elements, heap_allocator());
map_bool_init(&s->implicit, heap_allocator()); map_bool_init(&s->implicit, heap_allocator());
array_init(&s->shared, heap_allocator()); array_init(&s->shared, heap_allocator());
array_init(&s->imported, heap_allocator()); array_init(&s->imported, heap_allocator());
if (parent != NULL && parent != universal_scope) { if (parent != NULL && parent != universal_scope) {
DLIST_APPEND(parent->first_child, parent->last_child, s); 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) { 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 // Constants
add_global_constant(a, str_lit("true"), t_untyped_bool, make_exact_value_bool(true)); add_global_constant(a, str_lit("true"), t_untyped_bool, 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("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_nil(a, str_lit("nil"), t_untyped_nil));
add_global_entity(make_entity_library_name(a, universal_scope, add_global_entity(make_entity_library_name(a, universal_scope,
+31 -31
View File
@@ -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}; ExactValue result = {ExactValue_Compound};
result.value_compound = node; result.value_compound = node;
return result; return result;
} }
ExactValue make_exact_value_bool(bool b) { ExactValue exact_value_bool(bool b) {
ExactValue result = {ExactValue_Bool}; ExactValue result = {ExactValue_Bool};
result.value_bool = (b != 0); result.value_bool = (b != 0);
return result; return result;
} }
ExactValue make_exact_value_string(String string) { ExactValue exact_value_string(String string) {
// TODO(bill): Allow for numbers with underscores in them // TODO(bill): Allow for numbers with underscores in them
ExactValue result = {ExactValue_String}; ExactValue result = {ExactValue_String};
result.value_string = string; result.value_string = string;
return result; return result;
} }
ExactValue make_exact_value_integer(i64 i) { ExactValue exact_value_integer(i64 i) {
ExactValue result = {ExactValue_Integer}; ExactValue result = {ExactValue_Integer};
result.value_integer = i; result.value_integer = i;
return result; return result;
} }
ExactValue make_exact_value_float(f64 f) { ExactValue exact_value_float(f64 f) {
ExactValue result = {ExactValue_Float}; ExactValue result = {ExactValue_Float};
result.value_float = f; result.value_float = f;
return result; return result;
} }
ExactValue make_exact_value_pointer(i64 ptr) { ExactValue exact_value_pointer(i64 ptr) {
ExactValue result = {ExactValue_Pointer}; ExactValue result = {ExactValue_Pointer};
result.value_pointer = ptr; result.value_pointer = ptr;
return result; 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 // TODO(bill): Allow for numbers with underscores in them
i32 base = 10; i32 base = 10;
bool has_prefix = false; 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; isize i = 0;
u8 *str = string.text; u8 *str = string.text;
isize len = string.len; 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)); 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) { switch (token.kind) {
case Token_String: return make_exact_value_string(token.string); case Token_String: return exact_value_string(token.string);
case Token_Integer: return make_exact_value_integer_from_string(token.string); case Token_Integer: return exact_value_integer_from_string(token.string);
case Token_Float: return make_exact_value_float_from_string(token.string); case Token_Float: return exact_value_float_from_string(token.string);
case Token_Rune: { case Token_Rune: {
Rune r = GB_RUNE_INVALID; Rune r = GB_RUNE_INVALID;
gb_utf8_decode(token.string.text, token.string.len, &r); gb_utf8_decode(token.string.text, token.string.len, &r);
// gb_printf("%.*s rune: %d\n", LIT(token.string), r); // gb_printf("%.*s rune: %d\n", LIT(token.string), r);
return make_exact_value_integer(r); return exact_value_integer(r);
} }
default: default:
GB_PANIC("Invalid token for basic literal"); 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; i64 i = cast(i64)v.value_float;
f64 f = cast(f64)i; f64 f = cast(f64)i;
if (f == v.value_float) { if (f == v.value_float) {
return make_exact_value_integer(i); return exact_value_integer(i);
} }
} break; } break;
case ExactValue_Pointer: 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}; ExactValue r = {ExactValue_Invalid};
return r; return r;
@@ -231,7 +231,7 @@ ExactValue exact_value_to_integer(ExactValue v) {
ExactValue exact_value_to_float(ExactValue v) { ExactValue exact_value_to_float(ExactValue v) {
switch (v.kind) { switch (v.kind) {
case ExactValue_Integer: 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: case ExactValue_Float:
return v; return v;
} }
@@ -287,14 +287,14 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision)
i &= ~((~0ll)<<precision); i &= ~((~0ll)<<precision);
} }
return make_exact_value_integer(i); return exact_value_integer(i);
} break; } break;
case Token_Not: { case Token_Not: {
switch (v.kind) { switch (v.kind) {
case ExactValue_Invalid: return v; case ExactValue_Invalid: return v;
case ExactValue_Bool: case ExactValue_Bool:
return make_exact_value_bool(!v.value_bool); return exact_value_bool(!v.value_bool);
} }
} break; } break;
} }
@@ -348,7 +348,7 @@ void match_exact_values(ExactValue *x, ExactValue *y) {
return; return;
case ExactValue_Float: case ExactValue_Float:
// TODO(bill): Is this good enough? // 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; return;
} }
break; break;
@@ -372,10 +372,10 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
case ExactValue_Bool: case ExactValue_Bool:
switch (op) { switch (op) {
case Token_CmpAnd: 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 make_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 make_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 make_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; default: goto error;
} }
break; 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_Add: c = a + b; break;
case Token_Sub: c = a - b; break; case Token_Sub: c = a - b; break;
case Token_Mul: 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_QuoEq: c = a / b; break; // NOTE(bill): Integer division
case Token_Mod: c = a % b; break; case Token_Mod: c = a % b; break;
case Token_And: 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; default: goto error;
} }
return make_exact_value_integer(c); return exact_value_integer(c);
} break; } break;
case ExactValue_Float: { case ExactValue_Float: {
f64 a = x.value_float; f64 a = x.value_float;
f64 b = y.value_float; f64 b = y.value_float;
switch (op) { switch (op) {
case Token_Add: return make_exact_value_float(a + b); case Token_Add: return exact_value_float(a + b);
case Token_Sub: return make_exact_value_float(a - b); case Token_Sub: return exact_value_float(a - b);
case Token_Mul: return make_exact_value_float(a * b); case Token_Mul: return exact_value_float(a * b);
case Token_Quo: return make_exact_value_float(a / b); case Token_Quo: return exact_value_float(a / b);
default: goto error; default: goto error;
} }
} break; } break;
+315 -316
View File
File diff suppressed because it is too large Load Diff
+7 -11
View File
@@ -942,7 +942,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
switch (uo->op) { switch (uo->op) {
case Token_Sub: case Token_Sub:
if (is_type_float(elem_type)) { 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 { } else {
ir_fprintf(f, "0"); ir_fprintf(f, "0");
} }
@@ -1197,17 +1197,17 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
ir_fprintf(f, "call void "); ir_fprintf(f, "call void ");
ir_print_encoded_global(f, str_lit("__bounds_check_error"), false); ir_print_encoded_global(f, str_lit("__bounds_check_error"), false);
ir_fprintf(f, "("); 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_fprintf(f, ", ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
ir_fprintf(f, " "); 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_fprintf(f, ", ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
ir_fprintf(f, " "); 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_fprintf(f, ", ");
ir_print_type(f, m, t_int); 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_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_fprintf(f, ", ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
ir_fprintf(f, " "); 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_fprintf(f, ", ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
ir_fprintf(f, " "); 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_fprintf(f, ", ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
@@ -1408,10 +1408,6 @@ void print_llvm_ir(irGen *ir) {
irFileBuffer buf = {0}, *f = &buf; irFileBuffer buf = {0}, *f = &buf;
ir_file_buffer_init(f, &ir->output_file); 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_print_encoded_local(f, str_lit("..string"));
ir_fprintf(f, " = type {i8*, "); ir_fprintf(f, " = type {i8*, ");
ir_print_type(f, m, t_int); ir_print_type(f, m, t_int);
+3 -3
View File
@@ -8,9 +8,8 @@ extern "C" {
#include "build_settings.c" #include "build_settings.c"
#include "tokenizer.c" #include "tokenizer.c"
#include "parser.c" #include "parser.c"
// #include "printer.c"
#include "checker.c" #include "checker.c"
// #include "ssa.c" // #include "bytecode.c"
#include "ir.c" #include "ir.c"
#include "ir_opt.c" #include "ir_opt.c"
#include "ir_print.c" #include "ir_print.c"
@@ -144,6 +143,7 @@ int main(int argc, char **argv) {
init_scratch_memory(gb_megabytes(10)); init_scratch_memory(gb_megabytes(10));
init_global_error_collector(); init_global_error_collector();
#if 1 #if 1
init_build_context(); init_build_context();
@@ -217,7 +217,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
if (!ssa_generate(&checker.info)) { if (!bc_generate(&checker.info)) {
return 1; return 1;
} }
#else #else
+2 -2
View File
@@ -1215,7 +1215,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
// NOTE(bill): Underlying memory address cannot be changed // NOTE(bill): Underlying memory address cannot be changed
if (str_eq(field_name, count_str)) { if (str_eq(field_name, count_str)) {
// HACK(bill): Memory leak // 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; return sel;
} }
} else if (type->kind == Type_Vector) { } 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 // NOTE(bill): Vectors are not addressable
if (str_eq(field_name, count_str)) { if (str_eq(field_name, count_str)) {
// HACK(bill): Memory leak // 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; return sel;
} }