Annotation of gforth/vmgen-ex/mini.h, revision 1.10

1.1       anton       1: /* support functions for vmgen example
                      2: 
1.10    ! anton       3:   Copyright (C) 2001,2002,2003 Free Software Foundation, Inc.
1.1       anton       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: 
1.7       anton      24: typedef long Cell;
1.4       anton      25: #ifdef __GNUC__
1.1       anton      26: typedef void *Label;
1.7       anton      27: typedef Label Inst; /* we could "typedef Cell Inst", removing the need
                     28:                        for casts in a few places, but requiring a few
                     29:                        casts etc. in other places */
1.4       anton      30: #else
                     31: typedef long Label;
                     32: typedef long Inst;
                     33: #endif
1.1       anton      34: 
                     35: extern Inst *vm_prim;
                     36: extern int locals;
                     37: extern Cell peeptable;
                     38: extern int vm_debug;
                     39: extern FILE *yyin;
                     40: extern int yylineno;
                     41: extern char *program_name;
                     42: extern FILE *vm_out;
                     43: extern Inst *vmcodep;
                     44: extern Inst *last_compiled;
1.2       anton      45: extern Inst *vmcode_end;
1.5       anton      46: extern int use_super;
1.1       anton      47: 
                     48: /* generic vmgen support functions (e.g., wrappers) */
                     49: void gen_inst(Inst **vmcodepp, Inst i);
                     50: void init_peeptable(void);
                     51: void vm_disassemble(Inst *ip, Inst *endp, Inst prim[]);
                     52: void vm_count_block(Inst *ip);
                     53: struct block_count *block_insert(Inst *ip);
1.2       anton      54: void vm_print_profile(FILE *file);
1.6       anton      55: 
                     56: /* type change macros; these are specific to the types you use, so you
                     57:    have to change this part */
                     58: #define vm_Cell2i(_cell,x)     ((x)=(long)(_cell))
                     59: #define vm_Cell2target(_cell,x)        ((x)=(Inst *)(_cell))
                     60: #define vm_Cell2a(_cell,x)     ((x)=(char *)(_cell))
                     61: #define vm_i2Cell(x,_cell)     ((_cell)=(Cell)(x))
                     62: #define vm_target2Cell(x,_cell)        ((_cell)=(Cell)(x))
                     63: #define vm_a2Cell(x,_cell)     ((_cell)=(Cell)(x))
                     64: #define vm_Cell2Cell(_x,_y) ((_y)=(Cell)(_x))
1.7       anton      65: /* the cast in vm_Cell2Cell is needed because the base type for
                     66:    inst-stream is Cell, but *IP is an Inst */
1.6       anton      67: 
1.8       anton      68: /* for future extensions */
                     69: #define IMM_ARG(access,value)          (access)
                     70: 
1.3       anton      71: #define VM_IS_INST(inst, n) ((inst) == vm_prim[n])
1.1       anton      72: 
                     73: /* mini type-specific support functions */
                     74: void genarg_i(Inst **vmcodepp, Cell i);
                     75: void printarg_i(Cell i);
                     76: void genarg_target(Inst **vmcodepp, Inst *target);
                     77: void printarg_target(Inst *target);
                     78: void printarg_a(char *a);
1.2       anton      79: void printarg_Cell(Cell i);
1.1       anton      80: 
                     81: /* engine functions (type not fixed) */
                     82: Cell engine(Inst *ip0, Cell *sp, char *fp);
                     83: Cell engine_debug(Inst *ip0, Cell *sp, char *fp);
                     84: 
                     85: /* other generic functions */
                     86: int yyparse(void);
                     87: 
                     88: /* mini-specific functions */
                     89: void insert_func(char *name, Inst *start, int locals, int nonparams);
                     90: Inst *func_addr(char *name);
                     91: Cell func_calladjust(char *name);
                     92: void insert_local(char *name);
                     93: Cell var_offset(char *name);
                     94: void gen_main_end(void);
                     95: 
                     96: /* stack pointer change for a function with n nonparams */
                     97: #define adjust(n)  ((n) * -sizeof(Cell))

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