[vmkit-commits] [vmkit] r83554 - in /vmkit/trunk/lib/N3: PNetLib/PNetLib.cpp VMCore/Assembly.cpp VMCore/CLIJit.cpp VMCore/CLIRuntimeJIT.cpp VMCore/N3.cpp VMCore/N3Initialise.cpp VMCore/UTF8.cpp VMCore/UTF8.h VMCore/VMClass.cpp
Gael Thomas
gael.thomas at lip6.fr
Thu Oct 8 09:55:30 PDT 2009
Author: gthomas
Date: Thu Oct 8 11:55:29 2009
New Revision: 83554
URL: http://llvm.org/viewvc/llvm-project?rev=83554&view=rev
Log:
Unification of n3::UTF8 and mvm::UTF8 in progress
Modified:
vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.cpp
vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp
vmkit/trunk/lib/N3/VMCore/N3.cpp
vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
vmkit/trunk/lib/N3/VMCore/UTF8.cpp
vmkit/trunk/lib/N3/VMCore/UTF8.h
vmkit/trunk/lib/N3/VMCore/VMClass.cpp
Modified: vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp (original)
+++ vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp Thu Oct 8 11:55:29 2009
@@ -693,7 +693,7 @@
if (item->getVirtualTable() == Property::VT) {
Property* prop = (Property*)item;
if (attributes == METHOD_SEMANTIC_ATTRIBUTES_GETTER) {
- char* asciiz = prop->name->UTF8ToAsciiz();
+ const char* asciiz = utf8ToAsciiz(prop->name);
char* buf = (char*)alloca(strlen(asciiz) + 5);
sprintf(buf, "get_%s", asciiz);
N3* vm = VMThread::get()->vm;
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Thu Oct 8 11:55:29 2009
@@ -363,12 +363,12 @@
}
uint16* buf = (uint16*) alloca(sizeof(uint16) * size);
for (i = 0; i < name->size; i++) {
- buf[i] = name->at(i);
+ buf[i] = name->elements[i];
}
buf[i++] = '<';
for (std::vector<VMCommonClass*>::iterator it = genArgs.begin(), e = genArgs.end(); it!= e; ++it) {
for (int j = 0; j < (*it)->name->size; i++, j++) {
- buf[i] = (*it)->name->at(j);
+ buf[i] = (*it)->name->elements[j];
}
buf[i++] = ',';
}
@@ -1253,7 +1253,7 @@
}
}
- ArrayObject* res = ArrayObject::acons(vec.size(), MSCorlib::arrayObject);
+ ArrayObject* res = (ArrayObject*)MSCorlib::arrayObject->doNew(vec.size());
for (uint32 i = 0; i < vec.size(); ++i)
res->elements[i] = vec[i];
Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Thu Oct 8 11:55:29 2009
@@ -1547,8 +1547,8 @@
PointerType::getUnqual(module->getTypeByName("ArrayFloat"));
ArrayObject::llvmType =
PointerType::getUnqual(module->getTypeByName("ArrayObject"));
- UTF8::llvmType =
- PointerType::getUnqual(module->getTypeByName("ArrayUInt16"));
+ // UTF8::llvmType =
+ // PointerType::getUnqual(module->getTypeByName("ArrayUInt16"));
CacheNode::llvmType =
PointerType::getUnqual(module->getTypeByName("CacheNode"));
Enveloppe::llvmType =
Modified: vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp Thu Oct 8 11:55:29 2009
@@ -138,9 +138,9 @@
orig->parameters,
false, true);
if (dmeth == 0) {
- char* methAsciiz = orig->name->UTF8ToAsciiz();
- char* nameAsciiz = orig->classDef->name->UTF8ToAsciiz();
- char* nameSpaceAsciiz = orig->classDef->nameSpace->UTF8ToAsciiz();
+ const char* methAsciiz = utf8ToAsciiz(orig->name);
+ const char* nameAsciiz = utf8ToAsciiz(orig->classDef->name);
+ const char* nameSpaceAsciiz = utf8ToAsciiz(orig->classDef->nameSpace);
char *buf = (char*)alloca(3 + strlen(methAsciiz) +
strlen(nameAsciiz) +
Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3.cpp Thu Oct 8 11:55:29 2009
@@ -236,9 +236,9 @@
}
ArrayUInt8* N3::openAssembly(const UTF8* name, const char* ext) {
- char* asciiz = name->UTF8ToAsciiz();
+ const char* asciiz = utf8ToAsciiz(name);
uint32 alen = strlen(asciiz);
-
+
ArrayUInt8* res = 0;
uint32 idx = 0;
Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Thu Oct 8 11:55:29 2009
@@ -157,9 +157,6 @@
const llvm::Type* ArrayDouble::llvmType = 0;
const llvm::Type* ArrayLong::llvmType = 0;
const llvm::Type* ArrayObject::llvmType = 0;
-const llvm::Type* UTF8::llvmType = 0;
-
-
static void initialiseVT() {
@@ -188,7 +185,12 @@
INIT(ArrayFloat);
INIT(ArrayDouble);
INIT(ArrayObject);
- INIT(UTF8);
+
+ {
+ UTF8 fake(0);
+ UTF8::VT = ((VirtualTable**)(void*)(&fake))[0];
+ }
+
INIT(VMCond);
INIT(LockObj);
INIT(VMObject);
Modified: vmkit/trunk/lib/N3/VMCore/UTF8.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/UTF8.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/UTF8.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/UTF8.cpp Thu Oct 8 11:55:29 2009
@@ -7,58 +7,20 @@
using namespace n3;
-#define AT(name, elmt) \
- elmt name::at(sint32 offset) const { \
- if (offset >= size) \
- VMThread::get()->vm->indexOutOfBounds(this, offset); \
- return elements[offset]; \
- } \
- void name::setAt(sint32 offset, elmt value) { \
- if (offset >= size) \
- VMThread::get()->vm->indexOutOfBounds(this, offset); \
- elements[offset] = value; \
- }
-
-#define INITIALISE(name) \
- void name::initialise(VMCommonClass* atype, sint32 n) { \
- VMObject::initialise(atype); \
- this->size = n; \
- for (int i = 0; i < n; i++) \
- elements[i] = 0; \
- } \
-
-AT(UTF8, uint16)
-INITIALISE(UTF8)
-
-#undef AT
-#undef INITIALISE
-
-
-UTF8* UTF8::acons(sint32 n, VMClassArray* atype) {
- if (n < 0)
- VMThread::get()->vm->negativeArraySizeException(n);
- else if (n > VMArray::MaxArraySize)
- VMThread::get()->vm->outOfMemoryError(n);
- uint32 size = sizeof(VMObject) + sizeof(sint32) + n * sizeof(uint16);
- UTF8* res = (UTF8*)gc::operator new(size, UTF8::VT);
- res->initialise(atype, n);
- return res;
-}
-
void UTF8::print(mvm::PrintBuffer* buf) const {
for (int i = 0; i < size; i++)
buf->writeChar((char)elements[i]);
}
-const UTF8* UTF8::extract(N3 *vm, uint32 start, uint32 end) const {
+const UTF8* UTF8::extract(UTF8Map *map, uint32 start, uint32 end) const {
uint32 len = end - start;
uint16* buf = (uint16*)alloca(sizeof(uint16) * len);
for (uint32 i = 0; i < len; i++) {
- buf[i] = at(i + start);
+ buf[i] = elements[i + start];
}
- return readerConstruct(vm, buf, len);
+ return map->lookupOrCreateReader(buf, len);
}
const UTF8* UTF8::asciizConstruct(N3* vm, const char* asciiz) {
@@ -69,17 +31,6 @@
return vm->bufToUTF8(buf, n);
}
-char* UTF8::UTF8ToAsciiz() const {
- mvm::NativeString* buf = mvm::NativeString::alloc(size + 1);
- for (sint32 i = 0; i < size; ++i) {
- buf->setAt(i, elements[i]);
- }
- buf->setAt(size, 0);
- return buf->cString();
-}
-
-
-
static uint32 asciizHasher(const char* asciiz, sint32 size) {
uint32 r0 = 0, r1 = 0;
for (sint32 i = 0; i < size; i++) {
@@ -105,7 +56,7 @@
if (len != size) return false;
else {
for (sint32 i = 0; i < len; i++) {
- if (asciiz[i] != val->at(i)) return false;
+ if (asciiz[i] != val->elements[i]) return false;
}
return true;
}
@@ -134,9 +85,9 @@
}
if (res == 0) {
- UTF8* tmp = (UTF8 *)UTF8::acons(size, MSCorlib::arrayChar);
+ UTF8* tmp = (UTF8 *)new(size) UTF8(size);
for (sint32 i = 0; i < size; i++) {
- tmp->setAt(i, asciiz[i]);
+ tmp->elements[i] = asciiz[i];
}
res = (const UTF8*)tmp;
map.insert(std::make_pair(key, res));
@@ -162,7 +113,7 @@
}
if (res == 0) {
- UTF8* tmp = UTF8::acons(size, MSCorlib::arrayChar);
+ UTF8* tmp = new(size) UTF8(size);
memcpy(tmp->elements, buf, len * sizeof(uint16));
res = (const UTF8*)tmp;
map.insert(std::make_pair(key, res));
Modified: vmkit/trunk/lib/N3/VMCore/UTF8.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/UTF8.h?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/UTF8.h (original)
+++ vmkit/trunk/lib/N3/VMCore/UTF8.h Thu Oct 8 11:55:29 2009
@@ -10,6 +10,7 @@
namespace n3 {
class VMClassArray;
+ class UTF8Map;
class N3;
class UTF8 : public VMObject {
@@ -17,21 +18,23 @@
static VirtualTable* VT;
sint32 size;
uint16 elements[1];
-
- static const llvm::Type* llvmType;
- static UTF8* acons(sint32 n, VMClassArray* cl);
- void initialise(VMCommonClass* atype, sint32 n);
- unsigned short int at(sint32) const;
- void setAt(sint32, uint16);
+ /// operator new - Redefines the new operator of this class to allocate
+ /// its objects in permanent memory, not with the garbage collector.
+ void* operator new(size_t sz, sint32 n) {
+ return gc::operator new(sizeof(VMObject) + sizeof(sint32) + n * sizeof(uint16), UTF8::VT);
+ }
+ UTF8(sint32 n) {
+ size = n;
+ }
+
virtual void print(mvm::PrintBuffer* buf) const;
- char* UTF8ToAsciiz() const;
static const UTF8* asciizConstruct(N3 *vm, const char* asciiz);
static const UTF8* readerConstruct(N3 *vm, uint16* buf, uint32 n);
- const UTF8* extract(N3 *vm, uint32 start, uint32 len) const;
+ const UTF8* extract(UTF8Map *vm, uint32 start, uint32 len) const;
};
class UTF8Map : public mvm::PermanentObject {
@@ -104,6 +107,61 @@
}
};
+
+/// UTF8Buffer - Helper class to create char* buffers suitable for
+/// printf.
+///
+class UTF8Buffer {
+
+ /// buffer - The buffer that holds a string representation.
+ ///
+ char* buffer;
+public:
+
+ /// UTF8Buffer - Create a buffer with the following UTF8.
+ ///
+ UTF8Buffer(const UTF8* val) {
+ buffer = new char[val->size + 1];
+ for (sint32 i = 0; i < val->size; ++i)
+ buffer[i] = val->elements[i];
+ buffer[val->size] = 0;
+ printf("buffer: %s (%d)\n", buffer, val->size);
+ }
+
+ /// ~UTF8Buffer - Delete the buffer, as well as all dynamically
+ /// allocated memory.
+ ///
+ ~UTF8Buffer() {
+ printf("Destructor :(\n");
+ delete[] buffer;
+ }
+
+ /// replaceWith - replace the content of the buffer and free the old buffer
+ ///
+ void replaceWith(char *buffer) {
+ delete[] this->buffer;
+ this->buffer = buffer;
+ }
+
+
+ /// cString - Return a C string representation of the buffer, suitable
+ /// for printf.
+ ///
+ const char* cString() {
+ printf("cString: %s\n", buffer);
+ return buffer;
+ }
+};
+
+inline char *_utf8ToAsciiz(const UTF8 *val, char *buffer) {
+ for (sint32 i = 0; i < val->size; ++i)
+ buffer[i] = val->elements[i];
+ buffer[val->size] = 0;
+ return buffer;
+}
+
+#define utf8ToAsciiz(utf8) _utf8ToAsciiz(utf8, (char*)alloca(utf8->size + 1))
+
}
#endif
Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=83554&r1=83553&r2=83554&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Thu Oct 8 11:55:29 2009
@@ -172,7 +172,7 @@
}
const UTF8* VMClassArray::constructArrayName(const UTF8* name, uint32 dims) {
- const char* asciiz = name->UTF8ToAsciiz();
+ const char* asciiz = utf8ToAsciiz(name);
char* res = (char*)alloca(strlen(asciiz) + (dims * 2) + 1);
sprintf(res, asciiz);
@@ -184,7 +184,7 @@
}
const UTF8* VMClassPointer::constructPointerName(const UTF8* name, uint32 dims) {
- const char* asciiz = name->UTF8ToAsciiz();
+ const char* asciiz = utf8ToAsciiz(name);
char* res = (char*)alloca(strlen(asciiz) + (dims * 2) + 1);
sprintf(res, asciiz);
More information about the vmkit-commits
mailing list