Skip to content
Snippets Groups Projects
Commit 21ec962d authored by Meredith L. Patterson's avatar Meredith L. Patterson
Browse files

Working on benchmarking test. A lot of things needed to be const and weren't.

parent d0d9a94f
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,9 @@ hammer.o: hammer.h ...@@ -64,6 +64,9 @@ hammer.o: hammer.h
ifneq ($(INCLUDE_TESTS),0) ifneq ($(INCLUDE_TESTS),0)
all: test_suite all: test_suite
benchmark: t_benchmark.o libhammer.a
$(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS)
test: test_suite test: test_suite
./test_suite -v ./test_suite -v
......
#include "../internal.h" #include "../internal.h"
int h_packrat_compile(HAllocator* mm__, HParser* parser, const void* params) { int h_packrat_compile(HAllocator* mm__, const HParser* parser, const void* params) {
return 0; // No compilation necessary, and everything should work return 0; // No compilation necessary, and everything should work
// out of the box. // out of the box.
} }
HParseResult *h_packrat_parse(HAllocator* mm__, HParser* parser, HParseState* parse_state) { HParseResult *h_packrat_parse(HAllocator* mm__, const HParser* parser, HParseState* parse_state) {
return NULL; // TODO: fill this in. return NULL; // TODO: fill this in.
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
HBenchmarkResults *h_benchmark(HParser* parser, HParserTestcase* testcases) { HBenchmarkResults *h_benchmark(const HParser* parser, HParserTestcase* testcases) {
// For now, just output the results to stderr // For now, just output the results to stderr
HParserTestcase* tc = testcases; HParserTestcase* tc = testcases;
HParserBackend backend = PB_MIN; HParserBackend backend = PB_MIN;
......
...@@ -6,10 +6,10 @@ static HParserBackendVTable *backends[PB_MAX] = { ...@@ -6,10 +6,10 @@ static HParserBackendVTable *backends[PB_MAX] = {
&h__packrat_backend_vtable, &h__packrat_backend_vtable,
}; };
int h_compile(HParser* parser, HParserBackend backend, const void* params) { int h_compile(const HParser* parser, HParserBackend backend, const void* params) {
return h_compile__m(&system_allocator, parser, backend, params); return h_compile__m(&system_allocator, parser, backend, params);
} }
int h_compile__m(HAllocator* mm__, HParser* parser, HParserBackend backend, const void* params) { int h_compile__m(HAllocator* mm__, const HParser* parser, HParserBackend backend, const void* params) {
return backends[backend]->compile(mm__, parser, params); return backends[backend]->compile(mm__, parser, params);
} }
...@@ -543,7 +543,7 @@ HAMMER_FN_DECL(void, h_pprint, FILE* stream, const HParsedToken* tok, int indent ...@@ -543,7 +543,7 @@ HAMMER_FN_DECL(void, h_pprint, FILE* stream, const HParsedToken* tok, int indent
* *
* Returns -1 if grammar cannot be compiled with the specified options; 0 otherwise. * Returns -1 if grammar cannot be compiled with the specified options; 0 otherwise.
*/ */
HAMMER_FN_DECL(int, h_compile, HParser* parser, HParserBackend backend, const void* params); HAMMER_FN_DECL(int, h_compile, const HParser* parser, HParserBackend backend, const void* params);
/** /**
* TODO: Document me * TODO: Document me
...@@ -568,7 +568,7 @@ const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len); ...@@ -568,7 +568,7 @@ const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
void h_bit_writer_free(HBitWriter* w); void h_bit_writer_free(HBitWriter* w);
// {{{ Benchmark functions // {{{ Benchmark functions
HBenchmarkResults *h_benchmark(HParser* parser, HParserTestcase* testcases); HBenchmarkResults *h_benchmark(const HParser* parser, HParserTestcase* testcases);
void h_benchmark_report(FILE* stream, HBenchmarkResults* results); void h_benchmark_report(FILE* stream, HBenchmarkResults* results);
void h_benchmark_dump_optimized_code(FILE* stream, HBenchmarkResults* results); void h_benchmark_dump_optimized_code(FILE* stream, HBenchmarkResults* results);
// }}} // }}}
......
...@@ -110,8 +110,8 @@ struct HParseState_ { ...@@ -110,8 +110,8 @@ struct HParseState_ {
}; };
typedef struct HParserBackendVTable_ { typedef struct HParserBackendVTable_ {
int (*compile)(HAllocator *mm__, HParser* parser, const void* params); int (*compile)(HAllocator *mm__, const HParser* parser, const void* params);
HParseResult* (*parse)(HAllocator *mm__, HParser* parser, HParseState* parse_state); HParseResult* (*parse)(HAllocator *mm__, const HParser* parser, HParseState* parse_state);
} HParserBackendVTable; } HParserBackendVTable;
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
#include "hammer.h" #include "hammer.h"
HParserTestcase testcases[] = { HParserTestcase testcases[] = {
{NULL, 0, NULL} {(unsigned char*)"1,2,3", 5, "(u0x31 u0x32 u0x33)"},
{(unsigned char*)"1,3,2", 5, "(u0x31 u0x33 u0x32)"},
{(unsigned char*)"1,3", 3, "(u0x31 u0x33)"},
{(unsigned char*)"3", 1, "(u0x33)"}
}; };
void test_benchmark_1() { void test_benchmark_1() {
HParser *parser = NULL; // TODO: fill this in. const HParser *parser = h_sepBy1(h_choice(h_ch('1'), h_ch('2'), h_ch('3'), NULL), h_ch(','));
HBenchmarkResults *res = h_benchmark(parser, testcases); HBenchmarkResults *res = h_benchmark(parser, testcases);
h_benchmark_report(stderr, res); h_benchmark_report(stderr, res);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment