regex_compile should return -1 if not a regular grammar; give backends names

This commit is contained in:
Meredith L. Patterson 2014-04-20 17:23:25 +02:00
parent c9419f4c34
commit 1d12f9ffac
4 changed files with 17 additions and 6 deletions

View file

@ -47,7 +47,7 @@ env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backen
env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig")
env.ScanReplace('libhammer.pc.in')
env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes")
env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable")
if env['PLATFORM'] == 'darwin':
env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}')

View file

@ -353,7 +353,7 @@ static void h_regex_free(HParser *parser) {
static int h_regex_compile(HAllocator *mm__, HParser* parser, const void* params) {
if (!parser->vtable->isValidRegular(parser->env)) {
return 1;
return -1;
}
HRVMProg *prog = h_new(HRVMProg, 1);
prog->length = prog->action_count = 0;

View file

@ -80,13 +80,14 @@ HBenchmarkResults *h_benchmark__m(HAllocator* mm__, HParser* parser, HParserTest
// Step 1: Compile grammar for given parser...
if (h_compile(parser, backend, NULL) == -1) {
// backend inappropriate for grammar...
fprintf(stderr, "failed\n");
fprintf(stderr, "Compiling for %s failed\n", HParserBackendNames[backend]);
ret->results[backend].compile_success = false;
ret->results[backend].n_testcases = 0;
ret->results[backend].failed_testcases = 0;
ret->results[backend].cases = NULL;
continue;
}
fprintf(stderr, "Compiled for %s\n", HParserBackendNames[backend]);
ret->results[backend].compile_success = true;
int tc_failed = 0;
// Step 1: verify all test cases.
@ -103,7 +104,7 @@ HBenchmarkResults *h_benchmark__m(HAllocator* mm__, HParser* parser, HParserTest
if ((res_unamb == NULL && tc->output_unambiguous != NULL)
|| (res_unamb != NULL && strcmp(res_unamb, tc->output_unambiguous) != 0)) {
// test case failed...
fprintf(stderr, "failed\n");
fprintf(stderr, "Parsing with %s failed\n", HParserBackendNames[backend]);
// We want to run all testcases, for purposes of generating a
// report. (eg, if users are trying to fix a grammar for a
// faster backend)
@ -115,7 +116,7 @@ HBenchmarkResults *h_benchmark__m(HAllocator* mm__, HParser* parser, HParserTest
if (tc_failed > 0) {
// Can't use this parser; skip to the next
fprintf(stderr, "Backend failed testcases; skipping benchmark\n");
fprintf(stderr, "%s failed testcases; skipping benchmark\n", HParserBackendNames[backend]);
continue;
}
@ -140,6 +141,7 @@ HBenchmarkResults *h_benchmark__m(HAllocator* mm__, HParser* parser, HParserTest
time_diff = (ts_end.tv_sec - ts_start.tv_sec) * 1000000000 + (ts_end.tv_nsec - ts_start.tv_nsec);
} while (time_diff < 100000000);
ret->results[backend].cases[cur_case].parse_time = (time_diff / count);
ret->results[backend].cases[cur_case].length = tc->length;
cur_case++;
}
}
@ -152,7 +154,7 @@ void h_benchmark_report(FILE* stream, HBenchmarkResults* result) {
for (size_t j=0; j<result->results[i].n_testcases; ++j) {
if(result->results[i].cases == NULL)
continue;
fprintf(stream, "Case %zd: %zd ns/parse\n", j, result->results[i].cases[j].parse_time);
fprintf(stream, "Case %zd: %zd ns/parse, %zd ns/byte\n", j, result->results[i].cases[j].parse_time, result->results[i].cases[j].parse_time / result->results[i].cases[j].length);
}
}
}

View file

@ -46,6 +46,14 @@ typedef enum HParserBackend_ {
PB_MAX = PB_GLR
} HParserBackend;
static const char* HParserBackendNames[] = {
"Packrat",
"Regular",
"LL(k)",
"LALR",
"GLR"
};
typedef enum HTokenType_ {
// Before you change the explicit values of these, think of the poor bindings ;_;
TT_NONE = 1,
@ -178,6 +186,7 @@ typedef struct HCaseResult_ {
#else
HResultTiming timestamp;
#endif
size_t length;
} HCaseResult;
typedef struct HBackendResults_ {