Add enum-to-string functions for syntax tree and opcodes.

This commit is contained in:
Tor Andersson
2014-01-20 16:18:49 +01:00
parent 40a12fba0d
commit 759acbd4dd
4 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ struct js_Function
};
js_Function *jsC_compile(js_State *J, js_Ast *prog);
const char *jsC_opcodestring(int opcode);
void jsC_dumpfunction(js_State *J, js_Function *fun);
#endif
+16
View File
@@ -5,6 +5,8 @@
#include <assert.h>
#define nelem(a) (sizeof (a) / sizeof (a)[0])
static const char *astname[] = {
"list", "fundec", "ident", "number", "string", "regexp", "undef",
"null", "true", "false", "this", "fun", "array", "object", "prop_val",
@@ -25,6 +27,20 @@ static const char *opname[] = {
#include "opnames.h"
};
const char *jsP_aststring(js_AstType type)
{
if (type < 0 || type > nelem(astname))
return "<unknown>";
return astname[type];
}
const char *jsC_opcodestring(int type)
{
if (type < 0 || type > nelem(opname))
return "<unknown>";
return opname[type];
}
static inline void pc(int c)
{
putchar(c);
+1
View File
@@ -128,6 +128,7 @@ js_Ast *jsP_parse(js_State *J, const char *filename, const char *source);
void jsP_optimize(js_State *J, js_Ast *prog);
void jsP_freeparse(js_State *J);
const char *jsP_aststring(js_AstType type);
void jsP_dumpsyntax(js_State *J, js_Ast *prog);
void jsP_dumplist(js_State *J, js_Ast *prog);
+1 -1
View File
@@ -808,7 +808,7 @@ static void jsR_run(js_State *J, js_Function *F)
return;
default:
js_error(J, "illegal instruction: %d (pc=%d)", opcode, (int)(pc - F->code - 1));
js_error(J, "illegal instruction: %s (pc=%d)", jsC_opcodestring(opcode), (int)(pc - F->code - 1));
}
}
}