wip
This commit is contained in:
parent
04ca049e6c
commit
9d6d3935e3
1071
src/compiler.bbb
1071
src/compiler.bbb
File diff suppressed because it is too large
Load Diff
@ -3231,6 +3231,7 @@ fn void analyze_type(Module* module, Value* value, Type* expected_type, TypeAnal
|
|||||||
|
|
||||||
if (expected_type->array.element_count == 0)
|
if (expected_type->array.element_count == 0)
|
||||||
{
|
{
|
||||||
|
// TODO: use existing types?
|
||||||
expected_type->array.element_count = values.length;
|
expected_type->array.element_count = values.length;
|
||||||
assert(expected_type->name.equal(string_literal("")));
|
assert(expected_type->name.equal(string_literal("")));
|
||||||
expected_type->name = array_name(module, expected_type->array.element_type, expected_type->array.element_count);
|
expected_type->name = array_name(module, expected_type->array.element_type, expected_type->array.element_count);
|
||||||
@ -5081,11 +5082,6 @@ fn LLVMValueRef emit_call(Module* module, Value* value, LLVMValueRef left_llvm,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_byte_size(semantic_argument_type) > 60 && argument_abi.flags.kind != AbiKind::indirect)
|
|
||||||
{
|
|
||||||
trap();
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve_type_in_place(module, semantic_argument_type);
|
resolve_type_in_place(module, semantic_argument_type);
|
||||||
|
|
||||||
if (is_named_argument)
|
if (is_named_argument)
|
||||||
@ -8036,7 +8032,7 @@ fn void analyze_statement(Module* module, Scope* scope, Statement* statement, u3
|
|||||||
|
|
||||||
auto condition = statement->if_st.condition;
|
auto condition = statement->if_st.condition;
|
||||||
analyze_value(module, condition, 0, TypeKind::abi, false);
|
analyze_value(module, condition, 0, TypeKind::abi, false);
|
||||||
auto llvm_condition = emit_condition(module, statement->if_st.condition);
|
auto llvm_condition = emit_condition(module, condition);
|
||||||
|
|
||||||
LLVMBuildCondBr(module->llvm.builder, llvm_condition, taken_block, not_taken_block);
|
LLVMBuildCondBr(module->llvm.builder, llvm_condition, taken_block, not_taken_block);
|
||||||
LLVMPositionBuilderAtEnd(module->llvm.builder, taken_block);
|
LLVMPositionBuilderAtEnd(module->llvm.builder, taken_block);
|
||||||
@ -8125,12 +8121,12 @@ fn void analyze_statement(Module* module, Scope* scope, Statement* statement, u3
|
|||||||
|
|
||||||
LLVMBuildBr(module->llvm.builder, entry_block);
|
LLVMBuildBr(module->llvm.builder, entry_block);
|
||||||
|
|
||||||
if (llvm_value_use_empty((LLVMValueRef)body_block))
|
if (!LLVMGetFirstUse((LLVMValueRef)body_block))
|
||||||
{
|
{
|
||||||
trap();
|
trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (llvm_value_use_empty((LLVMValueRef)exit_block))
|
if (!LLVMGetFirstUse((LLVMValueRef)exit_block))
|
||||||
{
|
{
|
||||||
trap();
|
trap();
|
||||||
}
|
}
|
||||||
@ -8621,8 +8617,10 @@ fn void analyze_statement(Module* module, Scope* scope, Statement* statement, u3
|
|||||||
LLVMValueRef indices[] = {
|
LLVMValueRef indices[] = {
|
||||||
body_index_load,
|
body_index_load,
|
||||||
};
|
};
|
||||||
|
auto gep_type = aggregate_type->structure.fields[0].type->pointer.element_type;
|
||||||
|
resolve_type_in_place(module, gep_type);
|
||||||
auto gep = create_gep(module, {
|
auto gep = create_gep(module, {
|
||||||
.type = aggregate_type->structure.fields[0].type->pointer.element_type->llvm.memory,
|
.type = gep_type->llvm.memory,
|
||||||
.pointer = extract_pointer,
|
.pointer = extract_pointer,
|
||||||
.indices = array_to_slice(indices),
|
.indices = array_to_slice(indices),
|
||||||
});
|
});
|
||||||
@ -9552,7 +9550,7 @@ void emit(Module* module)
|
|||||||
{
|
{
|
||||||
assert(!LLVMGetBasicBlockTerminator(current_basic_block));
|
assert(!LLVMGetBasicBlockTerminator(current_basic_block));
|
||||||
|
|
||||||
if (llvm_basic_block_is_empty(current_basic_block) || llvm_value_use_empty((LLVMValueRef)current_basic_block))
|
if (!LLVMGetFirstInstruction(current_basic_block) || !LLVMGetFirstUse((LLVMValueRef)current_basic_block))
|
||||||
{
|
{
|
||||||
LLVMReplaceAllUsesWith((LLVMValueRef)return_block, (LLVMValueRef)current_basic_block);
|
LLVMReplaceAllUsesWith((LLVMValueRef)return_block, (LLVMValueRef)current_basic_block);
|
||||||
LLVMDeleteBasicBlock(return_block);
|
LLVMDeleteBasicBlock(return_block);
|
||||||
@ -9633,7 +9631,7 @@ void emit(Module* module)
|
|||||||
auto alloca = LLVMGetOperand(store, 1);
|
auto alloca = LLVMGetOperand(store, 1);
|
||||||
assert(alloca == return_alloca);
|
assert(alloca == return_alloca);
|
||||||
LLVMInstructionEraseFromParent(store);
|
LLVMInstructionEraseFromParent(store);
|
||||||
assert(llvm_value_use_empty(alloca));
|
assert(!LLVMGetFirstUse(alloca));
|
||||||
LLVMInstructionEraseFromParent(alloca);
|
LLVMInstructionEraseFromParent(alloca);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
10
src/llvm.cpp
10
src/llvm.cpp
@ -169,16 +169,6 @@ EXPORT LLVMValueRef llvm_find_return_value_dominating_store(LLVMBuilderRef b, LL
|
|||||||
return wrap(store);
|
return wrap(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT bool llvm_value_use_empty(LLVMValueRef value)
|
|
||||||
{
|
|
||||||
return llvm::unwrap(value)->use_empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPORT bool llvm_basic_block_is_empty(LLVMBasicBlockRef basic_block)
|
|
||||||
{
|
|
||||||
return llvm::unwrap(basic_block)->empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPORT LLVMValueRef llvm_builder_create_alloca(LLVMBuilderRef b, LLVMTypeRef type, unsigned address_space, u32 alignment, String name)
|
EXPORT LLVMValueRef llvm_builder_create_alloca(LLVMBuilderRef b, LLVMTypeRef type, unsigned address_space, u32 alignment, String name)
|
||||||
{
|
{
|
||||||
auto& builder = *llvm::unwrap(b);
|
auto& builder = *llvm::unwrap(b);
|
||||||
|
@ -133,10 +133,8 @@ extern "C" LLVMBasicBlockRef llvm_context_create_basic_block(LLVMContextRef cont
|
|||||||
extern "C" LLVMValueRef llvm_module_create_global_variable(LLVMModuleRef module, LLVMTypeRef type, bool is_constant, LLVMLinkage linkage_type, LLVMValueRef initial_value, String name, LLVMValueRef before, LLVMThreadLocalMode thread_local_mode, unsigned address_space, bool externally_initialized);
|
extern "C" LLVMValueRef llvm_module_create_global_variable(LLVMModuleRef module, LLVMTypeRef type, bool is_constant, LLVMLinkage linkage_type, LLVMValueRef initial_value, String name, LLVMValueRef before, LLVMThreadLocalMode thread_local_mode, unsigned address_space, bool externally_initialized);
|
||||||
|
|
||||||
extern "C" LLVMValueRef llvm_builder_create_alloca(LLVMBuilderRef builder, LLVMTypeRef type, unsigned address_space, u32 alignment, String name);
|
extern "C" LLVMValueRef llvm_builder_create_alloca(LLVMBuilderRef builder, LLVMTypeRef type, unsigned address_space, u32 alignment, String name);
|
||||||
extern "C" bool llvm_basic_block_is_empty(LLVMBasicBlockRef basic_block);
|
|
||||||
|
|
||||||
extern "C" LLVMValueRef llvm_find_return_value_dominating_store(LLVMBuilderRef b, LLVMValueRef ra, LLVMTypeRef et);
|
extern "C" LLVMValueRef llvm_find_return_value_dominating_store(LLVMBuilderRef b, LLVMValueRef ra, LLVMTypeRef et);
|
||||||
extern "C" bool llvm_value_use_empty(LLVMValueRef value);
|
|
||||||
extern "C" bool llvm_function_verify(LLVMValueRef function_value, String* error_message);
|
extern "C" bool llvm_function_verify(LLVMValueRef function_value, String* error_message);
|
||||||
extern "C" bool llvm_module_verify(LLVMModuleRef m, String* error_message);
|
extern "C" bool llvm_module_verify(LLVMModuleRef m, String* error_message);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user