diff --git a/GNUmakefile b/GNUmakefile index 7cf08f8c..942875ef 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -28,6 +28,7 @@ endif CPPFLAGS = $(EXTRA_CPPFLAGS) -Isljit_src CFLAGS += $(COMPAT_FLAGS) $(OPT_FLAGS) $(WARN_FLAGS) $(WERROR) REGEX_CFLAGS += $(CFLAGS) -fshort-wchar +EXAMPLE_CFLAGS += $(CFLAGS) -Wno-unused-but-set-variable LDFLAGS = $(EXTRA_LDFLAGS) BINDIR = bin @@ -85,25 +86,25 @@ $(BINDIR)/regex_test: $(BINDIR)/.keep $(BINDIR)/regexMain.o $(BINDIR)/regexJIT.o examples: $(EXAMPLE_TARGET) $(BINDIR)/first_program: $(EXAMPLEDIR)/first_program.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/first_program.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/first_program.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/branch: $(EXAMPLEDIR)/branch.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/branch.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/branch.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/loop: $(EXAMPLEDIR)/loop.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/loop.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/loop.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/array_access: $(EXAMPLEDIR)/array_access.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/array_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/array_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/func_call: $(EXAMPLEDIR)/func_call.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/func_call.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/func_call.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/struct_access: $(EXAMPLEDIR)/struct_access.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/struct_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/struct_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/temp_var: $(EXAMPLEDIR)/temp_var.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/temp_var.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/temp_var.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) $(BINDIR)/brainfuck: $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) + $(CC) $(CPPFLAGS) $(EXAMPLE_CFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS) diff --git a/doc/tutorial/array_access.c b/doc/tutorial/array_access.c index cee48567..71236386 100644 --- a/doc/tutorial/array_access.c +++ b/doc/tutorial/array_access.c @@ -3,19 +3,19 @@ #include #include -typedef long (SLJIT_FUNC *func_arr_t)(long *arr, long narr); +typedef sljit_sw (SLJIT_FUNC *func_arr_t)(sljit_sw *arr, sljit_sw narr); -static void SLJIT_FUNC print_num(long a) +static void SLJIT_FUNC print_num(sljit_sw a) { - printf("num = %ld\n", a); + printf("num = %ld\n", (long)a); } /* This example, we generate a function like this: -long func(long *array, long narray) +sljit_sw func(sljit_sw *array, sljit_sw narray) { - long i; + sljit_sw i; for (i = 0; i < narray; ++i) print_num(array[i]); return narray; @@ -23,19 +23,19 @@ long func(long *array, long narray) */ -static int array_access(long *arr, long narr) +static int array_access(sljit_sw *arr, sljit_sw narr) { void *code; - size_t len; + sljit_uw len; func_arr_t func; struct sljit_label *loopstart; struct sljit_jump *out; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); - sljit_emit_enter(C, 0, SLJIT_ARGS2(W, P, W), 1, 3, 0, 0, 0); - /* opt arg R S FR FS local_size */ + sljit_emit_enter(C, 0, SLJIT_ARGS2(W, P, W), 1, 3, 0); + /* opt arg R S local_size */ /* S2 = 0 */ sljit_emit_op2(C, SLJIT_XOR, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_S2, 0); @@ -49,7 +49,7 @@ static int array_access(long *arr, long narr) /* S2 >= narr --> jumo out */ out = sljit_emit_cmp(C, SLJIT_GREATER_EQUAL, SLJIT_S2, 0, SLJIT_S1, 0); - /* R0 = (long *)S0[S2]; */ + /* R0 = (sljit_sw *)S0[S2]; */ sljit_emit_op1(C, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_S2), SLJIT_WORD_SHIFT); /* print_num(R0) */ @@ -68,12 +68,12 @@ static int array_access(long *arr, long narr) sljit_emit_return(C, SLJIT_MOV, SLJIT_S1, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func_arr_t)code; - printf("func return %ld\n", func(arr, narr)); + printf("func return %ld\n", (long)func(arr, narr)); /* dump_code(code, len); */ @@ -85,6 +85,6 @@ static int array_access(long *arr, long narr) int main(void) { - long arr[8] = { 3, -10, 4, 6, 8, 12, 2000, 0 }; + sljit_sw arr[8] = { 3, -10, 4, 6, 8, 12, 2000, 0 }; return array_access(arr, 8); } diff --git a/doc/tutorial/brainfuck.c b/doc/tutorial/brainfuck.c index 50864683..e19d3bbc 100644 --- a/doc/tutorial/brainfuck.c +++ b/doc/tutorial/brainfuck.c @@ -116,12 +116,12 @@ static void *SLJIT_FUNC my_alloc(size_t size, size_t n) return calloc(size, n); } -static void SLJIT_FUNC my_putchar(long c) +static void SLJIT_FUNC my_putchar(sljit_sw c) { - putchar(c); + putchar((int)c); } -static long SLJIT_FUNC my_getchar(void) +static sljit_sw SLJIT_FUNC my_getchar(void) { return getchar(); } @@ -134,13 +134,13 @@ static void SLJIT_FUNC my_free(void *mem) #define loop_empty() (loop_sp == 0) /* compile bf source to a void func() */ -static void *compile(FILE *src, unsigned long *lcode) +static void *compile(FILE *src, sljit_uw *lcode) { void *code = NULL; int chr; int nchr; - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); struct sljit_jump *end; struct sljit_label *loop_start; struct sljit_jump *loop_end; @@ -148,8 +148,8 @@ static void *compile(FILE *src, unsigned long *lcode) int SP = SLJIT_S0; /* bf SP */ int CELLS = SLJIT_S1; /* bf array */ - sljit_emit_enter(C, 0, SLJIT_ARGS2V(W, W), 2, 2, 0, 0, 0); - /* opt arg R S FR FS local_size */ + sljit_emit_enter(C, 0, SLJIT_ARGS2V(W, W), 2, 2, 0); + /* opt arg R S local_size */ /* SP = 0 */ sljit_emit_op2(C, SLJIT_XOR, SP, 0, SP, 0, SP, 0); @@ -217,7 +217,7 @@ static void *compile(FILE *src, unsigned long *lcode) sljit_set_label(end, sljit_emit_label(C)); sljit_emit_return_void(C); - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); if (lcode) *lcode = sljit_get_generated_code_size(C); diff --git a/doc/tutorial/branch.c b/doc/tutorial/branch.c index f36c64b4..9a69dfb9 100644 --- a/doc/tutorial/branch.c +++ b/doc/tutorial/branch.c @@ -3,12 +3,12 @@ #include #include -typedef long (SLJIT_FUNC *func3_t)(long a, long b, long c); +typedef sljit_sw (SLJIT_FUNC *func3_t)(sljit_sw a, sljit_sw b, sljit_sw c); /* This example, we generate a function like this: -long func(long a, long b, long c) +sljit_sw func(sljit_sw a, sljit_sw b, sljit_sw c) { if ((a & 1) == 0) return c; @@ -16,20 +16,20 @@ long func(long a, long b, long c) } */ -static int branch(long a, long b, long c) +static int branch(sljit_sw a, sljit_sw b, sljit_sw c) { void *code; - unsigned long len; + sljit_uw len; func3_t func; struct sljit_jump *ret_c; struct sljit_jump *out; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); /* 3 arg, 1 temp reg, 3 save reg */ - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0); + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0); /* R0 = a & 1, S0 is argument a */ sljit_emit_op2(C, SLJIT_AND, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1); @@ -56,12 +56,12 @@ static int branch(long a, long b, long c) sljit_emit_return(C, SLJIT_MOV, SLJIT_RETURN_REG, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func3_t)code; - printf("func return %ld\n", func(a, b, c)); + printf("func return %ld\n", (long)func(a, b, c)); /* dump_code(code, len); */ diff --git a/doc/tutorial/first_program.c b/doc/tutorial/first_program.c index 3fa685dd..5f111961 100644 --- a/doc/tutorial/first_program.c +++ b/doc/tutorial/first_program.c @@ -3,19 +3,19 @@ #include #include -typedef long (SLJIT_FUNC *func3_t)(long a, long b, long c); +typedef sljit_sw (SLJIT_FUNC *func3_t)(sljit_sw a, sljit_sw b, sljit_sw c); -static int add3(long a, long b, long c) +static int add3(sljit_sw a, sljit_sw b, sljit_sw c) { void *code; - unsigned long len; + sljit_uw len; func3_t func; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); /* Start a context(function entry), have 3 arguments, discuss later */ - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0); + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0); /* The first arguments of function is register SLJIT_S0, 2nd, SLJIT_S1, etc. */ /* R0 = first */ @@ -32,12 +32,12 @@ static int add3(long a, long b, long c) sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func3_t)code; - printf("func return %ld\n", func(a, b, c)); + printf("func return %ld\n", (long)func(a, b, c)); /* dump_code(code, len); */ diff --git a/doc/tutorial/func_call.c b/doc/tutorial/func_call.c index 4a15f048..0a8a6c7a 100644 --- a/doc/tutorial/func_call.c +++ b/doc/tutorial/func_call.c @@ -3,18 +3,18 @@ #include #include -typedef long (SLJIT_FUNC *func3_t)(long a, long b, long c); +typedef sljit_sw (SLJIT_FUNC *func3_t)(sljit_sw a, sljit_sw b, sljit_sw c); -static long SLJIT_FUNC print_num(long a) +static sljit_sw SLJIT_FUNC print_num(sljit_sw a) { - printf("a = %ld\n", a); + printf("a = %ld\n", (long)a); return a + 1; } /* This example, we generate a function like this: -long func(long a, long b, long c) +sljit_sw func(sljit_sw a, sljit_sw b, sljit_sw c) { if ((a & 1) == 0) return print_num(c); @@ -22,19 +22,19 @@ long func(long a, long b, long c) } */ -static int func_call(long a, long b, long c) +static int func_call(sljit_sw a, sljit_sw b, sljit_sw c) { void *code; - unsigned long len; + sljit_uw len; func3_t func; struct sljit_jump *out; struct sljit_jump *print_c; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0, 0, 0); + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0); /* a & 1 --> R0 */ sljit_emit_op2(C, SLJIT_AND, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1); @@ -59,12 +59,12 @@ static int func_call(long a, long b, long c) sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func3_t)code; - printf("func return %ld\n", func(a, b, c)); + printf("func return %ld\n", (long)func(a, b, c)); /* dump_code(code, len); */ diff --git a/doc/tutorial/loop.c b/doc/tutorial/loop.c index fc3ccdce..f813e37b 100644 --- a/doc/tutorial/loop.c +++ b/doc/tutorial/loop.c @@ -3,15 +3,15 @@ #include #include -typedef long (SLJIT_FUNC *func2_t)(long a, long b); +typedef sljit_sw (SLJIT_FUNC *func2_t)(sljit_sw a, sljit_sw b); /* This example, we generate a function like this: -long func(long a, long b) +sljit_sw func(sljit_sw a, sljit_sw b) { - long i; - long ret = 0; + sljit_sw i; + sljit_sw ret = 0; for (i = 0; i < a; ++i) { ret += b; } @@ -19,20 +19,20 @@ long func(long a, long b) } */ -static int loop(long a, long b) +static int loop(sljit_sw a, sljit_sw b) { void *code; - unsigned long len; + sljit_uw len; func2_t func; struct sljit_label *loopstart; struct sljit_jump *out; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); /* 2 arg, 2 temp reg, 2 saved reg */ - sljit_emit_enter(C, 0, SLJIT_ARGS2(W, W, W), 2, 2, 0, 0, 0); + sljit_emit_enter(C, 0, SLJIT_ARGS2(W, W, W), 2, 2, 0); /* R0 = 0 */ sljit_emit_op2(C, SLJIT_XOR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R1, 0); @@ -55,12 +55,12 @@ static int loop(long a, long b) sljit_emit_return(C, SLJIT_MOV, SLJIT_RETURN_REG, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func2_t)code; - printf("func return %ld\n", func(a, b)); + printf("func return %ld\n", (long)func(a, b)); /* dump_code(code, len); */ diff --git a/doc/tutorial/sljit_tutorial.html b/doc/tutorial/sljit_tutorial.html index d83ab6d6..0f7fadfa 100644 --- a/doc/tutorial/sljit_tutorial.html +++ b/doc/tutorial/sljit_tutorial.html @@ -86,14 +86,14 @@

First program

{
    void *code;
    - sljit_sw len;
    + sljit_uw len;
    func3_t func;

    /* Create a SLJIT compiler */
    - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL);
    + struct sljit_compiler *C = sljit_create_compiler(NULL);

    /* Start a context(function entry), has 3 arguments, discuss later */
    - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0);
    + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0);

    /* The first arguments of function is register SLJIT_S0, 2nd, SLJIT_S1, etc. */
    /* R0 = first */
    @@ -110,12 +110,12 @@

    First program

    sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0);

    /* Generate machine code */
    - code = sljit_generate_code(C);
    + code = sljit_generate_code(C, 0, NULL);
    len = sljit_get_generated_code_size(C);

    /* Execute code */
    func = (func3_t)code;
    - printf("func return %ld\n", func(a, b, c));
    + printf("func return %ld\n", (long)func(a, b, c));

    /* dump_code(code, len); */

    @@ -212,10 +212,10 @@

    Branch

    struct sljit_jump *out;

    /* Create a SLJIT compiler */
    - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL);
    + struct sljit_compiler *C = sljit_create_compiler(NULL);

    /* 3 arg, 1 temp reg, 3 save reg */
    - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0);
    + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0);

    /* R0 = a & 1, S0 is argument a */
    sljit_emit_op2(C, SLJIT_AND, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
    @@ -242,12 +242,12 @@

    Branch

    sljit_emit_return(C, SLJIT_MOV, SLJIT_RETURN_REG, 0);

    /* Generate machine code */
    - code = sljit_generate_code(C);
    + code = sljit_generate_code(C, 0, NULL);
    len = sljit_get_generated_code_size(C);

    /* Execute code */
    func = (func3_t)code;
    - printf("func return %ld\n", func(a, b, c));
    + printf("func return %ld\n", (long)func(a, b, c));

    /* dump_code(code, len); */

    @@ -327,7 +327,7 @@

    Loop


      /* 2 arg, 2 temp reg, 2 saved reg */
      - sljit_emit_enter(C, 0, SLJIT_ARGS2(W, W, W), 2, 2, 0, 0, 0);
      + sljit_emit_enter(C, 0, SLJIT_ARGS2(W, W, W), 2, 2, 0);

      /* R0 = 0 */
      sljit_emit_op2(C, SLJIT_XOR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R1, 0);
      @@ -404,9 +404,9 @@

      Structure access

      struct point_st {
        sljit_sw x;
        - int y;
        - short z;
        - char d;
        + sljit_s32 y;
        + sljit_s16 z;
        + sljit_s8 d;
      };

      @@ -467,8 +467,8 @@

      Local variables

        /* reserved space in stack for sljit_sw arr[3] */
        - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 2, 3, 0, 0, 3 * sizeof(sljit_sw));
        - /* opt arg R S FR FS local_size */
        + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 2, 3, 3 * sizeof(sljit_sw));
        + /* opt arg R S local_size */

        /* arr[0] = S0, SLJIT_SP is the init address of local var */
        sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_S0, 0);
        diff --git a/doc/tutorial/struct_access.c b/doc/tutorial/struct_access.c index 561b2eef..50a69a89 100644 --- a/doc/tutorial/struct_access.c +++ b/doc/tutorial/struct_access.c @@ -4,24 +4,24 @@ #include struct point_st { - long x; - int y; - short z; - char d; + sljit_sw x; + sljit_s32 y; + sljit_s16 z; + sljit_s8 d; }; -typedef long (SLJIT_FUNC *point_func_t)(struct point_st *point); +typedef sljit_sw (SLJIT_FUNC *point_func_t)(struct point_st *point); -static long SLJIT_FUNC print_num(long a) +static sljit_sw SLJIT_FUNC print_num(sljit_sw a) { - printf("a = %ld\n", a); + printf("a = %ld\n", (long)a); return a + 1; } /* This example, we generate a function like this: -long func(struct point_st *point) +sljit_sw func(struct point_st *point) { print_num(point->x); print_num(point->y); @@ -34,7 +34,7 @@ long func(struct point_st *point) static int struct_access() { void *code; - unsigned long len; + sljit_uw len; point_func_t func; struct point_st point = { @@ -42,10 +42,10 @@ static int struct_access() }; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); - sljit_emit_enter(C, 0, SLJIT_ARGS1(W, W), 1, 1, 0, 0, 0); - /* opt arg R S FR FS local_size */ + sljit_emit_enter(C, 0, SLJIT_ARGS1(W, W), 1, 1, 0); + /* opt arg R S local_size */ /* S0->x --> R0; print_num(R0) */ sljit_emit_op1(C, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct point_st, x)); @@ -67,12 +67,12 @@ static int struct_access() sljit_emit_return(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct point_st, x)); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (point_func_t)code; - printf("func return %ld\n", func(&point)); + printf("func return %ld\n", (long)func(&point)); /* dump_code(code, len); */ diff --git a/doc/tutorial/temp_var.c b/doc/tutorial/temp_var.c index a0619317..c68f5a1b 100644 --- a/doc/tutorial/temp_var.c +++ b/doc/tutorial/temp_var.c @@ -3,15 +3,15 @@ #include #include -typedef long (SLJIT_FUNC *func3_t)(long a, long b, long c); +typedef sljit_sw (SLJIT_FUNC *func3_t)(sljit_sw a, sljit_sw b, sljit_sw c); -static long SLJIT_FUNC print_arr(long *a, long n) +static sljit_sw SLJIT_FUNC print_arr(sljit_sw *a, sljit_sw n) { - long i; - long sum = 0; + sljit_sw i; + sljit_sw sum = 0; for (i = 0; i < n; ++i) { sum += a[i]; - printf("arr[%ld] = %ld\n", i, a[i]); + printf("arr[%ld] = %ld\n", (long)i, (long)a[i]); } return sum; } @@ -19,32 +19,32 @@ static long SLJIT_FUNC print_arr(long *a, long n) /* This example, we generate a function like this: -long func(long a, long b, long c) +sljit_sw func(sljit_sw a, sljit_sw b, sljit_sw c) { - long arr[3] = { a, b, c }; + sljit_sw arr[3] = { a, b, c }; return print_arr(arr, 3); } */ -static int temp_var(long a, long b, long c) +static int temp_var(sljit_sw a, sljit_sw b, sljit_sw c) { void *code; - unsigned long len; + sljit_uw len; func3_t func; /* Create a SLJIT compiler */ - struct sljit_compiler *C = sljit_create_compiler(NULL, NULL); + struct sljit_compiler *C = sljit_create_compiler(NULL); - /* reserved space in stack for long arr[3] */ - sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 2, 3, 0, 0, 3 * sizeof(long)); - /* opt arg R S FR FS local_size */ + /* reserved space in stack for sljit_sw arr[3] */ + sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 2, 3, 3 * sizeof(sljit_sw)); + /* opt arg R S local_size */ /* arr[0] = S0, SLJIT_SP is the init address of local var */ sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_S0, 0); /* arr[1] = S1 */ - sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 1 * sizeof(long), SLJIT_S1, 0); + sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 1 * sizeof(sljit_sw), SLJIT_S1, 0); /* arr[2] = S2 */ - sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(long), SLJIT_S2, 0); + sljit_emit_op1(C, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_sw), SLJIT_S2, 0); /* R0 = arr; in fact SLJIT_SP is the address of arr, but can't do so in SLJIT */ sljit_get_local_base(C, SLJIT_R0, 0, 0); /* get the address of local variables */ @@ -53,12 +53,12 @@ static int temp_var(long a, long b, long c) sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0); /* Generate machine code */ - code = sljit_generate_code(C); + code = sljit_generate_code(C, 0, NULL); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func3_t)code; - printf("func return %ld\n", func(a, b, c)); + printf("func return %ld\n", (long)func(a, b, c)); /* dump_code(code, len); */