From 09f8df9f7e1166be48cdd6b1caba0f6771dd753e Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 4 Aug 2023 21:16:34 +0300 Subject: add simple patching mechanism --- tests/check.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'tests/check.c') diff --git a/tests/check.c b/tests/check.c index 8f4c6de..f6e775c 100644 --- a/tests/check.c +++ b/tests/check.c @@ -138,8 +138,45 @@ static void check_add() static void check_branch() { - /* oh yeah, I don't support forward references (yet), so this is a bit - * tricky */ + for (size_t i = 0; i < 2; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lia(&ctx, i); + reloc_t r = compile_placeholder(&ctx, compile_lio); + compile_ban(&ctx); + + compile_lix(&ctx, 0); + compile_end(&ctx); + + void *skip = compile_lix(&ctx, 1); + compile_end(&ctx); + compile_patch(r, skip); + + compile_finish(&ctx); + + assert(run(&ctx) == (i != 0)); + } + + for (size_t i = 0; i < 2; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lia(&ctx, i); + reloc_t r = compile_placeholder(&ctx, compile_lio); + compile_baz(&ctx); + + compile_lix(&ctx, 0); + compile_end(&ctx); + + void *skip = compile_lix(&ctx, 1); + compile_end(&ctx); + compile_patch(r, skip); + + compile_finish(&ctx); + + assert(run(&ctx) == (i == 0)); + } } int main() -- cgit v1.3