Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 1eeb6af

Browse files
committed
wip
1 parent d79589c commit 1eeb6af

File tree

10 files changed

+53
-30
lines changed

10 files changed

+53
-30
lines changed

.makim.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 1.0.0
22
env:
33
CFLAGS_EXTRA: "\
4-
-fsanitize\
4+
-fsanitize=address\
55
"
66
# use it for ASAN and LSAN
77
SAN_OPTIONS_DEFAULT: "\
@@ -19,8 +19,9 @@ env:
1919
:print_legend=1\
2020
:detect_leaks=1\
2121
"
22-
MESON_EXTRA: "-Db_coverage=true \
23-
-Doptimization=0 \
22+
MESON_EXTRA_DEBUG: "-Db_coverage=true \
23+
--optimization=0 \
24+
--debug \
2425
-Db_sanitize=address \
2526
"
2627
groups:
@@ -104,7 +105,7 @@ groups:
104105
- target: build.release
105106
args:
106107
build-type: "debug"
107-
meson-extra: {{ env.MESON_EXTRA }}
108+
meson-extra: {{ env.MESON_EXTRA_DEBUG }}
108109
clean: {{ args.clean }}
109110
asan-options: {{ env.SAN_OPTIONS_DEFAULT }}
110111
lsan-options: {{ env.SAN_OPTIONS_DEFAULT }}
@@ -120,7 +121,7 @@ groups:
120121
- target: build.release
121122
args:
122123
build-type: "debug"
123-
meson-extra: {{ env.MESON_EXTRA }} -Ddev=enabled
124+
meson-extra: {{ env.MESON_EXTRA_DEBUG }} -Ddev=enabled
124125
clean: {{ args.clean }}
125126
asan-options: {{ env.SAN_OPTIONS_DEFAULT }}
126127
lsan-options: {{ env.SAN_OPTIONS_DEFAULT }}
@@ -231,7 +232,7 @@ groups:
231232
232233
if [[ "{{ args.debug }}" == "True" ]]; then
233234
GDB="gdb --args"
234-
DEBUG_FLAGS="-g"
235+
DEBUG_FLAGS="-Og"
235236
fi
236237
237238
TEST_DIR_PATH="./tests"
@@ -261,7 +262,7 @@ groups:
261262
print_header "${test_name}"
262263
OBJECT_FILE="${TMP_DIR}/${test_name}.o"
263264
264-
${ARX} --output "${OBJECT_FILE}" --input "examples/${test_name}.arx"
265+
${ARX} --output "${OBJECT_FILE}" --input "examples/${test_name}.arx --build-lib"
265266
266267
set -x
267268
clang++ \
@@ -381,4 +382,5 @@ groups:
381382
gdb \
382383
--args build/arx \
383384
--input `pwd`/examples/{{ args.test_name }}.arx \
385+
--build-lib \
384386
--output "/tmp/{{ args.test_name }}" {{ args.meson_extra }}

src/codegen/arx-llvm.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ llvm::Type* ArxLLVM::VOID_TYPE;
2828
auto ArxLLVM::get_data_type(std::string type_name) -> llvm::Type* {
2929
if (type_name == "float") {
3030
return ArxLLVM::FLOAT_TYPE;
31-
} else if (type_name == "void") {
32-
return ArxLLVM::VOID_TYPE;
31+
} else if (type_name == "double") {
32+
return ArxLLVM::DOUBLE_TYPE;
33+
} else if (type_name == "int8") {
34+
return ArxLLVM::INT8_TYPE;
35+
} else if (type_name == "int32") {
36+
return ArxLLVM::INT32_TYPE;
3337
} else if (type_name == "char") {
3438
return ArxLLVM::INT8_TYPE;
39+
} else if (type_name == "void") {
40+
return ArxLLVM::VOID_TYPE;
3541
}
42+
43+
llvm::errs() << "[EE] type_name not valid.\n";
3644
return nullptr;
3745
}
3846

src/codegen/ast-to-llvm-ir.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ extern std::string ARX_VERSION;
4545
auto ASTToLLVMIRVisitor::CreateFunctionType(unsigned NumArgs)
4646
-> llvm::DISubroutineType* {
4747
llvm::SmallVector<llvm::Metadata*, 8> EltTys;
48-
llvm::DIType* DblTy = this->getDoubleTy();
48+
llvm::DIType* di_double_type = this->getDoubleTy();
4949

5050
// Add the result type.
51-
EltTys.emplace_back(DblTy);
51+
EltTys.emplace_back(di_double_type);
5252

5353
for (unsigned i = 0, e = NumArgs; i != e; ++i) {
54-
EltTys.emplace_back(DblTy);
54+
EltTys.emplace_back(di_double_type);
5555
}
5656

5757
return ArxLLVM::di_builder->createSubroutineType(
@@ -61,13 +61,23 @@ auto ASTToLLVMIRVisitor::CreateFunctionType(unsigned NumArgs)
6161
// DebugInfo
6262

6363
auto ASTToLLVMIRVisitor::getDoubleTy() -> llvm::DIType* {
64-
if (this->DblTy) {
65-
return this->DblTy;
64+
if (this->DI_DOUBLE_TYPE) {
65+
return this->DI_DOUBLE_TYPE;
6666
}
6767

68-
DblTy = ArxLLVM::di_builder->createBasicType(
68+
this->DI_DOUBLE_TYPE = ArxLLVM::di_builder->createBasicType(
6969
"double", 64, llvm::dwarf::DW_ATE_float);
70-
return DblTy;
70+
return this->DI_DOUBLE_TYPE;
71+
}
72+
73+
auto ASTToLLVMIRVisitor::getFloatTy() -> llvm::DIType* {
74+
if (this->DI_FLOAT_TYPE) {
75+
return this->DI_FLOAT_TYPE;
76+
}
77+
78+
this->DI_FLOAT_TYPE = ArxLLVM::di_builder->createBasicType(
79+
"float", 32, llvm::dwarf::DW_ATE_float);
80+
return this->DI_FLOAT_TYPE;
7181
}
7282

7383
auto ASTToLLVMIRVisitor::emitLocation(ExprAST& ast) -> void {

src/codegen/ast-to-llvm-ir.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class ASTToLLVMIRVisitor : public ASTToObjectVisitor {
3838
public:
3939
// DebugInfo
4040
llvm::DICompileUnit* TheCU;
41-
llvm::DIType* DblTy;
41+
llvm::DIType* DI_DOUBLE_TYPE;
42+
llvm::DIType* DI_FLOAT_TYPE;
4243
std::vector<llvm::DIScope*> LexicalBlocks;
4344

4445
llvm::ExitOnError ExitOnErr;
@@ -61,5 +62,6 @@ class ASTToLLVMIRVisitor : public ASTToObjectVisitor {
6162

6263
// DebugInfo
6364
void emitLocation(ExprAST& AST);
65+
llvm::DIType* getFloatTy();
6466
llvm::DIType* getDoubleTy();
6567
};

src/codegen/ast-to-object.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ auto ASTToObjectVisitor::getFunction(std::string name) -> void {
100100
*/
101101
auto ASTToObjectVisitor::CreateEntryBlockAlloca(
102102
llvm::Function* fn, llvm::StringRef var_name) -> llvm::AllocaInst* {
103-
llvm::IRBuilder<> tmp_builder(&fn->getEntryBlock(), fn->getEntryBlock().begin());
103+
llvm::IRBuilder<> tmp_builder(
104+
&fn->getEntryBlock(), fn->getEntryBlock().begin());
104105
return tmp_builder.CreateAlloca(ArxLLVM::FLOAT_TYPE, nullptr, var_name);
105106
}
106107

@@ -421,7 +422,7 @@ auto ASTToObjectVisitor::visit(ForExprAST& expr) -> void {
421422
// Reload, increment, and restore the alloca. This handles the case
422423
// where the body of the loop mutates the variable.
423424
llvm::Value* CurVar = ArxLLVM::ir_builder->CreateLoad(
424-
ArxLLVM::DOUBLE_TYPE, alloca, expr.var_name.c_str());
425+
ArxLLVM::FLOAT_TYPE, alloca, expr.var_name.c_str());
425426
llvm::Value* NextVar =
426427
ArxLLVM::ir_builder->CreateFAdd(CurVar, StepVal, "nextvar");
427428
ArxLLVM::ir_builder->CreateStore(NextVar, alloca);
@@ -525,7 +526,7 @@ auto ASTToObjectVisitor::visit(PrototypeAST& expr) -> void {
525526
for (auto& arg : expr.args) {
526527
arg_type = ArxLLVM::get_data_type(arg->type_name);
527528
if (arg_type != nullptr) {
528-
args.push_back(arg_type);
529+
args.emplace_back(arg_type);
529530
} else {
530531
llvm::errs() << "ARX::GEN-OBJECT[ERROR]: PrototypeAST: "
531532
<< "Argument data type " << arg->type_name

tests/integration/average.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <iostream>
22

33
extern "C" {
4-
double average(double, double);
4+
float average(float, float);
55
}
66

77
int main() {
8-
double avg_3_4 = average(3.0, 4.0);
8+
float avg_3_4 = average(3.0, 4.0);
99
std::cout << "average of 3.0 and 4.0: " << avg_3_4 << std::endl;
1010
}

tests/integration/constant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <iostream>
22

33
extern "C" {
4-
double get_constant(double);
4+
float get_constant(float);
55
}
66

77
int main() {
8-
double value = get_constant(3.0);
8+
float value = get_constant(3.0);
99
printf("get_constant(3.0): %f\n", value);
1010

1111
return 0;

tests/integration/fibonacci.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include <iostream>
33

44
extern "C" {
5-
double fib(double);
5+
float fib(float);
66
}
77

88
int main() {
9-
double fib_10 = fib(10.);
9+
float fib_10 = fib(10.);
1010
std::cout << "fib(40.): " << fib_10 << std::endl;
1111
}

tests/integration/print-star.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include <iostream>
33

44
extern "C" {
5-
double print_star(double);
5+
float print_star(float);
66
}
77

8-
extern "C" auto putchard(double X) -> double {
8+
extern "C" auto putchard(float X) -> float {
99
fputc(static_cast<char>(X), stderr);
1010
return 0;
1111
}

tests/integration/sum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include <iostream>
33

44
extern "C" {
5-
double sum(double, double);
5+
float sum(float, float);
66
}
77

88
int main() {
9-
double sum_3_4 = sum(3.0, 4.0);
9+
float sum_3_4 = sum(3.0, 4.0);
1010
std::cout << "sum of 3.0 and 4.0: " << sum_3_4 << std::endl;
1111
}

0 commit comments

Comments
 (0)