X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=58e060127b94f35fbce4ed012a9bd918b889f81e;hb=e66a2691d3291916ed2ec07ed1cdead2a95e1a9a;hp=799f3640b43ecfe6d2337688357fcddfaa5e5000;hpb=9e29e9c33f6511c4583e5b8ed83194d433e82c45;p=cparser diff --git a/main.c b/main.c index 799f364..58e0601 100644 --- a/main.c +++ b/main.c @@ -5,8 +5,9 @@ #include #include -#include "lexer_t.h" +#include "lexer.h" #include "token_t.h" +#include "type_hash.h" #include "parser.h" #if 0 @@ -36,10 +37,26 @@ void get_output_name(char *buf, size_t buflen, const char *inputname, #endif static -void compile(const char *fname) +translation_unit_t *do_parsing(const char *fname) { - token_t token; + FILE *in = fopen(fname, "r"); + if(in == NULL) { + fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno)); + exit(1); + } + + lexer_open_stream(in, fname); + + translation_unit_t *unit = parse(); + + fclose(in); + return unit; +} + +static +void lextest(const char *fname) +{ FILE *in = fopen(fname, "r"); if(in == NULL) { fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno)); @@ -49,26 +66,47 @@ void compile(const char *fname) lexer_open_stream(in, fname); do { - lexer_next_token(&token); - print_token(stdout, &token); + lexer_next_preprocessing_token(); + print_token(stdout, &lexer_token); puts(""); - } while(token.type != T_EOF); + } while(lexer_token.type != T_EOF); fclose(in); } +void write_fluffy_decls(translation_unit_t *unit); + int main(int argc, char **argv) { init_symbol_table(); init_tokens(); init_lexer(); + init_types(); + init_typehash(); + init_ast(); init_parser(); + if(argc > 2 && strcmp(argv[1], "--lextest") == 0) { + lextest(argv[2]); + return 0; + } + + if(argc > 2 && strcmp(argv[1], "--print-ast") == 0) { + translation_unit_t *unit = do_parsing(argv[2]); + ast_set_output(stdout); + print_ast(unit); + return 0; + } + for(int i = 1; i < argc; ++i) { - compile(argv[i]); + translation_unit_t *unit = do_parsing(argv[i]); + write_fluffy_decls(unit); } exit_parser(); + exit_ast(); + exit_typehash(); + exit_types(); exit_lexer(); exit_tokens(); exit_symbol_table();