Annotation of gforth/vmgen-ex2/mini-inst.vmg, revision 1.1
1.1 ! anton 1: \ mini.inst is generated automatically from mini-inst.vmg and mini-super.vmg
! 2: \ example .vmg file
! 3:
! 4: \ Copyright (C) 2001 Free Software Foundation, Inc.
! 5:
! 6: \ This file is part of Gforth.
! 7:
! 8: \ Gforth is free software; you can redistribute it and/or
! 9: \ modify it under the terms of the GNU General Public License
! 10: \ as published by the Free Software Foundation; either version 2
! 11: \ of the License, or (at your option) any later version.
! 12:
! 13: \ This program is distributed in the hope that it will be useful,
! 14: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
! 15: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 16: \ GNU General Public License for more details.
! 17:
! 18: \ You should have received a copy of the GNU General Public License
! 19: \ along with this program; if not, write to the Free Software
! 20: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
! 21:
! 22:
! 23: \ WARNING: This file is processed by m4. Make sure your identifiers
! 24: \ don't collide with m4's (e.g. by undefining them).
! 25:
! 26:
! 27: \ comments start with "\ "
! 28:
! 29: \ stack definitions:
! 30: \E stack data-stack sp Cell
! 31:
! 32: \ stack prefix definitions
! 33: \E inst-stream stack-prefix #
! 34:
! 35: \ type prefix definitions:
! 36: \E s" long" single data-stack type-prefix i
! 37: \E s" char *" single data-stack type-prefix a
! 38: \E s" Inst *" single data-stack type-prefix target
! 39:
! 40: \ simple VM instructions:
! 41: add ( i1 i2 -- i )
! 42: i = i1+i2;
! 43:
! 44: sub ( i1 i2 -- i )
! 45: i = i1-i2;
! 46:
! 47: mul ( i1 i2 -- i )
! 48: i = i1*i2;
! 49:
! 50: and ( i1 i2 -- i )
! 51: i = i1 & i2;
! 52:
! 53: or ( i1 i2 -- i )
! 54: i = i1 | i2;
! 55:
! 56: lessthan ( i1 i2 -- i )
! 57: i = i1<i2;
! 58:
! 59: equals ( i1 i2 -- i )
! 60: i = i1==i2;
! 61:
! 62: not ( i1 -- i2 )
! 63: i2 = !i1;
! 64:
! 65: negate ( i1 -- i2 )
! 66: i2 = -i1;
! 67:
! 68: lit ( #i -- i )
! 69:
! 70: drop ( i -- )
! 71:
! 72: print ( i -- )
! 73: printf("%ld\n", i);
! 74:
! 75: branch ( #target -- )
! 76: SET_IP(target);
! 77:
! 78: zbranch ( #target i -- )
! 79: if (i==0) {
! 80: SET_IP(target);
! 81: TAIL;
! 82: }
! 83:
! 84: \ The stack is organized as follows:
! 85: \ The stack grows downwards; a stack usually looks like this:
! 86:
! 87: \ higher addresses
! 88: \ --------------------- bottom of stack
! 89: \ locals of main
! 90: \ return address (points to VM code after call)
! 91: \ +->oldfp (NULL)
! 92: \ | intermediate results (e.g., 1 for a call like 1+foo(...))
! 93: \ | arguments passed to the called function
! 94: \ | locals of the called function
! 95: \ | return address (points to VM code after call)
! 96: \ +--oldfp <-- fp
! 97: \ intermediate results <-- sp
! 98: \ ---------------------- top of stack
! 99: \ lower addresses
! 100:
! 101: \ The following VM instructions also explicitly reference sp and
! 102: \ therefore may have to do something about spTOS caching.
! 103:
! 104: call ( #target #iadjust -- targetret aoldfp )
! 105: /* IF_spTOS(sp[2] = spTOS);*/ /* unnecessary; vmgen inserts a flush anyway */
! 106: targetret = IP;
! 107: SET_IP(target);
! 108: aoldfp = fp;
! 109: sp = (Cell *)(((char *)sp)+iadjust);
! 110: fp = (char *)sp;
! 111: /* IF_spTOS(spTOS = sp[0]); */ /* dead, thus unnecessary; vmgen copies aoldfp there */
! 112:
! 113: return ( #iadjust target afp i1 -- i2 )
! 114: /* IF_spTOS(sp[-2] = spTOS); */ /* unnecessary; that stack item is dead */
! 115: SET_IP(target);
! 116: sp = (Cell *)(((char *)sp)+iadjust);
! 117: fp = afp;
! 118: i2=i1;
! 119: /* IF_spTOS(spTOS = sp[0]); */ /* dead, thus unnecessary; vmgen copies i2 there */
! 120:
! 121: \ loadlocal and storelocal access stack items below spTOS, so we can
! 122: \ ignore spTOS caching.
! 123:
! 124: loadlocal ( #ioffset -- i )
! 125: vm_Cell2i(*(Cell *)(fp+ioffset),i);
! 126:
! 127: storelocal ( #ioffset i -- )
! 128: vm_i2Cell(i,*(Cell *)(fp+ioffset));
! 129:
! 130: end ( i -- )
! 131: /* SUPER_END would increment the next BB count (because IP points there);
! 132: this would be a problem if there is no following BB.
! 133: Instead, we do the following to add an end point for the current BB: */
! 134: #ifdef VM_PROFILING
! 135: block_insert(IP); /* we also do this at compile time, so this is unnecessary */
! 136: #endif
! 137: return i;
! 138:
! 139: include(mini-super.vmg)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>