[vmkit-commits] [vmkit] r53161 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h CLISignature.cpp
Tilmann Scheller
tilmann.scheller at googlemail.com
Sun Jul 6 12:52:02 PDT 2008
Author: tilmann
Date: Sun Jul 6 14:52:01 2008
New Revision: 53161
URL: http://llvm.org/viewvc/llvm-project?rev=53161&view=rev
Log:
add early support for generic methods
Modified:
vmkit/trunk/lib/N3/VMCore/Assembly.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.h
vmkit/trunk/lib/N3/VMCore/CLISignature.cpp
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53161&r1=53160&r2=53161&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sun Jul 6 14:52:01 2008
@@ -1147,10 +1147,13 @@
for (uint32 i = 0; i < nbMethods; ++i) {
VMMethod* meth = readMethodDef(i + methodList, cl);
- if (isStatic(meth->flags)) {
- cl->staticMethods.push_back(meth);
- } else {
- cl->virtualMethods.push_back(meth);
+
+ if (meth != NULL) {
+ if (isStatic(meth->flags)) {
+ cl->staticMethods.push_back(meth);
+ } else {
+ cl->virtualMethods.push_back(meth);
+ }
}
}
}
@@ -1320,35 +1323,43 @@
uint32 paramList = methArray[CONSTANT_METHODDEF_PARAMLIST];
uint32 offset = blobOffset + signature;
- VMMethod* meth =
- constructMethod((VMClass*)cl, readString(cl->vm, (name + stringOffset)),
- token);
- meth->virt = extractMethodSignature(offset, cl, meth->parameters);
- meth->flags = flags;
- meth->implFlags = implFlags;
-
- if (rva) {
- meth->offset = textSection->rawAddress +
- (rva - textSection->virtualAddress);
+
+ if (isGenericMethod(offset)) {
+ // generic methods are read on instantiation
+ return NULL;
} else {
- meth->offset = 0;
- }
+ offset = blobOffset + signature;
+
+ VMMethod* meth =
+ constructMethod((VMClass*)cl, readString(cl->vm, (name + stringOffset)),
+ token);
+ meth->virt = extractMethodSignature(offset, cl, meth->parameters);
+ meth->flags = flags;
+ meth->implFlags = implFlags;
+
+ if (rva) {
+ meth->offset = textSection->rawAddress +
+ (rva - textSection->virtualAddress);
+ } else {
+ meth->offset = 0;
+ }
- if (paramList && paramTable != 0 && paramList <= paramSize) {
- uint32 endParam = (index == methodSize) ?
- paramSize + 1 :
- methTable->readIndexInRow(index + 1, CONSTANT_METHODDEF_PARAMLIST,
+ if (paramList && paramTable != 0 && paramList <= paramSize) {
+ uint32 endParam = (index == methodSize) ?
+ paramSize + 1 :
+ methTable->readIndexInRow(index + 1, CONSTANT_METHODDEF_PARAMLIST,
bytes);
- uint32 nbParams = endParam - paramList;
+ uint32 nbParams = endParam - paramList;
+
+ for (uint32 j = 0; j < nbParams; ++j) {
+ meth->params.push_back(readParam(j + paramList, meth));
+ }
- for (uint32 j = 0; j < nbParams; ++j) {
- meth->params.push_back(readParam(j + paramList, meth));
}
+ return meth;
}
-
- return meth;
}
VMField* Assembly::readField(uint32 index, VMCommonClass* cl) {
@@ -1542,7 +1553,7 @@
uint32 table = value & 7;
index = value >> 3;
- VMCommonClass* type = 0;
+ VMCommonClass* type = NULL;
switch (table) {
case 0 : {
@@ -1601,6 +1612,7 @@
VMMethod* Assembly::getMethodFromToken(uint32 token) {
VMMethod* meth = lookupMethodFromToken(token);
+
if (!meth) {
uint32 table = token >> 24;
switch (table) {
@@ -1628,13 +1640,20 @@
meth = readMemberRefAsMethod(token);
break;
}
+
+ case CONSTANT_MethodSpec : {
+ meth = readMethodSpec(token);
+ break;
+ }
default : {
VMThread::get()->vm->error("implement me");
}
}
}
+
meth->getSignature();
+
return meth;
}
@@ -1703,7 +1722,7 @@
case 2:
case 3: VMThread::get()->vm->error("implement me %d", table); break;
case 4: {
- VMClass* type = (VMClass*)readTypeSpec(vm, index);
+ VMClass* type = (VMClass*) readTypeSpec(vm, index);
VMGenericClass* genClass = dynamic_cast<VMGenericClass*>(type);
@@ -1733,6 +1752,22 @@
return 0;
}
+VMMethod* Assembly::readMethodSpec(uint32 token) {
+ uint32 index = token & 0xffff;
+
+ Table* methodTable = CLIHeader->tables[CONSTANT_MethodSpec];
+ uint32* methodArray = (uint32*) alloca(sizeof(uint32) * methodTable->rowSize);
+
+ methodTable->readRow(methodArray, index, bytes);
+
+ uint32 method = methodArray[CONSTANT_METHOD_SPEC_METHOD];
+ uint32 instantiation = methodArray[CONSTANT_METHOD_SPEC_INSTANTIATION];
+
+ VMThread::get()->vm->error("MethodSpec");
+// return NULL;
+ return (VMMethod*) (method ^ instantiation);
+}
+
const UTF8* Assembly::readUserString(uint32 token) {
uint32 offset = CLIHeader->usStream->realOffset + token;
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=53161&r1=53160&r2=53161&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sun Jul 6 14:52:01 2008
@@ -217,6 +217,7 @@
void getProperties(VMCommonClass* cl);
Property* readProperty(uint32 index, VMCommonClass* cl);
VMMethod* readMethodDef(uint32 index, VMCommonClass* cl);
+ VMMethod* readMethodSpec(uint32 token);
VMField* readField(uint32 index, VMCommonClass* cl);
Param* readParam(uint32 index, VMMethod* meth);
VMClass* readTypeDef(N3* vm, uint32 index);
@@ -230,6 +231,7 @@
bool extractMethodSignature(uint32& offset, VMCommonClass* cl,
std::vector<VMCommonClass*> ¶ms);
+ bool isGenericMethod(uint32& offset);
void localVarSignature(uint32& offset,
std::vector<VMCommonClass*>& locals);
VMCommonClass* extractFieldSignature(uint32& offset);
@@ -530,7 +532,7 @@
bitmask = bitmask | ((fieldSize - 1) << (offset << 1)); \
}
-// Some encondigs are not used here
+// Some encodings are not used here
#define CUSTOM_ATTRIBUTE_TYPE(offset) { \
uint32 fieldSize = 0; \
if (tables[CONSTANT_MethodDef]->rowsNumber < 0x2000 && \
Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53161&r1=53160&r2=53161&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Sun Jul 6 14:52:01 2008
@@ -385,6 +385,15 @@
return hasThis != 0;
}
+// checks whether the MethodDefSig at offset contains generic parameters
+bool Assembly::isGenericMethod(uint32& offset) {
+ uncompressSignature(offset); // count
+
+ uint32 callingConvention = READ_U1(bytes, offset);
+
+ return callingConvention & CONSTANT_Generic ? true : false;
+}
+
void Assembly::localVarSignature(uint32& offset,
std::vector<VMCommonClass*>& locals) {
//uint32 count =
More information about the vmkit-commits
mailing list