OSDN Git Service

(union stacktype): Deleted.
[pf3gnuchains/gcc-fork.git] / gcc / bi-run.h
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,                            \
109                   BIT_OFFSET, NBYTES, TRAILING_BITS )                   \
110 \
111   { BYTE_OFFSET = (OFFSET) / (INTERP_BPC);                              \
112     BIT_OFFSET = (OFFSET) % (INTERP_BPC);                               \
113     NBYTES = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) / INTERP_BPC;       \
114     if ((NBYTES) < 0 || ((NBYTES) > 64))                                \
115       NBYTES = 0;                                                       \
116     if ((SIZE) + (BIT_OFFSET) <= INTERP_BPC)                            \
117       TRAILING_BITS = 0;                                                \
118     else                                                                \
119       TRAILING_BITS = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) % INTERP_BPC; }
120
121
122 /* SHIFT_IN_BITS retrieves NBITS bits from SOURCE and shifts into
123    DEST. The bit field starts OFFSET bits into SOURCE.
124
125    OR_IN_BITS copies the NBITS low bits from VALUE into a the bitfield in
126    DEST offset by OFFSET bits. */
127
128
129 #ifdef BYTES_BIG_ENDIAN
130
131 #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS)              \
132   (DEST = ((DEST) << (NBITS))                                   \
133    | (LM ((NBITS))                                              \
134       & ((SOURCE) >> (INTERP_BPC - (OFFSET) - (NBITS)))))
135
136 #define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS)                  \
137   (DEST = ((DEST) & ~(LM ((NBITS)) << (INTERP_BPC - (OFFSET) - (NBITS))))       \
138    | (((VALUE) & LM ((NBITS))) << (INTERP_BPC - (OFFSET) - (NBITS))))
139
140 #else
141
142 #define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS)              \
143   (DEST = ((DEST) << (NBITS))                                   \
144    | (LM ((NBITS))                                              \
145       & ((SOURCE) >> (OFFSET))))
146
147 #define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS)                  \
148   (DEST = ((DEST) & ~(LM ((NBITS)) << (OFFSET)))                \
149    | (((VALUE) & LM ((NBITS))) << (OFFSET)))
150
151 #endif
152
153
154 /* Procedure call; arguments are a pointer to the function to be called,
155    a pointer to a place to store the return value, a pointer to a vector
156    describing the type of procedure call, and the interpreter's stack pointer,
157    which will point to the first of the arguments at this point.  */
158
159 #define CALL(FUNC, CALLDESC, RETVAL, SP) __call(FUNC, CALLDESC, RETVAL, SP)
160
161
162 /* Procedure return; arguments are a pointer to the calldesc for this
163    function, and a pointer to the place where the value to be returned
164    may be found.  Generally the MACHARGS above contain a machine dependent
165    cookie that is used to determine where to jump to.  */
166
167 #define PROCRET(CALLDESC, RETVAL) return