1 /* 2 * Stack-less Just-In-Time compiler 3 * 4 * Copyright 2009-2010 Zoltan Herczeg (hzmester@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 #if 0 35 void error(SLJIT_CONST char* str) 36 { 37 printf("An error occured: %s\n", str); 38 exit(-1); 39 } 40 41 union executable_code { 42 void* code; 43 sljit_w (SLJIT_CALL *func)(sljit_w* a); 44 }; 45 typedef union executable_code executable_code; 46 47 void devel(void) 48 { 49 executable_code code; 50 51 struct sljit_compiler *compiler = sljit_create_compiler(); 52 sljit_w buf[4]; 53 54 if (!compiler) 55 error("Not enough of memory"); 56 buf[0] = 5; 57 buf[1] = 12; 58 buf[2] = 0; 59 buf[3] = 0; 60 61 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) 62 sljit_compiler_verbose(compiler, stdout); 63 #endif 64 sljit_emit_enter(compiler, 1, 4, 5, 2 * sizeof(sljit_w)); 65 66 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0); 67 68 code.code = sljit_generate_code(compiler); 69 sljit_free_compiler(compiler); 70 71 printf("Code at: %p\n", code.code); 72 73 printf("Function returned with %ld\n", (long)code.func((sljit_w*)buf)); 74 printf("buf[0] = %ld\n", (long)buf[0]); 75 printf("buf[1] = %ld\n", (long)buf[1]); 76 printf("buf[2] = %ld\n", (long)buf[2]); 77 printf("buf[3] = %ld\n", (long)buf[3]); 78 sljit_free_code(code.code); 79 } 80 #endif 81 82 int main(int argc, char* argv[]) 83 { 84 /* devel(); */ 85 sljit_test(); 86 87 return 0; 88 } 89