Skip to content

WIP: More information in the README and mahing it run with LLVM 3.0. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: llvm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.llvm
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Instructions
Requirements
------------

1. Install autoconf, libtool with their dependencies.
2. Install LLVM. If your package manager uses names like llvm-<app>-<version>,
make sure there are appropriate symlinks to llvm-<app>.
3. Install libclang, libapr1-dev and libicu-dev.

Instructions
------------

1. Run autoreconf
2. Run ./configure
3. Build scala with ant
Expand Down
18 changes: 14 additions & 4 deletions src/llvm/runtime/runscala.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Instructions.h"
#if LLVM_MAJOR_VERSION >=2 && LLVM_MINOR_VERSION >= 9
#if LLVM_MAJOR_VERSION >=3 || LLVM_MAJOR_VERSION ==2 && LLVM_MINOR_VERSION >= 9
# include "llvm/ADT/OwningPtr.h"
# include "llvm/Support/Process.h"
# include "llvm/Support/Signals.h"
Expand All @@ -31,8 +31,12 @@
# include "llvm/System/Process.h"
# include "llvm/System/Signals.h"
#endif
#include "llvm/Target/TargetSelect.h"
#include "llvm/Target/TargetOptions.h"
#if LLVM_MAJOR_VERSION >=3
# include "llvm/Support/TargetSelect.h"
# include "llvm/Target/TargetOptions.h"
#else
# include "llvm/Target/TargetOptions.h"
#endif
#include "llvm/Support/IRBuilder.h"
#include <cerrno>
#include <cstdlib>
Expand Down Expand Up @@ -129,9 +133,15 @@ void addTrace(Function *f, Constant *traceentryFn, Constant *traceexitFn)
void traceFuncs(Module &m)
{
LLVMContext &ctx = m.getContext();
#if LLVM_MAJOR_VERSION >=3
std::vector<Type*> argtypes;
argtypes.push_back(Type::getInt8PtrTy(ctx));
FunctionType *tracestringFnTy = FunctionType::get(Type::getVoidTy(ctx), makeArrayRef(argtypes), false);
#else
std::vector<const Type*> argtypes;
argtypes.push_back(Type::getInt8PtrTy(ctx));
FunctionType *tracestringFnTy = FunctionType::get(Type::getVoidTy(ctx), argtypes, false);
#endif
Constant *traceentryFn = m.getOrInsertFunction("traceentry", tracestringFnTy);
Constant *traceexitFn = m.getOrInsertFunction("traceexit", tracestringFnTy);
for (Module::iterator it = m.begin(); it != m.end(); ++it) {
Expand All @@ -152,7 +162,7 @@ int main(int argc, char *argv[], char * const *envp)
std::string ErrorMsg;
Module *Mod = NULL;

#if LLVM_MAJOR_VERSION >= 2 && LLVM_MINOR_VERSION >= 9
#if LLVM_MAJOR_VERSION >=3 || LLVM_MAJOR_VERSION >= 2 && LLVM_MINOR_VERSION >= 9
OwningPtr<MemoryBuffer> Buffer;
error_code errc = MemoryBuffer::getFileOrSTDIN(argv[1], Buffer);
if (errc) {
Expand Down
16 changes: 16 additions & 0 deletions src/llvm/runtime/wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include "wrapper.h"

#include "llvm/Function.h"
Expand Down Expand Up @@ -43,10 +44,17 @@ createMainWrapperFunction(
LLVMContext &ctx = module.getContext();

IRBuilder<> builder(ctx);
#if LLVM_MAJOR_VERSION >=3
std::vector<Type*> argtypes;
argtypes.push_back(Type::getInt32Ty(ctx));
argtypes.push_back(Type::getInt8PtrTy(ctx)->getPointerTo());
FunctionType *funtype = FunctionType::get(Type::getVoidTy(ctx), makeArrayRef(argtypes), false);
#else
std::vector<const Type*> argtypes;
argtypes.push_back(Type::getInt32Ty(ctx));
argtypes.push_back(Type::getInt8PtrTy(ctx)->getPointerTo());
FunctionType *funtype = FunctionType::get(Type::getVoidTy(ctx), argtypes, false);
#endif
Function *ret = Function::Create(funtype, Function::ExternalLinkage, name, &module);

Function *loadvtable = module.getFunction("rt_loadvtable");
Expand All @@ -72,7 +80,11 @@ createMainWrapperFunction(
args.push_back(builder.CreateBitCast(argvObj, realMain->getFunctionType()->getParamType(2)));
args.push_back(builder.CreateCall(loadvtable, builder.CreateBitCast(argvObj, loadvtable->getFunctionType()->getParamType(0))));

#if LLVM_MAJOR_VERSION >=3
builder.CreateInvoke(realMain, normalBlock, exceptionBlock, makeArrayRef(args));
#else
builder.CreateInvoke(realMain, normalBlock, exceptionBlock, args.begin(), args.end());
#endif

args.clear();

Expand All @@ -91,9 +103,13 @@ createMainWrapperFunction(
args.push_back(ConstantInt::get(builder.getInt32Ty(), 1));
args.push_back(ConstantInt::get(builder.getInt32Ty(), 0));

#if LLVM_MAJOR_VERSION >=3
builder.CreateCall(Intrinsic::getDeclaration(&module, Intrinsic::eh_selector), makeArrayRef(args));
#else
builder.CreateCall(
Intrinsic::getDeclaration(&module, Intrinsic::eh_selector),
args.begin(), args.end());
#endif

args.clear();

Expand Down