26 #include <sys/resource.h>
32 static int enableTiming = 0;
34 static void logTimeSince(clock_t c1,
const char *msg)
36 if (!enableTiming) {
return; }
39 getrusage(RUSAGE_SELF, &r);
40 fprintf(stderr,
"%s took %f seconds. Peak used %ldKB.\n", msg,
41 ((
double)c2 - (
double)c1) / (
double)CLOCKS_PER_SEC, r.ru_maxrss);
44 int main(
int argc,
char **argv)
48 int optimiseLevel = 0;
53 while ((c = getopt(argc, argv,
"ji:tO:x:m:")) != -1)
61 gridSize = strtol(optarg, 0, 10);
64 maxValue = strtol(optarg, 0, 10);
67 iterations = strtol(optarg, 0, 10);
73 optimiseLevel = strtol(optarg, 0, 10);
79 fprintf(stderr,
"usage: %s -jt -i {iterations} -o {optimisation level} -x {grid size} -m {max initial value} {file name}\n", argv[0]);
86 pegmatite::AsciiFileInput input(open(argv[0], O_RDONLY));
87 pegmatite::ErrorList el;
88 std::unique_ptr<AST::StatementList> ast = 0;
92 std::cout <<
"errors: \n";
95 std::cout <<
"line " << err.start.line
96 <<
", col " << err.finish.col <<
": ";
97 std::cout <<
"syntax error" << std::endl;
101 logTimeSince(c1,
"Parsing program");
106 for (uintptr_t i=0 ; i<result->count ; i++)
108 printAST(result->list[i]);
112 #ifdef STATIC_TESTING_GRID
113 int16_t oldgrid[] = {
122 int16_t *g1 = oldgrid;
123 int16_t *g2 = newgrid;
125 int16_t *g1 = (int16_t*)malloc(
sizeof(int16_t) * gridSize * gridSize);
126 int16_t *g2 = (int16_t*)malloc(
sizeof(int16_t) * gridSize * gridSize);
129 for (
int i=0 ; i<(gridSize*gridSize) ; i++)
131 g1[i] = random() % (maxValue + 1);
133 logTimeSince(c1,
"Generating random grid");
139 Compiler::automaton ca = Compiler::compile(ast.get(), optimiseLevel);
140 logTimeSince(c1,
"Compiling");
142 for (
int i=0 ; i<iterations ; i++)
144 ca(g1, g2, gridSize, gridSize);
147 logTimeSince(c1,
"Running compiled version");
152 for (
int i=0 ; i<iterations ; i++)
154 Interpreter::runOneStep(g1, g2, gridSize, gridSize, ast.get());
157 logTimeSince(c1,
"Interpreting");
159 for (
int x=0 ; x<gridSize ; x++)
161 for (
int y=0 ; y<gridSize ; y++)
163 printf(
"%d ", g1[i++]);
Rule statements
List of zero or more statements.
Class representing a parser for the CellAtom language.
Rule ignored
Rule for treating both comments and whitespace as ignored tokens.