summaryrefslogtreecommitdiff
path: root/misc/pascal/pascal/pasdefs.h
blob: ade1b7ed012307ffcf52b693f4967fc800b5c23a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/***********************************************************************
 * pascal/pasdefs.h
 * General definitions for the Pascal Compiler/Optimizer
 *
 *   Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ***********************************************************************/

#ifndef __PASDEFS_H
#define __PASDEFS_H

/***********************************************************************
 * Included Files
 ***********************************************************************/

#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>   /* for FILE */
#include <config.h>
#include "pdefs.h"   /* Common definitions */

/***********************************************************************
 * Pre-processor Definitions
 ***********************************************************************/

/* Size Parameters -- some of these can be overridden from the
 * command line.
 */

#define MAX_SYM           (4096)
#define MAX_STRINGS       (65536)
#define MAX_INCL           3      /* Max number of nested include files */
#define MAX_FILES          8      /* Max number of opened files */
#define FNAME_SIZE         40     /* Max size file name */
#define MAX_INCPATHES      8      /* Max number of include pathes */

/* Bit values for the 'flags' field of the symType_t, symProc_t, and
 * symVar_t (see below)
 */

#define STYPE_VARSIZE      0x01   /* Type has variable size */
#define SPROC_EXTERNAL     0x01   /* Proc/func. is defined externally */
#define SVAR_EXTERNAL      0x01   /* Variable is defined externally */

/***********************************************************************
 * Public Enumeration Types
 ***********************************************************************/

/* This enumeration identies what kind of binary object we are creating
 * with the compilation.  At present, we may be generating either a 
 * program binary or a unit binary.
 */

enum fileKind_e
{
  eIsProgram = 0,
  eIsUnit
};
typedef enum fileKind_e fileKind_t;

/* This enumeration determines what part of a file that we are
 * processing now.
 */

enum fileSection_e
{
  eIsOtherSection = 0,      /* Unspecified part of the file */
  eIsProgramSection,        /* Any part of a program file */
  eIsInterfaceSection,      /* INTERFACE section of a unit file */
  eIsImplementationSection, /* IMPLEMENTATION section of a unit file */
  eIsInitializationSection, /* INITIALIZATION section of a unit file */
};
typedef enum fileSection_e fileSection_t;

/***********************************************************************
 * Public Structure/Types
 ***********************************************************************/

/* Reserved word table entry */

struct R
{
  char   *rname;         /* pointer to name in string stack */
  uint8_t rtype;         /* reserved word type */
  uint8_t subtype;       /* reserved word extended type */
};
typedef struct R RTYPE;

/* Symbol table entry */

struct symType_s         /* for sKind = sTYPE */
{
  uint8_t   type;        /* specific type */
  uint8_t   rtype;       /* reference to type */
  uint8_t   subType;     /* constant type for subrange types */
  uint8_t   flags;       /* flags to customize a type (see above) */
  uint32_t  asize;       /* size of allocated instances of this type */
  uint32_t  rsize;       /* size of reference to an instances of this type */
  int32_t   minValue;    /* minimum value taken subrange */
  int32_t   maxValue;    /* maximum value taken by subrange or scalar */
  struct S *parent;      /* pointer to parent type */
};
typedef struct symType_s symType_t;

struct symConst_s        /* for sKind == constant type */
{
  union
  {
    double  f;           /* real value */
    int32_t i;           /* integer value */
  } val;
  struct S *parent;      /* pointer to parent type */
};
typedef struct symConst_s symConst_t;

struct symStringConst_s  /* for sKind == sSTRING_CONST */
{
  uint32_t offset;       /* RO data section offset of string */
  uint32_t size;         /* length of string in bytes */
};
typedef struct symStringConst_s symStringConst_t;

struct symVarString_s    /* for sKind == sSTRING */
{
  uint16_t label;        /* label at string declaration */
  uint16_t size;         /* valid length of string in bytes */
  uint16_t alloc;        /* max length of string in bytes */
};
typedef struct symVarString_s symVarString_t;

struct symLabel_s        /* for sKind == sLABEL */
{
  uint16_t label;        /* label number */
  bool     unDefined;    /* set false when defined */
};
typedef struct symLabel_s symLabel_t;

struct symVar_s          /* for sKind == type identifier */
{
  int32_t   offset;      /* Data stack offset */
  uint32_t  size;        /* Size of variable */
  uint8_t   flags;       /* flags to customize a variable (see above) */
  uint32_t  symIndex;    /* POFF symbol table index (if undefined) */
  struct S *parent;      /* pointer to parent type */
};
typedef struct symVar_s symVar_t;

struct symProc_s         /* for sKind == sPROC or sFUNC */
{
  uint16_t  label;       /* entry point label */
  uint16_t  nParms;      /* number of parameters that follow */
  uint8_t   flags;       /* flags to customize a proc/func (see above) */
  uint32_t  symIndex;    /* POFF symbol table index (if undefined) */
  struct S *parent;      /* pointer to parent type (sFUNC only) */
};
typedef struct symProc_s symProc_t;

struct symRecord_s       /* for sKind == sRECORD_OBJECT */
{
  uint32_t  size;        /* size of this field */
  uint32_t  offset;      /* offset into the RECORD */
  struct S *record;      /* pointer to parent sRECORD type */
  struct S *parent;      /* pointer to parent field type */
};
typedef struct symRecord_s symRecord_t;

struct S
{
  char     *sName;       /* pointer to name in string stack */
  uint8_t   sKind;       /* kind of symbol */
  uint8_t   sLevel;      /* static nesting level */
  union
  {
    symType_t        t;          /* for type definitions */
    symConst_t       c;          /* for constants */
    symStringConst_t s;          /* for strings of constant size*/
    symVarString_t   vs;         /* for strings of variable size*/
    uint16_t         fileNumber; /* for files */
    symLabel_t       l;          /* for labels */
    symVar_t         v;          /* for variables */
    symProc_t        p;          /* for functions & procedures */
    symRecord_t      r;          /* for files of RECORDS */
  } sParm;
};
typedef struct S STYPE;

/* WITH structure */

struct W
{
  uint8_t   level;       /* static nesting level */
  bool      pointer;     /* true if offset is to pointer to RECORD */
  bool      varParm;     /* true if VAR param (+pointer) */
  int32_t   offset;      /* Data stack offset */
  uint16_t  index;       /* RECORD offset (if pointer) */
  STYPE    *parent;      /* pointer to parent RECORD type */
};
typedef struct W WTYPE;

/* File table record */

struct F
{
  int16_t defined;
  int16_t flevel;
  int16_t ftype;
  int32_t faddr;
  int16_t fsize;
};
typedef struct F FTYPE;

/* This structure captures the parsing state of the compiler for a particular
 * file.  Since multiple, nested files can be processed, this represents
 * only level in the "stack" of nested files.
 */

struct fileState_s
{
  /* These fields are managed by the higher level parsing logic
   *
   * stream    - Stream pointer the input stream associated with this
   *             file.
   * kind      - Kind of file we are processing.  If include > 0,
   *             this should be eIsUnit.
   * section   - This is the part of the program that we are parsing
   *             now.
   * dstack    - Level zero dstack offset at the time the unit was
   *             included.  This is used to convert absolute program
   *             stack offsets into relative unit stack offsets.
   * include   - Is a unique number that identifies the file.  In
   *             POFF ouput file, this would be the index to the
   *             entry in the .files section.
   */

  FILE          *stream;
  fileKind_t     kind;
  fileSection_t  section;
  int32_t        dstack;
  int16_t        include;

  /* These fields are managed by the tokenizer.  These are all
   * initialized by primeTokenizer().
   *
   * buffer[]  - Holds the current input line
   * line      - Is the line number in this file for the current line
   * cp        - Is the current pointer into buffer[]
   */

  uint32_t       line;
  unsigned char *cp;
  unsigned char  buffer[LINE_SIZE + 1];
};
typedef struct fileState_s fileState_t;

#endif /* __PASDEFS_H */