Skip to content

Commit

Permalink
Start work on 0.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Nov 8, 2024
1 parent c16f34d commit 165ff32
Show file tree
Hide file tree
Showing 70 changed files with 878 additions and 872 deletions.
2 changes: 1 addition & 1 deletion src/build/build_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ static inline bool at_end()

static inline const char *next_arg()
{
assert(!at_end());
ASSERT0(!at_end());
current_arg = args[++arg_index];
return current_arg;
}
Expand Down
4 changes: 2 additions & 2 deletions src/build/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static void load_into_build_target(const char *filename, JSONObject *json, const
static void project_add_target(const char *filename, Project *project, BuildTarget *default_target, JSONObject *json,
const char *name, const char *type, TargetType target_type)
{
assert(json->type == J_OBJECT);
ASSERT0(json->type == J_OBJECT);
BuildTarget *target = CALLOCS(BuildTarget);
*target = *default_target;
vec_add(project->targets, target);
Expand All @@ -444,7 +444,7 @@ static void project_add_target(const char *filename, Project *project, BuildTarg

static void project_add_targets(const char *filename, Project *project, JSONObject *project_data)
{
assert(project_data->type == J_OBJECT);
ASSERT0(project_data->type == J_OBJECT);

BuildTarget default_target = default_build_target;
load_into_build_target(filename, project_data, NULL, &default_target);
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/abi/c_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ bool abi_arg_is_indirect(ABIArgInfo *info)

ABIArgInfo *abi_arg_new_indirect_realigned(AlignSize alignment, Type *by_val_type)
{
assert(alignment > 0);
ASSERT0(alignment > 0);
ABIArgInfo *info = abi_arg_new(ABI_ARG_INDIRECT);
info->indirect.alignment = alignment;
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
info->attributes.realign = true;
info->indirect.type = by_val_type;
info->attributes.by_val = true;
Expand All @@ -77,15 +77,15 @@ ABIArgInfo *abi_arg_new_indirect_by_val(Type *by_val_type)
info->indirect.alignment = type_abi_alignment(by_val_type);
info->indirect.type = by_val_type;
info->attributes.by_val = true;
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
return info;
}

ABIArgInfo *abi_arg_new_indirect_not_by_val(Type *type)
{
ABIArgInfo *info = abi_arg_new(ABI_ARG_INDIRECT);
info->indirect.alignment = type_abi_alignment(type);
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
info->indirect.type = type;
info->attributes.by_val = false;
return info;
Expand Down Expand Up @@ -175,7 +175,7 @@ ABIArgInfo *abi_arg_new_direct_coerce_int(void)

ABIArgInfo *abi_arg_new_direct_coerce_type(Type *type)
{
assert(type);
ASSERT0(type);
ABIArgInfo *info = abi_arg_new(ABI_ARG_DIRECT_COERCE);
info->direct_coerce_type = type->canonical;
return info;
Expand All @@ -191,7 +191,7 @@ ABIArgInfo *abi_arg_new_direct_struct_expand_i32(uint8_t elements)

void c_abi_func_create(FunctionPrototype *proto)
{
assert(!proto->is_resolved);
ASSERT0(!proto->is_resolved);
proto->is_resolved = true;
switch (compiler.platform.abi)
{
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/abi/c_abi_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ABIArgInfo *aarch64_coerce_illegal_vector(Type *type)
UNREACHABLE
}*/
}
assert(type->type_kind == TYPE_VECTOR);
ASSERT0(type->type_kind == TYPE_VECTOR);
TypeSize size = type_size(type);

// CLANG: Android promotes char[<2>] to ushort, not uint
Expand Down Expand Up @@ -107,7 +107,7 @@ ABIArgInfo *aarch64_classify_argument_type(Type *type)
unsigned members = 0;
if (type_is_homogenous_aggregate(type, &base, &members))
{
assert(members < 128);
ASSERT0(members < 128);
if (members > 1)
{
return abi_arg_new_direct_coerce_type(type_get_array(base, members));
Expand All @@ -134,7 +134,7 @@ ABIArgInfo *aarch64_classify_argument_type(Type *type)
size = aligned_offset(size, alignment);
// We use a pair of i64 for 16-byte aggregate with 8-byte alignment.
// For aggregates with 16-byte alignment, we use i128.
assert(alignment == 8 || alignment == 16);
ASSERT0(alignment == 8 || alignment == 16);

if (alignment == 16) return abi_arg_new_direct_coerce_type(type_u128);
ArraySize m = size / alignment;
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/abi/c_abi_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

static ABIArgInfo *riscv_coerce_and_expand_fpcc_struct(AbiType field1, unsigned field1_offset, AbiType field2, unsigned field2_offset)
{
assert(abi_type_is_type(field1));
ASSERT0(abi_type_is_type(field1));
if (!abi_type_is_valid(field2))
{
return abi_arg_new_direct_coerce_type(field1.type);
}

assert(abi_type_is_type(field2));
ASSERT0(abi_type_is_type(field2));
Type *type2 = field2.type;
ByteSize abi_type_size = type_size(type2);
// Not on even offset, use packed semantics.
Expand Down Expand Up @@ -132,10 +132,10 @@ static bool riscv_detect_fpcc_struct(Type *type, AbiType *field1_ref, unsigned *
static ABIArgInfo *riscv_classify_argument_type(Type *type, bool is_fixed, unsigned *gprs, unsigned *fprs)
{

assert(type == type->canonical);
ASSERT0(type == type->canonical);

unsigned xlen = compiler.platform.riscv.xlen;
assert(is_power_of_two(xlen));
ASSERT0(is_power_of_two(xlen));

ByteSize size = type_size(type);

Expand Down
48 changes: 24 additions & 24 deletions src/compiler/abi/c_abi_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ABIArgInfo *x64_indirect_result(Type *type, unsigned free_int_regs)
*/
ABIArgInfo *x64_classify_reg_call_struct_type_check(Type *type, Registers *needed_registers)
{
assert(x64_type_is_structure(type));
ASSERT0(x64_type_is_structure(type));

// These are all passed in two registers.
if (type->type_kind == TYPE_SLICE || type->type_kind == TYPE_ANY)
Expand All @@ -132,7 +132,7 @@ ABIArgInfo *x64_classify_reg_call_struct_type_check(Type *type, Registers *neede
}

// Struct, err type handled =>
assert(type->type_kind == TYPE_STRUCT);
ASSERT0(type->type_kind == TYPE_STRUCT);

// Variable array structs are always passed by pointer.
if (type->decl->has_variable_array) return x64_indirect_return_result(type);
Expand Down Expand Up @@ -175,7 +175,7 @@ static X64Class x64_merge(X64Class accum, X64Class field)
// 6. SSE

// Accum should never be memory (we should have returned) or
assert(accum != CLASS_MEMORY);
ASSERT0(accum != CLASS_MEMORY);
if (accum == field) return accum;

// Swap
Expand Down Expand Up @@ -305,7 +305,7 @@ void x64_classify_array(Type *type, ByteSize offset_base, X64Class *current, X64
if (*lo_class == CLASS_MEMORY || *hi_class == CLASS_MEMORY) break;
}
x64_classify_post_merge(size, lo_class, hi_class);
assert(*hi_class != CLASS_SSEUP || *lo_class == CLASS_SSE);
ASSERT0(*hi_class != CLASS_SSEUP || *lo_class == CLASS_SSE);
}

void x64_classify_vector(Type *type, ByteSize offset_base, X64Class *current, X64Class *lo_class, X64Class *hi_class,
Expand Down Expand Up @@ -365,7 +365,7 @@ static Decl *x64_get_member_at_offset(Decl *decl, unsigned offset)
if (member->offset > (ArrayIndex)offset) break;
last_match = member;
}
assert(last_match);
ASSERT0(last_match);
return last_match;
}

Expand Down Expand Up @@ -616,7 +616,7 @@ AbiType x64_get_int_type_at_offset(Type *type, unsigned offset, Type *source_typ
break;
}
ByteSize size = type_size(source_type);
assert(size != source_offset);
ASSERT0(size != source_offset);
if (size - source_offset > 8) return abi_type_get(type_ulong);
return abi_type_get_int_bits((size - source_offset) * 8);
}
Expand Down Expand Up @@ -649,7 +649,7 @@ static AbiType x64_get_byte_vector_type(Type *type)

unsigned size = type_size(type);

assert(size == 16 || size == 32 || size == 64);
ASSERT0(size == 16 || size == 32 || size == 64);

// Return a vector type based on the size.
return abi_type_get(type_get_vector(type_double, size / 8));
Expand All @@ -659,7 +659,7 @@ static ABIArgInfo *x64_get_argument_pair_return(AbiType low_type, AbiType high_t
{
TypeSize low_size = abi_type_size(low_type);
unsigned hi_start = aligned_offset(low_size, abi_type_abi_alignment(high_type));
assert(hi_start == 8 && "Expected aligned with C-style structs.");
ASSERT0(hi_start == 8 && "Expected aligned with C-style structs.");
return abi_arg_new_direct_pair(low_type, high_type);
}

Expand All @@ -673,8 +673,8 @@ ABIArgInfo *x64_classify_return(Type *return_type)
x64_classify(return_type, 0, &lo_class, &hi_class, NAMED);

// Invariants
assert(hi_class != CLASS_MEMORY || lo_class == CLASS_MEMORY);
assert(hi_class != CLASS_SSEUP || lo_class == CLASS_SSE);
ASSERT0(hi_class != CLASS_MEMORY || lo_class == CLASS_MEMORY);
ASSERT0(hi_class != CLASS_SSEUP || lo_class == CLASS_SSE);

AbiType result_type = ABI_TYPE_EMPTY;
switch (lo_class)
Expand All @@ -685,7 +685,7 @@ ABIArgInfo *x64_classify_return(Type *return_type)
return abi_arg_ignore();
}
// If low part is padding, keep type null
assert(hi_class == CLASS_SSE || hi_class == CLASS_INTEGER);
ASSERT0(hi_class == CLASS_SSE || hi_class == CLASS_INTEGER);
break;
case CLASS_SSEUP:
UNREACHABLE
Expand Down Expand Up @@ -717,11 +717,11 @@ ABIArgInfo *x64_classify_return(Type *return_type)
// Previously handled.
break;
case CLASS_INTEGER:
assert(lo_class != CLASS_NO_CLASS);
ASSERT0(lo_class != CLASS_NO_CLASS);
high_part = x64_get_int_type_at_offset(return_type, 8, return_type, 8);
break;
case CLASS_SSE:
assert(lo_class != CLASS_NO_CLASS);
ASSERT0(lo_class != CLASS_NO_CLASS);
high_part = abi_type_get(x64_get_sse_type_at_offset(return_type, 8, return_type, 8));
break;
case CLASS_SSEUP:
Expand All @@ -730,7 +730,7 @@ ABIArgInfo *x64_classify_return(Type *return_type)
// vector register.
//
// SSEUP should always be preceded by SSE, just widen.
assert(lo_class == CLASS_SSE && "Unexpected SSEUp classification.");
ASSERT0(lo_class == CLASS_SSE && "Unexpected SSEUp classification.");
result_type = x64_get_byte_vector_type(return_type);
break;
}
Expand All @@ -748,7 +748,7 @@ ABIArgInfo *x64_classify_return(Type *return_type)
}
return abi_arg_new_direct_coerce_type(result_type.type->canonical);
}
assert(result_type.int_bits_plus_1 - 1 == type_size(return_type) * 8);
ASSERT0(result_type.int_bits_plus_1 - 1 == type_size(return_type) * 8);
return abi_arg_new_direct_coerce_int();
}

Expand All @@ -764,14 +764,14 @@ ABIArgInfo *x64_classify_return(Type *return_type)
*/
static ABIArgInfo *x64_classify_argument_type(Type *type, unsigned free_int_regs, Registers *needed_registers, NamedArgument is_named)
{
assert(type == type_lowering(type));
ASSERT0(type == type_lowering(type));
X64Class hi_class;
X64Class lo_class;
x64_classify(type, 0, &lo_class, &hi_class, is_named);

// Invariants
assert(hi_class != CLASS_MEMORY || lo_class == CLASS_MEMORY);
assert(hi_class != CLASS_SSEUP || lo_class == CLASS_SSE);
ASSERT0(hi_class != CLASS_MEMORY || lo_class == CLASS_MEMORY);
ASSERT0(hi_class != CLASS_SSEUP || lo_class == CLASS_SSE);

AbiType result_type;
*needed_registers = (Registers) { 0, 0 };
Expand All @@ -781,7 +781,7 @@ static ABIArgInfo *x64_classify_argument_type(Type *type, unsigned free_int_regs
{
case CLASS_NO_CLASS:
// Only C++ would leave 8 bytes of padding, so we can ignore that case.
assert(hi_class == CLASS_NO_CLASS);
ASSERT0(hi_class == CLASS_NO_CLASS);
return abi_arg_ignore();
case CLASS_SSEUP:
UNREACHABLE
Expand All @@ -792,7 +792,7 @@ static ABIArgInfo *x64_classify_argument_type(Type *type, unsigned free_int_regs
result_type = x64_get_int_type_at_offset(type, 0, type, 0);
if (hi_class == CLASS_NO_CLASS && type_is_promotable_int_bool(type))
{
assert(abi_type_is_type(result_type));
ASSERT0(abi_type_is_type(result_type));
return abi_arg_new_direct_coerce_int_ext(result_type.type);
}
break;
Expand All @@ -814,15 +814,15 @@ static ABIArgInfo *x64_classify_argument_type(Type *type, unsigned free_int_regs
needed_registers->int_registers++;
high_part = x64_get_int_type_at_offset(type, 8, type, 8);
// Return directly into high part.
assert(lo_class != CLASS_NO_CLASS && "empty first 8 bytes not allowed, this is C++ stuff.");
ASSERT0(lo_class != CLASS_NO_CLASS && "empty first 8 bytes not allowed, this is C++ stuff.");
break;
case CLASS_SSE:
needed_registers->sse_registers++;
high_part = abi_type_get(x64_get_sse_type_at_offset(type, 8, type, 8));
assert(lo_class != CLASS_NO_CLASS && "empty first 8 bytes not allowed, this is C++ stuff");
ASSERT0(lo_class != CLASS_NO_CLASS && "empty first 8 bytes not allowed, this is C++ stuff");
break;
case CLASS_SSEUP:
assert(lo_class == CLASS_SSE && "Unexpected SSEUp classification.");
ASSERT0(lo_class == CLASS_SSE && "Unexpected SSEUp classification.");
result_type = x64_get_byte_vector_type(type);
break;
}
Expand All @@ -843,7 +843,7 @@ static ABIArgInfo *x64_classify_argument_type(Type *type, unsigned free_int_regs
}
return abi_arg_new_direct_coerce_type(result);
}
assert(result_type.int_bits_plus_1 - 1 == type_size(type) * 8);
ASSERT0(result_type.int_bits_plus_1 - 1 == type_size(type) * 8);
return abi_arg_new_direct_coerce_int();
}

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/abi/c_abi_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static ABIArgInfo *create_indirect_return_x86(Type *type, Regs *regs)

static bool x86_should_return_type_in_reg(Type *type)
{
assert(type->canonical == type);
ASSERT0(type->canonical == type);
ByteSize size = type_size(type);
if (size > 8) return false;

Expand Down Expand Up @@ -226,7 +226,7 @@ static inline bool x86_is_mmxtype(Type *type)

static inline bool x86_can_expand_indirect_aggregate_arg(Type *type)
{
assert(type_is_abi_aggregate(type));
ASSERT0(type_is_abi_aggregate(type));

// Test whether an argument type which is to be passed indirectly (on the
// stack) would have the equivalent layout if it was expanded into separate
Expand Down Expand Up @@ -373,7 +373,7 @@ static inline ABIArgInfo *x86_classify_vector(Regs *regs, Type *type)
static inline ABIArgInfo *x86_classify_aggregate(CallABI call, Regs *regs, Type *type)
{
// Only called for aggregates.
assert(type_is_abi_aggregate(type));
ASSERT0(type_is_abi_aggregate(type));

if (type_is_union_or_strukt(type) && type->decl->has_variable_array)
{
Expand All @@ -390,7 +390,7 @@ static inline ABIArgInfo *x86_classify_aggregate(CallABI call, Regs *regs, Type
// Here we coerce the aggregate into a struct { i32, i32, ... }
// but we do not generate this struct immediately here.
unsigned size_in_regs = (size + 3) / 4;
assert(size_in_regs < 8);
ASSERT0(size_in_regs < 8);
ABIArgInfo *info;
if (size_in_regs > 1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/asm_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static inline void reg_instr_clob(PlatformTarget *target, const char *name, Clob
unsigned param_count = 0;
while (args && args[0] != 0)
{
assert(param_count <= MAX_ASM_INSTRUCTION_PARAMS);
ASSERT0(param_count <= MAX_ASM_INSTRUCTION_PARAMS);
instr->param[param_count++] = decode_arg_type(&args);
}
instr->param_count = param_count;
Expand All @@ -188,7 +188,7 @@ static inline void reg_instr(PlatformTarget *target, const char *name, const cha
int param_count = 0;
while (args && args[0] != 0)
{
assert(param_count <= MAX_ASM_INSTRUCTION_PARAMS);
ASSERT0(param_count <= MAX_ASM_INSTRUCTION_PARAMS);
instr->param[param_count++] = decode_arg_type(&args);
}
instr->param_count = param_count;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Decl *decl_new_generated_var(Type *type, VarDeclKind kind, SourceSpan span)
decl->var.kind = kind;
decl->type = type;
decl->alignment = type ? type_alloca_alignment(type) : 0;
assert(!type || !type_is_user_defined(type) || type->decl->resolve_status == RESOLVE_DONE);
ASSERT0(!type || !type_is_user_defined(type) || type->decl->resolve_status == RESOLVE_DONE);
decl->var.type_info = type_info_id_new_base(type, span);
decl->resolve_status = RESOLVE_DONE;
return decl;
Expand Down Expand Up @@ -428,7 +428,7 @@ AlignSize decl_find_member_offset(Decl *decl, Decl *member)
default:
return NO_MATCH;
}
assert(members);
ASSERT0(members);
unsigned list = vec_size(members);
for (unsigned i = 0; i < list; i++)
{
Expand Down
Loading

0 comments on commit 165ff32

Please sign in to comment.