summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKBinaryStreamCharacterStream.m7
-rw-r--r--MLKLLVMCompiler.mm30
-rw-r--r--MLKRoot.m1
-rw-r--r--Toilet Lisp.xcodeproj/project.pbxproj114
4 files changed, 101 insertions, 51 deletions
diff --git a/MLKBinaryStreamCharacterStream.m b/MLKBinaryStreamCharacterStream.m
index f26db7b..c095147 100644
--- a/MLKBinaryStreamCharacterStream.m
+++ b/MLKBinaryStreamCharacterStream.m
@@ -60,9 +60,10 @@
//NSLog (@"%@", _binaryStream);
//NSLog(@"Read: 0x%x (%C)", buffer[i], buffer[i]);
- tmpstr = [[NSString alloc] initWithBytes:buffer
- length:(i+1)
- encoding:_encoding];
+ tmpstr = [[NSString alloc] initWithBytesNoCopy:buffer
+ length:(i+1)
+ encoding:_encoding
+ freeWhenDone:NO];
if ([tmpstr length] == 1)
{
retval = [tmpstr characterAtIndex:0];
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index c2007af..d9e67fb 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -41,9 +41,9 @@
#include <llvm/DerivedTypes.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
+#include <llvm/ExecutionEngine/Interpreter.h>
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/Instructions.h>
-//#include <llvm/Interpreter.h>
#include <llvm/Module.h>
#include <llvm/PassManager.h>
#include <llvm/Support/IRBuilder.h>
@@ -82,14 +82,16 @@ static Constant
Constant *(indices[2]);
indices[0] = indices[1] = ConstantInt::get (Int32Ty, 0);
- Constant *str = ConstantArray::get (*llvm_context, string);
- Constant *str2 = new GlobalVariable (str->getType(),
+ Constant *str = ConstantArray::get (*llvm_context, string, true);
+ Constant *str2 = new GlobalVariable (*module,
+ str->getType(),
true,
GlobalValue::InternalLinkage,
str,
- "",
- module);
- Constant *ptr = ConstantExpr::getGetElementPtr (str2, indices, 2);
+ "");
+ // ArrayRef<Constant*> aindices(indices, 2);
+ // Constant *ptr = ConstantExpr::getGetElementPtr (str2, aindices, false);
+ Constant *ptr = ConstantExpr::getGetElementPtr (str2, indices, 2, false);
return ptr;
}
@@ -125,9 +127,12 @@ static Constant
module = new llvm::Module ("MLKLLVMModule", *llvm_context);
+ LLVMLinkInInterpreter();
+ LLVMLinkInJIT();
+
InitializeNativeTarget();
std::string error;
- //execution_engine = ExecutionEngine::create (module, true);
+ //execution_engine = ExecutionEngine::create (module, true, &error);
execution_engine = ExecutionEngine::create (module, false, &error);
assert(execution_engine);
@@ -159,9 +164,7 @@ static Constant
Value *v = NULL;
BasicBlock *block;
- vector<const Type*> noargs (0, VoidTy);
FunctionType *function_type = FunctionType::get (VoidPointerTy,
- noargs,
false);
Function *function = Function::Create (function_type,
Function::ExternalLinkage,
@@ -174,6 +177,8 @@ static Constant
forCompiler:self];
[self markVariablesForHeapAllocationInForm:form];
+ //NSLog(@"Compiling form: %@", MLKPrintToString(object));
+
block = BasicBlock::Create (*llvm_context, "entry", function);
builder->SetInsertPoint (block);
@@ -181,9 +186,10 @@ static Constant
builder->CreateRet (v);
verifyFunction (*function);
+ //NSLog(@"Running FPM...");
fpm->run (*function);
+ //function->dump(); //!
- //function->dump();
//module->dump();
//NSLog (@"%p", fn);
@@ -195,7 +201,7 @@ static Constant
// JIT-compile.
vector<GenericValue> nogenericargs;
lambdaForm = (id)execution_engine->runFunction (function, nogenericargs).PointerVal;
- //fn = (id (*)()) execution_engine->getPointerToFunction (function);
+ //id (*fn)() = (id (*)()) execution_engine->getPointerToFunction (function);
// Execute.
//lambdaForm = fn();
// FIXME: Free machine code when appropriate. (I.e. now? But this crashes after a LOAD.)
@@ -635,7 +641,7 @@ static Constant
//[_compiler insertTrace:[NSString stringWithFormat:@"Now calling: %@.", MLKPrintToString(_head)]];
//[_compiler insertPointerTrace:functionPtr];
- CallInst *call = builder->CreateCall (functionPtr,
+ CallInst *call = builder->CreateCall(functionPtr,
args.begin(),
args.end(),
[MLKPrintToString(_head) UTF8String]);
diff --git a/MLKRoot.m b/MLKRoot.m
index 4ab2f2e..0f7afa5 100644
--- a/MLKRoot.m
+++ b/MLKRoot.m
@@ -163,6 +163,7 @@ load (id *_data, id *_multireturn, NSString *fileName, id _marker)
static id
require (id *_data, id *_multireturn, id moduleName, id _marker)
{
+ NSLog(@"require...");
NSBundle *toiletKit = [NSBundle bundleForClass:[MLKRoot class]];
NSString *path = [[toiletKit resourcePath]
stringByAppendingPathComponent:stringify(moduleName)];
diff --git a/Toilet Lisp.xcodeproj/project.pbxproj b/Toilet Lisp.xcodeproj/project.pbxproj
index ce46b7f..dae7b41 100644
--- a/Toilet Lisp.xcodeproj/project.pbxproj
+++ b/Toilet Lisp.xcodeproj/project.pbxproj
@@ -1538,17 +1538,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=3",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",
@@ -1574,17 +1581,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=3",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",
@@ -1611,17 +1625,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=5",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",
@@ -1649,17 +1670,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=3",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",
@@ -1685,17 +1713,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=3",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",
@@ -1722,17 +1757,24 @@
);
MACOSX_DEPLOYMENT_TARGET = "";
OTHER_CFLAGS = (
- "$(inherited)",
+ "-DHAVE_FFI_FFI_H",
+ "-I/opt/homebrew/include",
+ "-D_DEBUG",
+ "-D_GLIBCXX_DEBUG",
+ "-DXDEBUG",
+ "-D_GNU_SOURCE",
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+ "-O3",
+ "-g",
+ "-fno-common",
"-DUSE_LLVM",
- "-DLLVM_MAJOR_VERSION=2",
- "-DLLVM_MINOR_VERSION=3",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
- "-D_DEBUG",
- "-D_GNU_SOURCE",
- "-D__STDC_LIMIT_MACROS",
+ "$(OTHER_CFLAGS)",
"-Woverloaded-virtual",
+ "-I/opt/local/include",
);
OTHER_LDFLAGS = (
"-framework",