1 /*****************************************************************************/
5 /* Symbol table entries for the cc65 C compiler */
9 /* (C) 2000-2002 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
53 SymEntry* NewSymEntry (const char* Name, unsigned Flags)
54 /* Create a new symbol table with the given name */
56 /* Get the length of the name */
57 unsigned Len = strlen (Name);
59 /* Allocate memory for the symbol entry */
60 SymEntry* E = xmalloc (sizeof (SymEntry) + Len);
62 /* Initialize the entry */
71 memcpy (E->Name, Name, Len+1);
73 /* Return the new entry */
79 void FreeSymEntry (SymEntry* E)
80 /* Free a symbol entry */
89 void DumpSymEntry (FILE* F, const SymEntry* E)
90 /* Dump the given symbol table entry to the file in readable form */
96 /* Beware: Order is important! */
97 { "SC_TYPEDEF", SC_TYPEDEF },
98 { "SC_SFLD", SC_SFLD },
99 { "SC_STRUCT", SC_STRUCT },
100 { "SC_AUTO", SC_AUTO },
101 { "SC_REGISTER", SC_REGISTER },
102 { "SC_STATIC", SC_STATIC },
103 { "SC_EXTERN", SC_EXTERN },
104 { "SC_ENUM", SC_ENUM },
105 { "SC_CONST", SC_CONST },
106 { "SC_LABEL", SC_LABEL },
107 { "SC_PARAM", SC_PARAM },
108 { "SC_FUNC", SC_FUNC },
109 { "SC_STORAGE", SC_STORAGE },
110 { "SC_DEF", SC_DEF },
111 { "SC_REF", SC_REF },
112 { "SC_ZEROPAGE", SC_ZEROPAGE },
119 fprintf (F, "%s:\n", E->Name);
121 /* Print the assembler name if we have one */
123 fprintf (F, " AsmName: %s\n", E->AsmName);
126 /* Print the flags */
128 fprintf (F, " Flags: ");
129 for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
130 if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
131 SymFlags &= ~Flags[I].Val;
132 fprintf (F, "%s ", Flags[I].Name);
136 fprintf (F, "%04X", SymFlags);
141 fprintf (F, " Type: ");
143 PrintType (F, E->Type);
145 fprintf (F, "(none)");
152 int IsTypeDef (const SymEntry* E)
153 /* Return true if the given entry is a typedef entry */
155 return ((E->Flags & SC_TYPEDEF) == SC_TYPEDEF);
160 void ChangeSymType (SymEntry* Entry, type* Type)
161 /* Change the type of the given symbol */
163 TypeFree (Entry->Type);
164 Entry->Type = TypeDup (Type);
169 void ChangeAsmName (SymEntry* Entry, const char* NewAsmName)
170 /* Change the assembler name of the symbol */
172 xfree (Entry->AsmName);
173 Entry->AsmName = xstrdup (NewAsmName);
178 int HasAnonName (const SymEntry* Entry)
179 /* Return true if the symbol entry has an anonymous name */
181 return IsAnonName (Entry->Name);