/*===================================================================*/
/*===================== parser.c commandline ========================*/
/*===================================================================*/
+struct parser_s;
-bool parser_init ();
-bool parser_compile_file (const char *);
-bool parser_compile_string(const char *, const char *, size_t);
-bool parser_finish (const char *);
-void parser_cleanup ();
+struct parser_s *parser_create ();
+bool parser_compile_file (struct parser_s *parser, const char *);
+bool parser_compile_string(struct parser_s *parser, const char *, const char *, size_t);
+bool parser_finish (struct parser_s *parser, const char *);
+void parser_cleanup (struct parser_s *parser);
/*===================================================================*/
/*====================== ftepp.c commandline ========================*/
}
int main(int argc, char **argv) {
- size_t itr;
- int retval = 0;
- bool opts_output_free = false;
- bool operators_free = false;
- bool progs_src = false;
- FILE *outfile = NULL;
+ size_t itr;
+ int retval = 0;
+ bool opts_output_free = false;
+ bool operators_free = false;
+ bool progs_src = false;
+ FILE *outfile = NULL;
+ struct parser_s *parser = NULL;
app_name = argv[0];
con_init ();
}
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY)) {
- if (!parser_init()) {
+ if (!(parser = parser_create())) {
con_err("failed to initialize parser\n");
retval = 1;
goto cleanup;
}
data = ftepp_get();
if (vec_size(data)) {
- if (!parser_compile_string(items[itr].filename, data, vec_size(data))) {
+ if (!parser_compile_string(parser, items[itr].filename, data, vec_size(data))) {
retval = 1;
goto cleanup;
}
ftepp_flush();
}
else {
- if (!parser_compile_file(items[itr].filename)) {
+ if (!parser_compile_file(parser, items[itr].filename)) {
retval = 1;
goto cleanup;
}
ftepp_finish();
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY)) {
- if (!parser_finish(OPTS_OPTION_STR(OPTION_OUTPUT))) {
+ if (!parser_finish(parser, OPTS_OPTION_STR(OPTION_OUTPUT))) {
retval = 1;
goto cleanup;
}
vec_free(ppems);
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
- parser_cleanup();
+ parser_cleanup(parser);
if (opts_output_free)
mem_d(OPTS_OPTION_STR(OPTION_OUTPUT));
if (operators_free)
#define PARSER_HT_SIZE 128
#define TYPEDEF_HT_SIZE 16
-typedef struct {
+typedef struct parser_s {
lex_file *lex;
int tok;
code_crc = crc;
}
-static parser_t *parser;
-
-bool parser_init()
+parser_t *parser_create()
{
+ parser_t *parser;
lex_ctx empty_ctx;
size_t i;
parser = (parser_t*)mem_a(sizeof(parser_t));
if (!parser)
- return false;
+ return NULL;
memset(parser, 0, sizeof(*parser));
if (!parser->assign_op) {
printf("internal error: initializing parser: failed to find assign operator\n");
mem_d(parser);
- return false;
+ return NULL;
}
vec_push(parser->variables, parser->htfields = util_htnew(PARSER_HT_SIZE));
} else {
parser->reserved_version = NULL;
}
- return true;
+
+ return parser;
}
-bool parser_compile()
+bool parser_compile(parser_t *parser)
{
/* initial lexer/parser state */
parser->lex->flags.noops = true;
return !compile_errors;
}
-bool parser_compile_file(const char *filename)
+bool parser_compile_file(parser_t *parser, const char *filename)
{
parser->lex = lex_open(filename);
if (!parser->lex) {
con_err("failed to open file \"%s\"\n", filename);
return false;
}
- return parser_compile();
+ return parser_compile(parser);
}
-bool parser_compile_string(const char *name, const char *str, size_t len)
+bool parser_compile_string(parser_t *parser, const char *name, const char *str, size_t len)
{
parser->lex = lex_open_string(str, len, name);
if (!parser->lex) {
con_err("failed to create lexer for string \"%s\"\n", name);
return false;
}
- return parser_compile();
+ return parser_compile(parser);
}
-void parser_cleanup()
+void parser_cleanup(parser_t *parser)
{
size_t i;
for (i = 0; i < vec_size(parser->accessors); ++i) {
mem_d(parser);
}
-bool parser_finish(const char *output)
+bool parser_finish(parser_t *parser, const char *output)
{
size_t i;
ir_builder *ir;