X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=58e060127b94f35fbce4ed012a9bd918b889f81e;hb=e66a2691d3291916ed2ec07ed1cdead2a95e1a9a;hp=81d476022db346af8fd8e84f97f6194bf37f5856;hpb=d5e8df5885f97ea65839f8970b8697549c207610;p=cparser diff --git a/main.c b/main.c index 81d4760..58e0601 100644 --- a/main.c +++ b/main.c @@ -5,8 +5,10 @@ #include #include -#include "lexer_t.h" +#include "lexer.h" #include "token_t.h" +#include "type_hash.h" +#include "parser.h" #if 0 static @@ -35,38 +37,77 @@ 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) { - lexer_t lexer; - 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)); exit(1); } - lexer_init(&lexer, in, fname); + lexer_open_stream(in, fname); do { - lexer_next_token(&lexer, &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); - lexer_destroy(&lexer); 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(); return 0;