From 58ab7191eecd6d1758356bafd40ff40b42daf3d0 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 9 Nov 2019 19:47:29 +0000 Subject: Add basics for interpreter; add CLI options The compiler now accepts options on the command-line, such as whether to interpret or compile, or what kind of output is desired. Instead of mallocing (and creating a memory leak), generated code now uses the Boehm garbage collector to allocate memory for boxes. I'm not entirely sure how the GC works, but it does seem to be working (tested by setting the environment variable GC_PRINT_STATS when running a compiled program that calculates a Fibonacci number). More testing relating to the GC should be created. The basics for an interpreted mode has been started, but getting it to work fully would be difficult: it would require figuring out how to dynamically link LLVM modules/object files into the LLVM execution engine, both for calling wrapper functions and for using the GC. Removed -Weverything because it was finding problems in the GC code despite it being included as a system library. The main function of an inter program has been renamed to inter_main. The GC requires GC_INIT is invoked at initialisation on some systems, so common.c now contains the real main function, which runs GC_INIT followed by inter_main. GC_INIT is a macro, so it cannot be called easily from LLVMIR. --- Makefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 52ea0f7..c4214a2 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,18 @@ CXX = clang++ YACC = bison LEX = flex -DEBUG = -ggdb3 -O0 +DEBUG = -ggdb3 -O0 -DGC_DEBUG RELEASE = -O3 -DNDEBUG -CFLAGS = --std=c99 -Weverything +CFLAGS = --std=c99 -Wpedantic -Wall -Wextra -Werror $(DEBUG) LFLAGS = -D_POSIX_C_SOURCE=200809L +LLVM_MODULES = core executionengine mcjit interpreter analysis native bitwriter + CFLAGS += $(shell llvm-config --cflags) CXXFLAGS += $(shell llvm-config --cppflags) LDFLAGS += $(shell llvm-config --ldflags) -LDLIBS += $(shell llvm-config --libs core analysis --system-libs) +LDLIBS += $(shell llvm-config --libs $(LLVM_MODULES) --system-libs) -lgc .PHONY: default all clean default: all @@ -51,8 +53,14 @@ simple: simple.o common.o %.o: %.ll clang -c $(OUTPUT_OPTION) $< +%.o: %.bc + clang -c $(OUTPUT_OPTION) $< + %.ll: %.int basic - < $< ./basic > $@ + ./basic -clo $@ $< + +%.bc: %.int basic + ./basic -cbo $@ $< %.ll: %.c clang -S -emit-llvm $(OUTPUT_OPTION) $< -- cgit v1.2.1