diff --git a/SConstruct b/SConstruct index 9697213f6d06cc069f45d121fb2acb291b8aeae8..207419cbaaaf932d55881efc6c13b0955d57ca97 100644 --- a/SConstruct +++ b/SConstruct @@ -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}') diff --git a/src/backends/regex.c b/src/backends/regex.c index 758a7ed37b3d2751cc5557ea23e1027ea329aa44..c4f6a2bfffbcd65640febe01813694694583d6c6 100644 --- a/src/backends/regex.c +++ b/src/backends/regex.c @@ -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; diff --git a/src/benchmark.c b/src/benchmark.c index 632d7db3ba1321b1fb0fa6532f9fb76719725a5b..dfb66fe70cde11c2c75e4a11a74f2c6a1c611b9a 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -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); } } } diff --git a/src/hammer.h b/src/hammer.h index dc403c0c407fc6f786a3ce96cacea858ec6190ea..f0ac6866731f59e824de55422d3a6e105d357c83 100644 --- a/src/hammer.h +++ b/src/hammer.h @@ -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_ {