Annotation of gforth/vmgen-ex2/mini.h, revision 1.1

1.1     ! anton       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: typedef void *Label; 
        !            25: 
        !            26: #ifdef USE_CASTS
        !            27: typedef long Cell;
        !            28: Typedef Cell Inst;
        !            29: 
        !            30: /* type change macros; these are specific to the types you use, so you
        !            31:    have to change this part */
        !            32: #define vm_Cell2i(_cell,x) ((x)=(long)(_cell))
        !            33: #define vm_i2Cell(_cell,x) ((x)=(Cell)(_cell))
        !            34: #define vm_Cell2target(_cell,x) ((x)=(Inst *)(_cell))
        !            35: #define vm_target2Cell(_cell,x) ((x)=(Cell)(_cell))
        !            36: #define vm_Cell2a(_cell,x) ((x)=(char *)(_cell))
        !            37: #define vm_a2Cell(_cell,x) ((x)=(Cell)(_cell))
        !            38: #else
        !            39: typedef union Cell {
        !            40:   long i;
        !            41:   union Cell *target;
        !            42:   Label inst;
        !            43:   char *a;
        !            44: } Cell, Inst;
        !            45: 
        !            46: #define vm_Cell2i(_cell,_x)    ((_x)=(_cell).i)
        !            47: #define vm_i2Cell(_x,_cell)    ((_cell).i=(_x))        
        !            48: #define vm_Cell2target(_cell,_x) ((_x)=(_cell).target)
        !            49: #define vm_target2Cell(_x,_cell) ((_cell).target=(_x)) 
        !            50: #define vm_Cell2a(_cell,_x)    ((_x)=(_cell).a)
        !            51: #define vm_a2Cell(_x,_cell)    ((_cell).a=(_x))        
        !            52: #endif
        !            53: 
        !            54: #define VM_IS_INST(_inst, n) ((_inst).inst == vm_prim[n])
        !            55: 
        !            56: extern Label *vm_prim;
        !            57: extern int locals;
        !            58: extern struct Peeptable_entry **peeptable;
        !            59: extern int vm_debug;
        !            60: extern FILE *yyin;
        !            61: extern int yylineno;
        !            62: extern char *program_name;
        !            63: extern FILE *vm_out;
        !            64: extern Inst *vmcodep;
        !            65: extern Inst *last_compiled;
        !            66: extern Inst *vmcode_end;
        !            67: 
        !            68: /* generic vmgen support functions (e.g., wrappers) */
        !            69: void gen_inst(Inst **vmcodepp, Label i);
        !            70: void init_peeptable(void);
        !            71: void vm_disassemble(Inst *ip, Inst *endp, Label prim[]);
        !            72: void vm_count_block(Inst *ip);
        !            73: struct block_count *block_insert(Inst *ip);
        !            74: void vm_print_profile(FILE *file);
        !            75: 
        !            76: /* mini type-specific support functions */
        !            77: void genarg_i(Inst **vmcodepp, long i);
        !            78: void printarg_i(long i);
        !            79: void genarg_target(Inst **vmcodepp, Inst *target);
        !            80: void printarg_target(Inst *target);
        !            81: void printarg_a(char *a);
        !            82: void printarg_Cell(Cell i);
        !            83: 
        !            84: /* engine functions (type not fixed) */
        !            85: long engine(Inst *ip0, Cell *sp, char *fp);
        !            86: long engine_debug(Inst *ip0, Cell *sp, char *fp);
        !            87: 
        !            88: /* other generic functions */
        !            89: int yyparse(void);
        !            90: 
        !            91: /* mini-specific functions */
        !            92: void insert_func(char *name, Inst *start, int locals, int nonparams);
        !            93: Inst *func_addr(char *name);
        !            94: long func_calladjust(char *name);
        !            95: void insert_local(char *name);
        !            96: long var_offset(char *name);
        !            97: void gen_main_end(void);
        !            98: 
        !            99: /* stack pointer change for a function with n nonparams */
        !           100: #define adjust(n)  ((n) * -sizeof(Cell))

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