Skip to content

Commit

Permalink
refactor: move files into src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
diohabara committed Aug 5, 2023
1 parent ff63908 commit 9387598
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tmp*

# for debug
.vscode/
t
tests
ext
test.s
Expand Down
56 changes: 29 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
CFLAGS=-std=c11 -g -static
SRCS=$(wildcard *.c)
SRCS=$(wildcard src/*.c)
OBJS=$(SRCS:.c=.o)

$(OBJS): ccc.h

help:
@echo "Usage: make [lint|test|debug|clean|process]"
@echo " lint: run c and shell checker"
@echo " test: run tests"
@echo " debug: run tests in debug mode"
@echo " clean: remove object files"
@echo " process: run the preprocessor on all source files for each stage"
$(OBJS): src/ccc.h

ccc: $(OBJS)
$(CC) -o $@ $(OBJS) $(CFLAGS)
@$(CC) -o $@ $(OBJS) $(CFLAGS)

lint:
clang-format -i ./*.c
clang-format -i ./*.h
clang-format -i src/*.c
clang-format -i src/*.h

test: ccc
./ccc test/test.c > tmp.s
Expand All @@ -26,9 +18,15 @@ test: ccc
./tmp

clean:
rm -f ccc *.o *~ tmp* stage*/*
rm -f ccc src/*.o *~ tmp* stage*/*

help:
@echo "Usage: make [lint|test|clean|self-host]"
@echo " lint: run c and shell checker"
@echo " test: run tests"
@echo " clean: remove object files"
@echo " self-host: check self-hosted compiler"

.PHONY: help lint test clean process

# stage0: gcc
# stage1: ccc on host machine generated by stage0 (gcc)
Expand All @@ -43,11 +41,12 @@ ccc-stage1: $(OBJS)
ccc-stage2: ccc-stage1 $(SRCS)
@rm -rf stage2
@mkdir stage2
$(CC) -D__ccc_self__ -E -P codegen.c -o stage2/codegen.c
$(CC) -D__ccc_self__ -E -P main.c -o stage2/main.c
$(CC) -D__ccc_self__ -E -P parse.c -o stage2/parse.c
$(CC) -D__ccc_self__ -E -P tokenize.c -o stage2/tokenize.c
$(CC) -D__ccc_self__ -E -P type.c -o stage2/type.c
@echo "`-D__ccc_self__` is to avoid `#include \"ccc.h\"`"
$(CC) -D__ccc_self__ -E -P src/codegen.c -o stage2/codegen.c
$(CC) -D__ccc_self__ -E -P src/main.c -o stage2/main.c
$(CC) -D__ccc_self__ -E -P src/parse.c -o stage2/parse.c
$(CC) -D__ccc_self__ -E -P src/tokenize.c -o stage2/tokenize.c
$(CC) -D__ccc_self__ -E -P src/type.c -o stage2/type.c
stage1/ccc-stage1 stage2/codegen.c > stage2/codegen.s
stage1/ccc-stage1 stage2/main.c > stage2/main.s
stage1/ccc-stage1 stage2/parse.c > stage2/parse.s
Expand All @@ -58,19 +57,22 @@ ccc-stage2: ccc-stage1 $(SRCS)
ccc-stage3: ccc-stage2 $(SRCS)
@rm -rf stage3
@mkdir stage3
$(CC) -D__ccc_self__ -E -P type.c -o stage3/type.c
$(CC) -D__ccc_self__ -E -P codegen.c -o stage3/codegen.c
$(CC) -D__ccc_self__ -E -P main.c -o stage3/main.c
$(CC) -D__ccc_self__ -E -P parse.c -o stage3/parse.c
$(CC) -D__ccc_self__ -E -P tokenize.c -o stage3/tokenize.c
@echo "`-D__ccc_self__` is to avoid `#include \"ccc.h\"`"
$(CC) -D__ccc_self__ -E -P src/type.c -o stage3/type.c
$(CC) -D__ccc_self__ -E -P src/codegen.c -o stage3/codegen.c
$(CC) -D__ccc_self__ -E -P src/main.c -o stage3/main.c
$(CC) -D__ccc_self__ -E -P src/parse.c -o stage3/parse.c
$(CC) -D__ccc_self__ -E -P src/tokenize.c -o stage3/tokenize.c
stage2/ccc-stage2 stage3/codegen.c > stage3/codegen.s
stage2/ccc-stage2 stage3/main.c > stage3/main.s
stage2/ccc-stage2 stage3/parse.c > stage3/parse.s
stage2/ccc-stage2 stage3/tokenize.c > stage3/tokenize.s
stage2/ccc-stage2 stage3/type.c > stage3/type.s
$(CC) -o stage3/$@

test-self-host: ccc-stage1 ccc-stage2 ccc-stage3
self-host: ccc-stage1 ccc-stage2 ccc-stage3
strip stage2/ccc-stage2
strip stage3/ccc-stage3
diff -s stage2/ccc-stage2 stage3/ccc-stage3
diff -s stage2/ccc-stage2 stage3/ccc-stage3

.PHONY: all help lint test clean self-host
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions parse.c → src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ void global_var() {
ty->is_extern = is_extern;

// // TODO: write tyepdef here
// if (ty->is_typedef) {
// expect(";");
// ty->is_typedef = false;
// push_scope(name)->type_def = ty;
// return;
// }
if (ty->is_typedef) {
expect(";");
ty->is_typedef = false;
push_scope(name)->type_def = ty;
return;
}

Var *var = push_var(name, ty, false, tok);
push_scope(name)->var = var;
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 9387598

Please sign in to comment.