Merging JakobR's OS X build changes.
This commit is contained in:
parent
75dc4710a4
commit
43f1d70a5f
4 changed files with 39 additions and 12 deletions
|
|
@ -2,7 +2,10 @@
|
||||||
import os
|
import os
|
||||||
env = Environment()
|
env = Environment()
|
||||||
|
|
||||||
env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -lrt")
|
env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes")
|
||||||
|
|
||||||
|
if not env['PLATFORM'] == 'darwin':
|
||||||
|
env.MergeFlags("-lrt")
|
||||||
|
|
||||||
AddOption("--variant",
|
AddOption("--variant",
|
||||||
dest="variant",
|
dest="variant",
|
||||||
|
|
@ -37,7 +40,7 @@ if GetOption("coverage"):
|
||||||
LDFLAGS=["-fprofile-arcs", "-ftest-coverage"],
|
LDFLAGS=["-fprofile-arcs", "-ftest-coverage"],
|
||||||
LIBS=['gcov'])
|
LIBS=['gcov'])
|
||||||
|
|
||||||
if os.getenv("CC") == "clang":
|
if os.getenv("CC") == "clang" or env['PLATFORM'] == 'darwin':
|
||||||
env.Replace(CC="clang",
|
env.Replace(CC="clang",
|
||||||
CXX="clang++")
|
CXX="clang++")
|
||||||
Export('env')
|
Export('env')
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Intended to be included from regex_debug.c
|
// Intended to be included from regex_debug.c
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,29 @@
|
||||||
#include "hammer.h"
|
#include "hammer.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#ifdef __MACH__
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void h_benchmark_clock_gettime(struct timespec *ts) {
|
||||||
|
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
||||||
|
/*
|
||||||
|
* This returns real time, not CPU time. See http://stackoverflow.com/a/6725161
|
||||||
|
* Possible solution: http://stackoverflow.com/a/11659289
|
||||||
|
*/
|
||||||
|
clock_serv_t cclock;
|
||||||
|
mach_timespec_t mts;
|
||||||
|
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||||
|
clock_get_time(cclock, &mts);
|
||||||
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
|
ts->tv_sec = mts.tv_sec;
|
||||||
|
ts->tv_nsec = mts.tv_nsec;
|
||||||
|
#else
|
||||||
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Usage:
|
Usage:
|
||||||
Create your parser (i.e., const HParser*), and an array of test cases
|
Create your parser (i.e., const HParser*), and an array of test cases
|
||||||
|
|
@ -88,11 +111,11 @@ HBenchmarkResults *h_benchmark__m(HAllocator* mm__, HParser* parser, HParserTest
|
||||||
long long time_diff;
|
long long time_diff;
|
||||||
do {
|
do {
|
||||||
count *= 2; // Yes, this means that the first run will run the function twice. This is fine, as we want multiple runs anyway.
|
count *= 2; // Yes, this means that the first run will run the function twice. This is fine, as we want multiple runs anyway.
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts_start);
|
h_benchmark_clock_gettime(&ts_start);
|
||||||
for (cur = 0; cur < count; cur++) {
|
for (cur = 0; cur < count; cur++) {
|
||||||
h_parse_result_free(h_parse(parser, tc->input, tc->length));
|
h_parse_result_free(h_parse(parser, tc->input, tc->length));
|
||||||
}
|
}
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts_end);
|
h_benchmark_clock_gettime(&ts_end);
|
||||||
|
|
||||||
// time_diff is in ns
|
// time_diff is in ns
|
||||||
time_diff = (ts_end.tv_sec - ts_start.tv_sec) * 1000000000 + (ts_end.tv_nsec - ts_start.tv_nsec);
|
time_diff = (ts_end.tv_sec - ts_start.tv_sec) * 1000000000 + (ts_end.tv_nsec - ts_start.tv_nsec);
|
||||||
|
|
|
||||||
13
src/pprint.c
13
src/pprint.c
|
|
@ -21,6 +21,7 @@
|
||||||
#include "hammer.h"
|
#include "hammer.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
typedef struct pp_state {
|
typedef struct pp_state {
|
||||||
int delta;
|
int delta;
|
||||||
|
|
@ -49,13 +50,13 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) {
|
||||||
break;
|
break;
|
||||||
case TT_SINT:
|
case TT_SINT:
|
||||||
if (tok->sint < 0)
|
if (tok->sint < 0)
|
||||||
fprintf(stream, "%*ss -%#lx\n", indent, "", -tok->sint);
|
fprintf(stream, "%*ss -%#" PRIx64 "\n", indent, "", -tok->sint);
|
||||||
else
|
else
|
||||||
fprintf(stream, "%*ss %#lx\n", indent, "", tok->sint);
|
fprintf(stream, "%*ss %#" PRIx64 "\n", indent, "", tok->sint);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TT_UINT:
|
case TT_UINT:
|
||||||
fprintf(stream, "%*su %#lx\n", indent, "", tok->uint);
|
fprintf(stream, "%*su %#" PRIx64 "\n", indent, "", tok->uint);
|
||||||
break;
|
break;
|
||||||
case TT_SEQUENCE: {
|
case TT_SEQUENCE: {
|
||||||
fprintf(stream, "%*s[\n", indent, "");
|
fprintf(stream, "%*s[\n", indent, "");
|
||||||
|
|
@ -128,14 +129,14 @@ static void unamb_sub(const HParsedToken* tok, struct result_buf *buf) {
|
||||||
break;
|
break;
|
||||||
case TT_SINT:
|
case TT_SINT:
|
||||||
if (tok->sint < 0)
|
if (tok->sint < 0)
|
||||||
len = asprintf(&tmpbuf, "s-%#lx", -tok->sint);
|
len = asprintf(&tmpbuf, "s-%#" PRIx64, -tok->sint);
|
||||||
else
|
else
|
||||||
len = asprintf(&tmpbuf, "s%#lx", tok->sint);
|
len = asprintf(&tmpbuf, "s%#" PRIx64, tok->sint);
|
||||||
append_buf(buf, tmpbuf, len);
|
append_buf(buf, tmpbuf, len);
|
||||||
free(tmpbuf);
|
free(tmpbuf);
|
||||||
break;
|
break;
|
||||||
case TT_UINT:
|
case TT_UINT:
|
||||||
len = asprintf(&tmpbuf, "u%#lx", tok->uint);
|
len = asprintf(&tmpbuf, "u%#" PRIx64, tok->uint);
|
||||||
append_buf(buf, tmpbuf, len);
|
append_buf(buf, tmpbuf, len);
|
||||||
free(tmpbuf);
|
free(tmpbuf);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue