Working on benchmarking test. A lot of things needed to be const and weren't.
This commit is contained in:
parent
d0d9a94fd0
commit
21ec962d76
7 changed files with 17 additions and 11 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#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 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
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] = {
|
||||||
&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
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
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_ {
|
||||||
};
|
};
|
||||||
|
|
||||||
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 @@
|
||||||
#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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue