[vmkit-commits] [vmkit] r84331 - in /vmkit/trunk: include/mvm/ lib/N3/LLVMRuntime/ lib/N3/Mono/ lib/N3/PNetLib/ lib/N3/VMCore/
Gael Thomas
gael.thomas at lip6.fr
Sat Oct 17 06:01:26 PDT 2009
Author: gthomas
Date: Sat Oct 17 08:01:15 2009
New Revision: 84331
URL: http://llvm.org/viewvc/llvm-project?rev=84331&view=rev
Log:
Define macros to construct types. All vmfield assessors are safe.
Added:
vmkit/trunk/lib/N3/VMCore/N3MetaType.h
Modified:
vmkit/trunk/include/mvm/PrintBuffer.h
vmkit/trunk/lib/N3/LLVMRuntime/runtime.ll
vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp
vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.h
vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp
vmkit/trunk/lib/N3/VMCore/MSCorlib.h
vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
vmkit/trunk/lib/N3/VMCore/VMArray.cpp
vmkit/trunk/lib/N3/VMCore/VMArray.h
vmkit/trunk/lib/N3/VMCore/VMClass.cpp
vmkit/trunk/lib/N3/VMCore/VMClass.h
vmkit/trunk/lib/N3/VMCore/VMObject.h
Modified: vmkit/trunk/include/mvm/PrintBuffer.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/PrintBuffer.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/PrintBuffer.h (original)
+++ vmkit/trunk/include/mvm/PrintBuffer.h Sat Oct 17 08:01:15 2009
@@ -103,6 +103,11 @@
}
/// writeChar - Writes a char.
+ inline PrintBuffer *writeBool(bool v) {
+ return write(v ? "true" : "false");
+ }
+
+ /// writeChar - Writes a char.
inline PrintBuffer *writeChar(char v) {
char buf[32];
sprintf(buf, "%c", v);
Modified: vmkit/trunk/lib/N3/LLVMRuntime/runtime.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/LLVMRuntime/runtime.ll?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/LLVMRuntime/runtime.ll (original)
+++ vmkit/trunk/lib/N3/LLVMRuntime/runtime.ll Sat Oct 17 08:01:15 2009
@@ -2,18 +2,21 @@
;;; Types for CLI arrays. A size of 0 means an undefined size.
%CLIArray = type { %CLIObject, i32 }
-%ArraySInt8 = type { %CLIObject, i32, [0 x i8] }
-%ArrayUInt8 = type { %CLIObject, i32, [0 x i8] }
-%ArrayChar = type { %CLIObject, i32, [0 x i16] }
-%ArraySInt16 = type { %CLIObject, i32, [0 x i16] }
-%ArrayUInt16 = type { %CLIObject, i32, [0 x i16] }
-%ArraySInt32 = type { %CLIObject, i32, [0 x i32] }
-%ArrayUInt32 = type { %CLIObject, i32, [0 x i32] }
-%ArraySInt64 = type { %CLIObject, i32, [0 x i64] }
-%ArrayUInt64 = type { %CLIObject, i32, [0 x i64] }
-%ArrayFloat = type { %CLIObject, i32, [0 x float] }
-%ArrayDouble = type { %CLIObject, i32, [0 x double] }
-%ArrayObject = type { %CLIObject, i32, [0 x %CLIObject*] }
+%ArrayBoolean = type { %CLIObject, i32, [0 x i8] }
+%ArrayUInt8 = type { %CLIObject, i32, [0 x i8] }
+%ArraySInt8 = type { %CLIObject, i32, [0 x i8] }
+%ArrayChar = type { %CLIObject, i32, [0 x i16] }
+%ArraySInt16 = type { %CLIObject, i32, [0 x i16] }
+%ArrayUInt16 = type { %CLIObject, i32, [0 x i16] }
+%ArraySInt32 = type { %CLIObject, i32, [0 x i32] }
+%ArrayUInt32 = type { %CLIObject, i32, [0 x i32] }
+%ArraySInt64 = type { %CLIObject, i32, [0 x i64] }
+%ArrayUInt64 = type { %CLIObject, i32, [0 x i64] }
+%ArrayIntPtr = type { %CLIObject, i32, [0 x i32*] }
+%ArrayUIntPtr = type { %CLIObject, i32, [0 x i32*] }
+%ArrayFloat = type { %CLIObject, i32, [0 x float] }
+%ArrayDouble = type { %CLIObject, i32, [0 x double] }
+%ArrayObject = type { %CLIObject, i32, [0 x %CLIObject*] }
%CacheNode = type {i8*, i8*, i8*, i8*, i8*, i1}
Modified: vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp (original)
+++ vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp Sat Oct 17 08:01:15 2009
@@ -151,7 +151,7 @@
declare_gcroot(VMObject*, delegatee) = ooo_delegatee;
if (!delegatee) {
ooo_delegatee = delegatee = (*MSCorlib::clrType)();
- (*MSCorlib::typeClrType)(delegatee, (VMObject*)this);
+ MSCorlib::typeClrType->setIntPtr(delegatee, (int*)this);
}
return delegatee;
}
Modified: vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp (original)
+++ vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp Sat Oct 17 08:01:15 2009
@@ -247,7 +247,7 @@
}
extern "C" VMObject* System_Reflection_ClrType_GetElementType(VMObject* Klass) {
- VMCommonClass* cl = (VMCommonClass*)((*Klass)(MSCorlib::typeClrType).PointerVal);
+ VMCommonClass* cl = (VMCommonClass*)MSCorlib::typeClrType->getIntPtr(Klass);
if (!cl->isArray) {
VMThread::get()->getVM()->error("implement me");
return 0;
@@ -628,7 +628,7 @@
uint32 v = virt ? 1 : 0;
if (types->size + v + 1 != params.size()) return false;
for (sint32 i = 0; i < types->size; ++i) {
- VMCommonClass* cur = (VMCommonClass*)(*MSCorlib::typeClrType)(types->elements[i]).PointerVal;
+ VMCommonClass* cur = (VMCommonClass*)MSCorlib::typeClrType->getIntPtr(types->elements[i]);
if (cur != params[i + 1 + v]) return false;
}
return true;
@@ -636,7 +636,7 @@
extern "C" VMObject* System_Reflection_ClrType_GetMemberImpl(VMObject* Type, PNetString* str, sint32 memberTypes, sint32 bindingFlags, VMObject* binder,
sint32 callingConventions, ArrayObject* types, VMObject* modifiers) {
- VMCommonClass* type = (VMCommonClass*)((*MSCorlib::typeClrType)(Type).PointerVal);
+ VMCommonClass* type = (VMCommonClass*)MSCorlib::typeClrType->getIntPtr(Type);
N3* vm = (N3*)(VMThread::get()->getVM());
const UTF8* name = vm->arrayToUTF8(str->value);
if (memberTypes == MEMBER_TYPES_PROPERTY) {
@@ -740,7 +740,7 @@
}
extern "C" VMObject* System_Reflection_ClrMethod_Invoke(VMObject* Method, VMObject* obj, sint32 invokeAttr, VMObject* binder, ArrayObject* args, VMObject* culture) {
- VMMethod* meth = (VMMethod*)(*MSCorlib::methodMethodType)(Method).PointerVal;
+ VMMethod* meth = (VMMethod*)MSCorlib::methodMethodType->getIntPtr(Method);
meth->getSignature(NULL);
meth->compiledPtr(NULL);
llvm::Function* func = CLIJit::compile(meth->classDef, meth);
@@ -785,51 +785,16 @@
VMObject* res = 0;
VMCommonClass* retType = meth->parameters[0];
+
+#define CONSTRUCT_RES(name, type, gv_extractor) \
+ else if(retType == MSCorlib::p##name) { \
+ res = MSCorlib::p##name->doNew(); \
+ MSCorlib::ctor##name->set##name(res, (type)gv.gv_extractor); \
+ }
+
if (retType == MSCorlib::pVoid) {
res = (*MSCorlib::pVoid)();
- } else if (retType == MSCorlib::pBoolean) {
- res = (*MSCorlib::pBoolean)();
- (*MSCorlib::ctorBoolean)(res, gv.IntVal.getBoolValue());
- } else if (retType == MSCorlib::pUInt8) {
- res = (*MSCorlib::pUInt8)();
- (*MSCorlib::ctorUInt8)(res, (uint8)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pSInt8) {
- res = (*MSCorlib::pSInt8)();
- (*MSCorlib::ctorSInt8)(res, (uint8)gv.IntVal.getSExtValue());
- } else if (retType == MSCorlib::pChar) {
- res = (*MSCorlib::pChar)();
- (*MSCorlib::ctorChar)(res, (uint16)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pSInt16) {
- res = (*MSCorlib::pSInt16)();
- (*MSCorlib::ctorSInt16)(res, (sint16)gv.IntVal.getSExtValue());
- } else if (retType == MSCorlib::pUInt16) {
- res = (*MSCorlib::pUInt16)();
- (*MSCorlib::ctorUInt16)(res, (uint16)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pSInt32) {
- res = (*MSCorlib::pSInt32)();
- (*MSCorlib::ctorSInt32)(res, (sint32)gv.IntVal.getSExtValue());
- } else if (retType == MSCorlib::pUInt32) {
- res = (*MSCorlib::pUInt32)();
- (*MSCorlib::ctorUInt32)(res, (sint32)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pSInt64) {
- res = (*MSCorlib::pSInt64)();
- (*MSCorlib::ctorSInt64)(res, (sint64)gv.IntVal.getSExtValue());
- } else if (retType == MSCorlib::pUInt64) {
- res = (*MSCorlib::pUInt64)();
- (*MSCorlib::ctorUInt64)(res, (sint64)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pIntPtr) {
- res = (*MSCorlib::pIntPtr)();
- (*MSCorlib::ctorIntPtr)(res, (void*)gv.IntVal.getSExtValue());
- } else if (retType == MSCorlib::pUIntPtr) {
- res = (*MSCorlib::pUIntPtr)();
- (*MSCorlib::ctorUIntPtr)(res, (void*)gv.IntVal.getZExtValue());
- } else if (retType == MSCorlib::pFloat) {
- res = (*MSCorlib::pFloat)();
- (*MSCorlib::ctorFloat)(res, gv.FloatVal);
- } else if (retType == MSCorlib::pDouble) {
- res = (*MSCorlib::pDouble)();
- (*MSCorlib::ctorDouble)(res, gv.DoubleVal);
- } else {
+ } ON_PRIMITIVES(CONSTRUCT_RES, _F_NTE) else {
if (retType->super == MSCorlib::pValue || retType->super == MSCorlib::pEnum)
VMThread::get()->getVM()->error("implement me");
res = (VMObject*)gv.PointerVal;
@@ -881,7 +846,7 @@
}
extern "C" VMObject* System_Reflection_Assembly_GetManifestResourceStream(VMObject* Ass, PNetString* str) {
- Assembly* ass = (Assembly*)(*MSCorlib::assemblyAssemblyReflection)(Ass).PointerVal;
+ Assembly* ass = (Assembly*)MSCorlib::assemblyAssemblyReflection->getIntPtr(Ass);
N3* vm = (N3*)(VMThread::get()->getVM());
const UTF8* id = vm->arrayToUTF8(str->value);
Header* header = ass->CLIHeader;
Modified: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp (original)
+++ vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp Sat Oct 17 08:01:15 2009
@@ -135,7 +135,7 @@
if (!delegatee) {
delegatee = (*MSCorlib::propertyType)();
(*MSCorlib::ctorPropertyType)(delegatee);
- (*MSCorlib::propertyPropertyType)(delegatee, (VMObject*)this);
+ MSCorlib::propertyPropertyType->setIntPtr(delegatee, (int*)this);
}
return delegatee;
}
@@ -144,7 +144,7 @@
if (!delegatee) {
delegatee = (*MSCorlib::methodType)();
(*MSCorlib::ctorMethodType)(delegatee);
- (*MSCorlib::methodMethodType)(delegatee, (VMObject*)this);
+ MSCorlib::methodMethodType->setIntPtr(delegatee, (int*)this);
}
return delegatee;
}
@@ -155,7 +155,7 @@
if (!delegatee) {
ooo_delegatee = delegatee = (*MSCorlib::clrType)();
(*MSCorlib::ctorClrType)(delegatee);
- (*MSCorlib::typeClrType)(delegatee, (VMObject*)this);
+ MSCorlib::typeClrType->setIntPtr(delegatee, (int*)this);
}
return delegatee;
}
@@ -166,7 +166,7 @@
if (!delegatee) {
ooo_delegatee = delegatee = (*MSCorlib::assemblyReflection)();
(*MSCorlib::ctorAssemblyReflection)(delegatee);
- (*MSCorlib::assemblyAssemblyReflection)(delegatee, (VMObject*)this);
+ MSCorlib::assemblyAssemblyReflection->setIntPtr(delegatee, (int*)this);
}
return delegatee;
}
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Oct 17 08:01:15 2009
@@ -1293,7 +1293,7 @@
args.push_back(llvm::GenericValue(obj));
readCustomAttributes(blobOffset + attrArray[CONSTANT_CUSTOM_ATTRIBUTE_VALUE], args, cons);
- (*cons)(args);
+ cons->compileToNative()->invokeGeneric(args);
vec.push_back(obj);
}
}
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sat Oct 17 08:01:15 2009
@@ -39,7 +39,6 @@
using mvm::UTF8Map;
class ArrayChar;
-class ArrayUInt8;
class ArrayObject;
class Assembly;
class ClassNameMap;
Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Oct 17 08:01:15 2009
@@ -21,6 +21,7 @@
#include "VMCache.h"
#include "VMClass.h"
#include "VMThread.h"
+#include "N3MetaType.h"
#include <llvm/CallingConv.h>
#include <llvm/Constants.h>
@@ -239,12 +240,12 @@
cl->virtualTracer = func;
#endif
-#define CASE_ARRAY(name, elmt, nbb, printer, pre, sep, post) \
+#define CASE_ARRAY(name, type) \
if(cl->baseClass == MSCorlib::p##name) { \
((void**)res)[VT_PRINT_OFFSET] = ((void **)(unsigned int)Array##name::do_print); \
} else
- ON_ARRAY_CLASSES(CASE_ARRAY) {}
+ ON_TYPES(CASE_ARRAY, _F_NT) {}
#undef CASE_ARRAY
@@ -1563,10 +1564,12 @@
Enveloppe::llvmType =
PointerType::getUnqual(module->getTypeByName("Enveloppe"));
-#define GET_LLVM_ARRAY_TYPE(name, elmt, nbb, printer, pre, sep, post) \
+#define GET_LLVM_ARRAY_TYPE(name, type) \
Array##name::llvmType = \
- PointerType::getUnqual(module->getTypeByName("Array"#name));
- ON_ARRAY_CLASSES(GET_LLVM_ARRAY_TYPE)
+ PointerType::getUnqual(module->getTypeByName("Array"#name)); \
+
+ ON_TYPES(GET_LLVM_ARRAY_TYPE, _F_NT)
+
#undef GET_LLVM_ARRAY_TYPE
#ifdef WITH_TRACER
Modified: vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp Sat Oct 17 08:01:15 2009
@@ -33,163 +33,113 @@
return doNew();
}
-void VMField::operator()(VMObject* obj, float val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (signature->naturalType == Type::getFloatTy(getGlobalContext())) {
- ((float*)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
-
- return;
-}
-
-void VMField::operator()(VMObject* obj, double val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (signature->naturalType == Type::getDoubleTy(getGlobalContext())) {
- ((double*)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
-
- return;
-}
-
-void VMField::operator()(VMObject* obj, sint64 val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (signature->naturalType == Type::getInt64Ty(getGlobalContext())) {
- ((uint64*)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
-
- return;
-}
-
-void VMField::operator()(VMObject* obj, sint32 val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (signature->naturalType == Type::getInt32Ty(getGlobalContext())) {
- ((uint32*)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
-
- return;
-}
-
-void VMField::operator()(VMObject* obj, VMObject* val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (llvm::isa<PointerType>(signature->naturalType)) {
- ((VMObject**)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
+// TODO: MUST CHECK the type!
+// if (llvm::isa<check>(signature->naturalType)) {
+// if (signature->naturalType == Type::getFloatTy(getGlobalContext())) {
+
+#define IMPLEMENTS_VMFIELD_ASSESSORS(name, type, do_root) \
+ void VMField::set##name(VMObject* obj, type val) { \
+ llvm_gcroot(obj, 0); \
+ do_root(val, 0); \
+ \
+ if (classDef->status < ready) \
+ classDef->resolveType(true, true, NULL); \
+ \
+ *(type*)((char *)obj + ptrOffset) = val; \
+ \
+ return; \
+ } \
+ \
+ type VMField::get##name(VMObject* obj) { \
+ llvm_gcroot(obj, 0); \
+ if (classDef->status < ready) \
+ classDef->resolveType(true, true, NULL); \
+ \
+ type res; \
+ do_root(res, 0); \
+ res = *(type *)((char *)obj + ptrOffset); \
+ return res; \
+ }
+
+ON_TYPES(IMPLEMENTS_VMFIELD_ASSESSORS, _F_NTR)
+
+#undef IMPLEMENTS_VMFIELD_ASSESSORS
+
+GenericValue VMMethod::invokeGeneric(std::vector<llvm::GenericValue>& args) {
+ assert(code);
+ return mvm::MvmModule::executionEngine->runFunction(methPtr, args);
+}
+
+GenericValue VMMethod::invokeGeneric(va_list ap) {
+ assert(code);
+
+ Function* func = methPtr;
+ std::vector<GenericValue> args;
+ for (Function::arg_iterator i = func->arg_begin(), e = func->arg_end();
+ i != e; ++i) {
+ const Type* cur = i->getType();
+ if (cur == Type::getInt8Ty(getGlobalContext())) {
+ GenericValue gv;
+ gv.IntVal = APInt(8, va_arg(ap, int));
+ args.push_back(gv);
+ } else if (cur == Type::getInt16Ty(getGlobalContext())) {
+ GenericValue gv;
+ gv.IntVal = APInt(16, va_arg(ap, int));
+ args.push_back(gv);
+ } else if (cur == Type::getInt32Ty(getGlobalContext())) {
+ GenericValue gv;
+ gv.IntVal = APInt(32, va_arg(ap, int));
+ args.push_back(gv);
+ } else if (cur == Type::getInt64Ty(getGlobalContext())) {
+ GenericValue gv1;
+ gv1.IntVal = APInt(64, va_arg(ap, uint64));
+ args.push_back(gv1);
+ } else if (cur == Type::getDoubleTy(getGlobalContext())) {
+ GenericValue gv1;
+ gv1.DoubleVal = va_arg(ap, double);
+ args.push_back(gv1);
+ } else if (cur == Type::getFloatTy(getGlobalContext())) {
+ GenericValue gv;
+ gv.FloatVal = (float)(va_arg(ap, double));
+ args.push_back(gv);
+ } else {
+ GenericValue gv(va_arg(ap, VMObject*));
+ args.push_back(gv);
+ }
+ }
+
+ return invokeGeneric(args);
+}
+
+
+#define DEFINE_INVOKE(name, type, extractor) \
+ type VMMethod::invoke##name(...) { \
+ va_list ap; \
+ va_start(ap, this); \
+ GenericValue res = invokeGeneric(ap); \
+ va_end(ap); \
+ return (type)res.extractor; \
+ }
+
+ON_TYPES(DEFINE_INVOKE, _F_NTE)
+
+#undef DEFINE_INVOKE
+
+#define DEFINE_INVOKE_VOID(name, type, extractor) \
+ type VMMethod::invoke##name(...) { \
+ va_list ap; \
+ va_start(ap, this); \
+ invokeGeneric(ap); \
+ va_end(ap); \
+ }
- return;
-}
-void VMField::operator()(VMObject* obj, bool val) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) obj = classDef->staticInstance;
- void* ptr = (void*)((uint64)obj + ptrOffset);
-
- if (signature->naturalType == Type::getInt1Ty(getGlobalContext())) {
- ((bool*)ptr)[0] = val;
- } else {
- VMThread::get()->getVM()->unknownError("wrong type in field assignment");
- }
+ON_VOID(DEFINE_INVOKE_VOID, _F_NTE)
- return;
-}
+#undef DEFINE_INVOKE_VOID
-GenericValue VMField::operator()(VMObject* obj) {
-
- if (classDef->status < ready)
- classDef->resolveType(true, true, NULL);
-
- bool stat = isStatic(flags);
- if (stat) {
- if (obj != 0) {
- // Assignment to a static var
- void* ptr = (void*)((uint64)(classDef->staticInstance) + ptrOffset);
- ((VMObject**)ptr)[0] = obj;
- return GenericValue(0);
- } else {
- // Get a static var
- obj = classDef->staticInstance;
- }
- }
-
- void* ptr = (void*)((uint64)obj + ptrOffset);
- const Type* type = signature->naturalType;
- if (type == Type::getInt8Ty(getGlobalContext())) {
- GenericValue gv;
- gv.IntVal = APInt(8, ((uint8*)ptr)[0]);
- return gv;
- } else if (type == Type::getInt16Ty(getGlobalContext())) {
- GenericValue gv;
- gv.IntVal = APInt(16, ((uint16*)ptr)[0]);
- return gv;
- } else if (type == Type::getInt32Ty(getGlobalContext())) {
- GenericValue gv;
- gv.IntVal = APInt(32, ((uint32*)ptr)[0]);
- return gv;
- } else if (type == Type::getInt64Ty(getGlobalContext())) {
- GenericValue gv;
- gv.IntVal = APInt(64, ((uint64*)ptr)[0]);
- return gv;
- } else if (type == Type::getDoubleTy(getGlobalContext())) {
- GenericValue gv;
- gv.DoubleVal = ((double*)ptr)[0];
- return gv;
- } else if (type == Type::getFloatTy(getGlobalContext())) {
- GenericValue gv;
- gv.FloatVal = ((float*)ptr)[0];
- return gv;
- } else {
- GenericValue gv(((VMObject**)ptr)[0]);
- return gv;
- }
-}
+// mettre en param un Function *
+// materializeFunction avant
GenericValue VMMethod::operator()(va_list ap) {
if (classDef->status < ready)
@@ -307,59 +257,6 @@
return mvm::MvmModule::executionEngine->runFunction(func, args);
}
-GenericValue VMObject::operator()(VMField* field) {
- return (*field)(this);
-}
-
-void VMObject::operator()(VMField* field, float val) {
- return (*field)(this, val);
-}
-
-void VMObject::operator()(VMField* field, double val) {
- return (*field)(this, val);
-}
-
-void VMObject::operator()(VMField* field, sint32 val) {
- return (*field)(this, val);
-}
-
-void VMObject::operator()(VMField* field, sint64 val) {
- return (*field)(this, val);
-}
-
-void VMObject::operator()(VMField* field, VMObject* val) {
- return (*field)(this, val);
-}
-
-void VMObject::operator()(VMField* field, bool val) {
- return (*field)(this, val);
-}
-
-void VMField::operator()(float val) {
- VMField * field = this;
- return (*field)(classDef->virtualInstance, val);
-}
-
-void VMField::operator()(double val) {
- VMField * field = this;
- return (*field)(classDef->virtualInstance, val);
-}
-
-void VMField::operator()(sint64 val) {
- VMField * field = this;
- return (*field)(classDef->virtualInstance, val);
-}
-
-void VMField::operator()(sint32 val) {
- VMField * field = this;
- return (*field)(classDef->virtualInstance, val);
-}
-
-void VMField::operator()(bool val) {
- VMField * field = this;
- return (*field)(classDef->virtualInstance, val);
-}
-
GlobalVariable* VMCommonClass::llvmVar() {
if (!_llvmVar) {
aquire();
Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/MSCorlib.h (original)
+++ vmkit/trunk/lib/N3/VMCore/MSCorlib.h Sat Oct 17 08:01:15 2009
@@ -10,6 +10,8 @@
#ifndef N3_MSCORLIB_H
#define N3_MSCORLIB_H
+#include "N3MetaType.h"
+
namespace n3 {
class N3;
@@ -44,47 +46,27 @@
static VMClass* resourceStreamType;
static VMMethod* ctorResourceStreamType;
+
+#define DEF_TYPE(name, type) \
+ static VMClass* p##name;
+
+#define DEF_ARRAY_AND_TYPE(name, type) \
+ DEF_TYPE(name, type) \
+ static VMClassArray* array##name; \
+ static VMField* ctor##name;
+
+ ON_TYPES(DEF_ARRAY_AND_TYPE, _F_NT)
+ ON_STRING(DEF_ARRAY_AND_TYPE, _F_NT)
+ ON_VOID(DEF_TYPE, _F_NT)
+
+#undef DEF_ARRAY_AND_TYPE
+#undef DEF_TYPE
- static VMClass* pVoid;
- static VMClass* pBoolean;
- static VMClass* pChar;
- static VMClass* pSInt8;
- static VMClass* pUInt8;
- static VMClass* pSInt16;
- static VMClass* pUInt16;
- static VMClass* pSInt32;
- static VMClass* pUInt32;
- static VMClass* pSInt64;
- static VMClass* pUInt64;
- static VMClass* pFloat;
- static VMClass* pDouble;
- static VMClass* pIntPtr;
- static VMClass* pUIntPtr;
- static VMClass* pString;
- static VMClass* pObject;
static VMClass* pValue;
static VMClass* pEnum;
static VMClass* pArray;
static VMClass* pDelegate;
static VMClass* pException;
- static VMClassArray* arrayChar;
- static VMClassArray* arrayString;
- static VMClassArray* arrayByte;
- static VMClassArray* arrayObject;
- static VMField* ctorBoolean;
- static VMField* ctorUInt8;
- static VMField* ctorSInt8;
- static VMField* ctorChar;
- static VMField* ctorSInt16;
- static VMField* ctorUInt16;
- static VMField* ctorSInt32;
- static VMField* ctorUInt32;
- static VMField* ctorSInt64;
- static VMField* ctorUInt64;
- static VMField* ctorIntPtr;
- static VMField* ctorUIntPtr;
- static VMField* ctorDouble;
- static VMField* ctorFloat;
};
} // end namespace n3
Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Sat Oct 17 08:01:15 2009
@@ -34,70 +34,61 @@
N3* N3::bootstrapVM = 0;
mvm::Lock* VMObject::globalLock = 0;
-VMCommonClass* VMClassArray::SuperArray = 0;
-std::vector<VMClass*> VMClassArray::InterfacesArray;
+VMCommonClass* VMClassArray::SuperArray = 0;
+std::vector<VMClass*> VMClassArray::InterfacesArray;
std::vector<VMMethod*> VMClassArray::VirtualMethodsArray;
std::vector<VMMethod*> VMClassArray::StaticMethodsArray;
-std::vector<VMField*> VMClassArray::VirtualFieldsArray;
-std::vector<VMField*> VMClassArray::StaticFieldsArray;
+std::vector<VMField*> VMClassArray::VirtualFieldsArray;
+std::vector<VMField*> VMClassArray::StaticFieldsArray;
+
+#define DEF_TYPE(name, type) \
+ VMClass *MSCorlib::p##name = 0;
+
+#define DEF_ARRAY_LLVM_TYPE(name, type) \
+ const llvm::Type* Array##name::llvmType = 0;
+
+#define DEF_ARRAY_AND_TYPE(name, type) \
+ DEF_TYPE(name, type) \
+ VMClassArray *MSCorlib::array##name = 0; \
+ VMField* MSCorlib::ctor##name = 0;
+
+ON_TYPES(DEF_ARRAY_AND_TYPE, _F_NT)
+ON_TYPES(DEF_ARRAY_LLVM_TYPE, _F_NT)
+ON_STRING(DEF_ARRAY_AND_TYPE, _F_NT)
+ON_VOID(DEF_TYPE, _F_NT)
+
+#undef DEF_ARRAY_LLVM_TYPE
+#undef DEF_TYPE
+#undef DEF_ARRAY_AND_TYPE
-VMClass* MSCorlib::pVoid = 0;
-VMClass* MSCorlib::pBoolean= 0;
-VMClass* MSCorlib::pChar = 0;
-VMClass* MSCorlib::pSInt8 = 0;
-VMClass* MSCorlib::pUInt8 = 0;
-VMClass* MSCorlib::pSInt16 = 0;
-VMClass* MSCorlib::pUInt16 = 0;
-VMClass* MSCorlib::pSInt32 = 0;
-VMClass* MSCorlib::pUInt32 = 0;
-VMClass* MSCorlib::pSInt64 = 0;
-VMClass* MSCorlib::pUInt64 = 0;
-VMClass* MSCorlib::pFloat = 0;
-VMClass* MSCorlib::pDouble = 0;
-VMClass* MSCorlib::pIntPtr = 0;
-VMClass* MSCorlib::pUIntPtr = 0;
-VMClass* MSCorlib::pObject = 0;
-VMClass* MSCorlib::pString = 0;
VMClass* MSCorlib::pValue = 0;
VMClass* MSCorlib::pEnum = 0;
VMClass* MSCorlib::pArray = 0;
VMClass* MSCorlib::pDelegate = 0;
VMClass* MSCorlib::pException = 0;
-VMClassArray* MSCorlib::arrayChar = 0;
-VMClassArray* MSCorlib::arrayString = 0;
-VMClassArray* MSCorlib::arrayObject = 0;
-VMClassArray* MSCorlib::arrayByte = 0;
+
+
+const llvm::Type* VMArray::llvmType;
+const llvm::Type* VMObject::llvmType;
+const llvm::Type* Enveloppe::llvmType;
+const llvm::Type* CacheNode::llvmType;
+
VMMethod* MSCorlib::ctorPropertyType;
VMMethod* MSCorlib::ctorMethodType;
VMMethod* MSCorlib::ctorClrType;
-VMClass* MSCorlib::clrType;
-VMField* MSCorlib::typeClrType;
-VMField* MSCorlib::propertyPropertyType;
-VMField* MSCorlib::methodMethodType;
+VMClass* MSCorlib::clrType;
+VMField* MSCorlib::typeClrType;
+VMField* MSCorlib::propertyPropertyType;
+VMField* MSCorlib::methodMethodType;
VMMethod* MSCorlib::ctorAssemblyReflection;
-VMClass* MSCorlib::assemblyReflection;
-VMClass* MSCorlib::typedReference;
-VMField* MSCorlib::assemblyAssemblyReflection;
-VMClass* MSCorlib::propertyType;
-VMClass* MSCorlib::methodType;
-VMClass* MSCorlib::resourceStreamType;
+VMClass* MSCorlib::assemblyReflection;
+VMClass* MSCorlib::typedReference;
+VMField* MSCorlib::assemblyAssemblyReflection;
+VMClass* MSCorlib::propertyType;
+VMClass* MSCorlib::methodType;
+VMClass* MSCorlib::resourceStreamType;
VMMethod* MSCorlib::ctorResourceStreamType;
-VMField* MSCorlib::ctorBoolean;
-VMField* MSCorlib::ctorUInt8;
-VMField* MSCorlib::ctorSInt8;
-VMField* MSCorlib::ctorChar;
-VMField* MSCorlib::ctorSInt16;
-VMField* MSCorlib::ctorUInt16;
-VMField* MSCorlib::ctorSInt32;
-VMField* MSCorlib::ctorUInt32;
-VMField* MSCorlib::ctorSInt64;
-VMField* MSCorlib::ctorUInt64;
-VMField* MSCorlib::ctorIntPtr;
-VMField* MSCorlib::ctorUIntPtr;
-VMField* MSCorlib::ctorDouble;
-VMField* MSCorlib::ctorFloat;
-
const UTF8* N3::clinitName = 0;
const UTF8* N3::ctorName = 0;
const UTF8* N3::invokeName = 0;
@@ -116,11 +107,6 @@
const UTF8* N3::doubleName = 0;
const UTF8* N3::testInfinity = 0;
-const llvm::Type* VMArray::llvmType;
-const llvm::Type* VMObject::llvmType;
-const llvm::Type* Enveloppe::llvmType;
-const llvm::Type* CacheNode::llvmType;
-
llvm::Function* CLIJit::printExecutionLLVM;
llvm::Function* CLIJit::indexOutOfBoundsExceptionLLVM;
llvm::Function* CLIJit::nullPointerExceptionLLVM;
@@ -146,13 +132,6 @@
llvm::Function* CLIJit::getCppExceptionLLVM;
llvm::Function* CLIJit::newStringLLVM;
-#define DEFINE_ARRAY_LLVM_TYPE(name, elmt, size, printer, pre, sep, post) \
- const llvm::Type* Array##name::llvmType = 0;
-
-ON_ARRAY_CLASSES(DEFINE_ARRAY_LLVM_TYPE)
-
-#undef DEFINE_ARRAY_LLVM_TYPE
-
static void initialiseVT() {
}
@@ -187,27 +166,29 @@
var->virtualType = type; \
}}
- INIT(MSCorlib::pObject, "System", "Object", VMObject::llvmType, false);
+ assert(VMObject::llvmType);
+
+ INIT(MSCorlib::pObject, "System", "Object", VMObject::llvmType, false);
INIT(MSCorlib::pValue, "System", "ValueType", 0, false);
- INIT(MSCorlib::pVoid, "System", "Void", llvm::Type::getVoidTy(getGlobalContext()), true);
- INIT(MSCorlib::pBoolean, "System", "Boolean", llvm::Type::getInt1Ty(getGlobalContext()), true);
- INIT(MSCorlib::pUInt8, "System", "Byte", llvm::Type::getInt8Ty(getGlobalContext()), true);
- INIT(MSCorlib::pSInt8, "System", "SByte", llvm::Type::getInt8Ty(getGlobalContext()), true);
- INIT(MSCorlib::pChar, "System", "Char", llvm::Type::getInt16Ty(getGlobalContext()), true);
- INIT(MSCorlib::pSInt16, "System", "Int16", llvm::Type::getInt16Ty(getGlobalContext()), true);
- INIT(MSCorlib::pUInt16, "System", "UInt16", llvm::Type::getInt16Ty(getGlobalContext()), true);
- INIT(MSCorlib::pSInt32, "System", "Int32", llvm::Type::getInt32Ty(getGlobalContext()), true);
- INIT(MSCorlib::pUInt32, "System", "UInt32", llvm::Type::getInt32Ty(getGlobalContext()), true);
- INIT(MSCorlib::pSInt64, "System", "Int64", llvm::Type::getInt64Ty(getGlobalContext()), true);
- INIT(MSCorlib::pUInt64, "System", "UInt64", llvm::Type::getInt64Ty(getGlobalContext()), true);
- INIT(MSCorlib::pIntPtr, "System", "IntPtr", llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getGlobalContext())), true);
- INIT(MSCorlib::pUIntPtr, "System", "UIntPtr", llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getGlobalContext())), true);
- INIT(MSCorlib::pDouble, "System", "Double", llvm::Type::getDoubleTy(getGlobalContext()), true);
- INIT(MSCorlib::pFloat, "System", "Single", llvm::Type::getFloatTy(getGlobalContext()), true);
- INIT(MSCorlib::pEnum, "System", "Enum", llvm::Type::getInt32Ty(getGlobalContext()), true);
- INIT(MSCorlib::pArray, "System", "Array", 0, true);
+ INIT(MSCorlib::pVoid, "System", "Void", llvm::Type::getVoidTy(getGlobalContext()), true);
+ INIT(MSCorlib::pBoolean, "System", "Boolean", llvm::Type::getInt1Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pUInt8, "System", "Byte", llvm::Type::getInt8Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pSInt8, "System", "SByte", llvm::Type::getInt8Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pChar, "System", "Char", llvm::Type::getInt16Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pSInt16, "System", "Int16", llvm::Type::getInt16Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pUInt16, "System", "UInt16", llvm::Type::getInt16Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pSInt32, "System", "Int32", llvm::Type::getInt32Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pUInt32, "System", "UInt32", llvm::Type::getInt32Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pSInt64, "System", "Int64", llvm::Type::getInt64Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pUInt64, "System", "UInt64", llvm::Type::getInt64Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pIntPtr, "System", "IntPtr", llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getGlobalContext())), true);
+ INIT(MSCorlib::pUIntPtr, "System", "UIntPtr", llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getGlobalContext())), true);
+ INIT(MSCorlib::pDouble, "System", "Double", llvm::Type::getDoubleTy(getGlobalContext()), true);
+ INIT(MSCorlib::pFloat, "System", "Single", llvm::Type::getFloatTy(getGlobalContext()), true);
+ INIT(MSCorlib::pEnum, "System", "Enum", llvm::Type::getInt32Ty(getGlobalContext()), true);
+ INIT(MSCorlib::pArray, "System", "Array", 0, true);
INIT(MSCorlib::pException,"System", "Exception", 0, false);
- INIT(MSCorlib::pDelegate, "System", "Delegate", 0, false);
+ INIT(MSCorlib::pDelegate, "System", "Delegate", 0, false);
#undef INIT
@@ -215,10 +196,11 @@
MSCorlib::loadStringClass(vm);
- MSCorlib::arrayChar = ass->constructArray(MSCorlib::pChar, 1);
- MSCorlib::arrayString = ass->constructArray(MSCorlib::pString, 1);
- MSCorlib::arrayByte = ass->constructArray(MSCorlib::pUInt8, 1);
- MSCorlib::arrayObject = ass->constructArray(MSCorlib::pObject, 1);
+#define BUILD_ARRAY(name, type) \
+ MSCorlib::array##name = ass->constructArray(MSCorlib::p##name, 1);
+
+ ON_TYPES(BUILD_ARRAY, _F_NT);
+ ON_STRING(BUILD_ARRAY, _F_NT);
N3::clinitName = vm->asciizToUTF8(".cctor");
N3::ctorName = vm->asciizToUTF8(".ctor");
Added: vmkit/trunk/lib/N3/VMCore/N3MetaType.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3MetaType.h?rev=84331&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3MetaType.h (added)
+++ vmkit/trunk/lib/N3/VMCore/N3MetaType.h Sat Oct 17 08:01:15 2009
@@ -0,0 +1,44 @@
+#ifndef _N3_META_TYPE_H_
+#define _N3_META_TYPE_H_
+
+#define do_nothing(obj, val)
+
+#define _APP(A, B) A(B)
+
+#define ON_PRIMITIVES(_, _F) \
+ _APP(_, _F(Boolean, bool, IntVal.getBoolValue(), do_nothing, writeBool, "Array<", " ", ">")) \
+ _APP(_, _F(UInt8, uint8, IntVal.getZExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(SInt8, sint8, IntVal.getSExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(Char, uint16, IntVal.getZExtValue(), do_nothing, writeChar, "", "", "")) \
+ _APP(_, _F(UInt16, uint16, IntVal.getZExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(SInt16, sint16, IntVal.getSExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(UInt32, uint32, IntVal.getZExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(SInt32, sint32, IntVal.getSExtValue(), do_nothing, writeS4, "Array<", " ", ">")) \
+ _APP(_, _F(UInt64, uint64, IntVal.getZExtValue(), do_nothing, writeS8, "Array<", " ", ">")) \
+ _APP(_, _F(SInt64, sint64, IntVal.getSExtValue(), do_nothing, writeS8, "Array<", " ", ">")) \
+ _APP(_, _F(UIntPtr, uint*, PointerVal, do_nothing, writePtr, "Array<", " ", ">")) \
+ _APP(_, _F(IntPtr, int*, PointerVal, do_nothing, writePtr, "Array<", " ", ">")) \
+ _APP(_, _F(Float, float, FloatVal, do_nothing, writeFP, "Array<", " ", ">")) \
+ _APP(_, _F(Double, double, DoubleVal, do_nothing, writeFP, "Array<", " ", ">"))
+
+#define ON_VOID(_, _F) \
+ _APP(_, _F(Void, void, abort(), do_nothing, abort(), "", "", ""))
+
+#define ON_OBJECT(_, _F) \
+ _APP(_, _F(Object, VMObject*, PointerVal, llvm_gcroot, writeObj, "Array<", " ", ">"))
+
+#define ON_STRING(_, _F) \
+ _APP(_, _F(String, uint16*, PointerVal, llvm_gcroot, writeObj, "", "", ""))
+
+#define ON_TYPES(_, _F) \
+ ON_PRIMITIVES(_, _F) \
+ ON_OBJECT(_, _F)
+
+#define _F_NT( name, type, gv_extractor, do_root, writer, pre, sep, post) name, type
+#define _F_NTR( name, type, gv_extractor, do_root, writer, pre, sep, post) name, type, do_root
+#define _F_NTE( name, type, gv_extractor, do_root, writer, pre, sep, post) name, type, gv_extractor
+#define _F_NTRW(name, type, gv_extractor, do_root, writer, pre, sep, post) name, type, do_root, writer, pre, sep, post
+#define _F_ALL( name, type, gv_extractor, do_root, writer, pre, sep, post) name, type, gv_extractor, writer, do_root, pre, sep, post
+
+
+#endif
Modified: vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp Sat Oct 17 08:01:15 2009
@@ -26,26 +26,12 @@
bool N3ModuleProvider::materializeFunction(Function *F, std::string *ErrInfo) {
if (!F->empty()) return false;
VMMethod* meth = functions->lookup(F);
+
if (!meth) {
// VT methods
return false;
} else {
- void* res =
- mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(meth->methPtr);
- if (res == 0) {
- meth->classDef->aquire();
- res =
- mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(meth->methPtr);
- if (res == 0) {
- CLIJit::compile(meth->classDef, meth);
- void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(meth->methPtr);
- meth->code = res;
- N3* vm = VMThread::get()->getVM();
- vm->addMethodInFunctionMap(meth, res);
- }
- meth->classDef->release();
- meth->classDef->resolveStatic(true, NULL);
- }
+ meth->compileToNative();
return false;
}
}
Modified: vmkit/trunk/lib/N3/VMCore/VMArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMArray.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMArray.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMArray.cpp Sat Oct 17 08:01:15 2009
@@ -20,30 +20,21 @@
const sint32 VMArray::MaxArraySize = 268435455;
-#define DEFINE_ARRAY_PRINT(name, elmt, nbb, printer, pre, sep, post) \
+#define DEFINE_ARRAY_PRINT(name, type, do_root, printer, pre, sep, post) \
void Array##name::do_print(const Array##name *self, mvm::PrintBuffer *buf) { \
llvm_gcroot(self, 0); \
buf->write(pre); \
for(int i=0; i<self->size; i++) { \
if(i) \
buf->write(sep); \
- buf->printer(self->elements[i]); \
+ type cur; \
+ do_root(cur, 0); \
+ cur = self->elements[i]; \
+ buf->printer(cur); \
} \
buf->write(post); \
}
-ON_ARRAY_PRIMITIVE_CLASSES(DEFINE_ARRAY_PRINT)
-
-void ArrayObject::do_print(const ArrayObject *self, mvm::PrintBuffer *buf) {
- llvm_gcroot(self, 0);
- buf->write("Array<");
- for(int i=0; i<self->size; i++) {
- if(i)
- buf->write(" ");
- declare_gcroot(VMObject*, cur) = self->elements[i];
- buf->writeObj(cur);
- }
- buf->write(">");
-}
+ON_TYPES(DEFINE_ARRAY_PRINT, _F_NTRW)
#undef DEFINE_ARRAY_PRINT
Modified: vmkit/trunk/lib/N3/VMCore/VMArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMArray.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMArray.h (original)
+++ vmkit/trunk/lib/N3/VMCore/VMArray.h Sat Oct 17 08:01:15 2009
@@ -41,36 +41,18 @@
static llvm::Constant* elementsOffset();
};
-#define ON_ARRAY_PRIMITIVE_CLASSES(_) \
- _(UInt8, uint8, 1, writeS4, "Array<", " ", ">") \
- _(SInt8, sint8, 1, writeS4, "Array<", " ", ">") \
- _(Char, uint16, 2, writeChar, "", "", "") \
- _(UInt16, uint16, 2, writeS4, "Array<", " ", ">") \
- _(SInt16, sint16, 2, writeS4, "Array<", " ", ">") \
- _(UInt32, uint32, 4, writeS4, "Array<", " ", ">") \
- _(SInt32, sint32, 4, writeS4, "Array<", " ", ">") \
- _(UInt64, uint64, 8, writeS8, "Array<", " ", ">") \
- _(SInt64, sint64, 8, writeS8, "Array<", " ", ">") \
- _(Float, float, 4, writeFP, "Array<", " ", ">") \
- _(Double, double, 8, writeFP, "Array<", " ", ">")
-
-#define ON_ARRAY_CLASSES(_) \
- ON_ARRAY_PRIMITIVE_CLASSES(_) \
- _(Object, VMObject*, 4, writeObj, "Array<", " ", ">")
-
-
// never allocate a VMArray, it is just a C++ type to access N3 object
-#define DEFINE_ARRAY_CLASS(name, elmt, nbb, printer, pre, sep, post) \
+#define DEFINE_ARRAY_CLASS(name, type) \
class Array##name : public VMObject { \
void *operator new(size_t n) { return VMObject::operator new(n, 0); } \
public: \
static const llvm::Type* llvmType; \
sint32 size; \
- elmt elements[1]; \
+ type elements[1]; \
static void do_print(const Array##name *self, mvm::PrintBuffer* buf); \
};
-ON_ARRAY_CLASSES(DEFINE_ARRAY_CLASS)
+ON_TYPES(DEFINE_ARRAY_CLASS, _F_NT)
#undef DEFINE_ARRAY_CLASS
Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Sat Oct 17 08:01:15 2009
@@ -790,6 +790,31 @@
}
}
+VMMethod *VMMethod::compileToNative(VMGenericMethod* genMethod) {
+ if(!code) {
+ if (classDef->status < ready)
+ classDef->resolveType(true, true, NULL);
+
+ llvm::Function *methPtr = compiledPtr(genMethod);
+ void* res =
+ mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(methPtr);
+ if (res == 0) {
+ classDef->aquire();
+ res =
+ mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(methPtr);
+ if (res == 0) {
+ CLIJit::compile(classDef, this);
+ void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(methPtr);
+ code = res;
+ N3* vm = VMThread::get()->getVM();
+ vm->addMethodInFunctionMap(this, res);
+ }
+ classDef->release();
+ classDef->resolveStatic(true, NULL);
+ }
+ }
+ return this;
+}
bool VMMethod::signatureEquals(std::vector<VMCommonClass*>& args) {
bool stat = isStatic(flags);
Modified: vmkit/trunk/lib/N3/VMCore/VMClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.h (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.h Sat Oct 17 08:01:15 2009
@@ -21,6 +21,8 @@
#include "llvm/Function.h"
#include "llvm/Type.h"
+#include "N3MetaType.h"
+
#include <cstdarg>
namespace mvm {
@@ -224,12 +226,19 @@
bool canBeInlined;
void* code;
-
- llvm::GenericValue operator()(...);
- llvm::GenericValue operator()(va_list ap);
- llvm::GenericValue operator()(VMObject* obj, va_list ap);
- llvm::GenericValue operator()(std::vector<llvm::GenericValue>& args);
- llvm::GenericValue run(...);
+
+ VMMethod *compileToNative(VMGenericMethod* genMethod=0);
+
+ llvm::GenericValue invokeGeneric(std::vector<llvm::GenericValue>& args);
+ llvm::GenericValue invokeGeneric(va_list ap);
+
+#define DEFINE_CALLER(name, type) \
+ type invoke##name(...);
+
+ ON_TYPES(DEFINE_CALLER, _F_NT)
+ ON_VOID(DEFINE_CALLER, _F_NT)
+
+#undef DEFINE_CALLER
const llvm::FunctionType* getSignature(VMGenericMethod* genMethod);
static const llvm::FunctionType* resolveSignature(
@@ -265,18 +274,13 @@
void initField(VMObject* obj);
- llvm::GenericValue operator()(VMObject* obj = 0);
- void operator()(VMObject* obj, bool val);
- void operator()(VMObject* obj, float val);
- void operator()(VMObject* obj, double val);
- void operator()(VMObject* obj, sint32 val);
- void operator()(VMObject* obj, sint64 val);
- void operator()(VMObject* obj, VMObject* val);
- void operator()(bool val);
- void operator()(float val);
- void operator()(double val);
- void operator()(sint32 val);
- void operator()(sint64 val);
+#define DEF_VMFIELD_ASSESSORS(name, type) \
+ void set##name(VMObject *obj, type value); \
+ type get##name(VMObject *obj);
+
+ ON_TYPES(DEF_VMFIELD_ASSESSORS, _F_NT)
+
+#undef DEF_VMFIELD_ASSESSORS
llvm::GlobalVariable* llvmVar();
llvm::GlobalVariable* _llvmVar;
Modified: vmkit/trunk/lib/N3/VMCore/VMObject.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMObject.h?rev=84331&r1=84330&r2=84331&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMObject.h (original)
+++ vmkit/trunk/lib/N3/VMCore/VMObject.h Sat Oct 17 08:01:15 2009
@@ -12,6 +12,8 @@
#include <vector>
+#include "N3MetaType.h"
+
#include "llvm/Constants.h"
#include "llvm/Type.h"
#include "llvm/ExecutionEngine/GenericValue.h"
@@ -98,14 +100,6 @@
#define verifyNull(obj) \
if (obj == 0) VMThread::get()->getVM()->nullPointerException("");
#endif
-
- llvm::GenericValue operator()(VMField* field);
- void operator()(VMField* field, float val);
- void operator()(VMField* field, double val);
- void operator()(VMField* field, sint64 val);
- void operator()(VMField* field, sint32 val);
- void operator()(VMField* field, VMObject* val);
- void operator()(VMField* field, bool val);
};
More information about the vmkit-commits
mailing list