From cb6c36ce007327a1d8a592534ed3bef81caff99f Mon Sep 17 00:00:00 2001 From: Holodome Date: Mon, 16 Oct 2023 23:49:57 +0300 Subject: [PATCH] make amalgamated source file to improve inlining --- Makefile | 44 ++++++++++++++++++++---------------------- examples/mazegen.hl | 4 ++-- hololisp/amalgamated.c | 18 +++++++++++++++++ 3 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 hololisp/amalgamated.c diff --git a/Makefile b/Makefile index fb74fb7..e0eaea0 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -29,8 +27,8 @@ 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 @@ -38,25 +36,25 @@ OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OUT_DIR)/%.o) 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) @@ -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 @@ -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) diff --git a/examples/mazegen.hl b/examples/mazegen.hl index 26a6aa2..a52a0de 100644 --- a/examples/mazegen.hl +++ b/examples/mazegen.hl @@ -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 diff --git a/hololisp/amalgamated.c b/hololisp/amalgamated.c new file mode 100644 index 0000000..158e2a0 --- /dev/null +++ b/hololisp/amalgamated.c @@ -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"