|
|
1.1 ! root 1: /* Definitions for Bytecode Interpreter. ! 2: Copyright (C) 1993 Free Software Foundation, Inc. ! 3: ! 4: This file is part of GNU CC. ! 5: ! 6: GNU CC is free software; you can redistribute it and/or modify ! 7: it under the terms of the GNU General Public License as published by ! 8: the Free Software Foundation; either version 2, or (at your option) ! 9: any later version. ! 10: ! 11: GNU CC is distributed in the hope that it will be useful, ! 12: but WITHOUT ANY WARRANTY; without even the implied warranty of ! 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 14: GNU General Public License for more details. ! 15: ! 16: You should have received a copy of the GNU General Public License ! 17: along with GNU CC; see the file COPYING. If not, write to ! 18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ! 19: ! 20: #define MAXLITERALS 5 ! 21: ! 22: struct arityvec ! 23: { ! 24: char ninputs; ! 25: char noutputs; ! 26: char nliterals; ! 27: char literals[MAXLITERALS]; ! 28: }; ! 29: ! 30: struct argtype ! 31: { ! 32: int modealign; /* Argument mode:alignment */ ! 33: int size; /* Argument size, in bytes */ ! 34: }; ! 35: ! 36: struct callinfo ! 37: { ! 38: int nargs; /* Number of arguments in call */ ! 39: struct argtype retvaltype; /* Type of return value */ ! 40: struct argtype argtypes[1]; /* Argument types */ ! 41: }; ! 42: ! 43: /* Structure describing a bytecode function. If this changes, we also ! 44: need to change expand_function_end () in bc-trans.c */ ! 45: struct bytecode ! 46: { ! 47: int stacksize; /* Depth required of evaluation stack. */ ! 48: int localsize; /* Size in bytes of local variables. */ ! 49: unsigned char *pc0; /* Initial program counter. */ ! 50: void **ptrlit; /* Vector of (relocatable) pointer literals. */ ! 51: struct callinfo *callinfo; /* Vector of procedure call type info. */ ! 52: }; ! 53: ! 54: ! 55: #define INTERP_BPC 8 /* Bits per char */ ! 56: #define INTERP_BPI \ ! 57: (sizeof (int) * INTERP_BPC) /* Bits per int */ ! 58: ! 59: ! 60: #ifndef min ! 61: #define min(L, R) ((L) < (R) ? (L) : (R)) ! 62: #endif ! 63: ! 64: ! 65: /* bit field operations. */ ! 66: ! 67: /* Low (high) mask: int with low (high) N bits set */ ! 68: ! 69: #define LM(N) ((1 << (N)) - 1) ! 70: #define HM(N) ((~LM (INTERP_BPI - (N)))) ! 71: ! 72: ! 73: /* Sign-extend SIZE low bits of VALUE to integer (typeof VALUE) ! 74: Signed bitfields are loaded from memory by the sxloadBI instruction, ! 75: which first retrieves the bitfield with XFIELD and then sign extends ! 76: it to an SItype. */ ! 77: ! 78: #define EXTEND(SIZE, VALUE) \ ! 79: ({ SUtype value = (SUtype) (VALUE); \ ! 80: (value & (1 << ((SIZE) - 1)) ? value | ~LM (SIZE) : value); }) ! 81: ! 82: ! 83: /* Given OFFSET:SIZE for a bitfield, calculate: ! 84: ! 85: [1] BYTE_OFFSET = the byte offset of the bit field. ! 86: [2] BIT_OFFSET = the bit offset of the bit field (less than INTERP_BPC). ! 87: [3] NBYTES = the number of integral bytes in the bit field. ! 88: [4] TRAILING_BITS= the number of trailing bits (less than INTERP_BPC). ! 89: ! 90: ! 91: , , , , , (memory bytes) ! 92: ---------------- (bitfield) ! 93: | | || | | (divisions) ! 94: ^ ^ ^ ^ ! 95: | | | |__ [4] (bits) ! 96: | | |_________ [3] (bytes) ! 97: | |_________________ [2] (bits) ! 98: |___________________________ [1] (bytes) ! 99: ! 100: ! 101: The above applies to BYTE_LOW_ENDIAN machines. In BYTE_BIG_ENDIAN machines, the ! 102: bit numbering is reversed (i.e. bit 0 is the sign bit). ! 103: ! 104: (Alright, so I drew this to keep my tongue in cheek while writing the code below, ! 105: not because I'm into ASCII art.) */ ! 106: ! 107: ! 108: #define BI_PARAMS(OFFSET, SIZE, BYTE_OFFSET, BIT_OFFSET, NBYTES, TRAILING_BITS) \ ! 109: { BYTE_OFFSET = (OFFSET) / (INTERP_BPC); \ ! 110: BIT_OFFSET = (OFFSET) % (INTERP_BPC); \ ! 111: NBYTES = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) / INTERP_BPC; \ ! 112: if ((NBYTES) < 0 || ((NBYTES) > 64)) \ ! 113: NBYTES = 0; \ ! 114: if ((SIZE) + (BIT_OFFSET) <= INTERP_BPC) \ ! 115: TRAILING_BITS = 0; \ ! 116: else \ ! 117: TRAILING_BITS = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) % INTERP_BPC; } ! 118: ! 119: ! 120: /* SHIFT_IN_BITS retrieves NBITS bits from SOURCE and shifts into ! 121: DEST. The bit field starts OFFSET bits into SOURCE. ! 122: ! 123: OR_IN_BITS copies the NBITS low bits from VALUE into a the bitfield in ! 124: DEST offset by OFFSET bits. */ ! 125: ! 126: ! 127: #ifdef BYTES_BIG_ENDIAN ! 128: ! 129: #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \ ! 130: (DEST = ((DEST) << (NBITS)) \ ! 131: | (LM ((NBITS)) \ ! 132: & ((SOURCE) >> (INTERP_BPC - (OFFSET) - (NBITS))))) ! 133: ! 134: #define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \ ! 135: (DEST = ((DEST) & ~(LM ((NBITS)) << (INTERP_BPC - (OFFSET) - (NBITS)))) \ ! 136: | (((VALUE) & LM ((NBITS))) << (INTERP_BPC - (OFFSET) - (NBITS)))) ! 137: ! 138: #else ! 139: ! 140: #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \ ! 141: (DEST = ((DEST) << (NBITS)) \ ! 142: | (LM ((NBITS)) \ ! 143: & ((SOURCE) >> (OFFSET)))) ! 144: ! 145: #define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \ ! 146: (DEST = ((DEST) & ~(LM ((NBITS)) << (OFFSET))) \ ! 147: | (((VALUE) & LM ((NBITS))) << (OFFSET))) ! 148: ! 149: #endif ! 150: ! 151: ! 152: /* Procedure call; arguments are a pointer to the function to be called, ! 153: a pointer to a place to store the return value, a pointer to a vector ! 154: describing the type of procedure call, and the interpreter's stack pointer, ! 155: which will point to the first of the arguments at this point. */ ! 156: ! 157: #define CALL(FUNC, CALLDESC, RETVAL, SP) __call(FUNC, CALLDESC, RETVAL, SP) ! 158: ! 159: ! 160: /* Procedure return; arguments are a pointer to the calldesc for this ! 161: function, and a pointer to the place where the value to be returned ! 162: may be found. Generally the MACHARGS above contain a machine dependent ! 163: cookie that is used to determine where to jump to. */ ! 164: ! 165: #define PROCRET(CALLDESC, RETVAL) return
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.