1 /*****************************************************************************/
5 /* Symbol table management for the cc65 C compiler */
9 /* (C) 2000-2013, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 /*****************************************************************************/
43 #include "debugflag.h"
65 /*****************************************************************************/
67 /*****************************************************************************/
71 /* An empty symbol table */
72 SymTable EmptySymTab = {
81 /* Symbol table sizes */
82 #define SYMTAB_SIZE_GLOBAL 211U
83 #define SYMTAB_SIZE_FUNCTION 29U
84 #define SYMTAB_SIZE_BLOCK 13U
85 #define SYMTAB_SIZE_STRUCT 19U
86 #define SYMTAB_SIZE_LABEL 7U
88 /* The current and root symbol tables */
89 static unsigned LexicalLevel = 0; /* For safety checks */
90 static SymTable* SymTab0 = 0;
91 static SymTable* SymTab = 0;
92 static SymTable* TagTab0 = 0;
93 static SymTable* TagTab = 0;
94 static SymTable* LabelTab = 0;
98 /*****************************************************************************/
100 /*****************************************************************************/
104 static SymTable* NewSymTable (unsigned Size)
105 /* Create and return a symbol table for the given lexical level */
109 /* Allocate memory for the table */
110 SymTable* S = xmalloc (sizeof (SymTable) + (Size-1) * sizeof (SymEntry*));
112 /* Initialize the symbol table structure */
118 for (I = 0; I < Size; ++I) {
122 /* Return the symbol table */
128 static void FreeSymTable (SymTable* S)
129 /* Free the given symbo table including all symbols */
131 /* Free all symbols */
132 SymEntry* Sym = S->SymHead;
134 SymEntry* NextSym = Sym->NextSym;
139 /* Free the table itself */
145 /*****************************************************************************/
146 /* Check symbols in a table */
147 /*****************************************************************************/
151 static void CheckSymTable (SymTable* Tab)
152 /* Check a symbol table for open references, unused symbols ... */
154 SymEntry* Entry = Tab->SymHead;
157 /* Get the storage flags for tne entry */
158 unsigned Flags = Entry->Flags;
160 /* Ignore typedef entries */
161 if (!SymIsTypeDef (Entry)) {
163 /* Check if the symbol is one with storage, and it if it was
164 ** defined but not used.
166 if (((Flags & SC_AUTO) || (Flags & SC_STATIC)) && (Flags & SC_EXTERN) == 0) {
167 if (SymIsDef (Entry) && !SymIsRef (Entry) &&
168 !SymHasAttr (Entry, atUnused)) {
169 if (Flags & SC_PARAM) {
170 if (IS_Get (&WarnUnusedParam)) {
171 Warning ("Parameter `%s' is never used", Entry->Name);
174 if (IS_Get (&WarnUnusedVar)) {
175 Warning ("`%s' is defined but never used", Entry->Name);
181 /* If the entry is a label, check if it was defined in the function */
182 if (Flags & SC_LABEL) {
183 if (!SymIsDef (Entry)) {
184 /* Undefined label */
185 Error ("Undefined label: `%s'", Entry->Name);
186 } else if (!SymIsRef (Entry)) {
187 /* Defined but not used */
188 if (IS_Get (&WarnUnusedLabel)) {
189 Warning ("`%s' is defined but never used", Entry->Name);
197 Entry = Entry->NextSym;
203 /*****************************************************************************/
204 /* Handling of lexical levels */
205 /*****************************************************************************/
209 unsigned GetLexicalLevel (void)
210 /* Return the current lexical level */
217 void EnterGlobalLevel (void)
218 /* Enter the program global lexical level */
221 PRECONDITION (++LexicalLevel == LEX_LEVEL_GLOBAL);
223 /* Create and assign the symbol table */
224 SymTab0 = SymTab = NewSymTable (SYMTAB_SIZE_GLOBAL);
226 /* Create and assign the tag table */
227 TagTab0 = TagTab = NewSymTable (SYMTAB_SIZE_GLOBAL);
232 void LeaveGlobalLevel (void)
233 /* Leave the program global lexical level */
236 PRECONDITION (LexicalLevel-- == LEX_LEVEL_GLOBAL);
238 /* Check the tables */
239 CheckSymTable (SymTab0);
241 /* Dump the tables if requested */
243 PrintSymTable (SymTab0, stdout, "Global symbol table");
244 PrintSymTable (TagTab0, stdout, "Global tag table");
247 /* Don't delete the symbol and struct tables! */
254 void EnterFunctionLevel (void)
255 /* Enter function lexical level */
259 /* New lexical level */
262 /* Get a new symbol table and make it current */
263 S = NewSymTable (SYMTAB_SIZE_FUNCTION);
267 /* Get a new tag table and make it current */
268 S = NewSymTable (SYMTAB_SIZE_FUNCTION);
272 /* Create and assign a new label table */
273 S = NewSymTable (SYMTAB_SIZE_LABEL);
274 S->PrevTab = LabelTab;
280 void RememberFunctionLevel (struct FuncDesc* F)
281 /* Remember the symbol tables for the level and leave the level without checks */
283 /* Leave the lexical level */
286 /* Remember the tables */
290 /* Don't delete the tables */
291 SymTab = SymTab->PrevTab;
292 TagTab = TagTab->PrevTab;
293 LabelTab = LabelTab->PrevTab;
298 void ReenterFunctionLevel (struct FuncDesc* F)
299 /* Reenter the function lexical level using the existing tables from F */
301 /* New lexical level */
304 /* Make the tables current again */
305 F->SymTab->PrevTab = SymTab;
308 F->TagTab->PrevTab = TagTab;
311 /* Create and assign a new label table */
312 LabelTab = NewSymTable (SYMTAB_SIZE_LABEL);
317 void LeaveFunctionLevel (void)
318 /* Leave function lexical level */
320 /* Leave the lexical level */
323 /* Check the tables */
324 CheckSymTable (SymTab);
325 CheckSymTable (LabelTab);
327 /* Drop the label table if it is empty */
328 if (LabelTab->SymCount == 0) {
329 FreeSymTable (LabelTab);
332 /* Don't delete the tables */
333 SymTab = SymTab->PrevTab;
334 TagTab = TagTab->PrevTab;
340 void EnterBlockLevel (void)
341 /* Enter a nested block in a function */
345 /* New lexical level */
348 /* Get a new symbol table and make it current */
349 S = NewSymTable (SYMTAB_SIZE_BLOCK);
353 /* Get a new tag table and make it current */
354 S = NewSymTable (SYMTAB_SIZE_BLOCK);
361 void LeaveBlockLevel (void)
362 /* Leave a nested block in a function */
364 /* Leave the lexical level */
367 /* Check the tables */
368 CheckSymTable (SymTab);
370 /* Don't delete the tables */
371 SymTab = SymTab->PrevTab;
372 TagTab = TagTab->PrevTab;
377 void EnterStructLevel (void)
378 /* Enter a nested block for a struct definition */
382 /* Get a new symbol table and make it current. Note: Structs and enums
383 ** nested in struct scope are NOT local to the struct but visible in the
384 ** outside scope. So we will NOT create a new struct or enum table.
386 S = NewSymTable (SYMTAB_SIZE_BLOCK);
393 void LeaveStructLevel (void)
394 /* Leave a nested block for a struct definition */
396 /* Don't delete the table */
397 SymTab = SymTab->PrevTab;
402 /*****************************************************************************/
404 /*****************************************************************************/
408 static SymEntry* FindSymInTable (const SymTable* T, const char* Name, unsigned Hash)
409 /* Search for an entry in one table */
411 /* Get the start of the hash chain */
412 SymEntry* E = T->Tab [Hash % T->Size];
414 /* Compare the name */
415 if (strcmp (E->Name, Name) == 0) {
419 /* Not found, next entry in hash chain */
429 static SymEntry* FindSymInTree (const SymTable* Tab, const char* Name)
430 /* Find the symbol with the given name in the table tree that starts with T */
432 /* Get the hash over the name */
433 unsigned Hash = HashStr (Name);
435 /* Check all symbol tables for the symbol */
437 /* Try to find the symbol in this table */
438 SymEntry* E = FindSymInTable (Tab, Name, Hash);
440 /* Bail out if we found it */
445 /* Repeat the search in the next higher lexical level */
455 SymEntry* FindSym (const char* Name)
456 /* Find the symbol with the given name */
458 return FindSymInTree (SymTab, Name);
463 SymEntry* FindGlobalSym (const char* Name)
464 /* Find the symbol with the given name in the global symbol table only */
466 return FindSymInTable (SymTab0, Name, HashStr (Name));
471 SymEntry* FindLocalSym (const char* Name)
472 /* Find the symbol with the given name in the current symbol table only */
474 return FindSymInTable (SymTab, Name, HashStr (Name));
479 SymEntry* FindTagSym (const char* Name)
480 /* Find the symbol with the given name in the tag table */
482 return FindSymInTree (TagTab, Name);
487 SymEntry* FindStructField (const Type* T, const char* Name)
488 /* Find a struct field in the fields list */
492 /* The given type may actually be a pointer to struct */
497 /* Non-structs do not have any struct fields... */
498 if (IsClassStruct (T)) {
500 /* Get a pointer to the struct/union type */
501 const SymEntry* Struct = GetSymEntry (T);
504 /* Now search in the struct symbol table. Beware: The table may not
507 if (Struct->V.S.SymTab) {
508 Field = FindSymInTable (Struct->V.S.SymTab, Name, HashStr (Name));
517 /*****************************************************************************/
518 /* Add stuff to the symbol table */
519 /*****************************************************************************/
523 static void AddSymEntry (SymTable* T, SymEntry* S)
524 /* Add a symbol to a symbol table */
526 /* Get the hash value for the name */
527 unsigned Hash = HashStr (S->Name) % T->Size;
529 /* Insert the symbol into the list of all symbols in this level */
531 T->SymTail->NextSym = S;
533 S->PrevSym = T->SymTail;
535 if (T->SymHead == 0) {
541 /* Insert the symbol into the hash chain */
542 S->NextHash = T->Tab[Hash];
545 /* Tell the symbol in which table it is */
551 SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab)
552 /* Add a struct/union entry and return it */
556 /* Type must be struct or union */
557 PRECONDITION (Type == SC_STRUCT || Type == SC_UNION);
559 /* Do we have an entry with this name already? */
560 Entry = FindSymInTable (TagTab, Name, HashStr (Name));
563 /* We do have an entry. This may be a forward, so check it. */
564 if ((Entry->Flags & SC_TYPEMASK) != Type) {
565 /* Existing symbol is not a struct */
566 Error ("Symbol `%s' is already different kind", Name);
567 } else if (Size > 0 && Entry->V.S.Size > 0) {
568 /* Both structs are definitions. */
569 Error ("Multiple definition for `%s'", Name);
571 /* Define the struct size if it is given */
573 Entry->V.S.SymTab = Tab;
574 Entry->V.S.Size = Size;
580 /* Create a new entry */
581 Entry = NewSymEntry (Name, Type);
583 /* Set the struct data */
584 Entry->V.S.SymTab = Tab;
585 Entry->V.S.Size = Size;
587 /* Add it to the current table */
588 AddSymEntry (TagTab, Entry);
591 /* Return the entry */
597 SymEntry* AddBitField (const char* Name, unsigned Offs, unsigned BitOffs, unsigned Width)
598 /* Add a bit field to the local symbol table and return the symbol entry */
600 /* Do we have an entry with this name already? */
601 SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name));
604 /* We have a symbol with this name already */
605 Error ("Multiple definition for `%s'", Name);
609 /* Create a new entry */
610 Entry = NewSymEntry (Name, SC_BITFIELD);
612 /* Set the symbol attributes. Bit-fields are always of type unsigned */
613 Entry->Type = type_uint;
614 Entry->V.B.Offs = Offs;
615 Entry->V.B.BitOffs = BitOffs;
616 Entry->V.B.BitWidth = Width;
618 /* Add the entry to the symbol table */
619 AddSymEntry (SymTab, Entry);
623 /* Return the entry */
629 SymEntry* AddConstSym (const char* Name, const Type* T, unsigned Flags, long Val)
630 /* Add an constant symbol to the symbol table and return it */
632 /* Enums must be inserted in the global symbol table */
633 SymTable* Tab = ((Flags & SC_ENUM) == SC_ENUM)? SymTab0 : SymTab;
635 /* Do we have an entry with this name already? */
636 SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name));
638 if ((Entry->Flags & SC_CONST) != SC_CONST) {
639 Error ("Symbol `%s' is already different kind", Name);
641 Error ("Multiple definition for `%s'", Name);
646 /* Create a new entry */
647 Entry = NewSymEntry (Name, Flags);
649 /* Enum values are ints */
650 Entry->Type = TypeDup (T);
652 /* Set the enum data */
653 Entry->V.ConstVal = Val;
655 /* Add the entry to the symbol table */
656 AddSymEntry (Tab, Entry);
658 /* Return the entry */
663 DefOrRef* AddDefOrRef(SymEntry* E, unsigned Flags)
664 /* Add definition or reference to the SymEntry and preserve its attributes */
668 DOR = xmalloc (sizeof (DefOrRef));
669 CollAppend (E->V.L.DefsOrRefs, DOR);
670 DOR->Line = GetCurrentLine ();
671 DOR->LocalsBlockId = (long)CollLast (&CurrentFunc->LocalsBlockStack);
673 DOR->StackPtr = StackPtr;
674 DOR->Depth = CollCount (&CurrentFunc->LocalsBlockStack);
675 DOR->LateSP_Label = GetLocalLabel ();
680 SymEntry* AddLabelSym (const char* Name, unsigned Flags)
681 /* Add a goto label to the label table */
684 DefOrRef *DOR, *NewDOR;
685 /* We juggle it so much that a shortcut will help with clarity */
686 Collection *AIC = &CurrentFunc->LocalsBlockStack;
688 /* Do we have an entry with this name already? */
689 SymEntry* Entry = FindSymInTable (LabelTab, Name, HashStr (Name));
692 if (SymIsDef (Entry) && (Flags & SC_DEF) != 0) {
693 /* Trying to define the label more than once */
694 Error ("Label `%s' is defined more than once", Name);
697 NewDOR = AddDefOrRef (Entry, Flags);
699 /* Walk through all occurrences of the label so far and evaluate
700 their relationship with the one passed to the function. */
701 for (i = 0; i < CollCount (Entry->V.L.DefsOrRefs); i++) {
702 DOR = CollAt (Entry->V.L.DefsOrRefs, i);
704 if ((DOR->Flags & SC_DEF) && (Flags & SC_REF)) {
705 /* We're processing a goto and here is its destination label.
706 This means the difference between SP values is already known,
707 so we simply emit the SP adjustment code. */
708 if (StackPtr != DOR->StackPtr) {
709 g_space (StackPtr - DOR->StackPtr);
712 /* Are we jumping into a block with initalization of an object that
713 has automatic storage duration? Let's emit a warning. */
714 if ((long)CollLast (AIC) != DOR->LocalsBlockId &&
715 (CollCount (AIC) < DOR->Depth ||
716 (long)CollAt (AIC, DOR->Depth - 1) != DOR->LocalsBlockId)) {
717 Warning ("Goto at line %d to label %s jumps into a block with "
718 "initialization of an object that has automatic storage duration.",
719 GetCurrentLine (), Name);
724 if ((DOR->Flags & SC_REF) && (Flags & SC_DEF)) {
725 /* We're processing a label, let's update all gotos encountered
727 g_defdatalabel (DOR->LateSP_Label);
728 g_defdata (CF_CONST | CF_INT, StackPtr - DOR->StackPtr, 0);
730 /* Are we jumping into a block with initalization of an object that
731 has automatic storage duration? Let's emit a warning. */
732 if ((long)CollLast (AIC) != DOR->LocalsBlockId &&
733 (CollCount (AIC) >= DOR->Depth ||
734 (long)CollLast (AIC) >= DOR->Line))
735 Warning ("Goto at line %d to label %s jumps into a block with "
736 "initialization of an object that has automatic storage duration.",
742 Entry->Flags |= Flags;
746 /* Create a new entry */
747 Entry = NewSymEntry (Name, SC_LABEL | Flags);
749 /* Set a new label number */
750 Entry->V.L.Label = GetLocalLabel ();
752 /* Create Collection for label definition and references */
753 Entry->V.L.DefsOrRefs = NewCollection ();
754 NewDOR = AddDefOrRef (Entry, Flags);
756 /* Generate the assembler name of the label */
757 Entry->AsmName = xstrdup (LocalLabelName (Entry->V.L.Label));
759 /* Add the entry to the label table */
760 AddSymEntry (LabelTab, Entry);
764 /* We are processing a goto, but the label has not yet been defined */
765 if (!SymIsDef (Entry) && (Flags & SC_REF)) {
766 g_lateadjustSP (NewDOR->LateSP_Label);
769 /* Return the entry */
775 SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs)
776 /* Add a local symbol and return the symbol entry */
778 /* Do we have an entry with this name already? */
779 SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name));
782 /* We have a symbol with this name already */
783 Error ("Multiple definition for `%s'", Name);
787 /* Create a new entry */
788 Entry = NewSymEntry (Name, Flags);
790 /* Set the symbol attributes */
791 Entry->Type = TypeDup (T);
792 if ((Flags & SC_AUTO) == SC_AUTO) {
793 Entry->V.Offs = Offs;
794 } else if ((Flags & SC_REGISTER) == SC_REGISTER) {
795 Entry->V.R.RegOffs = Offs;
796 Entry->V.R.SaveOffs = StackPtr;
797 } else if ((Flags & SC_EXTERN) == SC_EXTERN) {
798 Entry->V.L.Label = Offs;
799 SymSetAsmName (Entry);
800 } else if ((Flags & SC_STATIC) == SC_STATIC) {
801 /* Generate the assembler name from the label number */
802 Entry->V.L.Label = Offs;
803 Entry->AsmName = xstrdup (LocalLabelName (Entry->V.L.Label));
804 } else if ((Flags & SC_STRUCTFIELD) == SC_STRUCTFIELD) {
805 Entry->V.Offs = Offs;
807 Internal ("Invalid flags in AddLocalSym: %04X", Flags);
810 /* Add the entry to the symbol table */
811 AddSymEntry (SymTab, Entry);
815 /* Return the entry */
821 SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags)
822 /* Add an external or global symbol to the symbol table and return the entry */
824 /* There is some special handling for functions, so check if it is one */
825 int IsFunc = IsTypeFunc (T);
827 /* Functions must be inserted in the global symbol table */
828 SymTable* Tab = IsFunc? SymTab0 : SymTab;
830 /* Do we have an entry with this name already? */
831 SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name));
836 /* We have a symbol with this name already */
837 if (Entry->Flags & SC_TYPE) {
838 Error ("Multiple definition for `%s'", Name);
842 /* Get the type string of the existing symbol */
845 /* If we are handling arrays, the old entry or the new entry may be an
846 ** incomplete declaration. Accept this, and if the exsting entry is
847 ** incomplete, complete it.
849 if (IsTypeArray (T) && IsTypeArray (EType)) {
851 /* Get the array sizes */
852 long Size = GetElementCount (T);
853 long ESize = GetElementCount (EType);
855 if ((Size != UNSPECIFIED && ESize != UNSPECIFIED && Size != ESize) ||
856 TypeCmp (T + 1, EType + 1) < TC_EQUAL) {
857 /* Types not identical: Conflicting types */
858 Error ("Conflicting types for `%s'", Name);
861 /* Check if we have a size in the existing definition */
862 if (ESize == UNSPECIFIED) {
863 /* Existing, size not given, use size from new def */
864 SetElementCount (EType, Size);
869 /* New type must be identical */
870 if (TypeCmp (EType, T) < TC_EQUAL) {
871 Error ("Conflicting types for `%s'", Name);
875 /* In case of a function, use the new type descriptor, since it
876 ** contains pointers to the new symbol tables that are needed if
877 ** an actual function definition follows. Be sure not to use the
878 ** new descriptor if it contains a function declaration with an
879 ** empty parameter list.
882 /* Get the function descriptor from the new type */
883 FuncDesc* F = GetFuncDesc (T);
884 /* Use this new function descriptor if it doesn't contain
885 ** an empty parameter list.
887 if ((F->Flags & FD_EMPTY) == 0) {
889 SetFuncDesc (EType, F);
894 /* If a static declaration follows a non-static declaration, then
895 ** warn about the conflict. (It will compile a public declaration.)
897 if ((Flags & SC_EXTERN) == 0 && (Entry->Flags & SC_EXTERN) != 0) {
898 Warning ("static declaration follows non-static declaration of `%s'.", Name);
901 /* An extern declaration must not change the current linkage. */
902 if (IsFunc || (Flags & (SC_EXTERN | SC_STORAGE)) == SC_EXTERN) {
906 /* If a public declaration follows a static declaration, then
907 ** warn about the conflict. (It will compile a public declaration.)
909 if ((Flags & SC_EXTERN) != 0 && (Entry->Flags & SC_EXTERN) == 0) {
910 Warning ("public declaration follows static declaration of `%s'.", Name);
913 /* Add the new flags */
914 Entry->Flags |= Flags;
918 /* Create a new entry */
919 Entry = NewSymEntry (Name, Flags);
921 /* Set the symbol attributes */
922 Entry->Type = TypeDup (T);
924 /* If this is a function, set the function descriptor and clear
925 ** additional fields.
928 Entry->V.F.Func = GetFuncDesc (Entry->Type);
932 /* Add the assembler name of the symbol */
933 SymSetAsmName (Entry);
935 /* Add the entry to the symbol table */
936 AddSymEntry (Tab, Entry);
939 /* Return the entry */
945 /*****************************************************************************/
947 /*****************************************************************************/
951 SymTable* GetSymTab (void)
952 /* Return the current symbol table */
959 SymTable* GetGlobalSymTab (void)
960 /* Return the global symbol table */
967 int SymIsLocal (SymEntry* Sym)
968 /* Return true if the symbol is defined in the highest lexical level */
970 return (Sym->Owner == SymTab || Sym->Owner == TagTab);
975 void MakeZPSym (const char* Name)
976 /* Mark the given symbol as zero page symbol */
978 /* Get the symbol table entry */
979 SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name));
981 /* Mark the symbol as zeropage */
983 Entry->Flags |= SC_ZEROPAGE;
985 Error ("Undefined symbol: `%s'", Name);
991 void PrintSymTable (const SymTable* Tab, FILE* F, const char* Header, ...)
992 /* Write the symbol table to the given file */
995 const SymEntry* Entry;
997 /* Print the header */
999 va_start (ap, Header);
1001 Len = vfprintf (F, Header, ap);
1005 /* Underline the header */
1011 /* Dump the table */
1012 Entry = Tab->SymHead;
1014 fprintf (F, "(empty)\n");
1017 DumpSymEntry (F, Entry);
1018 Entry = Entry->NextSym;
1021 fprintf (F, "\n\n\n");
1026 void EmitExternals (void)
1027 /* Write import/export statements for external symbols */
1031 Entry = SymTab->SymHead;
1033 unsigned Flags = Entry->Flags;
1034 if (Flags & SC_EXTERN) {
1035 /* Only defined or referenced externs */
1036 if (SymIsRef (Entry) && !SymIsDef (Entry)) {
1038 g_defimport (Entry->Name, Flags & SC_ZEROPAGE);
1039 } else if (SymIsDef (Entry)) {
1041 g_defexport (Entry->Name, Flags & SC_ZEROPAGE);
1044 Entry = Entry->NextSym;
1050 void EmitDebugInfo (void)
1051 /* Emit debug infos for the locals of the current scope */
1054 const SymEntry* Sym;
1056 /* Output info for locals if enabled */
1058 /* For cosmetic reasons in the output file, we will insert two tabs
1059 ** on global level and just one on local level.
1061 if (LexicalLevel == LEX_LEVEL_GLOBAL) {
1062 Head = "\t.dbg\t\tsym";
1064 Head = "\t.dbg\tsym";
1066 Sym = SymTab->SymHead;
1068 if ((Sym->Flags & (SC_CONST|SC_TYPE)) == 0) {
1069 if (Sym->Flags & SC_AUTO) {
1070 AddTextLine ("%s, \"%s\", \"00\", auto, %d",
1071 Head, Sym->Name, Sym->V.Offs);
1072 } else if (Sym->Flags & SC_REGISTER) {
1073 AddTextLine ("%s, \"%s\", \"00\", register, \"regbank\", %d",
1074 Head, Sym->Name, Sym->V.R.RegOffs);
1076 } else if (SymIsRef (Sym) && !SymIsDef (Sym)) {
1077 AddTextLine ("%s, \"%s\", \"00\", %s, \"%s\"",
1079 (Sym->Flags & SC_EXTERN)? "extern" : "static",