fixed test not passing
This commit is contained in:
parent
54c7103df1
commit
1c476cd561
|
@ -6,8 +6,8 @@
|
||||||
#include <llvm/types.h>
|
#include <llvm/types.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
|
|
||||||
BackendError impl_bitwise_operation(LLVMBackendCompileUnit *unit,
|
BackendError impl_bitwise_operation([[maybe_unused]] LLVMBackendCompileUnit *unit,
|
||||||
LLVMLocalScope *scope,
|
[[maybe_unused]] LLVMLocalScope *scope,
|
||||||
LLVMBuilderRef builder,
|
LLVMBuilderRef builder,
|
||||||
Operation *operation,
|
Operation *operation,
|
||||||
LLVMValueRef *llvm_result) {
|
LLVMValueRef *llvm_result) {
|
||||||
|
@ -57,8 +57,8 @@ static LLVMValueRef convert_integral_to_boolean(
|
||||||
return LLVMBuildICmp(builder, LLVMIntNE, zero, integral, "to boolean");
|
return LLVMBuildICmp(builder, LLVMIntNE, zero, integral, "to boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendError impl_logical_operation(LLVMBackendCompileUnit *unit,
|
BackendError impl_logical_operation([[maybe_unused]] LLVMBackendCompileUnit *unit,
|
||||||
LLVMLocalScope *scope,
|
[[maybe_unused]] LLVMLocalScope *scope,
|
||||||
LLVMBuilderRef builder,
|
LLVMBuilderRef builder,
|
||||||
Operation *operation,
|
Operation *operation,
|
||||||
LLVMValueRef *llvm_result) {
|
LLVMValueRef *llvm_result) {
|
||||||
|
@ -66,7 +66,7 @@ BackendError impl_logical_operation(LLVMBackendCompileUnit *unit,
|
||||||
LLVMValueRef rhs = NULL;
|
LLVMValueRef rhs = NULL;
|
||||||
LLVMValueRef lhs = NULL;
|
LLVMValueRef lhs = NULL;
|
||||||
|
|
||||||
if (operation->kind == LogicalNot) {
|
if (operation->impl.logical == LogicalNot) {
|
||||||
// single operand
|
// single operand
|
||||||
rhs = convert_integral_to_boolean(builder, rhs);
|
rhs = convert_integral_to_boolean(builder, rhs);
|
||||||
} else {
|
} else {
|
||||||
|
@ -75,7 +75,7 @@ BackendError impl_logical_operation(LLVMBackendCompileUnit *unit,
|
||||||
rhs = convert_integral_to_boolean(builder, rhs);
|
rhs = convert_integral_to_boolean(builder, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (operation->impl.bitwise) {
|
switch (operation->impl.logical) {
|
||||||
case LogicalAnd:
|
case LogicalAnd:
|
||||||
*llvm_result = LLVMBuildAnd(builder, lhs, rhs, "logical and");
|
*llvm_result = LLVMBuildAnd(builder, lhs, rhs, "logical and");
|
||||||
break;
|
break;
|
||||||
|
@ -108,8 +108,8 @@ static LLVMBool is_integral(LLVMValueRef value) {
|
||||||
return typeKind == LLVMIntegerTypeKind;
|
return typeKind == LLVMIntegerTypeKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendError impl_relational_operation(LLVMBackendCompileUnit *unit,
|
BackendError impl_relational_operation([[maybe_unused]] LLVMBackendCompileUnit *unit,
|
||||||
LLVMLocalScope *scope,
|
[[maybe_unused]] LLVMLocalScope *scope,
|
||||||
LLVMBuilderRef builder,
|
LLVMBuilderRef builder,
|
||||||
Operation *operation,
|
Operation *operation,
|
||||||
LLVMValueRef *llvm_result) {
|
LLVMValueRef *llvm_result) {
|
||||||
|
@ -158,8 +158,8 @@ BackendError impl_relational_operation(LLVMBackendCompileUnit *unit,
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendError impl_arithmetic_operation(LLVMBackendCompileUnit *unit,
|
BackendError impl_arithmetic_operation([[maybe_unused]] LLVMBackendCompileUnit *unit,
|
||||||
LLVMLocalScope *scope,
|
[[maybe_unused]] LLVMLocalScope *scope,
|
||||||
LLVMBuilderRef builder,
|
LLVMBuilderRef builder,
|
||||||
Operation *operation,
|
Operation *operation,
|
||||||
LLVMValueRef *llvm_result) {
|
LLVMValueRef *llvm_result) {
|
||||||
|
@ -169,7 +169,6 @@ BackendError impl_arithmetic_operation(LLVMBackendCompileUnit *unit,
|
||||||
|
|
||||||
if ((is_integral(lhs) && is_integral(rhs)) == 1) {
|
if ((is_integral(lhs) && is_integral(rhs)) == 1) {
|
||||||
// integral type
|
// integral type
|
||||||
LLVMIntPredicate operator = 0;
|
|
||||||
|
|
||||||
switch (operation->impl.arithmetic) {
|
switch (operation->impl.arithmetic) {
|
||||||
case Add:
|
case Add:
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <llvm/expr.h>
|
#include <llvm/expr.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
|
|
||||||
BackendError impl_assign_stmt(LLVMBackendCompileUnit *unit,
|
BackendError impl_assign_stmt([[maybe_unused]] LLVMBackendCompileUnit *unit,
|
||||||
const LLVMBuilderRef builder, const LLVMLocalScope *scope,
|
const LLVMBuilderRef builder, const LLVMLocalScope *scope,
|
||||||
const Assignment *assignment) {
|
const Assignment *assignment) {
|
||||||
BackendError err = SUCCESS;
|
BackendError err = SUCCESS;
|
||||||
|
@ -45,6 +45,7 @@ BackendError impl_basic_block(LLVMBackendCompileUnit *unit,
|
||||||
LLVMPositionBuilderAtEnd(builder, *llvm_block);
|
LLVMPositionBuilderAtEnd(builder, *llvm_block);
|
||||||
|
|
||||||
for (size_t i = 0; i < block->statemnts->len; i++) {
|
for (size_t i = 0; i < block->statemnts->len; i++) {
|
||||||
|
[[maybe_unused]]
|
||||||
Statement *stmt = ((Statement *) block->statemnts->data) + i;
|
Statement *stmt = ((Statement *) block->statemnts->data) + i;
|
||||||
|
|
||||||
// TODO: implement statement
|
// TODO: implement statement
|
||||||
|
@ -66,7 +67,7 @@ BackendError impl_while(LLVMBackendCompileUnit *unit,
|
||||||
LLVMPositionBuilderAtEnd(builder, while_cond_block);
|
LLVMPositionBuilderAtEnd(builder, while_cond_block);
|
||||||
// Resolve condition in block to a variable
|
// Resolve condition in block to a variable
|
||||||
LLVMValueRef cond_result = NULL;
|
LLVMValueRef cond_result = NULL;
|
||||||
impl_expr(unit, scope, builder, &while_stmt->conditon, &cond_result);
|
impl_expr(unit, scope, builder, (Expression*) &while_stmt->conditon, &cond_result);
|
||||||
|
|
||||||
// build body of loop
|
// build body of loop
|
||||||
LLVMBasicBlockRef while_body_block = NULL;
|
LLVMBasicBlockRef while_body_block = NULL;
|
||||||
|
@ -103,6 +104,7 @@ BackendError impl_func_call(LLVMBackendCompileUnit *unit,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
Paramer* parameter = (Paramer*) call->function->parameter->data + i;
|
Paramer* parameter = (Paramer*) call->function->parameter->data + i;
|
||||||
// TODO: create a pointer to LLVMValueRef in case parameter is `out`
|
// TODO: create a pointer to LLVMValueRef in case parameter is `out`
|
||||||
|
|
||||||
|
@ -123,7 +125,7 @@ BackendError impl_func_call(LLVMBackendCompileUnit *unit,
|
||||||
|
|
||||||
BackendError
|
BackendError
|
||||||
impl_cond_block(LLVMBackendCompileUnit *unit, LLVMBuilderRef builder, LLVMLocalScope *scope, Expression *cond,
|
impl_cond_block(LLVMBackendCompileUnit *unit, LLVMBuilderRef builder, LLVMLocalScope *scope, Expression *cond,
|
||||||
Block *block, LLVMBasicBlockRef *cond_block, LLVMBasicBlockRef *body_block,
|
const Block *block, LLVMBasicBlockRef *cond_block, LLVMBasicBlockRef *body_block,
|
||||||
LLVMValueRef *llvm_cond) {
|
LLVMValueRef *llvm_cond) {
|
||||||
BackendError err;
|
BackendError err;
|
||||||
|
|
||||||
|
@ -155,7 +157,7 @@ BackendError impl_branch(LLVMBackendCompileUnit *unit,
|
||||||
LLVMBasicBlockRef body_block = NULL;
|
LLVMBasicBlockRef body_block = NULL;
|
||||||
LLVMValueRef cond_value = NULL;
|
LLVMValueRef cond_value = NULL;
|
||||||
|
|
||||||
err = impl_cond_block(unit, builder, scope, &branch->ifBranch.conditon, &branch->ifBranch.block, &cond_block,
|
err = impl_cond_block(unit, builder, scope, (Expression*) &branch->ifBranch.conditon, &branch->ifBranch.block, &cond_block,
|
||||||
&body_block, &cond_value);
|
&body_block, &cond_value);
|
||||||
|
|
||||||
g_array_append_val(cond_blocks, cond_block);
|
g_array_append_val(cond_blocks, cond_block);
|
||||||
|
@ -215,4 +217,7 @@ BackendError impl_branch(LLVMBackendCompileUnit *unit,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendError impl_stmt(LLVMBackendCompileUnit *unit, Statement *stmt) {}
|
BackendError impl_stmt([[maybe_unused]] LLVMBackendCompileUnit *unit, [[maybe_unused]] Statement *stmt) {
|
||||||
|
// TODO: implement
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@ include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
link_libraries(PkgConfig::GLIB)
|
link_libraries(PkgConfig::GLIB)
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/dep/tomlc99)
|
||||||
|
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
# LLVM backend #
|
# LLVM backend #
|
||||||
|
@ -30,15 +32,13 @@ include_directories(${LLVM_INCLUDE_DIR})
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.c)
|
file(GLOB_RECURSE SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.c)
|
||||||
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/main.c)
|
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/main.c)
|
||||||
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c)
|
|
||||||
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/lex/lexer.ll.c)
|
|
||||||
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/lex/util.c)
|
|
||||||
add_executable(global_vars
|
add_executable(global_vars
|
||||||
global_vars.c ${SOURCE_FILES})
|
global_vars.c ${SOURCE_FILES})
|
||||||
set_target_properties(global_vars
|
set_target_properties(global_vars
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "global_vars"
|
OUTPUT_NAME "global_vars"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/llvm)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/llvm)
|
||||||
|
target_link_libraries(global_vars tomlc99)
|
||||||
add_test(NAME global_vars
|
add_test(NAME global_vars
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/llvm
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/llvm
|
||||||
COMMAND ${GEMSTONE_BINARY_DIR}/tests/llvm/global_vars)
|
COMMAND ${GEMSTONE_BINARY_DIR}/tests/llvm/global_vars)
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <set/types.h>
|
#include <set/types.h>
|
||||||
|
|
||||||
// NOTE: unused
|
|
||||||
AST_NODE_PTR root;
|
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
[[clang::always_inline]]
|
[[clang::always_inline]]
|
||||||
inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type type) {
|
inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type type) {
|
||||||
|
@ -85,7 +82,8 @@ inline Module* create_module() {
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char* argv[]) {
|
||||||
|
parse_options(argc, argv);
|
||||||
log_init();
|
log_init();
|
||||||
|
|
||||||
// no need to clean up ;-)
|
// no need to clean up ;-)
|
||||||
|
@ -99,11 +97,15 @@ int main() {
|
||||||
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = generate_code(module, NULL);
|
TargetConfig* config = default_target_config();
|
||||||
|
|
||||||
|
err = generate_code(module, config);
|
||||||
if (err.kind != Success) {
|
if (err.kind != Success) {
|
||||||
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_target_config(config);
|
||||||
|
|
||||||
err = deinit_backend();
|
err = deinit_backend();
|
||||||
if (err.kind != Success) {
|
if (err.kind != Success) {
|
||||||
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
PANIC("%ld: at [%p] %s", err.kind, err.impl.ast_node, err.impl.message);
|
||||||
|
|
Loading…
Reference in New Issue