Added necessary glue code to make nanojit compile in DEBUG mode.
authorAndreas Gal <gal@uci.edu>
Thu, 19 Jun 2008 15:32:40 -0700
changeset 17276 8c621db6a231a8c9d47a164f86785455afe3b977
parent 17275 378807e85abc0e91a11fb3c414b85d265c356ca8
child 17277 d7f7e6fe6ebe505772fbd4f30b863e8a88440c4c
push id1452
push usershaver@mozilla.com
push dateFri, 22 Aug 2008 00:08:22 +0000
treeherdermozilla-central@d13bb0868596 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a1pre
Added necessary glue code to make nanojit compile in DEBUG mode.
js/src/nanojit/avmplus.cpp
js/src/nanojit/avmplus.h
--- a/js/src/nanojit/avmplus.cpp
+++ b/js/src/nanojit/avmplus.cpp
@@ -33,9 +33,9 @@
 #include "avmplus.h"
 
 using namespace avmplus;
 
 AvmConfiguration AvmCore::config;
 static GC _gc;
 GC* AvmCore::gc = &_gc;
 GCHeap GC::heap;
-
+String* AvmCore::k_str[] = { (String*)"" };
--- a/js/src/nanojit/avmplus.h
+++ b/js/src/nanojit/avmplus.h
@@ -41,20 +41,22 @@
 #ifdef _MSC_VER
 #define __msvc_only(x)  x
 #else
 #define __msvc_only(x)
 #endif
 
 #define FASTCALL
 
-//#ifdef DEBUG
-//#define _DEBUG
-//#define NJ_VERBOSE
-//#endif
+#ifdef DEBUG
+#define _DEBUG
+#define NJ_VERBOSE
+#define NJ_PROFILE
+#include <stdarg.h>
+#endif
 
 #define AvmAssert(x) assert(x)
 #define AvmAssertMsg(x, y) 
 #define AvmDebugLog(x) printf x
 
 typedef JSUint8 uint8_t;
 typedef JSUint16 uint16_t;
 typedef JSUint32 uint32_t;
@@ -66,19 +68,19 @@ class GCObject
 
 class GCFinalizedObject
 {
 };
 
 class GCHeap
 {
 public:
-    uint32_t kNativePageSize;
-    
-    GCHeap() 
+    int32_t kNativePageSize;
+
+    GCHeap()
     {
         kNativePageSize = 4096; // @todo: what is this?
     }
     
     inline void*
     Alloc(uint32_t pages) 
     {
         void* p = malloc((pages + 1) * kNativePageSize);
@@ -94,16 +96,22 @@ public:
     
 };
 
 class GC 
 {
     static GCHeap heap;
     
 public:
+    static inline void*
+    Alloc(uint32_t bytes)
+    {
+        return (void*) new char[bytes];
+    }
+
     static inline void
     Free(void* p)
     {
     }
     
     static inline GCHeap*
     GetGCHeap()
     {
@@ -113,61 +121,174 @@ public:
 
 inline void*
 operator new(size_t size, GC* gc)
 {
     return (void*)new char[size];
 }
 
 #define DWB(x) x
+#define DRCWB(x) x
 
 #define MMGC_MEM_TYPE(x)
 
 typedef int FunctionID;
 
 namespace avmplus
 {
+    typedef const uint16_t* FOpcodep;
+
     class InterpState
     {
     public:
         void* f;
-        const uint16_t* ip;
+        FOpcodep ip;
         void* rp;
         void* sp;
     };
 
-    class AvmConfiguration 
+    class String
+    {
+    };
+
+    class StringNullTerminatedUTF8
+    {
+        const char* cstr;
+
+    public:
+        StringNullTerminatedUTF8(GC* gc, String* s)
+        {
+            cstr = strdup((const char*)s);
+        }
+
+        ~StringNullTerminatedUTF8()
+        {
+            free((void*)cstr);
+        }
+
+        inline
+        const char* c_str()
+        {
+            return cstr;
+        }
+    };
+
+    typedef String* Stringp;
+
+    class AvmConfiguration
     {
     public:
         AvmConfiguration() {
             memset(this, 0, sizeof(AvmConfiguration));
+#ifdef DEBUG
+            verbose = 1;
+            verbose_addrs = 1;
+            verbose_exits = 1;
+            verbose_live = 1;
+            show_stats = 1;
+#endif
         }
         
         uint32_t tree_opt:1;
+        uint32_t quiet_opt:1;
+        uint32_t verbose:1;
+        uint32_t verbose_addrs:1;
+        uint32_t verbose_live:1;
+        uint32_t verbose_exits:1;
+        uint32_t show_stats:1;
+    };
+
+    static const int kstrconst_emptyString = 0;
+
+    class AvmInterpreter
+    {
+        class Labels {
+        public:
+            const char* format(FOpcodep ip)
+            {
+                static char buf[33];
+                sprintf(buf, "%p", ip);
+                return buf;
+            }
+        };
+
+        Labels _labels;
+    public:
+        Labels* labels;
+
+        AvmInterpreter()
+        {
+            labels = &_labels;
+        }
+
     };
     
-    class AvmCore 
+    class AvmConsole 
     {
     public:
+        AvmConsole& operator<<(const char* s)
+        {
+            fprintf(stderr, "%s", s);
+            return *this;
+        }
+    };
+
+    class AvmCore
+    {
+    public:
+        AvmInterpreter interp;
+        AvmConsole console;
+
         static AvmConfiguration config;
         static GC* gc;
-        
-        static inline bool 
-        use_sse2() 
+        static String* k_str[];
+
+        static inline bool
+        use_sse2()
         {
             return true;
         }
 
+        static inline bool
+        quiet_opt()
+        {
+            return config.quiet_opt;
+        }
+
+        static inline bool
+        verbose()
+        {
+            return config.verbose;
+        }
+
         static inline GC*
         GetGC() 
         {
             return gc;
         }
+
+        static inline String* newString(const char* cstr) {
+            return (String*)strdup(cstr);
+        }
     };
-    
+
+    static inline
+    void writeln(AvmCore* core, const char* s)
+    {
+        fprintf(stderr, "%s\n", s);
+    }
+
+    static inline
+    const char* formatLabel(AvmCore* core, FOpcodep ip)
+    {
+        static char buffer[16];
+        printf(buffer, "%lx", ip);
+        return buffer;
+    }
+
     class OSDep
     {
     public:
         static inline void
         getDate()
         {
         }
     };