summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-23 18:19:32 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-23 18:19:32 +0200
commit6f71f22d665d7d629fd34f8ec3ba21ef84dda31a (patch)
tree4cd5a42567e78030ae6f0e31de1dc7be4ff87ede
parentad05662ae05336aa5db20f9d34d5c1d5bba9d6c2 (diff)
Factor the LLVM compiler out into its own library.
-rw-r--r--GNUmakefile71
-rw-r--r--MLKLLVMCompiler.mm5
-rw-r--r--MLKLexicalContext-MLKLLVMCompilation.h2
-rw-r--r--MLKLexicalContext-MLKLLVMCompilation.mm2
-rw-r--r--MLKReadEvalPrintLoop.m11
5 files changed, 78 insertions, 13 deletions
diff --git a/GNUmakefile b/GNUmakefile
index fdaf049..f1937b0 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,3 +1,5 @@
+## -*- mode: makefile-gmake; coding: utf-8 -*-
+##
## Toilet Lisp, a Common Lisp subset for the Étoilé runtime.
## Copyright (C) 2008 Matthias Andreas Benkard.
##
@@ -15,7 +17,16 @@
## along with this program. If not, see <http://www.gnu.org/licenses/>.
-default: ToiletKit toilet
+export USE_LLVM ADDITIONAL_OBJCFLAGS ADDITIONAL_LDFLAGS LLVM_CONFIG
+
+KIT_TARGETS = ToiletKit
+
+USE_LLVM := YES
+ifeq ($(USE_LLVM),YES)
+KIT_TARGETS += libtoilet-llvm
+endif
+
+default: $(KIT_TARGETS) toilet
include $(GNUSTEP_MAKEFILES)/common.make
@@ -24,6 +35,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = etshell toilet
FRAMEWORK_NAME = ToiletKit
BUNDLE_NAME = Test
+LIBRARY_NAME =
ADDITIONAL_OBJCFLAGS += $(CUSTOM_OBJCFLAGS)
ADDITIONAL_LDFLAGS += $(CUSTOM_LDFLAGS)
@@ -70,17 +82,39 @@ ToiletKit_OBJCFLAGS = -Wall
ToiletKit_LDFLAGS = -lgmp -lffi -ldl
#LIBRARIES_DEPEND_UPON
-USE_LLVM := YES
+
ifeq ($(USE_LLVM),YES)
+ADDITIONAL_OBJCFLAGS += -DUSE_LLVM
LLVM_CONFIG = llvm-config
+LLVM_LDFLAGS = `$(LLVM_CONFIG) --ldflags` `$(LLVM_CONFIG) --libs backend engine linker codegen transformutils scalaropts analysis ipo`
+endif
+
+ifeq ($(BUILD_TOILET_LLVM),YES)
+ifeq ($(USE_LLVM),YES)
+static = yes # This line is the reason for this whole “BUILD_TOILET_LLVM”
+ # recursive-make-gone-awry crap. Hooray for not being able
+ # to build static libraries without bending over backwards!
+ # Thanks a bunch, GNUstep-Make!
+
+LIBRARY_NAME += libtoilet-llvm
+
ADDITIONAL_OBJCCFLAGS = $(ADDITIONAL_OBJCFLAGS)
-ToiletKit_OBJC_FILES += MLKLexicalContext-MLKLLVMCompilation.m
-ToiletKit_OBJCC_FILES = MLKLLVMCompiler.mm
-ToiletKit_OBJCFLAGS = -DUSE_LLVM
-ToiletKit_OBJCCFLAGS = -DUSE_LLVM `$(LLVM_CONFIG) --cxxflags` $(ToiletKit_OBJCFLAGS)
-ToiletKit_LDFLAGS += `$(LLVM_CONFIG) --ldflags` `$(LLVM_CONFIG) --libs backend engine linker codegen transformutils scalaropts analysis ipo`
+libtoilet-llvm_OBJC_FILES += MLKLexicalContext-MLKLLVMCompilation.m
+libtoilet-llvm_OBJCC_FILES = MLKLLVMCompiler.mm
+libtoilet-llvm_OBJCFLAGS = -DUSE_LLVM
+libtoilet-llvm_OBJCCFLAGS = -DUSE_LLVM `$(LLVM_CONFIG) --cxxflags` $(ToiletKit_OBJCFLAGS)
+libtoilet-llvm_LDFLAGS += $(LLVM_LDFLAGS)
+endif
+else #!BUILD_TOILET_LLVM
+libtoilet-llvm:
+ $(MAKE) $@ shared=no BUILD_TOILET_LLVM=YES
endif
+-include GNUmakefile.preamble
+include $(GNUSTEP_MAKEFILES)/library.make
+-include GNUmakefile.postamble
+
+
#TOOL_NAME = etoilet
#etoilet_OBJC_FILES = main.m
#etoilet_OBJC_LIBS = -lToiletKit -LToiletKit.framework
@@ -94,22 +128,28 @@ etshell_OBJC_LIBS += -lStepTalk -lreadline -lncurses -lToiletKit \
etshell_OBJCFLAGS = -w
toilet_OBJC_FILES = MLKReadEvalPrintLoop.m
-toilet_OBJC_LIBS += -ledit -lncurses -lToiletKit -LToiletKit.framework \
- -LToiletKit.framework/Versions/Current `llvm-config --ldflags` `llvm-config --libs scalaropts analysis ipo`
+toilet_OBJC_LIBS += -ledit -lncurses -LToiletKit.framework \
+ -LToiletKit.framework/Versions/Current -lToiletKit
+
toilet_OBJCFLAGS = -Wall
+ifeq ($(USE_LLVM),YES)
+toilet_OBJC_LIBS += -Lobj -ltoilet-llvm $(LLVM_LDFLAGS) -lstdc++
+endif
+
Test_OBJC_FILES = MLKLowLevelTests.m
Test_OBJC_LIBS = -lUnitKit -LToiletKit.framework -lToiletKit
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/bundle.make
include $(GNUSTEP_MAKEFILES)/framework.make
+include $(GNUSTEP_MAKEFILES)/library.make
include $(GNUSTEP_MAKEFILES)/tool.make
-include GNUmakefile.postamble
before-all:: before-etshell before-toilet
-before-toilet:: ToiletKit
+before-toilet:: $(KIT_TARGETS)
rm -f obj/toilet
before-etshell:: ToiletKit
@@ -121,19 +161,24 @@ before-Test:: ToiletKit
#after-clean::
# -rmdir $(GNUSTEP_OBJ_DIR)/StepTalkShell
+ifneq ($(BUILD_TOILET_LLVM),YES)
+after-clean::
+ $(MAKE) clean shared=no BUILD_TOILET_LLVM=YES
+endif
+
test: ToiletKit Test
env LD_LIBRARY_PATH="`pwd`/ToiletKit.framework/Versions/Current:/usr/local/lib" ukrun Test.bundle
run-et: before-etshell ToiletKit etshell
env LD_LIBRARY_PATH="`pwd`/ToiletKit.framework/Versions/Current:/usr/local/lib" obj/etshell
-run-toilet: before-toilet ToiletKit toilet
+run-toilet: before-toilet $(KIT_TARGETS) toilet
env LD_LIBRARY_PATH="`pwd`/ToiletKit.framework/Versions/Current:/usr/local/lib" obj/toilet
run: run-toilet
-debugging-run: before-toilet ToiletKit toilet
+debugging-run: before-toilet $(KIT_TARGETS) toilet
env LD_LIBRARY_PATH="`pwd`/ToiletKit.framework/Versions/Current:/usr/local/lib" gdb -ex run obj/toilet
-ddd-run: before-toilet ToiletKit toilet
+ddd-run: before-toilet $(KIT_TARGETS) toilet
env LD_LIBRARY_PATH="`pwd`/ToiletKit.framework/Versions/Current:/usr/local/lib" ddd obj/toilet
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 4b63a89..53e0481 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -83,6 +83,11 @@ static Constant
MLKDefaultCompiler = self;
MLKLoadCompilesP = YES;
}
+
+ // GNU ld optimises the MLKLLVMCompilation category on
+ // MLKLexicalContext away unless we do this. Man, the crappiness of
+ // this Unix stuff is amazing...
+ MLKDummyUseLLVMLexicalContext = nil;
}
+(void) initialize
diff --git a/MLKLexicalContext-MLKLLVMCompilation.h b/MLKLexicalContext-MLKLLVMCompilation.h
index d791765..4f4c849 100644
--- a/MLKLexicalContext-MLKLLVMCompilation.h
+++ b/MLKLexicalContext-MLKLLVMCompilation.h
@@ -31,6 +31,8 @@ using namespace llvm;
#endif
+extern id MLKDummyUseLLVMLexicalContext;
+
@interface MLKLexicalContext (MLKLLVMCompilation)
#ifdef __cplusplus
-(void) setVariableHeapAllocation:(BOOL)heapp forSymbol:(id)name;
diff --git a/MLKLexicalContext-MLKLLVMCompilation.mm b/MLKLexicalContext-MLKLLVMCompilation.mm
index 22d211d..45208ed 100644
--- a/MLKLexicalContext-MLKLLVMCompilation.mm
+++ b/MLKLexicalContext-MLKLLVMCompilation.mm
@@ -31,6 +31,8 @@ using namespace llvm;
using namespace std;
+id MLKDummyUseLLVMLexicalContext = nil;
+
@implementation MLKLexicalContext (MLKLLVMCompilation)
-(void) setVariableHeapAllocation:(BOOL)heapp
forSymbol:(id)name
diff --git a/MLKReadEvalPrintLoop.m b/MLKReadEvalPrintLoop.m
index fc0d8ef..53943bc 100644
--- a/MLKReadEvalPrintLoop.m
+++ b/MLKReadEvalPrintLoop.m
@@ -26,6 +26,11 @@
#import "runtime-compatibility.h"
#import "util.h"
+#if USE_LLVM
+#import "MLKLLVMCompiler.h"
+#import "MLKLexicalContext-MLKLLVMCompilation.h"
+#endif
+
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSException.h>
#import <Foundation/NSNull.h>
@@ -76,6 +81,12 @@ static const char *prompt (EditLine *e) {
BOOL success;
NSAutoreleasePool *pool;
+#ifdef USE_LLVM
+ // We do this in order to prevent ld from “optimising” MLKLLVMCompiler
+ // away. GNU ld apparently sucks at dynamic languages.
+ [MLKLLVMCompiler class];
+#endif
+
editline = el_init (_argv[0], stdin, stdout, stderr);
el_set (editline, EL_PROMPT, &prompt);
el_set (editline, EL_EDITOR, "emacs");