From bf993be4a04bc7279f7d49ae18f185e1dca36479 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 4 Aug 2023 21:28:39 +0300 Subject: move main.c to examples --- .gitignore | 2 ++ Makefile | 17 ++++++++++++----- examples/main.c | 35 +++++++++++++++++++++++++++++++++++ src/main.c | 35 ----------------------------------- tests/check | Bin 1269672 -> 0 bytes 5 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 examples/main.c delete mode 100644 src/main.c delete mode 100755 tests/check diff --git a/.gitignore b/.gitignore index d0dcd40..5cc42f1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,7 @@ lib/*.d tests/*.d build copyjit +libcopyjit.a +examples/copyjit !include/copyjit !lib/gen/.gitkeep diff --git a/Makefile b/Makefile index 9a89746..7a207a7 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ INCLUDEFLAGS = -Iinclude COMPILEFLAGS = LINKFLAGS = -all: copyjit +all: libcopyjit.a # default values CROSS_COMPILE ?= @@ -68,6 +68,7 @@ ARCH != uname -m LINT = $(COMPILE) $(LINTFLAGS) +EXAMPLE_OBJS != ./scripts/gen-deps --sources examples/main.c TEST_OBJS != ./scripts/gen-deps --sources tests/check.c OBJS != ./scripts/gen-deps --sources "$(SOURCES)" OPS != ./scripts/gen-ops --ops "$(OP_SOURCES)" @@ -98,11 +99,17 @@ docs: check: tests/check ./tests/check -tests/check: $(OBJS) $(TEST_OBJS) - $(COMPILE) build/tests/check.o build/src/copyjit.o -o tests/check +.PHONY: examples +examples: examples/copyjit -copyjit: $(OBJS) - $(COMPILE) $(OBJS) -o $@ +examples/copyjit: libcopyjit.a $(EXAMPLE_OBJS) + $(COMPILE) $(EXAMPLE_OBJS) -o $@ -L. -lcopyjit + +tests/check: libcopyjit.a $(TEST_OBJS) + $(COMPILE) $(TEST_OBJS) -o $@ -L. -lcopyjit + +libcopyjit.a: $(OBJS) + $(AR) rcs $@ $(OBJS) # todo: generate operations after cloning? a bit tricky to tell make to generate # a bunch of files only when required, maybe have a configure stage? diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 0000000..94e372b --- /dev/null +++ b/examples/main.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ + +#include +#include +#include + +#include "../src/copyjit.h" + +int main() +{ + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lix(&ctx, 0); // total in x + + compile_fast_liy(&ctx, 0); // iter in y + + void *top = compile_add(&ctx); // iter + total in a + compile_movxa(&ctx); // move total to x + + compile_incy(&ctx); // increment iter + compile_fast_lio(&ctx, 1000000000); // limit in o + compile_subyo(&ctx); + + compile_fast_lio(&ctx, (uintptr_t)top); // branch target in o + /* if we already know the offset, we could generate a ban with immediate + * offsets to save one register? */ + compile_ban(&ctx); + + compile_end(&ctx); + + compile_finish(&ctx); + + printf("%lu\n", run(&ctx)); +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index de287f6..0000000 --- a/src/main.c +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: copyleft-next-0.3.1 */ - -#include -#include -#include - -#include "copyjit.h" - -int main() -{ - ctx_t ctx; - compile_start(&ctx); - - compile_fast_lix(&ctx, 0); // total in x - - compile_fast_liy(&ctx, 0); // iter in y - - void *top = compile_add(&ctx); // iter + total in a - compile_movxa(&ctx); // move total to x - - compile_incy(&ctx); // increment iter - compile_fast_lio(&ctx, 1000000000); // limit in o - compile_subyo(&ctx); - - compile_fast_lio(&ctx, (uintptr_t)top); // branch target in o - /* if we already know the offset, we could generate a ban with immediate - * offsets to save one register? */ - compile_ban(&ctx); - - compile_end(&ctx); - - compile_finish(&ctx); - - printf("%lu\n", run(&ctx)); -} diff --git a/tests/check b/tests/check deleted file mode 100755 index a904b37..0000000 Binary files a/tests/check and /dev/null differ -- cgit v1.3