File:  [gforth] / gforth / vmgen-ex2 / mini.h
Revision 1.9: download - view: text, annotated - select for diffs
Mon Dec 31 19:02:25 2007 UTC (16 years, 3 months ago) by anton
Branches: MAIN
CVS tags: v0-7-0, HEAD
updated copyright year after changing license notice

    1: /* support functions for vmgen example
    2: 
    3:   Copyright (C) 2001,2002,2003,2007 Free Software Foundation, Inc.
    4: 
    5:   This file is part of Gforth.
    6: 
    7:   Gforth is free software; you can redistribute it and/or
    8:   modify it under the terms of the GNU General Public License
    9:   as published by the Free Software Foundation, either version 3
   10:   of the License, or (at your option) any later version.
   11: 
   12:   This program is distributed in the hope that it will be useful,
   13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15:   GNU General Public License for more details.
   16: 
   17:   You should have received a copy of the GNU General Public License
   18:   along with this program; if not, see http://www.gnu.org/licenses/.
   19: */
   20: 
   21: #include <stdio.h>
   22: 
   23: #ifdef __GNUC__
   24: typedef void *Label; 
   25: #else
   26: typedef long Label;
   27: #endif
   28: 
   29: typedef union Cell {
   30:   long i;
   31:   union Cell *target;
   32:   Label inst;
   33:   char *a;
   34: } Cell, Inst;
   35: 
   36: #define vm_Cell2i(_cell,_x)	((_x)=(_cell).i)
   37: #define vm_i2Cell(_x,_cell)	((_cell).i=(_x))	
   38: #define vm_Cell2target(_cell,_x) ((_x)=(_cell).target)
   39: #define vm_target2Cell(_x,_cell) ((_cell).target=(_x))	
   40: #define vm_Cell2a(_cell,_x)	((_x)=(_cell).a)
   41: #define vm_a2Cell(_x,_cell)	((_cell).a=(_x))	
   42: #define vm_Cell2Cell(_x,_y) ((_y)=(_x))
   43: 
   44: /* for future extensions */
   45: #define IMM_ARG(access,value)		(access)
   46: 
   47: #define VM_IS_INST(_inst, n) ((_inst).inst == vm_prim[n])
   48: 
   49: extern Label *vm_prim;
   50: extern int locals;
   51: extern struct Peeptable_entry **peeptable;
   52: extern int vm_debug;
   53: extern FILE *yyin;
   54: extern int yylineno;
   55: extern char *program_name;
   56: extern FILE *vm_out;
   57: extern Inst *vmcodep;
   58: extern Inst *last_compiled;
   59: extern Inst *vmcode_end;
   60: extern int use_super;
   61: 
   62: /* generic vmgen support functions (e.g., wrappers) */
   63: void gen_inst(Inst **vmcodepp, Label i);
   64: void init_peeptable(void);
   65: void vm_disassemble(Inst *ip, Inst *endp, Label prim[]);
   66: void vm_count_block(Inst *ip);
   67: struct block_count *block_insert(Inst *ip);
   68: void vm_print_profile(FILE *file);
   69: 
   70: /* mini type-specific support functions */
   71: void genarg_i(Inst **vmcodepp, long i);
   72: void printarg_i(long i);
   73: void genarg_target(Inst **vmcodepp, Inst *target);
   74: void printarg_target(Inst *target);
   75: void printarg_a(char *a);
   76: void printarg_Cell(Cell i);
   77: 
   78: /* engine functions (type not fixed) */
   79: long engine(Inst *ip0, Cell *sp, char *fp);
   80: long engine_debug(Inst *ip0, Cell *sp, char *fp);
   81: 
   82: /* other generic functions */
   83: int yyparse(void);
   84: 
   85: /* mini-specific functions */
   86: void insert_func(char *name, Inst *start, int locals, int nonparams);
   87: Inst *func_addr(char *name);
   88: long func_calladjust(char *name);
   89: void insert_local(char *name);
   90: long var_offset(char *name);
   91: void gen_main_end(void);
   92: 
   93: /* stack pointer change for a function with n nonparams */
   94: #define adjust(n)  ((n) * -sizeof(Cell))

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>