Remove the complex type.

This commit is contained in:
Christoffer Lerno
2021-05-30 16:46:36 +02:00
committed by Christoffer Lerno
parent dd8b850544
commit cf58da4a3c
16 changed files with 7 additions and 169 deletions

View File

@@ -121,9 +121,7 @@ work on Windows. Also, parts of the code is still rough and needs to be made sol
- [ ] Stdlib inclusion
- [ ] String functions
- [ ] Compile time incremental arrays
- [ ] Vararrays e.g. `int[*]`
- [ ] Simd vector types
- [ ] Complex types
#### What can you help with?

View File

@@ -399,9 +399,6 @@ void fprint_type_recursive(Context *context, FILE *file, Type *type, int indent)
case TYPE_DISTINCT:
DUMPF("(distinct %s)", type->name);
return;
case TYPE_COMPLEX:
DUMP("(type complex");
return;
case TYPE_VECTOR:
DUMP("(type vector");
return;

View File

@@ -266,14 +266,17 @@ void compiler_compile(void)
vec_add(global_context.sources, strformat("%s/std/math.c3", global_context.lib_dir));
}
bool has_error = false;
VECEACH(global_context.sources, i)
{
bool loaded = false;
File *file = source_file_load(global_context.sources[i], &loaded);
if (loaded) continue;
if (!parse_file(file)) continue;
if (!parse_file(file)) has_error = true;
}
if (has_error) exit(EXIT_FAILURE);
global_context.std_module_path = (Path) { .module = kw_std, .span = INVALID_RANGE, .len = strlen(kw_std) };
global_context.std_module = (Module){ .name = &global_context.std_module_path };
global_context.std_module.stage = ANALYSIS_LAST;

View File

@@ -222,7 +222,6 @@ struct Type_
Type *pointer;
// Type[<123>] or Type<[123]>
TypeVector vector;
Type *complex;
};
};

View File

@@ -103,7 +103,6 @@ typedef enum
CAST_BOOLBOOL,
CAST_FPBOOL,
CAST_INTBOOL,
CAST_CXBOOL,
CAST_FPFP,
CAST_FPSI,
CAST_FPUI,
@@ -507,7 +506,6 @@ typedef enum
TYPE_TYPEINFO,
TYPE_MEMBER,
TYPE_VECTOR,
TYPE_COMPLEX,
TYPE_VIRTUAL,
TYPE_VIRTUAL_ANY,
TYPE_LAST = TYPE_MEMBER

View File

@@ -127,8 +127,6 @@ static void header_print_type(FILE *file, Type *type)
break;
case TYPE_VECTOR:
break;
case TYPE_COMPLEX:
break;
}
TODO
}

View File

@@ -63,23 +63,6 @@ static bool riscv_detect_fpcc_struct_internal(Type *type, unsigned current_offse
return false;
}
if (type->type_kind == TYPE_COMPLEX)
{
// Is the first field already occupied?
// Then fail because both needs to be available.
if (*field1) return false;
// If the field doesn't fit a register - bail.
Type *element_type = type->complex;
unsigned element_size = type_size(element_type);
if (element_size > flen) return false;
assert(!current_offset && "Expected zero offset");
*field1 = abi_type_new_plain(element_type);
*field2 = abi_type_new_plain(element_type);
*field1_offset = current_offset;
*field2_offset = current_offset + element_size;
return true;
}
if (type->type_kind == TYPE_ARRAY)
{
ByteSize array_len = type->array.len;
@@ -176,18 +159,6 @@ static ABIArgInfo *riscv_classify_argument_type(Type *type, bool is_fixed, unsig
return abi_arg_new_direct();
}
// Complex types for the hard float ABI must be passed direct rather than
// using CoerceAndExpand.
if (is_fixed && type->type_kind == TYPE_COMPLEX && *fprs >= 2)
{
Type *element_type = type->complex;
if (type_size(element_type) <= platform_target.riscv.flen)
{
(*fprs) -= 2;
// TODO check that this will expand correctly.
return abi_arg_new_direct();
}
}
if (is_fixed && platform_target.riscv.flen && (type->type_kind == TYPE_STRUCT || type->type_kind == TYPE_ERRTYPE))
{
@@ -306,17 +277,10 @@ void c_abi_func_create_riscv(FunctionSignature *signature)
// in LLVM IR, relying on the backend lowering code to rewrite the argument
// list and pass indirectly on RV32.
bool is_ret_indirect = abi_arg_is_indirect(return_abi);
if (!is_ret_indirect && type_is_scalar(return_type) && type_size(return_type) > 2 * platform_target.riscv.xlen)
if (type_is_scalar(return_type) && type_size(return_type) > 2 * platform_target.riscv.xlen)
{
if (return_type->type_kind == TYPE_COMPLEX && platform_target.riscv.flen)
{
is_ret_indirect = type_size(return_type->complex) > platform_target.riscv.flen;
}
else
{
// Normal scalar > 2 * XLen, e.g. f128 on RV32
is_ret_indirect = true;
}
// Normal scalar > 2 * XLen, e.g. f128 on RV32
is_ret_indirect = true;
}
// Clang: We must track the number of GPRs used in order to conform to the RISC-V
// ABI, as integer scalars passed in registers should have signext/zeroext

View File

@@ -369,48 +369,6 @@ void x64_classify_vector(Type *type, ByteSize offset_base, X64Class *current, X6
// Default pass by mem
}
void x64_classify_complex(Type *type, ByteSize offset_base, X64Class *current, X64Class *lo_class, X64Class *hi_class)
{
Type *element = type->complex;
ByteSize element_size = type_size(element);
switch (type->type_kind)
{
case TYPE_I8:
case TYPE_I16:
case TYPE_I32:
case TYPE_I64:
case TYPE_U8:
case TYPE_U16:
case TYPE_U32:
case TYPE_U64:
*current = CLASS_INTEGER;
break;
case TYPE_I128:
case TYPE_U128:
*lo_class = *hi_class = CLASS_INTEGER;
break;
case TYPE_F16:
TODO
case TYPE_F32:
*current = CLASS_SSE;
break;
case TYPE_F64:
*lo_class = *hi_class = CLASS_SSE;
break;
case TYPE_F128:
*current = CLASS_MEMORY;
break;
default:
UNREACHABLE
}
ByteSize real = offset_base / 8;
ByteSize imag = (offset_base + element_size) / 8;
// If it crosses boundary, split it.
if (*hi_class == CLASS_NO_CLASS && real != imag)
{
*hi_class = *lo_class;
}
}
Decl *x64_get_member_at_offset(Decl *decl, unsigned offset)
{
@@ -496,9 +454,6 @@ static void x64_classify(Type *type, ByteSize offset_base, X64Class *lo_class, X
case TYPE_VECTOR:
x64_classify_vector(type, offset_base, current, lo_class, hi_class, named);
break;
case TYPE_COMPLEX:
x64_classify_complex(type, offset_base, current, lo_class, hi_class);
break;
}
}
@@ -663,7 +618,6 @@ AbiType *x64_get_int_type_at_offset(Type *type, unsigned offset, Type *source_ty
case TYPE_F128:
case TYPE_UNION:
case TYPE_VECTOR:
case TYPE_COMPLEX:
break;
}
ByteSize size = type_size(source_type);

View File

@@ -130,7 +130,6 @@ static bool x86_should_return_type_in_reg(Type *type)
case TYPE_ERRTYPE:
case TYPE_VIRTUAL_ANY:
case TYPE_VIRTUAL:
case TYPE_COMPLEX:
return true;
case TYPE_ARRAY:
// Small arrays <= 8 bytes.
@@ -206,11 +205,6 @@ ABIArgInfo *x86_classify_return(CallConvention call, Regs *regs, Type *type)
{
return create_indirect_return_x86(regs);
}
// If we don't allow small structs in reg:
if (!platform_target.x86.return_small_struct_in_reg_abi && type->type_kind == TYPE_COMPLEX)
{
return create_indirect_return_x86(regs);
}
// Ignore empty struct/unions
if (type_is_empty_record(type, true))
{
@@ -320,13 +314,6 @@ static inline bool x86_can_expand_indirect_aggregate_arg(Type *type)
case TYPE_I64:
case TYPE_F64:
break;
case TYPE_COMPLEX:
{
ByteSize complex_type_size = type_size(member_type->complex);
if (complex_type_size != 4 && complex_type_size != 8) return false;
size += type_size(member_type);
break;
}
default:
return false;
}
@@ -630,7 +617,6 @@ static ABIArgInfo *x86_classify_argument(CallConvention call, Regs *regs, Type *
case TYPE_VIRTUAL:
case TYPE_ARRAY:
case TYPE_ERR_UNION:
case TYPE_COMPLEX:
return x86_classify_aggregate(call, regs, type);
case TYPE_TYPEINFO:
case TYPE_MEMBER:

View File

@@ -560,8 +560,6 @@ static inline LLVMMetadataRef llvm_get_debug_type_internal(GenContext *c, Type *
case TYPE_F64:
case TYPE_F128:
return llvm_debug_simple_type(c, type, DW_ATE_float);
case TYPE_COMPLEX:
return llvm_debug_simple_type(c, type, DW_ATE_complex_float);
case TYPE_VECTOR:
return type->backend_debug_type = llvm_debug_vector_type(c, type);
case TYPE_VOID:

View File

@@ -349,9 +349,6 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, BEValue *value, Type *to_
case CAST_VRPTR:
case CAST_PTRVR:
TODO
case CAST_CXBOOL:
TODO
case CAST_XIERR:
// TODO Insert zero check.
llvm_value_rvalue(c, value);
@@ -2236,17 +2233,6 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr)
llvm_value_set(be_value, llvm_const_int(c, type, bigint_as_signed(&expr->const_expr.i)), type);
}
return;
case TYPE_COMPLEX:
{
LLVMTypeRef element_type = llvm_get_type(c, type->complex);
LLVMValueRef value = LLVMGetUndef(llvm_get_type(c, type));
unsigned id = 0;
value = LLVMConstInsertValue(value, LLVMConstReal(element_type, (double)expr->const_expr.complex.r), &id, 1);
id++;
value = LLVMConstInsertValue(value, LLVMConstReal(element_type, (double)expr->const_expr.complex.i), &id, 1);
llvm_value_set(be_value, value, type);
return;
}
case ALL_FLOATS:
llvm_value_set(be_value, LLVMConstReal(llvm_get_type(c, type), (double) expr->const_expr.f), type);
return;
@@ -2344,7 +2330,6 @@ static void llvm_expand_type_to_args(GenContext *context, Type *param_type, LLVM
gencontext_expand_array_to_args(context, param_type, expand_ptr, values);
break;
case TYPE_UNION:
case TYPE_COMPLEX:
case TYPE_SUBARRAY:
case TYPE_VECTOR:
case TYPE_VIRTUAL_ANY:

View File

@@ -429,10 +429,6 @@ LLVMTypeRef llvm_get_type(GenContext *c, Type *any_type)
}
case TYPE_VECTOR:
return any_type->backend_type = LLVMVectorType(llvm_get_type(c, any_type->vector.base), any_type->vector.len);
case TYPE_COMPLEX:
return any_type->backend_type = llvm_get_twostruct(c,
llvm_get_type(c, any_type->complex),
llvm_get_type(c, any_type->complex));
}
UNREACHABLE;
}

View File

@@ -366,8 +366,6 @@ CastKind cast_to_bool_kind(Type *type)
return CAST_SABOOL;
case ALL_INTS:
return CAST_INTBOOL;
case TYPE_COMPLEX:
return CAST_CXBOOL;
case ALL_FLOATS:
return CAST_FPBOOL;
case TYPE_POINTER:
@@ -473,8 +471,6 @@ bool cast_may_explicit(Type *from_type, Type *to_type)
return to_kind == TYPE_POINTER;
case TYPE_VECTOR:
return type_is_structurally_equivalent(type_get_array(from->vector.base, from->vector.len), to);
case TYPE_COMPLEX:
return type_is_structurally_equivalent(type_get_array(from->complex, 2), to);
}
UNREACHABLE
}
@@ -817,8 +813,6 @@ bool cast(Expr *expr, Type *to_type)
break;
case TYPE_VECTOR:
TODO
case TYPE_COMPLEX:
TODO
}
UNREACHABLE
}

View File

@@ -464,7 +464,6 @@ static inline bool sema_analyse_distinct(Context *context, Decl *decl)
case TYPE_VARARRAY:
case TYPE_SUBARRAY:
case TYPE_VECTOR:
case TYPE_COMPLEX:
break;
}
// Do we need anything else?

View File

@@ -3936,8 +3936,6 @@ static bool sema_expr_analyse_comp(Context *context, Expr *expr, Expr *left, Exp
return false;
}
break;
case TYPE_COMPLEX:
TODO
case TYPE_VECTOR:
TODO
}
@@ -4258,7 +4256,6 @@ static bool sema_expr_analyse_not(Expr *expr, Expr *inner)
case TYPE_VIRTUAL_ANY:
case TYPE_VARARRAY:
case TYPE_SUBARRAY:
case TYPE_COMPLEX:
case TYPE_BOOL:
case TYPE_VECTOR:
case ALL_REAL_FLOATS:

View File

@@ -124,20 +124,6 @@ const char *type_to_error_string(Type *type)
return type->name;
case TYPE_FUNC:
return strcat_arena("func ", type->func.mangled_function_signature);
case TYPE_COMPLEX:
switch (type->complex->type_kind)
{
case TYPE_F16:
return "complex16";
case TYPE_F32:
return "complex32";
case TYPE_F64:
return "complex64";
case TYPE_F128:
return "complex128";
default:
UNREACHABLE
}
case TYPE_VECTOR:
asprintf(&buffer, "%s[<%llu>]", type_to_error_string(type->array.base), (unsigned long long)type->array.len);
return buffer;
@@ -208,8 +194,6 @@ ByteSize type_size(Type *type)
return type_size(type->decl->distinct_decl.base_type);
case TYPE_VECTOR:
return type_size(type->vector.base) * type->vector.len;
case TYPE_COMPLEX:
return type_size(type->complex) * 2;
case TYPE_POISONED:
case TYPE_TYPEINFO:
case TYPE_MEMBER:
@@ -369,7 +353,6 @@ bool type_is_abi_aggregate(Type *type)
case TYPE_SUBARRAY:
case TYPE_ARRAY:
case TYPE_ERR_UNION:
case TYPE_COMPLEX:
case TYPE_VIRTUAL:
case TYPE_VIRTUAL_ANY:
return true;
@@ -506,11 +489,6 @@ bool type_is_homogenous_aggregate(Type *type, Type **base, unsigned *elements)
RETRY:
switch (type->type_kind)
{
case TYPE_COMPLEX:
// Complex types are basically structs with 2 elements.
*base = type->complex;
*elements = 2;
break;
case TYPE_DISTINCT:
type = type->decl->distinct_decl.base_type;
goto RETRY;
@@ -676,7 +654,6 @@ AlignSize type_abi_alignment(Type *type)
case TYPE_INFERRED_ARRAY:
UNREACHABLE;
case TYPE_VECTOR:
case TYPE_COMPLEX:
TODO
case TYPE_VOID:
return 1;
@@ -1108,7 +1085,6 @@ static void type_append_name_to_scratch(Type *type)
case TYPE_TYPEID:
case TYPE_ERR_UNION:
case TYPE_VIRTUAL_ANY:
case TYPE_COMPLEX:
case TYPE_VECTOR:
scratch_buffer_append(type->name);
break;
@@ -1268,7 +1244,6 @@ bool type_is_scalar(Type *type)
case TYPE_ERRTYPE:
case TYPE_ERR_UNION:
case TYPE_VARARRAY:
case TYPE_COMPLEX:
case TYPE_VIRTUAL:
case TYPE_VIRTUAL_ANY:
return true;
@@ -1536,9 +1511,6 @@ Type *type_find_max_type(Type *type, Type *other)
case TYPE_VECTOR:
// No implicit conversion between vectors
return NULL;
case TYPE_COMPLEX:
// Implicit conversion or not?
TODO;
}
UNREACHABLE
}