Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ lex.yy.c
bin/*

.vscode/*
.idea/*
cmake-build-debug/*
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.19)
project(summoner)

set(CMAKE_C_STANDARD 99)

add_subdirectory(compiler)
add_subdirectory(debug)
add_subdirectory(share)
add_subdirectory(builtin)
list(APPEND EXTRA_LIBS COMPILER DEBUG SHARE BUILTIN)

add_executable(summoner main/main.c)

target_link_libraries(summoner PUBLIC ${EXTRA_LIBS})
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output: main.o lex.o grammar.o create.o string.o compiler.o builtin.o fix_tree.o codegen.o opcode.o disassemble.o error.o debug.o wchar.o
all: main.o lex.o grammar.o create.o string.o compiler.o builtin.o fix_tree.o codegen.o opcode.o disassemble.o error.o debug.o wchar.o
$(CC) -o bin/main $^
main.o : main/main.c
$(CC) -c main/main.c
Expand All @@ -17,11 +17,11 @@ builtin.o : builtin/builtin.c
create.o : compiler/create.c
$(CC) -c $< -o create.o
grammar.o : compiler/grammar.y
yacc -d $<
$(CC) -c y.tab.c -o grammar.o
yacc -d -o compiler/y.tab.c $<
$(CC) -c compiler/y.tab.c -o grammar.o
lex.o : compiler/lex.l grammar.o
lex $<
$(CC) -c lex.yy.c -o lex.o
lex -o compiler/lex.yy.c $<
$(CC) -c compiler/lex.yy.c -o lex.o
string.o : compiler/string.c
$(CC) -c $< -o string.o
wchar.o: share/wchar.c
Expand All @@ -32,7 +32,7 @@ debug.o: debug/debug.c
$(CC) -c $< -o debug.o

clean:
rm -f y.tab.*
rm -f lex.yy.c
rm -f compiler/y.tab.*
rm -f compiler/lex.yy.c
rm -f *.o
rm -f bin/main
2 changes: 2 additions & 0 deletions builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(BUILTIN builtin.c)
target_include_directories(BUILTIN INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
10 changes: 10 additions & 0 deletions compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lex.yy.c
COMMAND lex -o ${CMAKE_CURRENT_SOURCE_DIR}/lex.yy.c ${CMAKE_CURRENT_SOURCE_DIR}/lex.l
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/y.tab.c
COMMAND yacc -d -o ${CMAKE_CURRENT_SOURCE_DIR}/y.tab.c ${CMAKE_CURRENT_SOURCE_DIR}/grammar.y
)
add_library(COMPILER lex.yy.c y.tab.c codegen.c disassemble.c create.c error.c fix_tree.c opcode.c string.c compiler.c)
target_include_directories(COMPILER INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
2 changes: 1 addition & 1 deletion compiler/grammar.y
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
#include <stdio.h>
#include <stdlib.h>
#include "compiler/summoner.h"
#include "summoner.h"

int yylex();
int yyerror(const char *s);
Expand Down
2 changes: 1 addition & 1 deletion compiler/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
#include "compiler/summoner.h"
#include "summoner.h"

void lex_err(char *str) {
fprintf(stderr, "lexical error:%s\n", str);
Expand Down
2 changes: 2 additions & 0 deletions debug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(DEBUG debug.c)
target_include_directories(DEBUG INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
2 changes: 2 additions & 0 deletions share/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(SHARE wchar.c)
target_include_directories(SHARE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})