mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-19 19:20:23 +02:00
Implementation of new design
Documentation to come, as tests get added and things settle down.
This commit is contained in:
parent
0d81c5c337
commit
bad7e34c83
18 changed files with 4333 additions and 7149 deletions
16
tests/Makefile
Normal file
16
tests/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
TESTS = addr
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -O0 -g
|
||||
|
||||
all: $(addprefix test-,$(TESTS))
|
||||
|
||||
jit.o: ../jit.h ../jit/*.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -flto -I.. -o jit.o -c ../jit/jit.c
|
||||
|
||||
test-%: test-%.c jit.o test.h
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -flto -I.. -o $@ jit.o $<
|
||||
|
||||
clean:
|
||||
rm -f $(addprefix test-,$(TESTS))
|
||||
rm -f jit.o
|
27
tests/test-addr.c
Normal file
27
tests/test-addr.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "test.h"
|
||||
|
||||
static void
|
||||
run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
|
||||
{
|
||||
jit_begin(j, arena_base, arena_size);
|
||||
|
||||
jit_arg_abi_t abi[] = { JIT_ARG_ABI_INT32, JIT_ARG_ABI_INT32 };
|
||||
jit_arg_t args[2];
|
||||
jit_receive(j, 2, abi, args);
|
||||
ASSERT(args[0].kind == JIT_ARG_LOC_GPR);
|
||||
ASSERT(args[1].kind == JIT_ARG_LOC_GPR);
|
||||
jit_addr(j, JIT_R0, args[0].loc.gpr, args[1].loc.gpr);
|
||||
jit_retr(j, JIT_R0);
|
||||
|
||||
size_t size = 0;
|
||||
void* ret = jit_end(j, &size);
|
||||
|
||||
int (*f)(int, int) = ret;
|
||||
ASSERT(f(42, 69) == 111);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return main_helper(argc, argv, run_test);
|
||||
}
|
42
tests/test.h
Normal file
42
tests/test.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <jit.h>
|
||||
|
||||
#define ASSERT(x) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
fprintf(stderr, "%s:%d: assertion failed: " #x "\n", \
|
||||
__FILE__, __LINE__); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline int
|
||||
main_helper (int argc, char *argv[],
|
||||
void (*run_test)(jit_state_t*, uint8_t*, size_t))
|
||||
{
|
||||
ASSERT(init_jit());
|
||||
jit_state_t *j = jit_new_state();
|
||||
ASSERT(j);
|
||||
|
||||
const size_t arena_size = 4096;
|
||||
char *arena_base = mmap (NULL, arena_size,
|
||||
PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
if (arena_base == MAP_FAILED)
|
||||
{
|
||||
perror ("allocating JIT code buffer failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
run_test(j, (uint8_t*)arena_base, arena_size);
|
||||
|
||||
jit_destroy_state(j);
|
||||
|
||||
munmap(arena_base, arena_size);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue