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