Fix up disassembly of 24-bit-immediate formats (DEBUG-only 316862, r=shaver).

This commit is contained in:
brendan%mozilla.org 2006-01-04 05:53:16 +00:00
Родитель 628c8f51b5
Коммит 9a542ff0a2
3 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -1030,7 +1030,8 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
} }
js_Disassemble(cx, script, lines, stdout); if (!js_Disassemble(cx, script, lines, stdout))
return JS_FALSE;
SrcNotes(cx, script); SrcNotes(cx, script);
TryNotes(cx, script); TryNotes(cx, script);
} }

Просмотреть файл

@ -122,7 +122,7 @@ GetJumpOffset(jsbytecode *pc, jsbytecode *pc2)
#ifdef DEBUG #ifdef DEBUG
JS_FRIEND_API(void) JS_FRIEND_API(JSBool)
js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp) js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp)
{ {
jsbytecode *pc, *end; jsbytecode *pc, *end;
@ -137,9 +137,10 @@ js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp)
PTRDIFF(pc, script->code, jsbytecode), PTRDIFF(pc, script->code, jsbytecode),
lines, fp); lines, fp);
if (!len) if (!len)
return; return JS_FALSE;
pc += len; pc += len;
} }
return JS_TRUE;
} }
JS_FRIEND_API(uintN) JS_FRIEND_API(uintN)
@ -274,6 +275,48 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
break; break;
#endif #endif
case JOF_UINT24:
if (op == JSOP_FINDNAME) {
/* Special case to avoid a JOF_FINDNAME just for this op. */
atom = js_GetAtom(cx, &script->atomMap, GET_LITERAL_INDEX(pc));
str = js_ValueToSource(cx, ATOM_KEY(atom));
if (!str)
return 0;
fprintf(fp, " %s", JS_GetStringBytes(str));
break;
}
JS_ASSERT(op == JSOP_UINT24 || op == JSOP_LITERAL);
fprintf(fp, " %u", GET_LITERAL_INDEX(pc));
break;
case JOF_LITOPX:
atom = js_GetAtom(cx, &script->atomMap, GET_LITERAL_INDEX(pc));
str = js_ValueToSource(cx, ATOM_KEY(atom));
if (!str)
return 0;
/*
* Bytecode: JSOP_LITOPX <uint24> op [<varno> if JSOP_DEFLOCALFUN].
* Advance pc to point at op.
*/
pc += 1 + LITERAL_INDEX_LEN;
op = *pc;
cs = &js_CodeSpec[op];
fprintf(fp, " %s op %s", JS_GetStringBytes(str), cs->name);
#if JS_HAS_LEXICAL_CLOSURE
if ((cs->format & JOF_TYPEMASK) == JOF_INDEXCONST)
fprintf(fp, " %u", GET_VARNO(pc));
#endif
/*
* Set len to advance pc to skip op and any other immediates (namely,
* <varno> if JSOP_DEFLOCALFUN).
*/
JS_ASSERT(cs->length > ATOM_INDEX_LEN);
len = cs->length - ATOM_INDEX_LEN;
break;
default: { default: {
char numBuf[12]; char numBuf[12];
JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) cs->format); JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) cs->format);

Просмотреть файл

@ -256,7 +256,7 @@ js_puts(JSPrinter *jp, const char *s);
*/ */
#include <stdio.h> #include <stdio.h>
extern JS_FRIEND_API(void) extern JS_FRIEND_API(JSBool)
js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp); js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp);
extern JS_FRIEND_API(uintN) extern JS_FRIEND_API(uintN)