Merging JakobR's OS X build changes.

This commit is contained in:
Meredith L. Patterson 2013-10-18 12:14:18 +02:00
parent 75dc4710a4
commit 43f1d70a5f
4 changed files with 39 additions and 12 deletions

View file

@ -2,7 +2,10 @@
import os
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",
dest="variant",
@ -37,7 +40,7 @@ if GetOption("coverage"):
LDFLAGS=["-fprofile-arcs", "-ftest-coverage"],
LIBS=['gcov'])
if os.getenv("CC") == "clang":
if os.getenv("CC") == "clang" or env['PLATFORM'] == 'darwin':
env.Replace(CC="clang",
CXX="clang++")
Export('env')

View file

@ -1,7 +1,7 @@
// Intended to be included from regex_debug.c
#define _GNU_SOURCE
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

View file

@ -4,6 +4,29 @@
#include "hammer.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:
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;
do {
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++) {
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 = (ts_end.tv_sec - ts_start.tv_sec) * 1000000000 + (ts_end.tv_nsec - ts_start.tv_nsec);

View file

@ -21,6 +21,7 @@
#include "hammer.h"
#include "internal.h"
#include <stdlib.h>
#include <inttypes.h>
typedef struct pp_state {
int delta;
@ -49,13 +50,13 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) {
break;
case TT_SINT:
if (tok->sint < 0)
fprintf(stream, "%*ss -%#lx\n", indent, "", -tok->sint);
fprintf(stream, "%*ss -%#" PRIx64 "\n", indent, "", -tok->sint);
else
fprintf(stream, "%*ss %#lx\n", indent, "", tok->sint);
fprintf(stream, "%*ss %#" PRIx64 "\n", indent, "", tok->sint);
break;
case TT_UINT:
fprintf(stream, "%*su %#lx\n", indent, "", tok->uint);
fprintf(stream, "%*su %#" PRIx64 "\n", indent, "", tok->uint);
break;
case TT_SEQUENCE: {
fprintf(stream, "%*s[\n", indent, "");
@ -128,14 +129,14 @@ static void unamb_sub(const HParsedToken* tok, struct result_buf *buf) {
break;
case TT_SINT:
if (tok->sint < 0)
len = asprintf(&tmpbuf, "s-%#lx", -tok->sint);
len = asprintf(&tmpbuf, "s-%#" PRIx64, -tok->sint);
else
len = asprintf(&tmpbuf, "s%#lx", tok->sint);
len = asprintf(&tmpbuf, "s%#" PRIx64, tok->sint);
append_buf(buf, tmpbuf, len);
free(tmpbuf);
break;
case TT_UINT:
len = asprintf(&tmpbuf, "u%#lx", tok->uint);
len = asprintf(&tmpbuf, "u%#" PRIx64, tok->uint);
append_buf(buf, tmpbuf, len);
free(tmpbuf);
break;