2 * Stack-less Just-In-Time compiler
4 * Copyright 2009-2010 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 int sljit_test(int argc
, char* argv
[]);
34 void error(const char* str
)
36 printf("An error occured: %s\n", str
);
40 union executable_code
{
42 sljit_sw (SLJIT_FUNC
*func
)(sljit_sw
* a
);
44 typedef union executable_code executable_code
;
50 struct sljit_compiler
*compiler
= sljit_create_compiler(NULL
, NULL
);
54 error("Not enough of memory");
60 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
61 sljit_compiler_verbose(compiler
, stdout
);
63 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 4, 5, 4, 0, 2 * sizeof(sljit_sw
));
65 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
67 code
.code
= sljit_generate_code(compiler
);
68 sljit_free_compiler(compiler
);
70 printf("Code at: %p\n", (void*)SLJIT_FUNC_ADDR(code
.code
));
72 printf("Function returned with %ld\n", (long)code
.func((sljit_sw
*)buf
));
73 printf("buf[0] = %ld\n", (long)buf
[0]);
74 printf("buf[1] = %ld\n", (long)buf
[1]);
75 printf("buf[2] = %ld\n", (long)buf
[2]);
76 printf("buf[3] = %ld\n", (long)buf
[3]);
77 sljit_free_code(code
.code
, NULL
);
80 int main(int argc
, char* argv
[])
83 return sljit_test(argc
, argv
);