1 /* Definitions for Bytecode Interpreter.
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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. */
27 char literals
[MAXLITERALS
];
32 int modealign
; /* Argument mode:alignment */
33 int size
; /* Argument size, in bytes */
38 int nargs
; /* Number of arguments in call */
39 struct argtype retvaltype
; /* Type of return value */
40 struct argtype argtypes
[1]; /* Argument types */
43 /* Structure describing a bytecode function. If this changes, we also
44 need to change expand_function_end () in bc-trans.c */
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. */
55 #define INTERP_BPC 8 /* Bits per char */
57 (sizeof (int) * INTERP_BPC) /* Bits per int */
61 #define min(L, R) ((L) < (R) ? (L) : (R))
65 /* bit field operations. */
67 /* Low (high) mask: int with low (high) N bits set */
69 #define LM(N) ((1 << (N)) - 1)
70 #define HM(N) ((~LM (INTERP_BPI - (N))))
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
78 #define EXTEND(SIZE, VALUE) \
79 ({ SUtype value = (SUtype) (VALUE); \
80 (value & (1 << ((SIZE) - 1)) ? value | ~LM (SIZE) : value); })
83 /* Given OFFSET:SIZE for a bitfield, calculate:
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).
91 , , , , , (memory bytes)
92 ---------------- (bitfield)
93 | | || | | (divisions)
96 | | |_________ [3] (bytes)
97 | |_________________ [2] (bits)
98 |___________________________ [1] (bytes)
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).
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.) */
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)) \
114 if ((SIZE) + (BIT_OFFSET) <= INTERP_BPC) \
117 TRAILING_BITS = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) % INTERP_BPC; }
120 /* SHIFT_IN_BITS retrieves NBITS bits from SOURCE and shifts into
121 DEST. The bit field starts OFFSET bits into SOURCE.
123 OR_IN_BITS copies the NBITS low bits from VALUE into a the bitfield in
124 DEST offset by OFFSET bits. */
129 #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \
130 (DEST = ((DEST) << (NBITS)) \
132 & ((SOURCE) >> (INTERP_BPC - (OFFSET) - (NBITS)))))
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))))
140 #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \
141 (DEST = ((DEST) << (NBITS)) \
143 & ((SOURCE) >> (OFFSET))))
145 #define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \
146 (DEST = ((DEST) & ~(LM ((NBITS)) << (OFFSET))) \
147 | (((VALUE) & LM ((NBITS))) << (OFFSET)))
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. */
157 #define CALL(FUNC, CALLDESC, RETVAL, SP) __call(FUNC, CALLDESC, RETVAL, SP)
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. */
165 #define PROCRET(CALLDESC, RETVAL) return