]> git.sur5r.net Git - cc65/blob - src/cc65/symtab.h
Polishing and minor corrections
[cc65] / src / cc65 / symtab.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 symtab.h                                  */
4 /*                                                                           */
5 /*              Symbol table management for the cc65 C compiler              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 #include "datatype.h"
44 #include "symentry.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Symbol table */
55 typedef struct SymTable SymTable;
56 struct SymTable {
57     SymTable*           PrevTab;        /* Pointer to higher level symbol table */
58     SymEntry*           SymHead;        /* Double linked list of symbols */
59     SymEntry*           SymTail;        /* Double linked list of symbols */
60     unsigned            SymCount;       /* Count of symbols in this table */
61     unsigned            Size;           /* Size of table */
62     SymEntry*           Tab[1];         /* Actual table, dynamically allocated */
63 };
64
65 /* An empty symbol table */
66 extern SymTable         EmptySymTab;
67
68 /* Forwards */
69 struct FuncDesc;
70
71
72
73 /*****************************************************************************/
74 /*                        Handling of lexical levels                         */
75 /*****************************************************************************/
76
77
78
79 void EnterGlobalLevel (void);
80 /* Enter the program global lexical level */
81
82 void LeaveGlobalLevel (void);
83 /* Leave the program global lexical level */
84
85 void EnterFunctionLevel (void);
86 /* Enter function lexical level */
87
88 void RememberFunctionLevel (struct FuncDesc* F);
89 /* Remember the symbol tables for the level and leave the level without checks */
90
91 void ReenterFunctionLevel (struct FuncDesc* F);
92 /* Reenter the function lexical level using the existing tables from F */
93
94 void LeaveFunctionLevel (void);
95 /* Leave function lexical level */
96
97 void EnterBlockLevel (void);
98 /* Enter a nested block in a function */
99
100 void LeaveBlockLevel (void);
101 /* Leave a nested block in a function */
102
103 void EnterStructLevel (void);
104 /* Enter a nested block for a struct definition */
105
106 void LeaveStructLevel (void);
107 /* Leave a nested block for a struct definition */
108
109
110
111 /*****************************************************************************/
112 /*                              Find functions                               */
113 /*****************************************************************************/
114
115
116
117 SymEntry* FindSym (const char* Name);
118 /* Find the symbol with the given name */
119
120 SymEntry* FindGlobalSym (const char* Name);
121 /* Find the symbol with the given name in the global symbol table only */
122
123 SymEntry* FindLocalSym (const char* Name);
124 /* Find the symbol with the given name in the current symbol table only */
125
126 SymEntry* FindTagSym (const char* Name);
127 /* Find the symbol with the given name in the tag table */
128
129 SymEntry* FindStructField (const type* TypeArray, const char* Name);
130 /* Find a struct field in the fields list */
131
132
133
134 /*****************************************************************************/
135 /*                       Add stuff to the symbol table                       */
136 /*****************************************************************************/
137
138
139
140 SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab);
141 /* Add a struct/union entry and return it */
142
143 SymEntry* AddConstSym (const char* Name, const type* Type, unsigned Flags, long Val);
144 /* Add an constant symbol to the symbol table and return it */
145
146 SymEntry* AddLabelSym (const char* Name, unsigned Flags);
147 /* Add a goto label to the symbol table */
148
149 SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int Offs);
150 /* Add a local symbol and return the symbol entry */
151
152 SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags);
153 /* Add an external or global symbol to the symbol table and return the entry */
154
155
156
157 /*****************************************************************************/
158 /*                                   Code                                    */
159 /*****************************************************************************/
160
161
162
163 SymTable* GetSymTab (void);
164 /* Return the current symbol table */
165
166 SymTable* GetGlobalSymTab (void);
167 /* Return the global symbol table */
168
169 int SymIsLocal (SymEntry* Sym);
170 /* Return true if the symbol is defined in the highest lexical level */
171
172 void MakeZPSym (const char* Name);
173 /* Mark the given symbol as zero page symbol */
174
175 void PrintSymTable (const SymTable* Tab, FILE* F, const char* Header, ...);
176 /* Write the symbol table to the given file */
177
178 void EmitExternals (void);
179 /* Write import/export statements for external symbols */
180
181
182
183 /* End of symtab.h */
184
185 #endif
186
187
188