tool: validate: if parse fails, print any diagnostic messages
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "../diag/diag.h"
|
||||
#include "cmd.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -26,6 +27,7 @@
|
||||
#include <mie/ir/walk.h>
|
||||
#include <mie/name.h>
|
||||
#include <mie/parse/lex.h>
|
||||
#include <mie/parse/line-source.h>
|
||||
#include <mie/parse/parser.h>
|
||||
#include <mie/parse/token.h>
|
||||
#include <mie/pass/builtin.h>
|
||||
@@ -68,7 +70,10 @@ static int validate_file(const char *path, const b_arglist *args)
|
||||
|
||||
mie_builtin_passes_register(ctx);
|
||||
|
||||
struct mie_lex *lex = mie_lex_create(file);
|
||||
struct mie_line_source src;
|
||||
mie_line_source_init(&src, path, file);
|
||||
|
||||
struct mie_lex *lex = mie_lex_create(&src, ctx);
|
||||
struct mie_parser *parse = mie_parser_create(ctx, lex);
|
||||
|
||||
struct mie_name_map *names = mie_name_map_create(NULL);
|
||||
@@ -76,6 +81,13 @@ static int validate_file(const char *path, const b_arglist *args)
|
||||
struct mie_op *root = mie_op_create();
|
||||
|
||||
if (!mie_parser_parse_op(parse, NULL, root)) {
|
||||
struct mie_diag *diag = mie_ctx_pop_diag(ctx);
|
||||
while (diag) {
|
||||
mie_diag_write_pretty(diag, b_stdtty_err);
|
||||
/* TODO cleanup */
|
||||
diag = mie_ctx_pop_diag(ctx);
|
||||
}
|
||||
|
||||
printf("parse failed\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -215,6 +227,8 @@ static int validate_file(const char *path, const b_arglist *args)
|
||||
|
||||
mie_lex_destroy(lex);
|
||||
|
||||
mie_line_source_cleanup(&src);
|
||||
|
||||
b_file_unref(file);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user