[vmkit-commits] [vmkit] r52958 - in /vmkit/trunk: ./ autoconf/ lib/N3/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/n3/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Jul 1 06:41:03 PDT 2008
Author: geoffray
Date: Tue Jul 1 08:41:02 2008
New Revision: 52958
URL: http://llvm.org/viewvc/llvm-project?rev=52958&view=rev
Log:
Create an interface between N3 and its class library (currently pnetlib).
Added:
vmkit/trunk/lib/N3/PNetLib/
vmkit/trunk/lib/N3/PNetLib/Makefile
vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
vmkit/trunk/lib/N3/PNetLib/PNetLib.h
vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp
vmkit/trunk/lib/N3/PNetLib/PNetString.cpp
vmkit/trunk/lib/N3/PNetLib/PNetString.h
Removed:
vmkit/trunk/lib/N3/VMCore/CLIString.cpp
vmkit/trunk/lib/N3/VMCore/PNetLib.cpp
vmkit/trunk/lib/N3/VMCore/PNetLib.h
Modified:
vmkit/trunk/Makefile.config.in
vmkit/trunk/autoconf/configure.ac
vmkit/trunk/configure
vmkit/trunk/lib/N3/Makefile
vmkit/trunk/lib/N3/VMCore/Assembly.cpp
vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
vmkit/trunk/lib/N3/VMCore/CLISignature.cpp
vmkit/trunk/lib/N3/VMCore/CLIString.h
vmkit/trunk/lib/N3/VMCore/LockedMap.cpp
vmkit/trunk/lib/N3/VMCore/LockedMap.h
vmkit/trunk/lib/N3/VMCore/Makefile
vmkit/trunk/lib/N3/VMCore/N3.cpp
vmkit/trunk/lib/N3/VMCore/N3.h
vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
vmkit/trunk/lib/N3/VMCore/Opcodes.cpp
vmkit/trunk/lib/N3/VMCore/Reader.cpp
vmkit/trunk/lib/N3/VMCore/VMCache.cpp
vmkit/trunk/lib/N3/VMCore/VMClass.cpp
vmkit/trunk/lib/N3/VMCore/VMThread.cpp
vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp
vmkit/trunk/tools/n3/Makefile
Modified: vmkit/trunk/Makefile.config.in
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.config.in?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/Makefile.config.in (original)
+++ vmkit/trunk/Makefile.config.in Tue Jul 1 08:41:02 2008
@@ -1,3 +1,4 @@
GCLIB = @GC_LIBS@
WITH_N3 = @WITH_N3@
WITH_JNJVM = @WITH_JNJVM@
+N3_LIB = @N3_LIB@
Modified: vmkit/trunk/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/autoconf/configure.ac?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/autoconf/configure.ac (original)
+++ vmkit/trunk/autoconf/configure.ac Tue Jul 1 08:41:02 2008
@@ -301,6 +301,9 @@
AC_SUBST([pnetlocalprefix])
AC_SUBST([WITH_N3])
+N3_LIB=PNetLib
+AC_SUBST([N3_LIB])
+
dnl===-----------------------------------------------------------------------===
dnl===
dnl=== SECTION 4: Check for programs we need and that they are the right version
Modified: vmkit/trunk/configure
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/configure?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/configure (original)
+++ vmkit/trunk/configure Tue Jul 1 08:41:02 2008
@@ -698,6 +698,7 @@
WITH_JNJVM
pnetlocalprefix
WITH_N3
+N3_LIB
CXX
CXXFLAGS
ac_ct_CXX
@@ -4038,6 +4039,9 @@
+N3_LIB=PNetLib
+
+
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
@@ -7834,6 +7838,7 @@
WITH_JNJVM!$WITH_JNJVM$ac_delim
pnetlocalprefix!$pnetlocalprefix$ac_delim
WITH_N3!$WITH_N3$ac_delim
+N3_LIB!$N3_LIB$ac_delim
CXX!$CXX$ac_delim
CXXFLAGS!$CXXFLAGS$ac_delim
ac_ct_CXX!$ac_ct_CXX$ac_delim
@@ -7850,7 +7855,6 @@
SED!$SED$ac_delim
TAR!$TAR$ac_delim
BINPWD!$BINPWD$ac_delim
-CAT!$CAT$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -7892,6 +7896,7 @@
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
cat >conf$$subs.sed <<_ACEOF
+CAT!$CAT$ac_delim
LLVMAS!$LLVMAS$ac_delim
LLC!$LLC$ac_delim
INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim
@@ -7903,7 +7908,7 @@
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 9; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 10; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
Modified: vmkit/trunk/lib/N3/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Makefile?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/Makefile (original)
+++ vmkit/trunk/lib/N3/Makefile Tue Jul 1 08:41:02 2008
@@ -8,6 +8,8 @@
##===----------------------------------------------------------------------===##
LEVEL = ../..
-DIRS = VMCore
+include $(LEVEL)/Makefile.config
+
+DIRS = VMCore $(N3_LIB)
include $(LEVEL)/Makefile.common
Added: vmkit/trunk/lib/N3/PNetLib/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/Makefile?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/Makefile (added)
+++ vmkit/trunk/lib/N3/PNetLib/Makefile Tue Jul 1 08:41:02 2008
@@ -0,0 +1,13 @@
+##===- lib/N3/PNetLib/Makefile -----------------------------*- Makefile -*-===##
+#
+# The vmkit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../../..
+
+LIBRARYNAME = PNetLib
+include $(LEVEL)/Makefile.common
+CXX.Flags += -I../VMCore
Added: vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp (added)
+++ vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp Tue Jul 1 08:41:02 2008
@@ -0,0 +1,1210 @@
+//===--------------- PNetLib.cpp - PNetLib interface ----------------------===//
+//
+// N3
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <math.h>
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+#include "mvm/JIT.h"
+
+#include "Assembly.h"
+#include "CLIAccess.h"
+#include "CLIJit.h"
+#include "PNetString.h"
+#include "NativeUtil.h"
+#include "MSCorlib.h"
+#include "N3.h"
+#include "PNetLib.h"
+#include "Reader.h"
+#include "VMArray.h"
+#include "VMClass.h"
+#include "VMObject.h"
+#include "VMThread.h"
+
+using namespace n3;
+
+#define IL_CONSOLE_NORMAL 0
+
+
+#define MEMBER_TYPES_CONSTRUCTOR 0x1
+#define MEMBER_TYPES_EVENT 0x2
+#define MEMBER_TYPES_FIELD 0x4
+#define MEMBER_TYPES_METHOD 0x8
+#define MEMBER_TYPES_PROPERTY 0x10
+#define MEMBER_TYPES_TYPEINFO 0x20
+#define MEMBER_TYPES_CUSTOM 0x40
+#define MEMBER_TYPES_NESTEDTYPE 0x80
+#define MEMBER_TYPES_ALL 0xBF
+
+#define METHOD_SEMANTIC_ATTRIBUTES_SETTER 0x1
+#define METHOD_SEMANTIC_ATTRIBUTES_GETTER 0x2
+#define METHOD_SEMANTIC_ATTRIBUTES_OTHER 0x4
+#define METHOD_SEMANTIC_ATTRIBUTES_ADDON 0x8
+#define METHOD_SEMANTIC_ATTRIBUTES_REMOVEON 0x10
+#define METHOD_SEMANTIC_ATTRIBUTES_FIRE 0x20
+
+
+extern "C" {
+extern uint32 ILGetCodePage(void);
+extern uint32 ILGetCultureID(void);
+extern char* ILGetCultureName(void);
+extern sint32 ILAnsiGetMaxByteCount(sint32);
+extern sint32 ILConsoleWriteChar(sint32);
+extern uint32 ILConsoleGetMode(void);
+extern sint32 ILAnsiGetBytes(uint16*, sint32, uint8*, sint32);
+extern void _IL_Stdio_StdFlush(void*, sint32);
+extern char ILGetUnicodeCategory(sint32);
+extern sint64 _IL_TimeMethods_GetCurrentTime(void*);
+extern uint32 ILUnicodeStringToLower(void*, void*, uint32);
+extern sint32 ILUnicodeStringCompareIgnoreCase(void*, void*, sint32);
+extern sint32 ILUnicodeStringCompareNoIgnoreCase(void*, void*, sint32);
+
+#include "mvm/Config/config.h"
+// PNET wants this
+void *GC_run_thread(void *(*thread_func)(void *), void *arg){ return 0; }
+#if not(USE_GC_BOEHM)
+int GC_invoke_finalizers (void) { return 0; }
+int GC_should_invoke_finalizers (void) { return 0; }
+void GC_register_finalizer_no_order(void*, void (*)(void*, void*), void*, void (**)(void*, void*), void**) { return; }
+void GC_gcollect(void) {}
+void* GC_malloc_uncollectable(size_t) { return 0; }
+void GC_exclude_static_roots(void*, void*) {}
+void GC_free(void*) {}
+void GC_malloc_explicitly_typed(void) {}
+size_t GC_get_heap_size(void) {return 0;}
+int GC_register_disappearing_link(void**) { return 0; }
+int GC_general_register_disappearing_link(void**, void*) { return 0; }
+int GC_pthread_sigmask(int, const sigset_t*, sigset_t*) { return 0; }
+int GC_pthread_detach(pthread_t) { return 0; }
+int GC_pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*) { return 0; }
+void* GC_malloc(size_t) { return 0; }
+void GC_make_descriptor(void) {}
+int GC_unregister_disappearing_link(void**) { return 0; }
+void (*GC_finalizer_notifier)(void);
+int GC_java_finalization;
+int GC_finalize_on_demand;
+void GC_set_max_heap_size(size_t) {}
+void* GC_malloc_atomic(size_t) { return 0; }
+#endif
+
+// Fake termcap symbols
+void tigetstr(void) {
+ abort();
+}
+void tgetstr(void) {
+ abort();
+}
+void setupterm(void) {
+ abort();
+}
+void tigetnum(void) {
+ abort();
+}
+void tgetnum(void) {
+ abort();
+}
+void tigetflag(void) {
+ abort();
+}
+void tparm(void) {
+ abort();
+}
+void tgetent(void) {
+ abort();
+}
+void tputs(void) {
+ abort();
+}
+void tgoto(void) {
+ abort();
+}
+void tgetflag(void) {
+ abort();
+}
+}
+
+
+
+extern "C" void System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray(
+ VMArray* array, VMField* field) {
+ if (!array || !field) return;
+
+ VMClass* type = field->classDef;
+ VMClassArray* ts = (VMClassArray*)array->classOf;
+ VMCommonClass* bs = ts->baseClass;
+ Assembly* ass = type->assembly;
+
+ uint32 rva = ass->getRVAFromField(field->token);
+ Section* rsrcSection = ass->rsrcSection;
+
+ uint32 size = array->size;
+ uint32 offset = rsrcSection->rawAddress + (rva - rsrcSection->virtualAddress);
+ ArrayUInt8* bytes = ass->bytes;
+
+ if (bs == MSCorlib::pChar) {
+ for (uint32 i = 0; i < size; ++i) {
+ ((ArrayUInt16*)array)->elements[i] = READ_U2(bytes, offset);
+ }
+ } else if (bs == MSCorlib::pSInt32) {
+ for (uint32 i = 0; i < size; ++i) {
+ ((ArraySInt32*)array)->elements[i] = READ_U4(bytes, offset);
+ }
+ } else if (bs == MSCorlib::pDouble) {
+ for (uint32 i = 0; i < size; ++i) {
+ ((ArrayDouble*)array)->elements[i] = READ_U8(bytes, offset);
+ }
+ } else {
+ VMThread::get()->vm->error("implement me");
+ }
+}
+
+extern "C" VMObject* System_Type_GetTypeFromHandle(VMCommonClass* cl) {
+ return cl->getClassDelegatee();
+}
+
+extern "C" void System_Threading_Monitor_Enter(VMObject* obj) {
+ obj->aquire();
+}
+
+extern "C" void System_Threading_Monitor_Exit(VMObject* obj) {
+ obj->unlock();
+}
+
+extern "C" uint32 System_Text_DefaultEncoding_InternalCodePage() {
+ return ILGetCodePage();
+}
+
+extern "C" VMObject* System_Reflection_Assembly_GetCallingAssembly() {
+ Assembly* ass = Assembly::getCallingAssembly();
+ assert(ass);
+ return ass->getAssemblyDelegatee();
+}
+
+extern "C" VMObject* System_Reflection_Assembly_GetExecutingAssembly() {
+ Assembly* ass = Assembly::getExecutingAssembly();
+ assert(ass);
+ return ass->getAssemblyDelegatee();
+}
+
+extern "C" uint32 System_Globalization_CultureInfo_InternalCultureID() {
+ return ILGetCultureID();
+}
+
+extern "C" VMObject* System_Globalization_CultureInfo_InternalCultureName() {
+ char* val = ILGetCultureName();
+ N3* vm = (N3*)(VMThread::get()->vm);
+ if (val) {
+ VMObject* ret = vm->asciizToStr(val);
+ free(val);
+ return ret;
+ } else {
+ VMObject* ret = vm->asciizToStr("iv");
+ return ret;
+ }
+}
+
+extern "C" void System_Reflection_Assembly_LoadFromFile() {
+ VMThread::get()->vm->error("implement me");
+}
+
+static const UTF8* newBuilder(N3* vm, PNetString* value, uint32 length) {
+ uint32 valueLength = value ? value->length : 0;
+ const UTF8* utf8 = value ? value->value : 0;
+ uint32 roundLength = (7 + length) & 0xfffffff8;
+ uint16* buf = (uint16*)alloca(roundLength * sizeof(uint16));
+ uint32 strLength = 0;
+
+ if (value != 0) {
+ if (valueLength <= roundLength) {
+ memcpy(buf, utf8->elements, valueLength * sizeof(uint16));
+ strLength = valueLength;
+ } else {
+ memcpy(buf, utf8->elements, roundLength * sizeof(uint16));
+ strLength = roundLength;
+ }
+ }
+
+ return vm->readerConstructUTF8(buf, strLength);
+
+}
+
+extern "C" VMObject* System_String_NewBuilder(PNetString* value,
+ uint32 length) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ PNetString* str = (PNetString*)vm->UTF8ToStr(newBuilder(vm, value, length));
+ return str;
+}
+
+extern "C" VMObject* Platform_SysCharInfo_GetNewLine() {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ return vm->asciizToStr("\n");
+}
+
+extern "C" void System_String_CopyToChecked(PNetString* str, sint32 sstart,
+ ArrayUInt16* dest, sint32 dstart,
+ sint32 count) {
+ const UTF8* value = str->value;
+ memcpy(&dest->elements[dstart], &value->elements[sstart], count << 1);
+}
+
+extern "C" sint32 System_Text_DefaultEncoding_InternalGetMaxByteCount(sint32 val) {
+ return ILAnsiGetMaxByteCount(val);
+}
+
+extern "C" void Platform_Stdio_StdWrite(sint32 fd, ArrayUInt8* value,
+ sint32 index, sint32 count) {
+ if (fd == 1) {
+ if (ILConsoleGetMode() == IL_CONSOLE_NORMAL) {
+ fwrite(&value->elements[index], 1, count, stdout);
+ } else {
+ char* buf = (char*)(&value->elements[index]);
+ while (count > 0) {
+ ILConsoleWriteChar(*buf);
+ ++buf;
+ --count;
+ }
+ fflush(stdout);
+ }
+ } else {
+ fwrite(&value->elements[index], 1, count, stderr);
+ }
+}
+
+extern "C" sint32 System_Text_DefaultEncoding_InternalGetBytes(ArrayUInt16* chars,
+ sint32 charIndex, sint32 charCount, ArrayUInt8* bytes, sint32 byteIndex) {
+
+ return ILAnsiGetBytes(&chars->elements[charIndex], charCount, &bytes->elements[byteIndex], bytes->size - byteIndex);
+}
+
+extern "C" void Platform_Stdio_StdFlush(sint32 fd) {
+ _IL_Stdio_StdFlush(0, fd);
+}
+
+extern "C" void System_Array_InternalCopy(VMArray* src, sint32 sstart,
+ VMArray* dst, sint32 dstart,
+ sint32 len) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ verifyNull(src);
+ verifyNull(dst);
+
+ if (!(src->classOf->isArray && dst->classOf->isArray)) {
+ vm->arrayStoreException();
+ }
+
+ VMClassArray* ts = (VMClassArray*)src->classOf;
+ VMClassArray* td = (VMClassArray*)dst->classOf;
+ VMCommonClass* dstType = td->baseClass;
+ VMCommonClass* srcType = ts->baseClass;
+
+ if (len > src->size) {
+ vm->indexOutOfBounds(src, len);
+ } else if (len > dst->size) {
+ vm->indexOutOfBounds(dst, len);
+ } else if (len + sstart > src->size) {
+ vm->indexOutOfBounds(src, len + sstart);
+ } else if (len + dstart > dst->size) {
+ vm->indexOutOfBounds(dst, len + dstart);
+ } else if (dstart < 0) {
+ vm->indexOutOfBounds(dst, dstart);
+ } else if (sstart < 0) {
+ vm->indexOutOfBounds(src, sstart);
+ } else if (len < 0) {
+ vm->indexOutOfBounds(src, len);
+ }
+
+ bool doThrow = false;
+
+ if (srcType->super == MSCorlib::pValue && srcType != dstType) {
+ vm->arrayStoreException();
+ } else if (srcType->super != MSCorlib::pValue && srcType->super != MSCorlib::pEnum) {
+ sint32 i = sstart;
+ while (i < sstart + len && !doThrow) {
+ VMObject* cur = ((ArrayObject*)src)->at(i);
+ if (cur) {
+ if (!(cur->classOf->isAssignableFrom(dstType))) {
+ doThrow = true;
+ len = i;
+ }
+ }
+ ++i;
+ }
+ }
+
+
+ uint32 size = srcType->naturalType->getPrimitiveSizeInBits() / 8;
+ if (size == 0) size = sizeof(void*);
+ void* ptrDst = (void*)((int64_t)(dst->elements) + size * dstart);
+ void* ptrSrc = (void*)((int64_t)(src->elements) + size * sstart);
+ memmove(ptrDst, ptrSrc, size * len);
+
+ if (doThrow)
+ vm->arrayStoreException();
+
+}
+
+extern "C" sint32 System_Array_GetRank(VMObject* arr) {
+ verifyNull(arr);
+ if (arr->classOf->isArray) {
+ return ((VMClassArray*)(arr->classOf))->dims;
+ } else {
+ VMThread::get()->vm->error("implement me");
+ return 0;
+ }
+}
+
+extern "C" sint32 System_Array_GetLength(VMObject* arr) {
+ verifyNull(arr);
+ if (arr->classOf->isArray) {
+ return ((VMArray*)arr)->size;
+ } else {
+ VMThread::get()->vm->error("implement me");
+ return 0;
+ }
+}
+
+extern "C" sint32 System_Array_GetLowerBound(VMObject* arr, sint32 dim) {
+ return 0;
+}
+
+extern "C" VMObject* System_Object_GetType(VMObject* obj) {
+ verifyNull(obj);
+ return obj->classOf->getClassDelegatee();
+}
+
+extern "C" VMObject* System_Reflection_ClrType_GetElementType(VMObject* Klass) {
+ VMCommonClass* cl = (VMCommonClass*)((*Klass)(MSCorlib::typeClrType).PointerVal);
+ if (!cl->isArray) {
+ VMThread::get()->vm->error("implement me");
+ return 0;
+ } else {
+ return ((VMClassArray*)cl)->baseClass->getClassDelegatee();
+ }
+}
+
+extern "C" PNetString* System_String_NewString(uint32 size) {
+ PNetString* str = (PNetString*)(MSCorlib::pString->doNew());
+ str->length = size;
+ return str;
+}
+
+extern "C" void System_String_Copy_3(PNetString* dest, sint32 pos,
+ PNetString* src) {
+ ArrayUInt16* arr = ArrayUInt16::acons(pos + src->value->size,
+ (VMClassArray*)MSCorlib::pChar);
+
+ for (sint32 i = 0; i < pos; ++i) {
+ arr->setAt(i, dest->value->at(i));
+ }
+
+ for (sint32 i = 0; i < src->length; ++i) {
+ arr->setAt(pos + i, src->value->at(i));
+ }
+
+ dest->value = ((UTF8*)arr)->extract(VMThread::get()->vm, 0, pos + src->value->size);
+ dest->length = dest->value->size;
+}
+
+extern "C" void System_String_Copy_5(PNetString* dest, sint32 destPos,
+ PNetString* src, sint32 srcPos,
+ sint32 length) {
+ const UTF8* utf8Src = src->value->extract(VMThread::get()->vm, srcPos,
+ srcPos + length);
+ if (destPos == 0) {
+ dest->value = utf8Src;
+ dest->length = dest->value->size;
+ } else {
+ const UTF8* utf8Dest = dest->value->extract(VMThread::get()->vm, 0,
+ destPos);
+ sint32 len1 = utf8Dest->size;
+ sint32 len2 = utf8Src->size;
+ uint16* buf = (uint16*)alloca((len1 + len2) * sizeof(uint16));
+
+ memcpy(buf, utf8Dest->elements, len1 * sizeof(uint16));
+ memcpy(buf + len1, utf8Dest->elements, len2 * sizeof(uint16));
+
+ const UTF8* utf8 = VMThread::get()->vm->readerConstructUTF8(buf,
+ len1 + len2);
+ dest->value = utf8;
+ dest->length = dest->value->size;
+ }
+}
+
+extern "C" bool System_String_Equals(PNetString* str1, PNetString* str2) {
+ return str1->value == str2->value;
+}
+
+extern "C" VMObject* System_Threading_Thread_InternalCurrentThread() {
+ return VMThread::get()->vmThread;
+}
+
+extern "C" sint32 Platform_SysCharInfo_GetUnicodeCategory(char c) {
+ return ILGetUnicodeCategory(c);
+}
+
+extern "C" uint16 System_String_GetChar(PNetString* str, sint32 index) {
+ return str->value->at(index);
+}
+
+extern "C" sint32 System_String_IndexOf(PNetString* str, uint16 value,
+ sint32 startIndex, sint32 count) {
+ if (startIndex < 0) {
+ VMThread::get()->vm->error("shoud throw arg range");
+ }
+
+ if ((count < 0) || (str->length - startIndex < count)) {
+ VMThread::get()->vm->error("shoud throw arg range");
+ }
+
+ sint32 i = startIndex;
+ const UTF8* utf8 = str->value;
+ while (i < startIndex + count) {
+ if (utf8->at(i) == value) return i;
+ else ++i;
+ }
+
+ return -1;
+}
+
+extern "C" sint32 System_String_GetHashCode(PNetString* str) {
+ sint32 hash = 0;
+ const UTF8* utf8 = str->value;
+ for (sint32 i = 0; i < utf8->size; ++i) {
+ hash += ((hash << 5) + utf8->elements[i]);
+ }
+ return hash;
+}
+
+extern "C" double System_Decimal_ToDouble(void* ptr) {
+ VMThread::get()->vm->error("implement me");
+ return 0.0;
+}
+
+extern "C" double System_Math_Log10(double val) {
+ return log10(val);
+}
+
+extern "C" double System_Math_Floor(double val) {
+ return floor(val);
+}
+
+extern "C" VMObject* System_Text_StringBuilder_Insert_System_Text_StringBuilder_System_Int32_System_Char(
+ StringBuilder* obj,
+ sint32 index,
+ uint16 value) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ PNetString* buildString = obj->buildString;
+ const UTF8* utf8 = buildString->value;
+ sint32 strLength = buildString->length;
+ sint32 length = (index + 1) > strLength ? index + 1 : strLength + 1;
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+
+ if (index != 0) {
+ memcpy(buf, utf8->elements, index * sizeof(uint16));
+ }
+
+ if (strLength > index) {
+ memcpy(&(buf[index + 1]), &(utf8->elements[index]),
+ (strLength - index) * sizeof(uint16));
+ }
+
+ buf[index] = value;
+ PNetString* str = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
+ obj->buildString = str;
+
+ return obj;
+}
+
+extern "C" VMObject* System_Text_StringBuilder_Insert_System_Text_StringBuilder_System_Int32_System_String(
+ StringBuilder* obj,
+ sint32 index,
+ PNetString* str) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ PNetString* buildString = obj->buildString;
+ const UTF8* strUtf8 = str->value;
+ const UTF8* buildUtf8 = buildString->value;
+ sint32 strLength = str->length;
+ sint32 buildLength = buildString->length;
+ sint32 length = strLength + buildLength;
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+
+ if (index != 0) {
+ memcpy(buf, buildUtf8->elements, index * sizeof(uint16));
+ }
+
+ if (strLength != 0) {
+ memcpy(&(buf[index]), strUtf8->elements, strLength * sizeof(uint16));
+ }
+
+ if (buildLength - index > 0) {
+ memcpy(&(buf[strLength + index]), &(buildUtf8->elements[index]),
+ (buildLength - index) * sizeof(uint16));
+ }
+
+ PNetString* val = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
+ obj->buildString = val;
+
+ return obj;
+}
+
+extern "C" VMObject* System_Text_StringBuilder_Append_System_Text_StringBuilder_System_Char(
+ StringBuilder* obj,
+ uint16 value) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ PNetString* buildString = obj->buildString;
+ const UTF8* utf8 = buildString->value;
+ sint32 length = buildString->length;
+ uint16* buf = (uint16*)alloca((length + 1) * sizeof(uint16));
+
+ memcpy(buf, utf8->elements, length * sizeof(uint16));
+
+ buf[length] = value;
+ PNetString* val = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length + 1));
+ obj->buildString = val;
+ return obj;
+}
+
+
+extern "C" VMObject* System_Text_StringBuilder_Append_System_Text_StringBuilder_System_String(
+ StringBuilder* obj,
+ PNetString* str) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ PNetString* buildString = obj->buildString;
+ const UTF8* buildUtf8 = buildString->value;
+ const UTF8* strUtf8 = str->value;
+ sint32 buildLength = buildString->length;
+ sint32 strLength = str->length;
+ sint32 length = buildLength + strLength;
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+
+ memcpy(buf, buildUtf8->elements, buildLength * sizeof(uint16));
+ memcpy(&(buf[buildLength]), strUtf8->elements, strLength * sizeof(uint16));
+
+ PNetString* val = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
+ obj->buildString = val;
+ return obj;
+}
+
+extern "C" sint32 System_String_FindInRange(PNetString* obj, sint32 srcFirst,
+ sint32 srcLast, sint32 step,
+ PNetString* dest) {
+ uint16* buf1 = (uint16*)&(obj->value->elements[srcFirst]);
+ uint16* buf2 = (uint16*)(dest->value->elements);
+ sint32 destLength = dest->length;
+ sint32 size = destLength * sizeof(uint16);
+
+ if (step > 0) {
+ if (destLength == 1) {
+ while (srcFirst <= srcLast) {
+ if (buf1[0] == buf2[0]) {
+ return srcFirst;
+ } else {
+ buf1 = &(buf1[1]);
+ ++srcFirst;
+ }
+ }
+ } else {
+ while (srcFirst <= srcLast) {
+ if ((buf1[0] == buf2[0]) && !memcmp(buf1, buf2, size)) {
+ return srcFirst;
+ } else {
+ buf1 = &(buf1[1]);
+ ++srcFirst;
+ }
+ }
+ }
+ } else {
+ if (destLength == 1) {
+ while (srcFirst >= srcLast) {
+ if (buf1[0] == buf2[0]) {
+ return srcFirst;
+ } else {
+ buf1 = buf1 - 1;
+ --srcFirst;
+ }
+ }
+ } else {
+ while (srcFirst >= srcLast) {
+ if ((buf1[0] == buf2[0]) && !memcmp(buf1, buf2, size)) {
+ return srcFirst;
+ } else {
+ buf1 = buf1 - 1;
+ --srcFirst;
+ }
+ }
+ }
+ }
+ return -1;
+}
+
+extern "C" VMObject* System_Reflection_Assembly_LoadFromName(PNetString* str, sint32 & error, VMObject* parent) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ Assembly* ass = vm->loadAssembly(str->value, "dll");
+ if (!ass) vm->error("unfound assembly %s\n", str->value->printString());
+ error = 0;
+ return ass->getAssemblyDelegatee();
+}
+
+extern "C" PNetString* System_String_Concat_2(PNetString* str1, PNetString* str2) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ const UTF8* u1 = str1->value;
+ const UTF8* u2 = str2->value;
+ sint32 len1 = str1->length;
+ sint32 len2 = str2->length;
+ uint16* buf = (uint16*)alloca((len1 + len2) * sizeof(uint16));
+
+ memcpy(buf, u1->elements, len1 * sizeof(uint16));
+ memcpy(&(buf[len1]), u2->elements, len2 * sizeof(uint16));
+
+ PNetString* val = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, len1 + len2));
+
+ return val;
+}
+
+extern "C" PNetString* System_String_Concat_3(PNetString* str1, PNetString* str2, PNetString* str3) {
+ N3* vm = (N3*)(VMThread::get()->vm);
+ const UTF8* u1 = str1->value;
+ const UTF8* u2 = str2->value;
+ const UTF8* u3 = str3->value;
+ sint32 len1 = str1->length;
+ sint32 len2 = str2->length;
+ sint32 len3 = str3->length;
+ uint16* buf = (uint16*)alloca((len1 + len2 + len3) * sizeof(uint16));
+
+ memcpy(buf, u1->elements, len1 * sizeof(uint16));
+ memcpy(&(buf[len1]), u2->elements, len2 * sizeof(uint16));
+ memcpy(&(buf[len1 + len2]), u3->elements, len3 * sizeof(uint16));
+
+ PNetString* val = (PNetString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, len1 + len2 + len3));
+
+ return val;
+}
+
+extern "C" void System_String_RemoveSpace(PNetString* str, sint32 index, sint32 length) {
+ const UTF8* utf8 = str->value;
+ sint32 strLength = str->length;
+ uint16* buf = (uint16*)alloca(strLength * sizeof(uint16));
+ sint32 j = index;
+
+ if (index != 0) {
+ memcpy(buf, utf8->elements, index * sizeof(uint16));
+ }
+
+ // 32 is space
+ for (sint32 i = 0; i < length; ++i) {
+ uint16 cur = utf8->elements[index + i];
+ if (cur != 32) {
+ buf[j] = cur;
+ } else {
+ ++j;
+ }
+ }
+
+ if (strLength > (index + length)) {
+ memcpy(&(buf[j]), &(utf8->elements[index + length]), (strLength - (index + length)) * sizeof(uint16));
+ }
+
+ const UTF8* res = VMThread::get()->vm->readerConstructUTF8(buf, j);
+ str->value = res;
+ str->length = j;
+}
+
+extern "C" void System_String__ctor_3(PNetString* str, uint16 ch, sint32 count) {
+ ArrayUInt16* array = ArrayUInt16::acons(count, MSCorlib::arrayChar);
+ for (sint32 i = 0; i < count; ++i) {
+ array->elements[i] = ch;
+ }
+
+ const UTF8* utf8 = VMThread::get()->vm->readerConstructUTF8(array->elements, array->size);
+ str->value = utf8;
+ str->length = array->size;
+ str->capacity = array->size;
+}
+
+extern "C" int64_t Platform_TimeMethods_GetCurrentTime() {
+ return _IL_TimeMethods_GetCurrentTime(0);
+}
+
+#define ASSEMBLY_VALUE(obj) ((Assembly**)obj)[3]
+
+void* sys_memrchr(const void* s, int c, size_t n) {
+ unsigned char* m = (unsigned char*) s + n;
+ for (;;) {
+ if (!(n--)) return NULL;
+ else if (*m-- == (unsigned char)c) return (void*)(m+1);
+ }
+}
+
+extern "C" VMObject* System_Reflection_Assembly_GetType(VMObject* obj, PNetString* str, bool onError, bool ignoreCase) {
+ Assembly* ass = ASSEMBLY_VALUE(obj);
+ const UTF8* utf8 = str->value;
+ char* asciiz = utf8->UTF8ToAsciiz();
+ char* index = (char*)sys_memrchr(asciiz, '.', strlen(asciiz));
+ N3* vm = ass->vm;
+
+ index[0] = 0;
+ ++index;
+ VMCommonClass* cl = ass->loadTypeFromName(vm->asciizConstructUTF8(index), vm->asciizConstructUTF8(asciiz), true, true, true, onError);
+ if (!cl) VMThread::get()->vm->error("implement me");
+ return cl->getClassDelegatee();
+}
+
+static bool parameterMatch(std::vector<VMCommonClass*> params, ArrayObject* types, bool virt) {
+ 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;
+ if (cur != params[i + 1 + v]) return false;
+ }
+ return true;
+}
+
+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);
+ const UTF8* name = str->value;
+ if (memberTypes == MEMBER_TYPES_PROPERTY) {
+ std::vector<Property*, gc_allocator<Property*> > properties =
+ type->properties;
+ Property *res = 0;
+ for (std::vector<Property*, gc_allocator<Property*> >::iterator i = properties.begin(),
+ e = properties.end(); i!= e; ++i) {
+ if ((*i)->name == name) {
+ res = *i;
+ break;
+ }
+ }
+ if (res == 0) VMThread::get()->vm->error("implement me");
+ return res->getPropertyDelegatee();
+ } else if (memberTypes == MEMBER_TYPES_METHOD) {
+ std::vector<VMMethod*> virtualMethods = type->virtualMethods;
+ std::vector<VMMethod*> staticMethods = type->staticMethods;
+
+ for (std::vector<VMMethod*>::iterator i = virtualMethods.begin(),
+ e = virtualMethods.end(); i!= e; ++i) {
+ VMMethod* meth = *i;
+ if (meth->name == name) {
+ if (parameterMatch(meth->parameters, types, true)) {
+ return meth->getMethodDelegatee();
+ }
+ }
+ }
+
+ for (std::vector<VMMethod*>::iterator i = staticMethods.begin(),
+ e = staticMethods.end(); i!= e; ++i) {
+ VMMethod* meth = *i;
+ if (meth->name == name) {
+ if (parameterMatch(meth->parameters, types, false)) {
+ return meth->getMethodDelegatee();
+ }
+ }
+ }
+
+ } else {
+ VMThread::get()->vm->error("implement me");
+ }
+ return 0;
+}
+
+extern "C" VMObject* System_Reflection_ClrHelpers_GetSemantics(mvm::Object* item, uint32 attributes, bool nonPublic) {
+ if (item->getVirtualTable() == Property::VT) {
+ Property* prop = (Property*)item;
+ if (attributes == METHOD_SEMANTIC_ATTRIBUTES_GETTER) {
+ char* asciiz = prop->name->UTF8ToAsciiz();
+ char* buf = (char*)alloca(strlen(asciiz) + 5);
+ sprintf(buf, "get_%s", asciiz);
+ VirtualMachine* vm = VMThread::get()->vm;
+ VMMethod* meth = prop->type->lookupMethod(vm->asciizConstructUTF8(buf), prop->parameters, true, false);
+ assert(meth);
+ return meth->getMethodDelegatee();
+ }
+ } else {
+ VMThread::get()->vm->error("implement me");
+ }
+ return 0;
+}
+
+static void decapsulePrimitive(VMObject* arg, const llvm::Type* type, std::vector<llvm::GenericValue>& args) {
+ if (type == llvm::Type::Int1Ty) {
+ llvm::GenericValue gv;
+ gv.IntVal = llvm::APInt(1, (bool)((uint32*)arg)[VALUE_OFFSET]);
+ args.push_back(gv);
+ } else if (type == llvm::Type::Int8Ty) {
+ llvm::GenericValue gv;
+ gv.IntVal = llvm::APInt(8, (uint8)((uint32*)arg)[VALUE_OFFSET]);
+ args.push_back(gv);
+ } else if (type == llvm::Type::Int16Ty) {
+ llvm::GenericValue gv;
+ gv.IntVal = llvm::APInt(16, (uint16)((uint32*)arg)[VALUE_OFFSET]);
+ args.push_back(gv);
+ } else if (type == llvm::Type::Int32Ty) {
+ llvm::GenericValue gv;
+ gv.IntVal = llvm::APInt(32, (uint32)((uint32*)arg)[VALUE_OFFSET]);
+ args.push_back(gv);
+ } else if (type == llvm::Type::Int64Ty) {
+ llvm::GenericValue gv;
+ uint32* ptr = &((uint32*)arg)[VALUE_OFFSET];
+ gv.IntVal = llvm::APInt(64, ((uint64*)ptr)[0]);
+ args.push_back(gv);
+ } else if (type == llvm::Type::FloatTy) {
+ llvm::GenericValue gv;
+ float* ptr = &((float*)arg)[VALUE_OFFSET];
+ gv.FloatVal = ((float*)ptr)[0];
+ args.push_back(gv);
+ } else if (type == llvm::Type::DoubleTy) {
+ llvm::GenericValue gv;
+ uint32* ptr = &((uint32*)arg)[VALUE_OFFSET];
+ gv.DoubleVal = ((double*)ptr)[0];
+ args.push_back(gv);
+ } else if (type == llvm::PointerType::getUnqual(llvm::Type::Int8Ty)) {
+ llvm::GenericValue gv(((void**)arg)[VALUE_OFFSET]);
+ args.push_back(gv);
+ } else {
+ VMThread::get()->vm->error("implement me");
+ }
+}
+
+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;
+ meth->getSignature();
+ meth->compiledPtr();
+ llvm::Function* func = CLIJit::compile(meth->classDef, meth);
+ VMClass* type = meth->classDef;
+ type->resolveStatic(true);
+ uint32 virt = meth->virt;
+
+ if ((obj != 0) && virt) {
+ if (!(obj->classOf->isAssignableFrom(type))) {
+ VMThread::get()->vm->illegalArgumentException(meth->name->printString());
+ }
+ verifyNull(obj);
+ }
+
+ std::vector<llvm::GenericValue> gvargs;
+ uint32 index = 0;
+
+ llvm::Function::arg_iterator i = func->arg_begin();
+ llvm::Function::arg_iterator e = func->arg_end();
+ if (virt) {
+ llvm::GenericValue gv(obj);
+ gvargs.push_back(gv);
+ ++i;
+ }
+
+ for ( ;i != e; ++i, ++index) {
+ const llvm::Type* type = i->getType();
+ if (llvm::isa<llvm::PointerType>(type) && type != llvm::PointerType::getUnqual(llvm::Type::Int8Ty)) {
+ llvm::GenericValue gv(args->elements[index]);
+ gvargs.push_back(gv);
+ } else {
+ decapsulePrimitive(args->elements[index], type, gvargs);
+ }
+ }
+
+ llvm::GenericValue gv;
+ try{
+ gv = (*meth)(gvargs);
+ }catch(...) {
+ assert(0);
+ }
+
+ VMObject* res = 0;
+ VMCommonClass* retType = meth->parameters[0];
+ 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 {
+ if (retType->super == MSCorlib::pValue || retType->super == MSCorlib::pEnum)
+ VMThread::get()->vm->error("implement me");
+ res = (VMObject*)gv.PointerVal;
+ }
+
+ return res;
+}
+
+
+static VMObject* createResourceStream(Assembly* ass, sint32 posn) {
+ uint32 resSize = ass->resSize;
+ uint32 resRva = ass->resRva;
+ Section* textSection = ass->textSection;
+ uint32 sectionLen = resSize;
+ uint32 section = 0;
+ uint32 start = 0;
+ uint32 length = 0;
+ uint32 pad = 0;
+
+ Reader* reader = Reader::allocateReader(ass->bytes);
+ section = textSection->rawAddress + (resRva - textSection->virtualAddress);
+
+ reader->seek(section, Reader::SeekSet);
+ while (posn > 0) {
+ if (sectionLen < 4) return 0;
+ length = reader->readU4();
+ if (length > (sectionLen - 4)) return 0;
+ if ((length % 4) != 0) {
+ pad = 4 - (length % 4);
+ } else {
+ pad = 0;
+ }
+ start = start + length + pad + 4;
+ section = section + length + pad + 4;
+ reader->seek(section + length + pad + 4, Reader::SeekSet);
+ sectionLen = sectionLen - (length + pad + 4);
+ posn = posn - 1;
+ }
+
+ start = start + 4;
+ if (sectionLen < 4) return 0;
+ length = reader->readU4();
+ if (length > (sectionLen - 4)) return 0;
+
+ VMObject* res = (*MSCorlib::resourceStreamType)();
+ (*MSCorlib::ctorResourceStreamType)(res, ass, (uint64)start, (uint64)length);
+
+ return res;
+}
+
+extern "C" VMObject* System_Reflection_Assembly_GetManifestResourceStream(VMObject* Ass, PNetString* str) {
+ Assembly* ass = (Assembly*)(*MSCorlib::assemblyAssemblyReflection)(Ass).PointerVal;
+ const UTF8* utf8 = str->value;
+ Header* header = ass->CLIHeader;
+ uint32 stringOffset = header->stringStream->realOffset;
+ Table* manTable = header->tables[CONSTANT_ManifestResource];
+ uint32 manRows = manTable->rowsNumber;
+ sint32 pos = -1;
+ uint32 i = 0;
+ VirtualMachine* vm = VMThread::get()->vm;
+
+ while ((pos == -1) && (i < manRows)) {
+ uint32 nameOffset = manTable->readIndexInRow(i + 1, CONSTANT_MANIFEST_RESOURCE_NAME, ass->bytes);
+ const UTF8* name = ass->readString(vm, stringOffset + nameOffset);
+
+ if (name == utf8) {
+ pos = i;
+ } else {
+ ++i;
+ }
+ }
+
+ if (pos != -1) {
+ return createResourceStream(ass, pos);
+ } else {
+ return 0;
+ }
+}
+
+
+extern "C" ArrayObject* System_Reflection_ClrHelpers_GetCustomAttributes(Assembly* ass, VMCommonClass* clrTypePrivate, bool inherit) {
+ return ass->getCustomAttributes(clrTypePrivate->token, clrTypePrivate);
+}
+
+extern "C" VMObject* System_Globalization_TextInfo_ToLower(VMObject* obj, PNetString* str) {
+ verifyNull(str);
+ const UTF8* utf8 = str->value;
+ uint32 length = str->length;
+
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+
+ VirtualMachine* vm = VMThread::get()->vm;
+
+ memcpy(buf, utf8->elements, length * sizeof(uint16));
+ ILUnicodeStringToLower((void*)buf, (void*)utf8->elements, length);
+ const UTF8* res = vm->readerConstructUTF8(buf, length);
+ return ((N3*)vm)->UTF8ToStr(res);
+}
+
+extern "C" VMObject* System_String_Replace(PNetString* str, uint16 c1, uint16 c2) {
+ const UTF8* utf8 = str->value;
+ uint32 length = str->length;
+ if ((c1 == c2) || length == 0) return str;
+
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+ memcpy(buf, utf8->elements, length * sizeof(uint16));
+ for (uint32 i = 0; i < length; ++i) {
+ if (buf[i] == c1) buf[i] = c2;
+ }
+
+ N3* vm = (N3*)VMThread::get()->vm;
+ const UTF8* res = vm->readerConstructUTF8(buf, length);
+ return vm->UTF8ToStr(res);
+}
+
+extern "C" uint32 System_Reflection_ClrResourceStream_ResourceRead(Assembly* assembly, uint64 position, ArrayUInt8* buffer, uint32 offset, uint32 count) {
+ uint32 resRva = assembly->resRva;
+ ArrayUInt8* bytes = assembly->bytes;
+ Section* textSection = assembly->textSection;
+ uint32 section = 0;
+
+ section = textSection->rawAddress + (resRva - textSection->virtualAddress);
+ memcpy(&(buffer->elements[offset]), &(bytes->elements[section + position]), count);
+
+ return count;
+}
+
+extern "C" sint32 System_String_CompareInternal(PNetString* strA, sint32 indexA, sint32 lengthA, PNetString* strB, sint32 indexB, sint32 lengthB, bool ignoreCase) {
+ if (strA == 0) {
+ if (strB == 0) {
+ return 0;
+ }
+ return -1;
+ } else if (strB == 0) {
+ return 1;
+ } else {
+ sint32 cmp = 0;
+ if (lengthA >= lengthB) {
+ if (ignoreCase) {
+ cmp = ILUnicodeStringCompareIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthB);
+ } else {
+ cmp = ILUnicodeStringCompareNoIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthB);
+ }
+
+ if (cmp != 0) return cmp;
+ else if (lengthA > lengthB) return 1;
+ else return 0;
+ } else {
+ if (ignoreCase) {
+ cmp = ILUnicodeStringCompareIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthA);
+ } else {
+ cmp = ILUnicodeStringCompareNoIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthA);
+ }
+
+ if (cmp != 0) return cmp;
+ else return -1;
+ }
+ }
+}
+
+extern "C" void System_String_CharFill(PNetString* str, sint32 start, sint32 count, char ch) {
+ const UTF8* utf8 = str->value;
+ sint32 length = start + count;
+ uint16* buf = (uint16*)alloca(length * sizeof(uint16));
+
+ memcpy(buf, utf8->elements, start * sizeof(uint16));
+ for (sint32 i = 0; i < count; ++i) {
+ buf[i + start] = ch;
+ }
+
+ VirtualMachine* vm = VMThread::get()->vm;
+ const UTF8* val = vm->readerConstructUTF8(buf, length);
+ str->value = val;
+ str->length = length;
+}
+
+
+extern "C" sint32 System_String_InternalOrdinal(PNetString *strA, sint32 indexA, sint32 lengthA,
+ PNetString *strB, sint32 indexB, sint32 lengthB) {
+ const uint16 *bufA;
+ const uint16 *bufB;
+
+ /* Handle the easy cases first */
+ if(!strA)
+ {
+ if(!strB)
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else if(!strB)
+ {
+ return 1;
+ }
+
+ /* Compare the two strings */
+ bufA = &(strA->value->elements[indexA]);
+ bufB = &(strB->value->elements[indexB]);
+ while(lengthA > 0 && lengthB > 0)
+ {
+ if(*bufA < *bufB)
+ {
+ return -1;
+ }
+ else if(*bufA > *bufB)
+ {
+ return 1;
+ }
+ ++bufA;
+ ++bufB;
+ --lengthA;
+ --lengthB;
+ }
+
+ /* Determine the ordering based on the tail sections */
+ if(lengthA > 0)
+ {
+ return 1;
+ }
+ else if(lengthB > 0)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+extern "C" void System_GC_Collect() {
+#ifdef MULTIPLE_GC
+ mvm::Thread::get()->GC->collect();
+#else
+ Collector::collect();
+#endif
+}
+
+
+
+void NativeUtil::initialise() {
+ intptr_t p;
+ p = (intptr_t)&System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray;
+}
Added: vmkit/trunk/lib/N3/PNetLib/PNetLib.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.h?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetLib.h (added)
+++ vmkit/trunk/lib/N3/PNetLib/PNetLib.h Tue Jul 1 08:41:02 2008
@@ -0,0 +1,30 @@
+//===----------------- PNetLib.h - PNetLib interface ----------------------===//
+//
+// N3
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef N3_PNETLIB_H
+#define N3_PNETLIB_H
+
+#include "VMObject.h"
+
+
+namespace n3 {
+
+class PNetString;
+
+class StringBuilder : public VMObject {
+public:
+ PNetString* buildString;
+ sint32 maxCapactiy;
+ sint32 needsCopy;
+};
+
+}
+
+#endif
Added: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp (added)
+++ vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp Tue Jul 1 08:41:02 2008
@@ -0,0 +1,129 @@
+//===----- PNetMSCorlib.cpp - The Pnet MSCorlib implementation ------------===//
+//
+// N3
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "mvm/JIT.h"
+
+#include "Assembly.h"
+#include "MSCorlib.h"
+#include "N3.h"
+#include "VMClass.h"
+#include "VMObject.h"
+
+using namespace n3;
+
+void MSCorlib::loadStringClass(N3* vm) {
+ VMClass* type = (VMClass*)vm->coreAssembly->loadTypeFromName(
+ vm->asciizConstructUTF8("String"),
+ vm->asciizConstructUTF8("System"),
+ false, false, false, true);
+ MSCorlib::pString = type;
+ type->resolveType(false, false);
+
+ uint64 size = mvm::jit::getTypeSize(type->virtualType->getContainedType(0)) + sizeof(const UTF8*) + sizeof(llvm::GlobalVariable*);
+ type->virtualInstance =
+ (VMObject*)gc::operator new(size, type->virtualInstance->getVirtualTable());
+ type->virtualInstance->initialise(type);
+}
+
+
+void MSCorlib::initialise(N3* vm) {
+ #define INIT(var, nameSpace, name, type, prim) {\
+ var = (VMClass*)vm->coreAssembly->loadTypeFromName( \
+ vm->asciizConstructUTF8(name), \
+ vm->asciizConstructUTF8(nameSpace),\
+ false, false, false, true); \
+ var->isPrimitive = prim; \
+ if (type) { \
+ var->naturalType = type; \
+ var->virtualType = type; \
+ }}
+
+ INIT(MSCorlib::clrType, "System.Reflection", "ClrType", 0, false);
+ INIT(MSCorlib::assemblyReflection, "System.Reflection", "Assembly", 0, false);
+ INIT(MSCorlib::typedReference, "System", "TypedReference", 0, false);
+ INIT(MSCorlib::propertyType, "System.Reflection", "ClrProperty", 0, false);
+ INIT(MSCorlib::methodType, "System.Reflection", "ClrMethod", 0, false);
+ INIT(MSCorlib::resourceStreamType, "System.Reflection", "ClrResourceStream", 0, false);
+
+#undef INIT
+
+ {
+ MSCorlib::clrType->resolveType(false, false);
+ std::vector<VMCommonClass*> args;
+ args.push_back(MSCorlib::pVoid);
+ args.push_back(MSCorlib::clrType);
+ MSCorlib::ctorClrType = MSCorlib::clrType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
+ MSCorlib::typeClrType = MSCorlib::clrType->lookupField(vm->asciizConstructUTF8("privateData"), MSCorlib::pIntPtr, false, false);
+ }
+
+ {
+ MSCorlib::assemblyReflection->resolveType(false, false);
+ std::vector<VMCommonClass*> args;
+ args.push_back(MSCorlib::pVoid);
+ args.push_back(MSCorlib::assemblyReflection);
+ MSCorlib::ctorAssemblyReflection = MSCorlib::assemblyReflection->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
+ MSCorlib::assemblyAssemblyReflection = MSCorlib::assemblyReflection->lookupField(vm->asciizConstructUTF8("privateData"), MSCorlib::pIntPtr, false, false);
+ }
+
+ {
+ MSCorlib::propertyType->resolveType(false, false);
+ std::vector<VMCommonClass*> args;
+ args.push_back(MSCorlib::pVoid);
+ args.push_back(MSCorlib::propertyType);
+ MSCorlib::ctorPropertyType = MSCorlib::propertyType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
+ MSCorlib::propertyPropertyType = MSCorlib::propertyType->lookupField(vm->asciizConstructUTF8("privateData"), MSCorlib::pIntPtr, false, false);
+ }
+
+ {
+ MSCorlib::methodType->resolveType(false, false);
+ std::vector<VMCommonClass*> args;
+ args.push_back(MSCorlib::pVoid);
+ args.push_back(MSCorlib::methodType);
+ MSCorlib::ctorMethodType = MSCorlib::methodType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
+ MSCorlib::methodMethodType = MSCorlib::methodType->lookupField(vm->asciizConstructUTF8("privateData"), MSCorlib::pIntPtr, false, false);
+ }
+
+ {
+ MSCorlib::resourceStreamType->resolveType(false, false);
+ std::vector<VMCommonClass*> args;
+ args.push_back(MSCorlib::pVoid);
+ args.push_back(MSCorlib::resourceStreamType);
+ args.push_back(MSCorlib::pIntPtr);
+ args.push_back(MSCorlib::pSInt64);
+ args.push_back(MSCorlib::pSInt64);
+ MSCorlib::ctorResourceStreamType = MSCorlib::resourceStreamType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
+ }
+
+ VMCommonClass* voidPtr = vm->coreAssembly->constructPointer(MSCorlib::pVoid, 1);
+#define INIT(var, cl, type) {\
+ cl->resolveType(false, false); \
+ var = cl->lookupField(vm->asciizConstructUTF8("value_"), type, false, false); \
+ }
+
+ INIT(MSCorlib::ctorBoolean, MSCorlib::pBoolean, MSCorlib::pBoolean);
+ INIT(MSCorlib::ctorUInt8, MSCorlib::pUInt8, MSCorlib::pUInt8);
+ INIT(MSCorlib::ctorSInt8, MSCorlib::pSInt8, MSCorlib::pSInt8);
+ INIT(MSCorlib::ctorChar, MSCorlib::pChar, MSCorlib::pChar);
+ INIT(MSCorlib::ctorSInt16, MSCorlib::pSInt16, MSCorlib::pSInt16);
+ INIT(MSCorlib::ctorUInt16, MSCorlib::pUInt16, MSCorlib::pUInt16);
+ INIT(MSCorlib::ctorSInt32, MSCorlib::pSInt32, MSCorlib::pSInt32);
+ INIT(MSCorlib::ctorUInt32, MSCorlib::pUInt32, MSCorlib::pUInt32);
+ INIT(MSCorlib::ctorSInt64, MSCorlib::pSInt64, MSCorlib::pSInt64);
+ INIT(MSCorlib::ctorUInt64, MSCorlib::pUInt64, MSCorlib::pUInt64);
+ INIT(MSCorlib::ctorIntPtr, MSCorlib::pIntPtr, voidPtr);
+ INIT(MSCorlib::ctorUIntPtr, MSCorlib::pUIntPtr, voidPtr);
+ INIT(MSCorlib::ctorDouble, MSCorlib::pDouble, MSCorlib::pDouble);
+ INIT(MSCorlib::ctorFloat, MSCorlib::pFloat, MSCorlib::pFloat);
+
+#undef INIT
+
+
+}
+
Added: vmkit/trunk/lib/N3/PNetLib/PNetString.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetString.cpp?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetString.cpp (added)
+++ vmkit/trunk/lib/N3/PNetLib/PNetString.cpp Tue Jul 1 08:41:02 2008
@@ -0,0 +1,40 @@
+//===--- PNetString.cpp - Implementation of PNet string interface ---------===//
+//
+// N3
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CLIString.h"
+#include "MSCorlib.h"
+#include "N3.h"
+#include "PNetString.h"
+#include "VMArray.h"
+#include "VMClass.h"
+#include "VMThread.h"
+
+using namespace n3;
+
+
+CLIString* CLIString::stringDup(const UTF8*& utf8, N3* vm) {
+ PNetString* obj = (PNetString*)(*MSCorlib::pString)();
+ obj->capacity = utf8->size;
+ obj->length = utf8->size;
+ if (utf8->size == 0) {
+ obj->firstChar = 0;
+ } else {
+ obj->firstChar = utf8->at(0);
+ }
+ obj->value = utf8;
+ return obj;
+}
+
+char* CLIString::strToAsciiz() {
+ return ((PNetString*)this)->value->UTF8ToAsciiz();
+}
+
+const UTF8* CLIString::strToUTF8(N3* vm) {
+ return ((PNetString*)this)->value;
+}
Added: vmkit/trunk/lib/N3/PNetLib/PNetString.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetString.h?rev=52958&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetString.h (added)
+++ vmkit/trunk/lib/N3/PNetLib/PNetString.h Tue Jul 1 08:41:02 2008
@@ -0,0 +1,38 @@
+//===---------- PNetString.h - String representation in PNet --------------===//
+//
+// N3
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef N3_PNET_STRING_H
+#define N3_PNET_STRING_H
+
+#include "llvm/GlobalVariable.h"
+
+#include "types.h"
+#include "mvm/PrintBuffer.h"
+
+#include "CLIString.h"
+
+namespace n3 {
+
+class UTF8;
+
+class PNetString : public CLIString {
+public:
+
+ // !!! pnetlib layout !!!
+ sint32 capacity;
+ sint32 length;
+ uint8 firstChar;
+ const UTF8* value;
+ llvm::GlobalVariable* _llvmVar;
+
+};
+
+} // end namespace n3
+
+#endif
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Tue Jul 1 08:41:02 2008
@@ -14,8 +14,8 @@
#include "Assembly.h"
#include "CLIAccess.h"
-#include "CLIString.h"
#include "LockedMap.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "Reader.h"
#include "VirtualMachine.h"
@@ -1163,7 +1163,7 @@
uint32 start = meth->virt ? 1 : 0;
for (uint32 i = start + 1; i < meth->parameters.size(); ++i) {
- if (meth->parameters[i] == N3::pSInt32) {
+ if (meth->parameters[i] == MSCorlib::pSInt32) {
llvm::GenericValue gv;
gv.IntVal = llvm::APInt(32, READ_U4(bytes, offset));
args.push_back(gv);
@@ -1211,7 +1211,7 @@
}
}
- ArrayObject* res = ArrayObject::acons(vec.size(), N3::arrayObject);
+ ArrayObject* res = ArrayObject::acons(vec.size(), MSCorlib::arrayObject);
for (uint32 i = 0; i < vec.size(); ++i)
res->elements[i] = vec[i];
Modified: vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/BackTrace.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/BackTrace.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/BackTrace.cpp Tue Jul 1 08:41:02 2008
@@ -17,7 +17,6 @@
#include "Assembly.h"
#include "CLIJit.h"
-#include "CLIString.h"
#include "N3.h"
#include "N3ModuleProvider.h"
#include "VMClass.h"
Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Tue Jul 1 08:41:02 2008
@@ -33,7 +33,7 @@
#include "Assembly.h"
#include "CLIAccess.h"
#include "CLIJit.h"
-#include "CLIString.h"
+#include "MSCorlib.h"
#include "NativeUtil.h"
#include "N3.h"
#include "N3ModuleProvider.h"
@@ -64,13 +64,13 @@
e = cl->virtualFields.end(); i!= e; ++i) {
VMField* field = *i;
- if (field->signature->super == N3::pValue) {
+ if (field->signature->super == MSCorlib::pValue) {
if (!field->signature->isPrimitive) {
Value* ptr = GetElementPtrInst::Create(arg, field->offset, "",
block);
traceStruct(field->signature, block, ptr);
- } else if (field->signature == N3::pIntPtr ||
- field->signature == N3::pUIntPtr) {
+ } else if (field->signature == MSCorlib::pIntPtr ||
+ field->signature == MSCorlib::pUIntPtr) {
Value* valCast = new BitCastInst(arg, VMObject::llvmType, "", block);
#ifdef MULTIPLE_GC
std::vector<Value*> Args;
@@ -82,7 +82,7 @@
CallInst::Create(CLIJit::markAndTraceLLVM, valCast, "", block);
#endif
}
- } else if (field->signature->super != N3::pEnum) {
+ } else if (field->signature->super != MSCorlib::pEnum) {
Value* valCast = new BitCastInst(arg, VMObject::llvmType, "", block);
#ifdef MULTIPLE_GC
std::vector<Value*> Args;
@@ -109,7 +109,7 @@
for (std::vector<VMField*>::iterator i = fields.begin(),
e = fields.end(); i!= e; ++i) {
VMField* field = *i;
- if (field->signature->super == N3::pValue) {
+ if (field->signature->super == MSCorlib::pValue) {
std::vector<Value*> args; //size = 2
args.push_back(zero);
if (boxed) {
@@ -120,7 +120,7 @@
Value* ptr = GetElementPtrInst::Create(arg, args.begin(), args.end(), "",
block);
traceStruct(field->signature, block, ptr);
- } else if (field->signature->super != N3::pEnum) {
+ } else if (field->signature->super != MSCorlib::pEnum) {
std::vector<Value*> args; //size = 2
args.push_back(zero);
if (boxed) {
@@ -206,9 +206,9 @@
GetElementPtrInst::Create(ptr_v, ptr_tmp3_indices.begin(),
ptr_tmp3_indices.end(), "tmp3", label_bb);
- if (cl->baseClass->super == N3::pValue) {
+ if (cl->baseClass->super == MSCorlib::pValue) {
traceStruct(cl->baseClass, label_bb, ptr_tmp3);
- } else if (cl->baseClass->super != N3::pEnum) {
+ } else if (cl->baseClass->super != MSCorlib::pEnum) {
LoadInst* ptr_tmp4 = new LoadInst(ptr_tmp3, "tmp4", false, label_bb);
Value* arg = new BitCastInst(ptr_tmp4, VMObject::llvmType, "", label_bb);
#ifdef MULTIPLE_GC
@@ -282,7 +282,7 @@
}
#endif
- traceClass(cl, block, realArg, fields, (cl->super == N3::pValue && !stat));
+ traceClass(cl, block, realArg, fields, (cl->super == MSCorlib::pValue && !stat));
ReturnInst::Create(block);
void* tracer = mvm::jit::executionEngine->getPointerToGlobal(func);
@@ -605,7 +605,7 @@
res = invoke(func, Args, "", currentBlock, meth->structReturn);
}
- if (meth->parameters[0] != N3::pVoid) {
+ if (meth->parameters[0] != MSCorlib::pVoid) {
push(res);
}
}
@@ -635,7 +635,7 @@
push(invoke(arrayMultiConsLLVM, Args, "", currentBlock, false));
return;
- } else if (type->super == N3::pValue || type->super == N3::pEnum) {
+ } else if (type->super == MSCorlib::pValue || type->super == MSCorlib::pEnum) {
obj = new AllocaInst(type->naturalType, "", currentBlock);
uint64 size = mvm::jit::getTypeSize(type->naturalType);
@@ -668,7 +668,7 @@
invoke(func, Args, "", currentBlock, meth->structReturn);
}
- if ((type->super == N3::pValue || type->super == N3::pEnum) &&
+ if ((type->super == MSCorlib::pValue || type->super == MSCorlib::pEnum) &&
type->virtualFields.size() == 1) {
push(new LoadInst(obj, "", currentBlock));
} else {
@@ -679,14 +679,14 @@
llvm::Value* CLIJit::getVirtualField(uint32 value) {
VMField* field = compilingClass->assembly->getFieldFromToken(value, false);
Value* obj = pop();
- if ((field->classDef->super == N3::pValue ||
- field->classDef->super == N3::pEnum) &&
+ if ((field->classDef->super == MSCorlib::pValue ||
+ field->classDef->super == MSCorlib::pEnum) &&
field->classDef->virtualFields.size() == 1){
// struct!
return obj;
} else {
- if (field->classDef->super != N3::pValue &&
- field->classDef->super != N3::pEnum) {
+ if (field->classDef->super != MSCorlib::pValue &&
+ field->classDef->super != MSCorlib::pEnum) {
obj = new BitCastInst(obj, field->classDef->naturalType, "",
currentBlock);
}
@@ -725,14 +725,14 @@
Value* ptr = 0;
const Type* type = obj->getType();
- if ((field->classDef->super == N3::pValue ||
- field->classDef->super == N3::pEnum) &&
+ if ((field->classDef->super == MSCorlib::pValue ||
+ field->classDef->super == MSCorlib::pEnum) &&
field->classDef->virtualFields.size() == 1){
// struct!
ptr = obj;
} else {
- if (field->classDef->super != N3::pValue &&
- field->classDef->super != N3::pEnum) {
+ if (field->classDef->super != MSCorlib::pValue &&
+ field->classDef->super != MSCorlib::pEnum) {
obj = new BitCastInst(obj, field->classDef->naturalType, "", currentBlock);
}
std::vector<Value*> args;
@@ -884,7 +884,7 @@
assert(i == e);
BasicBlock* entry = createBasicBlock("entry");
- obj = new BitCastInst(obj, N3::pDelegate->virtualType, "", entry);
+ obj = new BitCastInst(obj, MSCorlib::pDelegate->virtualType, "", entry);
std::vector<Value*> elts;
elts.push_back(mvm::jit::constantZero);
elts.push_back(mvm::jit::constantOne);
@@ -911,7 +911,7 @@
PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "intern compile %s\n",
compilingMethod->printString());
- if (compilingClass->subclassOf(N3::pDelegate)) {
+ if (compilingClass->subclassOf(MSCorlib::pDelegate)) {
const UTF8* name = compilingMethod->name;
if (name == N3::ctorName) return createDelegate();
else if (name == N3::invokeName) return invokeDelegate();
@@ -1016,7 +1016,7 @@
ex->catchClass = ass->loadType((N3*)VMThread::get()->vm, classToken,
true, false, false, true);
} else {
- ex->catchClass = N3::pException;
+ ex->catchClass = MSCorlib::pException;
}
opcodeInfos[ex->handlerOffset].reqSuppl = true;
exceptions.push_back(ex);
Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Tue Jul 1 08:41:02 2008
@@ -9,6 +9,7 @@
#include "Assembly.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "Reader.h"
#include "VMClass.h"
@@ -24,59 +25,59 @@
}
static VMCommonClass* METHOD_ElementTypeVoid(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pVoid;
+ return MSCorlib::pVoid;
}
static VMCommonClass* METHOD_ElementTypeBoolean(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pBoolean;
+ return MSCorlib::pBoolean;
}
static VMCommonClass* METHOD_ElementTypeChar(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pChar;
+ return MSCorlib::pChar;
}
static VMCommonClass* METHOD_ElementTypeI1(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pSInt8;
+ return MSCorlib::pSInt8;
}
static VMCommonClass* METHOD_ElementTypeU1(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pUInt8;
+ return MSCorlib::pUInt8;
}
static VMCommonClass* METHOD_ElementTypeI2(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pSInt16;
+ return MSCorlib::pSInt16;
}
static VMCommonClass* METHOD_ElementTypeU2(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pUInt16;
+ return MSCorlib::pUInt16;
}
static VMCommonClass* METHOD_ElementTypeI4(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pSInt32;
+ return MSCorlib::pSInt32;
}
static VMCommonClass* METHOD_ElementTypeU4(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pUInt32;
+ return MSCorlib::pUInt32;
}
static VMCommonClass* METHOD_ElementTypeI8(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pSInt64;
+ return MSCorlib::pSInt64;
}
static VMCommonClass* METHOD_ElementTypeU8(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pUInt64;
+ return MSCorlib::pUInt64;
}
static VMCommonClass* METHOD_ElementTypeR4(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pFloat;
+ return MSCorlib::pFloat;
}
static VMCommonClass* METHOD_ElementTypeR8(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pDouble;
+ return MSCorlib::pDouble;
}
static VMCommonClass* METHOD_ElementTypeString(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pString;
+ return MSCorlib::pString;
}
static VMCommonClass* METHOD_ElementTypePtr(uint32 op, Assembly* ass, uint32& offset) {
@@ -220,15 +221,15 @@
}
static VMCommonClass* METHOD_ElementTypeTypedByRef(uint32 op, Assembly* ass, uint32& offset) {
- return N3::typedReference;
+ return MSCorlib::typedReference;
}
static VMCommonClass* METHOD_ElementTypeI(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pIntPtr;
+ return MSCorlib::pIntPtr;
}
static VMCommonClass* METHOD_ElementTypeU(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pUIntPtr;
+ return MSCorlib::pUIntPtr;
}
static VMCommonClass* METHOD_ElementTypeFnptr(uint32 op, Assembly* ass, uint32& offset) {
@@ -237,7 +238,7 @@
}
static VMCommonClass* METHOD_ElementTypeObject(uint32 op, Assembly* ass, uint32& offset) {
- return N3::pObject;
+ return MSCorlib::pObject;
}
static VMCommonClass* METHOD_ElementTypeSzarray(uint32 op, Assembly* ass, uint32& offset) {
Removed: vmkit/trunk/lib/N3/VMCore/CLIString.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIString.cpp?rev=52957&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIString.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIString.cpp (removed)
@@ -1,38 +0,0 @@
-//===---- CLIString.cpp - Internal correspondance with CLI Strings --------===//
-//
-// N3
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "CLIString.h"
-#include "N3.h"
-#include "VMArray.h"
-#include "VMClass.h"
-#include "VMThread.h"
-
-using namespace n3;
-
-
-CLIString* CLIString::stringDup(const UTF8*& utf8, N3* vm) {
- CLIString* obj = (CLIString*)(*N3::pString)();
- obj->capacity = utf8->size;
- obj->length = utf8->size;
- if (utf8->size == 0) {
- obj->firstChar = 0;
- } else {
- obj->firstChar = utf8->at(0);
- }
- obj->value = utf8;
- return obj;
-}
-
-char* CLIString::strToAsciiz() {
- return value->UTF8ToAsciiz();
-}
-
-const UTF8* CLIString::strToUTF8(N3* vm) {
- return value;
-}
Modified: vmkit/trunk/lib/N3/VMCore/CLIString.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIString.h?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIString.h (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIString.h Tue Jul 1 08:41:02 2008
@@ -30,12 +30,6 @@
}
virtual void TRACER;
- // !!! pnetlib layout !!!
- sint32 capacity;
- sint32 length;
- uint8 firstChar;
- const UTF8* value;
- llvm::GlobalVariable* _llvmVar;
llvm::GlobalVariable* llvmVar();
Modified: vmkit/trunk/lib/N3/VMCore/LockedMap.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/LockedMap.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/LockedMap.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/LockedMap.cpp Tue Jul 1 08:41:02 2008
@@ -10,8 +10,8 @@
#include <map>
#include "Assembly.h"
-#include "CLIString.h"
#include "LockedMap.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "VMArray.h"
#include "VMClass.h"
@@ -75,7 +75,7 @@
}
if (res == 0) {
- UTF8* tmp = UTF8::acons(size, N3::arrayChar);
+ UTF8* tmp = UTF8::acons(size, MSCorlib::arrayChar);
for (sint32 i = 0; i < size; i++) {
tmp->setAt(i, asciiz[i]);
}
@@ -103,7 +103,7 @@
}
if (res == 0) {
- UTF8* tmp = UTF8::acons(size, N3::arrayChar);
+ UTF8* tmp = UTF8::acons(size, MSCorlib::arrayChar);
memcpy(tmp->elements, buf, len * sizeof(uint16));
res = (const UTF8*)tmp;
map.insert(std::make_pair(key, res));
Modified: vmkit/trunk/lib/N3/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/LockedMap.h?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/N3/VMCore/LockedMap.h Tue Jul 1 08:41:02 2008
@@ -21,12 +21,12 @@
#include "types.h"
+#include "CLIString.h"
#include "VMArray.h"
namespace n3 {
class Assembly;
-class CLIString;
class N3;
class VMClass;
class VMCommonClass;
Modified: vmkit/trunk/lib/N3/VMCore/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Makefile?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Makefile (original)
+++ vmkit/trunk/lib/N3/VMCore/Makefile Tue Jul 1 08:41:02 2008
@@ -8,8 +8,5 @@
##===----------------------------------------------------------------------===##
LEVEL = ../../..
-CXX.Flags += -Wno-unused
LIBRARYNAME = N3
include $(LEVEL)/Makefile.common
-
-CXX.Flags += -Wno-unused
Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3.cpp Tue Jul 1 08:41:02 2008
@@ -18,6 +18,7 @@
#include "CLIJit.h"
#include "CLIString.h"
#include "LockedMap.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "N3ModuleProvider.h"
#include "Reader.h"
@@ -204,9 +205,9 @@
true, true, true, true);
VMObject* th = (*cl)();
std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
+ args.push_back(MSCorlib::pVoid);
args.push_back(cl);
- args.push_back(N3::pIntPtr);
+ args.push_back(MSCorlib::pIntPtr);
VMMethod* meth = cl->lookupMethod(asciizConstructUTF8(".ctor"), args,
false, false);
VMThread* myth = VMThread::get();
@@ -278,7 +279,7 @@
loadBootstrap();
- ArrayObject* args = ArrayObject::acons(argc - 2, arrayString);
+ ArrayObject* args = ArrayObject::acons(argc - 2, MSCorlib::arrayString);
for (int i = 2; i < argc; ++i) {
args->setAt(i - 2, (VMObject*)asciizToStr(argv[i]));
}
Modified: vmkit/trunk/lib/N3/VMCore/N3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.h?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3.h (original)
+++ vmkit/trunk/lib/N3/VMCore/N3.h Tue Jul 1 08:41:02 2008
@@ -63,48 +63,7 @@
void waitForExit();
static N3* bootstrapVM;
-
- 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;
-
+
static const UTF8* clinitName;
static const UTF8* ctorName;
static const UTF8* invokeName;
@@ -123,24 +82,6 @@
static const UTF8* doubleName;
static const UTF8* testInfinity;
- static VMMethod* ctorClrType;
- static VMClass* clrType;
- static VMField* typeClrType;
-
- static VMMethod* ctorAssemblyReflection;
- static VMClass* assemblyReflection;
- static VMClass* typedReference;
- static VMField* assemblyAssemblyReflection;
- static VMClass* propertyType;
- static VMClass* methodType;
-
- static VMMethod* ctorPropertyType;
- static VMMethod* ctorMethodType;
- static VMField* propertyPropertyType;
- static VMField* methodMethodType;
-
- static VMClass* resourceStreamType;
- static VMMethod* ctorResourceStreamType;
};
} // 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=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Tue Jul 1 08:41:02 2008
@@ -18,6 +18,7 @@
#include "CLIJit.h"
#include "LockedMap.h"
#include "NativeUtil.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "N3ModuleProvider.h"
#include "Reader.h"
@@ -40,62 +41,62 @@
std::vector<VMField*> VMClassArray::VirtualFieldsArray;
std::vector<VMField*> VMClassArray::StaticFieldsArray;
-VMClass* N3::pVoid = 0;
-VMClass* N3::pBoolean= 0;
-VMClass* N3::pChar = 0;
-VMClass* N3::pSInt8 = 0;
-VMClass* N3::pUInt8 = 0;
-VMClass* N3::pSInt16 = 0;
-VMClass* N3::pUInt16 = 0;
-VMClass* N3::pSInt32 = 0;
-VMClass* N3::pUInt32 = 0;
-VMClass* N3::pSInt64 = 0;
-VMClass* N3::pUInt64 = 0;
-VMClass* N3::pFloat = 0;
-VMClass* N3::pDouble = 0;
-VMClass* N3::pIntPtr = 0;
-VMClass* N3::pUIntPtr = 0;
-VMClass* N3::pObject = 0;
-VMClass* N3::pString = 0;
-VMClass* N3::pValue = 0;
-VMClass* N3::pEnum = 0;
-VMClass* N3::pArray = 0;
-VMClass* N3::pDelegate = 0;
-VMClass* N3::pException = 0;
-VMClassArray* N3::arrayChar = 0;
-VMClassArray* N3::arrayString = 0;
-VMClassArray* N3::arrayObject = 0;
-VMClassArray* N3::arrayByte = 0;
-VMMethod* N3::ctorPropertyType;
-VMMethod* N3::ctorMethodType;
-VMMethod* N3::ctorClrType;
-VMClass* N3::clrType;
-VMField* N3::typeClrType;
-VMField* N3::propertyPropertyType;
-VMField* N3::methodMethodType;
-VMMethod* N3::ctorAssemblyReflection;
-VMClass* N3::assemblyReflection;
-VMClass* N3::typedReference;
-VMField* N3::assemblyAssemblyReflection;
-VMClass* N3::propertyType;
-VMClass* N3::methodType;
-VMClass* N3::resourceStreamType;
-VMMethod* N3::ctorResourceStreamType;
-
-VMField* N3::ctorBoolean;
-VMField* N3::ctorUInt8;
-VMField* N3::ctorSInt8;
-VMField* N3::ctorChar;
-VMField* N3::ctorSInt16;
-VMField* N3::ctorUInt16;
-VMField* N3::ctorSInt32;
-VMField* N3::ctorUInt32;
-VMField* N3::ctorSInt64;
-VMField* N3::ctorUInt64;
-VMField* N3::ctorIntPtr;
-VMField* N3::ctorUIntPtr;
-VMField* N3::ctorDouble;
-VMField* N3::ctorFloat;
+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;
+VMMethod* MSCorlib::ctorPropertyType;
+VMMethod* MSCorlib::ctorMethodType;
+VMMethod* MSCorlib::ctorClrType;
+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;
+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;
@@ -216,19 +217,6 @@
}
-static void loadStringClass(N3* vm) {
- VMClass* type = (VMClass*)vm->coreAssembly->loadTypeFromName(
- vm->asciizConstructUTF8("String"),
- vm->asciizConstructUTF8("System"),
- false, false, false, true);
- N3::pString = type;
- type->resolveType(false, false);
-
- uint64 size = mvm::jit::getTypeSize(type->virtualType->getContainedType(0)) + sizeof(const UTF8*) + sizeof(llvm::GlobalVariable*);
- type->virtualInstance =
- (VMObject*)gc::operator new(size, type->virtualInstance->getVirtualTable());
- type->virtualInstance->initialise(type);
-}
static void initialiseStatics() {
NativeUtil::initialise();
@@ -258,10 +246,10 @@
const UTF8* System = vm->asciizConstructUTF8("System");
const UTF8* utf8OfChar = vm->asciizConstructUTF8("Char");
- N3::arrayChar = ass->constructArray(utf8OfChar, System, 1);
- ((UTF8*)System)->classOf = N3::arrayChar;
- ((UTF8*)utf8OfChar)->classOf = N3::arrayChar;
- ((UTF8*)mscorlib)->classOf = N3::arrayChar;
+ MSCorlib::arrayChar = ass->constructArray(utf8OfChar, System, 1);
+ ((UTF8*)System)->classOf = MSCorlib::arrayChar;
+ ((UTF8*)utf8OfChar)->classOf = MSCorlib::arrayChar;
+ ((UTF8*)mscorlib)->classOf = MSCorlib::arrayChar;
#define INIT(var, nameSpace, name, type, prim) {\
var = (VMClass*)vm->coreAssembly->loadTypeFromName( \
@@ -274,54 +262,48 @@
var->virtualType = type; \
}}
- INIT(N3::pObject, "System", "Object", VMObject::llvmType, false);
- INIT(N3::pValue, "System", "ValueType", 0, false);
- INIT(N3::pVoid, "System", "Void", llvm::Type::VoidTy, true);
- INIT(N3::pBoolean, "System", "Boolean", llvm::Type::Int1Ty, true);
- INIT(N3::pUInt8, "System", "Byte", llvm::Type::Int8Ty, true);
- INIT(N3::pSInt8, "System", "SByte", llvm::Type::Int8Ty, true);
- INIT(N3::pChar, "System", "Char", llvm::Type::Int16Ty, true);
- INIT(N3::pSInt16, "System", "Int16", llvm::Type::Int16Ty, true);
- INIT(N3::pUInt16, "System", "UInt16", llvm::Type::Int16Ty, true);
- INIT(N3::pSInt32, "System", "Int32", llvm::Type::Int32Ty, true);
- INIT(N3::pUInt32, "System", "UInt32", llvm::Type::Int32Ty, true);
- INIT(N3::pSInt64, "System", "Int64", llvm::Type::Int64Ty, true);
- INIT(N3::pUInt64, "System", "UInt64", llvm::Type::Int64Ty, true);
- INIT(N3::pIntPtr, "System", "IntPtr", llvm::PointerType::getUnqual(llvm::Type::Int8Ty), true);
- INIT(N3::pUIntPtr, "System", "UIntPtr", llvm::PointerType::getUnqual(llvm::Type::Int8Ty), true);
- INIT(N3::pDouble, "System", "Double", llvm::Type::DoubleTy, true);
- INIT(N3::pFloat, "System", "Single", llvm::Type::FloatTy, true);
- INIT(N3::pEnum, "System", "Enum", llvm::Type::Int32Ty, true);
- INIT(N3::pArray, "System", "Array", 0, true);
- INIT(N3::pException,"System", "Exception", 0, false);
- INIT(N3::pDelegate, "System", "Delegate", 0, false);
- INIT(N3::clrType, "System.Reflection", "ClrType", 0, false);
- INIT(N3::assemblyReflection, "System.Reflection", "Assembly", 0, false);
- INIT(N3::typedReference, "System", "TypedReference", 0, false);
- INIT(N3::propertyType, "System.Reflection", "ClrProperty", 0, false);
- INIT(N3::methodType, "System.Reflection", "ClrMethod", 0, false);
- INIT(N3::resourceStreamType, "System.Reflection", "ClrResourceStream", 0, false);
+ INIT(MSCorlib::pObject, "System", "Object", VMObject::llvmType, false);
+ INIT(MSCorlib::pValue, "System", "ValueType", 0, false);
+ INIT(MSCorlib::pVoid, "System", "Void", llvm::Type::VoidTy, true);
+ INIT(MSCorlib::pBoolean, "System", "Boolean", llvm::Type::Int1Ty, true);
+ INIT(MSCorlib::pUInt8, "System", "Byte", llvm::Type::Int8Ty, true);
+ INIT(MSCorlib::pSInt8, "System", "SByte", llvm::Type::Int8Ty, true);
+ INIT(MSCorlib::pChar, "System", "Char", llvm::Type::Int16Ty, true);
+ INIT(MSCorlib::pSInt16, "System", "Int16", llvm::Type::Int16Ty, true);
+ INIT(MSCorlib::pUInt16, "System", "UInt16", llvm::Type::Int16Ty, true);
+ INIT(MSCorlib::pSInt32, "System", "Int32", llvm::Type::Int32Ty, true);
+ INIT(MSCorlib::pUInt32, "System", "UInt32", llvm::Type::Int32Ty, true);
+ INIT(MSCorlib::pSInt64, "System", "Int64", llvm::Type::Int64Ty, true);
+ INIT(MSCorlib::pUInt64, "System", "UInt64", llvm::Type::Int64Ty, true);
+ INIT(MSCorlib::pIntPtr, "System", "IntPtr", llvm::PointerType::getUnqual(llvm::Type::Int8Ty), true);
+ INIT(MSCorlib::pUIntPtr, "System", "UIntPtr", llvm::PointerType::getUnqual(llvm::Type::Int8Ty), true);
+ INIT(MSCorlib::pDouble, "System", "Double", llvm::Type::DoubleTy, true);
+ INIT(MSCorlib::pFloat, "System", "Single", llvm::Type::FloatTy, true);
+ INIT(MSCorlib::pEnum, "System", "Enum", llvm::Type::Int32Ty, true);
+ INIT(MSCorlib::pArray, "System", "Array", 0, true);
+ INIT(MSCorlib::pException,"System", "Exception", 0, false);
+ INIT(MSCorlib::pDelegate, "System", "Delegate", 0, false);
#undef INIT
- N3::arrayChar->baseClass = N3::pChar;
- VMClassArray::SuperArray = N3::pArray;
- N3::arrayChar->super = N3::pArray;
-
- loadStringClass(vm);
+ MSCorlib::arrayChar->baseClass = MSCorlib::pChar;
+ VMClassArray::SuperArray = MSCorlib::pArray;
+ MSCorlib::arrayChar->super = MSCorlib::pArray;
- N3::arrayString = ass->constructArray(vm->asciizConstructUTF8("String"),
+ MSCorlib::loadStringClass(vm);
+
+ MSCorlib::arrayString = ass->constructArray(vm->asciizConstructUTF8("String"),
System, 1);
- N3::arrayString->baseClass = N3::pString;
+ MSCorlib::arrayString->baseClass = MSCorlib::pString;
- N3::arrayByte = ass->constructArray(vm->asciizConstructUTF8("Byte"),
+ MSCorlib::arrayByte = ass->constructArray(vm->asciizConstructUTF8("Byte"),
System, 1);
- N3::arrayByte->baseClass = N3::pUInt8;
+ MSCorlib::arrayByte->baseClass = MSCorlib::pUInt8;
- N3::arrayObject = ass->constructArray(vm->asciizConstructUTF8("Object"),
+ MSCorlib::arrayObject = ass->constructArray(vm->asciizConstructUTF8("Object"),
System, 1);
- N3::arrayObject->baseClass = N3::pObject;
+ MSCorlib::arrayObject->baseClass = MSCorlib::pObject;
N3::clinitName = vm->asciizConstructUTF8(".cctor");
@@ -342,75 +324,9 @@
N3::doubleName = vm->asciizConstructUTF8("Double");
N3::testInfinity = vm->asciizConstructUTF8("TestInfinity");
- {
- N3::clrType->resolveType(false, false);
- std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
- args.push_back(N3::clrType);
- N3::ctorClrType = N3::clrType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
- N3::typeClrType = N3::clrType->lookupField(vm->asciizConstructUTF8("privateData"), N3::pIntPtr, false, false);
- }
-
- {
- N3::assemblyReflection->resolveType(false, false);
- std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
- args.push_back(N3::assemblyReflection);
- N3::ctorAssemblyReflection = N3::assemblyReflection->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
- N3::assemblyAssemblyReflection = N3::assemblyReflection->lookupField(vm->asciizConstructUTF8("privateData"), N3::pIntPtr, false, false);
- }
-
- {
- N3::propertyType->resolveType(false, false);
- std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
- args.push_back(N3::propertyType);
- N3::ctorPropertyType = N3::propertyType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
- N3::propertyPropertyType = N3::propertyType->lookupField(vm->asciizConstructUTF8("privateData"), N3::pIntPtr, false, false);
- }
-
- {
- N3::methodType->resolveType(false, false);
- std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
- args.push_back(N3::methodType);
- N3::ctorMethodType = N3::methodType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
- N3::methodMethodType = N3::methodType->lookupField(vm->asciizConstructUTF8("privateData"), N3::pIntPtr, false, false);
- }
-
- {
- N3::resourceStreamType->resolveType(false, false);
- std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
- args.push_back(N3::resourceStreamType);
- args.push_back(N3::pIntPtr);
- args.push_back(N3::pSInt64);
- args.push_back(N3::pSInt64);
- N3::ctorResourceStreamType = N3::resourceStreamType->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, false, false);
- }
-
- VMCommonClass* voidPtr = vm->coreAssembly->constructPointer(N3::pVoid, 1);
-#define INIT(var, cl, type) {\
- cl->resolveType(false, false); \
- var = cl->lookupField(vm->asciizConstructUTF8("value_"), type, false, false); \
- }
-
- INIT(N3::ctorBoolean, N3::pBoolean, N3::pBoolean);
- INIT(N3::ctorUInt8, N3::pUInt8, N3::pUInt8);
- INIT(N3::ctorSInt8, N3::pSInt8, N3::pSInt8);
- INIT(N3::ctorChar, N3::pChar, N3::pChar);
- INIT(N3::ctorSInt16, N3::pSInt16, N3::pSInt16);
- INIT(N3::ctorUInt16, N3::pUInt16, N3::pUInt16);
- INIT(N3::ctorSInt32, N3::pSInt32, N3::pSInt32);
- INIT(N3::ctorUInt32, N3::pUInt32, N3::pUInt32);
- INIT(N3::ctorSInt64, N3::pSInt64, N3::pSInt64);
- INIT(N3::ctorUInt64, N3::pUInt64, N3::pUInt64);
- INIT(N3::ctorIntPtr, N3::pIntPtr, voidPtr);
- INIT(N3::ctorUIntPtr, N3::pUIntPtr, voidPtr);
- INIT(N3::ctorDouble, N3::pDouble, N3::pDouble);
- INIT(N3::ctorFloat, N3::pFloat, N3::pFloat);
-#undef INIT
+ MSCorlib::initialise(vm);
+
}
Modified: vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp Tue Jul 1 08:41:02 2008
@@ -15,7 +15,6 @@
#include "Assembly.h"
#include "CLIJit.h"
-#include "CLIString.h"
#include "N3ModuleProvider.h"
#include "VMClass.h"
Modified: vmkit/trunk/lib/N3/VMCore/Opcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Opcodes.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Opcodes.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Tue Jul 1 08:41:02 2008
@@ -44,6 +44,7 @@
#include "Assembly.h"
#include "CLIJit.h"
#include "CLIString.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "Reader.h"
#include "VMArray.h"
@@ -1509,7 +1510,7 @@
uint32 token = readU4(bytecodes, i);
VMCommonClass* cl = assembly->loadType(vm, token, true, false,
false, true);
- if (!(cl->super == N3::pValue || cl->super == N3::pEnum)) {
+ if (!(cl->super == MSCorlib::pValue || cl->super == MSCorlib::pEnum)) {
push(new LoadInst(pop(), "", currentBlock));
}
break;
@@ -1539,8 +1540,8 @@
(CLIString*)(((N3*)VMThread::get()->vm)->UTF8ToStr(utf8));
GlobalVariable* gv = str->llvmVar();
push(new BitCastInst(new LoadInst(gv, "", currentBlock),
- N3::pString->naturalType, "", currentBlock));*/
- push(new BitCastInst(res, N3::pString->naturalType, "", currentBlock));
+ MSCorlib::pString->naturalType, "", currentBlock));*/
+ push(new BitCastInst(res, MSCorlib::pString->naturalType, "", currentBlock));
break;
}
Removed: vmkit/trunk/lib/N3/VMCore/PNetLib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/PNetLib.cpp?rev=52957&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/PNetLib.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/PNetLib.cpp (removed)
@@ -1,1209 +0,0 @@
-//===--------------- PNetLib.cpp - PNetLib interface ----------------------===//
-//
-// N3
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <math.h>
-
-#include <dlfcn.h>
-#include <stdio.h>
-
-#include "mvm/JIT.h"
-
-#include "Assembly.h"
-#include "CLIAccess.h"
-#include "CLIJit.h"
-#include "CLIString.h"
-#include "NativeUtil.h"
-#include "N3.h"
-#include "PNetLib.h"
-#include "Reader.h"
-#include "VMArray.h"
-#include "VMClass.h"
-#include "VMObject.h"
-#include "VMThread.h"
-
-using namespace n3;
-
-#define IL_CONSOLE_NORMAL 0
-
-
-#define MEMBER_TYPES_CONSTRUCTOR 0x1
-#define MEMBER_TYPES_EVENT 0x2
-#define MEMBER_TYPES_FIELD 0x4
-#define MEMBER_TYPES_METHOD 0x8
-#define MEMBER_TYPES_PROPERTY 0x10
-#define MEMBER_TYPES_TYPEINFO 0x20
-#define MEMBER_TYPES_CUSTOM 0x40
-#define MEMBER_TYPES_NESTEDTYPE 0x80
-#define MEMBER_TYPES_ALL 0xBF
-
-#define METHOD_SEMANTIC_ATTRIBUTES_SETTER 0x1
-#define METHOD_SEMANTIC_ATTRIBUTES_GETTER 0x2
-#define METHOD_SEMANTIC_ATTRIBUTES_OTHER 0x4
-#define METHOD_SEMANTIC_ATTRIBUTES_ADDON 0x8
-#define METHOD_SEMANTIC_ATTRIBUTES_REMOVEON 0x10
-#define METHOD_SEMANTIC_ATTRIBUTES_FIRE 0x20
-
-
-extern "C" {
-extern uint32 ILGetCodePage(void);
-extern uint32 ILGetCultureID(void);
-extern char* ILGetCultureName(void);
-extern sint32 ILAnsiGetMaxByteCount(sint32);
-extern sint32 ILConsoleWriteChar(sint32);
-extern uint32 ILConsoleGetMode(void);
-extern sint32 ILAnsiGetBytes(uint16*, sint32, uint8*, sint32);
-extern void _IL_Stdio_StdFlush(void*, sint32);
-extern char ILGetUnicodeCategory(sint32);
-extern sint64 _IL_TimeMethods_GetCurrentTime(void*);
-extern uint32 ILUnicodeStringToLower(void*, void*, uint32);
-extern sint32 ILUnicodeStringCompareIgnoreCase(void*, void*, sint32);
-extern sint32 ILUnicodeStringCompareNoIgnoreCase(void*, void*, sint32);
-
-#include "mvm/Config/config.h"
-// PNET wants this
-void *GC_run_thread(void *(*thread_func)(void *), void *arg){ return 0; }
-#if not(USE_GC_BOEHM)
-int GC_invoke_finalizers (void) { return 0; }
-int GC_should_invoke_finalizers (void) { return 0; }
-void GC_register_finalizer_no_order(void*, void (*)(void*, void*), void*, void (**)(void*, void*), void**) { return; }
-void GC_gcollect(void) {}
-void* GC_malloc_uncollectable(size_t) { return 0; }
-void GC_exclude_static_roots(void*, void*) {}
-void GC_free(void*) {}
-void GC_malloc_explicitly_typed(void) {}
-size_t GC_get_heap_size(void) {return 0;}
-int GC_register_disappearing_link(void**) { return 0; }
-int GC_general_register_disappearing_link(void**, void*) { return 0; }
-int GC_pthread_sigmask(int, const sigset_t*, sigset_t*) { return 0; }
-int GC_pthread_detach(pthread_t) { return 0; }
-int GC_pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*) { return 0; }
-void* GC_malloc(size_t) { return 0; }
-void GC_make_descriptor(void) {}
-int GC_unregister_disappearing_link(void**) { return 0; }
-void (*GC_finalizer_notifier)(void);
-int GC_java_finalization;
-int GC_finalize_on_demand;
-void GC_set_max_heap_size(size_t) {}
-void* GC_malloc_atomic(size_t) { return 0; }
-#endif
-
-// Fake termcap symbols
-void tigetstr(void) {
- abort();
-}
-void tgetstr(void) {
- abort();
-}
-void setupterm(void) {
- abort();
-}
-void tigetnum(void) {
- abort();
-}
-void tgetnum(void) {
- abort();
-}
-void tigetflag(void) {
- abort();
-}
-void tparm(void) {
- abort();
-}
-void tgetent(void) {
- abort();
-}
-void tputs(void) {
- abort();
-}
-void tgoto(void) {
- abort();
-}
-void tgetflag(void) {
- abort();
-}
-}
-
-
-
-extern "C" void System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray(
- VMArray* array, VMField* field) {
- if (!array || !field) return;
-
- VMClass* type = field->classDef;
- VMClassArray* ts = (VMClassArray*)array->classOf;
- VMCommonClass* bs = ts->baseClass;
- Assembly* ass = type->assembly;
-
- uint32 rva = ass->getRVAFromField(field->token);
- Section* rsrcSection = ass->rsrcSection;
-
- uint32 size = array->size;
- uint32 offset = rsrcSection->rawAddress + (rva - rsrcSection->virtualAddress);
- ArrayUInt8* bytes = ass->bytes;
-
- if (bs == N3::pChar) {
- for (uint32 i = 0; i < size; ++i) {
- ((ArrayUInt16*)array)->elements[i] = READ_U2(bytes, offset);
- }
- } else if (bs == N3::pSInt32) {
- for (uint32 i = 0; i < size; ++i) {
- ((ArraySInt32*)array)->elements[i] = READ_U4(bytes, offset);
- }
- } else if (bs == N3::pDouble) {
- for (uint32 i = 0; i < size; ++i) {
- ((ArrayDouble*)array)->elements[i] = READ_U8(bytes, offset);
- }
- } else {
- VMThread::get()->vm->error("implement me");
- }
-}
-
-extern "C" VMObject* System_Type_GetTypeFromHandle(VMCommonClass* cl) {
- return cl->getClassDelegatee();
-}
-
-extern "C" void System_Threading_Monitor_Enter(VMObject* obj) {
- obj->aquire();
-}
-
-extern "C" void System_Threading_Monitor_Exit(VMObject* obj) {
- obj->unlock();
-}
-
-extern "C" uint32 System_Text_DefaultEncoding_InternalCodePage() {
- return ILGetCodePage();
-}
-
-extern "C" VMObject* System_Reflection_Assembly_GetCallingAssembly() {
- Assembly* ass = Assembly::getCallingAssembly();
- assert(ass);
- return ass->getAssemblyDelegatee();
-}
-
-extern "C" VMObject* System_Reflection_Assembly_GetExecutingAssembly() {
- Assembly* ass = Assembly::getExecutingAssembly();
- assert(ass);
- return ass->getAssemblyDelegatee();
-}
-
-extern "C" uint32 System_Globalization_CultureInfo_InternalCultureID() {
- return ILGetCultureID();
-}
-
-extern "C" VMObject* System_Globalization_CultureInfo_InternalCultureName() {
- char* val = ILGetCultureName();
- N3* vm = (N3*)(VMThread::get()->vm);
- if (val) {
- VMObject* ret = vm->asciizToStr(val);
- free(val);
- return ret;
- } else {
- VMObject* ret = vm->asciizToStr("iv");
- return ret;
- }
-}
-
-extern "C" void System_Reflection_Assembly_LoadFromFile() {
- VMThread::get()->vm->error("implement me");
-}
-
-static const UTF8* newBuilder(N3* vm, CLIString* value, uint32 length) {
- uint32 valueLength = value ? value->length : 0;
- const UTF8* utf8 = value ? value->value : 0;
- uint32 roundLength = (7 + length) & 0xfffffff8;
- uint16* buf = (uint16*)alloca(roundLength * sizeof(uint16));
- uint32 strLength = 0;
-
- if (value != 0) {
- if (valueLength <= roundLength) {
- memcpy(buf, utf8->elements, valueLength * sizeof(uint16));
- strLength = valueLength;
- } else {
- memcpy(buf, utf8->elements, roundLength * sizeof(uint16));
- strLength = roundLength;
- }
- }
-
- return vm->readerConstructUTF8(buf, strLength);
-
-}
-
-extern "C" VMObject* System_String_NewBuilder(CLIString* value,
- uint32 length) {
- N3* vm = (N3*)(VMThread::get()->vm);
- CLIString* str = (CLIString*)vm->UTF8ToStr(newBuilder(vm, value, length));
- return str;
-}
-
-extern "C" VMObject* Platform_SysCharInfo_GetNewLine() {
- N3* vm = (N3*)(VMThread::get()->vm);
- return vm->asciizToStr("\n");
-}
-
-extern "C" void System_String_CopyToChecked(CLIString* str, sint32 sstart,
- ArrayUInt16* dest, sint32 dstart,
- sint32 count) {
- const UTF8* value = str->value;
- memcpy(&dest->elements[dstart], &value->elements[sstart], count << 1);
-}
-
-extern "C" sint32 System_Text_DefaultEncoding_InternalGetMaxByteCount(sint32 val) {
- return ILAnsiGetMaxByteCount(val);
-}
-
-extern "C" void Platform_Stdio_StdWrite(sint32 fd, ArrayUInt8* value,
- sint32 index, sint32 count) {
- if (fd == 1) {
- if (ILConsoleGetMode() == IL_CONSOLE_NORMAL) {
- fwrite(&value->elements[index], 1, count, stdout);
- } else {
- char* buf = (char*)(&value->elements[index]);
- while (count > 0) {
- ILConsoleWriteChar(*buf);
- ++buf;
- --count;
- }
- fflush(stdout);
- }
- } else {
- fwrite(&value->elements[index], 1, count, stderr);
- }
-}
-
-extern "C" sint32 System_Text_DefaultEncoding_InternalGetBytes(ArrayUInt16* chars,
- sint32 charIndex, sint32 charCount, ArrayUInt8* bytes, sint32 byteIndex) {
-
- return ILAnsiGetBytes(&chars->elements[charIndex], charCount, &bytes->elements[byteIndex], bytes->size - byteIndex);
-}
-
-extern "C" void Platform_Stdio_StdFlush(sint32 fd) {
- _IL_Stdio_StdFlush(0, fd);
-}
-
-extern "C" void System_Array_InternalCopy(VMArray* src, sint32 sstart,
- VMArray* dst, sint32 dstart,
- sint32 len) {
- N3* vm = (N3*)(VMThread::get()->vm);
- verifyNull(src);
- verifyNull(dst);
-
- if (!(src->classOf->isArray && dst->classOf->isArray)) {
- vm->arrayStoreException();
- }
-
- VMClassArray* ts = (VMClassArray*)src->classOf;
- VMClassArray* td = (VMClassArray*)dst->classOf;
- VMCommonClass* dstType = td->baseClass;
- VMCommonClass* srcType = ts->baseClass;
-
- if (len > src->size) {
- vm->indexOutOfBounds(src, len);
- } else if (len > dst->size) {
- vm->indexOutOfBounds(dst, len);
- } else if (len + sstart > src->size) {
- vm->indexOutOfBounds(src, len + sstart);
- } else if (len + dstart > dst->size) {
- vm->indexOutOfBounds(dst, len + dstart);
- } else if (dstart < 0) {
- vm->indexOutOfBounds(dst, dstart);
- } else if (sstart < 0) {
- vm->indexOutOfBounds(src, sstart);
- } else if (len < 0) {
- vm->indexOutOfBounds(src, len);
- }
-
- bool doThrow = false;
-
- if (srcType->super == N3::pValue && srcType != dstType) {
- vm->arrayStoreException();
- } else if (srcType->super != N3::pValue && srcType->super != N3::pEnum) {
- sint32 i = sstart;
- while (i < sstart + len && !doThrow) {
- VMObject* cur = ((ArrayObject*)src)->at(i);
- if (cur) {
- if (!(cur->classOf->isAssignableFrom(dstType))) {
- doThrow = true;
- len = i;
- }
- }
- ++i;
- }
- }
-
-
- uint32 size = srcType->naturalType->getPrimitiveSizeInBits() / 8;
- if (size == 0) size = sizeof(void*);
- void* ptrDst = (void*)((int64_t)(dst->elements) + size * dstart);
- void* ptrSrc = (void*)((int64_t)(src->elements) + size * sstart);
- memmove(ptrDst, ptrSrc, size * len);
-
- if (doThrow)
- vm->arrayStoreException();
-
-}
-
-extern "C" sint32 System_Array_GetRank(VMObject* arr) {
- verifyNull(arr);
- if (arr->classOf->isArray) {
- return ((VMClassArray*)(arr->classOf))->dims;
- } else {
- VMThread::get()->vm->error("implement me");
- return 0;
- }
-}
-
-extern "C" sint32 System_Array_GetLength(VMObject* arr) {
- verifyNull(arr);
- if (arr->classOf->isArray) {
- return ((VMArray*)arr)->size;
- } else {
- VMThread::get()->vm->error("implement me");
- return 0;
- }
-}
-
-extern "C" sint32 System_Array_GetLowerBound(VMObject* arr, sint32 dim) {
- return 0;
-}
-
-extern "C" VMObject* System_Object_GetType(VMObject* obj) {
- verifyNull(obj);
- return obj->classOf->getClassDelegatee();
-}
-
-extern "C" VMObject* System_Reflection_ClrType_GetElementType(VMObject* Klass) {
- VMCommonClass* cl = (VMCommonClass*)((*Klass)(N3::typeClrType).PointerVal);
- if (!cl->isArray) {
- VMThread::get()->vm->error("implement me");
- return 0;
- } else {
- return ((VMClassArray*)cl)->baseClass->getClassDelegatee();
- }
-}
-
-extern "C" CLIString* System_String_NewString(uint32 size) {
- CLIString* str = (CLIString*)(N3::pString->doNew());
- str->length = size;
- return str;
-}
-
-extern "C" void System_String_Copy_3(CLIString* dest, sint32 pos,
- CLIString* src) {
- ArrayUInt16* arr = ArrayUInt16::acons(pos + src->value->size,
- (VMClassArray*)N3::pChar);
-
- for (sint32 i = 0; i < pos; ++i) {
- arr->setAt(i, dest->value->at(i));
- }
-
- for (sint32 i = 0; i < src->length; ++i) {
- arr->setAt(pos + i, src->value->at(i));
- }
-
- dest->value = ((UTF8*)arr)->extract(VMThread::get()->vm, 0, pos + src->value->size);
- dest->length = dest->value->size;
-}
-
-extern "C" void System_String_Copy_5(CLIString* dest, sint32 destPos,
- CLIString* src, sint32 srcPos,
- sint32 length) {
- const UTF8* utf8Src = src->value->extract(VMThread::get()->vm, srcPos,
- srcPos + length);
- if (destPos == 0) {
- dest->value = utf8Src;
- dest->length = dest->value->size;
- } else {
- const UTF8* utf8Dest = dest->value->extract(VMThread::get()->vm, 0,
- destPos);
- sint32 len1 = utf8Dest->size;
- sint32 len2 = utf8Src->size;
- uint16* buf = (uint16*)alloca((len1 + len2) * sizeof(uint16));
-
- memcpy(buf, utf8Dest->elements, len1 * sizeof(uint16));
- memcpy(buf + len1, utf8Dest->elements, len2 * sizeof(uint16));
-
- const UTF8* utf8 = VMThread::get()->vm->readerConstructUTF8(buf,
- len1 + len2);
- dest->value = utf8;
- dest->length = dest->value->size;
- }
-}
-
-extern "C" bool System_String_Equals(CLIString* str1, CLIString* str2) {
- return str1->value == str2->value;
-}
-
-extern "C" VMObject* System_Threading_Thread_InternalCurrentThread() {
- return VMThread::get()->vmThread;
-}
-
-extern "C" sint32 Platform_SysCharInfo_GetUnicodeCategory(char c) {
- return ILGetUnicodeCategory(c);
-}
-
-extern "C" uint16 System_String_GetChar(CLIString* str, sint32 index) {
- return str->value->at(index);
-}
-
-extern "C" sint32 System_String_IndexOf(CLIString* str, uint16 value,
- sint32 startIndex, sint32 count) {
- if (startIndex < 0) {
- VMThread::get()->vm->error("shoud throw arg range");
- }
-
- if ((count < 0) || (str->length - startIndex < count)) {
- VMThread::get()->vm->error("shoud throw arg range");
- }
-
- sint32 i = startIndex;
- const UTF8* utf8 = str->value;
- while (i < startIndex + count) {
- if (utf8->at(i) == value) return i;
- else ++i;
- }
-
- return -1;
-}
-
-extern "C" sint32 System_String_GetHashCode(CLIString* str) {
- sint32 hash = 0;
- const UTF8* utf8 = str->value;
- for (sint32 i = 0; i < utf8->size; ++i) {
- hash += ((hash << 5) + utf8->elements[i]);
- }
- return hash;
-}
-
-extern "C" double System_Decimal_ToDouble(void* ptr) {
- VMThread::get()->vm->error("implement me");
- return 0.0;
-}
-
-extern "C" double System_Math_Log10(double val) {
- return log10(val);
-}
-
-extern "C" double System_Math_Floor(double val) {
- return floor(val);
-}
-
-extern "C" VMObject* System_Text_StringBuilder_Insert_System_Text_StringBuilder_System_Int32_System_Char(
- StringBuilder* obj,
- sint32 index,
- uint16 value) {
- N3* vm = (N3*)(VMThread::get()->vm);
- CLIString* buildString = obj->buildString;
- const UTF8* utf8 = buildString->value;
- sint32 strLength = buildString->length;
- sint32 length = (index + 1) > strLength ? index + 1 : strLength + 1;
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
-
- if (index != 0) {
- memcpy(buf, utf8->elements, index * sizeof(uint16));
- }
-
- if (strLength > index) {
- memcpy(&(buf[index + 1]), &(utf8->elements[index]),
- (strLength - index) * sizeof(uint16));
- }
-
- buf[index] = value;
- CLIString* str = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
- obj->buildString = str;
-
- return obj;
-}
-
-extern "C" VMObject* System_Text_StringBuilder_Insert_System_Text_StringBuilder_System_Int32_System_String(
- StringBuilder* obj,
- sint32 index,
- CLIString* str) {
- N3* vm = (N3*)(VMThread::get()->vm);
- CLIString* buildString = obj->buildString;
- const UTF8* strUtf8 = str->value;
- const UTF8* buildUtf8 = buildString->value;
- sint32 strLength = str->length;
- sint32 buildLength = buildString->length;
- sint32 length = strLength + buildLength;
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
-
- if (index != 0) {
- memcpy(buf, buildUtf8->elements, index * sizeof(uint16));
- }
-
- if (strLength != 0) {
- memcpy(&(buf[index]), strUtf8->elements, strLength * sizeof(uint16));
- }
-
- if (buildLength - index > 0) {
- memcpy(&(buf[strLength + index]), &(buildUtf8->elements[index]),
- (buildLength - index) * sizeof(uint16));
- }
-
- CLIString* val = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
- obj->buildString = val;
-
- return obj;
-}
-
-extern "C" VMObject* System_Text_StringBuilder_Append_System_Text_StringBuilder_System_Char(
- StringBuilder* obj,
- uint16 value) {
- N3* vm = (N3*)(VMThread::get()->vm);
- CLIString* buildString = obj->buildString;
- const UTF8* utf8 = buildString->value;
- sint32 length = buildString->length;
- uint16* buf = (uint16*)alloca((length + 1) * sizeof(uint16));
-
- memcpy(buf, utf8->elements, length * sizeof(uint16));
-
- buf[length] = value;
- CLIString* val = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length + 1));
- obj->buildString = val;
- return obj;
-}
-
-
-extern "C" VMObject* System_Text_StringBuilder_Append_System_Text_StringBuilder_System_String(
- StringBuilder* obj,
- CLIString* str) {
- N3* vm = (N3*)(VMThread::get()->vm);
- CLIString* buildString = obj->buildString;
- const UTF8* buildUtf8 = buildString->value;
- const UTF8* strUtf8 = str->value;
- sint32 buildLength = buildString->length;
- sint32 strLength = str->length;
- sint32 length = buildLength + strLength;
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
-
- memcpy(buf, buildUtf8->elements, buildLength * sizeof(uint16));
- memcpy(&(buf[buildLength]), strUtf8->elements, strLength * sizeof(uint16));
-
- CLIString* val = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, length));
- obj->buildString = val;
- return obj;
-}
-
-extern "C" sint32 System_String_FindInRange(CLIString* obj, sint32 srcFirst,
- sint32 srcLast, sint32 step,
- CLIString* dest) {
- uint16* buf1 = (uint16*)&(obj->value->elements[srcFirst]);
- uint16* buf2 = (uint16*)(dest->value->elements);
- sint32 destLength = dest->length;
- sint32 size = destLength * sizeof(uint16);
-
- if (step > 0) {
- if (destLength == 1) {
- while (srcFirst <= srcLast) {
- if (buf1[0] == buf2[0]) {
- return srcFirst;
- } else {
- buf1 = &(buf1[1]);
- ++srcFirst;
- }
- }
- } else {
- while (srcFirst <= srcLast) {
- if ((buf1[0] == buf2[0]) && !memcmp(buf1, buf2, size)) {
- return srcFirst;
- } else {
- buf1 = &(buf1[1]);
- ++srcFirst;
- }
- }
- }
- } else {
- if (destLength == 1) {
- while (srcFirst >= srcLast) {
- if (buf1[0] == buf2[0]) {
- return srcFirst;
- } else {
- buf1 = buf1 - 1;
- --srcFirst;
- }
- }
- } else {
- while (srcFirst >= srcLast) {
- if ((buf1[0] == buf2[0]) && !memcmp(buf1, buf2, size)) {
- return srcFirst;
- } else {
- buf1 = buf1 - 1;
- --srcFirst;
- }
- }
- }
- }
- return -1;
-}
-
-extern "C" VMObject* System_Reflection_Assembly_LoadFromName(CLIString* str, sint32 & error, VMObject* parent) {
- N3* vm = (N3*)(VMThread::get()->vm);
- Assembly* ass = vm->loadAssembly(str->value, "dll");
- if (!ass) vm->error("unfound assembly %s\n", str->value->printString());
- error = 0;
- return ass->getAssemblyDelegatee();
-}
-
-extern "C" CLIString* System_String_Concat_2(CLIString* str1, CLIString* str2) {
- N3* vm = (N3*)(VMThread::get()->vm);
- const UTF8* u1 = str1->value;
- const UTF8* u2 = str2->value;
- sint32 len1 = str1->length;
- sint32 len2 = str2->length;
- uint16* buf = (uint16*)alloca((len1 + len2) * sizeof(uint16));
-
- memcpy(buf, u1->elements, len1 * sizeof(uint16));
- memcpy(&(buf[len1]), u2->elements, len2 * sizeof(uint16));
-
- CLIString* val = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, len1 + len2));
-
- return val;
-}
-
-extern "C" CLIString* System_String_Concat_3(CLIString* str1, CLIString* str2, CLIString* str3) {
- N3* vm = (N3*)(VMThread::get()->vm);
- const UTF8* u1 = str1->value;
- const UTF8* u2 = str2->value;
- const UTF8* u3 = str3->value;
- sint32 len1 = str1->length;
- sint32 len2 = str2->length;
- sint32 len3 = str3->length;
- uint16* buf = (uint16*)alloca((len1 + len2 + len3) * sizeof(uint16));
-
- memcpy(buf, u1->elements, len1 * sizeof(uint16));
- memcpy(&(buf[len1]), u2->elements, len2 * sizeof(uint16));
- memcpy(&(buf[len1 + len2]), u3->elements, len3 * sizeof(uint16));
-
- CLIString* val = (CLIString*)vm->UTF8ToStr(vm->readerConstructUTF8(buf, len1 + len2 + len3));
-
- return val;
-}
-
-extern "C" void System_String_RemoveSpace(CLIString* str, sint32 index, sint32 length) {
- const UTF8* utf8 = str->value;
- sint32 strLength = str->length;
- uint16* buf = (uint16*)alloca(strLength * sizeof(uint16));
- sint32 j = index;
-
- if (index != 0) {
- memcpy(buf, utf8->elements, index * sizeof(uint16));
- }
-
- // 32 is space
- for (sint32 i = 0; i < length; ++i) {
- uint16 cur = utf8->elements[index + i];
- if (cur != 32) {
- buf[j] = cur;
- } else {
- ++j;
- }
- }
-
- if (strLength > (index + length)) {
- memcpy(&(buf[j]), &(utf8->elements[index + length]), (strLength - (index + length)) * sizeof(uint16));
- }
-
- const UTF8* res = VMThread::get()->vm->readerConstructUTF8(buf, j);
- str->value = res;
- str->length = j;
-}
-
-extern "C" void System_String__ctor_3(CLIString* str, uint16 ch, sint32 count) {
- ArrayUInt16* array = ArrayUInt16::acons(count, N3::arrayChar);
- for (sint32 i = 0; i < count; ++i) {
- array->elements[i] = ch;
- }
-
- const UTF8* utf8 = VMThread::get()->vm->readerConstructUTF8(array->elements, array->size);
- str->value = utf8;
- str->length = array->size;
- str->capacity = array->size;
-}
-
-extern "C" int64_t Platform_TimeMethods_GetCurrentTime() {
- return _IL_TimeMethods_GetCurrentTime(0);
-}
-
-#define ASSEMBLY_VALUE(obj) ((Assembly**)obj)[3]
-
-void* sys_memrchr(const void* s, int c, size_t n) {
- unsigned char* m = (unsigned char*) s + n;
- for (;;) {
- if (!(n--)) return NULL;
- else if (*m-- == (unsigned char)c) return (void*)(m+1);
- }
-}
-
-extern "C" VMObject* System_Reflection_Assembly_GetType(VMObject* obj, CLIString* str, bool onError, bool ignoreCase) {
- Assembly* ass = ASSEMBLY_VALUE(obj);
- const UTF8* utf8 = str->value;
- char* asciiz = utf8->UTF8ToAsciiz();
- char* index = (char*)sys_memrchr(asciiz, '.', strlen(asciiz));
- N3* vm = ass->vm;
-
- index[0] = 0;
- ++index;
- VMCommonClass* cl = ass->loadTypeFromName(vm->asciizConstructUTF8(index), vm->asciizConstructUTF8(asciiz), true, true, true, onError);
- if (!cl) VMThread::get()->vm->error("implement me");
- return cl->getClassDelegatee();
-}
-
-static bool parameterMatch(std::vector<VMCommonClass*> params, ArrayObject* types, bool virt) {
- 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*)(*N3::typeClrType)(types->elements[i]).PointerVal;
- if (cur != params[i + 1 + v]) return false;
- }
- return true;
-}
-
-extern "C" VMObject* System_Reflection_ClrType_GetMemberImpl(VMObject* Type, CLIString* str, sint32 memberTypes, sint32 bindingFlags, VMObject* binder,
- sint32 callingConventions, ArrayObject* types, VMObject* modifiers) {
- VMCommonClass* type = (VMCommonClass*)((*N3::typeClrType)(Type).PointerVal);
- const UTF8* name = str->value;
- if (memberTypes == MEMBER_TYPES_PROPERTY) {
- std::vector<Property*, gc_allocator<Property*> > properties =
- type->properties;
- Property *res = 0;
- for (std::vector<Property*, gc_allocator<Property*> >::iterator i = properties.begin(),
- e = properties.end(); i!= e; ++i) {
- if ((*i)->name == name) {
- res = *i;
- break;
- }
- }
- if (res == 0) VMThread::get()->vm->error("implement me");
- return res->getPropertyDelegatee();
- } else if (memberTypes == MEMBER_TYPES_METHOD) {
- std::vector<VMMethod*> virtualMethods = type->virtualMethods;
- std::vector<VMMethod*> staticMethods = type->staticMethods;
-
- for (std::vector<VMMethod*>::iterator i = virtualMethods.begin(),
- e = virtualMethods.end(); i!= e; ++i) {
- VMMethod* meth = *i;
- if (meth->name == name) {
- if (parameterMatch(meth->parameters, types, true)) {
- return meth->getMethodDelegatee();
- }
- }
- }
-
- for (std::vector<VMMethod*>::iterator i = staticMethods.begin(),
- e = staticMethods.end(); i!= e; ++i) {
- VMMethod* meth = *i;
- if (meth->name == name) {
- if (parameterMatch(meth->parameters, types, false)) {
- return meth->getMethodDelegatee();
- }
- }
- }
-
- } else {
- VMThread::get()->vm->error("implement me");
- }
- return 0;
-}
-
-extern "C" VMObject* System_Reflection_ClrHelpers_GetSemantics(mvm::Object* item, uint32 attributes, bool nonPublic) {
- if (item->getVirtualTable() == Property::VT) {
- Property* prop = (Property*)item;
- if (attributes == METHOD_SEMANTIC_ATTRIBUTES_GETTER) {
- char* asciiz = prop->name->UTF8ToAsciiz();
- char* buf = (char*)alloca(strlen(asciiz) + 5);
- sprintf(buf, "get_%s", asciiz);
- VirtualMachine* vm = VMThread::get()->vm;
- VMMethod* meth = prop->type->lookupMethod(vm->asciizConstructUTF8(buf), prop->parameters, true, false);
- assert(meth);
- return meth->getMethodDelegatee();
- }
- } else {
- VMThread::get()->vm->error("implement me");
- }
- return 0;
-}
-
-static void decapsulePrimitive(VMObject* arg, const llvm::Type* type, std::vector<llvm::GenericValue>& args) {
- if (type == llvm::Type::Int1Ty) {
- llvm::GenericValue gv;
- gv.IntVal = llvm::APInt(1, (bool)((uint32*)arg)[VALUE_OFFSET]);
- args.push_back(gv);
- } else if (type == llvm::Type::Int8Ty) {
- llvm::GenericValue gv;
- gv.IntVal = llvm::APInt(8, (uint8)((uint32*)arg)[VALUE_OFFSET]);
- args.push_back(gv);
- } else if (type == llvm::Type::Int16Ty) {
- llvm::GenericValue gv;
- gv.IntVal = llvm::APInt(16, (uint16)((uint32*)arg)[VALUE_OFFSET]);
- args.push_back(gv);
- } else if (type == llvm::Type::Int32Ty) {
- llvm::GenericValue gv;
- gv.IntVal = llvm::APInt(32, (uint32)((uint32*)arg)[VALUE_OFFSET]);
- args.push_back(gv);
- } else if (type == llvm::Type::Int64Ty) {
- llvm::GenericValue gv;
- uint32* ptr = &((uint32*)arg)[VALUE_OFFSET];
- gv.IntVal = llvm::APInt(64, ((uint64*)ptr)[0]);
- args.push_back(gv);
- } else if (type == llvm::Type::FloatTy) {
- llvm::GenericValue gv;
- float* ptr = &((float*)arg)[VALUE_OFFSET];
- gv.FloatVal = ((float*)ptr)[0];
- args.push_back(gv);
- } else if (type == llvm::Type::DoubleTy) {
- llvm::GenericValue gv;
- uint32* ptr = &((uint32*)arg)[VALUE_OFFSET];
- gv.DoubleVal = ((double*)ptr)[0];
- args.push_back(gv);
- } else if (type == llvm::PointerType::getUnqual(llvm::Type::Int8Ty)) {
- llvm::GenericValue gv(((void**)arg)[VALUE_OFFSET]);
- args.push_back(gv);
- } else {
- VMThread::get()->vm->error("implement me");
- }
-}
-
-extern "C" VMObject* System_Reflection_ClrMethod_Invoke(VMObject* Method, VMObject* obj, sint32 invokeAttr, VMObject* binder, ArrayObject* args, VMObject* culture) {
- VMMethod* meth = (VMMethod*)(*N3::methodMethodType)(Method).PointerVal;
- meth->getSignature();
- meth->compiledPtr();
- llvm::Function* func = CLIJit::compile(meth->classDef, meth);
- VMClass* type = meth->classDef;
- type->resolveStatic(true);
- uint32 virt = meth->virt;
-
- if ((obj != 0) && virt) {
- if (!(obj->classOf->isAssignableFrom(type))) {
- VMThread::get()->vm->illegalArgumentException(meth->name->printString());
- }
- verifyNull(obj);
- }
-
- std::vector<llvm::GenericValue> gvargs;
- uint32 index = 0;
-
- llvm::Function::arg_iterator i = func->arg_begin();
- llvm::Function::arg_iterator e = func->arg_end();
- if (virt) {
- llvm::GenericValue gv(obj);
- gvargs.push_back(gv);
- ++i;
- }
-
- for ( ;i != e; ++i, ++index) {
- const llvm::Type* type = i->getType();
- if (llvm::isa<llvm::PointerType>(type) && type != llvm::PointerType::getUnqual(llvm::Type::Int8Ty)) {
- llvm::GenericValue gv(args->elements[index]);
- gvargs.push_back(gv);
- } else {
- decapsulePrimitive(args->elements[index], type, gvargs);
- }
- }
-
- llvm::GenericValue gv;
- try{
- gv = (*meth)(gvargs);
- }catch(...) {
- assert(0);
- }
-
- VMObject* res = 0;
- VMCommonClass* retType = meth->parameters[0];
- if (retType == N3::pVoid) {
- res = (*N3::pVoid)();
- } else if (retType == N3::pBoolean) {
- res = (*N3::pBoolean)();
- (*N3::ctorBoolean)(res, gv.IntVal.getBoolValue());
- } else if (retType == N3::pUInt8) {
- res = (*N3::pUInt8)();
- (*N3::ctorUInt8)(res, (uint8)gv.IntVal.getZExtValue());
- } else if (retType == N3::pSInt8) {
- res = (*N3::pSInt8)();
- (*N3::ctorSInt8)(res, (uint8)gv.IntVal.getSExtValue());
- } else if (retType == N3::pChar) {
- res = (*N3::pChar)();
- (*N3::ctorChar)(res, (uint16)gv.IntVal.getZExtValue());
- } else if (retType == N3::pSInt16) {
- res = (*N3::pSInt16)();
- (*N3::ctorSInt16)(res, (sint16)gv.IntVal.getSExtValue());
- } else if (retType == N3::pUInt16) {
- res = (*N3::pUInt16)();
- (*N3::ctorUInt16)(res, (uint16)gv.IntVal.getZExtValue());
- } else if (retType == N3::pSInt32) {
- res = (*N3::pSInt32)();
- (*N3::ctorSInt32)(res, (sint32)gv.IntVal.getSExtValue());
- } else if (retType == N3::pUInt32) {
- res = (*N3::pUInt32)();
- (*N3::ctorUInt32)(res, (sint32)gv.IntVal.getZExtValue());
- } else if (retType == N3::pSInt64) {
- res = (*N3::pSInt64)();
- (*N3::ctorSInt64)(res, (sint64)gv.IntVal.getSExtValue());
- } else if (retType == N3::pUInt64) {
- res = (*N3::pUInt64)();
- (*N3::ctorUInt64)(res, (sint64)gv.IntVal.getZExtValue());
- } else if (retType == N3::pIntPtr) {
- res = (*N3::pIntPtr)();
- (*N3::ctorIntPtr)(res, (void*)gv.IntVal.getSExtValue());
- } else if (retType == N3::pUIntPtr) {
- res = (*N3::pUIntPtr)();
- (*N3::ctorUIntPtr)(res, (void*)gv.IntVal.getZExtValue());
- } else if (retType == N3::pFloat) {
- res = (*N3::pFloat)();
- (*N3::ctorFloat)(res, gv.FloatVal);
- } else if (retType == N3::pDouble) {
- res = (*N3::pDouble)();
- (*N3::ctorDouble)(res, gv.DoubleVal);
- } else {
- if (retType->super == N3::pValue || retType->super == N3::pEnum)
- VMThread::get()->vm->error("implement me");
- res = (VMObject*)gv.PointerVal;
- }
-
- return res;
-}
-
-
-static VMObject* createResourceStream(Assembly* ass, sint32 posn) {
- uint32 resSize = ass->resSize;
- uint32 resRva = ass->resRva;
- Section* textSection = ass->textSection;
- uint32 sectionLen = resSize;
- uint32 section = 0;
- uint32 start = 0;
- uint32 length = 0;
- uint32 pad = 0;
-
- Reader* reader = Reader::allocateReader(ass->bytes);
- section = textSection->rawAddress + (resRva - textSection->virtualAddress);
-
- reader->seek(section, Reader::SeekSet);
- while (posn > 0) {
- if (sectionLen < 4) return 0;
- length = reader->readU4();
- if (length > (sectionLen - 4)) return 0;
- if ((length % 4) != 0) {
- pad = 4 - (length % 4);
- } else {
- pad = 0;
- }
- start = start + length + pad + 4;
- section = section + length + pad + 4;
- reader->seek(section + length + pad + 4, Reader::SeekSet);
- sectionLen = sectionLen - (length + pad + 4);
- posn = posn - 1;
- }
-
- start = start + 4;
- if (sectionLen < 4) return 0;
- length = reader->readU4();
- if (length > (sectionLen - 4)) return 0;
-
- VMObject* res = (*N3::resourceStreamType)();
- (*N3::ctorResourceStreamType)(res, ass, (uint64)start, (uint64)length);
-
- return res;
-}
-
-extern "C" VMObject* System_Reflection_Assembly_GetManifestResourceStream(VMObject* Ass, CLIString* str) {
- Assembly* ass = (Assembly*)(*N3::assemblyAssemblyReflection)(Ass).PointerVal;
- const UTF8* utf8 = str->value;
- Header* header = ass->CLIHeader;
- uint32 stringOffset = header->stringStream->realOffset;
- Table* manTable = header->tables[CONSTANT_ManifestResource];
- uint32 manRows = manTable->rowsNumber;
- sint32 pos = -1;
- uint32 i = 0;
- VirtualMachine* vm = VMThread::get()->vm;
-
- while ((pos == -1) && (i < manRows)) {
- uint32 nameOffset = manTable->readIndexInRow(i + 1, CONSTANT_MANIFEST_RESOURCE_NAME, ass->bytes);
- const UTF8* name = ass->readString(vm, stringOffset + nameOffset);
-
- if (name == utf8) {
- pos = i;
- } else {
- ++i;
- }
- }
-
- if (pos != -1) {
- return createResourceStream(ass, pos);
- } else {
- return 0;
- }
-}
-
-
-extern "C" ArrayObject* System_Reflection_ClrHelpers_GetCustomAttributes(Assembly* ass, VMCommonClass* clrTypePrivate, bool inherit) {
- return ass->getCustomAttributes(clrTypePrivate->token, clrTypePrivate);
-}
-
-extern "C" VMObject* System_Globalization_TextInfo_ToLower(VMObject* obj, CLIString* str) {
- verifyNull(str);
- const UTF8* utf8 = str->value;
- uint32 length = str->length;
-
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
-
- VirtualMachine* vm = VMThread::get()->vm;
-
- memcpy(buf, utf8->elements, length * sizeof(uint16));
- ILUnicodeStringToLower((void*)buf, (void*)utf8->elements, length);
- const UTF8* res = vm->readerConstructUTF8(buf, length);
- return ((N3*)vm)->UTF8ToStr(res);
-}
-
-extern "C" VMObject* System_String_Replace(CLIString* str, uint16 c1, uint16 c2) {
- const UTF8* utf8 = str->value;
- uint32 length = str->length;
- if ((c1 == c2) || length == 0) return str;
-
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
- memcpy(buf, utf8->elements, length * sizeof(uint16));
- for (uint32 i = 0; i < length; ++i) {
- if (buf[i] == c1) buf[i] = c2;
- }
-
- N3* vm = (N3*)VMThread::get()->vm;
- const UTF8* res = vm->readerConstructUTF8(buf, length);
- return vm->UTF8ToStr(res);
-}
-
-extern "C" uint32 System_Reflection_ClrResourceStream_ResourceRead(Assembly* assembly, uint64 position, ArrayUInt8* buffer, uint32 offset, uint32 count) {
- uint32 resRva = assembly->resRva;
- ArrayUInt8* bytes = assembly->bytes;
- Section* textSection = assembly->textSection;
- uint32 section = 0;
-
- section = textSection->rawAddress + (resRva - textSection->virtualAddress);
- memcpy(&(buffer->elements[offset]), &(bytes->elements[section + position]), count);
-
- return count;
-}
-
-extern "C" sint32 System_String_CompareInternal(CLIString* strA, sint32 indexA, sint32 lengthA, CLIString* strB, sint32 indexB, sint32 lengthB, bool ignoreCase) {
- if (strA == 0) {
- if (strB == 0) {
- return 0;
- }
- return -1;
- } else if (strB == 0) {
- return 1;
- } else {
- sint32 cmp = 0;
- if (lengthA >= lengthB) {
- if (ignoreCase) {
- cmp = ILUnicodeStringCompareIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthB);
- } else {
- cmp = ILUnicodeStringCompareNoIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthB);
- }
-
- if (cmp != 0) return cmp;
- else if (lengthA > lengthB) return 1;
- else return 0;
- } else {
- if (ignoreCase) {
- cmp = ILUnicodeStringCompareIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthA);
- } else {
- cmp = ILUnicodeStringCompareNoIgnoreCase((void*)&(strA->value->elements[indexA]), (void*)&(strB->value->elements[indexB]), lengthA);
- }
-
- if (cmp != 0) return cmp;
- else return -1;
- }
- }
-}
-
-extern "C" void System_String_CharFill(CLIString* str, sint32 start, sint32 count, char ch) {
- const UTF8* utf8 = str->value;
- sint32 length = start + count;
- uint16* buf = (uint16*)alloca(length * sizeof(uint16));
-
- memcpy(buf, utf8->elements, start * sizeof(uint16));
- for (sint32 i = 0; i < count; ++i) {
- buf[i + start] = ch;
- }
-
- VirtualMachine* vm = VMThread::get()->vm;
- const UTF8* val = vm->readerConstructUTF8(buf, length);
- str->value = val;
- str->length = length;
-}
-
-
-extern "C" sint32 System_String_InternalOrdinal(CLIString *strA, sint32 indexA, sint32 lengthA,
- CLIString *strB, sint32 indexB, sint32 lengthB) {
- const uint16 *bufA;
- const uint16 *bufB;
-
- /* Handle the easy cases first */
- if(!strA)
- {
- if(!strB)
- {
- return 0;
- }
- else
- {
- return -1;
- }
- }
- else if(!strB)
- {
- return 1;
- }
-
- /* Compare the two strings */
- bufA = &(strA->value->elements[indexA]);
- bufB = &(strB->value->elements[indexB]);
- while(lengthA > 0 && lengthB > 0)
- {
- if(*bufA < *bufB)
- {
- return -1;
- }
- else if(*bufA > *bufB)
- {
- return 1;
- }
- ++bufA;
- ++bufB;
- --lengthA;
- --lengthB;
- }
-
- /* Determine the ordering based on the tail sections */
- if(lengthA > 0)
- {
- return 1;
- }
- else if(lengthB > 0)
- {
- return -1;
- }
- else
- {
- return 0;
- }
-}
-
-extern "C" void System_GC_Collect() {
-#ifdef MULTIPLE_GC
- mvm::Thread::get()->GC->collect();
-#else
- Collector::collect();
-#endif
-}
-
-
-
-void NativeUtil::initialise() {
- intptr_t p;
- p = (intptr_t)&System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray;
-}
Removed: vmkit/trunk/lib/N3/VMCore/PNetLib.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/PNetLib.h?rev=52957&view=auto
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/PNetLib.h (original)
+++ vmkit/trunk/lib/N3/VMCore/PNetLib.h (removed)
@@ -1,30 +0,0 @@
-//===----------------- PNetLib.h - PNetLib interface ----------------------===//
-//
-// N3
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#ifndef N3_PNETLIB_H
-#define N3_PNETLIB_H
-
-#include "VMObject.h"
-
-
-namespace n3 {
-
-class CLIString;
-
-class StringBuilder : public VMObject {
-public:
- CLIString* buildString;
- sint32 maxCapactiy;
- sint32 needsCopy;
-};
-
-}
-
-#endif
Modified: vmkit/trunk/lib/N3/VMCore/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Reader.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Reader.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Reader.cpp Tue Jul 1 08:41:02 2008
@@ -12,6 +12,7 @@
#include "types.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "VMArray.h"
#include "VMThread.h"
@@ -58,7 +59,7 @@
fseek(fp, 0, SeekEnd);
long nbb = ftell(fp);
fseek(fp, 0, SeekSet);
- res = ArrayUInt8::acons(nbb, N3::arrayByte);
+ res = ArrayUInt8::acons(nbb, MSCorlib::arrayByte);
fread(res->elements, nbb, 1, fp);
fclose(fp);
}
Modified: vmkit/trunk/lib/N3/VMCore/VMCache.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMCache.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMCache.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMCache.cpp Tue Jul 1 08:41:02 2008
@@ -20,6 +20,7 @@
#include "Assembly.h"
#include "CLIJit.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "VirtualMachine.h"
#include "VMArray.h"
@@ -204,7 +205,7 @@
Function* func = dmeth->compiledPtr();
rcache->methPtr = mvm::jit::executionEngine->getPointerToGlobal(func);
rcache->lastCible = (VMClass*)ocl;
- rcache->box = (dmeth->classDef->super == N3::pValue);
+ rcache->box = (dmeth->classDef->super == MSCorlib::pValue);
}
if (enveloppe->firstCache != rcache) {
Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Tue Jul 1 08:41:02 2008
@@ -22,6 +22,7 @@
#include "Assembly.h"
#include "CLIAccess.h"
#include "CLIJit.h"
+#include "MSCorlib.h"
#include "N3.h"
#include "VirtualMachine.h"
#include "VMArray.h"
@@ -211,7 +212,7 @@
cl->status = inClinit;
std::vector<VMCommonClass*> args;
- args.push_back(N3::pVoid);
+ args.push_back(MSCorlib::pVoid);
VMMethod* meth = cl->lookupMethodDontThrow(N3::clinitName, args,
true, false);
@@ -293,7 +294,7 @@
((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(type);
naturalType = type;
} else if (super != 0) {
- if (super == N3::pValue) {
+ if (super == MSCorlib::pValue) {
uint32 size = virtualFields.size();
if (size == 1) {
virtualFields[0]->offset = mvm::jit::constantZero;
@@ -319,7 +320,7 @@
((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(tmp);
naturalType = tmp;
}
- } else if (super == N3::pEnum) {
+ } else if (super == MSCorlib::pEnum) {
((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(llvm::Type::Int32Ty); // TODO find max
naturalType = llvm::Type::Int32Ty;
} else {
@@ -345,7 +346,7 @@
unifyTypes();
- if (super == N3::pValue) {
+ if (super == MSCorlib::pValue) {
std::vector<const llvm::Type*> Elts;
Elts.push_back(VMObject::llvmType->getContainedType(0));
for (std::vector<VMField*>::iterator i = virtualFields.begin(),
@@ -357,7 +358,7 @@
virtualType = naturalType;
}
- if (super != N3::pEnum) {
+ if (super != MSCorlib::pEnum) {
VirtualTable* VT = CLIJit::makeVT(this, false);
uint64 size = mvm::jit::getTypeSize(cl->virtualType->getContainedType(0));
@@ -663,7 +664,7 @@
if (cur->naturalType->isAbstract()) {
cur->resolveType(false, false);
}
- if (cur->super != N3::pValue && cur->super != N3::pEnum) {
+ if (cur->super != MSCorlib::pValue && cur->super != MSCorlib::pEnum) {
args.push_back(cur->naturalType);
} else {
args.push_back(llvm::PointerType::getUnqual(cur->naturalType));
@@ -764,36 +765,36 @@
VMObject* Property::getPropertyDelegatee() {
if (!delegatee) {
- delegatee = (*N3::propertyType)();
- (*N3::ctorPropertyType)(delegatee);
- (*N3::propertyPropertyType)(delegatee, (VMObject*)this);
+ delegatee = (*MSCorlib::propertyType)();
+ (*MSCorlib::ctorPropertyType)(delegatee);
+ (*MSCorlib::propertyPropertyType)(delegatee, (VMObject*)this);
}
return delegatee;
}
VMObject* VMMethod::getMethodDelegatee() {
if (!delegatee) {
- delegatee = (*N3::methodType)();
- (*N3::ctorMethodType)(delegatee);
- (*N3::methodMethodType)(delegatee, (VMObject*)this);
+ delegatee = (*MSCorlib::methodType)();
+ (*MSCorlib::ctorMethodType)(delegatee);
+ (*MSCorlib::methodMethodType)(delegatee, (VMObject*)this);
}
return delegatee;
}
VMObject* VMCommonClass::getClassDelegatee() {
if (!delegatee) {
- delegatee = (*N3::clrType)();
- (*N3::ctorClrType)(delegatee);
- (*N3::typeClrType)(delegatee, (VMObject*)this);
+ delegatee = (*MSCorlib::clrType)();
+ (*MSCorlib::ctorClrType)(delegatee);
+ (*MSCorlib::typeClrType)(delegatee, (VMObject*)this);
}
return delegatee;
}
VMObject* Assembly::getAssemblyDelegatee() {
if (!delegatee) {
- delegatee = (*N3::assemblyReflection)();
- (*N3::ctorAssemblyReflection)(delegatee);
- (*N3::assemblyAssemblyReflection)(delegatee, (VMObject*)this);
+ delegatee = (*MSCorlib::assemblyReflection)();
+ (*MSCorlib::ctorAssemblyReflection)(delegatee);
+ (*MSCorlib::assemblyAssemblyReflection)(delegatee, (VMObject*)this);
}
return delegatee;
}
Modified: vmkit/trunk/lib/N3/VMCore/VMThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMThread.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMThread.cpp Tue Jul 1 08:41:02 2008
@@ -17,7 +17,6 @@
#include "Assembly.h"
#include "CLIJit.h"
-#include "CLIString.h"
#include "N3ModuleProvider.h"
#include "VMClass.h"
#include "VMObject.h"
Modified: vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp Tue Jul 1 08:41:02 2008
@@ -21,7 +21,6 @@
#include "types.h"
#include "Assembly.h"
-#include "CLIString.h"
#include "LockedMap.h"
#include "N3ModuleProvider.h"
#include "VirtualMachine.h"
Modified: vmkit/trunk/tools/n3/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3/Makefile?rev=52958&r1=52957&r2=52958&view=diff
==============================================================================
--- vmkit/trunk/tools/n3/Makefile (original)
+++ vmkit/trunk/tools/n3/Makefile Tue Jul 1 08:41:02 2008
@@ -12,7 +12,7 @@
TOOLNAME = n3
LINK_COMPONENTS = engine scalaropts instrumentation ipa ipo
-USEDLIBS = Allocator CommonThread Mvm N3 Main $(GCLIB)
+USEDLIBS = Allocator CommonThread Mvm N3 Main $(GCLIB) $(N3_LIB)
include $(LEVEL)/Makefile.common
More information about the vmkit-commits
mailing list