From c9b82a21e9a52122a226ecc05c46a29dc8f57dac Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 23 Apr 2021 10:01:52 +0100 Subject: Move `check_builtin_procedure` to check_builtin.cpp --- src/checker.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index f386d6da7..e74c6fc10 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -2903,6 +2903,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { #include "check_expr.cpp" +#include "check_builtin.cpp" #include "check_type.cpp" #include "check_decl.cpp" #include "check_stmt.cpp" -- cgit v1.2.3 From 6383714bffb05a34a5320a757e08dd73bf9a2b0c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 25 Apr 2021 19:56:46 +0100 Subject: Remove old procedure ABI code --- src/check_expr.cpp | 8 - src/check_type.cpp | 618 --------------------------------------------------- src/checker.cpp | 4 - src/llvm_backend.cpp | 19 +- src/types.cpp | 4 - 5 files changed, 8 insertions(+), 645 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 885a2eaa3..61cdf7822 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -103,10 +103,6 @@ CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Ty Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); -Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type, ProcCallingConvention cc); -Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCallingConvention cc); -bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type); -void set_procedure_abi_types(Type *type); void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type); void add_map_key_type_dependencies(CheckerContext *ctx, Type *key); @@ -1088,10 +1084,6 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, if (!ok) return false; } - if (modify_type) { - set_procedure_abi_types(source); - } - return true; #endif } diff --git a/src/check_type.cpp b/src/check_type.cpp index e3aac161c..aef1ddc7a 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1162,9 +1162,6 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper } if (is_polymorphic_type_assignable(ctx, poly_type, operand.type, false, modify_type)) { - if (show_error) { - set_procedure_abi_types(poly_type); - } return poly_type; } if (show_error) { @@ -1767,623 +1764,8 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { return tuple; } -Array systemv_distribute_struct_fields(Type *t) { - Type *bt = core_type(t); - - - isize distributed_cap = 1; - if (bt->kind == Type_Struct) { - distributed_cap = bt->Struct.fields.count; - } - auto distributed = array_make(heap_allocator(), 0, distributed_cap); - - i64 sz = type_size_of(bt); - switch (bt->kind) { - case Type_Basic: - switch (bt->Basic.kind){ - case Basic_complex64: - array_add(&distributed, t_f32); - array_add(&distributed, t_f32); - break; - case Basic_complex128: - array_add(&distributed, t_f64); - array_add(&distributed, t_f64); - break; - case Basic_quaternion128: - array_add(&distributed, t_f32); - array_add(&distributed, t_f32); - array_add(&distributed, t_f32); - array_add(&distributed, t_f32); - break; - case Basic_quaternion256: - goto DEFAULT; - case Basic_string: - array_add(&distributed, t_u8_ptr); - array_add(&distributed, t_int); - break; - case Basic_any: - GB_ASSERT(type_size_of(t_uintptr) == type_size_of(t_typeid)); - array_add(&distributed, t_rawptr); - array_add(&distributed, t_uintptr); - break; - - case Basic_u128: - case Basic_i128: - if (build_context.ODIN_OS == "windows") { - array_add(&distributed, alloc_type_simd_vector(2, t_u64)); - } else { - array_add(&distributed, bt); - } - break; - - default: - goto DEFAULT; - } - break; - - case Type_Struct: - if (bt->Struct.is_raw_union) { - goto DEFAULT; - } else { - // IMPORTANT TOOD(bill): handle #packed structs correctly - // IMPORTANT TODO(bill): handle #align structs correctly - for_array(field_index, bt->Struct.fields) { - Entity *f = bt->Struct.fields[field_index]; - auto nested = systemv_distribute_struct_fields(f->type); - array_add_elems(&distributed, nested.data, nested.count); - array_free(&nested); - } - } - break; - - case Type_Array: - for (i64 i = 0; i < bt->Array.count; i++) { - array_add(&distributed, bt->Array.elem); - } - break; - - case Type_BitSet: - array_add(&distributed, bit_set_to_int(bt)); - break; - - case Type_Tuple: - GB_PANIC("Invalid struct field type"); - break; - - case Type_Slice: - array_add(&distributed, t_rawptr); - array_add(&distributed, t_int); - break; - - case Type_Union: - case Type_DynamicArray: - case Type_Map: - // NOTE(bill, 2019-10-10): Odin specific, don't worry about C calling convention yet - goto DEFAULT; - - case Type_Pointer: - case Type_Proc: - case Type_SimdVector: // TODO(bill): Is this correct logic? - default: - DEFAULT:; - if (sz > 0) { - array_add(&distributed, bt); - } - break; - } - - return distributed; -} - -Type *struct_type_from_systemv_distribute_struct_fields(Type *abi_type) { - GB_ASSERT(is_type_tuple(abi_type)); - Type *final_type = alloc_type_struct(); - final_type->Struct.fields = abi_type->Tuple.variables; - return final_type; -} - - -Type *handle_single_distributed_type_parameter(Array const &types, bool packed, isize *offset) { - GB_ASSERT(types.count > 0); - - if (types.count == 1) { - if (offset) *offset = 1; - - i64 sz = type_size_of(types[0]); - - if (is_type_float(types[0])) { - return types[0]; - } - switch (sz) { - case 0: - GB_PANIC("Zero sized type found!"); - case 1: return t_u8; - case 2: return t_u16; - case 4: return t_u32; - case 8: return t_u64; - default: - return types[0]; - } - } else if (types.count >= 2) { - if (types[0] == t_f32 && types[1] == t_f32) { - if (offset) *offset = 2; - return alloc_type_simd_vector(2, t_f32); - } else if (type_size_of(types[0]) == 8) { - if (offset) *offset = 1; - return types[0]; - } - - i64 total_size = 0; - isize i = 0; - if (packed) { - for (; i < types.count && total_size < 8; i += 1) { - Type *t = types[i]; - i64 s = type_size_of(t); - total_size += s; - } - } else { - for (; i < types.count && total_size < 8; i += 1) { - Type *t = types[i]; - i64 s = gb_max(type_size_of(t), 0); - i64 a = gb_max(type_align_of(t), 1); - isize ts = align_formula(total_size, a); - if (ts >= 8) { - break; - } - total_size = ts + s; - } - } - if (offset) *offset = i; - switch (total_size) { - case 1: return t_u8; - case 2: return t_u16; - case 4: return t_u32; - case 8: return t_u64; - } - return t_u64; - } - - return nullptr; -} - -Type *handle_struct_system_v_amd64_abi_type(Type *t) { - if (type_size_of(t) > 16) { - return alloc_type_pointer(t); - } - Type *original_type = t; - Type *bt = core_type(t); - t = base_type(t); - i64 size = type_size_of(bt); - - switch (t->kind) { - case Type_Slice: - case Type_Struct: - break; - - case Type_Basic: - switch (bt->Basic.kind) { - case Basic_string: - case Basic_any: - case Basic_complex64: - case Basic_complex128: - case Basic_quaternion128: - break; - default: - return original_type; - } - break; - - default: - return original_type; - } - - bool is_packed = false; - if (is_type_struct(bt)) { - is_packed = bt->Struct.is_packed; - } - - if (is_type_raw_union(bt)) { - // TODO(bill): Handle raw union correctly for - return t; - } else { - auto field_types = systemv_distribute_struct_fields(bt); - defer (array_free(&field_types)); - - GB_ASSERT(field_types.count <= 16); - - Type *final_type = nullptr; - - if (field_types.count == 0) { - final_type = t; - } else if (field_types.count == 1) { - final_type = field_types[0]; - } else { - if (size <= 8) { - isize offset = 0; - final_type = handle_single_distributed_type_parameter(field_types, is_packed, &offset); - } else { - isize offset = 0; - isize next_offset = 0; - Type *two_types[2] = {}; - - two_types[0] = handle_single_distributed_type_parameter(field_types, is_packed, &offset); - auto remaining = array_slice(field_types, offset, field_types.count); - two_types[1] = handle_single_distributed_type_parameter(remaining, is_packed, &next_offset); - GB_ASSERT(offset + next_offset == field_types.count); - - auto variables = array_make(heap_allocator(), 2); - variables[0] = alloc_entity_param(nullptr, empty_token, two_types[0], false, false); - variables[1] = alloc_entity_param(nullptr, empty_token, two_types[1], false, false); - final_type = alloc_type_tuple(); - final_type->Tuple.variables = variables; - if (t->kind == Type_Struct) { - // NOTE(bill): Make this packed - final_type->Tuple.is_packed = t->Struct.is_packed; - } - } - } - - - GB_ASSERT(final_type != nullptr); - i64 ftsz = type_size_of(final_type); - i64 otsz = type_size_of(original_type); - if (ftsz != otsz) { - // TODO(bill): Handle this case which will be caused by #packed most likely - switch (otsz) { - case 1: - case 2: - case 4: - case 8: - GB_PANIC("Incorrectly handled case for handle_struct_system_v_amd64_abi_type, %s %lld vs %s %lld", type_to_string(final_type), ftsz, type_to_string(original_type), otsz); - } - } - - return final_type; - } -} -Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type, ProcCallingConvention cc) { - Type *new_type = original_type; - if (is_type_boolean(original_type)) { - Type *t = core_type(base_type(new_type)); - if (t == t_bool) { - return t_llvm_bool; - } - return new_type; - } - - if (is_type_proc(original_type)) { - // NOTE(bill): Force a cast to prevent a possible type cycle - return t_rawptr; - } - - if (is_calling_convention_none(cc)) { - return new_type; - } - - if (build_context.ODIN_ARCH == "386") { - return new_type; - } - - if (is_type_simd_vector(original_type)) { - return new_type; - } - if (build_context.ODIN_ARCH == "amd64") { - bool is_128 = is_type_integer_128bit(original_type); - if (!is_128 && is_type_bit_set(original_type) && type_size_of(original_type) == 16) { - // is_128 = true; - } - if (is_128) { - if (build_context.ODIN_OS == "windows") { - return alloc_type_simd_vector(2, t_u64); - } else { - return original_type; - } - } - } - - if (build_context.ODIN_OS == "windows") { - // NOTE(bill): Changing the passing parameter value type is to match C's ABI - // IMPORTANT TODO(bill): This only matches the ABI on MSVC at the moment - // SEE: https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx - - - Type *bt = core_type(original_type); - switch (bt->kind) { - // Okay to pass by value (usually) - // Especially the only Odin types - case Type_Basic: { - i64 sz = bt->Basic.size; - // if (sz > 8 && build_context.word_size < 8) { - if (sz > 8) { - new_type = alloc_type_pointer(original_type); - } - break; - } - case Type_Pointer: - if (is_type_struct(bt->Pointer.elem)) { - // Force to a raw pointer - new_type = t_rawptr; - } - break; - case Type_Proc: - new_type = t_rawptr; - break; // NOTE(bill): Just a pointer - - // Odin specific - case Type_Slice: - case Type_Array: - case Type_DynamicArray: - case Type_Map: - case Type_Union: - // Could be in C too - case Type_Struct: - { - i64 align = type_align_of(original_type); - i64 size = type_size_of(original_type); - - switch (8*size) { - case 8: new_type = t_u8; break; - case 16: new_type = t_u16; break; - case 32: new_type = t_u32; break; - case 64: new_type = t_u64; break; - default: - new_type = alloc_type_pointer(original_type); - break; - } - - break; - } - } - } else if (build_context.ODIN_OS == "linux" || - build_context.ODIN_OS == "darwin") { - Type *bt = core_type(original_type); - switch (bt->kind) { - // Okay to pass by value (usually) - // Especially the only Odin types - case Type_Basic: { - i64 sz = bt->Basic.size; - // if (sz > 8 && build_context.word_size < 8) { - if (sz > 8) { - new_type = alloc_type_pointer(original_type); - } - - break; - } - case Type_Pointer: break; - case Type_Proc: break; // NOTE(bill): Just a pointer - - default: { - i64 size = type_size_of(original_type); - if (size > 16) { - new_type = alloc_type_pointer(original_type); - } else if (build_context.ODIN_ARCH == "amd64") { - // NOTE(bill): System V AMD64 ABI - new_type = handle_struct_system_v_amd64_abi_type(bt); - if (are_types_identical(core_type(original_type), new_type)) { - new_type = original_type; - } - return new_type; - } - - break; - } - } - } else { - // IMPORTANT TODO(bill): figure out the ABI settings for Linux, OSX etc. for - // their architectures - } - - return new_type; -} - - -Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCallingConvention cc) { - Type *new_type = original_type; - if (new_type == nullptr) { - return nullptr; - } - GB_ASSERT(is_type_tuple(original_type)); - - Type *single_type = reduce_tuple_to_single_type(original_type); - - if (cc == ProcCC_InlineAsm) { - return new_type; - } - - if (is_type_proc(single_type)) { - // NOTE(bill): Force a cast to prevent a possible type cycle - return t_rawptr; - } - - if (is_type_simd_vector(single_type)) { - return new_type; - } - - if (is_type_pointer(single_type)) { - // NOTE(bill): Force a cast to prevent a possible type cycle - return t_rawptr; - } - - if (build_context.ODIN_OS == "windows") { - if (build_context.ODIN_ARCH == "amd64") { - if (is_type_integer_128bit(single_type)) { - if (is_calling_convention_none(cc)) { - return original_type; - } else { - return alloc_type_simd_vector(2, t_u64); - } - } - } - - Type *bt = core_type(reduce_tuple_to_single_type(original_type)); - // NOTE(bill): This is just reversed engineered from LLVM IR output - switch (bt->kind) { - // Okay to pass by value - // Especially the only Odin types - case Type_Pointer: break; - case Type_Proc: break; // NOTE(bill): Just a pointer - case Type_Basic: break; - - - default: { - i64 align = type_align_of(original_type); - i64 size = type_size_of(original_type); - switch (8*size) { -#if 1 - case 8: new_type = t_u8; break; - case 16: new_type = t_u16; break; - case 32: new_type = t_u32; break; - case 64: new_type = t_u64; break; -#endif - } - - break; - } - } - } else if (build_context.ODIN_OS == "linux" || build_context.ODIN_OS == "darwin") { - if (build_context.ODIN_ARCH == "amd64") { - - } - } else { - // IMPORTANT TODO(bill): figure out the ABI settings for Linux, OSX etc. for - // their architectures - } - - if (is_type_integer_128bit(single_type)) { - if (build_context.word_size == 8) { - return original_type; - } - } - - - if (new_type != original_type) { - Type *tuple = alloc_type_tuple(); - auto variables = array_make(a, 0, 1); - array_add(&variables, alloc_entity_param(original_type->Tuple.variables[0]->scope, empty_token, new_type, false, false)); - tuple->Tuple.variables = variables; - new_type = tuple; - } - - if (cc == ProcCC_None) { - for_array(i, new_type->Tuple.variables) { - Type **tp = &new_type->Tuple.variables[i]->type; - Type *t = core_type(*tp); - if (t == t_bool) { - *tp = t_llvm_bool; - } - } - } - - new_type->cached_size = -1; - new_type->cached_align = -1; - return new_type; -} - -bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type) { - if (abi_return_type == nullptr) { - return false; - } - if (is_calling_convention_none(cc)) { - return false; - } - - Type *single_type = reduce_tuple_to_single_type(abi_return_type); - - if (is_type_simd_vector(single_type)) { - return false; - } - - if (build_context.word_size == 8) { - if (is_type_integer_128bit(single_type)) { - return false; - } - } - - if (build_context.ODIN_OS == "windows" || build_context.ODIN_OS == "linux" ) { - i64 size = 8*type_size_of(abi_return_type); - switch (size) { - case 0: - case 8: - case 16: - case 32: - case 64: - return false; - default: - return true; - } - } else { - if (is_type_integer_128bit(single_type)) { - return build_context.word_size < 8; - } - } - - - - return false; -} - -void set_procedure_abi_types(Type *type) { - type = base_type(type); - if (type->kind != Type_Proc) { - return; - } - - if (type->Proc.abi_types_set || type->flags & TypeFlag_InProcessOfCheckingABI) { - return; - } - - gbAllocator allocator = permanent_allocator(); - - u32 flags = type->flags; - type->flags |= TypeFlag_InProcessOfCheckingABI; - - type->Proc.abi_compat_params = array_make(allocator, cast(isize)type->Proc.param_count); - for (i32 i = 0; i < type->Proc.param_count; i++) { - Entity *e = type->Proc.params->Tuple.variables[i]; - if (e->kind == Entity_Variable) { - Type *original_type = e->type; - Type *new_type = type_to_abi_compat_param_type(allocator, original_type, type->Proc.calling_convention); - type->Proc.abi_compat_params[i] = new_type; - switch (type->Proc.calling_convention) { - case ProcCC_Odin: - case ProcCC_Contextless: - if (is_type_pointer(new_type) && !is_type_pointer(e->type) && !is_type_proc(e->type)) { - e->flags |= EntityFlag_ImplicitReference; - } - break; - } - - if (build_context.ODIN_OS == "linux" || - build_context.ODIN_OS == "darwin") { - if (is_type_pointer(new_type) & !is_type_pointer(e->type) && !is_type_proc(e->type)) { - e->flags |= EntityFlag_ByVal; - } - } - } - } - - for (i32 i = 0; i < type->Proc.param_count; i++) { - Entity *e = type->Proc.params->Tuple.variables[i]; - if (e->kind == Entity_Variable) { - set_procedure_abi_types(e->type); - } - } - for (i32 i = 0; i < type->Proc.result_count; i++) { - Entity *e = type->Proc.results->Tuple.variables[i]; - if (e->kind == Entity_Variable) { - set_procedure_abi_types(e->type); - } - } - - // NOTE(bill): The types are the same - type->Proc.abi_compat_result_type = type_to_abi_compat_result_type(allocator, type->Proc.results, type->Proc.calling_convention); - type->Proc.return_by_pointer = abi_compat_return_by_pointer(allocator, type->Proc.calling_convention, type->Proc.abi_compat_result_type); - - type->Proc.abi_types_set = true; - type->flags = flags; -} // NOTE(bill): 'operands' is for generating non generic procedure type bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { diff --git a/src/checker.cpp b/src/checker.cpp index e74c6fc10..5a2203cfb 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -732,15 +732,11 @@ void init_universal(void) { add_global_type_entity(str_lit("byte"), &basic_types[Basic_u8]); { - void set_procedure_abi_types(Type *type); - Type *equal_args[2] = {t_rawptr, t_rawptr}; t_equal_proc = alloc_type_proc_from_types(equal_args, 2, t_bool, false, ProcCC_Contextless); - set_procedure_abi_types(t_equal_proc); Type *hasher_args[2] = {t_rawptr, t_uintptr}; t_hasher_proc = alloc_type_proc_from_types(hasher_args, 2, t_uintptr, false, ProcCC_Contextless); - set_procedure_abi_types(t_hasher_proc); } // Constants diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0d27b9c6f..3e7d858ed 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2545,8 +2545,6 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) { Type *pt = base_type(entity->type); GB_ASSERT(pt->kind == Type_Proc); - set_procedure_abi_types(entity->type); - p->type = entity->type; p->type_expr = decl->type_expr; p->body = pl->body; @@ -2845,6 +2843,14 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP return res; } +Type *struct_type_from_systemv_distribute_struct_fields(Type *abi_type) { + GB_ASSERT(is_type_tuple(abi_type)); + Type *final_type = alloc_type_struct(); + final_type->Struct.fields = abi_type->Tuple.variables; + return final_type; +} + + lbValue lb_add_param(lbProcedure *p, Entity *e, Ast *expr, Type *abi_type, i32 index) { lbParamPasskind kind = lbParamPass_Value; lbValue v = lb_value_param(p, e, abi_type, index, &kind); @@ -3476,9 +3482,6 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { name_len = gb_snprintf(name_text, name_len, "%.*s.%.*s-%d", LIT(p->name), LIT(pd_name), guid); String name = make_string(cast(u8 *)name_text, name_len-1); - set_procedure_abi_types(e->type); - - e->Procedure.link_name = name; lbProcedure *nested_proc = lb_create_procedure(p->module, e); @@ -3613,7 +3616,6 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { return; } - set_procedure_abi_types(e->type); e->Procedure.link_name = name; lbProcedure *nested_proc = lb_create_procedure(p->module, e); @@ -8201,8 +8203,6 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, LLVMBuildUnreachable(p->builder); }); - set_procedure_abi_types(pt); - bool is_c_vararg = pt->Proc.c_vararg; isize param_count = pt->Proc.param_count; if (is_c_vararg) { @@ -9584,7 +9584,6 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { Type *proc_type_ = base_type(value.type); GB_ASSERT(proc_type_->kind == Type_Proc); TypeProc *pt = &proc_type_->Proc; - set_procedure_abi_types(proc_type_); if (is_call_expr_field_value(ce)) { auto args = array_make(permanent_allocator(), pt->param_count); @@ -10765,8 +10764,6 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A String name = make_string((u8 *)name_text, name_len-1); Type *type = type_of_expr(expr); - set_procedure_abi_types(type); - Token token = {}; token.pos = ast_token(expr).pos; diff --git a/src/types.cpp b/src/types.cpp index a5c5c2eb2..56081acc8 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -198,11 +198,8 @@ struct TypeProc { isize specialization_count; ProcCallingConvention calling_convention; i32 variadic_index; - Array abi_compat_params; - Type * abi_compat_result_type; // TODO(bill): Make this a flag set rather than bools bool variadic; - bool abi_types_set; bool require_results; bool c_vararg; bool is_polymorphic; @@ -317,7 +314,6 @@ enum TypeFlag : u32 { TypeFlag_Polymorphic = 1<<1, TypeFlag_PolySpecialized = 1<<2, TypeFlag_InProcessOfCheckingPolymorphic = 1<<3, - TypeFlag_InProcessOfCheckingABI = 1<<4, }; struct Type { -- cgit v1.2.3 From cb2e6ea31db90ca80314e5ff8ce8f43371fade7c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 25 Apr 2021 20:03:05 +0100 Subject: Remove `use_llvm_api` related checks and other related things --- core/runtime/internal.odin | 40 ++++++++++------------------------------ core/sys/cpu/cpu.odin | 2 -- src/build_settings.cpp | 8 -------- src/check_builtin.cpp | 40 ---------------------------------------- src/check_expr.cpp | 4 ---- src/check_stmt.cpp | 3 --- src/checker.cpp | 24 +++--------------------- src/main.cpp | 1 - 8 files changed, 13 insertions(+), 109 deletions(-) (limited to 'src/checker.cpp') diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 3c05fb6a7..e2f8c7287 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -107,22 +107,12 @@ mem_copy :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr { } // NOTE(bill): This _must_ be implemented like C's memmove foreign _ { - when ODIN_USE_LLVM_API { - when size_of(rawptr) == 8 { - @(link_name="llvm.memmove.p0i8.p0i8.i64") - llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; - } else { - @(link_name="llvm.memmove.p0i8.p0i8.i32") - llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; - } + when size_of(rawptr) == 8 { + @(link_name="llvm.memmove.p0i8.p0i8.i64") + llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; } else { - when size_of(rawptr) == 8 { - @(link_name="llvm.memmove.p0i8.p0i8.i64") - llvm_memmove :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---; - } else { - @(link_name="llvm.memmove.p0i8.p0i8.i32") - llvm_memmove :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---; - } + @(link_name="llvm.memmove.p0i8.p0i8.i32") + llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; } } llvm_memmove(dst, src, len); @@ -135,22 +125,12 @@ mem_copy_non_overlapping :: proc "contextless" (dst, src: rawptr, len: int) -> r } // NOTE(bill): This _must_ be implemented like C's memcpy foreign _ { - when ODIN_USE_LLVM_API { - when size_of(rawptr) == 8 { - @(link_name="llvm.memcpy.p0i8.p0i8.i64") - llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; - } else { - @(link_name="llvm.memcpy.p0i8.p0i8.i32") - llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; - } + when size_of(rawptr) == 8 { + @(link_name="llvm.memcpy.p0i8.p0i8.i64") + llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; } else { - when size_of(rawptr) == 8 { - @(link_name="llvm.memcpy.p0i8.p0i8.i64") - llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---; - } else { - @(link_name="llvm.memcpy.p0i8.p0i8.i32") - llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---; - } + @(link_name="llvm.memcpy.p0i8.p0i8.i32") + llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---; } } llvm_memcpy(dst, src, len); diff --git a/core/sys/cpu/cpu.odin b/core/sys/cpu/cpu.odin index b6f770aed..b99fe01d8 100644 --- a/core/sys/cpu/cpu.odin +++ b/core/sys/cpu/cpu.odin @@ -1,7 +1,5 @@ package sys_cpu -#assert(ODIN_USE_LLVM_API); - Cache_Line_Pad :: struct {_: [_cache_line_size]byte}; initialized: bool; diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 0be18a0d4..461b1610c 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -204,8 +204,6 @@ struct BuildContext { bool ignore_warnings; bool warnings_as_errors; - bool use_llvm_api; - bool use_subsystem_windows; bool ignore_microsoft_magic; bool linker_map_file; @@ -782,8 +780,6 @@ void init_build_context(TargetMetrics *cross_target) { bc->link_flags = str_lit(" "); bc->opt_flags = str_lit(" "); - bc->use_llvm_api = true; - gbString llc_flags = gb_string_make_reserve(heap_allocator(), 64); if (bc->ODIN_DEBUG) { @@ -841,10 +837,6 @@ void init_build_context(TargetMetrics *cross_target) { bc->link_flags = str_lit("-arch arm64 "); break; } - if ((bc->command_kind & Command__does_build) != 0 && !bc->use_llvm_api) { - gb_printf_err("The arm64 architecture is only supported with -llvm-api\n");; - gb_exit(1); - } } else if (bc->metrics.arch == TargetArch_wasm32) { bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined "); diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 5f4411b90..94e8dcee6 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -614,9 +614,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } else if (type->kind == Type_SimdVector) { max_count = type->SimdVector.count; elem_type = type->SimdVector.elem; - if (!build_context.use_llvm_api) { - error(call, "'swizzle' with #simd vector is not supported on this backend"); - } } i64 arg_count = 0; @@ -1529,11 +1526,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } case BuiltinProc_soa_zip: { - if (!build_context.use_llvm_api) { - error(call, "'soa_zip' is not supported with this backend"); - return false; - } - auto types = array_make(temporary_allocator(), 0, ce->args.count); auto names = array_make(temporary_allocator(), 0, ce->args.count); @@ -1681,11 +1673,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } case BuiltinProc_soa_unzip: { - if (!build_context.use_llvm_api) { - error(call, "'soa_unzip' is not supported with this backend"); - return false; - } - Operand x = {}; check_expr(c, &x, ce->args[0]); if (x.mode == Addressing_Invalid) { @@ -1927,16 +1914,10 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_trap: case BuiltinProc_debug_trap: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - } operand->mode = Addressing_NoValue; break; case BuiltinProc_read_cycle_counter: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - } operand->mode = Addressing_Value; operand->type = t_i64; break; @@ -1944,10 +1925,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_count_ones: case BuiltinProc_trailing_zeros: case BuiltinProc_reverse_bits: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - // continue anyway - } { Operand x = {}; check_expr(c, &x, ce->args[0]); @@ -1971,10 +1948,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 break; case BuiltinProc_byte_swap: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - // continue anyway - } { Operand x = {}; check_expr(c, &x, ce->args[0]); @@ -2006,10 +1979,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_overflow_add: case BuiltinProc_overflow_sub: case BuiltinProc_overflow_mul: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - // continue anyway - } { Operand x = {}; Operand y = {}; @@ -2189,11 +2158,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_fixed_point_mul_sat: case BuiltinProc_fixed_point_div_sat: { - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - // continue anyway - } - Operand x = {}; Operand y = {}; Operand z = {}; @@ -2255,10 +2219,6 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_expect: - if (!build_context.use_llvm_api) { - error(ce->args[0], "'%.*s' is not supported on this backend", LIT(builtin_procs[id].name)); - // continue anyway - } { Operand x = {}; Operand y = {}; diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 61cdf7822..2c83565a4 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7903,10 +7903,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type error(node, "Inline asm expressions are only allowed within a procedure body"); } - if (!build_context.use_llvm_api) { - error(node, "Inline asm expressions are only currently allowed with -llvm-api"); - } - auto param_types = array_make(heap_allocator(), ia->param_types.count); Type *return_type = nullptr; for_array(i, ia->param_types) { diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cad2be85b..a3c9a529c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1795,9 +1795,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { if (is_ptr) use_by_reference_for_value = true; array_add(&vals, t->Struct.soa_elem); array_add(&vals, t_int); - if (!build_context.use_llvm_api) { - error(operand.expr, "#soa structures do not yet support for in loop iteration"); - } } break; } diff --git a/src/checker.cpp b/src/checker.cpp index 5a2203cfb..ecd9b5ea4 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -755,7 +755,6 @@ void init_universal(void) { add_global_constant(str_lit("ODIN_DEBUG"), t_untyped_bool, exact_value_bool(bc->ODIN_DEBUG)); add_global_constant(str_lit("ODIN_DISABLE_ASSERT"), t_untyped_bool, exact_value_bool(bc->ODIN_DISABLE_ASSERT)); add_global_constant(str_lit("ODIN_DEFAULT_TO_NIL_ALLOCATOR"), t_untyped_bool, exact_value_bool(bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR)); - add_global_constant(str_lit("ODIN_USE_LLVM_API"), t_untyped_bool, exact_value_bool(bc->use_llvm_api)); add_global_constant(str_lit("ODIN_NO_DYNAMIC_LITERALS"), t_untyped_bool, exact_value_bool(bc->no_dynamic_literals)); add_global_constant(str_lit("ODIN_TEST"), t_untyped_bool, exact_value_bool(bc->command_kind == Command_test)); @@ -1774,23 +1773,6 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { force_add_dependency_entity(c, c->info.runtime_package->scope, required_runtime_entities[i]); } - if (!build_context.use_llvm_api) { - String other_required_runtime_entities[] = { - str_lit("bswap_16"), - str_lit("bswap_32"), - str_lit("bswap_64"), - str_lit("bswap_128"), - - str_lit("bswap_f16"), - str_lit("bswap_f32"), - str_lit("bswap_f64"), - }; - - for (isize i = 0; i < gb_count_of(other_required_runtime_entities); i++) { - force_add_dependency_entity(c, c->info.runtime_package->scope, other_required_runtime_entities[i]); - } - } - if (build_context.no_crt) { String required_no_crt_entities[] = { // NOTE(bill): Only if these exist @@ -2741,7 +2723,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { } } - if (valid && build_context.use_llvm_api) { + if (valid) { if (ac->atom_op_table == nullptr) { ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable); } @@ -2800,7 +2782,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { } } - if (valid && build_context.use_llvm_api) { + if (valid) { if (ac->atom_op_table == nullptr) { ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable); } @@ -2882,7 +2864,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { } } - if (valid && build_context.use_llvm_api) { + if (valid) { if (ac->atom_op_table == nullptr) { ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable); } diff --git a/src/main.cpp b/src/main.cpp index 02a9b50f7..d2f84b29d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1185,7 +1185,6 @@ bool parse_build_flags(Array args) { case BuildFlag_UseLLVMApi: gb_printf_err("-llvm-api flag is not required any more\n"); - build_context.use_llvm_api = true; bad_flags = true; break; -- cgit v1.2.3 From 86c1aed20d3900b2a5df905a821bf13a074dc102 Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Sun, 25 Apr 2021 23:26:12 -0600 Subject: Fix for issue 820 (import name is not an identifier) --- src/checker.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index f386d6da7..42462c0fa 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3747,6 +3747,19 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage return empty_path; } #endif + +String get_invalid_import_name(String input) { + isize slash = 0; + for (isize i = input.len-1; i >= 0; i--) { + if (input[i] == '/' || input[i] == '\\') { + break; + } + slash = i; + } + input = substring(input, slash, input.len); + return input; +} + void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3804,7 +3817,14 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (id->is_using) { // TODO(bill): Should this be a warning? } else { - error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string)); + if (id->import_name.string == "") { + String invalid_name = id->fullpath; + invalid_name = get_invalid_import_name(invalid_name); + + error(id->token, "Import name %.*s, is not a valid identifier. Perhaps you want to reference the package by a different name like this: import \"%.*s\" ", LIT(invalid_name), LIT(invalid_name)); + } else { + error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string)); + } } } else { GB_ASSERT(id->import_name.pos.line != 0); -- cgit v1.2.3 From a38586420cd2d8534a7be83851d8ca174cce1bcb Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 19:46:42 +0100 Subject: Fix race condition with procedure aliases checking for declarations on constant aliases --- src/check_decl.cpp | 4 ++-- src/checker.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 85c58fdf9..218dce2ee 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -460,14 +460,14 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, case Entity_LibraryName: case Entity_ImportName: { - override_entity_in_scope(e, entity); - DeclInfo *decl = decl_info_of_entity(e); if (decl != nullptr) { if (decl->attributes.count > 0) { error(decl->attributes[0], "Constant alias declarations cannot have attributes"); } } + + override_entity_in_scope(e, entity); return; } } diff --git a/src/checker.cpp b/src/checker.cpp index 89809779b..878435d67 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3260,6 +3260,7 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) { d->type_expr = vd->type; d->init_expr = init; + if (is_ast_type(init)) { e = alloc_entity_type_name(d->scope, token, nullptr); // if (vd->type != nullptr) { -- cgit v1.2.3