* src/threads/threadlist.c: Moved to .cpp.
[cacao.git] / src / vm / jit / linenumbertable.c
index 9909fc0c57641560603a77aa6aaf991e01c50a66..6a1de8138eb3008d859342b735e81e5c0cf54bd8 100644 (file)
@@ -1,7 +1,7 @@
 /* src/vm/jit/linenumbertable.c - linenumber handling stuff
 
    Copyright (C) 2007
-   CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 
 #include "mm/memory.h"
 
-#include "vm/jit/code.h"
-#include "vm/jit/codegen-common.h"
-#include "vm/jit/linenumbertable.h"
+#include "toolbox/list.hpp"
 
 #if defined(ENABLE_STATISTICS)
-# include "vmcore/options.h"
-# include "vmcore/statistics.h"
+# include "vm/options.h"
+# include "vm/statistics.h"
 #endif
 
+#include "vm/jit/code.hpp"
+#include "vm/jit/codegen-common.hpp"
+#include "vm/jit/linenumbertable.h"
+
+
+#if defined(__S390__)
+#  define ADDR_MASK(type, x) ((type)((uintptr_t)(x) & 0x7FFFFFFF))
+#else
+#  define ADDR_MASK(type, x) (x)
+#endif
 
 /* linenumbertable_create ******************************************************
 
@@ -54,7 +62,8 @@ void linenumbertable_create(jitdata *jd)
        codegendata                  *cd;
        linenumbertable_t            *lnt;
        linenumbertable_entry_t      *lnte;
-       list_t                       *l;
+       List*                         l;
+       void*                         it;
        linenumbertable_list_entry_t *le;
        uint8_t                      *pv;
        void                         *pc;
@@ -68,13 +77,13 @@ void linenumbertable_create(jitdata *jd)
 
        l = cd->linenumbers;
 
-       if (l->size == 0)
+       if (List_size(l) == 0)
                return;
 
        /* Allocate the linenumber table and the entries array. */
 
        lnt  = NEW(linenumbertable_t);
-       lnte = MNEW(linenumbertable_entry_t, l->size);
+       lnte = MNEW(linenumbertable_entry_t, List_size(l));
 
 #if defined(ENABLE_STATISTICS)
        if (opt_stat) {
@@ -82,22 +91,26 @@ void linenumbertable_create(jitdata *jd)
 
                size_linenumbertable +=
                        sizeof(linenumbertable_t) +
-                       sizeof(linenumbertable_entry_t) * l->size;
+                       sizeof(linenumbertable_entry_t) * List_size(l);
        }
 #endif
 
        /* Fill the linenumber table. */
 
-       lnt->length  = l->size;
+       lnt->length  = List_size(l);
        lnt->entries = lnte;
 
        /* Fill the linenumber table entries in reverse order, so the
           search can be forward. */
 
-       pv = code->entrypoint;
+       /* FIXME I only made this change to prevent a problem when moving
+          to C++. This should be changed back when this file has
+          converted to C++. */
+
+       pv = ADDR_MASK(uint8_t *, code->entrypoint);
 
-       for (le = list_last_unsynced(l); le != NULL;
-                le = list_prev_unsynced(l, le), lnte++) {
+       for (it = List_iterator_begin(l); it != List_iterator_end(l); it = List_iterator_plusplus(it), lnte++) {
+               le = (linenumbertable_list_entry_t*) List_iterator_deref(it);
                /* If the entry contains an mcode pointer (normal case),
                   resolve it (see doc/inlining_stacktrace.txt for
                   details). */
@@ -138,7 +151,7 @@ void linenumbertable_list_entry_add(codegendata *cd, int32_t linenumber)
        le->linenumber = linenumber;
        le->mpc        = cd->mcodeptr - cd->mcodebase;
 
-       list_add_last_unsynced(cd->linenumbers, le);
+       DumpList_push_front(cd->linenumbers, le);
 }
 
 
@@ -164,7 +177,7 @@ void linenumbertable_list_entry_add_inline_start(codegendata *cd, instruction *i
        le->linenumber = (-2); /* marks start of inlined method */
        le->mpc        = (mpc = cd->mcodeptr - cd->mcodebase);
 
-       list_add_last_unsynced(cd->linenumbers, le);
+       DumpList_push_front(cd->linenumbers, le);
 
        insinfo = iptr->sx.s23.s3.inlineinfo;
 
@@ -201,7 +214,7 @@ void linenumbertable_list_entry_add_inline_end(codegendata *cd, instruction *ipt
        le->linenumber = (-3) - iptr->line;
        le->mpc        = (uintptr_t) insinfo->method;
 
-       list_add_last_unsynced(cd->linenumbers, le);
+       DumpList_push_front(cd->linenumbers, le);
 
        le = DNEW(linenumbertable_list_entry_t);
 
@@ -209,7 +222,7 @@ void linenumbertable_list_entry_add_inline_end(codegendata *cd, instruction *ipt
        le->linenumber = (-1);
        le->mpc        = insinfo->startmpc;
 
-       list_add_last_unsynced(cd->linenumbers, le);
+       DumpList_push_front(cd->linenumbers, le);
 }
 
 
@@ -225,6 +238,8 @@ static s4 linenumbertable_linenumber_for_pc_intern(methodinfo **pm, linenumberta
 {
        linenumbertable_entry_t *lntinline;   /* special entry for inlined method */
 
+       pc = ADDR_MASK(void *, pc);
+
        for (; lntsize > 0; lntsize--, lnte++) {
                /* Note: In case of inlining this may actually compare the pc
                   against a methodinfo *, yielding a non-sensical
@@ -320,7 +335,7 @@ int32_t linenumbertable_linenumber_for_pc(methodinfo **pm, codeinfo *code, void
  * Emacs will automagically detect them.
  * ---------------------------------------------------------------------
  * Local variables:
- * mode: c
+ * mode: c++
  * indent-tabs-mode: t
  * c-basic-offset: 4
  * tab-width: 4