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