]> git.sur5r.net Git - cc65/blob - src/ca65/symtab.h
Added structs and unions, more work on scopes and expressions
[cc65] / src / ca65 / symtab.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 symtab.h                                  */
4 /*                                                                           */
5 /*                 Symbol table for the ca65 macroassembler                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 52                                              */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SYMTAB_H
37 #define SYMTAB_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "exprdefs.h"
45 #include "inline.h"
46
47 /* ca65 */
48 #include "symentry.h"
49
50
51
52 /*****************************************************************************/
53 /*                                   Data                                    */
54 /*****************************************************************************/
55
56
57
58 /* Symbol table flags */
59 #define ST_NONE         0x00            /* No flags */
60 #define ST_DEFINED      0x01            /* Scope has been defined */
61
62 /* Symbol table types */
63 #define ST_GLOBAL       0x00            /* Root level */
64 #define ST_PROC         0x01            /* .PROC */
65 #define ST_SCOPE        0x02            /* .SCOPE */
66 #define ST_STRUCT       0x03            /* .STRUCT */
67 #define ST_UNION        0x04            /* .UNION */
68 #define ST_UNDEF        0xFF
69
70 /* A symbol table */
71 typedef struct SymTable SymTable;
72 struct SymTable {
73     SymTable*           Left;           /* Pointer to smaller entry */
74     SymTable*           Right;          /* Pointer to greater entry */
75     SymTable*           Parent;         /* Link to enclosing scope if any */
76     SymTable*           Childs;         /* Pointer to child scopes */
77     unsigned short      Flags;          /* Symbol table flags */
78     unsigned char       AddrSize;       /* Address size */
79     unsigned char       Type;           /* Type of the scope */
80     unsigned            Level;          /* Lexical level */
81     unsigned            TableSlots;     /* Number of hash table slots */
82     unsigned            TableEntries;   /* Number of entries in the table */
83     unsigned            Name;           /* Name of the scope */
84     SymEntry*           Table[1];       /* Dynamic allocation */
85 };
86
87 /* Symbol tables */
88 SymTable*       CurrentScope;   /* Pointer to current symbol table */
89 SymTable*       RootScope;      /* Root symbol table */
90
91
92
93 /*****************************************************************************/
94 /*                                   Code                                    */
95 /*****************************************************************************/
96
97
98
99 void SymEnterLevel (const char* ScopeName, unsigned char Type, unsigned char AddrSize);
100 /* Enter a new lexical level */
101
102 void SymLeaveLevel (void);
103 /* Leave the current lexical level */
104
105 SymTable* SymFindScope (SymTable* Parent, const char* Name, int AllocNew);
106 /* Find a scope in the given enclosing scope */
107
108 SymTable* SymFindAnyScope (SymTable* Parent, const char* Name);
109 /* Find a scope in the given or any of its parent scopes. The function will
110  * never create a new symbol, since this can only be done in one specific
111  * scope.
112  */
113
114 SymEntry* SymFind (SymTable* Scope, const char* Name, int AllocNew);
115 /* Find a new symbol table entry in the given table. If AllocNew is given and
116  * the entry is not found, create a new one. Return the entry found, or the
117  * new entry created, or - in case AllocNew is zero - return 0.
118  */
119
120 int SymIsZP (SymEntry* Sym);
121 /* Return true if the symbol is explicitly marked as zeropage symbol */
122
123 #if defined(HAVE_INLINE)
124 INLINE unsigned char GetSymTabType (const SymTable* S)
125 /* Return the type of the given symbol table */
126 {
127     return S->Type;
128 }
129 #else
130 #  define GetSymTabType(S)      ((S)->Type)
131 #endif
132
133 unsigned char GetCurrentSymTabType ();
134 /* Return the type of the current symbol table */
135
136 void SymCheck (void);
137 /* Run through all symbols and check for anomalies and errors */
138
139 void SymDump (FILE* F);
140 /* Dump the symbol table */
141
142 void WriteImports (void);
143 /* Write the imports list to the object file */
144
145 void WriteExports (void);
146 /* Write the exports list to the object file */
147
148 void WriteDbgSyms (void);
149 /* Write a list of all symbols to the object file */
150
151
152
153 /* End of symtab.h */
154
155 #endif
156
157
158
159