From nicolas.geoffray at lip6.fr Tue Jul 1 02:33:46 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 09:33:46 -0000 Subject: [vmkit-commits] [vmkit] r52953 - in /vmkit/trunk/lib/JnJVM/VMCore: Jnjvm.cpp Jnjvm.h Reader.cpp Reader.h VirtualTables.cpp Zip.cpp Zip.h Message-ID: <200807010933.m619XlYl011461@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 04:33:44 2008 New Revision: 52953 URL: http://llvm.org/viewvc/llvm-project?rev=52953&view=rev Log: JnJVM can now take glibj.zip and other .zip files as the base libraries. Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp vmkit/trunk/lib/JnJVM/VMCore/Reader.h vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp vmkit/trunk/lib/JnJVM/VMCore/Zip.h Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Tue Jul 1 04:33:44 2008 @@ -151,7 +151,14 @@ bootClasspath.push_back(temp); free(rp); } else { - bootClasspath.push_back(rp); + ArrayUInt8* bytes = Reader::openFile(this, rp); + free(rp); + if (bytes) { + ZipArchive *archive = new ZipArchive(bytes); + if (archive) { + bootArchives.push_back(archive); + } + } } } else { free(rp); @@ -278,26 +285,30 @@ ArrayUInt8* Jnjvm::openName(const UTF8* utf8) { char* asciiz = utf8->UTF8ToAsciiz(); uint32 alen = strlen(asciiz); - uint32 nbcp = bootClasspath.size(); - uint32 idx = 0; ArrayUInt8* res = 0; - while ((res == 0) && (idx < nbcp)) { - char* str = bootClasspath[idx]; + for (std::vector::iterator i = bootClasspath.begin(), + e = bootClasspath.end(); i != e; ++i) { + const char* str = *i; unsigned int strLen = strlen(str); - char* buf = (char*)alloca(strLen + alen + 16); + char* buf = (char*)alloca(strLen + alen + 7); - if (str[strLen - 1] == dirSeparator[0]) { - sprintf(buf, "%s%s.class", str, asciiz); - res = Reader::openFile(this, buf); - } else { - sprintf(buf, "%s.class", asciiz); - res = Reader::openZip(this, str, buf); - } - idx++; + sprintf(buf, "%s%s.class", str, asciiz); + res = Reader::openFile(this, buf); + if (res) return res; } - return res; + for (std::vector::iterator i = bootArchives.begin(), + e = bootArchives.end(); i != e; ++i) { + + ZipArchive* archive = *i; + char* buf = (char*)alloca(alen + 7); + sprintf(buf, "%s.class", asciiz); + res = Reader::openZip(this, archive, buf); + if (res) return res; + } + + return 0; } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Tue Jul 1 04:33:44 2008 @@ -53,7 +53,7 @@ class FunctionDefMap; class FunctionDefMap; class AllocationMap; - +class ZipArchive; class Jnjvm : public mvm::Object{ public: @@ -228,7 +228,8 @@ void* jniEnv; const void* javavmEnv; std::vector< std::pair > postProperties; - std::vector bootClasspath; + std::vector bootClasspath; + std::vector bootArchives; std::vector nativeLibs; const char* classpath; const char* libClasspathEnv; Modified: vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp Tue Jul 1 04:33:44 2008 @@ -38,16 +38,13 @@ return res; } -ArrayUInt8* Reader::openZip(Jnjvm* vm, char* zipname, char* filename) { - ZipArchive* archive = ZipArchive::hashedArchive(vm, zipname); +ArrayUInt8* Reader::openZip(Jnjvm* vm, ZipArchive* archive, char* filename) { ArrayUInt8* ret = 0; - if (archive != 0) { - ZipFile* file = archive->getFile(filename); - if (file != 0) { - ArrayUInt8* res = ArrayUInt8::acons(file->ucsize, JavaArray::ofByte, vm); - if (archive->readFile(res, file) != 0) { - ret = res; - } + ZipFile* file = archive->getFile(filename); + if (file != 0) { + ArrayUInt8* res = ArrayUInt8::acons(file->ucsize, JavaArray::ofByte, vm); + if (archive->readFile(res, file) != 0) { + ret = res; } } return ret; Modified: vmkit/trunk/lib/JnJVM/VMCore/Reader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Reader.h?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Reader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Reader.h Tue Jul 1 04:33:44 2008 @@ -20,6 +20,7 @@ namespace jnjvm { class Jnjvm; +class ZipArchive; class Reader { public: @@ -76,7 +77,7 @@ static const int SeekEnd; static ArrayUInt8* openFile(Jnjvm* vm, char* path); - static ArrayUInt8* openZip(Jnjvm* vm, char* zipname, char* filename); + static ArrayUInt8* openZip(Jnjvm* vm, ZipArchive* archive, char* filename); uint8 readU1() { return bytes->elements[cursor++]; Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Tue Jul 1 04:33:44 2008 @@ -104,6 +104,12 @@ statics->MARK_AND_TRACE; delegatees->MARK_AND_TRACE; #endif + + for (std::vector::iterator i = bootArchives.begin(), + e = bootArchives.end(); i != e; ++i) { + (*i)->bytes->MARK_AND_TRACE; + } + } void JavaIsolate::TRACER { Modified: vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp Tue Jul 1 04:33:44 2008 @@ -15,11 +15,6 @@ using namespace jnjvm; -ZipArchive* ZipArchive::hashedArchive(Jnjvm* vm, const char* name) { - assert(0 && "implement hashedArchive"); - return 0; -} - ZipArchive::ZipArchive(ArrayUInt8* bytes) { this->bytes = bytes; findOfscd(); Modified: vmkit/trunk/lib/JnJVM/VMCore/Zip.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Zip.h?rev=52953&r1=52952&r2=52953&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Zip.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Zip.h Tue Jul 1 04:33:44 2008 @@ -15,6 +15,7 @@ namespace jnjvm { class ArrayUInt8; +class Jnjvm; struct ZipFile { char* filename; @@ -30,6 +31,7 @@ class ZipArchive { + friend class Jnjvm; private: struct ltstr @@ -62,7 +64,6 @@ int getOfscd() { return ofscd; } ZipArchive(ArrayUInt8* bytes); - static ZipArchive* hashedArchive(Jnjvm* vm, const char* archname); ZipFile* getFile(const char* filename); int readFile(ArrayUInt8* array, const ZipFile* file); From nicolas.geoffray at lip6.fr Tue Jul 1 02:34:57 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 09:34:57 -0000 Subject: [vmkit-commits] [vmkit] r52954 - in /vmkit/trunk: autoconf/configure.ac configure lib/JnJVM/Classpath/Classpath.h.in Message-ID: <200807010934.m619Yv11011501@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 04:34:57 2008 New Revision: 52954 URL: http://llvm.org/viewvc/llvm-project?rev=52954&view=rev Log: JnJVM is configured by giving the GNU Classpath lib directory and the glibj.zip path. Modified: vmkit/trunk/autoconf/configure.ac vmkit/trunk/configure vmkit/trunk/lib/JnJVM/Classpath/Classpath.h.in Modified: vmkit/trunk/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/autoconf/configure.ac?rev=52954&r1=52953&r2=52954&view=diff ============================================================================== --- vmkit/trunk/autoconf/configure.ac (original) +++ vmkit/trunk/autoconf/configure.ac Tue Jul 1 04:34:57 2008 @@ -238,47 +238,45 @@ dnl GNU CLASSPATH installation prefix dnl ************************************************************************** -gnuclasspathversion=0.93; +classpathversion=0.97.2; -AC_ARG_WITH(gnu-classpath-local-prefix, - [AS_HELP_STRING(--with-gnu-classpath-local-prefix=something, - [GNU CLASSPATH local prefix (no default)])], - [[gnuclasspathlocalprefix=$withval]], - [[ echo Not using GNU CLASSPATH local prefix. - gnuclasspathlocalprefix='' - ]] +AC_ARG_WITH(gnu-classpath-libs, + [AS_HELP_STRING(--with-gnu-classpath-libs=something, + [GNU CLASSPATH libraries (default is /usr/lib/classpath)])], + [[classpathlibs=$withval]], + [[classpathlibs=/usr/lib/classpath]] ) -AC_ARG_WITH(gnu-classpath-installation-prefix, - [AS_HELP_STRING(--with-gnu-classpath-installation-prefix=something, - [GNU CLASSPATH installation prefix (default is '/usr/local/classpath')])], - [[gnuclasspathinstallationprefix=$withval]], - [[gnuclasspathinstallationprefix=/usr/local/classpath]] +AC_ARG_WITH(gnu-classpath-glibj, + [AS_HELP_STRING(--with-gnu-classpath-glibj, + [Build JnJVM with GNU Classpath install (default is '/usr/share/classpath/glibj.zip')])], + [[classpathglibj=$withval]], + [[classpathglibj=/usr/share/classpath/glibj.zip]] ) -WITH_JNJVM=0; - -if test "x${gnuclasspathinstallationprefix}" != x; then - echo Using ${gnuclasspathinstallationprefix} as GNU CLASSPATH installation prefix; - classpathglibj=${gnuclasspathinstallationprefix}/share/classpath/glibj.zip; - classpathlibs=${gnuclasspathinstallationprefix}/lib/classpath/; - classpathinclude=${gnuclasspathlocalprefix}/include; - WITH_JNJVM=1; -fi +AC_ARG_WITH(jnjvm, + [AS_HELP_STRING(--with-jnjvm=yes|no, + [Build JnJVM (default is yes)])], + [[WITH_JNJVM=$withval]], + [[WITH_JNJVM=yes]] +) -if test "x${gnuclasspathlocalprefix}" != x; then - echo Using ${gnuclasspathlocalprefix} as GNU CLASSPATH local prefix; - classpathglibj=${gnuclasspathlocalprefix}/lib/; - classpathlibs=${gnuclasspathlocalprefix}/lib/; - classpathinclude=${gnuclasspathlocalprefix}/include; - WITH_JNJVM=1; +if test "x${classpathlibs}" != "x/usr/lib/classpath"; then + classpathinclude=${classpathlibs}/../include:/usr/include/classpath; +else + classpathinclude=/usr/include/classpath; fi +if test "x${WITH_JNJVM}" = "xyes"; then + WITH_JNJVM=1; +else + WITH_JNJVM=0; +fi AC_SUBST([classpathglibj]) AC_SUBST([classpathlibs]) AC_SUBST([classpathinclude]) -AC_SUBST([gnuclasspathversion]) +AC_SUBST([classpathversion]) AC_SUBST([WITH_JNJVM]) dnl ************************************************************************** Modified: vmkit/trunk/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/configure?rev=52954&r1=52953&r2=52954&view=diff ============================================================================== --- vmkit/trunk/configure (original) +++ vmkit/trunk/configure Tue Jul 1 04:34:57 2008 @@ -694,7 +694,7 @@ classpathglibj classpathlibs classpathinclude -gnuclasspathversion +classpathversion WITH_JNJVM pnetlocalprefix WITH_N3 @@ -1318,11 +1318,13 @@ --with-gc=something GC type ('single-mmap' 'multi-mmap' or 'boehm') --with-vm-type=something VM type ('single' 'multi' or 'service') - --with-gnu-classpath-local-prefix=something - GNU CLASSPATH local prefix (no default) - --with-gnu-classpath-installation-prefix=something - GNU CLASSPATH installation prefix (default is - '/usr/local/classpath') + --with-gnu-classpath-libs=something + GNU CLASSPATH libraries (default is + /usr/lib/classpath) + --with-gnu-classpath-glibj + Build JnJVM with GNU Classpath install (default is + '/usr/share/classpath/glibj.zip') + --with-jnjvm=yes|no Build JnJVM (default is yes) --with-pnet-local-prefix=something PNET local prefix (no default) @@ -3964,48 +3966,49 @@ -gnuclasspathversion=0.93; +classpathversion=0.97.2; -# Check whether --with-gnu-classpath-local-prefix was given. -if test "${with_gnu_classpath_local_prefix+set}" = set; then - withval=$with_gnu_classpath_local_prefix; gnuclasspathlocalprefix=$withval +# Check whether --with-gnu-classpath-libs was given. +if test "${with_gnu_classpath_libs+set}" = set; then + withval=$with_gnu_classpath_libs; classpathlibs=$withval else - echo Not using GNU CLASSPATH local prefix. - gnuclasspathlocalprefix='' - + classpathlibs=/usr/lib/classpath fi -# Check whether --with-gnu-classpath-installation-prefix was given. -if test "${with_gnu_classpath_installation_prefix+set}" = set; then - withval=$with_gnu_classpath_installation_prefix; gnuclasspathinstallationprefix=$withval +# Check whether --with-gnu-classpath-glibj was given. +if test "${with_gnu_classpath_glibj+set}" = set; then + withval=$with_gnu_classpath_glibj; classpathglibj=$withval else - gnuclasspathinstallationprefix=/usr/local/classpath + classpathglibj=/usr/share/classpath/glibj.zip fi -WITH_JNJVM=0; -if test "x${gnuclasspathinstallationprefix}" != x; then - echo Using ${gnuclasspathinstallationprefix} as GNU CLASSPATH installation prefix; - classpathglibj=${gnuclasspathinstallationprefix}/share/classpath/glibj.zip; - classpathlibs=${gnuclasspathinstallationprefix}/lib/classpath/; - classpathinclude=${gnuclasspathlocalprefix}/include; - WITH_JNJVM=1; +# Check whether --with-jnjvm was given. +if test "${with_jnjvm+set}" = set; then + withval=$with_jnjvm; WITH_JNJVM=$withval +else + WITH_JNJVM=yes + fi -if test "x${gnuclasspathlocalprefix}" != x; then - echo Using ${gnuclasspathlocalprefix} as GNU CLASSPATH local prefix; - classpathglibj=${gnuclasspathlocalprefix}/lib/; - classpathlibs=${gnuclasspathlocalprefix}/lib/; - classpathinclude=${gnuclasspathlocalprefix}/include; - WITH_JNJVM=1; + +if test "x${classpathlibs}" != "x/usr/lib/classpath"; then + classpathinclude=${classpathlibs}/../include:/usr/include/classpath; +else + classpathinclude=/usr/include/classpath; fi +if test "x${WITH_JNJVM}" = "xyes"; then + WITH_JNJVM=1; +else + WITH_JNJVM=0; +fi @@ -7827,7 +7830,7 @@ classpathglibj!$classpathglibj$ac_delim classpathlibs!$classpathlibs$ac_delim classpathinclude!$classpathinclude$ac_delim -gnuclasspathversion!$gnuclasspathversion$ac_delim +classpathversion!$classpathversion$ac_delim WITH_JNJVM!$WITH_JNJVM$ac_delim pnetlocalprefix!$pnetlocalprefix$ac_delim WITH_N3!$WITH_N3$ac_delim Modified: vmkit/trunk/lib/JnJVM/Classpath/Classpath.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/Classpath.h.in?rev=52954&r1=52953&r2=52954&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/Classpath.h.in (original) +++ vmkit/trunk/lib/JnJVM/Classpath/Classpath.h.in Tue Jul 1 04:34:57 2008 @@ -10,5 +10,5 @@ const char* GNUClasspathLibs = "@classpathlibs@"; const char* GNUClasspathGlibj = "@classpathglibj@"; -const char* GNUClasspathVersion = "@gnuclasspathversion@"; +const char* GNUClasspathVersion = "@classpathversion@"; From nicolas.geoffray at lip6.fr Tue Jul 1 02:37:31 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 09:37:31 -0000 Subject: [vmkit-commits] [vmkit] r52955 - /vmkit/trunk/www/get_started.html Message-ID: <200807010937.m619bVKf011576@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 04:37:31 2008 New Revision: 52955 URL: http://llvm.org/viewvc/llvm-project?rev=52955&view=rev Log: New configure command lines. Modified: vmkit/trunk/www/get_started.html Modified: vmkit/trunk/www/get_started.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/get_started.html?rev=52955&r1=52954&r2=52955&view=diff ============================================================================== --- vmkit/trunk/www/get_started.html (original) +++ vmkit/trunk/www/get_started.html Tue Jul 1 04:37:31 2008 @@ -138,8 +138,10 @@
Tell vmkit where the LLVM source tree is located.

--with-llvmobj=<directory>
Tell vmkit where the LLVM object tree is located.
-

--with-gnu-classpath-local-prefix=<directory>
-
Tell vmkit where GNU Classpath is located.
+

--with-gnu-classpath-glibj=<file or directory>
+
Tell vmkit where GNU Classpath glibj.zip is located.
+

--with-gnu-classpath-libs=<directory>
+
Tell vmkit where GNU Classpath libs are located.

--with-pnet-local-prefix=<directory>
Tell vmkit where PNet is located.
From nicolas.geoffray at lip6.fr Tue Jul 1 06:41:03 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 13:41:03 -0000 Subject: [vmkit-commits] [vmkit] r52958 - in /vmkit/trunk: ./ autoconf/ lib/N3/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/n3/ Message-ID: <200807011341.m61Df4iv020047@zion.cs.uiuc.edu> 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 + +#include +#include + +#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 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 > properties = + type->properties; + Property *res = 0; + for (std::vector >::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 virtualMethods = type->virtualMethods; + std::vector staticMethods = type->staticMethods; + + for (std::vector::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::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& 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 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(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 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 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 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 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 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 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 Args; @@ -109,7 +109,7 @@ for (std::vector::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 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 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 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 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 #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 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 VMClassArray::VirtualFieldsArray; std::vector 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 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 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 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 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 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 - -#include -#include - -#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 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 > properties = - type->properties; - Property *res = 0; - for (std::vector >::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 virtualMethods = type->virtualMethods; - std::vector staticMethods = type->staticMethods; - - for (std::vector::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::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& 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 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(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 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 Elts; Elts.push_back(VMObject::llvmType->getContainedType(0)); for (std::vector::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 From nicolas.geoffray at lip6.fr Tue Jul 1 07:04:24 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 14:04:24 -0000 Subject: [vmkit-commits] [vmkit] r52959 - in /vmkit/trunk/lib/N3: PNetLib/PNetString.cpp VMCore/CLIJitMeta.cpp Message-ID: <200807011404.m61E4OfL020772@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 09:04:24 2008 New Revision: 52959 URL: http://llvm.org/viewvc/llvm-project?rev=52959&view=rev Log: Put ClIString::llvmVar in classlib directory. Modified: vmkit/trunk/lib/N3/PNetLib/PNetString.cpp vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp Modified: vmkit/trunk/lib/N3/PNetLib/PNetString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetString.cpp?rev=52959&r1=52958&r2=52959&view=diff ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetString.cpp (original) +++ vmkit/trunk/lib/N3/PNetLib/PNetString.cpp Tue Jul 1 09:04:24 2008 @@ -7,6 +7,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/GlobalVariable.h" + +#include "mvm/JIT.h" + #include "CLIString.h" #include "MSCorlib.h" #include "N3.h" @@ -16,6 +20,7 @@ #include "VMThread.h" using namespace n3; +using namespace llvm; CLIString* CLIString::stringDup(const UTF8*& utf8, N3* vm) { @@ -38,3 +43,21 @@ const UTF8* CLIString::strToUTF8(N3* vm) { return ((PNetString*)this)->value; } + +GlobalVariable* CLIString::llvmVar() { + PNetString* str = (PNetString*)this; + if (!str->_llvmVar) { + VirtualMachine* vm = VMThread::get()->vm; + if (!str->_llvmVar) { + const Type* pty = mvm::jit::ptrType; + Constant* cons = + ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t (this)), + pty); + str->_llvmVar = new GlobalVariable(pty, true, + GlobalValue::ExternalLinkage, + cons, "", + vm->module); + } + } + return str->_llvmVar; +} Modified: vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp?rev=52959&r1=52958&r2=52959&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp Tue Jul 1 09:04:24 2008 @@ -422,20 +422,3 @@ ConstantInt* VMObject::classOffset() { return mvm::jit::constantOne; } - -GlobalVariable* CLIString::llvmVar() { - if (!_llvmVar) { - VirtualMachine* vm = VMThread::get()->vm; - if (!_llvmVar) { - const Type* pty = mvm::jit::ptrType; - Constant* cons = - ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t (this)), - pty); - _llvmVar = new GlobalVariable(pty, true, - GlobalValue::ExternalLinkage, - cons, "", - vm->module); - } - } - return _llvmVar; -} From tilmann.scheller at googlemail.com Tue Jul 1 08:31:14 2008 From: tilmann.scheller at googlemail.com (Tilmann Scheller) Date: Tue, 1 Jul 2008 17:31:14 +0200 Subject: [vmkit-commits] [vmkit] r52958 - in /vmkit/trunk: ./ autoconf/ lib/N3/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/n3/ In-Reply-To: <200807011341.m61Df4iv020047@zion.cs.uiuc.edu> References: <200807011341.m61Df4iv020047@zion.cs.uiuc.edu> Message-ID: Hi Nicolas, it seems you forgot to add MSCorlib.h, I'm getting some compilation error due to a missing MSCorlib.h Really nice that there is an interface to the class library now :) Greetings, Tilmann From nicolas.geoffray at lip6.fr Tue Jul 1 10:44:25 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 17:44:25 -0000 Subject: [vmkit-commits] [vmkit] r52968 - /vmkit/trunk/lib/N3/VMCore/MSCorlib.h Message-ID: <200807011744.m61HiPvN028379@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 12:44:25 2008 New Revision: 52968 URL: http://llvm.org/viewvc/llvm-project?rev=52968&view=rev Log: Missed file rom previous patch. Added: vmkit/trunk/lib/N3/VMCore/MSCorlib.h Added: vmkit/trunk/lib/N3/VMCore/MSCorlib.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.h?rev=52968&view=auto ============================================================================== --- vmkit/trunk/lib/N3/VMCore/MSCorlib.h (added) +++ vmkit/trunk/lib/N3/VMCore/MSCorlib.h Tue Jul 1 12:44:25 2008 @@ -0,0 +1,89 @@ +//===------------- MSCorlib.h - The MSCorlib interface --------------------===// +// +// N3 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef N3_MSCORLIB_H +#define N3_MSCORLIB_H + +namespace n3 { + +class N3; +class VMClass; +class VMClassArray; +class VMField; +class VMMethod; + +class MSCorlib { +public: + static void initialise(N3* vm); + static void loadStringClass(N3* vm); + + 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; + + static VMClass* pVoid; + static VMClass* pBoolean; + static VMClass* pChar; + static VMClass* pSInt8; + static VMClass* pUInt8; + static VMClass* pSInt16; + static VMClass* pUInt16; + static VMClass* pSInt32; + static VMClass* pUInt32; + static VMClass* pSInt64; + static VMClass* pUInt64; + static VMClass* pFloat; + static VMClass* pDouble; + static VMClass* pIntPtr; + static VMClass* pUIntPtr; + static VMClass* pString; + static VMClass* pObject; + static VMClass* pValue; + static VMClass* pEnum; + static VMClass* pArray; + static VMClass* pDelegate; + static VMClass* pException; + static VMClassArray* arrayChar; + static VMClassArray* arrayString; + static VMClassArray* arrayByte; + static VMClassArray* arrayObject; + static VMField* ctorBoolean; + static VMField* ctorUInt8; + static VMField* ctorSInt8; + static VMField* ctorChar; + static VMField* ctorSInt16; + static VMField* ctorUInt16; + static VMField* ctorSInt32; + static VMField* ctorUInt32; + static VMField* ctorSInt64; + static VMField* ctorUInt64; + static VMField* ctorIntPtr; + static VMField* ctorUIntPtr; + static VMField* ctorDouble; + static VMField* ctorFloat; +}; + +} // end namespace n3 + +#endif // N3_MSCORLIB_H From nicolas.geoffray at lip6.fr Tue Jul 1 10:45:18 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 17:45:18 -0000 Subject: [vmkit-commits] [vmkit] r52969 - in /vmkit/trunk/lib/N3: PNetLib/PNetMSCorlib.cpp VMCore/VMClass.cpp Message-ID: <200807011745.m61HjI9H028416@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 1 12:45:18 2008 New Revision: 52969 URL: http://llvm.org/viewvc/llvm-project?rev=52969&view=rev Log: Move the get*Delegatee functions to the class library dependent files. Modified: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp vmkit/trunk/lib/N3/VMCore/VMClass.cpp Modified: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp?rev=52969&r1=52968&r2=52969&view=diff ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp Tue Jul 1 12:45:18 2008 @@ -127,3 +127,38 @@ } +VMObject* Property::getPropertyDelegatee() { + if (!delegatee) { + delegatee = (*MSCorlib::propertyType)(); + (*MSCorlib::ctorPropertyType)(delegatee); + (*MSCorlib::propertyPropertyType)(delegatee, (VMObject*)this); + } + return delegatee; +} + +VMObject* VMMethod::getMethodDelegatee() { + if (!delegatee) { + delegatee = (*MSCorlib::methodType)(); + (*MSCorlib::ctorMethodType)(delegatee); + (*MSCorlib::methodMethodType)(delegatee, (VMObject*)this); + } + return delegatee; +} + +VMObject* VMCommonClass::getClassDelegatee() { + if (!delegatee) { + delegatee = (*MSCorlib::clrType)(); + (*MSCorlib::ctorClrType)(delegatee); + (*MSCorlib::typeClrType)(delegatee, (VMObject*)this); + } + return delegatee; +} + +VMObject* Assembly::getAssemblyDelegatee() { + if (!delegatee) { + delegatee = (*MSCorlib::assemblyReflection)(); + (*MSCorlib::ctorAssemblyReflection)(delegatee); + (*MSCorlib::assemblyAssemblyReflection)(delegatee, (VMObject*)this); + } + return delegatee; +} Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=52969&r1=52968&r2=52969&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Tue Jul 1 12:45:18 2008 @@ -276,10 +276,19 @@ } void VMClass::unifyTypes() { + printf("in %s\n", this->printString()); + for (std::vector::iterator i = virtualFields.begin(), e = virtualFields.end(); i!= e; ++i) { + printf("Resolving in %s\n", this->printString()); (*i)->signature->resolveType(false, false); - } + printf("Now I have\n"); + naturalType->print(llvm::cout); + printf("\n"); + } + printf("this = %s\n", this->printString()); + naturalType->print(llvm::cout); + printf("\n"); if (naturalType->isAbstract()) naturalType = naturalType->getForwardedType(); @@ -763,41 +772,6 @@ } } -VMObject* Property::getPropertyDelegatee() { - if (!delegatee) { - delegatee = (*MSCorlib::propertyType)(); - (*MSCorlib::ctorPropertyType)(delegatee); - (*MSCorlib::propertyPropertyType)(delegatee, (VMObject*)this); - } - return delegatee; -} - -VMObject* VMMethod::getMethodDelegatee() { - if (!delegatee) { - delegatee = (*MSCorlib::methodType)(); - (*MSCorlib::ctorMethodType)(delegatee); - (*MSCorlib::methodMethodType)(delegatee, (VMObject*)this); - } - return delegatee; -} - -VMObject* VMCommonClass::getClassDelegatee() { - if (!delegatee) { - delegatee = (*MSCorlib::clrType)(); - (*MSCorlib::ctorClrType)(delegatee); - (*MSCorlib::typeClrType)(delegatee, (VMObject*)this); - } - return delegatee; -} - -VMObject* Assembly::getAssemblyDelegatee() { - if (!delegatee) { - delegatee = (*MSCorlib::assemblyReflection)(); - (*MSCorlib::ctorAssemblyReflection)(delegatee); - (*MSCorlib::assemblyAssemblyReflection)(delegatee, (VMObject*)this); - } - return delegatee; -} bool VMMethod::signatureEquals(std::vector& args) { bool stat = isStatic(flags); From nicolas.geoffray at lip6.fr Tue Jul 1 10:45:55 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 01 Jul 2008 19:45:55 +0200 Subject: [vmkit-commits] [vmkit] r52958 - in /vmkit/trunk: ./ autoconf/ lib/N3/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/n3/ In-Reply-To: References: <200807011341.m61Df4iv020047@zion.cs.uiuc.edu> Message-ID: <486A6D53.50805@lip6.fr> Tilmann Scheller wrote: > Hi Nicolas, > > it seems you forgot to add MSCorlib.h, I'm getting some compilation > error due to a missing MSCorlib.h > Right, sorry for that, I just commited MSCorlib.h. > Really nice that there is an interface to the class library now :) > Indeed! The goal is to implement support for Mono class libraries, which apparently needs generics support :) Nicolas > Greetings, > > Tilmann > _______________________________________________ > vmkit-commits mailing list > vmkit-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/vmkit-commits > From nicolas.geoffray at lip6.fr Wed Jul 2 06:56:08 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 02 Jul 2008 13:56:08 -0000 Subject: [vmkit-commits] [vmkit] r53019 - /vmkit/trunk/lib/N3/VMCore/VMClass.cpp Message-ID: <200807021356.m62DuA9R011617@zion.cs.uiuc.edu> Author: geoffray Date: Wed Jul 2 08:55:49 2008 New Revision: 53019 URL: http://llvm.org/viewvc/llvm-project?rev=53019&view=rev Log: Simplify code (and left out debugging code!). No functioanlity change. Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=53019&r1=53018&r2=53019&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Wed Jul 2 08:55:49 2008 @@ -276,19 +276,11 @@ } void VMClass::unifyTypes() { - printf("in %s\n", this->printString()); - for (std::vector::iterator i = virtualFields.begin(), e = virtualFields.end(); i!= e; ++i) { - printf("Resolving in %s\n", this->printString()); (*i)->signature->resolveType(false, false); - printf("Now I have\n"); - naturalType->print(llvm::cout); - printf("\n"); - } - printf("this = %s\n", this->printString()); - naturalType->print(llvm::cout); - printf("\n"); + } + if (naturalType->isAbstract()) naturalType = naturalType->getForwardedType(); @@ -296,26 +288,18 @@ } void VMClass::resolveVirtualFields() { - VMClass* cl = this; + const llvm::Type* ResultTy = 0; if (hasExplicitLayout(flags)) { explicitLayoutSize = assembly->getExplicitLayout(token); - const llvm::Type* type = llvm::IntegerType::get(explicitLayoutSize); - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(type); - naturalType = type; + ResultTy = llvm::IntegerType::get(explicitLayoutSize); } else if (super != 0) { if (super == MSCorlib::pValue) { uint32 size = virtualFields.size(); if (size == 1) { virtualFields[0]->offset = mvm::jit::constantZero; - if (naturalType->isAbstract()) { - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(virtualFields[0]->signature->naturalType); - naturalType = virtualFields[0]->signature->naturalType; - } + ResultTy = virtualFields[0]->signature->naturalType; } else if (size == 0) { - if (naturalType->isAbstract()) { - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(llvm::Type::VoidTy); - naturalType = llvm::Type::VoidTy; - } + ResultTy = Type::VoidTy; } else { std::vector Elts; uint32 offset = -1; @@ -325,13 +309,10 @@ const llvm::Type* type = (*i)->signature->naturalType; Elts.push_back(type); } - const llvm::Type* tmp = llvm::StructType::get(Elts); - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(tmp); - naturalType = tmp; + ResultTy = llvm::StructType::get(Elts); } } else if (super == MSCorlib::pEnum) { - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(llvm::Type::Int32Ty); // TODO find max - naturalType = llvm::Type::Int32Ty; + ResultTy = Type::Int32Ty; // TODO find max } else { std::vector Elts; Elts.push_back(super->naturalType->getContainedType(0)); @@ -342,19 +323,23 @@ const llvm::Type* type = (*i)->signature->naturalType; Elts.push_back(type); } - const llvm::Type* tmp = llvm::PointerType::getUnqual(llvm::StructType::get(Elts)); - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(tmp); - naturalType = tmp; + ResultTy = llvm::PointerType::getUnqual(llvm::StructType::get(Elts)); } } else { - if (naturalType->isAbstract()) { // interfaces - ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(VMObject::llvmType); - naturalType = VMObject::llvmType; + ResultTy = VMObject::llvmType; + } + + + if (naturalType->isAbstract()) { + const OpaqueType *OldTy = dyn_cast_or_null(this->naturalType); + if (OldTy) { + const_cast(OldTy)->refineAbstractTypeTo(ResultTy); } + naturalType = ResultTy; } - - unifyTypes(); + unifyTypes(); + if (super == MSCorlib::pValue) { std::vector Elts; Elts.push_back(VMObject::llvmType->getContainedType(0)); @@ -370,14 +355,14 @@ if (super != MSCorlib::pEnum) { VirtualTable* VT = CLIJit::makeVT(this, false); - uint64 size = mvm::jit::getTypeSize(cl->virtualType->getContainedType(0)); - cl->virtualInstance = (VMObject*)gc::operator new(size, VT); - cl->virtualInstance->initialise(cl); + uint64 size = mvm::jit::getTypeSize(this->virtualType->getContainedType(0)); + virtualInstance = (VMObject*)gc::operator new(size, VT); + virtualInstance->initialise(this); - for (std::vector::iterator i = cl->virtualFields.begin(), - e = cl->virtualFields.end(); i!= e; ++i) { + for (std::vector::iterator i = virtualFields.begin(), + e = virtualFields.end(); i!= e; ++i) { - (*i)->initField(cl->virtualInstance); + (*i)->initField(virtualInstance); } } From nicolas.geoffray at lip6.fr Wed Jul 2 07:40:58 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 02 Jul 2008 14:40:58 -0000 Subject: [vmkit-commits] [vmkit] r53021 - in /vmkit/trunk/lib/N3/VMCore: VMClass.cpp VMClass.h Message-ID: <200807021441.m62Ef90H013331@zion.cs.uiuc.edu> Author: geoffray Date: Wed Jul 2 09:40:42 2008 New Revision: 53021 URL: http://llvm.org/viewvc/llvm-project?rev=53021&view=rev Log: When resolving types, do not also resolve the VT. It will be allocated after the whole resolution process with type unification. Also, do type unification with PATypeHolders. Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp vmkit/trunk/lib/N3/VMCore/VMClass.h Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=53021&r1=53020&r2=53021&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Wed Jul 2 09:40:42 2008 @@ -200,7 +200,7 @@ int status = cl->status; if (status == ready) { cl->release(); - } else if (status == unified) { + } else if (status == static_resolved) { cl->status = clinitParent; cl->release(); if (cl->super) { @@ -230,7 +230,7 @@ cl->status = ready; cl->broadcastClass(); - } else if (status < unified) { + } else if (status < static_resolved) { cl->release(); VMThread::get()->vm->unknownError("try to clinit a not-readed class..."); } else { @@ -276,15 +276,12 @@ } void VMClass::unifyTypes() { + PATypeHolder PA = naturalType; for (std::vector::iterator i = virtualFields.begin(), e = virtualFields.end(); i!= e; ++i) { - (*i)->signature->resolveType(false, false); + (*i)->signature->resolveVirtual(); } - - if (naturalType->isAbstract()) - naturalType = naturalType->getForwardedType(); - - assert(naturalType); + naturalType = PA.get(); } void VMClass::resolveVirtualFields() { @@ -339,7 +336,7 @@ } unifyTypes(); - + if (super == MSCorlib::pValue) { std::vector Elts; Elts.push_back(VMObject::llvmType->getContainedType(0)); @@ -352,19 +349,6 @@ virtualType = naturalType; } - if (super != MSCorlib::pEnum) { - VirtualTable* VT = CLIJit::makeVT(this, false); - - uint64 size = mvm::jit::getTypeSize(this->virtualType->getContainedType(0)); - virtualInstance = (VMObject*)gc::operator new(size, VT); - virtualInstance->initialise(this); - - for (std::vector::iterator i = virtualFields.begin(), - e = virtualFields.end(); i!= e; ++i) { - - (*i)->initField(virtualInstance); - } - } } @@ -378,7 +362,6 @@ ((llvm::OpaqueType*)naturalType)->refineAbstractTypeTo(type); naturalType = type; virtualType = naturalType; - arrayVT = CLIJit::makeArrayVT(this); } void VMClassPointer::makeType() { @@ -388,13 +371,13 @@ naturalType = pType; } -void VMCommonClass::resolveType(bool stat, bool clinit) { +void VMCommonClass::resolveVirtual() { VMCommonClass* cl = this; //printf("*** Resolving: %s\n", cl->printString()); - if (cl->status < resolved) { + if (cl->status < virtual_resolved) { cl->aquire(); int status = cl->status; - if (status >= resolved) { + if (status >= virtual_resolved) { cl->release(); } else if (status < loaded) { cl->release(); @@ -405,13 +388,13 @@ VMCommonClass* baseClass = arrayCl->baseClass; baseClass->resolveType(false, false); arrayCl->makeType(); - cl->status = resolved; + cl->status = virtual_resolved; } else if (cl->isPointer) { VMClassPointer* pointerCl = (VMClassPointer*)cl; VMCommonClass* baseClass = pointerCl->baseClass; baseClass->resolveType(false, false); pointerCl->makeType(); - cl->status = resolved; + cl->status = virtual_resolved; } else { cl->release(); cl->loadParents(); @@ -420,50 +403,105 @@ assembly->readClass(cl); cl->status = readed; ((VMClass*)cl)->resolveVirtualFields(); - cl->status = resolved; + cl->status = virtual_resolved; + } + cl->release(); + } else { + if (!(cl->ownerClass())) { + while (status < virtual_resolved) { + cl->waitClass(); + } + } + cl->release(); + } + } +} + +void VMCommonClass::resolveVT() { + VMCommonClass* cl = this; + //printf("*** Resolving: %s\n", cl->printString()); + if (cl->status < vt_resolved) { + cl->aquire(); + int status = cl->status; + if (status >= vt_resolved) { + cl->release(); + } else if (status < loaded) { + cl->release(); + VMThread::get()->vm->unknownError("try to vt-resolve a not-resolved class"); + } else if (status == virtual_resolved) { + if (cl->isArray) { + VMClassArray* arrayCl = (VMClassArray*)cl; + arrayCl->baseClass->resolveVT(); + arrayCl->arrayVT = CLIJit::makeArrayVT(arrayCl); + cl->status = vt_resolved; + } else if (cl->isPointer) { + cl->status = vt_resolved; + } else { + VMClass* cl = (VMClass*)this; + if (super) super->resolveVT(); + + if (super != MSCorlib::pEnum) { + VirtualTable* VT = CLIJit::makeVT(cl, false); + + uint64 size = mvm::jit::getTypeSize(cl->virtualType->getContainedType(0)); + cl->virtualInstance = (VMObject*)gc::operator new(size, VT); + cl->virtualInstance->initialise(cl); + + for (std::vector::iterator i = cl->virtualFields.begin(), + e = cl->virtualFields.end(); i!= e; ++i) { + + (*i)->initField(cl->virtualInstance); + } + } + cl->status = vt_resolved; } cl->release(); } else { if (!(cl->ownerClass())) { - while (status < resolved) { + while (status < vt_resolved) { cl->waitClass(); } } cl->release(); } } - if (stat) cl->resolveStatic(clinit); +} + +void VMCommonClass::resolveType(bool stat, bool clinit) { + resolveVirtual(); + resolveVT(); + if (stat) resolveStatic(clinit); } void VMCommonClass::resolveStatic(bool clinit) { VMCommonClass* cl = this; - if (cl->status < unified) { + if (cl->status < static_resolved) { cl->aquire(); int status = cl->status; - if (status >= unified) { + if (status >= static_resolved) { cl->release(); - } else if (status < resolved) { + } else if (status < vt_resolved) { cl->release(); VMThread::get()->vm->unknownError("try to resolve static of a not virtual-resolved class"); - } else if (status == resolved) { + } else if (status == vt_resolved) { if (cl->isArray) { VMClassArray* arrayCl = (VMClassArray*)cl; VMCommonClass* baseClass = arrayCl->baseClass; baseClass->resolveStatic(false); - cl->status = unified; + cl->status = static_resolved; } else if (cl->isPointer) { VMClassPointer* pointerCl = (VMClassPointer*)cl; VMCommonClass* baseClass = pointerCl->baseClass; baseClass->resolveStatic(false); - cl->status = unified; + cl->status = static_resolved; } else { ((VMClass*)cl)->resolveStaticFields(); - cl->status = unified; + cl->status = static_resolved; } cl->release(); } else { if (!(cl->ownerClass())) { - while (status < unified) { + while (status < static_resolved) { cl->waitClass(); } } @@ -577,6 +615,7 @@ } VMObject* VMClass::doNew() { + if (status < inClinit) resolveType(true, true); uint64 size = mvm::jit::getTypeSize(virtualType->getContainedType(0)); VMObject* res = (VMObject*) gc::operator new(size, virtualInstance->getVirtualTable()); @@ -585,6 +624,7 @@ } VMObject* VMClassArray::doNew(uint32 nb) { + if (status < inClinit) resolveType(true, true); uint64 size = mvm::jit::getTypeSize(baseClass->naturalType); VMArray* res = (VMArray*) gc::operator new(size * nb + sizeof(VMObject) + sizeof(sint32), arrayVT); Modified: vmkit/trunk/lib/N3/VMCore/VMClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.h?rev=53021&r1=53020&r2=53021&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.h Wed Jul 2 09:40:42 2008 @@ -37,7 +37,7 @@ class VMObject; typedef enum VMClassState { - hashed = 0, loaded, prepared, readed, resolved, unified, clinitParent, inClinit, ready + hashed = 0, loaded, prepared, readed, virtual_resolved, vt_resolved, static_resolved, clinitParent, inClinit, ready }VMClassState; @@ -100,6 +100,8 @@ void assignType(); void clinitClass(); void resolveStatic(bool clinit); + void resolveVirtual(); + void resolveVT(); void resolveType(bool stat, bool clinit); void loadParents(); From nicolas.geoffray at lip6.fr Wed Jul 2 09:09:57 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 02 Jul 2008 16:09:57 -0000 Subject: [vmkit-commits] [vmkit] r53025 - in /vmkit/trunk: ./ autoconf/ lib/ lib/N3/ lib/N3/Mono/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/ tools/n3-mono/ tools/n3-pnetlib/ tools/n3/ Message-ID: <200807021610.m62GA0UO016292@zion.cs.uiuc.edu> Author: geoffray Date: Wed Jul 2 11:09:46 2008 New Revision: 53025 URL: http://llvm.org/viewvc/llvm-project?rev=53025&view=rev Log: Make room for Mono support (currently unsupported). No need to set the environment variable MSCORLIB anymore, the path to the mscorlib.dll file is given to configure. n3 is now either n3-mono or n3-pnetlib. n3-pnetlib is the previous n3. Added: vmkit/trunk/lib/N3/Mono/ vmkit/trunk/lib/N3/Mono/Makefile vmkit/trunk/lib/N3/Mono/Mono.cpp vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp vmkit/trunk/lib/N3/Mono/MonoPath.cpp.in vmkit/trunk/lib/N3/Mono/MonoString.cpp vmkit/trunk/lib/N3/Mono/MonoString.h vmkit/trunk/lib/N3/PNetLib/PNetPath.cpp.in vmkit/trunk/tools/n3-mono/ vmkit/trunk/tools/n3-mono/Makefile (with props) vmkit/trunk/tools/n3-pnetlib/ vmkit/trunk/tools/n3-pnetlib/Makefile (with props) Removed: vmkit/trunk/tools/n3/ Modified: vmkit/trunk/Makefile.config.in vmkit/trunk/autoconf/configure.ac vmkit/trunk/configure vmkit/trunk/lib/Makefile vmkit/trunk/lib/N3/Makefile vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp vmkit/trunk/lib/N3/VMCore/CLISignature.cpp vmkit/trunk/lib/N3/VMCore/MSCorlib.h vmkit/trunk/lib/N3/VMCore/N3.cpp vmkit/trunk/lib/N3/VMCore/N3.h vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp vmkit/trunk/tools/Makefile Modified: vmkit/trunk/Makefile.config.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.config.in?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/Makefile.config.in (original) +++ vmkit/trunk/Makefile.config.in Wed Jul 2 11:09:46 2008 @@ -1,4 +1,5 @@ GCLIB = @GC_LIBS@ -WITH_N3 = @WITH_N3@ +WITH_N3_PNETLIB = @WITH_N3_PNETLIB@ +WITH_N3_MONO = @WITH_N3_MONO@ 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=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/autoconf/configure.ac (original) +++ vmkit/trunk/autoconf/configure.ac Wed Jul 2 11:09:46 2008 @@ -262,7 +262,7 @@ ) if test "x${classpathlibs}" != "x/usr/lib/classpath"; then - classpathinclude=${classpathlibs}/../include:/usr/include/classpath; + classpathinclude=${classpathlibs}/../include; else classpathinclude=/usr/include/classpath; fi @@ -291,18 +291,43 @@ ]] ) +AC_ARG_WITH(pnetlib, + [AS_HELP_STRING(--with-pnetlib=something, + [Pnetlib's mscorlib.dll location (default is /usr/lib/cscc/lib/)])], + [[pnetlibpath=$withval]], + [[pnetlibpath=/usr/lib/cscc/lib/]] +) + if test "x$pnetlocalprefix" != x; then echo Using ${pnetlocalprefix} as PNET local prefix; - WITH_N3=1; + WITH_N3_PNETLIB=1; else - WITH_N3=0; + WITH_N3_PNETLIB=0; fi AC_SUBST([pnetlocalprefix]) -AC_SUBST([WITH_N3]) +AC_SUBST([WITH_N3_PNETLIB]) N3_LIB=PNetLib AC_SUBST([N3_LIB]) +AC_SUBST([pnetlibpath]) + +AC_ARG_WITH(mono, + [AS_HELP_STRING(--with-mono=something, + [Mono's mscorlib.dll location (no default)])], + [[monopath=$withval]], + [[echo Not using Mono]] +) + +if test "x$monopath" != x; then + echo Building N3 with Mono; + WITH_N3_MONO=1; +else + WITH_N3_MONO=0; +fi + +AC_SUBST([WITH_N3_MONO]) +AC_SUBST([monopath]) dnl===-----------------------------------------------------------------------=== dnl=== @@ -481,16 +506,12 @@ AC_CONFIG_FILES(Makefile.common) AC_CONFIG_FILES(Makefile.config) AC_CONFIG_FILES([lib/JnJVM/Classpath/Classpath.h]) +AC_CONFIG_FILES([lib/N3/PNetLib/PNetPath.cpp]) +AC_CONFIG_FILES([lib/N3/Mono/MonoPath.cpp]) dnl Do special configuration of Makefiles AC_CONFIG_MAKEFILE(Makefile) AC_CONFIG_MAKEFILE(lib/Makefile) -dnl ************************************************************************** -dnl LLVM Installation Prefix -dnl ************************************************************************** -dnl LLVMDYLIB="`$llvmprefix/Release/bin/llvm-config --ldflags all` `$llvmprefix/Release/bin/llvm-config --libs all`" -dnl AC_SUBST([LLVMDYLIB]) - AC_OUTPUT Modified: vmkit/trunk/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/configure?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/configure (original) +++ vmkit/trunk/configure Wed Jul 2 11:09:46 2008 @@ -697,8 +697,11 @@ classpathversion WITH_JNJVM pnetlocalprefix -WITH_N3 +WITH_N3_PNETLIB N3_LIB +pnetlibpath +WITH_N3_MONO +monopath CXX CXXFLAGS ac_ct_CXX @@ -1328,6 +1331,10 @@ --with-jnjvm=yes|no Build JnJVM (default is yes) --with-pnet-local-prefix=something PNET local prefix (no default) + --with-pnetlib=something + Pnetlib's mscorlib.dll location (default is + /usr/lib/cscc/lib/) + --with-mono=something Mono's mscorlib.dll location (no default) Some influential environment variables: CC C compiler command @@ -4000,7 +4007,7 @@ if test "x${classpathlibs}" != "x/usr/lib/classpath"; then - classpathinclude=${classpathlibs}/../include:/usr/include/classpath; + classpathinclude=${classpathlibs}/../include; else classpathinclude=/usr/include/classpath; fi @@ -4029,11 +4036,21 @@ fi + +# Check whether --with-pnetlib was given. +if test "${with_pnetlib+set}" = set; then + withval=$with_pnetlib; pnetlibpath=$withval +else + pnetlibpath=/usr/lib/cscc/lib/ + +fi + + if test "x$pnetlocalprefix" != x; then echo Using ${pnetlocalprefix} as PNET local prefix; - WITH_N3=1; + WITH_N3_PNETLIB=1; else - WITH_N3=0; + WITH_N3_PNETLIB=0; fi @@ -4043,6 +4060,27 @@ + +# Check whether --with-mono was given. +if test "${with_mono+set}" = set; then + withval=$with_mono; monopath=$withval +else + echo Not using Mono + +fi + + +if test "x$monopath" != x; then + echo Building N3 with Mono; + WITH_N3_MONO=1; +else + WITH_N3_MONO=0; +fi + + + + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -7103,6 +7141,10 @@ ac_config_files="$ac_config_files lib/JnJVM/Classpath/Classpath.h" +ac_config_files="$ac_config_files lib/N3/PNetLib/PNetPath.cpp" + +ac_config_files="$ac_config_files lib/N3/Mono/MonoPath.cpp" + ac_config_commands="$ac_config_commands Makefile" @@ -7112,7 +7154,6 @@ - cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -7694,6 +7735,8 @@ "Makefile.common") CONFIG_FILES="$CONFIG_FILES Makefile.common" ;; "Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;; "lib/JnJVM/Classpath/Classpath.h") CONFIG_FILES="$CONFIG_FILES lib/JnJVM/Classpath/Classpath.h" ;; + "lib/N3/PNetLib/PNetPath.cpp") CONFIG_FILES="$CONFIG_FILES lib/N3/PNetLib/PNetPath.cpp" ;; + "lib/N3/Mono/MonoPath.cpp") CONFIG_FILES="$CONFIG_FILES lib/N3/Mono/MonoPath.cpp" ;; "Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile" ;; "lib/Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS lib/Makefile" ;; @@ -7837,8 +7880,11 @@ classpathversion!$classpathversion$ac_delim WITH_JNJVM!$WITH_JNJVM$ac_delim pnetlocalprefix!$pnetlocalprefix$ac_delim -WITH_N3!$WITH_N3$ac_delim +WITH_N3_PNETLIB!$WITH_N3_PNETLIB$ac_delim N3_LIB!$N3_LIB$ac_delim +pnetlibpath!$pnetlibpath$ac_delim +WITH_N3_MONO!$WITH_N3_MONO$ac_delim +monopath!$monopath$ac_delim CXX!$CXX$ac_delim CXXFLAGS!$CXXFLAGS$ac_delim ac_ct_CXX!$ac_ct_CXX$ac_delim @@ -7852,9 +7898,6 @@ MV!$MV$ac_delim RANLIB!$RANLIB$ac_delim RM!$RM$ac_delim -SED!$SED$ac_delim -TAR!$TAR$ac_delim -BINPWD!$BINPWD$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -7896,6 +7939,9 @@ ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +SED!$SED$ac_delim +TAR!$TAR$ac_delim +BINPWD!$BINPWD$ac_delim CAT!$CAT$ac_delim LLVMAS!$LLVMAS$ac_delim LLC!$LLC$ac_delim @@ -7908,7 +7954,7 @@ LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 10; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 13; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 Modified: vmkit/trunk/lib/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Makefile?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/Makefile (original) +++ vmkit/trunk/lib/Makefile Wed Jul 2 11:09:46 2008 @@ -16,9 +16,7 @@ PARALLEL_DIRS += JnJVM endif -ifeq ($(WITH_N3), 1) PARALLEL_DIRS += N3 -endif LIBRARYNAME = Main Modified: vmkit/trunk/lib/N3/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Makefile?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Makefile (original) +++ vmkit/trunk/lib/N3/Makefile Wed Jul 2 11:09:46 2008 @@ -10,6 +10,15 @@ include $(LEVEL)/Makefile.config -DIRS = VMCore $(N3_LIB) +DIRS = VMCore + +ifeq ($(WITH_N3_MONO), 1) + DIRS += Mono +endif + +ifeq ($(WITH_N3_PNETLIB), 1) + DIRS += PNetLib +endif + include $(LEVEL)/Makefile.common Added: vmkit/trunk/lib/N3/Mono/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Makefile?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/Makefile (added) +++ vmkit/trunk/lib/N3/Mono/Makefile Wed Jul 2 11:09:46 2008 @@ -0,0 +1,13 @@ +##===- lib/N3/Mono/Makefile --------------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../.. + +LIBRARYNAME = Mono +include $(LEVEL)/Makefile.common +CXX.Flags += -I../VMCore Added: vmkit/trunk/lib/N3/Mono/Mono.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Mono.cpp?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/Mono.cpp (added) +++ vmkit/trunk/lib/N3/Mono/Mono.cpp Wed Jul 2 11:09:46 2008 @@ -0,0 +1,59 @@ +//===-------------- Mono.cpp - The Mono interface -------------------------===// +// +// 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 "Reader.h" +#include "VMArray.h" +#include "VMClass.h" +#include "VMObject.h" +#include "VMThread.h" + +using namespace n3; + +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(); +} Added: vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp (added) +++ vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp Wed Jul 2 11:09:46 2008 @@ -0,0 +1,166 @@ +//===----- MonoMSCorlib.cpp - The Mono 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" +#include "VMThread.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) { + + VMClass* runtimeTypeHandle = 0; + VMClass* realClrType = 0; + #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", "MonoType", 0, false); + INIT(realClrType, "System", "Type", 0, false); + INIT(runtimeTypeHandle, "System", "RuntimeTypeHandle", 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); + MSCorlib::typeClrType = realClrType->lookupField(vm->asciizConstructUTF8("_impl"), runtimeTypeHandle, false, false); + } + +/* + { + MSCorlib::assemblyReflection->resolveType(false, false); + std::vector 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 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 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 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 + + */ +} +#include "NativeUtil.h" +void NativeUtil::initialise() { +} + +VMObject* Property::getPropertyDelegatee() { + if (!delegatee) { + VMThread::get()->vm->error("implement me"); + } + return delegatee; +} + +VMObject* VMMethod::getMethodDelegatee() { + if (!delegatee) { + VMThread::get()->vm->error("implement me"); + } + return delegatee; +} + +VMObject* VMCommonClass::getClassDelegatee() { + if (!delegatee) { + delegatee = (*MSCorlib::clrType)(); + (*MSCorlib::typeClrType)(delegatee, (VMObject*)this); + } + return delegatee; +} + +VMObject* Assembly::getAssemblyDelegatee() { + if (!delegatee) { + VMThread::get()->vm->error("implement me"); + } + return delegatee; +} + +void MSCorlib::loadBootstrap(N3* vm) { +} Added: vmkit/trunk/lib/N3/Mono/MonoPath.cpp.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoPath.cpp.in?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoPath.cpp.in (added) +++ vmkit/trunk/lib/N3/Mono/MonoPath.cpp.in Wed Jul 2 11:09:46 2008 @@ -0,0 +1,15 @@ +//===------ MonoPath.cpp - mscorlib.dll location for mono -----------------===// +// +// N3 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "MSCorlib.h" + +using namespace n3; + +const char* MSCorlib::libsPath = "@monopath@/"; + Added: vmkit/trunk/lib/N3/Mono/MonoString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoString.cpp?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoString.cpp (added) +++ vmkit/trunk/lib/N3/Mono/MonoString.cpp Wed Jul 2 11:09:46 2008 @@ -0,0 +1,62 @@ +//===--- 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 "llvm/GlobalVariable.h" + +#include "mvm/JIT.h" + +#include "CLIString.h" +#include "MSCorlib.h" +#include "N3.h" +#include "MonoString.h" +#include "VMArray.h" +#include "VMClass.h" +#include "VMThread.h" + +using namespace n3; +using namespace llvm; + + +CLIString* CLIString::stringDup(const UTF8*& utf8, N3* vm) { + MonoString* obj = (MonoString*)(*MSCorlib::pString)(); + obj->length = utf8->size; + if (utf8->size == 0) { + obj->startChar = 0; + } else { + obj->startChar = utf8->at(0); + } + obj->value = utf8; + return obj; +} + +char* CLIString::strToAsciiz() { + return ((MonoString*)this)->value->UTF8ToAsciiz(); +} + +const UTF8* CLIString::strToUTF8(N3* vm) { + return ((MonoString*)this)->value; +} + +GlobalVariable* CLIString::llvmVar() { + MonoString* str = (MonoString*)this; + if (!str->_llvmVar) { + VirtualMachine* vm = VMThread::get()->vm; + if (!str->_llvmVar) { + const Type* pty = mvm::jit::ptrType; + Constant* cons = + ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t (this)), + pty); + str->_llvmVar = new GlobalVariable(pty, true, + GlobalValue::ExternalLinkage, + cons, "", + vm->module); + } + } + return str->_llvmVar; +} Added: vmkit/trunk/lib/N3/Mono/MonoString.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoString.h?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoString.h (added) +++ vmkit/trunk/lib/N3/Mono/MonoString.h Wed Jul 2 11:09:46 2008 @@ -0,0 +1,37 @@ +//===---------- MonoString.h - String representation in Mono --------------===// +// +// N3 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef N3_MONO_STRING_H +#define N3_MONO_STRING_H + +#include "llvm/GlobalVariable.h" + +#include "types.h" +#include "mvm/PrintBuffer.h" + +#include "CLIString.h" + +namespace n3 { + +class UTF8; + +class MonoString : public CLIString { +public: + + // !!! mono layout !!! + sint32 length; + uint8 startChar; + const UTF8* value; + llvm::GlobalVariable* _llvmVar; + +}; + +} // end namespace n3 + +#endif Modified: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp Wed Jul 2 11:09:46 2008 @@ -15,6 +15,7 @@ #include "N3.h" #include "VMClass.h" #include "VMObject.h" +#include "VMThread.h" using namespace n3; @@ -162,3 +163,24 @@ } return delegatee; } + +static void mapInitialThread(N3* vm) { + VMClass* cl = (VMClass*)vm->coreAssembly->loadTypeFromName( + vm->asciizConstructUTF8("Thread"), + vm->asciizConstructUTF8("System.Threading"), + true, true, true, true); + VMObject* th = (*cl)(); + std::vector args; + args.push_back(MSCorlib::pVoid); + args.push_back(cl); + args.push_back(MSCorlib::pIntPtr); + VMMethod* meth = cl->lookupMethod(vm->asciizConstructUTF8(".ctor"), args, + false, false); + VMThread* myth = VMThread::get(); + (*meth)(th, myth); + myth->vmThread = th; +} + +void MSCorlib::loadBootstrap(N3* vm) { + mapInitialThread(vm); +} Added: vmkit/trunk/lib/N3/PNetLib/PNetPath.cpp.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetPath.cpp.in?rev=53025&view=auto ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetPath.cpp.in (added) +++ vmkit/trunk/lib/N3/PNetLib/PNetPath.cpp.in Wed Jul 2 11:09:46 2008 @@ -0,0 +1,15 @@ +//===---------- PNetPath.h - Configuration for pnetlib --------------------===// +// +// N3 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "MSCorlib.h" + +using namespace n3; + +const char* MSCorlib::libsPath = "@pnetlibpath@/"; + Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Wed Jul 2 11:09:46 2008 @@ -19,6 +19,9 @@ using namespace n3; +// ECMA 335: page 150 23.1.16 Element types used in signatures + + static VMCommonClass* METHOD_ElementTypeEnd(uint32 op, Assembly* ass, uint32& offset) { VMThread::get()->vm->error("implement me"); return 0; Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.h?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/MSCorlib.h (original) +++ vmkit/trunk/lib/N3/VMCore/MSCorlib.h Wed Jul 2 11:09:46 2008 @@ -22,6 +22,9 @@ public: static void initialise(N3* vm); static void loadStringClass(N3* vm); + static void loadBootstrap(N3* vm); + + static const char* libsPath; static VMMethod* ctorClrType; static VMClass* clrType; Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3.cpp Wed Jul 2 11:09:46 2008 @@ -198,27 +198,6 @@ } -void N3::mapInitialThread() { - VMClass* cl = (VMClass*)coreAssembly->loadTypeFromName( - asciizConstructUTF8("Thread"), - asciizConstructUTF8("System.Threading"), - true, true, true, true); - VMObject* th = (*cl)(); - std::vector args; - args.push_back(MSCorlib::pVoid); - args.push_back(cl); - args.push_back(MSCorlib::pIntPtr); - VMMethod* meth = cl->lookupMethod(asciizConstructUTF8(".ctor"), args, - false, false); - VMThread* myth = VMThread::get(); - (*meth)(th, myth); - myth->vmThread = th; -} - -void N3::loadBootstrap() { - mapInitialThread(); -} - void N3::waitForExit() { threadSystem->nonDaemonLock->lock(); --(threadSystem->nonDaemonThreads); @@ -277,7 +256,7 @@ argv = argv + info.appArgumentsPos - 1; argc = argc - info.appArgumentsPos + 1; - loadBootstrap(); + MSCorlib::loadBootstrap(this); ArrayObject* args = ArrayObject::acons(argc - 2, MSCorlib::arrayString); for (int i = 2; i < argc; ++i) { Modified: vmkit/trunk/lib/N3/VMCore/N3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.h?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.h (original) +++ vmkit/trunk/lib/N3/VMCore/N3.h Wed Jul 2 11:09:46 2008 @@ -58,8 +58,6 @@ Assembly* loadAssembly(const UTF8* name, const char* extension); void executeAssembly(const char* name, ArrayObject* args); void runMain(int argc, char** argv); - void mapInitialThread(); - void loadBootstrap(); void waitForExit(); static N3* bootstrapVM; Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Wed Jul 2 11:09:46 2008 @@ -228,12 +228,8 @@ - char* assemblyName = getenv("MSCORLIB"); - if (assemblyName == 0) - VMThread::get()->vm->error("can not find mscorlib.dll. Abort"); - vm->assemblyPath.push_back(""); - vm->assemblyPath.push_back(assemblyName); + vm->assemblyPath.push_back(MSCorlib::libsPath); const UTF8* mscorlib = vm->asciizConstructUTF8("mscorlib"); Assembly* ass = vm->loadAssembly(mscorlib, "dll"); Modified: vmkit/trunk/tools/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=53025&r1=53024&r2=53025&view=diff ============================================================================== --- vmkit/trunk/tools/Makefile (original) +++ vmkit/trunk/tools/Makefile Wed Jul 2 11:09:46 2008 @@ -16,8 +16,12 @@ PARALLEL_DIRS += jnjvm endif -ifeq ($(WITH_N3), 1) - PARALLEL_DIRS += n3 +ifeq ($(WITH_N3_MONO), 1) + PARALLEL_DIRS += n3-mono +endif + +ifeq ($(WITH_N3_PNETLIB), 1) + PARALLEL_DIRS += n3-pnetlib endif Added: vmkit/trunk/tools/n3-mono/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Makefile?rev=53025&view=auto ============================================================================== --- vmkit/trunk/tools/n3-mono/Makefile (added) +++ vmkit/trunk/tools/n3-mono/Makefile Wed Jul 2 11:09:46 2008 @@ -0,0 +1,17 @@ +##===- tools/n3/Mono/Makefile ------------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../.. + +include $(LEVEL)/Makefile.config + +TOOLNAME = n3-mono +LINK_COMPONENTS = engine scalaropts instrumentation ipa ipo +USEDLIBS = Allocator CommonThread Mvm N3 Main $(GCLIB) Mono + +include $(LEVEL)/Makefile.common Propchange: vmkit/trunk/tools/n3-mono/Makefile ------------------------------------------------------------------------------ svn:executable = * Added: vmkit/trunk/tools/n3-pnetlib/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-pnetlib/Makefile?rev=53025&view=auto ============================================================================== --- vmkit/trunk/tools/n3-pnetlib/Makefile (added) +++ vmkit/trunk/tools/n3-pnetlib/Makefile Wed Jul 2 11:09:46 2008 @@ -0,0 +1,22 @@ +##===- tools/n3/Makefile -----------------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../.. + +include $(LEVEL)/Makefile.config + +TOOLNAME = n3-pnetlib +LINK_COMPONENTS = engine scalaropts instrumentation ipa ipo +USEDLIBS = Allocator CommonThread Mvm N3 Main $(GCLIB) PNetLib + +include $(LEVEL)/Makefile.common + + +LIBS += $(PNETLIB)/engine/libILEngine.a $(PNETLIB)/image/libILImage.a $(PNETLIB)/support/libILSupport.a \ + $(PNETLIB)/libffi/.libs/libffi.a $(PNETLIB)//dumpasm/libILDumpAsm.a + Propchange: vmkit/trunk/tools/n3-pnetlib/Makefile ------------------------------------------------------------------------------ svn:executable = * From nicolas.geoffray at lip6.fr Wed Jul 2 09:15:36 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 02 Jul 2008 16:15:36 -0000 Subject: [vmkit-commits] [vmkit] r53026 - /vmkit/trunk/www/get_started.html Message-ID: <200807021615.m62GFb11016483@zion.cs.uiuc.edu> Author: geoffray Date: Wed Jul 2 11:15:32 2008 New Revision: 53026 URL: http://llvm.org/viewvc/llvm-project?rev=53026&view=rev Log: New configure options, and replace n3 by n3-pnetlib. Modified: vmkit/trunk/www/get_started.html Modified: vmkit/trunk/www/get_started.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/get_started.html?rev=53026&r1=53025&r2=53026&view=diff ============================================================================== --- vmkit/trunk/www/get_started.html (original) +++ vmkit/trunk/www/get_started.html Wed Jul 2 11:15:32 2008 @@ -122,7 +122,6 @@
  • tar zxvf pnetlib-0.8.0.tar.gz
  • cd pnetlib-0.8.0
  • ./configure; make
  • -
  • export MSCORLIB=$PWD/runtime/mscorlib.dll
  • Checkout vmkit:
  • @@ -144,6 +143,8 @@
    Tell vmkit where GNU Classpath libs are located.

    --with-pnet-local-prefix=<directory>
    Tell vmkit where PNet is located.
    +

    --with-pnetlib=<directory>
    +
    Tell vmkit where pnetlib's mscorlib.dll is located.
    @@ -154,12 +155,12 @@
  • make (this will give you a debug build)
  • -
  • Try it out: (assuming that you are in vmkit/Debug/bin)
  • +
  • Try it out: (assuming vmkit/Debug/bin is in your path)
    • jnjvm --help
    • jnjvm HelloWorld
    • -
    • n3 --help
    • -
    • n3 HelloWorld.exe
    • +
    • n3-pnetlib --help
    • +
    • n3-pnetlib HelloWorld.exe
    From sanxiyn at gmail.com Wed Jul 2 16:52:39 2008 From: sanxiyn at gmail.com (Seo Sanghyeon) Date: Wed, 02 Jul 2008 23:52:39 -0000 Subject: [vmkit-commits] [vmkit] r53059 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp LockedMap.h Message-ID: <200807022352.m62NqduG032182@zion.cs.uiuc.edu> Author: sanxiyn Date: Wed Jul 2 18:52:39 2008 New Revision: 53059 URL: http://llvm.org/viewvc/llvm-project?rev=53059&view=rev Log: GCC 4.3 compilation fixes Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp vmkit/trunk/lib/N3/VMCore/LockedMap.h Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53059&r1=53058&r2=53059&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Wed Jul 2 18:52:39 2008 @@ -718,7 +718,7 @@ const UTF8* Assembly::readString(VirtualMachine* vm, uint32 offset) { uint32 end = offset; uint32 cur = 0; - while ((cur = READ_U1(bytes, end)) != 0); + while ((cur = READ_U1(bytes, end)) != 0) {} return readUTF8(vm, (end - 1 - offset), bytes, offset); } Modified: vmkit/trunk/lib/N3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/LockedMap.h?rev=53059&r1=53058&r2=53059&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/N3/VMCore/LockedMap.h Wed Jul 2 18:52:39 2008 @@ -35,7 +35,6 @@ class VMMethod; class VMField; class UTF8; -class llvm::Function; template class LockedMap : public mvm::Object { From nicolas.geoffray at lip6.fr Thu Jul 3 01:12:31 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 03 Jul 2008 08:12:31 -0000 Subject: [vmkit-commits] [vmkit] r53093 - /vmkit/trunk/www/get_started.html Message-ID: <200807030812.m638CVgv026409@zion.cs.uiuc.edu> Author: geoffray Date: Thu Jul 3 03:12:31 2008 New Revision: 53093 URL: http://llvm.org/viewvc/llvm-project?rev=53093&view=rev Log: vmkit requires building llvm with REQUIRES_EH=1 Modified: vmkit/trunk/www/get_started.html Modified: vmkit/trunk/www/get_started.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/get_started.html?rev=53093&r1=53092&r2=53093&view=diff ============================================================================== --- vmkit/trunk/www/get_started.html (original) +++ vmkit/trunk/www/get_started.html Thu Jul 3 03:12:31 2008 @@ -86,7 +86,7 @@
    • svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
    • cd llvm
    • -
    • ./configure; make
    • +
    • ./configure; make REQUIRES_EH=1
    From nicolas.geoffray at lip6.fr Fri Jul 4 09:22:02 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 04 Jul 2008 16:22:02 -0000 Subject: [vmkit-commits] [vmkit] r53138 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaAccess.h JavaArray.cpp JavaArray.h JavaCache.cpp JavaCache.h JavaJIT.cpp JavaRuntimeJIT.cpp Message-ID: <200807041622.m64GM2ZM008613@zion.cs.uiuc.edu> Author: geoffray Date: Fri Jul 4 11:22:01 2008 New Revision: 53138 URL: http://llvm.org/viewvc/llvm-project?rev=53138&view=rev Log: Simplify & comment. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h Fri Jul 4 11:22:01 2008 @@ -6,6 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// This file defines macros and functions for knowing and checking the access +// type of Java class, fields or methods. +// +//===----------------------------------------------------------------------===// #ifndef JNJVM_JAVA_ACCESS_H #define JNJVM_JAVA_ACCESS_H Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Fri Jul 4 11:22:01 2008 @@ -20,7 +20,10 @@ using namespace jnjvm; +/// This value is the same value than IBM's JVM. const sint32 JavaArray::MaxArraySize = 268435455; + +/// The JVM defines constants for referencing arrays of primitive types. const unsigned int JavaArray::T_BOOLEAN = 4; const unsigned int JavaArray::T_CHAR = 5; const unsigned int JavaArray::T_FLOAT = 6; @@ -73,6 +76,7 @@ } #endif +/// Each array class has its own element size for allocating arrays. ACONS(ArrayUInt8, uint8, 1, JavaArray::VT) ACONS(ArraySInt8, sint8, 1, JavaArray::VT) ACONS(ArrayUInt16, uint16, 2, JavaArray::VT) @@ -82,6 +86,10 @@ ACONS(ArrayLong, sint64, 8, JavaArray::VT) ACONS(ArrayFloat, float, 4, JavaArray::VT) ACONS(ArrayDouble, double, 8, JavaArray::VT) + +/// ArrayObject differs wit arrays of primitive types because its +/// tracer method traces the objects in the array as well as the class of the +/// array. ACONS(ArrayObject, JavaObject*, sizeof(JavaObject*), ArrayObject::VT) #undef ARRAYCLASS @@ -150,6 +158,7 @@ return buf; } +/// Currently, this uses malloc/free. This should use a custom memory pool. void* UTF8::operator new(size_t sz, sint32 size) { return malloc(sz + size * sizeof(uint16)); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Fri Jul 4 11:22:01 2008 @@ -6,6 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// This file defines the internal representation of Java arrays. +// +//===----------------------------------------------------------------------===// #ifndef JNJVM_JAVA_ARRAY_H #define JNJVM_JAVA_ARRAY_H @@ -23,18 +27,38 @@ class JavaObject; class Jnjvm; +/// TJavaArray - Template class to be instantiated by real arrays. All arrays +/// have a constant size and an array of element. When JnJVM allocates an +/// instantiation of this class, it allocates with the actual size of this +/// array. Hence instantiation of TJavaArrays have a layout of +/// {JavaObject, size, [0 * T]}. template class TJavaArray : public JavaObject { public: + /// size - The (constant) size of the array. sint32 size; + + /// elements - Elements of this array. The size here is different than the + /// actual size of the Java array. This is to facilitate Java array accesses + /// in JnJVM code. The size should be set to zero, but this is invalid C99. T elements[1]; }; +/// JavaArray - This class is just a placeholder for constants and for the +/// virtual table of arrays of primitive types (e.g. double, int). class JavaArray : public TJavaArray { public: - static VirtualTable *VT; + /// VT - The virtual table of Java arrays of primitive types (e.g. int, + /// double). + static VirtualTable *VT; + + /// MaxArraySize - The maximum size a Java array can have. Allocating an + /// array with a bigger size than MaxArraySize raises an out of memory + /// error. static const sint32 MaxArraySize; + + /// JVM representation of Java arrays of primitive types. static const unsigned int T_BOOLEAN; static const unsigned int T_CHAR; static const unsigned int T_FLOAT; @@ -44,6 +68,7 @@ static const unsigned int T_INT; static const unsigned int T_LONG; + /// The Java class of Java arrays used in JnJVM. static ClassArray* ofByte; static ClassArray* ofChar; static ClassArray* ofString; @@ -54,11 +79,15 @@ static ClassArray* ofFloat; static ClassArray* ofDouble; static ClassArray* ofObject; - + + /// tracer - The trace method of Java arrays of primitive types. Since their + /// class lives throughout the lifetime of the application, there is no need + /// to trace them. Therefore this trace function does nothing. virtual void TRACER; }; +/// Instantiation of the TJavaArray class for Java arrays of primitive types. #define ARRAYCLASS(name, elmt) \ class name : public TJavaArray { \ public: \ @@ -77,30 +106,63 @@ #undef ARRAYCLASS +/// ArrayObject - Instantiation of the TJavaArray class for arrays of objects. +/// Arrays of objects are different than arrays of primitive types because +/// they have to trace all objects in the array. class ArrayObject : public TJavaArray { public: + /// VT - The virtual table of arrays of objects. static VirtualTable *VT; + + /// acons - Allocates a Java array of objects. The class given as argument is + /// the class of the array, not the class of its elements. static ArrayObject* acons(sint32 n, ClassArray* cl, Jnjvm* vm); + + /// tracer - The tracer method of Java arrays of objects. This method will + /// trace all objects in the array. virtual void TRACER; }; + +/// UTF8 - The UTF8 class is basically the ArrayUInt16 class (arrays of elements +/// of type uint16) with helper functions for manipulating UTF8. Each JVM +/// instance hashes UTF8. UTF8 are not allocated by the application's garbage +/// collector, but resides in permanent memory (e.g malloc). class UTF8 : public ArrayUInt16 { public: + /// acons - Allocates an UTF8 in permanent memory. The class argument must be + /// JavaArray::ofChar. static const UTF8* acons(sint32 n, ClassArray* cl, Jnjvm* vm); + /// internalToJava - Creates a copy of the UTF8 at its given offset and size + /// woth all its '.' replaced by '/'. The JVM bytecode reference classes in + /// packages with the '.' as the separating character. The JVM language uses + /// the '/' character. const UTF8* internalToJava(Jnjvm *vm, unsigned int start, unsigned int len) const; + /// javaToInternal - Replaces all '/' into '.'. const UTF8* javaToInternal(Jnjvm *vm, unsigned int start, unsigned int len) const; - + + /// UTF8ToAsciiz - Allocates a C string with the contents of this UTF8. char* UTF8ToAsciiz() const; + + /// asciizConstruct - Constructs an UTF8 with the given C string. static const UTF8* asciizConstruct(Jnjvm *vm, char* asciiz); + + /// readerConstruct - Constructs an UTF8 with the given buffer and size. + /// This function is called when parsing JVM bytecode. static const UTF8* readerConstruct(Jnjvm *vm, uint16* buf, uint32 n); + /// extract - Creates an UTF8 by extracting the contents at the given size + /// of this. const UTF8* extract(Jnjvm *vm, uint32 start, uint32 len) const; + /// equals - Returns whether two UTF8s are equals. When the JnJVM executes + /// in single mode, equality is just a pointer comparison. When executing + /// in multiple mode, we compare the contents f the UTF8s. #ifndef MULTIPLE_VM bool equals(const UTF8* other) const { return this == other; @@ -112,8 +174,15 @@ } #endif + /// print - Prints the UTF8 for debugging purposes. virtual void print(mvm::PrintBuffer* buf) const; + + /// operator new - Redefines the new operator of this class to allocate + /// its objects in permanent memory, not with the garbage collector. void* operator new(size_t sz, sint32 size); + + /// operator delete - Redefines the delete operator to remove the object + /// from permanent memory. void operator delete(void* obj); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp Fri Jul 4 11:22:01 2008 @@ -37,20 +37,17 @@ } } -void CacheNode::initialise() { - this->lastCible = 0; - this->methPtr = 0; - this->next = 0; +CacheNode::CacheNode(Enveloppe* E) { + lastCible = 0; + methPtr = 0; + next = 0; + enveloppe = E; } -Enveloppe* Enveloppe::allocate(JavaCtpInfo* ctp, uint32 index) { - Enveloppe* enveloppe = new Enveloppe(); - enveloppe->firstCache = new CacheNode(); - enveloppe->firstCache->initialise(); - enveloppe->firstCache->enveloppe = enveloppe; - enveloppe->cacheLock = mvm::Lock::allocNormal(); - enveloppe->ctpInfo = ctp; - enveloppe->index = index; - return enveloppe; + Enveloppe::Enveloppe(JavaCtpInfo* ctp, uint32 i) { + firstCache = new CacheNode(this); + cacheLock = mvm::Lock::allocNormal(); + ctpInfo = ctp; + index = i; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h Fri Jul 4 11:22:01 2008 @@ -6,6 +6,17 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// Caches in JnJVM are used when invoking interface methods in the JVM +// bytecode. A cache is a linked-list of {class, method pointer} pairs that +// were already encountered during the execution of the program. Its efficiency +// is based on the hypothesis that for one invokeinterface location, the "this" +// arguments will share most of the times the same class. +// +// At a given time, the first entry in the linked list is the last class of the +// "this" parameter. +// +//===----------------------------------------------------------------------===// #ifndef JNJVM_JAVA_CACHE_H #define JNJVM_JAVA_CACHE_H @@ -22,28 +33,53 @@ class Enveloppe; class JavaCtpInfo; +/// CacheNode - A {class, method pointer} pair. class CacheNode { public: + /// methPtr - The method pointer of this cache. void* methPtr; + + /// lastCible - The class of this cache. Class* lastCible; + + /// next - The next cache. CacheNode* next; + + /// enveloppe - The container to which this class belongs to. Enveloppe* enveloppe; - void initialise(); - + /// CacheNode - Creates a CacheNode with empty values. + CacheNode(Enveloppe* E); }; +/// Enveloppe - A reference to the linked list of CacheNode. class Enveloppe { public: + /// ~Enveloppe - Deletes all CacheNode in the linked list. ~Enveloppe(); + + /// firstCache - The first entry in the linked list, hence the last + /// class occurence for a given invokeinterface call. CacheNode *firstCache; + + /// ctpInfo - The constant pool info that owns the invokeinterface + /// bytecode. This is used to resolve the interface call at its first + /// occurence. JavaCtpInfo* ctpInfo; + + /// cacheLock - The linked list may be modified by concurrent thread. This + /// lock ensures that the list stays consistent. mvm::Lock* cacheLock; + + /// index - The index in the constant pool of the interface method. uint32 index; - static Enveloppe* allocate(JavaCtpInfo* info, uint32 index); + /// Enveloppe - Allocates the linked list with the given constant pool info + /// at the given index, so as the resolution process knows which interface + /// method the invokeinterface bytecode references. + Enveloppe(JavaCtpInfo* info, uint32 index); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Fri Jul 4 11:22:01 2008 @@ -1979,7 +1979,7 @@ } // ok now the cache - Enveloppe* enveloppe = Enveloppe::allocate(compilingClass->ctpInfo, index); + Enveloppe* enveloppe = new Enveloppe(compilingClass->ctpInfo, index); compilingMethod->caches.push_back(enveloppe); Value* zero = mvm::jit::constantZero; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=53138&r1=53137&r2=53138&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Fri Jul 4 11:22:01 2008 @@ -65,9 +65,7 @@ if (!rcache) { JavaMethod* dmeth = ocl->lookupMethod(utf8, sign->keyName, false, true); if (cache->methPtr) { - rcache = new CacheNode(); - rcache->initialise(); - rcache->enveloppe = enveloppe; + rcache = new CacheNode(enveloppe); } else { rcache = cache; } From nicolas.geoffray at lip6.fr Fri Jul 4 13:47:55 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 04 Jul 2008 20:47:55 -0000 Subject: [vmkit-commits] [vmkit] r53139 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMClassLoader.cpp.inc VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaJIT.cpp VMCore/Jnjvm.cpp Message-ID: <200807042047.m64KltC8016979@zion.cs.uiuc.edu> Author: geoffray Date: Fri Jul 4 15:47:54 2008 New Revision: 53139 URL: http://llvm.org/viewvc/llvm-project?rev=53139&view=rev Log: Typo & comment. Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp.inc vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp.inc?rev=53139&r1=53138&r2=53139&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp.inc (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp.inc Fri Jul 4 15:47:54 2008 @@ -94,7 +94,7 @@ Class* cl = vm->constructClass(name, (JavaObject*)loader); if (cl->status == hashed) { - cl->aquire(); + cl->acquire(); if (cl->status == hashed) { cl->bytes = (ArrayUInt8*)bytes; cl->status = loaded; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=53139&r1=53138&r2=53139&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Fri Jul 4 15:47:54 2008 @@ -283,7 +283,7 @@ void* JavaMethod::_compiledPtr() { if (code != 0) return code; else { - classDef->aquire(); + classDef->acquire(); if (code == 0) { code = classDef->isolate->TheModuleProvider->materializeFunction(this); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=53139&r1=53138&r2=53139&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Fri Jul 4 15:47:54 2008 @@ -63,13 +63,25 @@ }; - +/// CommonClass - This class is the root class of all Java classes. It is +/// currently GC-allocated in JnJVM, but will be permanently allocated when the +/// class loader finalizer method will be defined. +/// class CommonClass : public mvm::Object { private: + +/// FieldCmp - Internal class for field and method lookup in a class. +/// class FieldCmp { public: + + /// name - The name of the field/method + /// const UTF8* name; + + /// type - The type of the field/method. + /// const UTF8* type; FieldCmp(const UTF8* n, const UTF8* t) : name(n), type(t) {} @@ -83,23 +95,44 @@ public: - /// virtualSize - The size of instances of this class. - /// +//===----------------------------------------------------------------------===// +// +// Do not reorder these fields or add new ones! the LLVM runtime assumes that +// classes have the following beginning layout. +// +//===----------------------------------------------------------------------===// + + + /// virtualSize - The size of instances of this class. Array classes do + /// not need this information, but to simplify accessing this field in + /// the JIT, we put this in here. + /// uint32 virtualSize; - /// virtualVT - The virtual table of instances of this class. + /// virtualVT - The virtual table of instances of this class. Like the + /// virtualSize field, array classes do not need this information. But we + /// simplify JIT generation to set it here. /// VirtualTable* virtualVT; - /// display - The class hierarchy of supers for this class. + /// display - The class hierarchy of supers for this class. Array classes + /// do not need it. /// CommonClass** display; /// depth - The depth of this class in its class hierarchy. - /// display[depth] contains the class. + /// display[depth] contains the class. Array classes do not need it. /// uint32 depth; + + +//===----------------------------------------------------------------------===// +// +// New fields can be added from now, or reordered. +// +//===----------------------------------------------------------------------===// + /// virtualTableSize - The size of the virtual table of this class. /// uint32 virtualTableSize; @@ -192,65 +225,134 @@ /// method_map staticMethods; - + /// constructMethod - Add a new method in this class method map. + /// JavaMethod* constructMethod(const UTF8* name, const UTF8* type, uint32 access); + /// constructField - Add a new field in this class field map. + /// JavaField* constructField(const UTF8* name, const UTF8* type, uint32 access); + /// printClassName - Adds a string representation of this class in the + /// given buffer. + /// static void printClassName(const UTF8* name, mvm::PrintBuffer* buf); - void aquire() { + /// acquire - Acquire this class lock. + /// + void acquire() { lockVar->lock(); } + /// release - Release this class lock. + /// void release() { lockVar->unlock(); } + /// waitClass - Wait for the class to be loaded/initialized/resolved. + /// void waitClass() { condVar->wait(lockVar); } - + + /// broadcastClass - Unblock threads that were waiting on the class being + /// loaded/initialized/resolved. + /// void broadcastClass() { condVar->broadcast(); } + /// ownerClass - Is the current thread the owner of this thread? + /// bool ownerClass() { return mvm::Lock::selfOwner(lockVar); } + /// lookupMethodDontThrow - Lookup a method in the method map of this class. + /// Do not throw if the method is not found. + /// JavaMethod* lookupMethodDontThrow(const UTF8* name, const UTF8* type, bool isStatic, bool recurse); + /// lookupMethod - Lookup a method and throw an exception if not found. + /// JavaMethod* lookupMethod(const UTF8* name, const UTF8* type, bool isStatic, bool recurse); + /// lookupFieldDontThrow - Lookup a field in the field map of this class. Do + /// not throw if the field is not found. + /// JavaField* lookupFieldDontThrow(const UTF8* name, const UTF8* type, bool isStatic, bool recurse); + /// lookupField - Lookup a field and throw an exception if not found. + /// JavaField* lookupField(const UTF8* name, const UTF8* type, bool isStatic, bool recurse); - + /// print - Print the class for debugging purposes. + /// virtual void print(mvm::PrintBuffer *buf) const; + + /// tracer - The tracer of this GC-allocated class. + /// virtual void TRACER; + /// inheritName - Does this class in its class hierarchy inherits + /// the given name? Equality is on the name. This function does not take + /// into account array classes. + /// bool inheritName(const UTF8* Tname); + + /// isOfTypeName - Does this class inherits the given name? Equality is on + /// the name. This function takes into account array classes. + /// bool isOfTypeName(const UTF8* Tname); + + /// implements - Does this class implement the given class? Returns true if + /// the class is in the interface class hierarchy. + /// bool implements(CommonClass* cl); + + /// instantationOfArray - If this class is an array class, does its subclass + /// implements the given array class subclass? + /// bool instantiationOfArray(ClassArray* cl); + + /// subclassOf - If this class is a regular class, is it a subclass of the + /// given class? + /// bool subclassOf(CommonClass* cl); + + /// isAssignableFrom - Is this class assignable from the given class? The + /// classes may be of any type. + /// bool isAssignableFrom(CommonClass* cl); + + /// getClassDelegatee - Return the java/lang/Class representation of this + /// class. + /// JavaObject* getClassDelegatee(); + + /// initialiseClass - If the class has a static initializer and has not been + /// initialized yet, call it. void initialiseClass(); + + /// resolveClass - If the class has not been resolved yet, resolve it. + /// void resolveClass(bool doClinit); #ifndef MULTIPLE_VM + /// getStatus - Get the resolution/initialization status of this class. + /// JavaState* getStatus() { return &status; } + /// isReady - Has this class been initialized? + /// bool isReady() { return status == ready; } @@ -260,16 +362,33 @@ return *getStatus() == ready; } #endif + + /// isResolved - Has this class been resolved? + /// bool isResolved() { return status >= resolved; } + /// CommonClass - Create a class with th given name. + /// CommonClass(Jnjvm* vm, const UTF8* name, bool isArray); + /// VT - The virtual table of instances of this class (TODO: should be + /// removed). + /// static VirtualTable* VT; + + /// jnjvmClassLoader - The bootstrap class loader (null). + /// static JavaObject* jnjvmClassLoader; + /// ~CommonClass - Free memory used by this class, and remove it from + /// metadata. + /// ~CommonClass(); + + /// CommonClass - Default constructor. + /// CommonClass(); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=53139&r1=53138&r2=53139&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Fri Jul 4 15:47:54 2008 @@ -905,7 +905,7 @@ // We don't need the lock here, and Java requires to load the classes in the // try clause, which may require compilation. Therefore we release the lock - // and aquire it after the exception table is read. + // and acquire it after the exception table is read. mvm::jit::executionEngine->lock.release(); for (uint16 i = 0; i < nbe - sync; ++i) { Exception* ex = new Exception(); @@ -1090,7 +1090,7 @@ if (type == JavaCtpInfo::ConstantString) { Value* toPush = 0; if (ctpInfo->ctpRes[index] == 0) { - compilingClass->aquire(); + compilingClass->acquire(); if (ctpInfo->ctpRes[index] == 0) { const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]); void* val = 0; Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=53139&r1=53138&r2=53139&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Fri Jul 4 15:47:54 2008 @@ -319,7 +319,7 @@ if (cl->isArray || cl->isPrimitive) { *status = ready; } else if (!(*status == ready)) { - cl->aquire(); + cl->acquire(); JavaState* status = cl->getStatus(); if (*status == ready) { cl->release(); @@ -381,7 +381,7 @@ void Jnjvm::resolveClass(CommonClass* cl, bool doClinit) { if (cl->status < resolved) { - cl->aquire(); + cl->acquire(); int status = cl->status; if (status >= resolved) { cl->release(); @@ -399,7 +399,7 @@ cl->status = readed; cl->release(); loadParents((Class*)cl); - cl->aquire(); + cl->acquire(); cl->status = prepared; TheModule->resolveVirtualClass((Class*)cl); cl->status = resolved; @@ -429,7 +429,7 @@ if (bytes) { if (!cl) cl = bootstrapVM->constructClass(bootstrapName, loader); if (cl->status == hashed) { - cl->aquire(); + cl->acquire(); if (cl->status == hashed) { cl->status = loaded; ((Class*)cl)->bytes = bytes; @@ -782,7 +782,7 @@ #ifndef MULTIPLE_VM JavaObject* Jnjvm::getClassDelegatee(CommonClass* cl) { - cl->aquire(); + cl->acquire(); if (!(cl->delegatee)) { JavaObject* delegatee = (*Classpath::newClass)(this); cl->delegatee = delegatee; @@ -799,7 +799,7 @@ } #else JavaObject* Jnjvm::getClassDelegatee(CommonClass* cl) { - cl->aquire(); + cl->acquire(); JavaObject* val = delegatees->lookup(cl); if (!val) { val = (*Classpath::newClass)(this); From tilmann.scheller at googlemail.com Sat Jul 5 12:28:07 2008 From: tilmann.scheller at googlemail.com (Tilmann Scheller) Date: Sat, 05 Jul 2008 19:28:07 -0000 Subject: [vmkit-commits] [vmkit] r53148 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h CLIJit.cpp CLISignature.cpp VMClass.cpp VMThread.h Message-ID: <200807051928.m65JS7qi002106@zion.cs.uiuc.edu> Author: tilmann Date: Sat Jul 5 14:28:07 2008 New Revision: 53148 URL: http://llvm.org/viewvc/llvm-project?rev=53148&view=rev Log: support for accessing generic type parameters Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp vmkit/trunk/lib/N3/VMCore/Assembly.h vmkit/trunk/lib/N3/VMCore/CLIJit.cpp vmkit/trunk/lib/N3/VMCore/CLISignature.cpp vmkit/trunk/lib/N3/VMCore/VMClass.cpp vmkit/trunk/lib/N3/VMCore/VMThread.h Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Jul 5 14:28:07 2008 @@ -375,7 +375,7 @@ } buf[i] = '>'; const UTF8* genName = UTF8::readerConstruct(VMThread::get()->vm, buf, size); - printf("%s\n", genName->printString()); + //printf("%s\n", genName->printString()); ClassNameCmp CC(genName, nameSpace); VMGenericClass* cl = (VMGenericClass*) loadedNameClasses->lookupOrCreate(CC, this, genClassDup); @@ -395,10 +395,21 @@ VMField* Assembly::constructField(VMClass* cl, const UTF8* name, VMCommonClass* signature, uint32 token) { - VMField* field = loadedTokenFields->lookupOrCreate(token, this, fieldDup); + VMField* field; + + if (VMThread::get()->currGenericClass == 0) { + // we are not reading a generic class + field = loadedTokenFields->lookupOrCreate(token, this, fieldDup); + } else { + // we are reading a generic class, don't add a reference + // to the loadedTokenFields map + field = fieldDup(token, this); + } + field->classDef = cl; field->signature = signature; field->name = name; + return field; } @@ -411,10 +422,21 @@ VMMethod* Assembly::constructMethod(VMClass* cl, const UTF8* name, uint32 token) { - VMMethod* meth = loadedTokenMethods->lookupOrCreate(token, this, methodDup); + VMMethod* meth; + + if (VMThread::get()->currGenericClass == 0) { + // we are not reading a generic class + meth = loadedTokenMethods->lookupOrCreate(token, this, methodDup); + } else { + // we are reading a generic class, don't add a reference + // to the loadedTokenMethods map + meth = methodDup(token, this); + } + meth->classDef = cl; meth->_signature = 0; meth->name = name; + return meth; } @@ -427,7 +449,6 @@ ass->assemblyRefs = 0; ass->isRead = false; ass->name = name; - ass->currGenericClass = 0; return ass; } @@ -1097,7 +1118,8 @@ void Assembly::readClass(VMCommonClass* cl) { // temporarily store the class being read in case it is a generic class - currGenericClass = dynamic_cast(cl); + VMGenericClass* old = VMThread::get()->currGenericClass; + VMThread::get()->currGenericClass = dynamic_cast(cl); uint32 index = cl->token & 0xffff; Table* typeTable = CLIHeader->tables[CONSTANT_TypeDef]; @@ -1151,7 +1173,7 @@ } // we have stopped reading a generic class - currGenericClass = 0; + VMThread::get()->currGenericClass = old; } void Assembly::readCustomAttributes(uint32 offset, std::vector& args, VMMethod* meth) { @@ -1515,40 +1537,65 @@ const UTF8* name = readString((N3*)(VMThread::get()->vm), stringOffset + memberArray[CONSTANT_MEMBERREF_NAME]); - uint32 offset = blobOffset + memberArray[CONSTANT_MEMBERREF_SIGNATURE]; - VMCommonClass* signature = extractFieldSignature(offset); - uint32 value = memberArray[CONSTANT_MEMBERREF_CLASS]; uint32 table = value & 7; index = value >> 3; + VMCommonClass* type = 0; + switch (table) { case 0 : { uint32 typeToken = index + (CONSTANT_TypeDef << 24); - VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken, + type = loadType(((N3*)VMThread::get()->vm), typeToken, true, false, false, true); - VMField* field = type->lookupField(name, signature, stat, true); - return field; + break; } case 1 : { uint32 typeToken = index + (CONSTANT_TypeRef << 24); - VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken, + type = loadType(((N3*)VMThread::get()->vm), typeToken, true, false, false, true); - VMField* field = type->lookupField(name, signature, stat, true); - return field; + break; } case 2: - case 3: - case 4: VMThread::get()->vm->error("implement me"); break; + case 3: VMThread::get()->vm->error("implement me"); break; + case 4: { + uint32 typeToken = index + (CONSTANT_TypeSpec << 24); + type = loadType(((N3*)VMThread::get()->vm), typeToken, + true, false, false, true); + break; + } default: VMThread::get()->vm->error("unknown MemberRefParent tag %d", table); } - return 0; + uint32 offset = blobOffset + memberArray[CONSTANT_MEMBERREF_SIGNATURE]; + + VMGenericClass* genClass = dynamic_cast(type); + + if (genClass) { + // save previous generic class + VMGenericClass* old = VMThread::get()->currGenericClass; + + // set generic class this MemberRef is referring to + VMThread::get()->currGenericClass = genClass; + + VMCommonClass* signature = extractFieldSignature(offset); + + // restore saved class + VMThread::get()->currGenericClass = old; + + VMField* field = type->lookupField(name, signature, stat, true); + return field; + } else { + VMCommonClass* signature = extractFieldSignature(offset); + VMField* field = type->lookupField(name, signature, stat, true); + return field; + } + } Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.h (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sat Jul 5 14:28:07 2008 @@ -161,9 +161,6 @@ MethodTokenMap* loadedTokenMethods; FieldTokenMap* loadedTokenFields; - // helper which points to the current generic class while it is being read in readClass() - VMGenericClass* currGenericClass; - mvm::Lock* lockVar; mvm::Cond* condVar; const UTF8* name; Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Jul 5 14:28:07 2008 @@ -459,10 +459,10 @@ jit->compilingClass = meth->classDef; jit->compilingMethod = meth; - // save current class in case of recursive calls to compile() - VMGenericClass* old = jit->compilingClass->assembly->currGenericClass; + // save previous current generic class to restore it later + VMGenericClass* old = VMThread::get()->currGenericClass; // temporarily store the class being compiled in case it is a generic class - jit->compilingClass->assembly->currGenericClass = dynamic_cast(jit->compilingClass); + VMThread::get()->currGenericClass = dynamic_cast(jit->compilingClass); jit->unifiedUnreachable = unifiedUnreachable; @@ -473,7 +473,7 @@ inlineMethods[meth] = false; // restore saved class - jit->compilingClass = old; + VMThread::get()->currGenericClass = old; return ret; } @@ -1420,14 +1420,28 @@ jit->compilingClass = cl; jit->compilingMethod = meth; + // save previous generic class + VMGenericClass* old = VMThread::get()->currGenericClass; + + // temporarily store the class of the method to be compiled + // in case it is a generic class + VMThread::get()->currGenericClass = dynamic_cast(cl); + + Function* func; meth->getSignature(); + if (isInternal(meth->implFlags)) { - return jit->compileNative(); + func = jit->compileNative(); } else if (meth->offset == 0) { - return jit->compileIntern(); + func = jit->compileIntern(); } else { - return jit->compileFatOrTiny(); + func = jit->compileFatOrTiny(); } + + // restore saved class + VMThread::get()->currGenericClass = old; + + return func; } llvm::Function *VMMethod::compiledPtr() { Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Sat Jul 5 14:28:07 2008 @@ -1,4 +1,4 @@ -//===--------- CLIsignature.cpp - Reads CLI signatures --------------------===// +//===--------- CLISignature.cpp - Reads CLI signatures --------------------===// // // N3 // @@ -141,10 +141,8 @@ static VMCommonClass* METHOD_ElementTypeVar(uint32 op, Assembly* ass, uint32& offset) { uint32 number = ass->uncompressSignature(offset); - return ass->currGenericClass->genericParams[number]; - //uint32 type = READ_U4(ass->bytes, offset); - //VMThread::get()->vm->error("implement me"); - //return 0; + + return VMThread::get()->currGenericClass->genericParams[number]; } static VMCommonClass* METHOD_ElementTypeArray(uint32 op, Assembly* ass, uint32& offset) { @@ -371,6 +369,7 @@ uint32 hasThis = call & CONSTANT_HasThis ? 1 : 0; uint32 realCount = paramCount + hasThis; + //uint32 generic = call & CONSTANT_Generic ? 1 : 0; VMCommonClass* ret = exploreType(offset); types.push_back(ret); @@ -410,6 +409,9 @@ if (fieldSig != 0x6) { VMThread::get()->vm->error("unknown field sig %x", fieldSig); } + + // TODO implement support for custom modifiers + // see ECMA 335 23.2.4, 23.2.7 return exploreType(offset); Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Sat Jul 5 14:28:07 2008 @@ -216,8 +216,8 @@ VMMethod* meth = cl->lookupMethodDontThrow(N3::clinitName, args, true, false); - PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "; ", 0); - PRINT_DEBUG(N3_LOAD, 0, LIGHT_GREEN, "clinit ", 0); + PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "%s", "; "); + PRINT_DEBUG(N3_LOAD, 0, LIGHT_GREEN, "%s", "clinit "); PRINT_DEBUG(N3_LOAD, 0, COLOR_NORMAL, "%s::%s\n", printString(), cl->printString()); @@ -818,5 +818,8 @@ } void VMGenericClass::print(mvm::PrintBuffer* buf) const { - buf->write("Generic Class"); -} + buf->write("GenCLIType<"); + nameSpace->print(buf); + buf->write("::"); + name->print(buf); + buf->write(">");} Modified: vmkit/trunk/lib/N3/VMCore/VMThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.h?rev=53148&r1=53147&r2=53148&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMThread.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMThread.h Sat Jul 5 14:28:07 2008 @@ -24,6 +24,7 @@ class VirtualMachine; class VMClass; +class VMGenericClass; class VMObject; class VMThread : public mvm::Thread { @@ -38,6 +39,9 @@ unsigned int self; unsigned int interruptFlag; unsigned int state; + + // helper which points to the current generic class + VMGenericClass* currGenericClass; static const unsigned int StateRunning; static const unsigned int StateWaiting; From tilmann.scheller at googlemail.com Sun Jul 6 12:52:02 2008 From: tilmann.scheller at googlemail.com (Tilmann Scheller) Date: Sun, 06 Jul 2008 19:52:02 -0000 Subject: [vmkit-commits] [vmkit] r53161 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h CLISignature.cpp Message-ID: <200807061952.m66Jq2uG014961@zion.cs.uiuc.edu> Author: tilmann Date: Sun Jul 6 14:52:01 2008 New Revision: 53161 URL: http://llvm.org/viewvc/llvm-project?rev=53161&view=rev Log: add early support for generic methods Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp vmkit/trunk/lib/N3/VMCore/Assembly.h vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53161&r1=53160&r2=53161&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sun Jul 6 14:52:01 2008 @@ -1147,10 +1147,13 @@ for (uint32 i = 0; i < nbMethods; ++i) { VMMethod* meth = readMethodDef(i + methodList, cl); - if (isStatic(meth->flags)) { - cl->staticMethods.push_back(meth); - } else { - cl->virtualMethods.push_back(meth); + + if (meth != NULL) { + if (isStatic(meth->flags)) { + cl->staticMethods.push_back(meth); + } else { + cl->virtualMethods.push_back(meth); + } } } } @@ -1320,35 +1323,43 @@ uint32 paramList = methArray[CONSTANT_METHODDEF_PARAMLIST]; uint32 offset = blobOffset + signature; - VMMethod* meth = - constructMethod((VMClass*)cl, readString(cl->vm, (name + stringOffset)), - token); - meth->virt = extractMethodSignature(offset, cl, meth->parameters); - meth->flags = flags; - meth->implFlags = implFlags; - - if (rva) { - meth->offset = textSection->rawAddress + - (rva - textSection->virtualAddress); + + if (isGenericMethod(offset)) { + // generic methods are read on instantiation + return NULL; } else { - meth->offset = 0; - } + offset = blobOffset + signature; + + VMMethod* meth = + constructMethod((VMClass*)cl, readString(cl->vm, (name + stringOffset)), + token); + meth->virt = extractMethodSignature(offset, cl, meth->parameters); + meth->flags = flags; + meth->implFlags = implFlags; + + if (rva) { + meth->offset = textSection->rawAddress + + (rva - textSection->virtualAddress); + } else { + meth->offset = 0; + } - if (paramList && paramTable != 0 && paramList <= paramSize) { - uint32 endParam = (index == methodSize) ? - paramSize + 1 : - methTable->readIndexInRow(index + 1, CONSTANT_METHODDEF_PARAMLIST, + if (paramList && paramTable != 0 && paramList <= paramSize) { + uint32 endParam = (index == methodSize) ? + paramSize + 1 : + methTable->readIndexInRow(index + 1, CONSTANT_METHODDEF_PARAMLIST, bytes); - uint32 nbParams = endParam - paramList; + uint32 nbParams = endParam - paramList; + + for (uint32 j = 0; j < nbParams; ++j) { + meth->params.push_back(readParam(j + paramList, meth)); + } - for (uint32 j = 0; j < nbParams; ++j) { - meth->params.push_back(readParam(j + paramList, meth)); } + return meth; } - - return meth; } VMField* Assembly::readField(uint32 index, VMCommonClass* cl) { @@ -1542,7 +1553,7 @@ uint32 table = value & 7; index = value >> 3; - VMCommonClass* type = 0; + VMCommonClass* type = NULL; switch (table) { case 0 : { @@ -1601,6 +1612,7 @@ VMMethod* Assembly::getMethodFromToken(uint32 token) { VMMethod* meth = lookupMethodFromToken(token); + if (!meth) { uint32 table = token >> 24; switch (table) { @@ -1628,13 +1640,20 @@ meth = readMemberRefAsMethod(token); break; } + + case CONSTANT_MethodSpec : { + meth = readMethodSpec(token); + break; + } default : { VMThread::get()->vm->error("implement me"); } } } + meth->getSignature(); + return meth; } @@ -1703,7 +1722,7 @@ case 2: case 3: VMThread::get()->vm->error("implement me %d", table); break; case 4: { - VMClass* type = (VMClass*)readTypeSpec(vm, index); + VMClass* type = (VMClass*) readTypeSpec(vm, index); VMGenericClass* genClass = dynamic_cast(type); @@ -1733,6 +1752,22 @@ return 0; } +VMMethod* Assembly::readMethodSpec(uint32 token) { + uint32 index = token & 0xffff; + + Table* methodTable = CLIHeader->tables[CONSTANT_MethodSpec]; + uint32* methodArray = (uint32*) alloca(sizeof(uint32) * methodTable->rowSize); + + methodTable->readRow(methodArray, index, bytes); + + uint32 method = methodArray[CONSTANT_METHOD_SPEC_METHOD]; + uint32 instantiation = methodArray[CONSTANT_METHOD_SPEC_INSTANTIATION]; + + VMThread::get()->vm->error("MethodSpec"); +// return NULL; + return (VMMethod*) (method ^ instantiation); +} + const UTF8* Assembly::readUserString(uint32 token) { uint32 offset = CLIHeader->usStream->realOffset + token; Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=53161&r1=53160&r2=53161&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.h (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sun Jul 6 14:52:01 2008 @@ -217,6 +217,7 @@ void getProperties(VMCommonClass* cl); Property* readProperty(uint32 index, VMCommonClass* cl); VMMethod* readMethodDef(uint32 index, VMCommonClass* cl); + VMMethod* readMethodSpec(uint32 token); VMField* readField(uint32 index, VMCommonClass* cl); Param* readParam(uint32 index, VMMethod* meth); VMClass* readTypeDef(N3* vm, uint32 index); @@ -230,6 +231,7 @@ bool extractMethodSignature(uint32& offset, VMCommonClass* cl, std::vector ¶ms); + bool isGenericMethod(uint32& offset); void localVarSignature(uint32& offset, std::vector& locals); VMCommonClass* extractFieldSignature(uint32& offset); @@ -530,7 +532,7 @@ bitmask = bitmask | ((fieldSize - 1) << (offset << 1)); \ } -// Some encondigs are not used here +// Some encodings are not used here #define CUSTOM_ATTRIBUTE_TYPE(offset) { \ uint32 fieldSize = 0; \ if (tables[CONSTANT_MethodDef]->rowsNumber < 0x2000 && \ Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53161&r1=53160&r2=53161&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Sun Jul 6 14:52:01 2008 @@ -385,6 +385,15 @@ return hasThis != 0; } +// checks whether the MethodDefSig at offset contains generic parameters +bool Assembly::isGenericMethod(uint32& offset) { + uncompressSignature(offset); // count + + uint32 callingConvention = READ_U1(bytes, offset); + + return callingConvention & CONSTANT_Generic ? true : false; +} + void Assembly::localVarSignature(uint32& offset, std::vector& locals) { //uint32 count = From nicolas.geoffray at lip6.fr Mon Jul 7 09:41:27 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 07 Jul 2008 16:41:27 -0000 Subject: [vmkit-commits] [vmkit] r53173 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathMethod.cpp.inc Classpath/ClasspathVMClass.cpp.inc Classpath/ClasspathVMField.cpp.inc Classpath/ClasspathVMThrowable.cpp.inc VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaConstantPool.cpp VMCore/JavaMetaJIT.cpp VMCore/JavaUpcalls.cpp VMCore/JavaUpcalls.h VMCore/Jnjvm.cpp VMCore/LowerConstantCalls.cpp Message-ID: <200807071641.m67GfR3t001804@zion.cs.uiuc.edu> Author: geoffray Date: Mon Jul 7 11:41:26 2008 New Revision: 53173 URL: http://llvm.org/viewvc/llvm-project?rev=53173&view=rev Log: Simplify & comment. Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp.inc vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp.inc vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMField.cpp.inc vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp.inc vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp.inc?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp.inc (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp.inc Mon Jul 7 11:41:26 2008 @@ -128,42 +128,42 @@ } else if (retType == AssessorDesc::dBool) { uint32 val = 0; RUN_METH(Int); - res = (*Classpath::boolClass)(vm); + res = Classpath::boolClass->doNew(vm); Classpath::boolValue->setVirtualInt8Field(res, val); } else if (retType == AssessorDesc::dByte) { uint32 val = 0; RUN_METH(Int); - res = (*Classpath::byteClass)(vm); + res = Classpath::byteClass->doNew(vm); Classpath::byteValue->setVirtualInt8Field(res, val); } else if (retType == AssessorDesc::dChar) { uint32 val = 0; RUN_METH(Int); - res = (*Classpath::charClass)(vm); + res = Classpath::charClass->doNew(vm); Classpath::charValue->setVirtualInt16Field(res, val); } else if (retType == AssessorDesc::dShort) { uint32 val = 0; RUN_METH(Int); - res = (*Classpath::shortClass)(vm); + res = Classpath::shortClass->doNew(vm); Classpath::shortValue->setVirtualInt16Field(res, val); } else if (retType == AssessorDesc::dInt) { uint32 val = 0; RUN_METH(Int); - res = (*Classpath::intClass)(vm); + res = Classpath::intClass->doNew(vm); Classpath::intValue->setVirtualInt32Field(res, val); } else if (retType == AssessorDesc::dLong) { sint64 val = 0; RUN_METH(Long); - res = (*Classpath::longClass)(vm); + res = Classpath::longClass->doNew(vm); Classpath::longValue->setVirtualLongField(res, val); } else if (retType == AssessorDesc::dFloat) { float val = 0; RUN_METH(Float); - res = (*Classpath::floatClass)(vm); + res = Classpath::floatClass->doNew(vm); Classpath::floatValue->setVirtualFloatField(res, val); } else if (retType == AssessorDesc::dDouble) { double val = 0; RUN_METH(Double); - res = (*Classpath::doubleClass)(vm); + res = Classpath::doubleClass->doNew(vm); Classpath::doubleValue->setVirtualDoubleField(res, val); } else if (retType == AssessorDesc::dTab || retType == AssessorDesc::dRef) { JavaObject* val = 0; Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp.inc?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp.inc (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp.inc Mon Jul 7 11:41:26 2008 @@ -99,7 +99,7 @@ i != e; ++i, ++index) { JavaMethod* meth = *i; // TODO: check parameter types - JavaObject* tmp = (*Classpath::newConstructor)(vm); + JavaObject* tmp = Classpath::newConstructor->doNew(vm); Classpath::initConstructor->invokeIntSpecial(vm, tmp, Cl, meth); ret->elements[index] = tmp; } @@ -146,7 +146,7 @@ i != e; ++i, ++index) { JavaMethod* meth = *i; // TODO: check parameter types - JavaObject* tmp = (*Classpath::newMethod)(vm); + JavaObject* tmp = Classpath::newMethod->doNew(vm); Classpath::initMethod->invokeIntSpecial(vm, tmp, Cl, vm->UTF8ToStr(meth->name), meth); ret->elements[index] = tmp; @@ -315,7 +315,7 @@ i != e; ++i, ++index) { JavaField* field = *i; // TODO: check parameter types - JavaObject* tmp = (*Classpath::newField)(vm); + JavaObject* tmp = Classpath::newField->doNew(vm); Classpath::initField->invokeIntSpecial(vm, tmp, Cl, vm->UTF8ToStr(field->name), field); ret->elements[index] = tmp; Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMField.cpp.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMField.cpp.inc?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMField.cpp.inc (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMField.cpp.inc Mon Jul 7 11:41:26 2008 @@ -318,7 +318,7 @@ uint8 val = (isStatic(field->access) ? field->getStaticInt8Field() : field->getVirtualInt8Field(obj)); - res = (*Classpath::boolClass)(vm); + res = Classpath::boolClass->doNew(vm); Classpath::boolValue->setVirtualInt8Field(res, val); break; } @@ -326,7 +326,7 @@ sint8 val = (isStatic(field->access) ? field->getStaticInt8Field() : field->getVirtualInt8Field(obj)); - res = (*Classpath::byteClass)(vm); + res = Classpath::byteClass->doNew(vm); Classpath::byteValue->setVirtualInt8Field(res, val); break; } @@ -334,7 +334,7 @@ uint16 val = (isStatic(field->access) ? field->getStaticInt16Field() : field->getVirtualInt16Field(obj)); - res = (*Classpath::charClass)(vm); + res = Classpath::charClass->doNew(vm); Classpath::charValue->setVirtualInt16Field(res, val); break; } @@ -342,7 +342,7 @@ sint16 val = (isStatic(field->access) ? field->getStaticInt16Field() : field->getVirtualInt16Field(obj)); - res = (*Classpath::shortClass)(vm); + res = Classpath::shortClass->doNew(vm); Classpath::shortValue->setVirtualInt16Field(res, val); break; } @@ -350,7 +350,7 @@ sint32 val = (isStatic(field->access) ? field->getStaticInt32Field() : field->getVirtualInt32Field(obj)); - res = (*Classpath::intClass)(vm); + res = Classpath::intClass->doNew(vm); Classpath::intValue->setVirtualInt32Field(res, val); break; } @@ -358,7 +358,7 @@ sint64 val = (isStatic(field->access) ? field->getStaticLongField() : field->getVirtualLongField(obj)); - res = (*Classpath::longClass)(vm); + res = Classpath::longClass->doNew(vm); Classpath::longValue->setVirtualLongField(res, val); break; } @@ -366,7 +366,7 @@ float val = (isStatic(field->access) ? field->getStaticFloatField() : field->getVirtualFloatField(obj)); - res = (*Classpath::floatClass)(vm); + res = Classpath::floatClass->doNew(vm); Classpath::floatValue->setVirtualFloatField(res, val); break; } @@ -374,7 +374,7 @@ double val = (isStatic(field->access) ? field->getStaticDoubleField() : field->getVirtualDoubleField(obj)); - res = (*Classpath::doubleClass)(vm); + res = Classpath::doubleClass->doNew(vm); Classpath::doubleValue->setVirtualDoubleField(res, val); break; } Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp.inc?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp.inc (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp.inc Mon Jul 7 11:41:26 2008 @@ -64,7 +64,7 @@ bool native = isNative(meth->access); - JavaObject* res = (*Classpath::newStackTraceElement)(vm); + JavaObject* res = Classpath::newStackTraceElement->doNew(vm); Classpath::initStackTraceElement->invokeIntSpecial(vm, res, sourceName, (uint32)ip, className, methodName, native); @@ -83,7 +83,7 @@ return recGetStackTrace(stack, first + 1, rec); } } else { - return ArrayObject::acons(rec, JavaArray::ofObject, vm); + return ArrayObject::acons(rec, Classpath::stackTraceArray, vm); } } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Jul 7 11:41:26 2008 @@ -41,10 +41,10 @@ std::vector ClassArray::InterfacesArray; -Attribut::Attribut(const UTF8* name, unsigned int length, - const Reader& reader) { +Attribut::Attribut(const UTF8* name, uint32 length, + uint32 offset) { - this->start = reader.cursor; + this->start = offset; this->nbb = length; this->name = name; @@ -280,7 +280,7 @@ } } -void* JavaMethod::_compiledPtr() { +void* JavaMethod::compiledPtr() { if (code != 0) return code; else { classDef->acquire(); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Mon Jul 7 11:41:26 2008 @@ -35,30 +35,80 @@ class JavaJIT; class JavaMethod; class JavaObject; -class Reader; class Signdef; class Typedef; class UTF8; +/// JavaState - List of states a Java class can have. A class is ready to be +/// used (i.e allocating instances of the class, calling methods of the class +/// and accessing static fields of the class) when it is in the ready state. +/// typedef enum JavaState { - hashed = 0, loaded, readed, prepared, resolved, clinitParent, inClinit, ready + hashed = 0, /// The class is hashed in a class loader table. + loaded, /// The .class file has been found. + classRead, /// The .class file has been read. + prepared, /// The parents of this class has been resolved. + resolved, /// The class has been resolved. + clinitParent, /// The class is cliniting its parents. + inClinit, /// The class is cliniting. + ready /// The class is ready to be used. }JavaState; +/// Attribut - This class represents JVM attributes to Java class, methods and +/// fields located in the .class file. +/// class Attribut { public: + + /// name - The name of the attribut. These are specified in the JVM book. + /// Experimental attributes exist, but the JnJVM does nor parse them. + /// const UTF8* name; + + /// start - The offset in the class of this attribut. + /// unsigned int start; - unsigned int nbb; - Attribut(const UTF8* name, unsigned int length, const Reader& reader); + /// nbb - The size of the attribut. + /// + unsigned int nbb; + /// Attribut - Create an attribut at the given length and offset. + /// + Attribut(const UTF8* name, uint32 length, uint32 offset); + + /// codeAttribut - The "Code" JVM attribut. This is a method attribut for + /// finding the bytecode of a method in the .class file. + // static const UTF8* codeAttribut; + + /// exceptionsAttribut - The "Exceptions" attribut. This is a method + /// attribut for finding the exception table of a method in the .class + /// file. + /// static const UTF8* exceptionsAttribut; + + /// constantAttribut - The "ConstantValue" attribut. This is a field attribut + /// when the field has a static constant value. + /// static const UTF8* constantAttribut; + + /// lineNumberTableAttribut - The "LineNumberTable" attribut. This is used + /// for corresponding JVM bytecode to source line in the .java file. + /// static const UTF8* lineNumberTableAttribut; + + /// innerClassAttribut - The "InnerClasses" attribut. This is a class attribut + /// for knowing the inner/outer informations of a Java class. + /// static const UTF8* innerClassesAttribut; + + /// sourceFileAttribut - The "SourceFile" attribut. This is a class attribut + /// and gives the correspondance between a class and the name of its Java + /// file. + /// static const UTF8* sourceFileAttribut; }; @@ -393,122 +443,273 @@ }; +/// ClassPrimitive - This class represents internal classes for primitive +/// types, e.g. java/lang/Integer.TYPE. +/// class ClassPrimitive : public CommonClass { public: ClassPrimitive(Jnjvm* vm, const UTF8* name); }; + +/// Class - This class is the representation of Java regular classes (i.e not +/// array or primitive). Theses classes have a constant pool. +/// class Class : public CommonClass { public: + + /// VT - The virtual table of this class. + /// static VirtualTable* VT; + + /// minor - The minor version of this class. + /// unsigned int minor; + + /// major - The major version of this class. + /// unsigned int major; + + /// bytes - The .class file of this class. + /// ArrayUInt8* bytes; + + /// ctpInfo - The constant pool info of this class. + /// JavaCtpInfo* ctpInfo; + + /// attributs - JVM attributes of this class. + /// std::vector attributs; + + /// innerClasses - The inner classes of this class. + /// std::vector innerClasses; + + /// outerClass - The outer class, if this class is an inner class. + /// Class* outerClass; + + /// innerAccess - The access of this class, if this class is an inner class. + /// uint32 innerAccess; + + /// innerOuterResolved - Is the inner/outer resolution done? + /// bool innerOuterResolved; + /// staticSize - The size of the static instance of this class. + /// uint32 staticSize; + + /// staticVT - The virtual table of the static instance of this class. + /// VirtualTable* staticVT; + + /// doNew - Allocates a Java object whose class is this class. + /// JavaObject* doNew(Jnjvm* vm); + + /// print - Prints a string representation of this class in the buffer. + /// virtual void print(mvm::PrintBuffer *buf) const; + + /// tracer - Tracer function of instances of Class. + /// virtual void TRACER; ~Class(); Class(); - - JavaObject* operator()(Jnjvm* vm); + /// lookupAttribut - Look up a JVM attribut of this class. + /// Attribut* lookupAttribut(const UTF8* key); - + + /// staticInstance - Get the static instance of this class. A static instance + /// is inlined when the vm is in a single environment. In a multiple + /// environment, the static instance is in a hashtable. + /// #ifndef MULTIPLE_VM JavaObject* _staticInstance; JavaObject* staticInstance() { return _staticInstance; } + + /// createStaticInstance - Create the static instance of this class. This is + /// a no-op in a single environment because it is created only once when + /// creating the static type of the class. In a multiple environment, it is + /// called on each initialization of the class. + /// void createStaticInstance() { } #else JavaObject* staticInstance(); void createStaticInstance(); #endif + /// Class - Create a class in the given virtual machine and with the given + /// name. Class(Jnjvm* vm, const UTF8* name); }; - +/// ClassArray - This class represents Java array classes. +/// class ClassArray : public CommonClass { public: + + /// VT - The virtual table of array classes. + /// static VirtualTable* VT; + + /// _baseClass - The base class of the array, or null if not resolved. + /// CommonClass* _baseClass; + + /// _funcs - The type of the base class of the array (primitive or + /// reference). Null if not resolved. + /// AssessorDesc* _funcs; + /// resolveComponent - Resolve the array class. The base class and the + /// AssessorDesc are resolved. + /// void resolveComponent(); + /// baseClass - Get the base class of this array class. Resolve the array + /// class if needed. + /// CommonClass* baseClass() { if (_baseClass == 0) resolveComponent(); return _baseClass; } + /// funcs - Get the type of the base class/ Resolve the array if needed. AssessorDesc* funcs() { if (_funcs == 0) resolveComponent(); return _funcs; } - /// Empty constructor for VT + /// ClassArray - Empty constructor for VT. + /// ClassArray() {} + + /// ClassArray - Construct a Java array class with the given name. + /// ClassArray(Jnjvm* vm, const UTF8* name); + + /// arrayLoader - Return the class loader of the class with the name 'name'. + /// If the class has not been loaded, load it with the given loader and + /// return the real class loader that loaded this class. + /// static JavaObject* arrayLoader(Jnjvm* isolate, const UTF8* name, JavaObject* loader, unsigned int start, unsigned int end); + /// print - Print a string representation of this array class. Used for + /// debugging purposes. + /// virtual void print(mvm::PrintBuffer *buf) const; + + /// tracer - Tracer of array classes. + /// virtual void TRACER; + /// SuperArray - The super class of array classes. + /// static CommonClass* SuperArray; - static std::vector InterfacesArray; -}; + /// InterfacesArray - The interfaces that array classes implement. + /// + static std::vector InterfacesArray; +}; +/// JavaMethod - This class represents Java methods. +/// class JavaMethod { friend class CommonClass; private: - void* _compiledPtr(); + + /// _signature - The signature of this method. Null if not resolved. + /// Signdef* _signature; + public: + + /// compiledPtr - Return a pointer to the compiled code of this Java method, + /// compiling it if necessary. + /// + void* compiledPtr(); + + /// JavaMethod - Delete the method as well as the cache enveloppes and + /// attributes of the method. + /// ~JavaMethod(); + + /// access - Java access type of this method (e.g. private, public...). + /// unsigned int access; + + /// attributs - List of Java attributs of this method. + /// std::vector attributs; + + /// caches - List of caches in this method. For all invokeinterface bytecode + /// there is a corresponding cache. + /// std::vector caches; + + /// classDef - The Java class where the method is defined. + /// Class* classDef; + + /// name - The name of the method. + /// const UTF8* name; + + /// type - The UTF8 signature of the method. + /// const UTF8* type; + + /// canBeInlined - Can the method be inlined? + /// bool canBeInlined; + + /// code - Pointer to the compiled code of this method. + /// void* code; /// offset - The index of the method in the virtual table. /// uint32 offset; + /// lookupAttribut - Look up an attribut in the method's attributs. Returns + /// null if the attribut is not found. + /// Attribut* lookupAttribut(const UTF8* key); - void* compiledPtr() { - if (!code) return _compiledPtr(); - return code; - } - + /// getSignature - Get the signature of thes method, resolving it if + /// necessary. + /// Signdef* getSignature() { if(!_signature) _signature = (Signdef*) classDef->isolate->constructType(type); return _signature; } + + /// printString - Output a string representation of the method. + /// + const char* printString() const; +//===----------------------------------------------------------------------===// +// +// Upcalls from JnJVM code to Java code. +// +//===----------------------------------------------------------------------===// + + /// This class of methods takes a variable argument list. uint32 invokeIntSpecialAP(Jnjvm* vm, JavaObject* obj, va_list ap); float invokeFloatSpecialAP(Jnjvm* vm, JavaObject* obj, va_list ap); double invokeDoubleSpecialAP(Jnjvm* vm, JavaObject* obj, va_list ap); @@ -526,7 +727,9 @@ double invokeDoubleStaticAP(Jnjvm* vm, va_list ap); sint64 invokeLongStaticAP(Jnjvm* vm, va_list ap); JavaObject* invokeJavaObjectStaticAP(Jnjvm* vm, va_list ap); - + + /// This class of methods takes a buffer which contain the arguments of the + /// call. uint32 invokeIntSpecialBuf(Jnjvm* vm, JavaObject* obj, void* buf); float invokeFloatSpecialBuf(Jnjvm* vm, JavaObject* obj, void* buf); double invokeDoubleSpecialBuf(Jnjvm* vm, JavaObject* obj, void* buf); @@ -544,7 +747,8 @@ double invokeDoubleStaticBuf(Jnjvm* vm, void* buf); sint64 invokeLongStaticBuf(Jnjvm* vm, void* buf); JavaObject* invokeJavaObjectStaticBuf(Jnjvm* vm, void* buf); - + + /// This class of methods is variadic. uint32 invokeIntSpecial(Jnjvm* vm, JavaObject* obj, ...); float invokeFloatSpecial(Jnjvm* vm, JavaObject* obj, ...); double invokeDoubleSpecial(Jnjvm* vm, JavaObject* obj, ...); @@ -563,35 +767,75 @@ sint64 invokeLongStatic(Jnjvm* vm, ...); JavaObject* invokeJavaObjectStatic(Jnjvm* vm, ...); - const char* printString() const; }; +/// JavaField - This class represents a Java field. +/// class JavaField { friend class CommonClass; private: + /// _signature - The signature of the field. Null if not resolved. + /// Typedef* _signature; public: + + /// ~JavaField - Destroy the field as well as its attributs. + /// ~JavaField(); + + /// access - The Java access type of this field (e.g. public, private). + /// unsigned int access; + + /// name - The name of the field. + /// const UTF8* name; + + /// type - The UTF8 type name of the field. + /// const UTF8* type; + + /// attributs - List of Java attributs for this field. + /// std::vector attributs; + + /// classDef - The class where the field is defined. + /// Class* classDef; + + /// ptrOffset - The offset of the field when the object containing + /// the field is casted to an array of bytes. + /// uint64 ptrOffset; + /// num - The index of the field in the field list. /// uint32 num; + /// getSignature - Get the signature of this field, resolving it if + /// necessary. + /// Typedef* getSignature() { if(!_signature) _signature = classDef->isolate->constructType(type); return _signature; } + /// initField - Init the value of the field in the given object. This is + /// used for static fields which have a default value. + /// void initField(JavaObject* obj); + + /// lookupAttribut - Look up the attribut in the field's list of attributs. + /// Attribut* lookupAttribut(const UTF8* key); + + /// printString - Output a string representation of the field. + /// const char* printString() const; + /// getVritual*Field - Get a virtual field of an object. + /// #define GETVIRTUALFIELD(TYPE, TYPE_NAME) \ TYPE getVirtual##TYPE_NAME##Field(JavaObject* obj) { \ assert(*(classDef->getStatus()) >= inClinit); \ @@ -599,6 +843,8 @@ return ((TYPE*)ptr)[0]; \ } + /// getStatic*Field - Get a static field in the defining class. + /// #define GETSTATICFIELD(TYPE, TYPE_NAME) \ TYPE getStatic##TYPE_NAME##Field() { \ assert(*(classDef->getStatus()) >= inClinit); \ @@ -607,6 +853,8 @@ return ((TYPE*)ptr)[0]; \ } + /// setVirtual*Field - Set a virtual of an object. + /// #define SETVIRTUALFIELD(TYPE, TYPE_NAME) \ void setVirtual##TYPE_NAME##Field(JavaObject* obj, TYPE val) { \ assert(*(classDef->getStatus()) >= inClinit); \ @@ -614,6 +862,7 @@ ((TYPE*)ptr)[0] = val; \ } + /// setStatic*Field - Set a static field in the defining class. #define SETSTATICFIELD(TYPE, TYPE_NAME) \ void setStatic##TYPE_NAME##Field(TYPE val) { \ assert(*(classDef->getStatus()) >= inClinit); \ Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Mon Jul 7 11:41:26 2008 @@ -354,7 +354,7 @@ sint32 ntIndex = entry & 0xFFFF; const UTF8* utf8 = UTF8At(ctpDef[ntIndex] >> 16); cl = getMethodClassIfLoaded(entry >> 16); - if (cl && cl->status >= readed) { + if (cl && cl->status >= classRead) { // lookup the method meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access), false); @@ -397,7 +397,7 @@ sint32 ntIndex = entry & 0xFFFF; const UTF8* utf8 = UTF8At(ctpDef[ntIndex] >> 16); CommonClass* cl = getMethodClassIfLoaded(entry >> 16); - if (cl && cl->status >= readed) { + if (cl && cl->status >= classRead) { // lookup the method meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access), false); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Mon Jul 7 11:41:26 2008 @@ -49,11 +49,6 @@ -JavaObject* Class::operator()(Jnjvm* vm) { - assert(*getStatus() >= inClinit); - return doNew(vm); -} - #define readArgs(buf, signature, ap) \ for (std::vector::iterator i = signature->args.begin(), \ Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon Jul 7 11:41:26 2008 @@ -96,6 +96,7 @@ JavaField* Classpath::doubleValue; Class* Classpath::newStackTraceElement; +ClassArray* Classpath::stackTraceArray; JavaMethod* Classpath::initStackTraceElement; Class* Classpath::voidClass; @@ -170,7 +171,7 @@ void ClasspathThread::createInitialThread(Jnjvm* vm, JavaObject* th) { vm->loadName(newVMThread->name, newVMThread->classLoader, true, true, true); - JavaObject* vmth = (*newVMThread)(vm); + JavaObject* vmth = newVMThread->doNew(vm); name->setVirtualObjectField(th, (JavaObject*)vm->asciizToStr("main")); priority->setVirtualInt32Field(th, (uint32)1); daemon->setVirtualInt8Field(th, (uint32)0); @@ -188,7 +189,7 @@ void ClasspathThread::mapInitialThread(Jnjvm* vm) { vm->loadName(newThread->name, newThread->classLoader, true, true, true); - JavaObject* th = (*newThread)(vm); + JavaObject* th = newThread->doNew(vm); createInitialThread(vm, th); JavaThread* myth = JavaThread::get(); myth->javaThread = th; @@ -308,6 +309,9 @@ newStackTraceElement = UPCALL_CLASS(vm, "java/lang/StackTraceElement"); + + stackTraceArray = + UPCALL_ARRAY_CLASS(vm, "java/lang/StackTraceElement", 1); initStackTraceElement = UPCALL_METHOD(vm, "java/lang/StackTraceElement", "", Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Mon Jul 7 11:41:26 2008 @@ -108,6 +108,7 @@ static JavaField* doubleValue; static Class* newStackTraceElement; + static ClassArray* stackTraceArray; static JavaMethod* initStackTraceElement; static void initialiseClasspath(Jnjvm* vm); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Jul 7 11:41:26 2008 @@ -215,7 +215,7 @@ for (int i = 0; i < nba; i++) { const UTF8* attName = ctpInfo->UTF8At(reader.readU2()); uint32 attLen = reader.readU4(); - Attribut* att = new Attribut(attName, attLen, reader); + Attribut* att = new Attribut(attName, attLen, reader.cursor); attr.push_back(att); reader.seek(attLen, Reader::SeekCur); } @@ -367,7 +367,7 @@ cl->broadcastClass(); } else if (*status < resolved) { cl->release(); - unknownError("try to clinit a not-readed class..."); + unknownError("try to clinit a not-read class..."); } else { if (!cl->ownerClass()) { while (*status < ready) cl->waitClass(); @@ -387,7 +387,7 @@ cl->release(); } else if (status < loaded) { cl->release(); - unknownError("try to resolve a not-readed class"); + unknownError("try to resolve a not-read class"); } else if (status == loaded || cl->ownerClass()) { if (cl->isArray) { ClassArray* arrayCl = (ClassArray*)cl; @@ -396,7 +396,7 @@ cl->status = resolved; } else { readClass((Class*)cl); - cl->status = readed; + cl->status = classRead; cl->release(); loadParents((Class*)cl); cl->acquire(); @@ -461,7 +461,7 @@ Class* cl = (Class*) this->loadName(this->asciizConstructUTF8(className), CommonClass::jnjvmClassLoader, true, true, true); - JavaObject* obj = (*cl)(this); + JavaObject* obj = cl->doNew(this); JavaJIT::invokeOnceVoid(this, CommonClass::jnjvmClassLoader, className, "", "(Ljava/lang/Throwable;)V", ACC_VIRTUAL, obj, excp); JavaThread::throwException(obj); @@ -477,7 +477,7 @@ vsnprintf(tmp, 4096, fmt, ap); va_end(ap); - JavaObject* obj = (*cl)(this); + JavaObject* obj = cl->doNew(this); JavaJIT::invokeOnceVoid(this, CommonClass::jnjvmClassLoader, className, "", "(Ljava/lang/String;)V", ACC_VIRTUAL, obj, this->asciizToStr(tmp)); @@ -492,7 +492,7 @@ true, true, true); vsnprintf(tmp, 4096, fmt, ap); va_end(ap); - JavaObject* obj = (*cl)(this); + JavaObject* obj = cl->doNew(this); JavaJIT::invokeOnceVoid(this, CommonClass::jnjvmClassLoader, className, "", "(Ljava/lang/String;)V", ACC_VIRTUAL, obj, this->asciizToStr(tmp)); @@ -784,12 +784,12 @@ JavaObject* Jnjvm::getClassDelegatee(CommonClass* cl) { cl->acquire(); if (!(cl->delegatee)) { - JavaObject* delegatee = (*Classpath::newClass)(this); + JavaObject* delegatee = Classpath::newClass->doNew(this); cl->delegatee = delegatee; Classpath::initClass->invokeIntSpecial(this, delegatee, cl); } else if (cl->delegatee->classOf != Classpath::newClass) { JavaObject* pd = cl->delegatee; - JavaObject* delegatee = (*Classpath::newClass)(this); + JavaObject* delegatee = Classpath::newClass->doNew(this); cl->delegatee = delegatee;; Classpath::initClassWithProtectionDomain->invokeIntSpecial(this, delegatee, cl, pd); @@ -802,12 +802,12 @@ cl->acquire(); JavaObject* val = delegatees->lookup(cl); if (!val) { - val = (*Classpath::newClass)(this); + val = Classpath::newClass->doNew(this); delegatees->hash(cl, val); Classpath::initClass->invokeIntSpecial(this, val, cl); } else if (val->classOf != Classpath::newClass) { JavaObject* pd = val; - val = (*Classpath::newClass)(this); + val = Classpath::newClass->doNew(this); delegatees->remove(cl); delegatees->hash(cl, val); Classpath::initClassWithProtectionDomain->invokeIntSpecial(this, val, cl, Modified: vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=53173&r1=53172&r2=53173&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Mon Jul 7 11:41:26 2008 @@ -170,7 +170,7 @@ BranchInst::Create(ifTrue, notEquals, cmp, ifFalse); node->addIncoming(ConstantInt::getTrue(), ifFalse); - if (cl->status < readed) { + if (cl->status < classRead) { std::vector args; args.push_back(objCl); args.push_back(CE); From nicolas.geoffray at lip6.fr Tue Jul 8 03:51:32 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 08 Jul 2008 10:51:32 -0000 Subject: [vmkit-commits] [vmkit] r53232 - in /vmkit/trunk/lib/N3: Mono/Mono.cpp Mono/MonoMSCorlib.cpp PNetLib/PNetMSCorlib.cpp VMCore/VMClass.cpp VMCore/VMClass.h Message-ID: <200807081051.m68ApWIN018034@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 8 05:51:32 2008 New Revision: 53232 URL: http://llvm.org/viewvc/llvm-project?rev=53232&view=rev Log: Fix tye resolution. A virtual table is only allocated during clinit. This makes the string hack trickier. Modified: vmkit/trunk/lib/N3/Mono/Mono.cpp vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp vmkit/trunk/lib/N3/VMCore/VMClass.cpp vmkit/trunk/lib/N3/VMCore/VMClass.h Modified: vmkit/trunk/lib/N3/Mono/Mono.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Mono.cpp?rev=53232&r1=53231&r2=53232&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/Mono.cpp (original) +++ vmkit/trunk/lib/N3/Mono/Mono.cpp Tue Jul 8 05:51:32 2008 @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// - #include "mvm/JIT.h" #include "Assembly.h" +#include "MonoString.h" #include "MSCorlib.h" #include "N3.h" #include "Reader.h" @@ -57,3 +57,13 @@ extern "C" VMObject* System_Type_GetTypeFromHandle(VMCommonClass* cl) { return cl->getClassDelegatee(); } + +extern "C" int System_Environment_get_Platform (void) { +#if defined (PLATFORM_WIN32) + /* Win32NT */ + return 2; +#else + /* Unix */ + return 128; +#endif +} Modified: vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp?rev=53232&r1=53231&r2=53232&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp Tue Jul 8 05:51:32 2008 @@ -25,7 +25,10 @@ vm->asciizConstructUTF8("System"), false, false, false, true); MSCorlib::pString = type; - type->resolveType(false, false); + MSCorlib::pObject->resolveType(true, false); + MSCorlib::pObject->resolveVT(); + type->resolveType(true, false); + type->resolveVT(); uint64 size = mvm::jit::getTypeSize(type->virtualType->getContainedType(0)) + sizeof(const UTF8*) + sizeof(llvm::GlobalVariable*); type->virtualInstance = Modified: vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp?rev=53232&r1=53231&r2=53232&view=diff ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/PNetLib/PNetMSCorlib.cpp Tue Jul 8 05:51:32 2008 @@ -25,7 +25,10 @@ vm->asciizConstructUTF8("System"), false, false, false, true); MSCorlib::pString = type; - type->resolveType(false, false); + MSCorlib::pObject->resolveType(true, false); + MSCorlib::pObject->resolveVT(); + type->resolveType(true, false); + type->resolveVT(); uint64 size = mvm::jit::getTypeSize(type->virtualType->getContainedType(0)) + sizeof(const UTF8*) + sizeof(llvm::GlobalVariable*); type->virtualInstance = Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=53232&r1=53231&r2=53232&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Tue Jul 8 05:51:32 2008 @@ -211,6 +211,7 @@ } cl->status = inClinit; + resolveVT(); std::vector args; args.push_back(MSCorlib::pVoid); VMMethod* meth = cl->lookupMethodDontThrow(N3::clinitName, args, @@ -419,28 +420,18 @@ void VMCommonClass::resolveVT() { VMCommonClass* cl = this; - //printf("*** Resolving: %s\n", cl->printString()); - if (cl->status < vt_resolved) { - cl->aquire(); - int status = cl->status; - if (status >= vt_resolved) { - cl->release(); - } else if (status < loaded) { - cl->release(); - VMThread::get()->vm->unknownError("try to vt-resolve a not-resolved class"); - } else if (status == virtual_resolved) { if (cl->isArray) { VMClassArray* arrayCl = (VMClassArray*)cl; arrayCl->baseClass->resolveVT(); arrayCl->arrayVT = CLIJit::makeArrayVT(arrayCl); - cl->status = vt_resolved; } else if (cl->isPointer) { - cl->status = vt_resolved; } else { VMClass* cl = (VMClass*)this; if (super) super->resolveVT(); - if (super != MSCorlib::pEnum) { + // We check for virtual instance because the string class has a + // bigger size than the class declares. + if (super != MSCorlib::pEnum && !cl->virtualInstance) { VirtualTable* VT = CLIJit::makeVT(cl, false); uint64 size = mvm::jit::getTypeSize(cl->virtualType->getContainedType(0)); @@ -453,23 +444,11 @@ (*i)->initField(cl->virtualInstance); } } - cl->status = vt_resolved; } - cl->release(); - } else { - if (!(cl->ownerClass())) { - while (status < vt_resolved) { - cl->waitClass(); - } - } - cl->release(); - } - } } void VMCommonClass::resolveType(bool stat, bool clinit) { resolveVirtual(); - resolveVT(); if (stat) resolveStatic(clinit); } @@ -480,10 +459,10 @@ int status = cl->status; if (status >= static_resolved) { cl->release(); - } else if (status < vt_resolved) { + } else if (status < virtual_resolved) { cl->release(); VMThread::get()->vm->unknownError("try to resolve static of a not virtual-resolved class"); - } else if (status == vt_resolved) { + } else if (status == virtual_resolved) { if (cl->isArray) { VMClassArray* arrayCl = (VMClassArray*)cl; VMCommonClass* baseClass = arrayCl->baseClass; Modified: vmkit/trunk/lib/N3/VMCore/VMClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.h?rev=53232&r1=53231&r2=53232&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.h Tue Jul 8 05:51:32 2008 @@ -37,7 +37,7 @@ class VMObject; typedef enum VMClassState { - hashed = 0, loaded, prepared, readed, virtual_resolved, vt_resolved, static_resolved, clinitParent, inClinit, ready + hashed = 0, loaded, prepared, readed, virtual_resolved, static_resolved, clinitParent, inClinit, ready }VMClassState; From nicolas.geoffray at lip6.fr Sat Jul 12 02:39:08 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:39:08 -0000 Subject: [vmkit-commits] [vmkit] r53510 - in /vmkit/trunk/lib/N3/VMCore: CLIJit.cpp CLIJit.h Opcodes.cpp Message-ID: <200807120939.m6C9d8k8026644@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:39:07 2008 New Revision: 53510 URL: http://llvm.org/viewvc/llvm-project?rev=53510&view=rev Log: Implement volatile. and switch opcodes. Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp vmkit/trunk/lib/N3/VMCore/CLIJit.h vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=53510&r1=53509&r2=53510&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Jul 12 04:39:07 2008 @@ -717,7 +717,7 @@ } -void CLIJit::setVirtualField(uint32 value) { +void CLIJit::setVirtualField(uint32 value, bool isVolatile) { VMField* field = compilingClass->assembly->getFieldFromToken(value, false); Value* val = pop(); Value* obj = pop(); @@ -749,10 +749,10 @@ val = changeType(val, type); } - new StoreInst(val, ptr, false, currentBlock); + new StoreInst(val, ptr, isVolatile, currentBlock); } -void CLIJit::setStaticField(uint32 value) { +void CLIJit::setStaticField(uint32 value, bool isVolatile) { VMField* field = compilingClass->assembly->getFieldFromToken(value, true); VMCommonClass* cl = field->classDef; @@ -773,7 +773,7 @@ } else if (type != valType) { val = changeType(val, type); } - new StoreInst(val, ptr, false, currentBlock); + new StoreInst(val, ptr, isVolatile, currentBlock); } void CLIJit::JITVerifyNull(Value* obj) { Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.h?rev=53510&r1=53509&r2=53510&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.h (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.h Sat Jul 12 04:39:07 2008 @@ -131,8 +131,8 @@ void invokeNew(uint32 value); llvm::Value* getVirtualField(uint32 value); llvm::Value* getStaticField(uint32 value); - void setVirtualField(uint32 value); - void setStaticField(uint32 value); + void setVirtualField(uint32 value, bool isVolatile); + void setStaticField(uint32 value, bool isVolatile); void JITVerifyNull(llvm::Value* obj); Modified: vmkit/trunk/lib/N3/VMCore/Opcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Opcodes.cpp?rev=53510&r1=53509&r2=53510&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Opcodes.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Sat Jul 12 04:39:07 2008 @@ -7,34 +7,23 @@ // //===----------------------------------------------------------------------===// -//#define DEBUG 0 -//#define N3_COMPILE 0 -//#define N3_EXECUTE 0 +#define DEBUG 0 +#define N3_COMPILE 0 +#define N3_EXECUTE 0 #include -#include -#include #include -#include #include +#include +#include #include #include -#include -#include -#include #include -#include +#include #include #include -#include #include -#include -#include -#include <../lib/ExecutionEngine/JIT/JIT.h> - -#include - #include "mvm/JIT.h" #include "mvm/Method.h" @@ -54,10 +43,6 @@ #include "OpcodeNames.def" -#include - - - using namespace n3; using namespace llvm; @@ -148,6 +133,9 @@ } else if (t1->isInteger() && t2 == PointerType::getUnqual(Type::Int8Ty)) { // CLI says that this is fine for some operation val2 = new PtrToIntInst(val2, t1, "", currentBlock); + } else if (t2->isInteger() && t1 == PointerType::getUnqual(Type::Int8Ty)) { + // CLI says that this is fine for some operation + val1 = new PtrToIntInst(val1, t2, "", currentBlock); } } } @@ -181,7 +169,7 @@ convertValue(val, contained, currentBlock); } new StoreInst(val, local, vol, currentBlock); - } else { + } else if (isa(val->getType())) { uint64 size = mvm::jit::getTypeSize(contained); std::vector params; @@ -190,6 +178,8 @@ params.push_back(ConstantInt::get(Type::Int32Ty, size)); params.push_back(mvm::jit::constantZero); CallInst::Create(mvm::jit::llvm_memcpy_i32, params.begin(), params.end(), "", currentBlock); + } else { + new StoreInst(val, local, vol, currentBlock); } } @@ -212,10 +202,11 @@ void CLIJit::compileOpcodes(uint8* bytecodes, uint32 codeLength) { uint32 leaveIndex = 0; + bool isVolatile = false; for(uint32 i = 0; i < codeLength; ++i) { if (bytecodes[i] != 0xFE) { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5d] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %x] %-5d ", i, bytecodes[i]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "compiling %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNames[bytecodes[i]]); @@ -235,15 +226,16 @@ } #if N3_EXECUTE > 1 - std::vector args; - args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)OpcodeNames[bytecodes[i]])); - args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)compilingMethod)); - CallInst::Create(printExecutionLLVM, args.begin(), args.end(), "", currentBlock); if (bytecodes[i] == 0xFE) { std::vector args; args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)OpcodeNamesFE[bytecodes[i + 1]])); args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)compilingMethod)); CallInst::Create(printExecutionLLVM, args.begin(), args.end(), "", currentBlock); + } else { + std::vector args; + args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)OpcodeNames[bytecodes[i]])); + args.push_back(ConstantInt::get(Type::Int32Ty, (int64_t)compilingMethod)); + CallInst::Create(printExecutionLLVM, args.begin(), args.end(), "", currentBlock); } #endif @@ -528,10 +520,20 @@ case CONV_I : { Value* val = pop(); - if (val->getType() != Type::Int64Ty) - val = new ZExtInst(val, Type::Int64Ty, "", currentBlock); - push(new IntToPtrInst(val, PointerType::getUnqual(Type::Int8Ty), "", - currentBlock)); + Value* res = 0; + + if (val->getType()->isInteger()) { + if (val->getType() != Type::Int64Ty) { + val = new ZExtInst(val, Type::Int64Ty, "", currentBlock); + } + res = new IntToPtrInst(val, PointerType::getUnqual(Type::Int8Ty), "", currentBlock); + } else if (!val->getType()->isFloatingPoint()) { + res = new BitCastInst(val, PointerType::getUnqual(Type::Int8Ty), "", currentBlock); + } else { + VMThread::get()->vm->unknownError("implement me"); + } + + push(res); break; } @@ -817,7 +819,8 @@ case LDIND_I1 : { Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::Int8Ty), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -825,36 +828,45 @@ case LDIND_I2 : { Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::Int16Ty), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } case LDIND_U4 : case LDIND_I4 : { - Value* _val = pop(); - Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::Int32Ty), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + Value* val = pop(); + if (val->getType()->isInteger()) { + val = new IntToPtrInst(val, PointerType::getUnqual(Type::Int32Ty), "", currentBlock); + } else { + val = new BitCastInst(val, PointerType::getUnqual(Type::Int32Ty), "", currentBlock); + } + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } case LDIND_I8 : { Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::Int64Ty), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } case LDIND_R4 : { Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::FloatTy), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } case LDIND_R8 : { Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual(Type::DoubleTy), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -862,7 +874,8 @@ Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual( PointerType::getUnqual(Type::Int8Ty)), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -870,7 +883,8 @@ Value* _val = pop(); Value* val = new BitCastInst(_val, PointerType::getUnqual( PointerType::getUnqual(VMObject::llvmType)), "", currentBlock); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -1101,7 +1115,8 @@ Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::Int8Ty), "", currentBlock); convertValue(val, Type::Int8Ty, currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1110,7 +1125,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::Int16Ty), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1119,7 +1135,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::Int32Ty), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1128,7 +1145,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::Int64Ty), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1137,7 +1155,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::FloatTy), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1146,7 +1165,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::DoubleTy), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1155,7 +1175,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(Type::Int32Ty), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1164,7 +1185,8 @@ Value* _addr = pop(); Value* addr = new BitCastInst(_addr, PointerType::getUnqual(val->getType()), "", currentBlock); - new StoreInst(val, addr, false, currentBlock); + new StoreInst(val, addr, isVolatile, currentBlock); + isVolatile = false; break; } @@ -1222,7 +1244,18 @@ } case SWITCH : { - VMThread::get()->vm->error("implement me"); + uint32 value = readU4(bytecodes, i); + Value* val = pop(); + uint32 next = i + value * sizeof(sint32) + 1; + BasicBlock* defBB = opcodeInfos[next].newBlock; + SwitchInst* SI = SwitchInst::Create(val, defBB, value, currentBlock); + for (uint32 t = 0; t < value; t++) { + sint32 offset = readS4(bytecodes, i); + sint32 index = next + offset; + assert(index > 0); + BasicBlock* BB = opcodeInfos[index].newBlock; + SI->addCase(ConstantInt::get(Type::Int32Ty, t), BB); + } break; } @@ -1489,7 +1522,8 @@ case LDFLD : { uint32 value = readU4(bytecodes, i); Value* val = getVirtualField(value); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -1511,7 +1545,8 @@ VMCommonClass* cl = assembly->loadType(vm, token, true, false, false, true); if (!(cl->super == MSCorlib::pValue || cl->super == MSCorlib::pEnum)) { - push(new LoadInst(pop(), "", currentBlock)); + push(new LoadInst(pop(), "", isVolatile, currentBlock)); + isVolatile = false; } break; } @@ -1519,7 +1554,8 @@ case LDSFLD : { uint32 value = readU4(bytecodes, i); Value* val = getStaticField(value); - push(new LoadInst(val, "", currentBlock)); + push(new LoadInst(val, "", isVolatile, currentBlock)); + isVolatile = false; break; } @@ -1707,18 +1743,21 @@ case STFLD : { uint32 index = readU4(bytecodes, i); - setVirtualField(index); + setVirtualField(index, isVolatile); + isVolatile = false; break; } case STOBJ : { VMThread::get()->vm->error("implement me"); + isVolatile = false; break; } case STSFLD : { uint32 index = readU4(bytecodes, i); - setStaticField(index); + setStaticField(index, isVolatile); + isVolatile = false; break; } @@ -1777,7 +1816,7 @@ } case 0xFE : { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5d] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %x] %-5d ", i, bytecodes[i + 1]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "compiling %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNamesFE[bytecodes[i + 1]]); @@ -1817,6 +1856,7 @@ args.push_back(three); CallInst::Create(mvm::jit::llvm_memcpy_i32, args.begin(), args.end(), "", currentBlock); + isVolatile = false; break; } @@ -1863,6 +1903,7 @@ args.push_back(three); CallInst::Create(mvm::jit::llvm_memset_i32, args.begin(), args.end(), "", currentBlock); + isVolatile = false; break; } @@ -1933,6 +1974,11 @@ VMThread::get()->vm->error("implement me"); break; } + + case VOLATILE_ : { + isVolatile = true; + break; + } default : VMThread::get()->vm->unknownError("unknown bytecode"); } @@ -2224,7 +2270,21 @@ case SUB_OVF_UN : break; case SWITCH : { - VMThread::get()->vm->error("implement me"); + uint32 value = readU4(bytecodes, i); + uint32 next = i + value * sizeof(sint32) + 1; + for (uint32 t = 0; t < value; t++) { + sint32 offset = readS4(bytecodes, i); + sint32 index = next + offset; + assert(index > 0); + if (!(opcodeInfos[index].newBlock)) { + BasicBlock* block = createBasicBlock("switch"); + opcodeInfos[index].newBlock = block; + } + } + if (!(opcodeInfos[i + 1].newBlock)) { + BasicBlock* block = createBasicBlock("switch"); + opcodeInfos[i + 1].newBlock = block; + } break; } @@ -2381,7 +2441,7 @@ PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5d] %-5d ", i, bytecodes[i + 1]); - PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "exploring "); + PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "exploring %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNamesFE[bytecodes[i + 1]]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "\n"); @@ -2466,6 +2526,10 @@ VMThread::get()->vm->error("implement me"); break; } + + case VOLATILE_ : { + break; + } default : VMThread::get()->vm->unknownError("unknown bytecode"); } From nicolas.geoffray at lip6.fr Sat Jul 12 02:43:56 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:43:56 -0000 Subject: [vmkit-commits] [vmkit] r53511 - /vmkit/trunk/lib/N3/VMCore/Assembly.cpp Message-ID: <200807120943.m6C9hui2026805@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:43:56 2008 New Revision: 53511 URL: http://llvm.org/viewvc/llvm-project?rev=53511&view=rev Log: Resolve static type if looking for a static field. Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=53511&r1=53510&r2=53511&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Jul 12 04:43:56 2008 @@ -1483,7 +1483,7 @@ } } } - field->classDef->resolveType(false, false); + field->classDef->resolveType(stat, false); return field; } From nicolas.geoffray at lip6.fr Sat Jul 12 02:45:05 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:45:05 -0000 Subject: [vmkit-commits] [vmkit] r53512 - /vmkit/trunk/lib/N3/VMCore/N3.cpp Message-ID: <200807120945.m6C9j5ji026840@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:45:04 2008 New Revision: 53512 URL: http://llvm.org/viewvc/llvm-project?rev=53512&view=rev Log: More verbose information if N3 had an unknown exception. Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=53512&r1=53511&r2=53512&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3.cpp Sat Jul 12 04:45:04 2008 @@ -265,7 +265,8 @@ try{ executeAssembly(info.assembly, args); }catch(...) { - printf("N3 catched it\n"); + VMObject* exc = VMThread::get()->pendingException; + printf("N3 caught %s\n", exc->printString()); } waitForExit(); } From nicolas.geoffray at lip6.fr Sat Jul 12 02:47:18 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:47:18 -0000 Subject: [vmkit-commits] [vmkit] r53513 - in /vmkit/trunk/lib/N3: Mono/Makefile Mono/Mono.cpp Mono/MonoMSCorlib.cpp PNetLib/PNetLib.cpp VMCore/MSCorlib.cpp VMCore/N3Initialise.cpp VMCore/NativeUtil.h Message-ID: <200807120947.m6C9lIP4026915@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:47:18 2008 New Revision: 53513 URL: http://llvm.org/viewvc/llvm-project?rev=53513&view=rev Log: Improve Mono support (It now prints Hello World!), and move shared mscorlib functions into VMCore/MSCorlib.cpp. Also remove initializing NativeUtil for faking the linker, as with the new build system this is not required anymore. Added: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Modified: vmkit/trunk/lib/N3/Mono/Makefile vmkit/trunk/lib/N3/Mono/Mono.cpp vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp vmkit/trunk/lib/N3/VMCore/NativeUtil.h Modified: vmkit/trunk/lib/N3/Mono/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Makefile?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/Makefile (original) +++ vmkit/trunk/lib/N3/Mono/Makefile Sat Jul 12 04:47:18 2008 @@ -11,3 +11,6 @@ LIBRARYNAME = Mono include $(LEVEL)/Makefile.common CXX.Flags += -I../VMCore + +CXX.Flags += `pkg-config --cflags glib-2.0 gthread-2.0` +CXX.Flags += `pkg-config --cflags gmodule-2.0` Modified: vmkit/trunk/lib/N3/Mono/Mono.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Mono.cpp?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/Mono.cpp (original) +++ vmkit/trunk/lib/N3/Mono/Mono.cpp Sat Jul 12 04:47:18 2008 @@ -19,51 +19,234 @@ #include "VMObject.h" #include "VMThread.h" +#include + +#include "number-formatter.h" + using namespace n3; -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" int System_Environment_get_Platform (void) { +#if defined (PLATFORM_WIN32) + /* Win32NT */ + return 2; +#else + /* Unix */ + return 128; +#endif } -extern "C" VMObject* System_Type_GetTypeFromHandle(VMCommonClass* cl) { - return cl->getClassDelegatee(); +static const char *encodings [] = { + (char *) 1, + "ascii", "us_ascii", "us", "ansi_x3.4_1968", + "ansi_x3.4_1986", "cp367", "csascii", "ibm367", + "iso_ir_6", "iso646_us", "iso_646.irv:1991", + (char *) 2, + "utf_7", "csunicode11utf7", "unicode_1_1_utf_7", + "unicode_2_0_utf_7", "x_unicode_1_1_utf_7", + "x_unicode_2_0_utf_7", + (char *) 3, + "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8", + "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8", + (char *) 4, + "utf_16", "UTF_16LE", "ucs_2", "unicode", + "iso_10646_ucs2", + (char *) 5, + "unicodefffe", "utf_16be", + (char *) 6, + "iso_8859_1", + (char *) 0 +}; + +/* + * Returns the internal codepage, if the value of "int_code_page" is + * 1 at entry, and we can not compute a suitable code page number, + * returns the code page as a string + */ +extern "C" MonoString* +System_Text_Encoding_InternalCodePage (gint32 *int_code_page) +{ + const char *cset; + const char *p; + char *c; + char *codepage = NULL; + int code; + int want_name = *int_code_page; + int i; + + *int_code_page = -1; + + g_get_charset (&cset); + c = codepage = strdup (cset); + for (c = codepage; *c; c++){ + if (isascii (*c) && isalpha (*c)) + *c = tolower (*c); + if (*c == '-') + *c = '_'; + } + /* g_print ("charset: %s\n", cset); */ + + /* handle some common aliases */ + p = encodings [0]; + code = 0; + for (i = 0; p != 0; ){ + if ((gssize) p < 7){ + code = (gssize) p; + p = encodings [++i]; + continue; + } + if (strcmp (p, codepage) == 0){ + *int_code_page = code; + break; + } + p = encodings [++i]; + } + + if (strstr (codepage, "utf_8") != NULL) + *int_code_page |= 0x10000000; + free (codepage); + + if (want_name && *int_code_page == -1) + return (MonoString*)(((N3*)VMThread::get()->vm)->asciizToStr(cset)); + else + return NULL; } -extern "C" int System_Environment_get_Platform (void) { +extern "C" void System_Threading_Monitor_Monitor_exit(VMObject* obj) { + obj->unlock(); +} + +extern "C" bool System_Threading_Monitor_Monitor_try_enter(VMObject* obj, int ms) { + obj->aquire(); + return true; +} + + +extern "C" void* System_IO_MonoIO_get_ConsoleError() { + return (void*)stderr; +} + +extern "C" void* System_IO_MonoIO_get_ConsoleOutput() { + return (void*)stdout; +} + +extern "C" void* System_IO_MonoIO_get_ConsoleInput() { + return (void*)stdin; +} + +enum MonoFileType { + Unknown=0x0000, + Disk=0x0001, + Char=0x0002, + Pipe=0x0003, + Remote=0x8000 +}; + +extern "C" MonoFileType System_IO_MonoIO_GetFileType(void* handle, int* error) { + if (handle == (void*)stdin || handle == (void*)stdout || handle == (void*)stderr) + return Char; + else + return Unknown; +} + +extern "C" MonoString * +System_Environment_get_NewLine (void) +{ #if defined (PLATFORM_WIN32) - /* Win32NT */ - return 2; + return (MonoString*)((N3*)VMThread::get()->vm)->asciizToStr("\r\n"); #else - /* Unix */ - return 128; + return (MonoString*)((N3*)VMThread::get()->vm)->asciizToStr("\n"); #endif } + +extern "C" void +System_String_InternalCopyTo(MonoString* str, sint32 sindex, VMArray* dest, sint32 destIndex, sint32 count) { + const UTF8* contents = str->value; + memcpy(&dest->elements[destIndex], &contents->elements[sindex], count * sizeof(uint16)); +} + +extern "C" uint16 System_String_get_Chars(MonoString* str, sint32 offset) { + return str->value->elements[offset]; +} + +static sint32 byteLength(VMArray* array) { + VMClassArray* cl = (VMClassArray*)array->classOf; + VMCommonClass* base = cl->baseClass; + uint32 size = base->naturalType->getPrimitiveSizeInBits() / 8; + return array->size * size; +} + +extern "C" bool System_Buffer_BlockCopyInternal (VMArray* src, int src_offset, VMArray* dest, int dest_offset, int count) { + uint8 *src_buf, *dest_buf; + + /* watch out for integer overflow */ + if ((src_offset > byteLength(src) - count) || (dest_offset > byteLength(dest) - count)) + return false; + + src_buf = (uint8 *)src->elements + src_offset; + dest_buf = (uint8 *)dest->elements + dest_offset; + + if (src != dest) + memcpy (dest_buf, src_buf, count); + else + memmove (dest_buf, src_buf, count); /* Source and dest are the same array */ + + return true; + +} + +extern "C" sint32 System_Buffer_ByteLengthInternal(VMArray* array) { + return byteLength(array); +} + +extern "C" sint32 +System_IO_MonoIO_Write (void* handle, ArrayUInt8 *src, + sint32 src_offset, sint32 count, + sint32 *error) +{ + char* buffer = (char*)alloca( 1024);//(count + 8) * sizeof(uint16)); + uint32 n = 0; + + *error = 0; + + if (src_offset + count > src->size) + return 0; + + memcpy(buffer, (char*)&(src->elements[src_offset]), count); + buffer[count] = 0; + n = fprintf((FILE*)handle, buffer); + + return (sint32)n; +} + +/* These parameters are "readonly" in corlib/System/NumberFormatter.cs */ +extern "C" void +System_NumberFormatter_GetFormatterTables (guint64 const **mantissas, + gint32 const **exponents, + gunichar2 const **digitLowerTable, + gunichar2 const **digitUpperTable, + gint64 const **tenPowersList, + gint32 const **decHexDigits) +{ + *mantissas = Formatter_MantissaBitsTable; + *exponents = Formatter_TensExponentTable; + *digitLowerTable = Formatter_DigitLowerTable; + *digitUpperTable = Formatter_DigitUpperTable; + *tenPowersList = Formatter_TenPowersList; + *decHexDigits = Formatter_DecHexDigits; +} + +extern "C" VMObject* System_Threading_Thread_CurrentThread_internal() { + return VMThread::get()->vmThread; +} + +extern "C" VMObject* +System_Threading_Thread_GetCachedCurrentCulture (VMObject *obj) +{ + return 0; +} + +extern "C" VMObject* +System_Threading_Thread_GetSerializedCurrentCulture (VMObject *obj) +{ + return 0; +} Modified: vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/Mono/MonoMSCorlib.cpp Sat Jul 12 04:47:18 2008 @@ -132,9 +132,6 @@ */ } -#include "NativeUtil.h" -void NativeUtil::initialise() { -} VMObject* Property::getPropertyDelegatee() { if (!delegatee) { @@ -166,4 +163,12 @@ } void MSCorlib::loadBootstrap(N3* vm) { + VMClass* cl = (VMClass*)vm->coreAssembly->loadTypeFromName( + vm->asciizConstructUTF8("Thread"), + vm->asciizConstructUTF8("System.Threading"), + true, true, true, true); + VMObject* th = (*cl)(); + VMThread* myth = VMThread::get(); + myth->vmThread = th; + } Modified: vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp (original) +++ vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp Sat Jul 12 04:47:18 2008 @@ -132,67 +132,10 @@ -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(); } @@ -210,10 +153,6 @@ } } -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; @@ -287,97 +226,6 @@ _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) { @@ -436,12 +284,17 @@ } } -extern "C" bool System_String_Equals(PNetString* str1, PNetString* str2) { - return str1->value == str2->value; +extern "C" void System_Threading_Monitor_Enter(VMObject* obj) { + obj->aquire(); } -extern "C" VMObject* System_Threading_Thread_InternalCurrentThread() { - return VMThread::get()->vmThread; +extern "C" void System_Threading_Monitor_Exit(VMObject* obj) { + obj->unlock(); +} + + +extern "C" bool System_String_Equals(PNetString* str1, PNetString* str2) { + return str1->value == str2->value; } extern "C" sint32 Platform_SysCharInfo_GetUnicodeCategory(char c) { @@ -481,19 +334,6 @@ 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, @@ -1194,17 +1034,6 @@ } } -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; +extern "C" VMObject* System_Threading_Thread_InternalCurrentThread() { + return VMThread::get()->vmThread; } Added: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp?rev=53513&view=auto ============================================================================== --- vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp (added) +++ vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Sat Jul 12 04:47:18 2008 @@ -0,0 +1,200 @@ +//===------------- MSCorlib.cpp - mscorlib interface ----------------------===// +// +// N3 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +#include +#include + +#include "mvm/JIT.h" + +#include "Assembly.h" +#include "CLIAccess.h" +#include "CLIJit.h" +#include "NativeUtil.h" +#include "MSCorlib.h" +#include "N3.h" +#include "Reader.h" +#include "VMArray.h" +#include "VMClass.h" +#include "VMObject.h" +#include "VMThread.h" + +using namespace n3; + +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" 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" void System_Reflection_Assembly_LoadFromFile() { + VMThread::get()->vm->error("implement me"); +} + +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" 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" void System_GC_Collect() { +#ifdef MULTIPLE_GC + mvm::Thread::get()->GC->collect(); +#else + Collector::collect(); +#endif +} + +extern "C" void System_GC_SuppressFinalize(VMObject* obj) { + // TODO: implement me +} + Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Sat Jul 12 04:47:18 2008 @@ -219,7 +219,6 @@ static void initialiseStatics() { - NativeUtil::initialise(); CLIJit::initialise(); VMObject::globalLock = mvm::Lock::allocNormal(); Modified: vmkit/trunk/lib/N3/VMCore/NativeUtil.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/NativeUtil.h?rev=53513&r1=53512&r2=53513&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/NativeUtil.h (original) +++ vmkit/trunk/lib/N3/VMCore/NativeUtil.h Sat Jul 12 04:47:18 2008 @@ -19,7 +19,6 @@ public: static void* nativeLookup(VMCommonClass* cl, VMMethod* meth); - static void initialise(); }; } From nicolas.geoffray at lip6.fr Sat Jul 12 02:49:43 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:49:43 -0000 Subject: [vmkit-commits] [vmkit] r53515 - /vmkit/trunk/tools/n3-mono/Makefile Message-ID: <200807120949.m6C9nhOB026997@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:49:43 2008 New Revision: 53515 URL: http://llvm.org/viewvc/llvm-project?rev=53515&view=rev Log: Add glib libraries for the linker. Modified: vmkit/trunk/tools/n3-mono/Makefile Modified: vmkit/trunk/tools/n3-mono/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Makefile?rev=53515&r1=53514&r2=53515&view=diff ============================================================================== --- vmkit/trunk/tools/n3-mono/Makefile (original) +++ vmkit/trunk/tools/n3-mono/Makefile Sat Jul 12 04:49:43 2008 @@ -15,3 +15,9 @@ USEDLIBS = Allocator CommonThread Mvm N3 Main $(GCLIB) Mono include $(LEVEL)/Makefile.common + +CXX.Flags += `pkg-config --cflags glib-2.0 gthread-2.0` +LIBS += `pkg-config --libs glib-2.0 gthread-2.0` +CXX.Flags += `pkg-config --cflags gmodule-2.0` +LIBS += `pkg-config --libs gmodule-2.0` + From nicolas.geoffray at lip6.fr Sat Jul 12 02:54:58 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 12 Jul 2008 09:54:58 -0000 Subject: [vmkit-commits] [vmkit] r53516 - /vmkit/trunk/lib/N3/Mono/number-formatter.h Message-ID: <200807120954.m6C9sxnG027142@zion.cs.uiuc.edu> Author: geoffray Date: Sat Jul 12 04:54:58 2008 New Revision: 53516 URL: http://llvm.org/viewvc/llvm-project?rev=53516&view=rev Log: Add the number-fromatter.h file of Mono. This file is under the Mono license. Added: vmkit/trunk/lib/N3/Mono/number-formatter.h Added: vmkit/trunk/lib/N3/Mono/number-formatter.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/number-formatter.h?rev=53516&view=auto ============================================================================== --- vmkit/trunk/lib/N3/Mono/number-formatter.h (added) +++ vmkit/trunk/lib/N3/Mono/number-formatter.h Sat Jul 12 04:54:58 2008 @@ -0,0 +1,914 @@ +/* + * This file is under the Mono License. + * (C) 2008 Ximian, Inc. http://www.ximian.com + */ + +#ifndef _MONO_METADATA_NUMBER_FORMATTER_H_ +#define _MONO_METADATA_NUMBER_FORMATTER_H_ 1 + +static const guint64 Formatter_MantissaBitsTable [] = { + 4556951262222748432ULL, 9113902524445496865ULL, 18227805048890993730ULL, + 3645561009778198746ULL, 7291122019556397492ULL, 14582244039112794984ULL, + 2916448807822558996ULL, 5832897615645117993ULL, 11665795231290235987ULL, + 2333159046258047197ULL, 4666318092516094394ULL, 9332636185032188789ULL, + 1866527237006437757ULL, 3733054474012875515ULL, 7466108948025751031ULL, + 14932217896051502063ULL, 2986443579210300412ULL, 5972887158420600825ULL, + 11945774316841201651ULL, 2389154863368240330ULL, 4778309726736480660ULL, + 9556619453472961320ULL, 1911323890694592264ULL, 3822647781389184528ULL, + 7645295562778369056ULL, 15290591125556738113ULL, 3058118225111347622ULL, + 6116236450222695245ULL, 12232472900445390490ULL, 2446494580089078098ULL, + 4892989160178156196ULL, 9785978320356312392ULL, 1957195664071262478ULL, + 3914391328142524957ULL, 7828782656285049914ULL, 15657565312570099828ULL, + 3131513062514019965ULL, 6263026125028039931ULL, 12526052250056079862ULL, + 2505210450011215972ULL, 5010420900022431944ULL, 10020841800044863889ULL, + 2004168360008972777ULL, 4008336720017945555ULL, 8016673440035891111ULL, + 16033346880071782223ULL, 3206669376014356444ULL, 6413338752028712889ULL, + 12826677504057425779ULL, 2565335500811485155ULL, 5130671001622970311ULL, + 10261342003245940623ULL, 2052268400649188124ULL, 4104536801298376249ULL, + 8209073602596752498ULL, 16418147205193504997ULL, 3283629441038700999ULL, + 6567258882077401998ULL, 13134517764154803997ULL, 2626903552830960799ULL, + 5253807105661921599ULL, 10507614211323843198ULL, 2101522842264768639ULL, + 4203045684529537279ULL, 8406091369059074558ULL, 16812182738118149117ULL, + 3362436547623629823ULL, 6724873095247259646ULL, 13449746190494519293ULL, + 2689949238098903858ULL, 5379898476197807717ULL, 10759796952395615435ULL, + 2151959390479123087ULL, 4303918780958246174ULL, 8607837561916492348ULL, + 17215675123832984696ULL, 3443135024766596939ULL, 6886270049533193878ULL, + 13772540099066387756ULL, 2754508019813277551ULL, 5509016039626555102ULL, + 11018032079253110205ULL, 2203606415850622041ULL, 4407212831701244082ULL, + 8814425663402488164ULL, 17628851326804976328ULL, 3525770265360995265ULL, + 7051540530721990531ULL, 14103081061443981063ULL, 2820616212288796212ULL, + 5641232424577592425ULL, 11282464849155184850ULL, 2256492969831036970ULL, + 4512985939662073940ULL, 9025971879324147880ULL, 18051943758648295760ULL, + 3610388751729659152ULL, 7220777503459318304ULL, 14441555006918636608ULL, + 2888311001383727321ULL, 5776622002767454643ULL, 11553244005534909286ULL, + 2310648801106981857ULL, 4621297602213963714ULL, 9242595204427927429ULL, + 1848519040885585485ULL, 3697038081771170971ULL, 7394076163542341943ULL, + 14788152327084683887ULL, 2957630465416936777ULL, 5915260930833873554ULL, + 11830521861667747109ULL, 2366104372333549421ULL, 4732208744667098843ULL, + 9464417489334197687ULL, 1892883497866839537ULL, 3785766995733679075ULL, + 7571533991467358150ULL, 15143067982934716300ULL, 3028613596586943260ULL, + 6057227193173886520ULL, 12114454386347773040ULL, 2422890877269554608ULL, + 4845781754539109216ULL, 9691563509078218432ULL, 1938312701815643686ULL, + 3876625403631287372ULL, 7753250807262574745ULL, 15506501614525149491ULL, + 3101300322905029898ULL, 6202600645810059796ULL, 12405201291620119593ULL, + 2481040258324023918ULL, 4962080516648047837ULL, 9924161033296095674ULL, + 1984832206659219134ULL, 3969664413318438269ULL, 7939328826636876539ULL, + 15878657653273753079ULL, 3175731530654750615ULL, 6351463061309501231ULL, + 12702926122619002463ULL, 2540585224523800492ULL, 5081170449047600985ULL, + 10162340898095201970ULL, 2032468179619040394ULL, 4064936359238080788ULL, + 8129872718476161576ULL, 16259745436952323153ULL, 3251949087390464630ULL, + 6503898174780929261ULL, 13007796349561858522ULL, 2601559269912371704ULL, + 5203118539824743409ULL, 10406237079649486818ULL, 2081247415929897363ULL, + 4162494831859794727ULL, 8324989663719589454ULL, 16649979327439178909ULL, + 3329995865487835781ULL, 6659991730975671563ULL, 13319983461951343127ULL, + 2663996692390268625ULL, 5327993384780537250ULL, 10655986769561074501ULL, + 2131197353912214900ULL, 4262394707824429800ULL, 8524789415648859601ULL, + 17049578831297719202ULL, 3409915766259543840ULL, 6819831532519087681ULL, + 13639663065038175362ULL, 2727932613007635072ULL, 5455865226015270144ULL, + 10911730452030540289ULL, 2182346090406108057ULL, 4364692180812216115ULL, + 8729384361624432231ULL, 17458768723248864463ULL, 3491753744649772892ULL, + 6983507489299545785ULL, 13967014978599091570ULL, 2793402995719818314ULL, + 5586805991439636628ULL, 11173611982879273256ULL, 2234722396575854651ULL, + 4469444793151709302ULL, 8938889586303418605ULL, 17877779172606837210ULL, + 3575555834521367442ULL, 7151111669042734884ULL, 14302223338085469768ULL, + 2860444667617093953ULL, 5720889335234187907ULL, 11441778670468375814ULL, + 2288355734093675162ULL, 4576711468187350325ULL, 9153422936374700651ULL, + 18306845872749401303ULL, 3661369174549880260ULL, 7322738349099760521ULL, + 14645476698199521043ULL, 2929095339639904208ULL, 5858190679279808417ULL, + 11716381358559616834ULL, 2343276271711923366ULL, 4686552543423846733ULL, + 9373105086847693467ULL, 1874621017369538693ULL, 3749242034739077387ULL, + 7498484069478154774ULL, 14996968138956309548ULL, 2999393627791261909ULL, + 5998787255582523819ULL, 11997574511165047638ULL, 2399514902233009527ULL, + 4799029804466019055ULL, 9598059608932038110ULL, 1919611921786407622ULL, + 3839223843572815244ULL, 7678447687145630488ULL, 15356895374291260977ULL, + 3071379074858252195ULL, 6142758149716504390ULL, 12285516299433008781ULL, + 2457103259886601756ULL, 4914206519773203512ULL, 9828413039546407025ULL, + 1965682607909281405ULL, 3931365215818562810ULL, 7862730431637125620ULL, + 15725460863274251240ULL, 3145092172654850248ULL, 6290184345309700496ULL, + 12580368690619400992ULL, 2516073738123880198ULL, 5032147476247760397ULL, + 10064294952495520794ULL, 2012858990499104158ULL, 4025717980998208317ULL, + 8051435961996416635ULL, 16102871923992833270ULL, 3220574384798566654ULL, + 6441148769597133308ULL, 12882297539194266616ULL, 2576459507838853323ULL, + 5152919015677706646ULL, 10305838031355413293ULL, 2061167606271082658ULL, + 4122335212542165317ULL, 8244670425084330634ULL, 16489340850168661269ULL, + 3297868170033732253ULL, 6595736340067464507ULL, 13191472680134929015ULL, + 2638294536026985803ULL, 5276589072053971606ULL, 10553178144107943212ULL, + 2110635628821588642ULL, 4221271257643177284ULL, 8442542515286354569ULL, + 16885085030572709139ULL, 3377017006114541827ULL, 6754034012229083655ULL, + 13508068024458167311ULL, 2701613604891633462ULL, 5403227209783266924ULL, + 10806454419566533849ULL, 2161290883913306769ULL, 4322581767826613539ULL, + 8645163535653227079ULL, 17290327071306454158ULL, 3458065414261290831ULL, + 6916130828522581663ULL, 13832261657045163327ULL, 2766452331409032665ULL, + 5532904662818065330ULL, 11065809325636130661ULL, 2213161865127226132ULL, + 4426323730254452264ULL, 8852647460508904529ULL, 17705294921017809058ULL, + 3541058984203561811ULL, 7082117968407123623ULL, 14164235936814247246ULL, + 2832847187362849449ULL, 5665694374725698898ULL, 11331388749451397797ULL, + 2266277749890279559ULL, 4532555499780559119ULL, 9065110999561118238ULL, + 18130221999122236476ULL, 3626044399824447295ULL, 7252088799648894590ULL, + 14504177599297789180ULL, 2900835519859557836ULL, 5801671039719115672ULL, + 11603342079438231344ULL, 2320668415887646268ULL, 4641336831775292537ULL, + 9282673663550585075ULL, 1856534732710117015ULL, 3713069465420234030ULL, + 7426138930840468060ULL, 14852277861680936121ULL, 2970455572336187224ULL, + 5940911144672374448ULL, 11881822289344748896ULL, 2376364457868949779ULL, + 4752728915737899558ULL, 9505457831475799117ULL, 1901091566295159823ULL, + 3802183132590319647ULL, 7604366265180639294ULL, 15208732530361278588ULL, + 3041746506072255717ULL, 6083493012144511435ULL, 12166986024289022870ULL, + 2433397204857804574ULL, 4866794409715609148ULL, 9733588819431218296ULL, + 1946717763886243659ULL, 3893435527772487318ULL, 7786871055544974637ULL, + 15573742111089949274ULL, 3114748422217989854ULL, 6229496844435979709ULL, + 12458993688871959419ULL, 2491798737774391883ULL, 4983597475548783767ULL, + 9967194951097567535ULL, 1993438990219513507ULL, 3986877980439027014ULL, + 7973755960878054028ULL, 15947511921756108056ULL, 3189502384351221611ULL, + 6379004768702443222ULL, 12758009537404886445ULL, 2551601907480977289ULL, + 5103203814961954578ULL, 10206407629923909156ULL, 2041281525984781831ULL, + 4082563051969563662ULL, 8165126103939127325ULL, 16330252207878254650ULL, + 3266050441575650930ULL, 6532100883151301860ULL, 13064201766302603720ULL, + 2612840353260520744ULL, 5225680706521041488ULL, 10451361413042082976ULL, + 2090272282608416595ULL, 4180544565216833190ULL, 8361089130433666380ULL, + 16722178260867332761ULL, 3344435652173466552ULL, 6688871304346933104ULL, + 13377742608693866209ULL, 2675548521738773241ULL, 5351097043477546483ULL, + 10702194086955092967ULL, 2140438817391018593ULL, 4280877634782037187ULL, + 8561755269564074374ULL, 17123510539128148748ULL, 3424702107825629749ULL, + 6849404215651259499ULL, 13698808431302518998ULL, 2739761686260503799ULL, + 5479523372521007599ULL, 10959046745042015198ULL, 2191809349008403039ULL, + 4383618698016806079ULL, 8767237396033612159ULL, 17534474792067224318ULL, + 3506894958413444863ULL, 7013789916826889727ULL, 14027579833653779454ULL, + 2805515966730755890ULL, 5611031933461511781ULL, 11222063866923023563ULL, + 2244412773384604712ULL, 4488825546769209425ULL, 8977651093538418850ULL, + 17955302187076837701ULL, 3591060437415367540ULL, 7182120874830735080ULL, + 14364241749661470161ULL, 2872848349932294032ULL, 5745696699864588064ULL, + 11491393399729176129ULL, 2298278679945835225ULL, 4596557359891670451ULL, + 9193114719783340903ULL, 18386229439566681806ULL, 3677245887913336361ULL, + 7354491775826672722ULL, 14708983551653345445ULL, 2941796710330669089ULL, + 5883593420661338178ULL, 11767186841322676356ULL, 2353437368264535271ULL, + 4706874736529070542ULL, 9413749473058141084ULL, 1882749894611628216ULL, + 3765499789223256433ULL, 7530999578446512867ULL, 15061999156893025735ULL, + 3012399831378605147ULL, 6024799662757210294ULL, 12049599325514420588ULL, + 2409919865102884117ULL, 4819839730205768235ULL, 9639679460411536470ULL, + 1927935892082307294ULL, 3855871784164614588ULL, 7711743568329229176ULL, + 15423487136658458353ULL, 3084697427331691670ULL, 6169394854663383341ULL, + 12338789709326766682ULL, 2467757941865353336ULL, 4935515883730706673ULL, + 9871031767461413346ULL, 1974206353492282669ULL, 3948412706984565338ULL, + 7896825413969130677ULL, 15793650827938261354ULL, 3158730165587652270ULL, + 6317460331175304541ULL, 12634920662350609083ULL, 2526984132470121816ULL, + 5053968264940243633ULL, 10107936529880487266ULL, 2021587305976097453ULL, + 4043174611952194906ULL, 8086349223904389813ULL, 16172698447808779626ULL, + 3234539689561755925ULL, 6469079379123511850ULL, 12938158758247023701ULL, + 2587631751649404740ULL, 5175263503298809480ULL, 10350527006597618960ULL, + 2070105401319523792ULL, 4140210802639047584ULL, 8280421605278095168ULL, + 16560843210556190337ULL, 3312168642111238067ULL, 6624337284222476135ULL, + 13248674568444952270ULL, 2649734913688990454ULL, 5299469827377980908ULL, + 10598939654755961816ULL, 2119787930951192363ULL, 4239575861902384726ULL, + 8479151723804769452ULL, 16958303447609538905ULL, 3391660689521907781ULL, + 6783321379043815562ULL, 13566642758087631124ULL, 2713328551617526224ULL, + 5426657103235052449ULL, 10853314206470104899ULL, 2170662841294020979ULL, + 4341325682588041959ULL, 8682651365176083919ULL, 17365302730352167839ULL, + 3473060546070433567ULL, 6946121092140867135ULL, 13892242184281734271ULL, + 2778448436856346854ULL, 5556896873712693708ULL, 11113793747425387417ULL, + 2222758749485077483ULL, 4445517498970154966ULL, 8891034997940309933ULL, + 17782069995880619867ULL, 3556413999176123973ULL, 7112827998352247947ULL, + 14225655996704495894ULL, 2845131199340899178ULL, 5690262398681798357ULL, + 11380524797363596715ULL, 2276104959472719343ULL, 4552209918945438686ULL, + 9104419837890877372ULL, 18208839675781754744ULL, 3641767935156350948ULL, + 7283535870312701897ULL, 14567071740625403795ULL, 2913414348125080759ULL, + 5826828696250161518ULL, 11653657392500323036ULL, 2330731478500064607ULL, + 4661462957000129214ULL, 9322925914000258429ULL, 1864585182800051685ULL, + 3729170365600103371ULL, 7458340731200206743ULL, 14916681462400413486ULL, + 2983336292480082697ULL, 5966672584960165394ULL, 11933345169920330789ULL, + 2386669033984066157ULL, 4773338067968132315ULL, 9546676135936264631ULL, + 1909335227187252926ULL, 3818670454374505852ULL, 7637340908749011705ULL, + 15274681817498023410ULL, 3054936363499604682ULL, 6109872726999209364ULL, + 12219745453998418728ULL, 2443949090799683745ULL, 4887898181599367491ULL, + 9775796363198734982ULL, 1955159272639746996ULL, 3910318545279493993ULL, + 7820637090558987986ULL, 15641274181117975972ULL, 3128254836223595194ULL, + 6256509672447190388ULL, 12513019344894380777ULL, 2502603868978876155ULL, + 5005207737957752311ULL, 10010415475915504622ULL, 2002083095183100924ULL, + 4004166190366201848ULL, 8008332380732403697ULL, 16016664761464807395ULL, + 3203332952292961479ULL, 6406665904585922958ULL, 12813331809171845916ULL, + 2562666361834369183ULL, 5125332723668738366ULL, 10250665447337476733ULL, + 2050133089467495346ULL, 4100266178934990693ULL, 8200532357869981386ULL, + 16401064715739962772ULL, 3280212943147992554ULL, 6560425886295985109ULL, + 13120851772591970218ULL, 2624170354518394043ULL, 5248340709036788087ULL, + 10496681418073576174ULL, 2099336283614715234ULL, 4198672567229430469ULL, + 8397345134458860939ULL, 16794690268917721879ULL, 3358938053783544375ULL, + 6717876107567088751ULL, 13435752215134177503ULL, 2687150443026835500ULL, + 5374300886053671001ULL, 10748601772107342002ULL, 2149720354421468400ULL, + 4299440708842936801ULL, 8598881417685873602ULL, 17197762835371747204ULL, + 3439552567074349440ULL, 6879105134148698881ULL, 13758210268297397763ULL, + 2751642053659479552ULL, 5503284107318959105ULL, 11006568214637918210ULL, + 2201313642927583642ULL, 4402627285855167284ULL, 8805254571710334568ULL, + 17610509143420669137ULL, 3522101828684133827ULL, 7044203657368267654ULL, + 14088407314736535309ULL, 2817681462947307061ULL, 5635362925894614123ULL, + 11270725851789228247ULL, 2254145170357845649ULL, 4508290340715691299ULL, + 9016580681431382598ULL, 18033161362862765196ULL, 3606632272572553039ULL, + 7213264545145106078ULL, 14426529090290212157ULL, 2885305818058042431ULL, + 5770611636116084862ULL, 11541223272232169725ULL, 2308244654446433945ULL, + 4616489308892867890ULL, 9232978617785735780ULL, 1846595723557147156ULL, + 3693191447114294312ULL, 7386382894228588624ULL, 14772765788457177249ULL, + 2954553157691435449ULL, 5909106315382870899ULL, 11818212630765741799ULL, + 2363642526153148359ULL, 4727285052306296719ULL, 9454570104612593439ULL, + 1890914020922518687ULL, 3781828041845037375ULL, 7563656083690074751ULL, + 15127312167380149503ULL, 3025462433476029900ULL, 6050924866952059801ULL, + 12101849733904119602ULL, 2420369946780823920ULL, 4840739893561647841ULL, + 9681479787123295682ULL, 1936295957424659136ULL, 3872591914849318272ULL, + 7745183829698636545ULL, 15490367659397273091ULL, 3098073531879454618ULL, + 6196147063758909236ULL, 12392294127517818473ULL, 2478458825503563694ULL, + 4956917651007127389ULL, 9913835302014254778ULL, 1982767060402850955ULL, + 3965534120805701911ULL, 7931068241611403822ULL, 15862136483222807645ULL, + 3172427296644561529ULL, 6344854593289123058ULL, 12689709186578246116ULL, + 2537941837315649223ULL, 5075883674631298446ULL, 10151767349262596893ULL, + 2030353469852519378ULL, 4060706939705038757ULL, 8121413879410077514ULL, + 16242827758820155028ULL, 3248565551764031005ULL, 6497131103528062011ULL, + 12994262207056124023ULL, 2598852441411224804ULL, 5197704882822449609ULL, + 10395409765644899218ULL, 2079081953128979843ULL, 4158163906257959687ULL, + 8316327812515919374ULL, 16632655625031838749ULL, 3326531125006367749ULL, + 6653062250012735499ULL, 13306124500025470999ULL, 2661224900005094199ULL, + 5322449800010188399ULL, 10644899600020376799ULL, 2128979920004075359ULL, + 4257959840008150719ULL, 8515919680016301439ULL, 17031839360032602879ULL, + 3406367872006520575ULL, 6812735744013041151ULL, 13625471488026082303ULL, + 2725094297605216460ULL, 5450188595210432921ULL, 10900377190420865842ULL, + 2180075438084173168ULL, 4360150876168346337ULL, 8720301752336692674ULL, + 17440603504673385348ULL, 3488120700934677069ULL, 6976241401869354139ULL, + 13952482803738708279ULL, 2790496560747741655ULL, 5580993121495483311ULL, + 11161986242990966623ULL, 2232397248598193324ULL, 4464794497196386649ULL, + 8929588994392773298ULL, 17859177988785546597ULL, 3571835597757109319ULL, + 7143671195514218638ULL, 14287342391028437277ULL, 2857468478205687455ULL, + 5714936956411374911ULL, 11429873912822749822ULL, 2285974782564549964ULL, + 4571949565129099928ULL, 9143899130258199857ULL, 18287798260516399715ULL, + 3657559652103279943ULL, 7315119304206559886ULL, 14630238608413119772ULL, + 2926047721682623954ULL, 5852095443365247908ULL, 11704190886730495817ULL, + 2340838177346099163ULL, 4681676354692198327ULL, 9363352709384396654ULL, + 1872670541876879330ULL, 3745341083753758661ULL, 7490682167507517323ULL, + 14981364335015034646ULL, 2996272867003006929ULL, 5992545734006013858ULL, + 11985091468012027717ULL, 2397018293602405543ULL, 4794036587204811087ULL, + 9588073174409622174ULL, 1917614634881924434ULL, 3835229269763848869ULL, + 7670458539527697739ULL, 15340917079055395478ULL, 3068183415811079095ULL, + 6136366831622158191ULL, 12272733663244316382ULL, 2454546732648863276ULL, + 4909093465297726553ULL, 9818186930595453106ULL, 1963637386119090621ULL, + 3927274772238181242ULL, 7854549544476362484ULL, 15709099088952724969ULL, + 3141819817790544993ULL, 6283639635581089987ULL, 12567279271162179975ULL, + 2513455854232435995ULL, 5026911708464871990ULL, 10053823416929743980ULL, + 2010764683385948796ULL, 4021529366771897592ULL, 8043058733543795184ULL, + 16086117467087590369ULL, 3217223493417518073ULL, 6434446986835036147ULL, + 12868893973670072295ULL, 2573778794734014459ULL, 5147557589468028918ULL, + 10295115178936057836ULL, 2059023035787211567ULL, 4118046071574423134ULL, + 8236092143148846269ULL, 16472184286297692538ULL, 3294436857259538507ULL, + 6588873714519077015ULL, 13177747429038154030ULL, 2635549485807630806ULL, + 5271098971615261612ULL, 10542197943230523224ULL, 2108439588646104644ULL, + 4216879177292209289ULL, 8433758354584418579ULL, 16867516709168837158ULL, + 3373503341833767431ULL, 6747006683667534863ULL, 13494013367335069727ULL, + 2698802673467013945ULL, 5397605346934027890ULL, 10795210693868055781ULL, + 2159042138773611156ULL, 4318084277547222312ULL, 8636168555094444625ULL, + 17272337110188889250ULL, 3454467422037777850ULL, 6908934844075555700ULL, + 13817869688151111400ULL, 2763573937630222280ULL, 5527147875260444560ULL, + 11054295750520889120ULL, 2210859150104177824ULL, 4421718300208355648ULL, + 8843436600416711296ULL, 17686873200833422592ULL, 3537374640166684518ULL, + 7074749280333369037ULL, 14149498560666738074ULL, 2829899712133347614ULL, + 5659799424266695229ULL, 11319598848533390459ULL, 2263919769706678091ULL, + 4527839539413356183ULL, 9055679078826712367ULL, 18111358157653424735ULL, + 3622271631530684947ULL, 7244543263061369894ULL, 14489086526122739788ULL, + 2897817305224547957ULL, 5795634610449095915ULL, 11591269220898191830ULL, + 2318253844179638366ULL, 4636507688359276732ULL, 9273015376718553464ULL, + 1854603075343710692ULL, 3709206150687421385ULL, 7418412301374842771ULL, + 14836824602749685542ULL, 2967364920549937108ULL, 5934729841099874217ULL, + 11869459682199748434ULL, 2373891936439949686ULL, 4747783872879899373ULL, + 9495567745759798747ULL, 1899113549151959749ULL, 3798227098303919498ULL, + 7596454196607838997ULL, 15192908393215677995ULL, 3038581678643135599ULL, + 6077163357286271198ULL, 12154326714572542396ULL, 2430865342914508479ULL, + 4861730685829016958ULL, 9723461371658033917ULL, 1944692274331606783ULL, + 3889384548663213566ULL, 7778769097326427133ULL, 15557538194652854267ULL, + 3111507638930570853ULL, 6223015277861141707ULL, 12446030555722283414ULL, + 2489206111144456682ULL, 4978412222288913365ULL, 9956824444577826731ULL, + 1991364888915565346ULL, 3982729777831130692ULL, 7965459555662261385ULL, + 15930919111324522770ULL, 3186183822264904554ULL, 6372367644529809108ULL, + 12744735289059618216ULL, 2548947057811923643ULL, 5097894115623847286ULL, + 10195788231247694572ULL, 2039157646249538914ULL, 4078315292499077829ULL, + 8156630584998155658ULL, 16313261169996311316ULL, 3262652233999262263ULL, + 6525304467998524526ULL, 13050608935997049053ULL, 2610121787199409810ULL, + 5220243574398819621ULL, 10440487148797639242ULL, 2088097429759527848ULL, + 4176194859519055697ULL, 8352389719038111394ULL, 16704779438076222788ULL, + 3340955887615244557ULL, 6681911775230489115ULL, 13363823550460978230ULL, + 2672764710092195646ULL, 5345529420184391292ULL, 10691058840368782584ULL, + 2138211768073756516ULL, 4276423536147513033ULL, 8552847072295026067ULL, + 17105694144590052135ULL, 3421138828918010427ULL, 6842277657836020854ULL, + 13684555315672041708ULL, 2736911063134408341ULL, 5473822126268816683ULL, + 10947644252537633366ULL, 2189528850507526673ULL, 4379057701015053346ULL, + 8758115402030106693ULL, 17516230804060213386ULL, 3503246160812042677ULL, + 7006492321624085354ULL, 14012984643248170709ULL, 2802596928649634141ULL, + 5605193857299268283ULL, 11210387714598536567ULL, 2242077542919707313ULL, + 4484155085839414626ULL, 8968310171678829253ULL, 17936620343357658507ULL, + 3587324068671531701ULL, 7174648137343063403ULL, 14349296274686126806ULL, + 2869859254937225361ULL, 5739718509874450722ULL, 11479437019748901445ULL, + 2295887403949780289ULL, 4591774807899560578ULL, 9183549615799121156ULL, + 18367099231598242312ULL, 3673419846319648462ULL, 7346839692639296924ULL, + 14693679385278593849ULL, 2938735877055718769ULL, 5877471754111437539ULL, + 11754943508222875079ULL, 2350988701644575015ULL, 4701977403289150031ULL, + 9403954806578300063ULL, 1880790961315660012ULL, 3761581922631320025ULL, + 7523163845262640050ULL, 15046327690525280101ULL, 3009265538105056020ULL, + 6018531076210112040ULL, 12037062152420224081ULL, 2407412430484044816ULL, + 4814824860968089632ULL, 9629649721936179265ULL, 1925929944387235853ULL, + 3851859888774471706ULL, 7703719777548943412ULL, 15407439555097886824ULL, + 3081487911019577364ULL, 6162975822039154729ULL, 12325951644078309459ULL, + 2465190328815661891ULL, 4930380657631323783ULL, 9860761315262647567ULL, + 1972152263052529513ULL, 3944304526105059027ULL, 7888609052210118054ULL, + 15777218104420236108ULL, 3155443620884047221ULL, 6310887241768094443ULL, + 12621774483536188886ULL, 2524354896707237777ULL, 5048709793414475554ULL, + 10097419586828951109ULL, 2019483917365790221ULL, 4038967834731580443ULL, + 8077935669463160887ULL, 16155871338926321774ULL, 3231174267785264354ULL, + 6462348535570528709ULL, 12924697071141057419ULL, 2584939414228211483ULL, + 5169878828456422967ULL, 10339757656912845935ULL, 2067951531382569187ULL, + 4135903062765138374ULL, 8271806125530276748ULL, 16543612251060553497ULL, + 3308722450212110699ULL, 6617444900424221398ULL, 13234889800848442797ULL, + 2646977960169688559ULL, 5293955920339377119ULL, 10587911840678754238ULL, + 2117582368135750847ULL, 4235164736271501695ULL, 8470329472543003390ULL, + 16940658945086006781ULL, 3388131789017201356ULL, 6776263578034402712ULL, + 13552527156068805425ULL, 2710505431213761085ULL, 5421010862427522170ULL, + 10842021724855044340ULL, 2168404344971008868ULL, 4336808689942017736ULL, + 8673617379884035472ULL, 17347234759768070944ULL, 3469446951953614188ULL, + 6938893903907228377ULL, 13877787807814456755ULL, 2775557561562891351ULL, + 5551115123125782702ULL, 11102230246251565404ULL, 2220446049250313080ULL, + 4440892098500626161ULL, 8881784197001252323ULL, 17763568394002504646ULL, + 3552713678800500929ULL, 7105427357601001858ULL, 14210854715202003717ULL, + 2842170943040400743ULL, 5684341886080801486ULL, 11368683772161602973ULL, + 2273736754432320594ULL, 4547473508864641189ULL, 9094947017729282379ULL, + 18189894035458564758ULL, 3637978807091712951ULL, 7275957614183425903ULL, + 14551915228366851806ULL, 2910383045673370361ULL, 5820766091346740722ULL, + 11641532182693481445ULL, 2328306436538696289ULL, 4656612873077392578ULL, + 9313225746154785156ULL, 1862645149230957031ULL, 3725290298461914062ULL, + 7450580596923828125ULL, 14901161193847656250ULL, 2980232238769531250ULL, + 5960464477539062500ULL, 11920928955078125000ULL, 2384185791015625000ULL, + 4768371582031250000ULL, 9536743164062500000ULL, 1907348632812500000ULL, + 3814697265625000000ULL, 7629394531250000000ULL, 15258789062500000000ULL, + 3051757812500000000ULL, 6103515625000000000ULL, 12207031250000000000ULL, + 2441406250000000000ULL, 4882812500000000000ULL, 9765625000000000000ULL, + 1953125000000000000ULL, 3906250000000000000ULL, 7812500000000000000ULL, + 15625000000000000000ULL, 3125000000000000000ULL, 6250000000000000000ULL, + 12500000000000000000ULL, 2500000000000000000ULL, 5000000000000000000ULL, + 10000000000000000000ULL, 2000000000000000000ULL, 4000000000000000000ULL, + 8000000000000000000ULL, 16000000000000000000ULL, 3200000000000000000ULL, + 6400000000000000000ULL, 12800000000000000000ULL, 2560000000000000000ULL, + 5120000000000000000ULL, 10240000000000000000ULL, 2048000000000000000ULL, + 4096000000000000000ULL, 8192000000000000000ULL, 16384000000000000000ULL, + 3276800000000000000ULL, 6553600000000000000ULL, 13107200000000000000ULL, + 2621440000000000000ULL, 5242880000000000000ULL, 10485760000000000000ULL, + 2097152000000000000ULL, 4194304000000000000ULL, 8388608000000000000ULL, + 16777216000000000000ULL, 3355443200000000000ULL, 6710886400000000000ULL, + 13421772800000000000ULL, 2684354560000000000ULL, 5368709120000000000ULL, + 10737418240000000000ULL, 2147483648000000000ULL, 4294967296000000000ULL, + 8589934592000000000ULL, 17179869184000000000ULL, 3435973836800000000ULL, + 6871947673600000000ULL, 13743895347200000000ULL, 2748779069440000000ULL, + 5497558138880000000ULL, 10995116277760000000ULL, 2199023255552000000ULL, + 4398046511104000000ULL, 8796093022208000000ULL, 17592186044416000000ULL, + 3518437208883200000ULL, 7036874417766400000ULL, 14073748835532800000ULL, + 2814749767106560000ULL, 5629499534213120000ULL, 11258999068426240000ULL, + 2251799813685248000ULL, 4503599627370496000ULL, 9007199254740992000ULL, + 18014398509481984000ULL, 3602879701896396800ULL, 7205759403792793600ULL, + 14411518807585587200ULL, 2882303761517117440ULL, 5764607523034234880ULL, + 11529215046068469760ULL, 2305843009213693952ULL, 4611686018427387904ULL, + 9223372036854775808ULL, 1844674407370955161ULL, 3689348814741910323ULL, + 7378697629483820646ULL, 14757395258967641292ULL, 2951479051793528258ULL, + 5902958103587056517ULL, 11805916207174113034ULL, 2361183241434822606ULL, + 4722366482869645213ULL, 9444732965739290427ULL, 1888946593147858085ULL, + 3777893186295716170ULL, 7555786372591432341ULL, 15111572745182864683ULL, + 3022314549036572936ULL, 6044629098073145873ULL, 12089258196146291747ULL, + 2417851639229258349ULL, 4835703278458516698ULL, 9671406556917033397ULL, + 1934281311383406679ULL, 3868562622766813359ULL, 7737125245533626718ULL, + 15474250491067253436ULL, 3094850098213450687ULL, 6189700196426901374ULL, + 12379400392853802748ULL, 2475880078570760549ULL, 4951760157141521099ULL, + 9903520314283042199ULL, 1980704062856608439ULL, 3961408125713216879ULL, + 7922816251426433759ULL, 15845632502852867518ULL, 3169126500570573503ULL, + 6338253001141147007ULL, 12676506002282294014ULL, 2535301200456458802ULL, + 5070602400912917605ULL, 10141204801825835211ULL, 2028240960365167042ULL, + 4056481920730334084ULL, 8112963841460668169ULL, 16225927682921336339ULL, + 3245185536584267267ULL, 6490371073168534535ULL, 12980742146337069071ULL, + 2596148429267413814ULL, 5192296858534827628ULL, 10384593717069655257ULL, + 2076918743413931051ULL, 4153837486827862102ULL, 8307674973655724205ULL, + 16615349947311448411ULL, 3323069989462289682ULL, 6646139978924579364ULL, + 13292279957849158729ULL, 2658455991569831745ULL, 5316911983139663491ULL, + 10633823966279326983ULL, 2126764793255865396ULL, 4253529586511730793ULL, + 8507059173023461586ULL, 17014118346046923173ULL, 3402823669209384634ULL, + 6805647338418769269ULL, 13611294676837538538ULL, 2722258935367507707ULL, + 5444517870735015415ULL, 10889035741470030830ULL, 2177807148294006166ULL, + 4355614296588012332ULL, 8711228593176024664ULL, 17422457186352049329ULL, + 3484491437270409865ULL, 6968982874540819731ULL, 13937965749081639463ULL, + 2787593149816327892ULL, 5575186299632655785ULL, 11150372599265311570ULL, + 2230074519853062314ULL, 4460149039706124628ULL, 8920298079412249256ULL, + 17840596158824498513ULL, 3568119231764899702ULL, 7136238463529799405ULL, + 14272476927059598810ULL, 2854495385411919762ULL, 5708990770823839524ULL, + 11417981541647679048ULL, 2283596308329535809ULL, 4567192616659071619ULL, + 9134385233318143238ULL, 18268770466636286477ULL, 3653754093327257295ULL, + 7307508186654514591ULL, 14615016373309029182ULL, 2923003274661805836ULL, + 5846006549323611672ULL, 11692013098647223345ULL, 2338402619729444669ULL, + 4676805239458889338ULL, 9353610478917778676ULL, 1870722095783555735ULL, + 3741444191567111470ULL, 7482888383134222941ULL, 14965776766268445882ULL, + 2993155353253689176ULL, 5986310706507378352ULL, 11972621413014756705ULL, + 2394524282602951341ULL, 4789048565205902682ULL, 9578097130411805364ULL, + 1915619426082361072ULL, 3831238852164722145ULL, 7662477704329444291ULL, + 15324955408658888583ULL, 3064991081731777716ULL, 6129982163463555433ULL, + 12259964326927110866ULL, 2451992865385422173ULL, 4903985730770844346ULL, + 9807971461541688693ULL, 1961594292308337738ULL, 3923188584616675477ULL, + 7846377169233350954ULL, 15692754338466701909ULL, 3138550867693340381ULL, + 6277101735386680763ULL, 12554203470773361527ULL, 2510840694154672305ULL, + 5021681388309344611ULL, 10043362776618689222ULL, 2008672555323737844ULL, + 4017345110647475688ULL, 8034690221294951377ULL, 16069380442589902755ULL, + 3213876088517980551ULL, 6427752177035961102ULL, 12855504354071922204ULL, + 2571100870814384440ULL, 5142201741628768881ULL, 10284403483257537763ULL, + 2056880696651507552ULL, 4113761393303015105ULL, 8227522786606030210ULL, + 16455045573212060421ULL, 3291009114642412084ULL, 6582018229284824168ULL, + 13164036458569648337ULL, 2632807291713929667ULL, 5265614583427859334ULL, + 10531229166855718669ULL, 2106245833371143733ULL, 4212491666742287467ULL, + 8424983333484574935ULL, 16849966666969149871ULL, 3369993333393829974ULL, + 6739986666787659948ULL, 13479973333575319897ULL, 2695994666715063979ULL, + 5391989333430127958ULL, 10783978666860255917ULL, 2156795733372051183ULL, + 4313591466744102367ULL, 8627182933488204734ULL, 17254365866976409468ULL, + 3450873173395281893ULL, 6901746346790563787ULL, 13803492693581127574ULL, + 2760698538716225514ULL, 5521397077432451029ULL, 11042794154864902059ULL, + 2208558830972980411ULL, 4417117661945960823ULL, 8834235323891921647ULL, + 17668470647783843295ULL, 3533694129556768659ULL, 7067388259113537318ULL, + 14134776518227074636ULL, 2826955303645414927ULL, 5653910607290829854ULL, + 11307821214581659709ULL, 2261564242916331941ULL, 4523128485832663883ULL, + 9046256971665327767ULL, 18092513943330655534ULL, 3618502788666131106ULL, + 7237005577332262213ULL, 14474011154664524427ULL, 2894802230932904885ULL, + 5789604461865809771ULL, 11579208923731619542ULL, 2315841784746323908ULL, + 4631683569492647816ULL, 9263367138985295633ULL, 1852673427797059126ULL, + 3705346855594118253ULL, 7410693711188236507ULL, 14821387422376473014ULL, + 2964277484475294602ULL, 5928554968950589205ULL, 11857109937901178411ULL, + 2371421987580235682ULL, 4742843975160471364ULL, 9485687950320942729ULL, + 1897137590064188545ULL, 3794275180128377091ULL, 7588550360256754183ULL, + 15177100720513508366ULL, 3035420144102701673ULL, 6070840288205403346ULL, + 12141680576410806693ULL, 2428336115282161338ULL, 4856672230564322677ULL, + 9713344461128645354ULL, 1942668892225729070ULL, 3885337784451458141ULL, + 7770675568902916283ULL, 15541351137805832567ULL, 3108270227561166513ULL, + 6216540455122333026ULL, 12433080910244666053ULL, 2486616182048933210ULL, + 4973232364097866421ULL, 9946464728195732843ULL, 1989292945639146568ULL, + 3978585891278293137ULL, 7957171782556586274ULL, 15914343565113172548ULL, + 3182868713022634509ULL, 6365737426045269019ULL, 12731474852090538039ULL, + 2546294970418107607ULL, 5092589940836215215ULL, 10185179881672430431ULL, + 2037035976334486086ULL, 4074071952668972172ULL, 8148143905337944345ULL, + 16296287810675888690ULL, 3259257562135177738ULL, 6518515124270355476ULL, + 13037030248540710952ULL, 2607406049708142190ULL, 5214812099416284380ULL, + 10429624198832568761ULL, 2085924839766513752ULL, 4171849679533027504ULL, + 8343699359066055009ULL, 16687398718132110018ULL, 3337479743626422003ULL, + 6674959487252844007ULL, 13349918974505688014ULL, 2669983794901137602ULL, + 5339967589802275205ULL, 10679935179604550411ULL, 2135987035920910082ULL, + 4271974071841820164ULL, 8543948143683640329ULL, 17087896287367280659ULL, + 3417579257473456131ULL, 6835158514946912263ULL, 13670317029893824527ULL, + 2734063405978764905ULL, 5468126811957529810ULL, 10936253623915059621ULL, + 2187250724783011924ULL, 4374501449566023848ULL, 8749002899132047697ULL, + 17498005798264095394ULL, 3499601159652819078ULL, 6999202319305638157ULL, + 13998404638611276315ULL, 2799680927722255263ULL, 5599361855444510526ULL, + 11198723710889021052ULL, 2239744742177804210ULL, 4479489484355608421ULL, + 8958978968711216842ULL, 17917957937422433684ULL, 3583591587484486736ULL, + 7167183174968973473ULL, 14334366349937946947ULL, 2866873269987589389ULL, + 5733746539975178779ULL, 11467493079950357558ULL, 2293498615990071511ULL, + 4586997231980143023ULL, 9173994463960286046ULL, 18347988927920572092ULL, + 3669597785584114418ULL, 7339195571168228837ULL, 14678391142336457674ULL, + 2935678228467291534ULL, 5871356456934583069ULL, 11742712913869166139ULL, + 2348542582773833227ULL, 4697085165547666455ULL, 9394170331095332911ULL, + 1878834066219066582ULL, 3757668132438133164ULL, 7515336264876266329ULL, + 15030672529752532658ULL, 3006134505950506531ULL, 6012269011901013063ULL, + 12024538023802026126ULL, 2404907604760405225ULL, 4809815209520810450ULL, + 9619630419041620901ULL, 1923926083808324180ULL, 3847852167616648360ULL, + 7695704335233296721ULL, 15391408670466593442ULL, 3078281734093318688ULL, + 6156563468186637376ULL, 12313126936373274753ULL, 2462625387274654950ULL, + 4925250774549309901ULL, 9850501549098619803ULL, 1970100309819723960ULL, + 3940200619639447921ULL, 7880401239278895842ULL, 15760802478557791684ULL, + 3152160495711558336ULL, 6304320991423116673ULL, 12608641982846233347ULL, + 2521728396569246669ULL, 5043456793138493339ULL, 10086913586276986678ULL, + 2017382717255397335ULL, 4034765434510794671ULL, 8069530869021589342ULL, + 16139061738043178685ULL, 3227812347608635737ULL, 6455624695217271474ULL, + 12911249390434542948ULL, 2582249878086908589ULL, 5164499756173817179ULL, + 10328999512347634358ULL, 2065799902469526871ULL, 4131599804939053743ULL, + 8263199609878107486ULL, 16526399219756214973ULL, 3305279843951242994ULL, + 6610559687902485989ULL, 13221119375804971979ULL, 2644223875160994395ULL, + 5288447750321988791ULL, 10576895500643977583ULL, 2115379100128795516ULL, + 4230758200257591033ULL, 8461516400515182066ULL, 16923032801030364133ULL, + 3384606560206072826ULL, 6769213120412145653ULL, 13538426240824291306ULL, + 2707685248164858261ULL, 5415370496329716522ULL, 10830740992659433045ULL, + 2166148198531886609ULL, 4332296397063773218ULL, 8664592794127546436ULL, + 17329185588255092872ULL, 3465837117651018574ULL, 6931674235302037148ULL, + 13863348470604074297ULL, 2772669694120814859ULL, 5545339388241629719ULL, + 11090678776483259438ULL, 2218135755296651887ULL, 4436271510593303775ULL, + 8872543021186607550ULL, 17745086042373215101ULL, 3549017208474643020ULL, + 7098034416949286040ULL, 14196068833898572081ULL, 2839213766779714416ULL, + 5678427533559428832ULL, 11356855067118857664ULL, 2271371013423771532ULL, + 4542742026847543065ULL, 9085484053695086131ULL, 18170968107390172263ULL, + 3634193621478034452ULL, 7268387242956068905ULL, 14536774485912137810ULL, + 2907354897182427562ULL, 5814709794364855124ULL, 11629419588729710248ULL, + 2325883917745942049ULL, 4651767835491884099ULL, 9303535670983768199ULL, + 1860707134196753639ULL, 3721414268393507279ULL, 7442828536787014559ULL, + 14885657073574029118ULL, 2977131414714805823ULL, 5954262829429611647ULL, + 11908525658859223294ULL, 2381705131771844658ULL, 4763410263543689317ULL, + 9526820527087378635ULL, 1905364105417475727ULL, 3810728210834951454ULL, + 7621456421669902908ULL, 15242912843339805817ULL, 3048582568667961163ULL, + 6097165137335922326ULL, 12194330274671844653ULL, 2438866054934368930ULL, + 4877732109868737861ULL, 9755464219737475723ULL, 1951092843947495144ULL, + 3902185687894990289ULL, 7804371375789980578ULL, 15608742751579961156ULL, + 3121748550315992231ULL, 6243497100631984462ULL, 12486994201263968925ULL, + 2497398840252793785ULL, 4994797680505587570ULL, 9989595361011175140ULL, + 1997919072202235028ULL, 3995838144404470056ULL, 7991676288808940112ULL, + 15983352577617880224ULL, 3196670515523576044ULL, 6393341031047152089ULL, + 12786682062094304179ULL, 2557336412418860835ULL, 5114672824837721671ULL, + 10229345649675443343ULL, 2045869129935088668ULL, 4091738259870177337ULL, + 8183476519740354675ULL, 16366953039480709350ULL, 3273390607896141870ULL, + 6546781215792283740ULL, 13093562431584567480ULL, 2618712486316913496ULL, + 5237424972633826992ULL, 10474849945267653984ULL, 2094969989053530796ULL, + 4189939978107061593ULL, 8379879956214123187ULL, 16759759912428246374ULL, + 3351951982485649274ULL, 6703903964971298549ULL, 13407807929942597099ULL, + 2681561585988519419ULL, 5363123171977038839ULL, 10726246343954077679ULL, + 2145249268790815535ULL, 4290498537581631071ULL, 8580997075163262143ULL, + 17161994150326524287ULL, 3432398830065304857ULL, 6864797660130609714ULL, + 13729595320261219429ULL, 2745919064052243885ULL, 5491838128104487771ULL, + 10983676256208975543ULL, 2196735251241795108ULL, 4393470502483590217ULL, + 8786941004967180435ULL, 17573882009934360870ULL, 3514776401986872174ULL, + 7029552803973744348ULL, 14059105607947488696ULL, 2811821121589497739ULL, + 5623642243178995478ULL, 11247284486357990957ULL, 2249456897271598191ULL, + 4498913794543196382ULL, 8997827589086392765ULL, 17995655178172785531ULL, + 3599131035634557106ULL, 7198262071269114212ULL, 14396524142538228424ULL, + 2879304828507645684ULL, 5758609657015291369ULL, 11517219314030582739ULL, + 2303443862806116547ULL, 4606887725612233095ULL, 9213775451224466191ULL, + 18427550902448932383ULL, 3685510180489786476ULL, 7371020360979572953ULL, + 14742040721959145907ULL, 2948408144391829181ULL, 5896816288783658362ULL, + 11793632577567316725ULL, 2358726515513463345ULL, 4717453031026926690ULL, + 9434906062053853380ULL, 1886981212410770676ULL, 3773962424821541352ULL, + 7547924849643082704ULL, 15095849699286165408ULL, 3019169939857233081ULL, + 6038339879714466163ULL, 12076679759428932327ULL, 2415335951885786465ULL, + 4830671903771572930ULL, 9661343807543145861ULL, 1932268761508629172ULL, + 3864537523017258344ULL, 7729075046034516689ULL, 15458150092069033378ULL, + 3091630018413806675ULL, 6183260036827613351ULL, 12366520073655226703ULL, + 2473304014731045340ULL, 4946608029462090681ULL, 9893216058924181362ULL, + 1978643211784836272ULL, 3957286423569672544ULL, 7914572847139345089ULL, + 15829145694278690179ULL, 3165829138855738035ULL, 6331658277711476071ULL, + 12663316555422952143ULL, 2532663311084590428ULL, 5065326622169180857ULL, + 10130653244338361715ULL, 2026130648867672343ULL, 4052261297735344686ULL, + 8104522595470689372ULL, 16209045190941378744ULL, 3241809038188275748ULL, + 6483618076376551497ULL, 12967236152753102995ULL, 2593447230550620599ULL, + 5186894461101241198ULL, 10373788922202482396ULL, 2074757784440496479ULL, + 4149515568880992958ULL, 8299031137761985917ULL, 16598062275523971834ULL, + 3319612455104794366ULL, 6639224910209588733ULL, 13278449820419177467ULL, + 2655689964083835493ULL, 5311379928167670986ULL, 10622759856335341973ULL, + 2124551971267068394ULL, 4249103942534136789ULL, 8498207885068273579ULL, + 16996415770136547158ULL, 3399283154027309431ULL, 6798566308054618863ULL, + 13597132616109237726ULL, 2719426523221847545ULL, 5438853046443695090ULL, + 10877706092887390181ULL, 2175541218577478036ULL, 4351082437154956072ULL, + 8702164874309912144ULL, 17404329748619824289ULL, 3480865949723964857ULL, + 6961731899447929715ULL, 13923463798895859431ULL, 2784692759779171886ULL, + 5569385519558343772ULL, 11138771039116687545ULL, 2227754207823337509ULL, + 4455508415646675018ULL, 8911016831293350036ULL, 17822033662586700072ULL, + 3564406732517340014ULL, 7128813465034680029ULL, 14257626930069360058ULL, + 2851525386013872011ULL, 5703050772027744023ULL, 11406101544055488046ULL, + 2281220308811097609ULL, 4562440617622195218ULL, 9124881235244390437ULL, + 18249762470488780874ULL, 3649952494097756174ULL, 7299904988195512349ULL, + 14599809976391024699ULL, 2919961995278204939ULL, 5839923990556409879ULL, + 11679847981112819759ULL, 2335969596222563951ULL, 4671939192445127903ULL, + 9343878384890255807ULL, 1868775676978051161ULL, 3737551353956102323ULL, + 7475102707912204646ULL, 14950205415824409292ULL, 2990041083164881858ULL, + 5980082166329763716ULL, 11960164332659527433ULL, 2392032866531905486ULL, + 4784065733063810973ULL, 9568131466127621947ULL, 1913626293225524389ULL, + 3827252586451048778ULL, 7654505172902097557ULL, 15309010345804195115ULL, + 3061802069160839023ULL, 6123604138321678046ULL, 12247208276643356092ULL, + 2449441655328671218ULL, 4898883310657342436ULL, 9797766621314684873ULL, + 1959553324262936974ULL, 3919106648525873949ULL, 7838213297051747899ULL, + 15676426594103495798ULL, 3135285318820699159ULL, 6270570637641398319ULL, + 12541141275282796638ULL, 2508228255056559327ULL, 5016456510113118655ULL, + 10032913020226237310ULL, 2006582604045247462ULL, 4013165208090494924ULL, + 8026330416180989848ULL, 16052660832361979697ULL, 3210532166472395939ULL, + 6421064332944791878ULL, 12842128665889583757ULL, 2568425733177916751ULL, + 5136851466355833503ULL, 10273702932711667006ULL, 2054740586542333401ULL, + 4109481173084666802ULL, 8218962346169333605ULL, 16437924692338667210ULL, + 3287584938467733442ULL, 6575169876935466884ULL, 13150339753870933768ULL, + 2630067950774186753ULL, 5260135901548373507ULL, 10520271803096747014ULL, + 2104054360619349402ULL, 4208108721238698805ULL, 8416217442477397611ULL, + 16832434884954795223ULL, 3366486976990959044ULL, 6732973953981918089ULL, + 13465947907963836178ULL, 2693189581592767235ULL, 5386379163185534471ULL, + 10772758326371068942ULL, 2154551665274213788ULL, 4309103330548427577ULL, + 8618206661096855154ULL, 17236413322193710308ULL, 3447282664438742061ULL, + 6894565328877484123ULL, 13789130657754968246ULL, 2757826131550993649ULL, + 5515652263101987298ULL, 11031304526203974597ULL, 2206260905240794919ULL, + 4412521810481589838ULL, 8825043620963179677ULL, 17650087241926359355ULL, + 3530017448385271871ULL, 7060034896770543742ULL, 14120069793541087484ULL, + 2824013958708217496ULL, 5648027917416434993ULL, 11296055834832869987ULL, + 2259211166966573997ULL, 4518422333933147995ULL, 9036844667866295990ULL, + 18073689335732591980ULL, 3614737867146518396ULL, 7229475734293036792ULL, + 14458951468586073584ULL, 2891790293717214716ULL, 5783580587434429433ULL, + 11567161174868858867ULL, 2313432234973771773ULL, 4626864469947543547ULL, + 9253728939895087094ULL, 1850745787979017418ULL, 3701491575958034837ULL, + 7402983151916069675ULL, 14805966303832139350ULL, 2961193260766427870ULL, + 5922386521532855740ULL, 11844773043065711480ULL, 2368954608613142296ULL, + 4737909217226284592ULL, 9475818434452569184ULL, 1895163686890513836ULL, + 3790327373781027673ULL, 7580654747562055347ULL, 15161309495124110694ULL, + 3032261899024822138ULL, 6064523798049644277ULL, 12129047596099288555ULL, + 2425809519219857711ULL, 4851619038439715422ULL, 9703238076879430844ULL, + 1940647615375886168ULL, 3881295230751772337ULL, 7762590461503544675ULL, + 15525180923007089351ULL, 3105036184601417870ULL, 6210072369202835740ULL, + 12420144738405671481ULL, 2484028947681134296ULL, 4968057895362268592ULL, + 9936115790724537184ULL, 1987223158144907436ULL, 3974446316289814873ULL, + 7948892632579629747ULL, 15897785265159259495ULL, 3179557053031851899ULL, + 6359114106063703798ULL, 12718228212127407596ULL, 2543645642425481519ULL, + 5087291284850963038ULL, 10174582569701926077ULL, 2034916513940385215ULL, + 4069833027880770430ULL, 8139666055761540861ULL, 16279332111523081723ULL, + 3255866422304616344ULL, 6511732844609232689ULL, 13023465689218465379ULL, + 2604693137843693075ULL, 5209386275687386151ULL, 10418772551374772303ULL, + 2083754510274954460ULL, 4167509020549908921ULL, 8335018041099817842ULL, + 16670036082199635685ULL, 3334007216439927137ULL, 6668014432879854274ULL, + 13336028865759708548ULL, 2667205773151941709ULL, 5334411546303883419ULL, + 10668823092607766838ULL, 2133764618521553367ULL, 4267529237043106735ULL, + 8535058474086213470ULL, 17070116948172426941ULL, 3414023389634485388ULL, + 6828046779268970776ULL, 13656093558537941553ULL, 2731218711707588310ULL, + 5462437423415176621ULL, 10924874846830353242ULL, 2184974969366070648ULL, + 4369949938732141297ULL, 8739899877464282594ULL, 17479799754928565188ULL, + 3495959950985713037ULL, 6991919901971426075ULL, 13983839803942852150ULL, + 2796767960788570430ULL, 5593535921577140860ULL, 11187071843154281720ULL, + 2237414368630856344ULL, 4474828737261712688ULL, 8949657474523425376ULL, + 17899314949046850752ULL, 3579862989809370150ULL, 7159725979618740301ULL, + 14319451959237480602ULL, 2863890391847496120ULL, 5727780783694992240ULL, + 11455561567389984481ULL, 2291112313477996896ULL, 4582224626955993792ULL, + 9164449253911987585ULL, 18328898507823975170ULL, 3665779701564795034ULL, + 7331559403129590068ULL, 14663118806259180136ULL, 2932623761251836027ULL, + 5865247522503672054ULL, 11730495045007344109ULL, 2346099009001468821ULL, + 4692198018002937643ULL, 9384396036005875287ULL, 1876879207201175057ULL, + 3753758414402350114ULL, 7507516828804700229ULL, 15015033657609400459ULL, + 3003006731521880091ULL, 6006013463043760183ULL, 12012026926087520367ULL, + 2402405385217504073ULL, 4804810770435008147ULL, 9609621540870016294ULL, + 1921924308174003258ULL, 3843848616348006517ULL, 7687697232696013035ULL, + 15375394465392026070ULL, 3075078893078405214ULL, 6150157786156810428ULL, + 12300315572313620856ULL, 2460063114462724171ULL, 4920126228925448342ULL, + 9840252457850896685ULL, 1968050491570179337ULL, 3936100983140358674ULL, + 7872201966280717348ULL, 15744403932561434696ULL, 3148880786512286939ULL, + 6297761573024573878ULL, 12595523146049147757ULL, 2519104629209829551ULL, + 5038209258419659102ULL, 10076418516839318205ULL, 2015283703367863641ULL, + 4030567406735727282ULL, 8061134813471454564ULL, 16122269626942909129ULL, + 3224453925388581825ULL, 6448907850777163651ULL, 12897815701554327303ULL, + 2579563140310865460ULL, 5159126280621730921ULL, 10318252561243461842ULL, + 2063650512248692368ULL, 4127301024497384737ULL, 8254602048994769474ULL, + 16509204097989538948ULL, 3301840819597907789ULL, 6603681639195815579ULL, + 13207363278391631158ULL, 2641472655678326231ULL, 5282945311356652463ULL, + 10565890622713304927ULL, 2113178124542660985ULL, 4226356249085321970ULL, + 8452712498170643941ULL, 16905424996341287883ULL, 3381084999268257576ULL, + 6762169998536515153ULL, 13524339997073030306ULL, 2704867999414606061ULL, + 5409735998829212122ULL, 10819471997658424245ULL, 2163894399531684849ULL, + 4327788799063369698ULL, 8655577598126739396ULL, 17311155196253478792ULL, + 3462231039250695758ULL, 6924462078501391516ULL, 13848924157002783033ULL, + 2769784831400556606ULL, 5539569662801113213ULL, 11079139325602226427ULL, + 2215827865120445285ULL, 4431655730240890570ULL, 8863311460481781141ULL, + 17726622920963562283ULL, 3545324584192712456ULL, 7090649168385424913ULL, + 14181298336770849826ULL, 2836259667354169965ULL, 5672519334708339930ULL, + 11345038669416679861ULL, 2269007733883335972ULL, 4538015467766671944ULL, + 9076030935533343889ULL, 18152061871066687778ULL, 3630412374213337555ULL, + 7260824748426675111ULL, 14521649496853350222ULL, 2904329899370670044ULL, + 5808659798741340089ULL, 11617319597482680178ULL, 2323463919496536035ULL, + 4646927838993072071ULL, 9293855677986144142ULL, 1858771135597228828ULL, + 3717542271194457656ULL, 7435084542388915313ULL, 14870169084777830627ULL, + 2974033816955566125ULL, 5948067633911132251ULL, 11896135267822264502ULL, + 2379227053564452900ULL, 4758454107128905800ULL, 9516908214257811601ULL, + 1903381642851562320ULL, 3806763285703124640ULL, 7613526571406249281ULL, + 15227053142812498563ULL, 3045410628562499712ULL, 6090821257124999425ULL, + 12181642514249998850ULL, 2436328502849999770ULL, 4872657005699999540ULL, + 9745314011399999080ULL, 1949062802279999816ULL, 3898125604559999632ULL, + 7796251209119999264ULL, 15592502418239998528ULL, 3118500483647999705ULL, + 6237000967295999411ULL, 12474001934591998822ULL, 2494800386918399764ULL, + 4989600773836799529ULL, 9979201547673599058ULL, 1995840309534719811ULL, + 3991680619069439623ULL, 7983361238138879246ULL, 15966722476277758493ULL, + 3193344495255551698ULL, 6386688990511103397ULL, 12773377981022206794ULL, + 2554675596204441358ULL, 5109351192408882717ULL, 10218702384817765435ULL, + 2043740476963553087ULL, 4087480953927106174ULL, 8174961907854212348ULL, + 16349923815708424697ULL, 3269984763141684939ULL, 6539969526283369878ULL, + 13079939052566739757ULL, 2615987810513347951ULL, 5231975621026695903ULL, + 10463951242053391806ULL, 2092790248410678361ULL, 4185580496821356722ULL, + 8371160993642713444ULL, 16742321987285426889ULL, 3348464397457085377ULL, + 6696928794914170755ULL, 13393857589828341511ULL, 2678771517965668302ULL, + 5357543035931336604ULL, 10715086071862673209ULL, 2143017214372534641ULL, + 4286034428745069283ULL, 8572068857490138567ULL, 17144137714980277135ULL, + 3428827542996055427ULL, 6857655085992110854ULL, 13715310171984221708ULL, + 2743062034396844341ULL, 5486124068793688683ULL, 10972248137587377366ULL, + 2194449627517475473ULL, 4388899255034950946ULL, 8777798510069901893ULL, + 17555597020139803786ULL, 3511119404027960757ULL, 7022238808055921514ULL, + 14044477616111843029ULL, 2808895523222368605ULL, 5617791046444737211ULL, + 11235582092889474423ULL, 2247116418577894884ULL, 4494232837155789769ULL, + 8988465674311579538ULL, 17976931348623159077ULL, 3595386269724631815ULL, + 7190772539449263630ULL, 14381545078898527261ULL, 2876309015779705452ULL, + 5752618031559410904ULL, 11505236063118821809ULL, 2301047212623764361ULL, + 4602094425247528723ULL, 9204188850495057447ULL, 18408377700990114895ULL, + 3681675540198022979ULL, 7363351080396045958ULL, +}; + +static const gint32 Formatter_TensExponentTable [] = { + -323, -323, -323, -322, -322, -322, -321, -321, -321, -320, -320, -320, + -319, -319, -319, -319, -318, -318, -318, -317, -317, -317, -316, -316, + -316, -316, -315, -315, -315, -314, -314, -314, -313, -313, -313, -313, + -312, -312, -312, -311, -311, -311, -310, -310, -310, -310, -309, -309, + -309, -308, -308, -308, -307, -307, -307, -307, -306, -306, -306, -305, + -305, -305, -304, -304, -304, -304, -303, -303, -303, -302, -302, -302, + -301, -301, -301, -301, -300, -300, -300, -299, -299, -299, -298, -298, + -298, -298, -297, -297, -297, -296, -296, -296, -295, -295, -295, -295, + -294, -294, -294, -293, -293, -293, -292, -292, -292, -291, -291, -291, + -291, -290, -290, -290, -289, -289, -289, -288, -288, -288, -288, -287, + -287, -287, -286, -286, -286, -285, -285, -285, -285, -284, -284, -284, + -283, -283, -283, -282, -282, -282, -282, -281, -281, -281, -280, -280, + -280, -279, -279, -279, -279, -278, -278, -278, -277, -277, -277, -276, + -276, -276, -276, -275, -275, -275, -274, -274, -274, -273, -273, -273, + -273, -272, -272, -272, -271, -271, -271, -270, -270, -270, -270, -269, + -269, -269, -268, -268, -268, -267, -267, -267, -267, -266, -266, -266, + -265, -265, -265, -264, -264, -264, -264, -263, -263, -263, -262, -262, + -262, -261, -261, -261, -260, -260, -260, -260, -259, -259, -259, -258, + -258, -258, -257, -257, -257, -257, -256, -256, -256, -255, -255, -255, + -254, -254, -254, -254, -253, -253, -253, -252, -252, -252, -251, -251, + -251, -251, -250, -250, -250, -249, -249, -249, -248, -248, -248, -248, + -247, -247, -247, -246, -246, -246, -245, -245, -245, -245, -244, -244, + -244, -243, -243, -243, -242, -242, -242, -242, -241, -241, -241, -240, + -240, -240, -239, -239, -239, -239, -238, -238, -238, -237, -237, -237, + -236, -236, -236, -236, -235, -235, -235, -234, -234, -234, -233, -233, + -233, -232, -232, -232, -232, -231, -231, -231, -230, -230, -230, -229, + -229, -229, -229, -228, -228, -228, -227, -227, -227, -226, -226, -226, + -226, -225, -225, -225, -224, -224, -224, -223, -223, -223, -223, -222, + -222, -222, -221, -221, -221, -220, -220, -220, -220, -219, -219, -219, + -218, -218, -218, -217, -217, -217, -217, -216, -216, -216, -215, -215, + -215, -214, -214, -214, -214, -213, -213, -213, -212, -212, -212, -211, + -211, -211, -211, -210, -210, -210, -209, -209, -209, -208, -208, -208, + -208, -207, -207, -207, -206, -206, -206, -205, -205, -205, -205, -204, + -204, -204, -203, -203, -203, -202, -202, -202, -201, -201, -201, -201, + -200, -200, -200, -199, -199, -199, -198, -198, -198, -198, -197, -197, + -197, -196, -196, -196, -195, -195, -195, -195, -194, -194, -194, -193, + -193, -193, -192, -192, -192, -192, -191, -191, -191, -190, -190, -190, + -189, -189, -189, -189, -188, -188, -188, -187, -187, -187, -186, -186, + -186, -186, -185, -185, -185, -184, -184, -184, -183, -183, -183, -183, + -182, -182, -182, -181, -181, -181, -180, -180, -180, -180, -179, -179, + -179, -178, -178, -178, -177, -177, -177, -177, -176, -176, -176, -175, + -175, -175, -174, -174, -174, -173, -173, -173, -173, -172, -172, -172, + -171, -171, -171, -170, -170, -170, -170, -169, -169, -169, -168, -168, + -168, -167, -167, -167, -167, -166, -166, -166, -165, -165, -165, -164, + -164, -164, -164, -163, -163, -163, -162, -162, -162, -161, -161, -161, + -161, -160, -160, -160, -159, -159, -159, -158, -158, -158, -158, -157, + -157, -157, -156, -156, -156, -155, -155, -155, -155, -154, -154, -154, + -153, -153, -153, -152, -152, -152, -152, -151, -151, -151, -150, -150, + -150, -149, -149, -149, -149, -148, -148, -148, -147, -147, -147, -146, + -146, -146, -145, -145, -145, -145, -144, -144, -144, -143, -143, -143, + -142, -142, -142, -142, -141, -141, -141, -140, -140, -140, -139, -139, + -139, -139, -138, -138, -138, -137, -137, -137, -136, -136, -136, -136, + -135, -135, -135, -134, -134, -134, -133, -133, -133, -133, -132, -132, + -132, -131, -131, -131, -130, -130, -130, -130, -129, -129, -129, -128, + -128, -128, -127, -127, -127, -127, -126, -126, -126, -125, -125, -125, + -124, -124, -124, -124, -123, -123, -123, -122, -122, -122, -121, -121, + -121, -121, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118, + -117, -117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, + -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -111, -110, + -110, -110, -109, -109, -109, -108, -108, -108, -108, -107, -107, -107, + -106, -106, -106, -105, -105, -105, -105, -104, -104, -104, -103, -103, + -103, -102, -102, -102, -102, -101, -101, -101, -100, -100, -100, -99, + -99, -99, -99, -98, -98, -98, -97, -97, -97, -96, -96, -96, + -96, -95, -95, -95, -94, -94, -94, -93, -93, -93, -93, -92, + -92, -92, -91, -91, -91, -90, -90, -90, -90, -89, -89, -89, + -88, -88, -88, -87, -87, -87, -86, -86, -86, -86, -85, -85, + -85, -84, -84, -84, -83, -83, -83, -83, -82, -82, -82, -81, + -81, -81, -80, -80, -80, -80, -79, -79, -79, -78, -78, -78, + -77, -77, -77, -77, -76, -76, -76, -75, -75, -75, -74, -74, + -74, -74, -73, -73, -73, -72, -72, -72, -71, -71, -71, -71, + -70, -70, -70, -69, -69, -69, -68, -68, -68, -68, -67, -67, + -67, -66, -66, -66, -65, -65, -65, -65, -64, -64, -64, -63, + -63, -63, -62, -62, -62, -62, -61, -61, -61, -60, -60, -60, + -59, -59, -59, -59, -58, -58, -58, -57, -57, -57, -56, -56, + -56, -55, -55, -55, -55, -54, -54, -54, -53, -53, -53, -52, + -52, -52, -52, -51, -51, -51, -50, -50, -50, -49, -49, -49, + -49, -48, -48, -48, -47, -47, -47, -46, -46, -46, -46, -45, + -45, -45, -44, -44, -44, -43, -43, -43, -43, -42, -42, -42, + -41, -41, -41, -40, -40, -40, -40, -39, -39, -39, -38, -38, + -38, -37, -37, -37, -37, -36, -36, -36, -35, -35, -35, -34, + -34, -34, -34, -33, -33, -33, -32, -32, -32, -31, -31, -31, + -31, -30, -30, -30, -29, -29, -29, -28, -28, -28, -27, -27, + -27, -27, -26, -26, -26, -25, -25, -25, -24, -24, -24, -24, + -23, -23, -23, -22, -22, -22, -21, -21, -21, -21, -20, -20, + -20, -19, -19, -19, -18, -18, -18, -18, -17, -17, -17, -16, + -16, -16, -15, -15, -15, -15, -14, -14, -14, -13, -13, -13, + -12, -12, -12, -12, -11, -11, -11, -10, -10, -10, -9, -9, + -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -6, + -5, -5, -5, -4, -4, -4, -3, -3, -3, -3, -2, -2, + -2, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 2, + 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, + 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, + 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, + 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, + 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20, + 20, 20, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, + 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, + 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, + 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, + 35, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, + 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 41, + 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, + 45, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 49, + 49, 49, 50, 50, 50, 50, 51, 51, 51, 52, 52, 52, + 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, + 56, 56, 57, 57, 57, 58, 58, 58, 59, 59, 59, 60, + 60, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63, 63, + 63, 64, 64, 64, 65, 65, 65, 66, 66, 66, 66, 67, + 67, 67, 68, 68, 68, 69, 69, 69, 69, 70, 70, 70, + 71, 71, 71, 72, 72, 72, 72, 73, 73, 73, 74, 74, + 74, 75, 75, 75, 75, 76, 76, 76, 77, 77, 77, 78, + 78, 78, 78, 79, 79, 79, 80, 80, 80, 81, 81, 81, + 81, 82, 82, 82, 83, 83, 83, 84, 84, 84, 84, 85, + 85, 85, 86, 86, 86, 87, 87, 87, 87, 88, 88, 88, + 89, 89, 89, 90, 90, 90, 91, 91, 91, 91, 92, 92, + 92, 93, 93, 93, 94, 94, 94, 94, 95, 95, 95, 96, + 96, 96, 97, 97, 97, 97, 98, 98, 98, 99, 99, 99, + 100, 100, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, + 103, 103, 104, 104, 104, 105, 105, 105, 106, 106, 106, 106, + 107, 107, 107, 108, 108, 108, 109, 109, 109, 109, 110, 110, + 110, 111, 111, 111, 112, 112, 112, 112, 113, 113, 113, 114, + 114, 114, 115, 115, 115, 115, 116, 116, 116, 117, 117, 117, + 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 121, 121, + 121, 122, 122, 122, 122, 123, 123, 123, 124, 124, 124, 125, + 125, 125, 125, 126, 126, 126, 127, 127, 127, 128, 128, 128, + 128, 129, 129, 129, 130, 130, 130, 131, 131, 131, 131, 132, + 132, 132, 133, 133, 133, 134, 134, 134, 134, 135, 135, 135, + 136, 136, 136, 137, 137, 137, 137, 138, 138, 138, 139, 139, + 139, 140, 140, 140, 140, 141, 141, 141, 142, 142, 142, 143, + 143, 143, 143, 144, 144, 144, 145, 145, 145, 146, 146, 146, + 146, 147, 147, 147, 148, 148, 148, 149, 149, 149, 150, 150, + 150, 150, 151, 151, 151, 152, 152, 152, 153, 153, 153, 153, + 154, 154, 154, 155, 155, 155, 156, 156, 156, 156, 157, 157, + 157, 158, 158, 158, 159, 159, 159, 159, 160, 160, 160, 161, + 161, 161, 162, 162, 162, 162, 163, 163, 163, 164, 164, 164, + 165, 165, 165, 165, 166, 166, 166, 167, 167, 167, 168, 168, + 168, 168, 169, 169, 169, 170, 170, 170, 171, 171, 171, 171, + 172, 172, 172, 173, 173, 173, 174, 174, 174, 174, 175, 175, + 175, 176, 176, 176, 177, 177, 177, 178, 178, 178, 178, 179, + 179, 179, 180, 180, 180, 181, 181, 181, 181, 182, 182, 182, + 183, 183, 183, 184, 184, 184, 184, 185, 185, 185, 186, 186, + 186, 187, 187, 187, 187, 188, 188, 188, 189, 189, 189, 190, + 190, 190, 190, 191, 191, 191, 192, 192, 192, 193, 193, 193, + 193, 194, 194, 194, 195, 195, 195, 196, 196, 196, 196, 197, + 197, 197, 198, 198, 198, 199, 199, 199, 199, 200, 200, 200, + 201, 201, 201, 202, 202, 202, 202, 203, 203, 203, 204, 204, + 204, 205, 205, 205, 206, 206, 206, 206, 207, 207, 207, 208, + 208, 208, 209, 209, 209, 209, 210, 210, 210, 211, 211, 211, + 212, 212, 212, 212, 213, 213, 213, 214, 214, 214, 215, 215, + 215, 215, 216, 216, 216, 217, 217, 217, 218, 218, 218, 218, + 219, 219, 219, 220, 220, 220, 221, 221, 221, 221, 222, 222, + 222, 223, 223, 223, 224, 224, 224, 224, 225, 225, 225, 226, + 226, 226, 227, 227, 227, 227, 228, 228, 228, 229, 229, 229, + 230, 230, 230, 230, 231, 231, 231, 232, 232, 232, 233, 233, + 233, 233, 234, 234, 234, 235, 235, 235, 236, 236, 236, 237, + 237, 237, 237, 238, 238, 238, 239, 239, 239, 240, 240, 240, + 240, 241, 241, 241, 242, 242, 242, 243, 243, 243, 243, 244, + 244, 244, 245, 245, 245, 246, 246, 246, 246, 247, 247, 247, + 248, 248, 248, 249, 249, 249, 249, 250, 250, 250, 251, 251, + 251, 252, 252, 252, 252, 253, 253, 253, 254, 254, 254, 255, + 255, 255, 255, 256, 256, 256, 257, 257, 257, 258, 258, 258, + 258, 259, 259, 259, 260, 260, 260, 261, 261, 261, 261, 262, + 262, 262, 263, 263, 263, 264, 264, 264, 265, 265, 265, 265, + 266, 266, 266, 267, 267, 267, 268, 268, 268, 268, 269, 269, + 269, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 273, + 273, 273, 274, 274, 274, 274, 275, 275, 275, 276, 276, 276, + 277, 277, 277, 277, 278, 278, 278, 279, 279, 279, 280, 280, + 280, 280, 281, 281, 281, 282, 282, 282, 283, 283, 283, 283, + 284, 284, 284, 285, 285, 285, 286, 286, 286, 286, 287, 287, + 287, 288, 288, 288, 289, 289, 289, 289, 290, 290, 290, 291, + 291, 291, 292, 292, 292, 292, 293, 293, +}; + +static const gunichar2 Formatter_DigitLowerTable [] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' +}; + +static const gunichar2 Formatter_DigitUpperTable [] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' +}; + +static gint64 Formatter_TenPowersList [] = { + 1LL, + 10LL, + 100LL, + 1000LL, + 10000LL, + 100000LL, + 1000000LL, + 10000000LL, + 100000000LL, + 1000000000LL, + 10000000000LL, + 100000000000LL, + 1000000000000LL, + 10000000000000LL, + 100000000000000LL, + 1000000000000000LL, + 10000000000000000LL, + 100000000000000000LL, + 1000000000000000000LL, +}; + +// DecHexDigits s a translation table from a decimal number to its +// digits hexadecimal representation (e.g. DecHexDigits [34] = 0x34). +static gint32 Formatter_DecHexDigits [] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, +}; + +#endif From nicolas.geoffray at lip6.fr Tue Jul 15 01:47:50 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 15 Jul 2008 08:47:50 -0000 Subject: [vmkit-commits] [vmkit] r53593 - /vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Message-ID: <200807150847.m6F8loGY023805@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 15 03:47:50 2008 New Revision: 53593 URL: http://llvm.org/viewvc/llvm-project?rev=53593&view=rev Log: Look at all sections when finding array data. Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp?rev=53593&r1=53592&r2=53593&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Tue Jul 15 03:47:50 2008 @@ -38,10 +38,17 @@ Assembly* ass = type->assembly; uint32 rva = ass->getRVAFromField(field->token); - Section* rsrcSection = ass->rsrcSection; + Section* inSection = 0; + + if (rva >= ass->rsrcSection->virtualAddress && rva < ass->rsrcSection->virtualAddress + ass->rsrcSection->virtualSize) + inSection = ass->rsrcSection; + if (rva >= ass->textSection->virtualAddress && rva < ass->textSection->virtualAddress + ass->textSection->virtualSize) + inSection = ass->textSection; + if (rva >= ass->relocSection->virtualAddress && rva < ass->relocSection->virtualAddress + ass->relocSection->virtualSize) + inSection = ass->relocSection; uint32 size = array->size; - uint32 offset = rsrcSection->rawAddress + (rva - rsrcSection->virtualAddress); + uint32 offset = inSection->rawAddress + (rva - inSection->virtualAddress); ArrayUInt8* bytes = ass->bytes; if (bs == MSCorlib::pChar) { From nicolas.geoffray at lip6.fr Tue Jul 15 01:49:05 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 15 Jul 2008 08:49:05 -0000 Subject: [vmkit-commits] [vmkit] r53594 - /vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Message-ID: <200807150849.m6F8n6gc023868@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 15 03:49:05 2008 New Revision: 53594 URL: http://llvm.org/viewvc/llvm-project?rev=53594&view=rev Log: Bugfix for ElementTypePINNED and don't add it to the list of locals. Currenty, the PINNED info is ignored. Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=53594&r1=53593&r2=53594&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Tue Jul 15 03:49:05 2008 @@ -279,7 +279,6 @@ } static VMCommonClass* METHOD_ElementTypePinned(uint32 op, Assembly* ass, uint32& offset) { - VMThread::get()->vm->error("implement me"); return 0; } @@ -353,6 +352,7 @@ unimplemented, // 0x3D unimplemented, // 0x3E unimplemented, // 0x3F + unimplemented, // 0x40 METHOD_ElementTypeSentinel, // 0x41 unimplemented, // 0x42 unimplemented, // 0x43 @@ -406,7 +406,9 @@ } for (uint32 i = 0; i < nbLocals; ++i) { - locals.push_back(exploreType(offset)); + VMCommonClass* cl = exploreType(offset); + if (!cl) --i; // PINNED + else locals.push_back(cl); } } @@ -434,7 +436,7 @@ VMCommonClass* Assembly::exploreType(uint32& offset) { uint32 op = READ_U1(bytes, offset); - //printf("reading %s\n", signatureNames[op]); + assert(op < 0x46 && "unknown signature type"); return (signatureVector[op])(op, this, offset); } From nicolas.geoffray at lip6.fr Tue Jul 15 01:50:46 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 15 Jul 2008 08:50:46 -0000 Subject: [vmkit-commits] [vmkit] r53595 - /vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Message-ID: <200807150850.m6F8okhS023942@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 15 03:50:46 2008 New Revision: 53595 URL: http://llvm.org/viewvc/llvm-project?rev=53595&view=rev Log: If setVirtualField is a struct, do a memcpy. Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=53595&r1=53594&r2=53595&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Tue Jul 15 03:50:46 2008 @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -//#define DEBUG 0 -//#define N3_COMPILE 0 -//#define N3_EXECUTE 0 +#define DEBUG 0 +#define N3_COMPILE 0 +#define N3_EXECUTE 0 #include "debug.h" #include "types.h" @@ -741,15 +741,28 @@ ptr = GetElementPtrInst::Create(obj, args.begin(), args.end(), "", currentBlock); } + + if (field->signature->super == MSCorlib::pValue && + field->signature->virtualFields.size() > 1) { + uint64 size = mvm::jit::getTypeSize(field->signature->naturalType); + + std::vector params; + params.push_back(new BitCastInst(ptr, PointerType::getUnqual(Type::Int8Ty), "", currentBlock)); + params.push_back(new BitCastInst(val, PointerType::getUnqual(Type::Int8Ty), "", currentBlock)); + params.push_back(ConstantInt::get(Type::Int32Ty, size)); + params.push_back(mvm::jit::constantZero); + CallInst::Create(mvm::jit::llvm_memcpy_i32, params.begin(), params.end(), "", currentBlock); - type = field->signature->naturalType; - if (val == constantVMObjectNull) { - val = Constant::getNullValue(type); - } else if (type != valType) { - val = changeType(val, type); - } + } else { + type = field->signature->naturalType; + if (val == constantVMObjectNull) { + val = Constant::getNullValue(type); + } else if (type != valType) { + val = changeType(val, type); + } - new StoreInst(val, ptr, isVolatile, currentBlock); + new StoreInst(val, ptr, isVolatile, currentBlock); + } } void CLIJit::setStaticField(uint32 value, bool isVolatile) { @@ -1121,6 +1134,30 @@ } +#if N3_EXECUTE > 1 +static void printArgs(std::vector args, BasicBlock* insertAt) { + for (std::vector::iterator i = args.begin(), + e = args.end(); i!= e; ++i) { + llvm::Value* arg = *i; + const llvm::Type* type = arg->getType(); + if (type == Type::Int8Ty || type == Type::Int16Ty || type == Type::Int1Ty) { + CallInst::Create(mvm::jit::printIntLLVM, new ZExtInst(arg, Type::Int32Ty, "", insertAt), "", insertAt); + } else if (type == Type::Int32Ty) { + CallInst::Create(mvm::jit::printIntLLVM, arg, "", insertAt); + } else if (type == Type::Int64Ty) { + CallInst::Create(mvm::jit::printLongLLVM, arg, "", insertAt); + } else if (type == Type::FloatTy) { + CallInst::Create(mvm::jit::printFloatLLVM, arg, "", insertAt); + } else if (type == Type::DoubleTy) { + CallInst::Create(mvm::jit::printDoubleLLVM, arg, "", insertAt); + } else { + CallInst::Create(mvm::jit::printIntLLVM, new PtrToIntInst(arg, Type::Int32Ty, "", insertAt), "", insertAt); + } + } + +} +#endif + Function* CLIJit::compileFatOrTiny() { PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "tiny or fat compile %s\n", compilingMethod->printString()); @@ -1240,6 +1277,11 @@ endBlock->eraseFromParent(); } else { if (endType != Type::VoidTy) { +#if N3_EXECUTE > 1 + std::vector args; + args.push_back(endNode); + printArgs(args, endBlock); +#endif ReturnInst::Create(endNode, endBlock); } else if (compilingMethod->structReturn) { const Type* lastType = @@ -2013,30 +2055,6 @@ Constant* CLIJit::constantVMObjectNull; -#if N3_EXECUTE > 1 -static void printArgs(std::vector args, BasicBlock* insertAt) { - for (std::vector::iterator i = args.begin(), - e = args.end(); i!= e; ++i) { - llvm::Value* arg = *i; - const llvm::Type* type = arg->getType(); - if (type == Type::Int8Ty || type == Type::Int16Ty || type == Type::Int1Ty) { - CallInst::Create(mvm::jit::printIntLLVM, new ZExtInst(arg, Type::Int32Ty, "", insertAt), "", insertAt); - } else if (type == Type::Int32Ty) { - CallInst::Create(mvm::jit::printIntLLVM, arg, "", insertAt); - } else if (type == Type::Int64Ty) { - CallInst::Create(mvm::jit::printLongLLVM, arg, "", insertAt); - } else if (type == Type::FloatTy) { - CallInst::Create(mvm::jit::printFloatLLVM, arg, "", insertAt); - } else if (type == Type::DoubleTy) { - CallInst::Create(mvm::jit::printDoubleLLVM, arg, "", insertAt); - } else { - CallInst::Create(mvm::jit::printObjectLLVM, new BitCastInst(arg, mvm::jit::ptrType, "", insertAt), "", insertAt); - } - } - -} -#endif - Value* CLIJit::invoke(Value *F, std::vector args, const char* Name, BasicBlock *InsertAtEnd, bool structReturn) { From nicolas.geoffray at lip6.fr Tue Jul 15 01:51:31 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 15 Jul 2008 08:51:31 -0000 Subject: [vmkit-commits] [vmkit] r53596 - /vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Message-ID: <200807150851.m6F8pV1m023977@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 15 03:51:31 2008 New Revision: 53596 URL: http://llvm.org/viewvc/llvm-project?rev=53596&view=rev Log: Implement INITOBJ. Bugfix for ADD. Modified: vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Modified: vmkit/trunk/lib/N3/VMCore/Opcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Opcodes.cpp?rev=53596&r1=53595&r2=53596&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Opcodes.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Tue Jul 15 03:51:31 2008 @@ -206,7 +206,7 @@ for(uint32 i = 0; i < codeLength; ++i) { if (bytecodes[i] != 0xFE) { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %x] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5x] %-5d ", i, bytecodes[i]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "compiling %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNames[bytecodes[i]]); @@ -247,9 +247,15 @@ case ADD: { Value* val2 = pop(); + bool isPointer = (val2->getType() == mvm::jit::ptrType); Value* val1 = pop(); + isPointer |= (val1->getType() == mvm::jit::ptrType); verifyType(val1, val2, currentBlock); - push(BinaryOperator::createAdd(val1, val2, "", currentBlock)); + Value* res = BinaryOperator::createAdd(val1, val2, "", currentBlock); + if (isPointer) { + res = new IntToPtrInst(res, mvm::jit::ptrType, "", currentBlock); + } + push(res); break; } @@ -1547,7 +1553,7 @@ if (!(cl->super == MSCorlib::pValue || cl->super == MSCorlib::pEnum)) { push(new LoadInst(pop(), "", isVolatile, currentBlock)); isVolatile = false; - } + } break; } @@ -1816,7 +1822,7 @@ } case 0xFE : { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %x] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5x] %-5d ", i, bytecodes[i + 1]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "compiling %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNamesFE[bytecodes[i + 1]]); @@ -1940,7 +1946,24 @@ } case INITOBJ : { - VMThread::get()->vm->error("implement me"); + uint32 token = readU4(bytecodes, i); + Assembly* assembly = compilingClass->assembly; + N3* vm = (N3*)(VMThread::get()->vm); + VMCommonClass* type = assembly->loadType(vm, token, true, false, false, + true); + if (type->super == MSCorlib::pValue) { + uint64 size = mvm::jit::getTypeSize(type->naturalType); + + std::vector params; + params.push_back(new BitCastInst(pop(), mvm::jit::ptrType, "", + currentBlock)); + params.push_back(mvm::jit::constantInt8Zero); + params.push_back(ConstantInt::get(Type::Int32Ty, size)); + params.push_back(mvm::jit::constantZero); + CallInst::Create(mvm::jit::llvm_memset_i32, params.begin(), + params.end(), "", currentBlock); + } + break; } @@ -1995,7 +2018,7 @@ for(uint32 i = 0; i < codeLength; ++i) { if (bytecodes[i] != 0xFE) { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5d] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5x] %-5d ", i, bytecodes[i]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "exploring %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNames[bytecodes[i]]); @@ -2439,7 +2462,7 @@ case 0xFE : { - PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5d] %-5d ", i, + PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "\t[at %5x] %-5d ", i, bytecodes[i + 1]); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_BLUE, "exploring %s::", compilingMethod->printString()); PRINT_DEBUG(N3_COMPILE, 1, LIGHT_CYAN, OpcodeNamesFE[bytecodes[i + 1]]); @@ -2504,7 +2527,7 @@ } case INITOBJ : { - VMThread::get()->vm->error("implement me"); + i += 4; break; } From nicolas.geoffray at lip6.fr Tue Jul 15 01:52:53 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 15 Jul 2008 08:52:53 -0000 Subject: [vmkit-commits] [vmkit] r53597 - /vmkit/trunk/lib/N3/Mono/Mono.cpp Message-ID: <200807150852.m6F8qrqP024029@zion.cs.uiuc.edu> Author: geoffray Date: Tue Jul 15 03:52:52 2008 New Revision: 53597 URL: http://llvm.org/viewvc/llvm-project?rev=53597&view=rev Log: Implement Mono functions. Modified: vmkit/trunk/lib/N3/Mono/Mono.cpp Modified: vmkit/trunk/lib/N3/Mono/Mono.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/Mono.cpp?rev=53597&r1=53596&r2=53597&view=diff ============================================================================== --- vmkit/trunk/lib/N3/Mono/Mono.cpp (original) +++ vmkit/trunk/lib/N3/Mono/Mono.cpp Tue Jul 15 03:52:52 2008 @@ -250,3 +250,90 @@ { return 0; } + +extern "C" VMObject* System_Object_MemberwiseClone(VMObject* obj) { + uint64 size = obj->objectSize(); + VMObject* res = (VMObject*)gc::operator new(size, obj->getVirtualTable()); + memcpy(res, obj, size); + res->lockObj = 0; + return res; +} + +extern "C" bool +System_Globalization_CultureInfo_construct_internal_locale_from_current_locale (VMObject *ci) +{ + return false; +} + +extern "C" void +System_Threading_Thread_SetCachedCurrentCulture (VMObject* thread, VMObject *culture) +{ +} + +extern "C" void +System_String__ctor(MonoString* str, ArrayUInt16* array, sint32 startIndex, sint32 count) { + VirtualMachine* vm = VMThread::get()->vm; + const UTF8* utf8 = vm->readerConstructUTF8(&(array->elements[startIndex]), count); + str->length = count; + str->startChar = array->elements[startIndex]; + str->value = utf8; +} + +extern "C" MonoString * +System_String_InternalJoin (MonoString *separator, VMArray * value, sint32 sindex, sint32 count) +{ + MonoString *current; + sint32 length; + sint32 pos; + sint32 insertlen; + sint32 destpos; + sint32 srclen; + const uint16 *insert; + const uint16 *src; + uint16 *dest; + + insert = separator->value->elements; + insertlen = separator->length; + + length = 0; + for (pos = sindex; pos != sindex + count; pos++) { + current = (MonoString*)value->elements[pos]; + if (current != NULL) + length += current->length; + + if (pos < sindex + count - 1) + length += insertlen; + } + + dest = (uint16*)alloca(length * sizeof(uint16)); + destpos = 0; + + for (pos = sindex; pos != sindex + count; pos++) { + current = (MonoString*)value->elements[pos]; + if (current != NULL) { + src = current->value->elements; + srclen = current->length; + + memcpy (dest + destpos, src, srclen * sizeof(uint16)); + destpos += srclen; + } + + if (pos < sindex + count - 1) { + memcpy(dest + destpos, insert, insertlen * sizeof(uint16)); + destpos += insertlen; + } + } + + N3* vm = (N3*)VMThread::get()->vm; + const UTF8* utf8 = vm->readerConstructUTF8(dest, length); + return (MonoString*)vm->UTF8ToStr(utf8); +} + +extern "C" MonoString * +System_String_InternalAllocateStr (sint32 length) +{ + MonoString* str = (MonoString*)(MSCorlib::pString->doNew()); + str->length = length; + return str; +} + From tilmann.scheller at googlemail.com Sun Jul 27 12:42:11 2008 From: tilmann.scheller at googlemail.com (Tilmann Scheller) Date: Sun, 27 Jul 2008 19:42:11 -0000 Subject: [vmkit-commits] [vmkit] r54126 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h CLISignature.cpp Message-ID: <200807271942.m6RJgBLf000386@zion.cs.uiuc.edu> Author: tilmann Date: Sun Jul 27 14:42:11 2008 New Revision: 54126 URL: http://llvm.org/viewvc/llvm-project?rev=54126&view=rev Log: add basic support for MethodSpecs Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp vmkit/trunk/lib/N3/VMCore/Assembly.h vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=54126&r1=54125&r2=54126&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sun Jul 27 14:42:11 2008 @@ -1754,6 +1754,7 @@ VMMethod* Assembly::readMethodSpec(uint32 token) { uint32 index = token & 0xffff; + uint32 blobOffset = CLIHeader->blobStream->realOffset; Table* methodTable = CLIHeader->tables[CONSTANT_MethodSpec]; uint32* methodArray = (uint32*) alloca(sizeof(uint32) * methodTable->rowSize); @@ -1763,6 +1764,27 @@ uint32 method = methodArray[CONSTANT_METHOD_SPEC_METHOD]; uint32 instantiation = methodArray[CONSTANT_METHOD_SPEC_INSTANTIATION]; + uint32 offset = blobOffset + instantiation; + + std::vector genArgs; + methodSpecSignature(offset, genArgs); + + uint32 table = method & 1; + index = method >> 1; + + uint32 methodToken; + + switch (table) { + case 0 : { + methodToken = index + (CONSTANT_MethodDef << 24); + break; + } + case 1 : { + methodToken = index + (CONSTANT_MemberRef << 24); + return readMemberRefAsMethod(methodToken); + } + } + VMThread::get()->vm->error("MethodSpec"); // return NULL; return (VMMethod*) (method ^ instantiation); Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=54126&r1=54125&r2=54126&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/Assembly.h (original) +++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sun Jul 27 14:42:11 2008 @@ -234,6 +234,8 @@ bool isGenericMethod(uint32& offset); void localVarSignature(uint32& offset, std::vector& locals); + void methodSpecSignature(uint32& offset, + std::vector& genArgs); VMCommonClass* extractFieldSignature(uint32& offset); VMCommonClass* extractTypeInSignature(uint32& offset); VMCommonClass* exploreType(uint32& offset); Modified: vmkit/trunk/lib/N3/VMCore/CLISignature.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLISignature.cpp?rev=54126&r1=54125&r2=54126&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLISignature.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLISignature.cpp Sun Jul 27 14:42:11 2008 @@ -394,6 +394,22 @@ return callingConvention & CONSTANT_Generic ? true : false; } +void Assembly::methodSpecSignature(uint32& offset, + std::vector& genArgs) { + uncompressSignature(offset); // count + uint32 genericSig = uncompressSignature(offset); + + if (genericSig != 0x0a) { + VMThread::get()->vm->error("unknown methodSpec sig %x", genericSig); + } + + uint32 genArgCount = uncompressSignature(offset); + + for (uint32 i = 0; i < genArgCount; i++) { + genArgs.push_back(exploreType(offset)); + } +} + void Assembly::localVarSignature(uint32& offset, std::vector& locals) { //uint32 count =