From 1988856eedc1a9714c42a22ea369d8154dcf7589 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 5 Mar 2021 12:56:36 +0000 Subject: [PATCH] Minimize the size of `runtime.Source_Code_Location` to use `i32` instead of `int` --- core/fmt/fmt.odin | 4 ++-- core/runtime/core.odin | 2 +- core/runtime/error_checks.odin | 22 +++++++++++----------- src/ir.cpp | 32 ++++++++++++++++---------------- src/ir_print.cpp | 4 ++-- src/llvm_backend.cpp | 28 ++++++++++++++-------------- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 15fe3ce7d..a59a7dad0 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1286,9 +1286,9 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { case runtime.Source_Code_Location: io.write_string(fi.writer, a.file_path); io.write_byte(fi.writer, '('); - io.write_int(fi.writer, a.line); + io.write_int(fi.writer, int(a.line)); io.write_byte(fi.writer, ':'); - io.write_int(fi.writer, a.column); + io.write_int(fi.writer, int(a.column)); io.write_byte(fi.writer, ')'); return; diff --git a/core/runtime/core.odin b/core/runtime/core.odin index b89e77ebd..7e01146e5 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -246,7 +246,7 @@ args__: []cstring; Source_Code_Location :: struct { file_path: string, - line, column: int, + line, column: i32, procedure: string, } diff --git a/core/runtime/error_checks.odin b/core/runtime/error_checks.odin index 8874cce00..b172ae9c8 100644 --- a/core/runtime/error_checks.odin +++ b/core/runtime/error_checks.odin @@ -17,11 +17,11 @@ type_assertion_trap :: proc "contextless" () -> ! { } -bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) { +bounds_check_error :: proc "contextless" (file: string, line, column: i32, index, count: int) { if 0 <= index && index < count { return; } - handle_error :: proc "contextless" (file: string, line, column: int, index, count: int) { + handle_error :: proc "contextless" (file: string, line, column: i32, index, count: int) { context = default_context(); print_caller_location(Source_Code_Location{file, line, column, ""}); print_string(" Index "); @@ -34,7 +34,7 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index handle_error(file, line, column, index, count); } -slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) -> ! { +slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) -> ! { context = default_context(); print_caller_location(Source_Code_Location{file, line, column, ""}); print_string(" Invalid slice indices: "); @@ -47,25 +47,25 @@ slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, h bounds_trap(); } -slice_expr_error_hi :: proc "contextless" (file: string, line, column: int, hi: int, len: int) { +slice_expr_error_hi :: proc "contextless" (file: string, line, column: i32, hi: int, len: int) { if 0 <= hi && hi <= len { return; } slice_handle_error(file, line, column, 0, hi, len); } -slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { +slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) { if 0 <= lo && lo <= len && lo <= hi && hi <= len { return; } slice_handle_error(file, line, column, lo, hi, len); } -dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) { +dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) { if 0 <= low && low <= high && high <= max { return; } - handle_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) { + handle_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) { context = default_context(); print_caller_location(Source_Code_Location{file, line, column, ""}); print_string(" Invalid dynamic array values: "); @@ -81,11 +81,11 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, } -type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) { +type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) { if ok { return; } - handle_error :: proc "contextless" (file: string, line, column: int, from, to: typeid) { + handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid) { context = default_context(); print_caller_location(Source_Code_Location{file, line, column, ""}); print_string(" Invalid type assertion from "); @@ -98,7 +98,7 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column handle_error(file, line, column, from, to); } -type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid, from_data: rawptr) { +type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid, from_data: rawptr) { if ok { return; } @@ -130,7 +130,7 @@ type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, colum return id; } - handle_error :: proc "contextless" (file: string, line, column: int, from, to: typeid, from_data: rawptr) { + handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid, from_data: rawptr) { context = default_context(); actual := variant_type(from, from_data); diff --git a/src/ir.cpp b/src/ir.cpp index 22265fcd0..1ca7b4cd4 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6420,8 +6420,8 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token args[0] = ok; args[1] = ir_find_or_add_entity_string(proc->module, get_file_path_string(pos.file_id)); - args[2] = ir_const_int(pos.line); - args[3] = ir_const_int(pos.column); + args[2] = ir_const_i32(pos.line); + args[3] = ir_const_i32(pos.column); args[4] = ir_typeid(proc->module, src_type); args[5] = ir_typeid(proc->module, dst_type); @@ -6480,8 +6480,8 @@ irAddr ir_emit_any_cast_addr(irProcedure *proc, irValue *value, Type *type, Toke args[0] = ok; args[1] = ir_find_or_add_entity_string(proc->module, get_file_path_string(pos.file_id)); - args[2] = ir_const_int(pos.line); - args[3] = ir_const_int(pos.column); + args[2] = ir_const_i32(pos.line); + args[3] = ir_const_i32(pos.column); args[4] = any_typeid; args[5] = dst_typeid; @@ -6677,8 +6677,8 @@ void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValu gbAllocator a = ir_allocator(); irValue *file = ir_find_or_add_entity_string(proc->module, get_file_path_string(token.pos.file_id)); - irValue *line = ir_const_int(token.pos.line); - irValue *column = ir_const_int(token.pos.column); + irValue *line = ir_const_i32(token.pos.line); + irValue *column = ir_const_i32(token.pos.column); auto args = array_make(ir_allocator(), 5); @@ -6701,8 +6701,8 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir gbAllocator a = ir_allocator(); irValue *file = ir_find_or_add_entity_string(proc->module, get_file_path_string(token.pos.file_id)); - irValue *line = ir_const_int(token.pos.line); - irValue *column = ir_const_int(token.pos.column); + irValue *line = ir_const_i32(token.pos.line); + irValue *column = ir_const_i32(token.pos.column); high = ir_emit_conv(proc, high, t_int); if (!lower_value_used) { @@ -6740,8 +6740,8 @@ void ir_emit_dynamic_array_bounds_check(irProcedure *proc, Token token, irValue gbAllocator a = ir_allocator(); irValue *file = ir_find_or_add_entity_string(proc->module, get_file_path_string(token.pos.file_id)); - irValue *line = ir_const_int(token.pos.line); - irValue *column = ir_const_int(token.pos.column); + irValue *line = ir_const_i32(token.pos.line); + irValue *column = ir_const_i32(token.pos.column); low = ir_emit_conv(proc, low, t_int); high = ir_emit_conv(proc, high, t_int); @@ -7078,8 +7078,8 @@ irValue *ir_emit_source_code_location(irProcedure *proc, String procedure, Token gbAllocator a = ir_allocator(); irValue *v = ir_alloc_value(irValue_SourceCodeLocation); v->SourceCodeLocation.file = ir_find_or_add_entity_string(proc->module, get_file_path_string(pos.file_id)); - v->SourceCodeLocation.line = ir_const_int(pos.line); - v->SourceCodeLocation.column = ir_const_int(pos.column); + v->SourceCodeLocation.line = ir_const_i32(pos.line); + v->SourceCodeLocation.column = ir_const_i32(pos.column); v->SourceCodeLocation.procedure = ir_find_or_add_entity_string(proc->module, procedure); return v; } @@ -8260,8 +8260,8 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { args[0] = ok; args[1] = ir_find_or_add_entity_string(proc->module, get_file_path_string(pos.file_id)); - args[2] = ir_const_int(pos.line); - args[3] = ir_const_int(pos.column); + args[2] = ir_const_i32(pos.line); + args[3] = ir_const_i32(pos.column); args[4] = ir_typeid(proc->module, src_type); args[5] = ir_typeid(proc->module, dst_type); @@ -8285,8 +8285,8 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { args[0] = ok; args[1] = ir_find_or_add_entity_string(proc->module, get_file_path_string(pos.file_id)); - args[2] = ir_const_int(pos.line); - args[3] = ir_const_int(pos.column); + args[2] = ir_const_i32(pos.line); + args[3] = ir_const_i32(pos.column); args[4] = any_id; args[5] = id; diff --git a/src/ir_print.cpp b/src/ir_print.cpp index bab68cadd..c87030e84 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -1426,9 +1426,9 @@ void ir_print_value(irFileBuffer *f, irModule *m, irValue *value, Type *type_hin ir_write_byte(f, '{'); ir_print_type(f, m, t_string); ir_write_byte(f, ' '); ir_print_value(f, m, file, t_string); ir_write_string(f, str_lit(", ")); - ir_print_type(f, m, t_int); ir_write_byte(f, ' '); ir_print_value(f, m, line, t_int); + ir_print_type(f, m, t_i32); ir_write_byte(f, ' '); ir_print_value(f, m, line, t_i32); ir_write_string(f, str_lit(", ")); - ir_print_type(f, m, t_int); ir_write_byte(f, ' '); ir_print_value(f, m, column, t_int); + ir_print_type(f, m, t_i32); ir_write_byte(f, ' '); ir_print_value(f, m, column, t_i32); ir_write_string(f, str_lit(", ")); ir_print_type(f, m, t_string); ir_write_byte(f, ' '); ir_print_value(f, m, procedure, t_string); ir_write_byte(f, '}'); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 2a6479d2f..5ce03bccf 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -186,8 +186,8 @@ void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue le len = lb_emit_conv(p, len, t_int); lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_int, token.pos.line); - lbValue column = lb_const_int(p->module, t_int, token.pos.column); + lbValue line = lb_const_int(p->module, t_i32, token.pos.line); + lbValue column = lb_const_int(p->module, t_i32, token.pos.column); auto args = array_make(permanent_allocator(), 5); args[0] = file; @@ -208,8 +208,8 @@ void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValu } lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_int, token.pos.line); - lbValue column = lb_const_int(p->module, t_int, token.pos.column); + lbValue line = lb_const_int(p->module, t_i32, token.pos.line); + lbValue column = lb_const_int(p->module, t_i32, token.pos.column); high = lb_emit_conv(p, high, t_int); if (!lower_value_used) { @@ -5415,8 +5415,8 @@ lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, To LLVMValueRef fields[4] = {}; fields[0]/*file*/ = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)).value; - fields[1]/*line*/ = lb_const_int(m, t_int, pos.line).value; - fields[2]/*column*/ = lb_const_int(m, t_int, pos.column).value; + fields[1]/*line*/ = lb_const_int(m, t_i32, pos.line).value; + fields[2]/*column*/ = lb_const_int(m, t_i32, pos.column).value; fields[3]/*procedure*/ = lb_find_or_add_entity_string(p->module, procedure).value; lbValue res = {}; @@ -9510,8 +9510,8 @@ lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos p args[0] = ok; args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(m, t_int, pos.line); - args[3] = lb_const_int(m, t_int, pos.column); + args[2] = lb_const_int(m, t_i32, pos.line); + args[3] = lb_const_int(m, t_i32, pos.column); args[4] = lb_typeid(m, src_type); args[5] = lb_typeid(m, dst_type); @@ -9572,8 +9572,8 @@ lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos args[0] = ok; args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(m, t_int, pos.line); - args[3] = lb_const_int(m, t_int, pos.column); + args[2] = lb_const_int(m, t_i32, pos.line); + args[3] = lb_const_int(m, t_i32, pos.column); args[4] = any_typeid; args[5] = dst_typeid; @@ -9878,8 +9878,8 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) { args[0] = ok; args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(p->module, t_int, pos.line); - args[3] = lb_const_int(p->module, t_int, pos.column); + args[2] = lb_const_int(p->module, t_i32, pos.line); + args[3] = lb_const_int(p->module, t_i32, pos.column); args[4] = lb_typeid(p->module, src_type); args[5] = lb_typeid(p->module, dst_type); @@ -9903,8 +9903,8 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) { args[0] = ok; args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(p->module, t_int, pos.line); - args[3] = lb_const_int(p->module, t_int, pos.column); + args[2] = lb_const_int(p->module, t_i32, pos.line); + args[3] = lb_const_int(p->module, t_i32, pos.column); args[4] = any_id; args[5] = id;