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