[gforth] / gforth / vmgen-ex / mini.h  

gforth: gforth/vmgen-ex/mini.h


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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help