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