Generate bytecode while parsing
This commit is contained in:
+19
-85
@@ -35,8 +35,6 @@
|
||||
#include "jerry-libc.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "pretty-printer.h"
|
||||
#include "bytecode-generator.h"
|
||||
|
||||
#define DUMP_TOKENS (1u << 0)
|
||||
#define DUMP_AST (1u << 1)
|
||||
@@ -99,27 +97,9 @@ fake_exit (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void
|
||||
check_for_several_dumps (uint8_t dump)
|
||||
{
|
||||
bool was_bit = 0;
|
||||
for (; dump; dump >>= 1)
|
||||
{
|
||||
if (dump & 1u)
|
||||
{
|
||||
if (was_bit)
|
||||
jerry_Exit (ERR_SEVERAL_FILES);
|
||||
else
|
||||
was_bit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
statement st;
|
||||
uint8_t dump = 0;
|
||||
#ifdef __HOST
|
||||
const char *file_name = NULL;
|
||||
FILE *file = NULL;
|
||||
@@ -127,27 +107,15 @@ main (int argc, char **argv)
|
||||
|
||||
mem_Init ();
|
||||
|
||||
if (argc > 0)
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!__strcmp ("-t", argv[i]))
|
||||
dump |= DUMP_TOKENS;
|
||||
else if (!__strcmp ("-a", argv[i]))
|
||||
dump |= DUMP_AST;
|
||||
else if (!__strcmp ("-b", argv[i]))
|
||||
dump |= DUMP_BYTECODE;
|
||||
#ifdef __HOST
|
||||
else if (file_name == NULL)
|
||||
file_name = argv[i];
|
||||
#endif
|
||||
if (argc > 0)
|
||||
{
|
||||
if (file_name == NULL)
|
||||
file_name = argv[1];
|
||||
else
|
||||
jerry_Exit (ERR_SEVERAL_FILES);
|
||||
}
|
||||
|
||||
check_for_several_dumps (dump);
|
||||
|
||||
if (!dump)
|
||||
dump |= DUMP_BYTECODE;
|
||||
#endif
|
||||
|
||||
#ifdef __HOST
|
||||
if (file_name == NULL)
|
||||
@@ -165,60 +133,26 @@ main (int argc, char **argv)
|
||||
lexer_set_source (generated_source);
|
||||
#endif
|
||||
|
||||
if (dump & DUMP_AST)
|
||||
{
|
||||
parser_init ();
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
while (st.type != STMT_EOF)
|
||||
{
|
||||
pp_statement (st);
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
}
|
||||
}
|
||||
// const char *strings[MAX_STRINGS];
|
||||
// uint8_t strings_num;
|
||||
// First run parser to fill list of strings
|
||||
token tok = lexer_next_token ();
|
||||
while (tok.type != TOK_EOF)
|
||||
tok = lexer_next_token ();
|
||||
|
||||
if (dump & DUMP_TOKENS)
|
||||
{
|
||||
token tok = lexer_next_token ();
|
||||
while (tok.type != TOK_EOF)
|
||||
{
|
||||
pp_token (tok);
|
||||
tok = lexer_next_token ();
|
||||
}
|
||||
}
|
||||
// strings_num = lexer_get_strings (strings);
|
||||
|
||||
if (dump & DUMP_BYTECODE)
|
||||
{
|
||||
const char *strings[MAX_STRINGS];
|
||||
uint8_t strings_num;
|
||||
// First run parser to fill list of strings
|
||||
token tok = lexer_next_token ();
|
||||
while (tok.type != TOK_EOF)
|
||||
tok = lexer_next_token ();
|
||||
|
||||
strings_num = lexer_get_strings (strings);
|
||||
|
||||
// Reset lexer
|
||||
// Reset lexer
|
||||
#ifdef __HOST
|
||||
__rewind (file);
|
||||
lexer_set_file (file);
|
||||
__rewind (file);
|
||||
lexer_set_file (file);
|
||||
#else
|
||||
lexer_set_source (generated_source);
|
||||
lexer_set_source (generated_source);
|
||||
#endif
|
||||
|
||||
parser_init ();
|
||||
generator_init ();
|
||||
generator_dump_strings (strings, strings_num);
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
while (st.type != STMT_EOF)
|
||||
{
|
||||
generator_dump_statement (st);
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
}
|
||||
}
|
||||
parser_init ();
|
||||
TODO (serializer_dump_data (strings strings_num));
|
||||
parser_parse_program ();
|
||||
|
||||
//gen_bytecode (generated_source);
|
||||
//gen_bytecode ();
|
||||
|
||||
Reference in New Issue
Block a user