Skip to content

Commit

Permalink
Merge pull request snabbco#127 from lukego/lineinfo-no-compress
Browse files Browse the repository at this point in the history
Remove feature to compress GCproto.lineinfo
  • Loading branch information
lukego committed Dec 1, 2017
2 parents 77dabca + 17b3c9c commit 14120c1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 49 deletions.
16 changes: 5 additions & 11 deletions src/lj_bcread.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,12 @@ static uint32_t bcread_uleb128_33(LexState *ls)
/* Read debug info of a prototype. */
static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)
{
void *lineinfo = (void *)proto_lineinfo(pt);
uint32_t *lineinfo = (uint32_t*)proto_lineinfo(pt);
bcread_block(ls, lineinfo, sizedbg);
/* Swap lineinfo if the endianess differs. */
if (bcread_swap(ls) && pt->numline >= 256) {
MSize i, n = pt->sizebc-1;
if (pt->numline < 65536) {
uint16_t *p = (uint16_t *)lineinfo;
for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8));
} else {
uint32_t *p = (uint32_t *)lineinfo;
for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]);
}
if (bcread_swap(ls)) {
int i;
for (i = 0; i < pt->sizebc-1; i++) lineinfo[i] = lj_bswap(lineinfo[i]);
}
}

Expand Down Expand Up @@ -367,7 +361,7 @@ GCproto *lj_bcread_proto(LexState *ls)
pt->firstline = firstline;
pt->numline = numline;
if (sizedbg) {
MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
MSize sizeli = (sizebc-1) * sizeof(BCLine);
setmref(pt->lineinfo, (char *)pt + ofsdbg);
setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);
bcread_dbg(ls, pt, sizedbg);
Expand Down
15 changes: 3 additions & 12 deletions src/lj_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ BCLine lj_debug_line(GCproto *pt, BCPos pc)
BCLine first = pt->firstline;
if (pc == pt->sizebc) return first + pt->numline;
if (pc-- == 0) return first;
if (pt->numline < 256)
return first + (BCLine)((const uint8_t *)lineinfo)[pc];
else if (pt->numline < 65536)
return first + (BCLine)((const uint16_t *)lineinfo)[pc];
else
return first + (BCLine)((const uint32_t *)lineinfo)[pc];
return first + ((BCLine *)lineinfo)[pc];
}
return 0;
}
Expand Down Expand Up @@ -497,16 +492,12 @@ int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)
if (isluafunc(fn)) {
GCtab *t = lj_tab_new(L, 0, 0);
GCproto *pt = funcproto(fn);
const void *lineinfo = proto_lineinfo(pt);
const uint32_t *lineinfo = proto_lineinfo(pt);
if (lineinfo) {
BCLine first = pt->firstline;
int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
MSize i, szl = pt->sizebc-1;
for (i = 0; i < szl; i++) {
BCLine line = first +
(sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
(BCLine)((const uint32_t *)lineinfo)[i]);
BCLine line = first + lineinfo[i];
setboolV(lj_tab_setint(L, t, line), 1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ typedef struct GCproto {
GCRef chunkname; /* Name of the chunk this function was defined in. */
BCLine firstline; /* First line of the function definition. */
BCLine numline; /* Number of lines for the function definition. */
MRef lineinfo; /* Compressed map from bytecode ins. to source line. */
MRef lineinfo; /* Map from bytecode ins. to source line. */
MRef uvinfo; /* Upvalue names. */
MRef varinfo; /* Names and compressed extents of local variables. */
} GCproto;
Expand Down Expand Up @@ -345,7 +345,7 @@ typedef struct GCproto {

#define proto_chunkname(pt) (strref((pt)->chunkname))
#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt))))
#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void))
#define proto_lineinfo(pt) (mref((pt)->lineinfo, const uint32_t))
#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t))
#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t))

Expand Down
32 changes: 8 additions & 24 deletions src/lj_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ static void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv)
/* Prepare lineinfo for prototype. */
static size_t fs_prep_line(FuncState *fs, BCLine numline)
{
return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
return (fs->pc-1) * sizeof(BCLine);
}

/* Fixup lineinfo for prototype. */
Expand All @@ -1365,28 +1365,12 @@ static void fs_fixup_line(FuncState *fs, GCproto *pt,
pt->firstline = fs->linedefined;
pt->numline = numline;
setmref(pt->lineinfo, lineinfo);
if (LJ_LIKELY(numline < 256)) {
uint8_t *li = (uint8_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0 && delta < 256);
li[i] = (uint8_t)delta;
} while (++i < n);
} else if (LJ_LIKELY(numline < 65536)) {
uint16_t *li = (uint16_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0 && delta < 65536);
li[i] = (uint16_t)delta;
} while (++i < n);
} else {
uint32_t *li = (uint32_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0);
li[i] = (uint32_t)delta;
} while (++i < n);
}
uint32_t *li = (uint32_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0);
li[i] = (uint32_t)delta;
} while (++i < n);
}

/* Prepare variable info for prototype. */
Expand Down Expand Up @@ -1443,7 +1427,7 @@ static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)
/* Initialize with empty debug info, if disabled. */
#define fs_prep_line(fs, numline) (UNUSED(numline), 0)
#define fs_fixup_line(fs, pt, li, numline) \
pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)
pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)
#define fs_prep_var(ls, fs, ofsvar) (UNUSED(ofsvar), 0)
#define fs_fixup_var(ls, pt, p, ofsvar) \
setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL)
Expand Down

0 comments on commit 14120c1

Please sign in to comment.