Fix couple of bugs show-opcodes: lexer should not dump lines, serializer must not rewrite a single opcode when dumping

This commit is contained in:
Ilmir Usmanov 2014-07-31 21:09:42 +04:00
parent 0d1935e3a8
commit 14f0563d1a
4 changed files with 14 additions and 8 deletions

View File

@ -21,6 +21,7 @@
static token saved_token;
static token empty_token = { .type = TOK_EMPTY, .data.uid = 0 };
static bool allow_dump_lines = false;
typedef struct
{
@ -93,6 +94,9 @@ dump_current_line (void)
{
const char *i;
if (!allow_dump_lines)
return;
__printf ("// ");
for (i = buffer; *i != '\n' && *i != 0; i++)
@ -915,10 +919,11 @@ lexer_dump_buffer_state (void)
}
void
lexer_init( const char *source)
lexer_init (const char *source, bool show_opcodes)
{
saved_token = empty_token;
lexer_set_source( source);
allow_dump_lines = show_opcodes;
lexer_set_source (source);
increase_strings_cache ();
}

View File

@ -147,7 +147,7 @@ typedef struct
} __packed
token;
void lexer_init(const char *);
void lexer_init(const char *, bool);
void lexer_free (void);
void lexer_run_first_pass( void);
token lexer_next_token (void);

View File

@ -99,10 +99,9 @@ serializer_dump_nums (const int32_t nums[], uint8_t size, uint16_t offset, uint8
{
__printf ("%3d %7d\n", i + strings_num, nums[i]);
}
__printf ("\n");
}
__printf ("\n");
data = mem_heap_alloc_block ((size_t) (offset + size * 4 + 1), MEM_HEAP_ALLOC_LONG_TERM);
if (!data)
parser_fatal (ERR_MEMORY);
@ -148,6 +147,8 @@ serializer_dump_opcode (OPCODE opcode)
__printf ("\n");
}
else
opcode_counter++;
}
void

View File

@ -33,7 +33,7 @@
#define MAX_NUMS 25
static const OPCODE *
parser_run (const char *script_source, size_t script_source_size __unused)
parser_run (const char *script_source, size_t script_source_size __unused, bool is_show_opcodes)
{
const char *strings[MAX_STRINGS];
int32_t nums[MAX_NUMS];
@ -43,7 +43,7 @@ parser_run (const char *script_source, size_t script_source_size __unused)
TODO( Consider using script_source_size in lexer to check buffer boundaries );
lexer_init( script_source);
lexer_init( script_source, is_show_opcodes);
lexer_run_first_pass();
@ -80,7 +80,7 @@ jerry_run (const char *script_source, size_t script_source_size, bool is_parse_o
serializer_init (is_show_opcodes);
opcodes = parser_run (script_source, script_source_size);
opcodes = parser_run (script_source, script_source_size, is_show_opcodes);
if (is_parse_only)
{