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