mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 15:34:09 +00:00
Clean up test file and add script to run tests.
./run.sh will now execute the tests. It is a very simple setup currently, and is limited to linux on s390x. Enough to get started with.
This commit is contained in:
parent
d7f7509894
commit
54199bd9bc
13
dynasm/Examples/run.sh
Executable file
13
dynasm/Examples/run.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
# run test
|
||||||
|
lua ../dynasm.lua test_z_inst.c | gcc -std=gnu99 -Wall -Werror -g -x c -o test_z_inst -
|
||||||
|
./test_z_inst
|
||||||
|
ec=$?
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm -f ./test_z_inst
|
||||||
|
|
||||||
|
# exit
|
||||||
|
exit $ec
|
@ -2,91 +2,82 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "../dynasm/dasm_proto.h"
|
#include "../dasm_proto.h"
|
||||||
#include "../dynasm/dasm_s390x.h"
|
#include "../dasm_s390x.h"
|
||||||
|
|
||||||
//DynASM directives.
|
// DynASM directives.
|
||||||
|.arch s390x
|
|.arch s390x
|
||||||
|.actionlist actions
|
|.actionlist actions
|
||||||
|
|
||||||
typedef struct
|
static void add(dasm_State *state)
|
||||||
{
|
{
|
||||||
int arg1;
|
dasm_State ** Dst = &state;
|
||||||
int arg2;
|
|
||||||
void (*fn)(dasm_State *);
|
|
||||||
int want;
|
|
||||||
char *testname;
|
|
||||||
}test_table;
|
|
||||||
|
|
||||||
test_table test[] = {
|
| ar r2,r3
|
||||||
{1,2,add,3,"add"},
|
| br r14
|
||||||
{10,5 ,sub ,5,"subract"} ,
|
|
||||||
{2,3,mul,6,"Multiply"}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void *jitcode(dasm_State **state);
|
|
||||||
void add(dasm_State *);
|
|
||||||
void sub(dasm_State *);
|
|
||||||
void mul(dasm_State *);
|
|
||||||
|
|
||||||
void *jitcode(dasm_State **state)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
int dasm_status = dasm_link(state, &size);
|
|
||||||
assert(dasm_status == DASM_S_OK);
|
|
||||||
|
|
||||||
void *ret = (int *)calloc(10,sizeof(int));
|
|
||||||
dasm_encode(state, ret);
|
|
||||||
dasm_free(state);
|
|
||||||
|
|
||||||
return (int *)ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(dasm_State *state)
|
static void sub(dasm_State *state)
|
||||||
{
|
|
||||||
dasm_State ** Dst = &state;
|
|
||||||
|
|
||||||
| ar r2,r3
|
|
||||||
| br r14
|
|
||||||
}
|
|
||||||
|
|
||||||
void sub(dasm_State *state)
|
|
||||||
{
|
{
|
||||||
dasm_State **Dst = &state;
|
dasm_State **Dst = &state;
|
||||||
|
|
||||||
| sr r2,r3
|
| sr r2,r3
|
||||||
| br r14
|
| br r14
|
||||||
}
|
}
|
||||||
|
|
||||||
void mul(dasm_State *state)
|
static void mul(dasm_State *state)
|
||||||
{
|
{
|
||||||
dasm_State **Dst = &state;
|
dasm_State **Dst = &state;
|
||||||
|
|
||||||
| msr r2 , r3
|
| msr r2 , r3
|
||||||
| br r14
|
| br r14
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(int argc, char *argv[])
|
typedef struct {
|
||||||
|
int arg1;
|
||||||
|
int arg2;
|
||||||
|
void (*fn)(dasm_State *);
|
||||||
|
int want;
|
||||||
|
const char *testname;
|
||||||
|
} test_table;
|
||||||
|
|
||||||
|
test_table test[] = {
|
||||||
|
{ 1, 2, add, 3, "add"},
|
||||||
|
{10, 5, sub, 5, "sub"},
|
||||||
|
{ 2, 3, mul, 6, "mul"}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void *jitcode(dasm_State **state, size_t *size)
|
||||||
|
{
|
||||||
|
int dasm_status = dasm_link(state, size);
|
||||||
|
assert(dasm_status == DASM_S_OK);
|
||||||
|
|
||||||
|
void *ret = mmap(0, *size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
dasm_encode(state, ret);
|
||||||
|
dasm_free(state);
|
||||||
|
|
||||||
|
mprotect(ret, *size, PROT_READ | PROT_EXEC);
|
||||||
|
return (int *)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
dasm_State *state;
|
dasm_State *state;
|
||||||
dasm_State **Dst = &state;
|
|
||||||
int i;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
for(i=0;i<sizeof(test)/sizeof(test[0]);i++)
|
|
||||||
{
|
|
||||||
dasm_init(&state, 1);
|
|
||||||
dasm_setup(&state, actions);
|
|
||||||
test[i].fn(state);
|
|
||||||
int (*fptr)(int, int) = jitcode(&state);
|
|
||||||
int got = fptr(test[i].arg1, test[i].arg2);
|
|
||||||
|
|
||||||
if (got != test[i].want) {
|
for(int i=0; i < sizeof(test)/sizeof(test[0]); i++) {
|
||||||
fprintf(stderr, "test %s failed: want %d, got %d\n", test[i].testname, test[i].want, got);
|
dasm_init(&state, 1);
|
||||||
|
dasm_setup(&state, actions);
|
||||||
|
test[i].fn(state);
|
||||||
|
size_t size;
|
||||||
|
int (*fptr)(int, int) = jitcode(&state, &size);
|
||||||
|
int got = fptr(test[i].arg1, test[i].arg2);
|
||||||
|
|
||||||
|
if (got != test[i].want) {
|
||||||
|
fprintf(stderr, "FAIL: test %s: want %d, got %d\n", test[i].testname, test[i].want, got);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
free(fptr);
|
munmap(fptr, size);
|
||||||
}
|
}
|
||||||
printf("All test passed\n");
|
printf("all tests passed\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user