[vmkit-commits] [vmkit] r83538 - in /vmkit/trunk: lib/Mvm/Compiler/JIT.cpp tools/jnjvm/Makefile tools/n3-mono/Makefile tools/n3-pnetlib/Makefile tools/vmjc/Makefile tools/vmkit/Makefile
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Oct 8 02:01:00 PDT 2009
Author: geoffray
Date: Thu Oct 8 04:01:00 2009
New Revision: 83538
URL: http://llvm.org/viewvc/llvm-project?rev=83538&view=rev
Log:
Add the possibility to load .bc or .ll files dynamically and link
with application code.
Modified:
vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
vmkit/trunk/tools/jnjvm/Makefile
vmkit/trunk/tools/n3-mono/Makefile
vmkit/trunk/tools/n3-pnetlib/Makefile
vmkit/trunk/tools/vmjc/Makefile
vmkit/trunk/tools/vmkit/Makefile
Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Oct 8 04:01:00 2009
@@ -12,6 +12,7 @@
#include <llvm/DerivedTypes.h>
#include <llvm/Instructions.h>
#include <llvm/LinkAllPasses.h>
+#include <llvm/Linker.h>
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/ModuleProvider.h>
@@ -19,11 +20,15 @@
#include <llvm/Type.h>
#include <llvm/Analysis/LoopPass.h>
#include <llvm/Analysis/Verifier.h>
+#include <llvm/Assembly/Parser.h>
#include <llvm/CodeGen/GCStrategy.h>
#include <llvm/Config/config.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
+#include "llvm/Support/CommandLine.h"
#include <llvm/Support/Debug.h>
+#include <llvm/Support/IRReader.h>
#include <llvm/Support/MutexGuard.h>
+#include "llvm/Support/SourceMgr.h"
#include <llvm/Target/TargetData.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
@@ -40,6 +45,10 @@
using namespace llvm;
+static cl::list<std::string>
+LoadBytecodeFiles("load-bc", cl::desc("Load bytecode file"), cl::ZeroOrMore,
+ cl::CommaSeparated);
+
namespace mvm {
namespace llvm_runtime {
#include "LLVMRuntime.inc"
@@ -51,6 +60,17 @@
return LLVM_HOSTTRIPLE;
}
+void MvmModule::loadBytecodeFile(const std::string& str) {
+ SMDiagnostic Err;
+ Module* M = ParseIRFile(str, Err, getGlobalContext());
+ if (M) {
+ M->setTargetTriple(getHostTriple());
+ Linker::LinkModules(globalModule, M, 0);
+ delete M;
+ } else {
+ Err.Print("load bytecode", errs());
+ }
+}
void MvmModule::initialise(CodeGenOpt::Level level, Module* M,
TargetMachine* T) {
@@ -97,7 +117,12 @@
ptrPtrType = PointerType::getUnqual(ptrType);
pointerSizeType = globalModule->getPointerSize() == Module::Pointer32 ?
Type::getInt32Ty(Context) : Type::getInt64Ty(Context);
-
+
+ for (std::vector<std::string>::iterator i = LoadBytecodeFiles.begin(),
+ e = LoadBytecodeFiles.end(); i != e; ++i) {
+ loadBytecodeFile(*i);
+ }
+
}
@@ -333,12 +358,12 @@
// Loop over all of the functions in the src module, mapping them over
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SF = I; // SrcFunction
- assert(SF->isDeclaration() &&
- "Don't know how top copy functions with body");
- Function* F = Function::Create(SF->getFunctionType(),
- GlobalValue::ExternalLinkage,
- SF->getName(), Dst);
- F->setAttributes(SF->getAttributes());
+ if (SF->isDeclaration()) {
+ Function* F = Function::Create(SF->getFunctionType(),
+ GlobalValue::ExternalLinkage,
+ SF->getName(), Dst);
+ F->setAttributes(SF->getAttributes());
+ }
}
}
Modified: vmkit/trunk/tools/jnjvm/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/jnjvm/Makefile?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/tools/jnjvm/Makefile (original)
+++ vmkit/trunk/tools/jnjvm/Makefile Thu Oct 8 04:01:00 2009
@@ -37,7 +37,7 @@
endif
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitreader asmparser linker
include $(LEVEL)/Makefile.common
Modified: vmkit/trunk/tools/n3-mono/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Makefile?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/tools/n3-mono/Makefile (original)
+++ vmkit/trunk/tools/n3-mono/Makefile Thu Oct 8 04:01:00 2009
@@ -11,7 +11,7 @@
include $(LEVEL)/Makefile.config
TOOLNAME = n3-mono
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitreader asmparser linker
ifeq ($(WITH_LLVM_GCC), 1)
Modified: vmkit/trunk/tools/n3-pnetlib/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-pnetlib/Makefile?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/tools/n3-pnetlib/Makefile (original)
+++ vmkit/trunk/tools/n3-pnetlib/Makefile Thu Oct 8 04:01:00 2009
@@ -11,7 +11,7 @@
include $(LEVEL)/Makefile.config
TOOLNAME = n3-pnetlib
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitreader asmparser linker
ifeq ($(WITH_LLVM_GCC), 1)
MODULESNAME = vmkit
Modified: vmkit/trunk/tools/vmjc/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/Makefile?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/tools/vmjc/Makefile (original)
+++ vmkit/trunk/tools/vmjc/Makefile Thu Oct 8 04:01:00 2009
@@ -29,6 +29,6 @@
Mvm.a MvmCompiler.a $(GCLIB).a
endif
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitwriter
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitwriter bitreader asmparser linker
include $(LEVEL)/Makefile.common
Modified: vmkit/trunk/tools/vmkit/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Makefile?rev=83538&r1=83537&r2=83538&view=diff
==============================================================================
--- vmkit/trunk/tools/vmkit/Makefile (original)
+++ vmkit/trunk/tools/vmkit/Makefile Thu Oct 8 04:01:00 2009
@@ -53,7 +53,7 @@
endif
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitreader asmparser linker
include $(LEVEL)/Makefile.common
More information about the vmkit-commits
mailing list