sljitMain.c revision 1.2.2.2 1 1.2.2.2 alnsn /*
2 1.2.2.2 alnsn * Stack-less Just-In-Time compiler
3 1.2.2.2 alnsn *
4 1.2.2.2 alnsn * Copyright 2009-2010 Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
5 1.2.2.2 alnsn *
6 1.2.2.2 alnsn * Redistribution and use in source and binary forms, with or without modification, are
7 1.2.2.2 alnsn * permitted provided that the following conditions are met:
8 1.2.2.2 alnsn *
9 1.2.2.2 alnsn * 1. Redistributions of source code must retain the above copyright notice, this list of
10 1.2.2.2 alnsn * conditions and the following disclaimer.
11 1.2.2.2 alnsn *
12 1.2.2.2 alnsn * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 1.2.2.2 alnsn * of conditions and the following disclaimer in the documentation and/or other materials
14 1.2.2.2 alnsn * provided with the distribution.
15 1.2.2.2 alnsn *
16 1.2.2.2 alnsn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 1.2.2.2 alnsn * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.2.2 alnsn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 1.2.2.2 alnsn * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.2.2 alnsn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 1.2.2.2 alnsn * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 1.2.2.2 alnsn * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.2.2.2 alnsn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.2.2.2 alnsn * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.2.2.2 alnsn */
26 1.2.2.2 alnsn
27 1.2.2.2 alnsn #include "sljitLir.h"
28 1.2.2.2 alnsn
29 1.2.2.2 alnsn #include <stdio.h>
30 1.2.2.2 alnsn #include <stdlib.h>
31 1.2.2.2 alnsn
32 1.2.2.2 alnsn void sljit_test(void);
33 1.2.2.2 alnsn
34 1.2.2.2 alnsn #if 0
35 1.2.2.2 alnsn void error(SLJIT_CONST char* str)
36 1.2.2.2 alnsn {
37 1.2.2.2 alnsn printf("An error occured: %s\n", str);
38 1.2.2.2 alnsn exit(-1);
39 1.2.2.2 alnsn }
40 1.2.2.2 alnsn
41 1.2.2.2 alnsn union executable_code {
42 1.2.2.2 alnsn void* code;
43 1.2.2.2 alnsn sljit_w (SLJIT_CALL *func)(sljit_w* a);
44 1.2.2.2 alnsn };
45 1.2.2.2 alnsn typedef union executable_code executable_code;
46 1.2.2.2 alnsn
47 1.2.2.2 alnsn void devel(void)
48 1.2.2.2 alnsn {
49 1.2.2.2 alnsn executable_code code;
50 1.2.2.2 alnsn
51 1.2.2.2 alnsn struct sljit_compiler *compiler = sljit_create_compiler();
52 1.2.2.2 alnsn sljit_w buf[4];
53 1.2.2.2 alnsn
54 1.2.2.2 alnsn if (!compiler)
55 1.2.2.2 alnsn error("Not enough of memory");
56 1.2.2.2 alnsn buf[0] = 5;
57 1.2.2.2 alnsn buf[1] = 12;
58 1.2.2.2 alnsn buf[2] = 0;
59 1.2.2.2 alnsn buf[3] = 0;
60 1.2.2.2 alnsn
61 1.2.2.2 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
62 1.2.2.2 alnsn sljit_compiler_verbose(compiler, stdout);
63 1.2.2.2 alnsn #endif
64 1.2.2.2 alnsn sljit_emit_enter(compiler, 1, 4, 5, 2 * sizeof(sljit_w));
65 1.2.2.2 alnsn
66 1.2.2.2 alnsn sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
67 1.2.2.2 alnsn
68 1.2.2.2 alnsn code.code = sljit_generate_code(compiler);
69 1.2.2.2 alnsn sljit_free_compiler(compiler);
70 1.2.2.2 alnsn
71 1.2.2.2 alnsn printf("Code at: %p\n", code.code);
72 1.2.2.2 alnsn
73 1.2.2.2 alnsn printf("Function returned with %ld\n", (long)code.func((sljit_w*)buf));
74 1.2.2.2 alnsn printf("buf[0] = %ld\n", (long)buf[0]);
75 1.2.2.2 alnsn printf("buf[1] = %ld\n", (long)buf[1]);
76 1.2.2.2 alnsn printf("buf[2] = %ld\n", (long)buf[2]);
77 1.2.2.2 alnsn printf("buf[3] = %ld\n", (long)buf[3]);
78 1.2.2.2 alnsn sljit_free_code(code.code);
79 1.2.2.2 alnsn }
80 1.2.2.2 alnsn #endif
81 1.2.2.2 alnsn
82 1.2.2.2 alnsn int main(int argc, char* argv[])
83 1.2.2.2 alnsn {
84 1.2.2.2 alnsn /* devel(); */
85 1.2.2.2 alnsn sljit_test();
86 1.2.2.2 alnsn
87 1.2.2.2 alnsn return 0;
88 1.2.2.2 alnsn }
89