Browse Source

Use cdata to pass IR_KINT64 to -jdump.

Mike Pall 14 years ago
parent
commit
331b148737
4 changed files with 17 additions and 3 deletions
  1. 3 0
      lib/dump.lua
  2. 1 1
      src/Makefile.dep
  3. 12 2
      src/lj_ir.c
  4. 1 0
      src/lj_ir.h

+ 3 - 0
lib/dump.lua

@@ -295,6 +295,9 @@ local function formatk(tr, idx)
       s = format("[%p]", k)
       if s == "[0x00000000]" then s = "NULL" end
     end
+  elseif t == 21 then -- int64_t
+    s = sub(tostring(k), 1, -3)
+    if sub(s, 1, 1) ~= "-" then s = "+"..s end
   else
     s = tostring(k) -- For primitives.
   end

+ 1 - 1
src/Makefile.dep

@@ -91,7 +91,7 @@ lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_dispatch.h
 lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
  lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
- lj_bc.h lj_traceerr.h lj_lib.h
+ lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h lj_lib.h
 lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
  lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h lualib.h \
  lj_lex.h lj_parse.h lj_char.h

+ 12 - 2
src/lj_ir.c

@@ -21,6 +21,10 @@
 #include "lj_jit.h"
 #include "lj_iropt.h"
 #include "lj_trace.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#endif
 #include "lj_lib.h"
 
 /* Some local macros to save typing. Undef'd at the end. */
@@ -380,8 +384,14 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
   case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;
   case IR_KPTR: case IR_KNULL: setlightudV(tv, mref(ir->ptr, void)); break;
   case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break;
-  /* NYI: use FFI int64_t. */
-  case IR_KINT64: setnumV(tv, (lua_Number)(int64_t)ir_kint64(ir)->u64); break;
+#if LJ_HASFFI
+  case IR_KINT64: {
+    GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8);
+    *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64;
+    setcdataV(L, tv, cd);
+    break;
+    }
+#endif
   default: lua_assert(0); break;
   }
 }

+ 1 - 0
src/lj_ir.h

@@ -553,6 +553,7 @@ typedef union IRIns {
 #define ir_kstr(ir)	(gco2str(ir_kgc((ir))))
 #define ir_ktab(ir)	(gco2tab(ir_kgc((ir))))
 #define ir_kfunc(ir)	(gco2func(ir_kgc((ir))))
+#define ir_kcdata(ir)	(gco2cd(ir_kgc((ir))))
 #define ir_knum(ir)	check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue))
 #define ir_kint64(ir)	check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
 #define ir_k64(ir) \