commit 78ab1d361c89debc36336835569daac1b6bbd642
parent 52be0374cd86a082d3250d79d5f51d885bc2e8de
Author: citbl <citbl@citbl.org>
Date: Mon, 13 Oct 2025 19:33:01 +1000
fix test, quiet flag
Diffstat:
6 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/ex8.ox b/ex8.ox
@@ -2,6 +2,6 @@ void main() {
print("test 1");
}
-void test() {
- print("test 2");
-}
+// void test() {
+// print("test 2");
+// }
diff --git a/ex9.ox b/ex9.ox
@@ -1,8 +1,8 @@
int jack = 111;
-void test() {
- float alice = 222;
-}
+// void test() {
+// float alice = 222;
+// }
void main() {
int peter = 333;
diff --git a/makefile b/makefile
@@ -35,7 +35,8 @@ check: clean
test: clean default
@for f in ex*.ox; do \
- ./${BIN} $$f > /dev/null 2>err.log || { echo "FAIL: $$f"; cat err.log; exit 1; }; \
+ ./${BIN} --quiet $$f > /dev/null 2>err.log || { echo "FAIL: $$f"; cat err.log; exit 1; }; \
+ echo $$f; \
if [ -s err.log ]; then echo "FAIL: $$f"; cat err.log; exit 1; fi; \
done; \
rm -f err.log
diff --git a/src/gen.h b/src/gen.h
@@ -18,5 +18,5 @@ typedef struct {
const char *src;
} Gen;
-Gen gen_init(Scope *, const char *, Node*);
+Gen gen_init(Scope *, const char *, Node*, bool);
void gen_next(Gen *, Node *);
diff --git a/src/gen/gen.c b/src/gen/gen.c
@@ -24,7 +24,7 @@ loc_from_node(Gen *gen, Node *node)
}
Gen
-gen_init(Scope *scope, const char *src, Node *node)
+gen_init(Scope *scope, const char *src, Node *node, bool quiet)
{
if (scope == NULL || src == NULL) { panic("gen_init: no Scope or AST provided"); }
@@ -37,7 +37,8 @@ gen_init(Scope *scope, const char *src, Node *node)
// needs loc* to work
// gcc_jit_context_set_bool_option(ctx, GCC_JIT_BOOL_OPTION_DEBUGINFO, 1);
// high level
- gcc_jit_context_set_bool_option(ctx, GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 1);
+ if (quiet == false) { gcc_jit_context_set_bool_option(ctx, GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 1); }
+
// gcc_jit_context_set_bool_option(ctx, GCC_JIT_BOOL_OPTION_DUMP_SUMMARY, 1);
gcc_jit_context_set_str_option(ctx, GCC_JIT_STR_OPTION_PROGNAME, "ox");
diff --git a/src/main.c b/src/main.c
@@ -11,15 +11,34 @@
#include "gen.h"
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: %s <file>\n", argv[0]);
return 1;
}
- const char* filename = argv[1];
- const char* contents = readfile(filename);
+ const char *contents = NULL;
+ const char *filename = NULL;
+ const char *flag = NULL;
+
+ filename = argv[1];
+ switch (argc) {
+ case 2:
+ filename = argv[1];
+ break;
+ case 3:
+ flag = argv[1];
+ filename = argv[2];
+ break;
+
+ default:
+ panic("unsupported arguments");
+ }
+
+ contents = readfile(filename);
+
+ bool quiet_flag = flag == NULL ? false : (strcmp(flag, "--quiet") == 0);
if (contents == NULL) { panic("error reading file: %s", filename); }
@@ -45,10 +64,10 @@ main(int argc, char* argv[])
printf("--- gen --- \n");
- Gen gen = gen_init(&program_scope, contents, ast.node);
+ Gen gen = gen_init(&program_scope, contents, ast.node, quiet_flag);
gen_next(&gen, ast.node);
- gcc_jit_result* result;
+ gcc_jit_result *result;
/* Compile the code. */
result = gcc_jit_context_compile(gen.ctx);