File:  [gforth] / gforth / vmgen-ex2 / mini.h
Revision 1.3: download - view: text, annotated - select for diffs
Tue Jul 30 20:55:11 2002 UTC (21 years, 8 months ago) by anton
Branches: MAIN
CVS tags: HEAD
profiling now turns off superinstructions in vmgen-ex*

    1: /* support functions for vmgen example
    2: 
    3:   Copyright (C) 2001 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 2
   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, write to the Free Software
   19:   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: */
   21: 
   22: #include <stdio.h>
   23: 
   24: #ifdef __GNUC__
   25: typedef void *Label; 
   26: #else
   27: typedef long Label;
   28: #endif
   29: 
   30: typedef union Cell {
   31:   long i;
   32:   union Cell *target;
   33:   Label inst;
   34:   char *a;
   35: } Cell, Inst;
   36: 
   37: #define vm_Cell2i(_cell,_x)	((_x)=(_cell).i)
   38: #define vm_i2Cell(_x,_cell)	((_cell).i=(_x))	
   39: #define vm_Cell2target(_cell,_x) ((_x)=(_cell).target)
   40: #define vm_target2Cell(_x,_cell) ((_cell).target=(_x))	
   41: #define vm_Cell2a(_cell,_x)	((_x)=(_cell).a)
   42: #define vm_a2Cell(_x,_cell)	((_cell).a=(_x))	
   43: 
   44: #define VM_IS_INST(_inst, n) ((_inst).inst == vm_prim[n])
   45: 
   46: extern Label *vm_prim;
   47: extern int locals;
   48: extern struct Peeptable_entry **peeptable;
   49: extern int vm_debug;
   50: extern FILE *yyin;
   51: extern int yylineno;
   52: extern char *program_name;
   53: extern FILE *vm_out;
   54: extern Inst *vmcodep;
   55: extern Inst *last_compiled;
   56: extern Inst *vmcode_end;
   57: extern int use_super;
   58: 
   59: /* generic vmgen support functions (e.g., wrappers) */
   60: void gen_inst(Inst **vmcodepp, Label i);
   61: void init_peeptable(void);
   62: void vm_disassemble(Inst *ip, Inst *endp, Label prim[]);
   63: void vm_count_block(Inst *ip);
   64: struct block_count *block_insert(Inst *ip);
   65: void vm_print_profile(FILE *file);
   66: 
   67: /* mini type-specific support functions */
   68: void genarg_i(Inst **vmcodepp, long i);
   69: void printarg_i(long i);
   70: void genarg_target(Inst **vmcodepp, Inst *target);
   71: void printarg_target(Inst *target);
   72: void printarg_a(char *a);
   73: void printarg_Cell(Cell i);
   74: 
   75: /* engine functions (type not fixed) */
   76: long engine(Inst *ip0, Cell *sp, char *fp);
   77: long engine_debug(Inst *ip0, Cell *sp, char *fp);
   78: 
   79: /* other generic functions */
   80: int yyparse(void);
   81: 
   82: /* mini-specific functions */
   83: void insert_func(char *name, Inst *start, int locals, int nonparams);
   84: Inst *func_addr(char *name);
   85: long func_calladjust(char *name);
   86: void insert_local(char *name);
   87: long var_offset(char *name);
   88: void gen_main_end(void);
   89: 
   90: /* stack pointer change for a function with n nonparams */
   91: #define adjust(n)  ((n) * -sizeof(Cell))

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