Skip to content

Commit

Permalink
make amalgamated source file to improve inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
Holodome committed Oct 16, 2023
1 parent 449ca48 commit cb6c36c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
44 changes: 21 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
SRC_DIR = hololisp
OUT_DIR = build
TARGET = $(OUT_DIR)/hololisp
TARGET = build/hololisp
CFLAGS = -O2
LDFLAGS = -lm

$(shell mkdir -p $(OUT_DIR))
$(shell mkdir -p build)

ifneq (,$(COV))
COVERAGE_FLAGS = --coverage -fprofile-arcs -ftest-coverage
endif

LOCAL_CFLAGS = -std=c99 -I$(SRC_DIR) -pedantic -Wshadow -Wextra -Wall -Werror
LOCAL_CFLAGS = -std=c99 -Ihololisp -pedantic -Wshadow -Wextra -Wall -Werror

DEPFLAGS = -MT $@ -MMD -MP -MF $(OUT_DIR)/$*.d
DEPFLAGS = -MT $@ -MMD -MP -MF build/$*.d

ifneq (,$(ASAN))
CFLAGS += -fsanitize=address
Expand All @@ -29,34 +27,34 @@ else
CFLAGS += -DNDEBUG
endif

SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OUT_DIR)/%.o)
SRCS = hololisp/amalgamated.c
OBJS = $(SRCS:hololisp/%.c=build/%.o)

#
# Program rules
#

all: $(TARGET)

-include $(SRCS:$(SRC_DIR)/%.c=$(OUT_DIR)/%.d)
-include $(SRCS:hololisp/%.c=build/%.d)

$(TARGET): $(OBJS)
$(CC) $(COVERAGE_FLAGS) -o $@ $^ $(LDFLAGS)

$(OUT_DIR)/%.o: $(SRC_DIR)/%.c
build/%.o: hololisp/%.c
$(CC) $(LOCAL_CFLAGS) $(DEPFLAGS) $(CFLAGS) $(COVERAGE_FLAGS) -c -o $@ $<

clean:
rm -rf $(OUT_DIR)
rm -rf build

#
# Test rules
#

TEST_DIR = tests
UNIT_TEST_OUT_DIR = $(OUT_DIR)/$(TEST_DIR)
UNIT_TEST_PROJECT_SRCS = $(filter-out $(SRC_DIR)/main.c, $(SRCS))
UNIT_TEST_PROJECT_OBJS = $(UNIT_TEST_PROJECT_SRCS:$(SRC_DIR)/%.c=$(UNIT_TEST_OUT_DIR)/%.o)
UNIT_TEST_OUT_DIR = build/$(TEST_DIR)
UNIT_TEST_PROJECT_SRCS = $(filter-out hololisp/main.c, $(SRCS))
UNIT_TEST_PROJECT_OBJS = $(UNIT_TEST_PROJECT_SRCS:hololisp/%.c=$(UNIT_TEST_OUT_DIR)/%.o)
UNIT_TEST_SRCS = $(wildcard $(TEST_DIR)/*.c)
UNIT_TESTS = $(UNIT_TEST_SRCS:$(TEST_DIR)/%.c=$(UNIT_TEST_OUT_DIR)/%.test)

Expand All @@ -67,7 +65,7 @@ UNIT_TEST_DEPFLAGS = -MT $@ -MMD -MP -MF $(UNIT_TEST_OUT_DIR)/$*.d
$(UNIT_TEST_OUT_DIR)/%.test: $(UNIT_TEST_PROJECT_OBJS) $(UNIT_TEST_OUT_DIR)/%.o
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(COVERAGE_FLAGS) -g -O0 -o $@ $^ $(LDFLAGS)

$(UNIT_TEST_OUT_DIR)/%.o: $(SRC_DIR)/%.c
$(UNIT_TEST_OUT_DIR)/%.o: hololisp/%.c
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(UNIT_TEST_DEPFLAGS) $(COVERAGE_FLAGS) -g -O0 -c -o $@ $<

$(UNIT_TEST_OUT_DIR)/%.o: $(TEST_DIR)/%.c
Expand All @@ -76,28 +74,28 @@ $(UNIT_TEST_OUT_DIR)/%.o: $(TEST_DIR)/%.c
test tests: $(UNIT_TEST_OUT_DIR) $(UNIT_TESTS) all
./scripts/test.sh

$(UNIT_TEST_OUT_DIR): $(OUT_DIR)
$(UNIT_TEST_OUT_DIR): build
mkdir -p $(UNIT_TEST_OUT_DIR)

WASM_TARGET = $(OUT_DIR)/hololisp.wasm
WASM_SOURCES = $(filter-out $(SRC_DIR)/main.c, $(SRCS))
WASM_TARGET = build/hololisp.wasm
WASM_SOURCES = $(filter-out hololisp/main.c, $(SRCS))
WASM_FLAGS = -sSTRICT=1 -sALLOW_MEMORY_GROWTH=1 -sMALLOC=dlmalloc -sEXPORT_ES6=1
EMCC = emcc
EMRUN = emrun

wasm: $(OUT_DIR) $(WASM_TARGET)
wasm: build $(WASM_TARGET)

$(WASM_TARGET): $(WASM_SOURCES)
$(EMCC) -O2 --no-entry -sEXPORTED_RUNTIME_METHODS=ccall,cwrap $(WASM_FLAGS) -o $(OUT_DIR)/hololisp.js $^
$(EMCC) -O2 --no-entry -sEXPORTED_RUNTIME_METHODS=ccall,cwrap $(WASM_FLAGS) -o build/hololisp.js $^

wasm-test: $(SRCS)
$(EMCC) -O0 --preload-file examples --emrun $(WASM_FLAGS) -o $(OUT_DIR)/test.html $^
$(EMCC) -O0 --preload-file examples --emrun $(WASM_FLAGS) -o build/test.html $^
./scripts/replace_arguments_emcc.py
EXECUTABLE="emrun --browser firefox build/test.html --" ./tests/test_lisp.sh

FUZZ = $(OUT_DIR)/fuzz
FUZZ = build/fuzz

$(FUZZ): $(filter-out $(SRC_DIR)/main.c, $(SRCS)) tests/fuzz/fuzz.c
$(FUZZ): $(filter-out hololisp/main.c, $(SRCS)) tests/fuzz/fuzz.c
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -g -O0 -fsanitize=fuzzer,address $^ -o $@

fuzz: $(FUZZ)
Expand Down
4 changes: 2 additions & 2 deletions examples/mazegen.hl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
;;

(define VISITED 1)
(define WIDTH 40)
(define HEIGHT 40)
(define WIDTH 80)
(define HEIGHT 80)

(define (print-board board)
(when board
Expand Down
18 changes: 18 additions & 0 deletions hololisp/amalgamated.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "hll_builtins.c"
#include "hll_bytecode.c"
#include "hll_bytecode.h"
#include "hll_compiler.c"
#include "hll_compiler.h"
#include "hll_debug.c"
#include "hll_debug.h"
#include "hll_gc.c"
#include "hll_gc.h"
#include "hll_hololisp.h"
#include "hll_mem.c"
#include "hll_mem.h"
#include "hll_util.h"
#include "hll_value.c"
#include "hll_value.h"
#include "hll_vm.c"
#include "hll_vm.h"
#include "main.c"

0 comments on commit cb6c36c

Please sign in to comment.