sljitMain.c revision 1.1 1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2010 Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
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.
15 *
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.
25 */
26
27 #include "sljitLir.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 void sljit_test(void);
33
34 void error(SLJIT_CONST char* str)
35 {
36 printf("An error occured: %s\n", str);
37 exit(-1);
38 }
39
40 union executable_code {
41 void* code;
42 sljit_w (SLJIT_CALL *func)(sljit_w* a);
43 };
44 typedef union executable_code executable_code;
45
46 void devel(void)
47 {
48 executable_code code;
49
50 struct sljit_compiler* compiler = sljit_create_compiler();
51 sljit_w buf[4];
52
53 if (!compiler)
54 error("Not enough of memory");
55 buf[0] = 5;
56 buf[1] = 12;
57 buf[2] = 0;
58 buf[3] = 0;
59
60 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
61 sljit_compiler_verbose(compiler, stdout);
62 #endif
63 sljit_emit_enter(compiler, 1, 4, 5, 2 * sizeof(sljit_w));
64
65 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
66
67 code.code = sljit_generate_code(compiler);
68 sljit_free_compiler(compiler);
69
70 printf("Code at: %p\n", code.code);
71
72 printf("Function returned with %ld\n", (long)code.func((sljit_w*)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);
78 }
79
80 int main(int argc, char* argv[])
81 {
82 /* devel(); */
83 sljit_test();
84
85 return 0;
86 }
87