last commit for now
This commit is contained in:
parent
5e02ecd80d
commit
7a1a986e28
6 changed files with 122 additions and 22 deletions
94
makefile
Normal file
94
makefile
Normal file
|
@ -0,0 +1,94 @@
|
|||
# this is the build file for project
|
||||
# it is autogenerated by the xmake build system.
|
||||
# do not edit by hand.
|
||||
|
||||
ifneq ($(VERBOSE),1)
|
||||
VV=@
|
||||
endif
|
||||
|
||||
CXX=/usr/bin/gcc
|
||||
CU=/usr/bin/clang
|
||||
NC=/home/sam/Documents/Projects/Nim/bin/nim
|
||||
MXX=/usr/bin/gcc
|
||||
AS=/usr/bin/gcc
|
||||
CC=/usr/bin/gcc
|
||||
RC=/home/sam/.cargo/bin/rustc
|
||||
ZC=/snap/bin/zig
|
||||
GC=/usr/bin/go
|
||||
MM=/usr/bin/gcc
|
||||
|
||||
AR=/usr/bin/ar
|
||||
RCAR=/home/sam/.cargo/bin/rustc
|
||||
ZCAR=/snap/bin/zig
|
||||
NCAR=/home/sam/Documents/Projects/Nim/bin/nim
|
||||
GCAR=/usr/bin/go
|
||||
SH=/usr/bin/g++
|
||||
RCSH=/home/sam/.cargo/bin/rustc
|
||||
ZCSH=/snap/bin/zig
|
||||
NCSH=/home/sam/Documents/Projects/Nim/bin/nim
|
||||
LD=/usr/bin/g++
|
||||
RCLD=/home/sam/.cargo/bin/rustc
|
||||
ZCLD=/snap/bin/zig
|
||||
NCLD=/home/sam/Documents/Projects/Nim/bin/nim
|
||||
GCLD=/usr/bin/go
|
||||
|
||||
compiler-c_LD=/usr/bin/g++
|
||||
compiler-c_CC=/usr/bin/gcc
|
||||
|
||||
compiler-c_CCFLAGS=-g -O0 -isystem /home/sam/.xmake/packages/s/stc/v4.2/bfec6d3335d54b48969cc50946a9b5ac/include
|
||||
compiler-c_LDFLAGS=
|
||||
|
||||
default: compiler-c
|
||||
|
||||
all: compiler-c
|
||||
|
||||
.PHONY: default all compiler-c
|
||||
|
||||
compiler-c: build/linux/arm64/debug/compiler-c
|
||||
build/linux/arm64/debug/compiler-c: build/.objs/compiler-c/linux/arm64/debug/src/codegen.c.o build/.objs/compiler-c/linux/arm64/debug/src/helpers.c.o build/.objs/compiler-c/linux/arm64/debug/src/parser.c.o build/.objs/compiler-c/linux/arm64/debug/src/lexer.c.o build/.objs/compiler-c/linux/arm64/debug/src/compiler.c.o build/.objs/compiler-c/linux/arm64/debug/src/main.c.o
|
||||
@echo linking.debug compiler-c
|
||||
@mkdir -p build/linux/arm64/debug
|
||||
$(VV)$(compiler-c_LDFLAGS)$(compiler-c_LD) -o build/linux/arm64/debug/compiler-c build/.objs/compiler-c/linux/arm64/debug/src/codegen.c.o build/.objs/compiler-c/linux/arm64/debug/src/helpers.c.o build/.objs/compiler-c/linux/arm64/debug/src/parser.c.o build/.objs/compiler-c/linux/arm64/debug/src/lexer.c.o build/.objs/compiler-c/linux/arm64/debug/src/compiler.c.o build/.objs/compiler-c/linux/arm64/debug/src/main.c.o
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/codegen.c.o: src/codegen.c
|
||||
@echo compiling.debug src/codegen.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/codegen.c.o src/codegen.c
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/helpers.c.o: src/helpers.c
|
||||
@echo compiling.debug src/helpers.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/helpers.c.o src/helpers.c
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/parser.c.o: src/parser.c
|
||||
@echo compiling.debug src/parser.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/parser.c.o src/parser.c
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/lexer.c.o: src/lexer.c
|
||||
@echo compiling.debug src/lexer.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/lexer.c.o src/lexer.c
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/compiler.c.o: src/compiler.c
|
||||
@echo compiling.debug src/compiler.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/compiler.c.o src/compiler.c
|
||||
|
||||
build/.objs/compiler-c/linux/arm64/debug/src/main.c.o: src/main.c
|
||||
@echo compiling.debug src/main.c
|
||||
@mkdir -p build/.objs/compiler-c/linux/arm64/debug/src
|
||||
$(VV)$(compiler-c_CC) -c $(compiler-c_CCFLAGS) -o build/.objs/compiler-c/linux/arm64/debug/src/main.c.o src/main.c
|
||||
|
||||
clean: clean_compiler-c
|
||||
|
||||
clean_compiler-c:
|
||||
@rm -rf build/linux/arm64/debug/compiler-c
|
||||
@rm -rf build/linux/arm64/debug/compiler-c.sym
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/codegen.c.o
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/helpers.c.o
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/parser.c.o
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/lexer.c.o
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/compiler.c.o
|
||||
@rm -rf build/.objs/compiler-c/linux/arm64/debug/src/main.c.o
|
||||
|
|
@ -17,7 +17,7 @@ void codegen(Node node, bool emit_type) {
|
|||
codegen_arg_decl(node.arg_decl, emit_type);
|
||||
break;
|
||||
case NODE_REFERENCE:
|
||||
codegen_reference(node.reference, emit_type);
|
||||
codegen_reference(node.reference);
|
||||
break;
|
||||
case NODE_NUMBER:
|
||||
codegen_number(node.number, emit_type);
|
||||
|
@ -31,7 +31,7 @@ void codegen(Node node, bool emit_type) {
|
|||
}
|
||||
|
||||
void codegen_function_call(FunctionCall node) {
|
||||
printf("call $%s(", node.name);
|
||||
printf("%s(", node.name);
|
||||
// printf("FunctionCall(%s", node.function_call.name);
|
||||
/*if(Nodes_size(&node.function_call.args) > 0)
|
||||
printf(", ");*/
|
||||
|
@ -43,7 +43,7 @@ void codegen_function_call(FunctionCall node) {
|
|||
printf(", ");
|
||||
}
|
||||
}
|
||||
printf(")\n");
|
||||
printf(");\n");
|
||||
}
|
||||
|
||||
void codegen_function_decl(FunctionDecl node) {
|
||||
|
@ -60,7 +60,7 @@ void codegen_function_decl(FunctionDecl node) {
|
|||
}
|
||||
|
||||
void codegen_function_impl(FunctionImpl node) {
|
||||
printf("export function %s $%s(", node.type, node.name);
|
||||
printf("%s %s(", node.type, node.name);
|
||||
for(size_t i = 0; i < Nodes_size(&node.args); i++) {
|
||||
const Node* arg = Nodes_at(&node.args, i);
|
||||
codegen(*arg, true);
|
||||
|
@ -69,7 +69,7 @@ void codegen_function_impl(FunctionImpl node) {
|
|||
printf(", ");
|
||||
}
|
||||
}
|
||||
printf(") {\n@start\n\t");
|
||||
printf(") {\n\t");
|
||||
|
||||
for(size_t i = 0; i < Nodes_size(&node.body); i++) {
|
||||
const Node* n = Nodes_at(&node.body, i);
|
||||
|
@ -88,28 +88,25 @@ void codegen_arg_decl(ArgDecl node, bool emit_type) {
|
|||
if(emit_type) {
|
||||
printf("%s ", node.type);
|
||||
}
|
||||
printf("%%%s", node.name);
|
||||
printf("%s", node.name);
|
||||
}
|
||||
|
||||
void codegen_reference(Reference node, bool emit_type) {
|
||||
void codegen_reference(Reference node) {
|
||||
// printf("Reference(%s)", node.reference.name);
|
||||
if(emit_type) {
|
||||
printf("%s ", node.type);
|
||||
}
|
||||
printf("%%%s", node.name);
|
||||
printf("%s", node.name);
|
||||
}
|
||||
|
||||
void codegen_number(Number node, bool emit_type) {
|
||||
// printf("Number(%llu)", node.number.value);
|
||||
if(emit_type) {
|
||||
printf("w ");
|
||||
}
|
||||
printf("%d", node.value);
|
||||
}
|
||||
|
||||
void codegen_return(Return node) {
|
||||
printf("ret ");
|
||||
printf("return");
|
||||
|
||||
if(node.value != NULL) {
|
||||
printf(" ");
|
||||
codegen(*node.value, false);
|
||||
}
|
||||
printf(";");
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ void codegen_function_call(FunctionCall node);
|
|||
void codegen_function_decl(FunctionDecl node);
|
||||
void codegen_arg_decl(ArgDecl node, bool emit_type);
|
||||
void codegen_function_impl(FunctionImpl node);
|
||||
void codegen_reference(Reference node, bool emit_type);
|
||||
void codegen_reference(Reference node);
|
||||
void codegen_number(Number node, bool emit_type);
|
||||
void codegen_return(Return node);
|
||||
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -31,11 +31,11 @@ int main(int argc, char** argv) {
|
|||
.lexer = &lexer,
|
||||
.types = c_make(cmap_str,
|
||||
{
|
||||
{ "i8", "b" },
|
||||
{ "i16", "h" },
|
||||
{ "i32", "w" },
|
||||
{ "i64", "l" },
|
||||
{ "void", "" },
|
||||
{ "i8", "char" },
|
||||
{ "i16", "short" },
|
||||
{ "i32", "int" },
|
||||
{ "i64", "long long int" },
|
||||
{ "void", "void" },
|
||||
}),
|
||||
.symbols = { 0 },
|
||||
};
|
||||
|
|
7
test.c
Normal file
7
test.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
generic T;
|
||||
int add(T value) {
|
||||
printf("%v\n", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = add<char*>("bob");
|
4
test.ssa
4
test.ssa
|
@ -3,9 +3,11 @@ export function w $sayhi(w %char) {
|
|||
call $putchar(w 72)
|
||||
call $putchar(w 105)
|
||||
call $putchar(w %char)
|
||||
ret 5
|
||||
%tempval =w load 5
|
||||
ret %tempval
|
||||
}
|
||||
|
||||
|
||||
export function $main() {
|
||||
@start
|
||||
call $sayhi(w 74)
|
||||
|
|
Loading…
Add table
Reference in a new issue