X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fsymtab.c;h=eca971f654b2fa58168f2429309d6e4a6c2085ee;hb=426bea8c19391ebd809cb4dfac28ae20c0d4953b;hp=9228e5628617abec115547b8f077a11492fdb0f5;hpb=594a941ee94d1cd7369256ac6ffa9ebf26e33a64;p=cc65 diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 9228e5628..eca971f65 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -224,13 +224,13 @@ void LeaveGlobalLevel (void) /* Dump the tables if requested */ if (Debug) { - PrintSymTable (SymTab0, stdout, "Global symbol table"); - PrintSymTable (TagTab0, stdout, "Global tag table"); + PrintSymTable (SymTab0, stdout, "Global symbol table"); + PrintSymTable (TagTab0, stdout, "Global tag table"); } /* Don't delete the symbol and struct tables! */ - SymTab0 = SymTab = 0; - TagTab0 = TagTab = 0; + SymTab = 0; + TagTab = 0; } @@ -441,6 +441,14 @@ SymEntry* FindSym (const char* Name) +SymEntry* FindGlobalSym (const char* Name) +/* Find the symbol with the given name in the global symbol table only */ +{ + return FindSymInTable (SymTab0, Name, HashStr (Name)); +} + + + SymEntry* FindLocalSym (const char* Name) /* Find the symbol with the given name in the current symbol table only */ { @@ -567,13 +575,13 @@ SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab) -SymEntry* AddEnumSym (const char* Name, int Val) -/* Add an enum symbol to the symbol table and return it */ +SymEntry* AddConstSym (const char* Name, const type* Type, unsigned Flags, long Val) +/* Add an constant symbol to the symbol table and return it */ { /* Do we have an entry with this name already? */ SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name)); if (Entry) { - if (Entry->Flags != SC_ENUM) { + if ((Entry->Flags & SC_CONST) != SC_CONST) { Error ("Symbol `%s' is already different kind", Name); } else { Error ("Multiple definition for `%s'", Name); @@ -582,13 +590,13 @@ SymEntry* AddEnumSym (const char* Name, int Val) } /* Create a new entry */ - Entry = NewSymEntry (Name, SC_ENUM); + Entry = NewSymEntry (Name, Flags); /* Enum values are ints */ - Entry->Type = TypeDup (type_int); + Entry->Type = TypeDup (Type); /* Set the enum data */ - Entry->V.EnumVal = Val; + Entry->V.ConstVal = Val; /* Add the entry to the symbol table */ AddSymEntry (SymTab, Entry); @@ -618,7 +626,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags) Entry = NewSymEntry (Name, SC_LABEL | Flags); /* Set a new label number */ - Entry->V.Label = GetLabel (); + Entry->V.Label = GetLocalLabel (); /* Add the entry to the label table */ AddSymEntry (LabelTab, Entry); @@ -664,8 +672,11 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) /* Add an external or global symbol to the symbol table and return the entry */ { + /* There is some special handling for functions, so check if it is one */ + int IsFunc = IsTypeFunc (Type); + /* Functions must be inserted in the global symbol table */ - SymTable* Tab = IsTypeFunc (Type)? SymTab0 : SymTab; + SymTable* Tab = IsFunc? SymTab0 : SymTab; /* Do we have an entry with this name already? */ SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name)); @@ -692,7 +703,7 @@ SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) unsigned Size = Decode (Type + 1); unsigned ESize = Decode (EType + 1); - if ((Size != 0 && ESize != 0) || + if ((Size != 0 && ESize != 0 && Size != ESize) || TypeCmp (Type+DECODE_SIZE+1, EType+DECODE_SIZE+1) < TC_EQUAL) { /* Types not identical: Conflicting types */ Error ("Conflicting types for `%s'", Name); @@ -716,8 +727,12 @@ SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) * contains pointers to the new symbol tables that are needed if * an actual function definition follows. */ - if (IsTypeFunc (Type)) { - CopyEncode (Type+1, EType+1); + if (IsFunc) { + /* Get the function descriptor from the new type */ + FuncDesc* F = GetFuncDesc (Type); + /* Use this new function descriptor */ + Entry->V.F.Func = F; + EncodePtr (EType+1, F); } } @@ -729,9 +744,17 @@ SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) /* Create a new entry */ Entry = NewSymEntry (Name, Flags); - /* Set the symbol attributes */ + /* Set the symbol attributes */ Entry->Type = TypeDup (Type); + /* If this is a function, set the function descriptor and clear + * additional fields. + */ + if (IsFunc) { + Entry->V.F.Func = GetFuncDesc (Entry->Type); + Entry->V.F.Seg = 0; + } + /* Add the entry to the symbol table */ AddSymEntry (Tab, Entry); } @@ -756,6 +779,14 @@ SymTable* GetSymTab (void) +SymTable* GetGlobalSymTab (void) +/* Return the global symbol table */ +{ + return SymTab0; +} + + + int SymIsLocal (SymEntry* Sym) /* Return true if the symbol is defined in the highest lexical level */ { @@ -820,8 +851,6 @@ void EmitExternals (void) { SymEntry* Entry; - AddEmptyLine (); - Entry = SymTab->SymHead; while (Entry) { unsigned Flags = Entry->Flags;