[vmkit-commits] [vmkit] r53148 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h CLIJit.cpp CLISignature.cpp VMClass.cpp VMThread.h
Tilmann Scheller
tilmann.scheller at googlemail.com
Sat Jul 5 12:28:07 PDT 2008
Author: tilmann
Date: Sat Jul 5 14:28:07 2008
New Revision: 53148
URL: http://llvm.org/viewvc/llvm-project?rev=53148&view=rev
Log:
support for accessing generic type parameters
Modified:
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/CLISignature.cpp
vmkit/trunk/lib/N3/VMCore/VMClass.cpp
vmkit/trunk/lib/N3/VMCore/VMThread.h
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Jul 5 14:28:07 2008
@@ -375,7 +375,7 @@
}
buf[i] = '>';
const UTF8* genName = UTF8::readerConstruct(VMThread::get()->vm, buf, size);
- printf("%s\n", genName->printString());
+ //printf("%s\n", genName->printString());
ClassNameCmp CC(genName, nameSpace);
VMGenericClass* cl = (VMGenericClass*) loadedNameClasses->lookupOrCreate(CC, this, genClassDup);
@@ -395,10 +395,21 @@
VMField* Assembly::constructField(VMClass* cl, const UTF8* name,
VMCommonClass* signature,
uint32 token) {
- VMField* field = loadedTokenFields->lookupOrCreate(token, this, fieldDup);
+ VMField* field;
+
+ if (VMThread::get()->currGenericClass == 0) {
+ // we are not reading a generic class
+ field = loadedTokenFields->lookupOrCreate(token, this, fieldDup);
+ } else {
+ // we are reading a generic class, don't add a reference
+ // to the loadedTokenFields map
+ field = fieldDup(token, this);
+ }
+
field->classDef = cl;
field->signature = signature;
field->name = name;
+
return field;
}
@@ -411,10 +422,21 @@
VMMethod* Assembly::constructMethod(VMClass* cl, const UTF8* name,
uint32 token) {
- VMMethod* meth = loadedTokenMethods->lookupOrCreate(token, this, methodDup);
+ VMMethod* meth;
+
+ if (VMThread::get()->currGenericClass == 0) {
+ // we are not reading a generic class
+ meth = loadedTokenMethods->lookupOrCreate(token, this, methodDup);
+ } else {
+ // we are reading a generic class, don't add a reference
+ // to the loadedTokenMethods map
+ meth = methodDup(token, this);
+ }
+
meth->classDef = cl;
meth->_signature = 0;
meth->name = name;
+
return meth;
}
@@ -427,7 +449,6 @@
ass->assemblyRefs = 0;
ass->isRead = false;
ass->name = name;
- ass->currGenericClass = 0;
return ass;
}
@@ -1097,7 +1118,8 @@
void Assembly::readClass(VMCommonClass* cl) {
// temporarily store the class being read in case it is a generic class
- currGenericClass = dynamic_cast<VMGenericClass*>(cl);
+ VMGenericClass* old = VMThread::get()->currGenericClass;
+ VMThread::get()->currGenericClass = dynamic_cast<VMGenericClass*>(cl);
uint32 index = cl->token & 0xffff;
Table* typeTable = CLIHeader->tables[CONSTANT_TypeDef];
@@ -1151,7 +1173,7 @@
}
// we have stopped reading a generic class
- currGenericClass = 0;
+ VMThread::get()->currGenericClass = old;
}
void Assembly::readCustomAttributes(uint32 offset, std::vector<llvm::GenericValue>& args, VMMethod* meth) {
@@ -1515,40 +1537,65 @@
const UTF8* name = readString((N3*)(VMThread::get()->vm), stringOffset +
memberArray[CONSTANT_MEMBERREF_NAME]);
- uint32 offset = blobOffset + memberArray[CONSTANT_MEMBERREF_SIGNATURE];
- VMCommonClass* signature = extractFieldSignature(offset);
-
uint32 value = memberArray[CONSTANT_MEMBERREF_CLASS];
uint32 table = value & 7;
index = value >> 3;
+ VMCommonClass* type = 0;
+
switch (table) {
case 0 : {
uint32 typeToken = index + (CONSTANT_TypeDef << 24);
- VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken,
+ type = loadType(((N3*)VMThread::get()->vm), typeToken,
true, false, false, true);
- VMField* field = type->lookupField(name, signature, stat, true);
- return field;
+ break;
}
case 1 : {
uint32 typeToken = index + (CONSTANT_TypeRef << 24);
- VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken,
+ type = loadType(((N3*)VMThread::get()->vm), typeToken,
true, false, false, true);
- VMField* field = type->lookupField(name, signature, stat, true);
- return field;
+ break;
}
case 2:
- case 3:
- case 4: VMThread::get()->vm->error("implement me"); break;
+ case 3: VMThread::get()->vm->error("implement me"); break;
+ case 4: {
+ uint32 typeToken = index + (CONSTANT_TypeSpec << 24);
+ type = loadType(((N3*)VMThread::get()->vm), typeToken,
+ true, false, false, true);
+ break;
+ }
default:
VMThread::get()->vm->error("unknown MemberRefParent tag %d", table);
}
- return 0;
+ uint32 offset = blobOffset + memberArray[CONSTANT_MEMBERREF_SIGNATURE];
+
+ VMGenericClass* genClass = dynamic_cast<VMGenericClass*>(type);
+
+ if (genClass) {
+ // save previous generic class
+ VMGenericClass* old = VMThread::get()->currGenericClass;
+
+ // set generic class this MemberRef is referring to
+ VMThread::get()->currGenericClass = genClass;
+
+ VMCommonClass* signature = extractFieldSignature(offset);
+
+ // restore saved class
+ VMThread::get()->currGenericClass = old;
+
+ VMField* field = type->lookupField(name, signature, stat, true);
+ return field;
+ } else {
+ VMCommonClass* signature = extractFieldSignature(offset);
+ VMField* field = type->lookupField(name, signature, stat, true);
+ return field;
+ }
+
}
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sat Jul 5 14:28:07 2008
@@ -161,9 +161,6 @@
MethodTokenMap* loadedTokenMethods;
FieldTokenMap* loadedTokenFields;
- // helper which points to the current generic class while it is being read in readClass()
- VMGenericClass* currGenericClass;
-
mvm::Lock* lockVar;
mvm::Cond* condVar;
const UTF8* name;
Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Jul 5 14:28:07 2008
@@ -459,10 +459,10 @@
jit->compilingClass = meth->classDef;
jit->compilingMethod = meth;
- // save current class in case of recursive calls to compile()
- VMGenericClass* old = jit->compilingClass->assembly->currGenericClass;
+ // save previous current generic class to restore it later
+ VMGenericClass* old = VMThread::get()->currGenericClass;
// temporarily store the class being compiled in case it is a generic class
- jit->compilingClass->assembly->currGenericClass = dynamic_cast<VMGenericClass*>(jit->compilingClass);
+ VMThread::get()->currGenericClass = dynamic_cast<VMGenericClass*>(jit->compilingClass);
jit->unifiedUnreachable = unifiedUnreachable;
@@ -473,7 +473,7 @@
inlineMethods[meth] = false;
// restore saved class
- jit->compilingClass = old;
+ VMThread::get()->currGenericClass = old;
return ret;
}
@@ -1420,14 +1420,28 @@
jit->compilingClass = cl;
jit->compilingMethod = meth;
+ // save previous generic class
+ VMGenericClass* old = VMThread::get()->currGenericClass;
+
+ // temporarily store the class of the method to be compiled
+ // in case it is a generic class
+ VMThread::get()->currGenericClass = dynamic_cast<VMGenericClass*>(cl);
+
+ Function* func;
meth->getSignature();
+
if (isInternal(meth->implFlags)) {
- return jit->compileNative();
+ func = jit->compileNative();
} else if (meth->offset == 0) {
- return jit->compileIntern();
+ func = jit->compileIntern();
} else {
- return jit->compileFatOrTiny();
+ func = jit->compileFatOrTiny();
}
+
+ // restore saved class
+ VMThread::get()->currGenericClass = old;
+
+ return func;
}
llvm::Function *VMMethod::compiledPtr() {
Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Sat Jul 5 14:28:07 2008
@@ -1,4 +1,4 @@
-//===--------- CLIsignature.cpp - Reads CLI signatures --------------------===//
+//===--------- CLISignature.cpp - Reads CLI signatures --------------------===//
//
// N3
//
@@ -141,10 +141,8 @@
static VMCommonClass* METHOD_ElementTypeVar(uint32 op, Assembly* ass, uint32& offset) {
uint32 number = ass->uncompressSignature(offset);
- return ass->currGenericClass->genericParams[number];
- //uint32 type = READ_U4(ass->bytes, offset);
- //VMThread::get()->vm->error("implement me");
- //return 0;
+
+ return VMThread::get()->currGenericClass->genericParams[number];
}
static VMCommonClass* METHOD_ElementTypeArray(uint32 op, Assembly* ass, uint32& offset) {
@@ -371,6 +369,7 @@
uint32 hasThis = call & CONSTANT_HasThis ? 1 : 0;
uint32 realCount = paramCount + hasThis;
+ //uint32 generic = call & CONSTANT_Generic ? 1 : 0;
VMCommonClass* ret = exploreType(offset);
types.push_back(ret);
@@ -410,6 +409,9 @@
if (fieldSig != 0x6) {
VMThread::get()->vm->error("unknown field sig %x", fieldSig);
}
+
+ // TODO implement support for custom modifiers
+ // see ECMA 335 23.2.4, 23.2.7
return exploreType(offset);
Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Sat Jul 5 14:28:07 2008
@@ -216,8 +216,8 @@
VMMethod* meth = cl->lookupMethodDontThrow(N3::clinitName, args,
true, false);
- PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "; ", 0);
- PRINT_DEBUG(N3_LOAD, 0, LIGHT_GREEN, "clinit ", 0);
+ PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "%s", "; ");
+ PRINT_DEBUG(N3_LOAD, 0, LIGHT_GREEN, "%s", "clinit ");
PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "%s::%s\n", printString(),
cl->printString());
@@ -818,5 +818,8 @@
}
void VMGenericClass::print(mvm::PrintBuffer* buf) const {
- buf->write("Generic Class");
-}
+ buf->write("GenCLIType<");
+ nameSpace->print(buf);
+ buf->write("::");
+ name->print(buf);
+ buf->write(">");}
Modified: vmkit/trunk/lib/N3/VMCore/VMThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.h?rev=53148&r1=53147&r2=53148&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMThread.h (original)
+++ vmkit/trunk/lib/N3/VMCore/VMThread.h Sat Jul 5 14:28:07 2008
@@ -24,6 +24,7 @@
class VirtualMachine;
class VMClass;
+class VMGenericClass;
class VMObject;
class VMThread : public mvm::Thread {
@@ -38,6 +39,9 @@
unsigned int self;
unsigned int interruptFlag;
unsigned int state;
+
+ // helper which points to the current generic class
+ VMGenericClass* currGenericClass;
static const unsigned int StateRunning;
static const unsigned int StateWaiting;
More information about the vmkit-commits
mailing list