[vmkit-commits] [vmkit] r56850 - in /vmkit/branches/isolate/lib/N3: LLVMRuntime/ LLVMRuntime/Makefile LLVMRuntime/runtime.ll Makefile VMCore/CLIJit.cpp VMCore/CLIRuntimeJIT.cpp VMCore/CLISignature.cpp VMCore/Makefile VMCore/VMCache.cpp VMCore/VMClass.cpp VMCore/VMClass.h VMCore/VirtualTables.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Sep 30 09:06:06 PDT 2008
Author: geoffray
Date: Tue Sep 30 11:06:06 2008
New Revision: 56850
URL: http://llvm.org/viewvc/llvm-project?rev=56850&view=rev
Log:
Declare runtime functions for LLVM in LLVM format.
Added:
vmkit/branches/isolate/lib/N3/LLVMRuntime/
vmkit/branches/isolate/lib/N3/LLVMRuntime/Makefile
vmkit/branches/isolate/lib/N3/LLVMRuntime/runtime.ll
vmkit/branches/isolate/lib/N3/VMCore/CLIRuntimeJIT.cpp
Modified:
vmkit/branches/isolate/lib/N3/Makefile
vmkit/branches/isolate/lib/N3/VMCore/CLIJit.cpp
vmkit/branches/isolate/lib/N3/VMCore/CLISignature.cpp
vmkit/branches/isolate/lib/N3/VMCore/Makefile
vmkit/branches/isolate/lib/N3/VMCore/VMCache.cpp
vmkit/branches/isolate/lib/N3/VMCore/VMClass.cpp
vmkit/branches/isolate/lib/N3/VMCore/VMClass.h
vmkit/branches/isolate/lib/N3/VMCore/VirtualTables.cpp
Added: vmkit/branches/isolate/lib/N3/LLVMRuntime/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/LLVMRuntime/Makefile?rev=56850&view=auto
==============================================================================
--- vmkit/branches/isolate/lib/N3/LLVMRuntime/Makefile (added)
+++ vmkit/branches/isolate/lib/N3/LLVMRuntime/Makefile Tue Sep 30 11:06:06 2008
@@ -0,0 +1,16 @@
+##===- lib/N3/LLVMRuntime/Makefile -------------------------*- Makefile -*-===##
+#
+# The vmkit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../../..
+
+include $(LEVEL)/Makefile.config
+
+VMKIT_RUNTIME = runtime.ll
+BUILT_SOURCES = LLVMRuntime.inc
+
+include $(LEVEL)/Makefile.common
Added: vmkit/branches/isolate/lib/N3/LLVMRuntime/runtime.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/LLVMRuntime/runtime.ll?rev=56850&view=auto
==============================================================================
--- vmkit/branches/isolate/lib/N3/LLVMRuntime/runtime.ll (added)
+++ vmkit/branches/isolate/lib/N3/LLVMRuntime/runtime.ll Tue Sep 30 11:06:06 2008
@@ -0,0 +1,53 @@
+%CLIObject = type {i8*, i8*, i8*}
+
+;;; Types for CLI arrays. A size of 0 means an undefined size.
+%CLIArray = type { %CLIObject, i32 }
+%ArrayDouble = type { %CLIObject, i32, [0 x double] }
+%ArrayFloat = type { %CLIObject, i32, [0 x float] }
+%ArrayLong = type { %CLIObject, i32, [0 x i64] }
+%ArrayObject = type { %CLIObject, i32, [0 x %CLIObject*] }
+%ArraySInt16 = type { %CLIObject, i32, [0 x i16] }
+%ArraySInt32 = type { %CLIObject, i32, [0 x i32] }
+%ArraySInt8 = type { %CLIObject, i32, [0 x i8] }
+%ArrayUInt16 = type { %CLIObject, i32, [0 x i16] }
+%ArrayUInt32 = type { %CLIObject, i32, [0 x i32] }
+%ArrayUInt8 = type { %CLIObject, i32, [0 x i8] }
+
+%CacheNode = type {i8*, i8*, i8*, i8*, i8*, i1}
+
+%Enveloppe = type {i8*, %CacheNode*, i8*, i8*}
+
+declare void @MarkAndTrace(%CLIObject*)
+declare void @CLIObjectTracer(%CLIObject*)
+
+declare %CLIObject* @initialiseClass(i8*)
+
+declare %CacheNode* @n3VirtualLookup(%CacheNode*, %CLIObject*)
+
+declare %CLIObject* @newArray(i8*, i32)
+declare %CLIObject* @newObject(i8*)
+declare %CLIObject* @newMultiArray(i8*)
+declare %CLIObject* @newString(i8*)
+
+declare %CLIObject* @initialiseObject(i8*, i32) readnone
+
+declare i32 @arrayLength(%CLIArray*) readnone
+
+declare void @n3NullPointerException()
+declare void @n3ClassCastException()
+declare void @indexOutOfBounds(%CLIObject*, i32)
+
+declare void @ThrowException(%CLIObject*)
+declare void @ClearException()
+declare i8* @GetCppException()
+declare %CLIObject* @GetCLIException()
+declare i1 @CompareException(i8*)
+
+declare i32 @n3InstanceOf(%CLIObject*, i8*)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Debugging methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare void @printExecution(i32, i32)
+
Modified: vmkit/branches/isolate/lib/N3/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/Makefile?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/Makefile (original)
+++ vmkit/branches/isolate/lib/N3/Makefile Tue Sep 30 11:06:06 2008
@@ -10,7 +10,7 @@
include $(LEVEL)/Makefile.config
-DIRS = VMCore
+DIRS = LLVMRuntime VMCore
ifeq ($(WITH_N3_MONO), 1)
DIRS += Mono
Modified: vmkit/branches/isolate/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/CLIJit.cpp?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/CLIJit.cpp Tue Sep 30 11:06:06 2008
@@ -14,6 +14,7 @@
#include "debug.h"
#include "types.h"
+#include "llvm/CallingConv.h"
#include <llvm/Constants.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Function.h>
@@ -1497,33 +1498,6 @@
}
-extern "C" VMObject* initialiseClass(VMClass* cl) {
- cl->clinitClass(NULL);
- return cl->staticInstance;
-}
-
-extern "C" void n3ClassCastException() {
- fflush(stdout);
- assert(0 && "implement class cast exception");
-}
-
-extern "C" void n3NullPointerException() {
- fflush(stdout);
- assert(0 && "implement null pointer exception");
-}
-
-extern "C" void indexOutOfBounds() {
- fflush(stdout);
- assert(0 && "implement index out of bounds exception");
-}
-
-
-extern "C" VMObject* newString(const UTF8* utf8) {
- CLIString * str =
- (CLIString*)(((N3*)VMThread::get()->vm)->UTF8ToStr(utf8));
- return str;
-}
-
void CLIJit::initialise() {
}
@@ -1533,501 +1507,82 @@
mvm::jit::protectEngine->unlock();
}
+namespace n3 {
+ namespace llvm_runtime {
+ #include "LLVMRuntime.inc"
+ }
+}
+
+
void CLIJit::initialiseBootstrapVM(N3* vm) {
Module* module = vm->module;
mvm::jit::protectEngine->lock();
mvm::jit::executionEngine->addModuleProvider(vm->TheModuleProvider);
mvm::jit::protectEngine->unlock();
-
-
-
- {
- std::vector<const llvm::Type *> arg_types;
- arg_types.insert (arg_types.begin (), llvm::PointerType::getUnqual(mvm::jit::ptrType));
- llvm::FunctionType *mtype = llvm::FunctionType::get (llvm::Type::VoidTy, arg_types, false);
- Function::Create(mtype, llvm::GlobalValue::ExternalLinkage, "llvm.va_start", module);
- }
-
- {
- std::vector<const llvm::Type *> arg_types;
- arg_types.insert (arg_types.begin (), llvm::Type::Int32Ty);
-
- llvm::FunctionType *mtype = llvm::FunctionType::get (llvm::PointerType::getUnqual(llvm::Type::Int8Ty), arg_types, false);
- Function::Create(mtype, llvm::GlobalValue::ExternalLinkage, "llvm.frameaddress", module);
- }
+ n3::llvm_runtime::makeLLVMModuleContents(module);
-
- {
- const llvm::Type *BPTy = PointerType::getUnqual(llvm::Type::Int8Ty);
- // Prototype malloc as "char* malloc(...)", because we don't know in
- // doInitialization whether size_t is int or long.
- FunctionType *FT = FunctionType::get(BPTy, std::vector<const llvm::Type*>(), true);
- Function::Create(FT, llvm::GlobalValue::ExternalLinkage, "_ZN2gcnwEjP5gc_vt", module);
- }
-
-
- // Create VMObject::llvmType
- const llvm::Type* Pty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
-
- std::vector<const llvm::Type*> objectFields;
- objectFields.push_back(Pty); // VT
- objectFields.push_back(Pty); // Class
- objectFields.push_back(Pty); // Lock
VMObject::llvmType =
- llvm::PointerType::getUnqual(llvm::StructType::get(objectFields, false));
-
- // Create VMArray::llvmType
- {
- std::vector<const llvm::Type*> arrayFields;
- arrayFields.push_back(VMObject::llvmType->getContainedType(0));
- arrayFields.push_back(llvm::Type::Int32Ty);
- VMArray::llvmType =
- llvm::PointerType::getUnqual(llvm::StructType::get(arrayFields, false));
- }
-
-#define ARRAY_TYPE(name, type) \
- { \
- std::vector<const Type*> arrayFields; \
- arrayFields.push_back(VMObject::llvmType->getContainedType(0)); \
- arrayFields.push_back(Type::Int32Ty); \
- arrayFields.push_back(ArrayType::get(type, 0)); \
- name::llvmType = PointerType::getUnqual(StructType::get(arrayFields, false)); \
- }
-
- ARRAY_TYPE(ArrayUInt8, Type::Int8Ty);
- ARRAY_TYPE(ArraySInt8, Type::Int8Ty);
- ARRAY_TYPE(ArrayUInt16, Type::Int16Ty);
- ARRAY_TYPE(ArraySInt16, Type::Int16Ty);
- ARRAY_TYPE(ArrayUInt32, Type::Int32Ty);
- ARRAY_TYPE(ArraySInt32, Type::Int32Ty);
- ARRAY_TYPE(ArrayLong, Type::Int64Ty);
- ARRAY_TYPE(ArrayDouble, Type::DoubleTy);
- ARRAY_TYPE(ArrayFloat, Type::FloatTy);
- ARRAY_TYPE(ArrayObject, VMObject::llvmType);
-
-#undef ARRAY_TYPE
-
- // Create UTF8::llvmType
- {
- std::vector<const llvm::Type*> arrayFields;
- arrayFields.push_back(VMObject::llvmType->getContainedType(0));
- arrayFields.push_back(llvm::Type::Int32Ty);
- arrayFields.push_back(llvm::ArrayType::get(llvm::Type::Int16Ty, 0));
- UTF8::llvmType =
- llvm::PointerType::getUnqual(llvm::StructType::get(arrayFields, false));
- }
+ PointerType::getUnqual(module->getTypeByName("CLIObject"));
+ VMArray::llvmType =
+ PointerType::getUnqual(module->getTypeByName("CLIArray"));
+ ArrayUInt8::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayUInt8"));
+ ArraySInt8::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArraySInt8"));
+ ArrayUInt16::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayUInt16"));
+ ArraySInt16::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArraySInt16"));
+ ArraySInt32::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArraySInt32"));
+ ArrayLong::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayLong"));
+ ArrayDouble::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayDouble"));
+ ArrayFloat::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayFloat"));
+ ArrayObject::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayObject"));
+ UTF8::llvmType =
+ PointerType::getUnqual(module->getTypeByName("ArrayUInt16"));
+ CacheNode::llvmType =
+ PointerType::getUnqual(module->getTypeByName("CacheNode"));
+ Enveloppe::llvmType =
+ PointerType::getUnqual(module->getTypeByName("Enveloppe"));
- // Create CacheNode::llvmType
- {
- std::vector<const llvm::Type*> arrayFields;
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // VT
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // methPtr
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // lastCible
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // next
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // enveloppe
- arrayFields.push_back(Type::Int1Ty); // box
- CacheNode::llvmType =
- PointerType::getUnqual(StructType::get(arrayFields, false));
- }
-
- // Create Enveloppe::llvmType
- {
- std::vector<const llvm::Type*> arrayFields;
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // VT
- arrayFields.push_back(CacheNode::llvmType); // firstCache
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // cacheLock
- arrayFields.push_back(PointerType::getUnqual(Type::Int8Ty)); // originalMethod
- Enveloppe::llvmType =
- PointerType::getUnqual(StructType::get(arrayFields, false));
- }
-
#ifdef WITH_TRACER
- // Create markAndTraceLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
-#ifdef MULTIPLE_GC
- args.push_back(mvm::jit::ptrType);
-#endif
- markAndTraceLLVMType = FunctionType::get(llvm::Type::VoidTy, args, false);
- markAndTraceLLVM = Function::Create(markAndTraceLLVMType,
- GlobalValue::ExternalLinkage,
-#ifdef MULTIPLE_GC
- "_ZNK2gc12markAndTraceEP9Collector",
-#else
- "_ZNK2gc12markAndTraceEv",
-#endif
- module);
- }
-#endif
-
- // Create vmObjectTracerLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
-#ifdef MULTIPLE_GC
- args.push_back(mvm::jit::ptrType);
-#endif
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
- vmObjectTracerLLVM = Function::Create(type,
- GlobalValue::ExternalLinkage,
-#ifdef MULTIPLE_GC
- "_ZN2n38VMObject6tracerEPv",
-#else
- "_ZN2n38VMObject6tracerEv",
+ markAndTraceLLVM = module->getFunction("MarkAndTrace");
+ markAndTraceLLVMType = markAndTraceLLVM->getFunctionType();
+ vmObjectTracerLLVM = module->getFunction("CLIObjectTracer");
#endif
- module);
- }
- // Create intialiseClassLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args, false);
- initialiseClassLLVM = Function::Create(type,
- GlobalValue::ExternalLinkage,
- "initialiseClass",
- module);
- }
-
- // Create resolveStringLLVM
- /*{
- std::vector<const Type*> args;
- args.push_back(UTF8::llvmType);
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- args.push_back(llvm::Type::Int32Ty);
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
- stringLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n37CLIJit12stringLookupEPKNS_4UTF8EPNS_5ClassEj",
- module);
- }*/
-
- // Create staticLookupLLVM
- /*{
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- args.push_back(llvm::Type::Int32Ty);
- const FunctionType* type =
- FunctionType::get(llvm::PointerType::getUnqual(llvm::Type::Int8Ty), args,
- false);
-
- staticLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n37CLIJit12staticLookupEPNS_5ClassEj",
- module);
- }*/
-
- // Create virtualLookupLLVM
- {
- std::vector<const Type*> args;
- //args.push_back(VMObject::llvmType);
- //args.push_back(PointerType::getUnqual(Type::Int8Ty));
- //args.push_back(llvm::Type::Int32Ty);
- args.push_back(CacheNode::llvmType);
- args.push_back(VMObject::llvmType);
- const FunctionType* type =
- FunctionType::get(CacheNode::llvmType, args, false);
-
- virtualLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "n3VirtualLookup", module);
-
-/*
- virtualLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n37CLIJit13virtualLookupEPNS_10VMObjectEPNS_5ClassEj",
- module);
-*/
- }
-
- // Create newLookupLLVM
- /*{
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- args.push_back(llvm::Type::Int32Ty);
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
-
- newLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n37CLIJit9newLookupEPNS_5ClassEj",
- module);
- }*/
-
- // Create arrayConsLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- args.push_back(Type::Int32Ty);
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
-
- arrayConsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n312VMClassArray5doNewEj",
- module);
- }
-
- // Create objConsLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
-
- objConsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n37VMClass5doNewEv",
- module);
- }
-
- // Create objInitLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- args.push_back(VMObject::llvmType);
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
-
- objInitLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n37VMClass16initialiseObjectEPNS_8VMObjectE",
- module);
- PAListPtr func_toto_PAL;
- SmallVector<ParamAttrsWithIndex, 4> Attrs;
- ParamAttrsWithIndex PAWI;
- PAWI.Index = 0; PAWI.Attrs = 0 | ParamAttr::ReadNone;
- Attrs.push_back(PAWI);
- func_toto_PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
- objInitLLVM->setParamAttrs(func_toto_PAL);
- }
-
- // Create arrayLengthLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMArray::llvmType);
- const FunctionType* type = FunctionType::get(Type::Int32Ty, args, false);
-
- arrayLengthLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "arrayLength",
- module);
- PAListPtr func_toto_PAL;
- SmallVector<ParamAttrsWithIndex, 4> Attrs;
- ParamAttrsWithIndex PAWI;
- PAWI.Index = 0; PAWI.Attrs = 0 | ParamAttr::ReadNone;
- Attrs.push_back(PAWI);
- func_toto_PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
- arrayLengthLLVM->setParamAttrs(func_toto_PAL);
- }
+ initialiseClassLLVM = module->getFunction("initialiseClass");
+ virtualLookupLLVM = module->getFunction("n3VirtualLookup");
-
- // Create nullPointerExceptionLLVM
- {
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
+ arrayConsLLVM = module->getFunction("newArray");
+ objConsLLVM = module->getFunction("newObject");
+ newStringLLVM = module->getFunction("newString");
+ objInitLLVM = module->getFunction("initialiseObject");
+ arrayMultiConsLLVM = module->getFunction("newMultiArray");
+ arrayLengthLLVM = module->getFunction("arrayLength");
+ instanceOfLLVM = module->getFunction("n3InstanceOf");
- nullPointerExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "n3NullPointerException",
- module);
- }
-
- // Create classCastExceptionLLVM
- {
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
+ nullPointerExceptionLLVM = module->getFunction("n3NullPointerException");
+ classCastExceptionLLVM = module->getFunction("n3ClassCastException");
+ indexOutOfBoundsExceptionLLVM = module->getFunction("indexOutOfBounds");
- classCastExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "n3ClassCastException",
- module);
- }
-
- // Create indexOutOfBoundsExceptionLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
- args.push_back(Type::Int32Ty);
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-
- indexOutOfBoundsExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "indexOutOfBounds",
- module);
- }
-
- // Create proceedPendingExceptionLLVM
- /*{
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-
- jniProceedPendingExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n37CLIJit26jniProceedPendingExceptionEv",
- module);
- }*/
- // Create printExecutionLLVM
- {
- std::vector<const Type*> args;
- args.push_back(Type::Int32Ty);
- args.push_back(Type::Int32Ty);
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
+ throwExceptionLLVM = module->getFunction("ThrowException");
+ clearExceptionLLVM = module->getFunction("ClearException");
+ compareExceptionLLVM = module->getFunction("CompareException");
+ getCppExceptionLLVM = module->getFunction("GetCppException");
+ getCLIExceptionLLVM = module->getFunction("GetCLIException");
- printExecutionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n36CLIJit14printExecutionEPcPNS_8VMMethodE",
- module);
- }
-
- // Create throwExceptionLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-
- throwExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMThread14throwExceptionEPNS_8VMObjectE",
- module);
- }
-
- // Create clearExceptionLLVM
- {
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
- clearExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMThread14clearExceptionEv",
- module);
- }
-
-
- // Create compareExceptionLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(Type::Int1Ty, args, false);
+ printExecutionLLVM = module->getFunction("printExecution");
- compareExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMThread16compareExceptionEPNS_7VMClassE",
- module);
- }
-
- // Create instanceOfLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(Type::Int32Ty, args, false);
-
- instanceOfLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMObject10instanceOfEPNS_13VMCommonClassE",
- module);
- }
-
- // Create arrayMultiConsLLVM
- {
- std::vector<const Type*> args;
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- true);
-
- arrayMultiConsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "doMultiNew",
- module);
- }
-
- /*
- // Create aquireObjectLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-
- aquireObjectLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n310VMObject6aquireEv",
- module);
- }
-
- // Create releaseObjectLLVM
- {
- std::vector<const Type*> args;
- args.push_back(VMObject::llvmType);
- const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-
- releaseObjectLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n310VMObject6unlockEv",
- module);
- }
-
- */
-
-
- // Create *AconsLLVM
- /*{
- std::vector<const Type*> args;
- args.push_back(Type::Int32Ty);
- args.push_back(PointerType::getUnqual(Type::Int8Ty));
- const FunctionType* type = FunctionType::get(VMObject::llvmType, args,
- false);
-
- FloatAconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n310ArrayFloat5aconsEiPNS_10VMClassArrayE",
- module);
-
- Int8AconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n310ArraySInt85aconsEiPNS_10VMClassArrayE",
- module);
-
- DoubleAconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n311ArrayDouble5aconsEiPNS_10VMClassArrayE",
- module);
-
- Int16AconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n311ArraySInt165aconsEiPNS_10VMClassArrayE",
- module);
-
- Int32AconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n311ArraySInt325aconsEiPNS_10VMClassArrayE",
- module);
-
- UTF8AconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n34UTF85aconsEiPNS_10VMClassArrayE",
- module);
-
- LongAconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n39ArrayLong5aconsEiPNS_10VMClassArrayE",
- module);
-
- ObjectAconsLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN5n311ArrayObject5aconsEiPNS_10VMClassArrayE",
- module);
- }*/
-
- // Create getCppExceptionLLVM
- {
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(mvm::jit::ptrType,
- args, false);
-
- getCppExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMThread15getCppExceptionEv",
- module);
- }
-
- // Create getCLIExceptionLLVM
- {
- std::vector<const Type*> args;
- const FunctionType* type = FunctionType::get(VMObject::llvmType,
- args, false);
-
- getCLIExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "_ZN2n38VMThread15getCLIExceptionEv",
- module);
- }
-
- // Create newStringLLVM
- {
- std::vector<const Type*> args;
- args.push_back(mvm::jit::ptrType);
- const FunctionType* type = FunctionType::get(VMObject::llvmType,
- args, false);
-
- newStringLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
- "newString",
- module);
- }
constantVMObjectNull = Constant::getNullValue(VMObject::llvmType);
Added: vmkit/branches/isolate/lib/N3/VMCore/CLIRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/CLIRuntimeJIT.cpp?rev=56850&view=auto
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/CLIRuntimeJIT.cpp (added)
+++ vmkit/branches/isolate/lib/N3/VMCore/CLIRuntimeJIT.cpp Tue Sep 30 11:06:06 2008
@@ -0,0 +1,183 @@
+//===--- CLIRuntimeJIT.cpp - Runtime functions for the JIT compiled code --===//
+//
+// The vmkit project
+//
+// This file is distributed under the University Of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include <stdio.h>
+
+#include "llvm/DerivedTypes.h"
+#include "llvm/Instructions.h"
+
+#include "mvm/JIT.h"
+#include "mvm/Object.h"
+#include "mvm/PrintBuffer.h"
+#include "mvm/Threads/Locks.h"
+
+#include "CLIString.h"
+#include "MSCorlib.h"
+#include "N3.h"
+#include "VMArray.h"
+#include "VMCache.h"
+#include "VMClass.h"
+#include "VMObject.h"
+#include "VMThread.h"
+
+using namespace n3;
+using namespace llvm;
+
+extern "C" VMObject* initialiseClass(VMClass* cl) {
+ cl->clinitClass(NULL);
+ return cl->staticInstance;
+}
+
+extern "C" void n3ClassCastException() {
+ fflush(stdout);
+ assert(0 && "implement class cast exception");
+}
+
+extern "C" void n3NullPointerException() {
+ fflush(stdout);
+ assert(0 && "implement null pointer exception");
+}
+
+extern "C" void indexOutOfBounds() {
+ fflush(stdout);
+ assert(0 && "implement index out of bounds exception");
+}
+
+extern "C" VMObject* newString(const UTF8* utf8) {
+ CLIString * str =
+ (CLIString*)(((N3*)VMThread::get()->vm)->UTF8ToStr(utf8));
+ return str;
+}
+
+extern "C" bool n3InstanceOf(VMObject* obj, VMCommonClass* cl) {
+ return obj->instanceOf(cl);
+}
+
+extern "C" void* GetCppException() {
+ return VMThread::getCppException();
+}
+
+extern "C" void ThrowException(VMObject* obj) {
+ return VMThread::throwException(obj);
+}
+
+extern "C" VMObject* GetCLIException() {
+ return VMThread::getCLIException();
+}
+
+extern "C" bool CompareException(VMClass* cl) {
+ return VMThread::compareException(cl);
+}
+
+extern "C" void ClearException() {
+ return VMThread::clearException();
+}
+
+static VMObject* doMultiNewIntern(VMClassArray* cl, uint32 dim, sint32* buf) {
+ if (dim <= 0) VMThread::get()->vm->error("Can't happen");
+ sint32 n = buf[0];
+ if (n < 0) VMThread::get()->vm->negativeArraySizeException(n);
+
+ VMArray* res = (VMArray*)cl->doNew(n);
+ if (dim > 1) {
+ VMCommonClass* base = cl->baseClass;
+ if (n > 0) {
+ for (sint32 i = 0; i < n; ++i) {
+ res->elements[i] = doMultiNewIntern((VMClassArray*)base, dim - 1, &(buf[1]));
+ }
+ }
+ for (uint32 i = 1; i < dim; ++i) {
+ if (buf[i] < 0) VMThread::get()->vm->negativeArraySizeException(buf[i]);
+ }
+ }
+ return res;
+}
+
+extern "C" VMObject* doMultiNew(VMClassArray* cl, ...) {
+ sint32* dimSizes = (sint32*)alloca(cl->dims * sizeof(sint32));
+ va_list ap;
+ va_start(ap, cl);
+ for (uint32 i = 0; i < cl->dims; ++i) {
+ dimSizes[i] = va_arg(ap, sint32);
+ }
+ va_end(ap);
+ return doMultiNewIntern(cl, cl->dims, dimSizes);
+}
+
+extern "C" CacheNode* n3VirtualLookup(CacheNode* cache, VMObject *obj) {
+ Enveloppe* enveloppe = cache->enveloppe;
+ VMCommonClass* ocl = obj->classOf;
+ VMMethod* orig = enveloppe->originalMethod;
+
+ CacheNode* rcache = 0;
+ CacheNode* tmp = enveloppe->firstCache;
+ CacheNode* last = tmp;
+ enveloppe->cacheLock->lock();
+
+ while (tmp) {
+ if (ocl == tmp->lastCible) {
+ rcache = tmp;
+ break;
+ } else {
+ last = tmp;
+ tmp = tmp->next;
+ }
+ }
+
+ if (!rcache) {
+ VMMethod* dmeth = ocl->lookupMethodDontThrow(orig->name,
+ orig->parameters,
+ false, true);
+ if (dmeth == 0) {
+ char* methAsciiz = orig->name->UTF8ToAsciiz();
+ char* nameAsciiz = orig->classDef->name->UTF8ToAsciiz();
+ char* nameSpaceAsciiz = orig->classDef->nameSpace->UTF8ToAsciiz();
+
+ char *buf = (char*)alloca(3 + strlen(methAsciiz) +
+ strlen(nameAsciiz) +
+ strlen(nameSpaceAsciiz));
+ sprintf(buf, "%s.%s.%s", nameSpaceAsciiz, nameAsciiz, methAsciiz);
+ const UTF8* newName = VMThread::get()->vm->asciizConstructUTF8(buf);
+ dmeth = ocl->lookupMethod(newName, orig->parameters, false, true);
+ }
+
+ if (cache->methPtr) {
+ rcache = CacheNode::allocate();
+ rcache->enveloppe = enveloppe;
+ } else {
+ rcache = cache;
+ }
+
+ Function* func = dmeth->compiledPtr(NULL);
+ rcache->methPtr = mvm::jit::executionEngine->getPointerToGlobal(func);
+ rcache->lastCible = (VMClass*)ocl;
+ rcache->box = (dmeth->classDef->super == MSCorlib::pValue);
+ }
+
+ if (enveloppe->firstCache != rcache) {
+ CacheNode *f = enveloppe->firstCache;
+ enveloppe->firstCache = rcache;
+ last->next = rcache->next;
+ rcache->next = f;
+
+ }
+
+ enveloppe->cacheLock->unlock();
+
+ return rcache;
+}
+
+extern "C" VMObject* newObject(VMClass* cl) {
+ return cl->doNew();
+}
+
+extern "C" VMObject* newArray(VMClassArray* cl, sint32 nb) {
+ return cl->doNew(nb);
+}
Modified: vmkit/branches/isolate/lib/N3/VMCore/CLISignature.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/CLISignature.cpp?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/CLISignature.cpp (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/CLISignature.cpp Tue Sep 30 11:06:06 2008
@@ -300,10 +300,9 @@
if (currGenericMethod == NULL) {
// when reading in signatures which contain references to generic arguments
// of generic methods we need create a placeholder for each of them,
- // this is done by creating a dummy VMClass,
- // the token field is used to store the generic argument number
+ // this is done by creating a dummy VMClass which has the assembly field
+ // set to NULL, the token field is used to store the generic argument number
VMClass* cl = gc_new(VMClass)();
- cl->isDummy = true;
cl->token = number;
cl->assembly = ass;
cl->nameSpace = ass->name;
Modified: vmkit/branches/isolate/lib/N3/VMCore/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/Makefile?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/Makefile (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/Makefile Tue Sep 30 11:06:06 2008
@@ -10,3 +10,5 @@
LIBRARYNAME = N3
include $(LEVEL)/Makefile.common
+
+CXX.Flags += -I../LLVMRuntime
Modified: vmkit/branches/isolate/lib/N3/VMCore/VMCache.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/VMCache.cpp?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/VMCache.cpp (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/VMCache.cpp Tue Sep 30 11:06:06 2008
@@ -157,66 +157,3 @@
push(ret);
}
}
-
-extern "C" CacheNode* n3VirtualLookup(CacheNode* cache, VMObject *obj) {
- Enveloppe* enveloppe = cache->enveloppe;
- VMCommonClass* ocl = obj->classOf;
- VMMethod* orig = enveloppe->originalMethod;
-
- CacheNode* rcache = 0;
- CacheNode* tmp = enveloppe->firstCache;
- CacheNode* last = tmp;
- enveloppe->cacheLock->lock();
-
- while (tmp) {
- if (ocl == tmp->lastCible) {
- rcache = tmp;
- break;
- } else {
- last = tmp;
- tmp = tmp->next;
- }
- }
-
- if (!rcache) {
- VMMethod* dmeth = ocl->lookupMethodDontThrow(orig->name,
- orig->parameters,
- false, true);
- if (dmeth == 0) {
- char* methAsciiz = orig->name->UTF8ToAsciiz();
- char* nameAsciiz = orig->classDef->name->UTF8ToAsciiz();
- char* nameSpaceAsciiz = orig->classDef->nameSpace->UTF8ToAsciiz();
-
- char *buf = (char*)alloca(3 + strlen(methAsciiz) +
- strlen(nameAsciiz) +
- strlen(nameSpaceAsciiz));
- sprintf(buf, "%s.%s.%s", nameSpaceAsciiz, nameAsciiz, methAsciiz);
- const UTF8* newName = VMThread::get()->vm->asciizConstructUTF8(buf);
- dmeth = ocl->lookupMethod(newName, orig->parameters, false, true);
- }
-
- if (cache->methPtr) {
- rcache = CacheNode::allocate();
- rcache->enveloppe = enveloppe;
- } else {
- rcache = cache;
- }
-
- Function* func = dmeth->compiledPtr(NULL);
- rcache->methPtr = mvm::jit::executionEngine->getPointerToGlobal(func);
- rcache->lastCible = (VMClass*)ocl;
- rcache->box = (dmeth->classDef->super == MSCorlib::pValue);
- }
-
- if (enveloppe->firstCache != rcache) {
- CacheNode *f = enveloppe->firstCache;
- enveloppe->firstCache = rcache;
- last->next = rcache->next;
- rcache->next = f;
-
- }
-
- enveloppe->cacheLock->unlock();
-
- return rcache;
-}
Modified: vmkit/branches/isolate/lib/N3/VMCore/VMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/VMClass.cpp?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/VMClass.cpp (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/VMClass.cpp Tue Sep 30 11:06:06 2008
@@ -168,7 +168,6 @@
this->isArray = isArray;
this->isPointer = false;
this->isPrimitive = false;
- this->isDummy = false;
this->naturalType = llvm::OpaqueType::get();
}
@@ -640,38 +639,6 @@
return res;
}
-static VMObject* doMultiNewIntern(VMClassArray* cl, uint32 dim, sint32* buf) {
- if (dim <= 0) VMThread::get()->vm->error("Can't happen");
- sint32 n = buf[0];
- if (n < 0) VMThread::get()->vm->negativeArraySizeException(n);
-
- VMArray* res = (VMArray*)cl->doNew(n);
- if (dim > 1) {
- VMCommonClass* base = cl->baseClass;
- if (n > 0) {
- for (sint32 i = 0; i < n; ++i) {
- res->elements[i] = doMultiNewIntern((VMClassArray*)base, dim - 1, &(buf[1]));
- }
- }
- for (uint32 i = 1; i < dim; ++i) {
- if (buf[i] < 0) VMThread::get()->vm->negativeArraySizeException(buf[i]);
- }
- }
- return res;
-}
-
-extern "C" VMObject* doMultiNew(VMClassArray* cl, ...) {
- sint32* dimSizes = (sint32*)alloca(cl->dims * sizeof(sint32));
- va_list ap;
- va_start(ap, cl);
- for (uint32 i = 0; i < cl->dims; ++i) {
- dimSizes[i] = va_arg(ap, sint32);
- }
- va_end(ap);
- return doMultiNewIntern(cl, cl->dims, dimSizes);
-}
-
-
static void disassembleStruct(std::vector<const llvm::Type*> &args,
const llvm::Type* arg) {
const llvm::StructType* STy = llvm::dyn_cast<llvm::StructType>(arg);
@@ -832,14 +799,16 @@
std::vector<VMCommonClass*>::iterator i = parameters.begin(), a =
args.begin(), e = args.end();
+ // dummy classes for generic arguments have a NULL assembly field
// check whether both i and a point to a dummy class
- if (((*i)->isDummy && !(*a)->isDummy) || (!(*i)->isDummy && (*a)->isDummy))
+ if (((*i)->assembly == NULL && (*a)->assembly != NULL) ||
+ ((*i)->assembly != NULL && (*a)->assembly == NULL))
return false;
// dummy classes for generic arguments contain the
// argument number in the token field
// signature is only equal if the argument number matches
- if ((*i)->isDummy && (*a)->isDummy) {
+ if ((*i)->assembly == NULL && (*a)->assembly == NULL) {
if ((*i)->token != (*a)->token) {
return false;
}
@@ -856,14 +825,16 @@
}
for (; a != e; ++i, ++a) {
+ // dummy classes for generic arguments have a NULL assembly field
// check whether both i and a point to a dummy class
- if (((*i)->isDummy && !(*a)->isDummy) || (!(*i)->isDummy && (*a)->isDummy))
+ if (((*i)->assembly == NULL && (*a)->assembly != NULL) ||
+ ((*i)->assembly != NULL && (*a)->assembly == NULL))
return false;
// dummy classes for generic arguments contain the
// argument number in the token field
// signature is only equal if the argument number matches
- if ((*i)->isDummy && (*a)->isDummy) {
+ if ((*i)->assembly == NULL && (*a)->assembly == NULL) {
if ((*i)->token != (*a)->token) {
return false;
} else {
Modified: vmkit/branches/isolate/lib/N3/VMCore/VMClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/VMClass.h?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/VMClass.h (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/VMClass.h Tue Sep 30 11:06:06 2008
@@ -74,7 +74,6 @@
bool isArray;
bool isPointer;
bool isPrimitive;
- bool isDummy;
uint32 depth;
VMClassState status;
uint32 flags;
Modified: vmkit/branches/isolate/lib/N3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/N3/VMCore/VirtualTables.cpp?rev=56850&r1=56849&r2=56850&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/N3/VMCore/VirtualTables.cpp (original)
+++ vmkit/branches/isolate/lib/N3/VMCore/VirtualTables.cpp Tue Sep 30 11:06:06 2008
@@ -300,3 +300,13 @@
void Exception::TRACER {
catchClass->MARK_AND_TRACE;
}
+
+#ifdef MULTIPLE_GC
+extern "C" void CLIObjectTracer(VMObject* obj, Collector* GC) {
+#else
+extern "C" void CLIObjectTracer(VMObject* obj) {
+#endif
+ obj->classOf->MARK_AND_TRACE;
+ obj->lockObj->MARK_AND_TRACE;
+}
+
More information about the vmkit-commits
mailing list