Fix memory corruptions in lexer, which occured while parsing cse.js; remove lexer.log and parser.log files
This commit is contained in:
@@ -22,6 +22,7 @@ nbproject
|
|||||||
*~
|
*~
|
||||||
js.files
|
js.files
|
||||||
core
|
core
|
||||||
|
vgcore.*
|
||||||
**.orig
|
**.orig
|
||||||
|
|
||||||
# ctags and ID database
|
# ctags and ID database
|
||||||
|
|||||||
+1
-1
@@ -143,7 +143,7 @@ endif
|
|||||||
#
|
#
|
||||||
|
|
||||||
CFLAGS_JERRY = $(CFLAGS_WARNINGS) $(CFLAGS_WERROR)
|
CFLAGS_JERRY = $(CFLAGS_WARNINGS) $(CFLAGS_WERROR)
|
||||||
DEFINES_JERRY = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS
|
DEFINES_JERRY = -DMEM_HEAP_CHUNK_SIZE=$$((256)) -DMEM_HEAP_AREA_SIZE=$$((32768)) -DMEM_STATS
|
||||||
|
|
||||||
# FIXME:
|
# FIXME:
|
||||||
# Add common-io.c and sensors.c
|
# Add common-io.c and sensors.c
|
||||||
|
|||||||
+1
-20
@@ -88,7 +88,7 @@ num_and_token;
|
|||||||
#define MAX_NAMES 100
|
#define MAX_NAMES 100
|
||||||
#define MAX_NUMS 25
|
#define MAX_NUMS 25
|
||||||
|
|
||||||
static string_and_token seen_names[MAX_NUMS];
|
static string_and_token seen_names[MAX_NAMES];
|
||||||
static uint8_t seen_names_count = 0;
|
static uint8_t seen_names_count = 0;
|
||||||
|
|
||||||
static num_and_token seen_nums[MAX_NAMES] =
|
static num_and_token seen_nums[MAX_NAMES] =
|
||||||
@@ -112,7 +112,6 @@ static const char *token_start;
|
|||||||
#define LA(I) (*(buffer + I))
|
#define LA(I) (*(buffer + I))
|
||||||
|
|
||||||
#ifdef __HOST
|
#ifdef __HOST
|
||||||
_FILE *lexer_debug_log;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_current_line (void)
|
dump_current_line (void)
|
||||||
@@ -816,10 +815,6 @@ lexer_next_token_private (void)
|
|||||||
parser_fatal (ERR_NON_CHAR);
|
parser_fatal (ERR_NON_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __HOST
|
|
||||||
static int i = 0;
|
|
||||||
#endif /* __HOST */
|
|
||||||
|
|
||||||
token
|
token
|
||||||
lexer_next_token (void)
|
lexer_next_token (void)
|
||||||
{
|
{
|
||||||
@@ -836,12 +831,6 @@ lexer_next_token (void)
|
|||||||
dump_current_line ();
|
dump_current_line ();
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
if (tok.type == TOK_CLOSE_BRACE)
|
|
||||||
{
|
|
||||||
// if (i == 300)
|
|
||||||
__fprintf (lexer_debug_log, "lexer_next_token(%d): type=%d, data=%d\n", i, tok.type, tok.data.uid);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
#endif /* __HOST */
|
#endif /* __HOST */
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
@@ -849,10 +838,6 @@ lexer_next_token (void)
|
|||||||
void
|
void
|
||||||
lexer_save_token (token tok)
|
lexer_save_token (token tok)
|
||||||
{
|
{
|
||||||
#ifdef __HOST
|
|
||||||
if (tok.type == TOK_CLOSE_BRACE)
|
|
||||||
__fprintf (lexer_debug_log, "lexer_save_token(%d): type=%d, data=%d\n", i, tok.type, tok.data.uid);
|
|
||||||
#endif /* __HOST */
|
|
||||||
saved_token = tok;
|
saved_token = tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -867,10 +852,6 @@ lexer_init( const char *source)
|
|||||||
{
|
{
|
||||||
saved_token = empty_token;
|
saved_token = empty_token;
|
||||||
lexer_set_source( source);
|
lexer_set_source( source);
|
||||||
|
|
||||||
#ifdef __HOST
|
|
||||||
lexer_debug_log = __fopen ("lexer.log", "w");
|
|
||||||
#endif /* __HOST */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ static OPCODE opcode;
|
|||||||
static T_IDX opcode_counter = 0;
|
static T_IDX opcode_counter = 0;
|
||||||
static T_IDX temp_name_stack[MAX_OPCODES], temp_name_stack_head = 0, max_temp_name;
|
static T_IDX temp_name_stack[MAX_OPCODES], temp_name_stack_head = 0, max_temp_name;
|
||||||
|
|
||||||
#ifdef __HOST
|
|
||||||
_FILE *debug_file;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static T_IDX parse_expression (void);
|
static T_IDX parse_expression (void);
|
||||||
static void parse_statement (void);
|
static void parse_statement (void);
|
||||||
static T_IDX parse_assignment_expression (void);
|
static T_IDX parse_assignment_expression (void);
|
||||||
@@ -147,13 +143,13 @@ insert_semicolon (void)
|
|||||||
do { skip_newlines (); ID = parse_##TYPE (); } while (0)
|
do { skip_newlines (); ID = parse_##TYPE (); } while (0)
|
||||||
|
|
||||||
#define DUMP_VOID_OPCODE(GETOP) \
|
#define DUMP_VOID_OPCODE(GETOP) \
|
||||||
do { opcode=getop_##GETOP (); serializer_dump_opcode (&opcode); opcode_counter++; } while (0)
|
do { opcode=getop_##GETOP (); serializer_dump_opcode (opcode); opcode_counter++; } while (0)
|
||||||
|
|
||||||
#define DUMP_OPCODE(GETOP, ...) \
|
#define DUMP_OPCODE(GETOP, ...) \
|
||||||
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_dump_opcode (&opcode); opcode_counter++; } while (0)
|
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_dump_opcode (opcode); opcode_counter++; } while (0)
|
||||||
|
|
||||||
#define REWRITE_OPCODE(OC, GETOP, ...) \
|
#define REWRITE_OPCODE(OC, GETOP, ...) \
|
||||||
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_rewrite_opcode (OC, &opcode); } while (0)
|
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_rewrite_opcode (OC, opcode); } while (0)
|
||||||
|
|
||||||
static T_IDX
|
static T_IDX
|
||||||
integer_zero (void)
|
integer_zero (void)
|
||||||
@@ -1835,9 +1831,6 @@ void
|
|||||||
parser_init (void)
|
parser_init (void)
|
||||||
{
|
{
|
||||||
max_temp_name = temp_name = min_temp_name = lexer_get_reserved_ids_count ();
|
max_temp_name = temp_name = min_temp_name = lexer_get_reserved_ids_count ();
|
||||||
#ifdef __HOST
|
|
||||||
debug_file = __fopen ("parser.log", "w");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#define SERIALIZER_H
|
#define SERIALIZER_H
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "opcodes.h"
|
||||||
|
|
||||||
void serializer_init (void);
|
void serializer_init (void);
|
||||||
|
|
||||||
@@ -24,9 +25,9 @@ uint8_t serializer_dump_strings (const char **, uint8_t);
|
|||||||
|
|
||||||
void serializer_dump_nums (const int32_t *, uint8_t, uint8_t, uint8_t);
|
void serializer_dump_nums (const int32_t *, uint8_t, uint8_t, uint8_t);
|
||||||
|
|
||||||
void serializer_dump_opcode (const void *);
|
void serializer_dump_opcode (OPCODE);
|
||||||
|
|
||||||
void serializer_rewrite_opcode (const uint8_t, const void *);
|
void serializer_rewrite_opcode (const uint8_t, OPCODE);
|
||||||
|
|
||||||
void serializer_print_opcodes (void);
|
void serializer_print_opcodes (void);
|
||||||
|
|
||||||
|
|||||||
@@ -116,32 +116,32 @@ serializer_dump_nums (const int32_t nums[], uint8_t size, uint8_t offset, uint8_
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int opcode_counter = 0;
|
static int32_t opcode_counter = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_opcode (const void *opcode)
|
serializer_dump_opcode (OPCODE opcode)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
int opcode_num = (int)((char*)opcode)[0];
|
uint8_t opcode_num = opcode.op_idx;
|
||||||
|
|
||||||
bytecode_opcodes[opcode_counter] = *((OPCODE*)opcode);
|
bytecode_opcodes[opcode_counter] = opcode;
|
||||||
__printf ("%03d: %20s ", opcode_counter++, opcode_names[opcode_num]);
|
__printf ("%03d: %20s ", opcode_counter++, opcode_names[opcode_num]);
|
||||||
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
||||||
__printf ("%4d ", ((char*)opcode)[i]);
|
__printf ("%4d ", ((uint8_t*)&opcode)[i]);
|
||||||
|
|
||||||
__printf ("\n");
|
__printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
|
serializer_rewrite_opcode (const uint8_t loc, OPCODE opcode)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
int opcode_num = (int)((char*)opcode)[0];
|
uint8_t opcode_num = opcode.op_idx;
|
||||||
|
|
||||||
bytecode_opcodes[loc] = *((OPCODE*)opcode);
|
bytecode_opcodes[loc] = opcode;
|
||||||
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
|
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
|
||||||
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
||||||
__printf ("%4d ", ((char*)opcode)[i]);
|
__printf ("%4d ", ((uint8_t*)&opcode)[i]);
|
||||||
|
|
||||||
__printf ("// REWRITE\n");
|
__printf ("// REWRITE\n");
|
||||||
}
|
}
|
||||||
@@ -149,9 +149,9 @@ serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
|
|||||||
void
|
void
|
||||||
serializer_print_opcodes (void)
|
serializer_print_opcodes (void)
|
||||||
{
|
{
|
||||||
int loc = -1, i;
|
int32_t loc = -1, i;
|
||||||
OPCODE* opcode;
|
OPCODE* opcode;
|
||||||
int opcode_num;
|
uint8_t opcode_num;
|
||||||
|
|
||||||
__printf ("AFTER OPTIMIZER:\n");
|
__printf ("AFTER OPTIMIZER:\n");
|
||||||
|
|
||||||
@@ -160,11 +160,11 @@ serializer_print_opcodes (void)
|
|||||||
loc++;
|
loc++;
|
||||||
|
|
||||||
opcode = bytecode_opcodes + loc;
|
opcode = bytecode_opcodes + loc;
|
||||||
opcode_num = (int)((char*)opcode)[0];
|
opcode_num = opcode->op_idx;
|
||||||
|
|
||||||
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
|
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
|
||||||
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
||||||
__printf ("%4d ", ((char*)opcode)[i]);
|
__printf ("%4d ", ((uint8_t*)opcode)[i]);
|
||||||
__printf ("\n");
|
__printf ("\n");
|
||||||
}
|
}
|
||||||
while (opcode->op_idx != __op__idx_exitval);
|
while (opcode->op_idx != __op__idx_exitval);
|
||||||
|
|||||||
@@ -94,15 +94,15 @@ serializer_dump_nums (const int32_t nums[], uint8_t size, uint8_t offset, uint8_
|
|||||||
static int opcode_counter = 0;
|
static int opcode_counter = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_opcode (const void *opcode)
|
serializer_dump_opcode (OPCODE opcode)
|
||||||
{
|
{
|
||||||
bytecode_opcodes[opcode_counter++] = *((OPCODE*)opcode);
|
bytecode_opcodes[opcode_counter++] = opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
|
serializer_rewrite_opcode (const uint8_t loc, OPCODE opcode)
|
||||||
{
|
{
|
||||||
bytecode_opcodes[loc] = *((OPCODE*)opcode);
|
bytecode_opcodes[loc] = opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user