Pass more tests #32
130
src/compiler.bbb
130
src/compiler.bbb
@ -1989,6 +1989,10 @@ value_is_constant = fn (value: &Value) u1
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
.call =>
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
else =>
|
||||
{
|
||||
#trap();
|
||||
@ -2322,6 +2326,9 @@ LLVMICmpPredicate = enum u32
|
||||
[extern] LLVMDIBuilderCreateFunction = fn [cc(c)] (di_builder: &LLVMDIBuilder, scope: &LLVMMetadata, name_pointer: &u8, name_length: u64, linkage_name_pointer: &u8, linkage_name_length: u64, file: &LLVMMetadata, line: u32, type: &LLVMMetadata, is_local_to_unit: s32, is_definition: s32, scope_line: u32, flags: LLVMDIFlags, is_optimized: s32) &LLVMMetadata;
|
||||
[extern] LLVMDIBuilderFinalizeSubprogram = fn [cc(c)] (di_builder: &LLVMDIBuilder, subprogram: &LLVMMetadata) void;
|
||||
|
||||
[extern] LLVMDIBuilderCreateGlobalVariableExpression = fn [cc(c)] (di_builder: &LLVMDIBuilder, scope: &LLVMMetadata, name_pointer: &u8, name_length: u64, linkage_name_pointer: &u8, linkage_name_length: u64, file: &LLVMMetadata, line: u32, type: &LLVMMetadata, local_to_unit: s32, expression: &LLVMMetadata, declaration: &LLVMMetadata, bit_alignment: u32) &LLVMMetadata;
|
||||
[extern] LLVMGlobalSetMetadata = fn [cc(c)] (global: &LLVMValue, kind: u32, metadata: &LLVMMetadata) void;
|
||||
|
||||
[extern] LLVMDIBuilderCreateLexicalBlock = fn [cc(c)] (di_builder: &LLVMDIBuilder, scope: &LLVMMetadata, file: &LLVMMetadata, line: u32, column: u32) &LLVMMetadata;
|
||||
[extern] LLVMDIBuilderCreateDebugLocation = fn [cc(c)] (context: &LLVMContext, line: u32, column: u32, scope: &LLVMMetadata, inlined_at: &LLVMMetadata) &LLVMMetadata;
|
||||
[extern] LLVMDIBuilderCreateAutoVariable = fn [cc(c)] (di_builder: &LLVMDIBuilder, scope: &LLVMMetadata, name_pointer: &u8, name_length: u64, file: &LLVMMetadata, line: u32, type: &LLVMMetadata, always_preserve: s32, flags: LLVMDIFlags, bit_alignment: u32) &LLVMMetadata;
|
||||
@ -6234,7 +6241,30 @@ parse = fn (module: &Module) void
|
||||
|
||||
if (!is_global_keyword)
|
||||
{
|
||||
#trap();
|
||||
>initial_value = parse_value(module, scope, zero);
|
||||
skip_space(module);
|
||||
expect_character(module, ';');
|
||||
|
||||
>global_storage = new_value(module);
|
||||
global_storage.& = {
|
||||
.id = .global,
|
||||
zero,
|
||||
};
|
||||
|
||||
>global = new_global(module);
|
||||
global.& = {
|
||||
.variable = {
|
||||
.storage = global_storage,
|
||||
.type = global_type,
|
||||
.scope = scope,
|
||||
.name = global_name,
|
||||
.line = global_line,
|
||||
.column = global_column,
|
||||
},
|
||||
.initial_value = initial_value,
|
||||
.linkage = .internal, // TODO: linkage
|
||||
zero,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7011,7 +7041,11 @@ abi_system_v_classify_return_type = fn (module: &Module, semantic_return_type: &
|
||||
{
|
||||
if (is_integral_or_enumeration_type(semantic_return_type) and? is_promotable_integer_type_for_abi(semantic_return_type))
|
||||
{
|
||||
#trap();
|
||||
return abi_system_v_get_extend({
|
||||
.semantic_type = semantic_return_type,
|
||||
.sign = type_is_signed(semantic_return_type),
|
||||
zero,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -10821,14 +10855,14 @@ emit = fn (module: &Module) void
|
||||
continue;
|
||||
}
|
||||
|
||||
>global_pointer_type = global.variable.storage.type;
|
||||
assert(global_pointer_type.id == .pointer);
|
||||
>global_value_type = global_pointer_type.content.pointer.element_type;
|
||||
|
||||
switch (global.variable.storage.id)
|
||||
{
|
||||
.function, .forward_declared_function =>
|
||||
{
|
||||
>global_pointer_type = global.variable.storage.type;
|
||||
assert(global_pointer_type.id == .pointer);
|
||||
>global_value_type = global_pointer_type.content.pointer.element_type;
|
||||
|
||||
>function_type = &global_value_type.content.function;
|
||||
>semantic_argument_types = function_type.base.semantic_argument_types;
|
||||
>semantic_return_type = function_type.base.semantic_return_type;
|
||||
@ -11036,7 +11070,51 @@ emit = fn (module: &Module) void
|
||||
},
|
||||
.global =>
|
||||
{
|
||||
#trap();
|
||||
assert(!module.current_function);
|
||||
>initial_value = global.initial_value;
|
||||
analyze_value(module, initial_value, global.variable.type, .memory, 1);
|
||||
|
||||
>initial_value_type = initial_value.type;
|
||||
|
||||
if (!global.variable.type)
|
||||
{
|
||||
global.variable.type = initial_value_type;
|
||||
}
|
||||
|
||||
>global_type = global.variable.type;
|
||||
|
||||
if (global_type != initial_value_type)
|
||||
{
|
||||
report_error();
|
||||
}
|
||||
|
||||
resolve_type_in_place(module, global_type);
|
||||
|
||||
>is_constant: u1 = 0;
|
||||
>linkage: LLVMLinkage = undefined;
|
||||
switch (global.linkage)
|
||||
{
|
||||
.internal => { linkage = .internal; },
|
||||
.external => { linkage = .external; },
|
||||
}
|
||||
|
||||
>thread_local_mode: LLVMThreadLocalMode = .none;
|
||||
>externally_initialized: u1 = 0;
|
||||
>alignment = get_byte_alignment(global_type);
|
||||
>unnamed_address: LLVMUnnamedAddress = .none;
|
||||
|
||||
>llvm_global = llvm_create_global_variable(module.llvm.module, global_type.llvm.memory, is_constant, linkage, initial_value.llvm, global.variable.name, thread_local_mode, externally_initialized, alignment, unnamed_address);
|
||||
global.variable.storage.llvm = llvm_global;
|
||||
global.variable.storage.type = get_pointer_type(module, global_type);
|
||||
|
||||
if (module.has_debug_info)
|
||||
{
|
||||
>name = global.variable.name;
|
||||
>linkage_name = name;
|
||||
>local_to_unit = global.linkage == .internal;
|
||||
>global_debug = LLVMDIBuilderCreateGlobalVariableExpression(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, linkage_name.pointer, linkage_name.length, module.llvm.file, global.variable.line, global_type.llvm.debug, #extend(local_to_unit), null_expression(module), zero, alignment * 8);
|
||||
LLVMGlobalSetMetadata(llvm_global, 0, global_debug);
|
||||
}
|
||||
},
|
||||
else =>
|
||||
{
|
||||
@ -11055,6 +11133,11 @@ emit = fn (module: &Module) void
|
||||
assert(!module.current_macro_instantiation);
|
||||
assert(!module.current_macro_declaration);
|
||||
|
||||
if (global.emitted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (global.variable.storage.id == .function)
|
||||
{
|
||||
module.current_function = global;
|
||||
@ -11088,11 +11171,11 @@ emit = fn (module: &Module) void
|
||||
.ignore => {},
|
||||
.indirect =>
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
},
|
||||
.in_alloca =>
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
},
|
||||
else =>
|
||||
{
|
||||
@ -11134,12 +11217,12 @@ emit = fn (module: &Module) void
|
||||
|
||||
if (coerce_to_type.llvm.abi != LLVMTypeOf(v))
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
|
||||
if (is_promoted)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
|
||||
// TODO: this we can get rid of because we handle all of this inside `create_alloca`, load, stores, etc
|
||||
@ -11171,7 +11254,7 @@ emit = fn (module: &Module) void
|
||||
}
|
||||
else
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
|
||||
create_store(module, {
|
||||
@ -11206,7 +11289,7 @@ emit = fn (module: &Module) void
|
||||
>is_fixed_vector_type: u1 = 0;
|
||||
if (is_fixed_vector_type)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
|
||||
if (coerce_to_type.id == .struct and coerce_to_type.content.struct.fields.length > 1 and argument_abi.flags.kind == .direct and !argument_abi.flags.can_be_flattened)
|
||||
@ -11214,7 +11297,7 @@ emit = fn (module: &Module) void
|
||||
>contains_homogeneous_scalable_vector_types: u1 = 0;
|
||||
if (contains_homogeneous_scalable_vector_types)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -11229,7 +11312,7 @@ emit = fn (module: &Module) void
|
||||
|
||||
if (argument_abi.attributes.direct.offset > 0)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -11245,7 +11328,7 @@ emit = fn (module: &Module) void
|
||||
|
||||
if (is_scalable)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -11309,7 +11392,7 @@ emit = fn (module: &Module) void
|
||||
},
|
||||
.indirect =>
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
},
|
||||
else =>
|
||||
{
|
||||
@ -11349,7 +11432,7 @@ emit = fn (module: &Module) void
|
||||
}
|
||||
else
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -11373,7 +11456,7 @@ emit = fn (module: &Module) void
|
||||
|
||||
if (has_single_jump_to_return_block)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -11391,7 +11474,7 @@ emit = fn (module: &Module) void
|
||||
>semantic_return_type = return_abi.semantic_type;
|
||||
if (semantic_return_type == noreturn_type(module) or function.content.function.attributes.naked)
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
else if (semantic_return_type == void_type(module))
|
||||
{
|
||||
@ -11429,12 +11512,12 @@ emit = fn (module: &Module) void
|
||||
}
|
||||
else
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
}
|
||||
},
|
||||
.indirect =>
|
||||
{
|
||||
#trap();
|
||||
#trap();
|
||||
},
|
||||
}
|
||||
|
||||
@ -11773,6 +11856,9 @@ names: [_][]u8 = [
|
||||
"basic_while",
|
||||
"pointer",
|
||||
"pointer_cast",
|
||||
"u1_return",
|
||||
"local_type_inference",
|
||||
"global",
|
||||
];
|
||||
|
||||
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32
|
||||
|
@ -9461,7 +9461,6 @@ void emit(Module* module)
|
||||
}
|
||||
|
||||
LLVMThreadLocalMode thread_local_mode = LLVMNotThreadLocal;
|
||||
unsigned address_space = 0;
|
||||
bool externally_initialized = false;
|
||||
|
||||
auto alignment = get_byte_alignment(global_type);
|
||||
|
Loading…
x
Reference in New Issue
Block a user