Browse Source

Switch SECTION.Symbols from list-type operations to tree-type operations.

git-svn-id: file:///var/svn/tigccpp/branches/ld-tigcc-optimization@1290 9552661e-59e3-4036-b4f2-dbe53926924f
debrouxl 15 years ago
parent
commit
703ef9e97e
9 changed files with 51 additions and 51 deletions
  1. 22 22
      constmrg.c
  2. 6 6
      dump.c
  3. 5 5
      export/exp_dbg.c
  4. 1 1
      gcunused.c
  5. 1 1
      import/imp_amig.c
  6. 2 2
      insert/kernel.c
  7. 2 2
      insert/other.c
  8. 7 7
      manip.c
  9. 5 5
      special.c

+ 22 - 22
constmrg.c

@@ -59,7 +59,7 @@ void MergeConstants (PROGRAM *Program)
 		SYMBOL *Symbol1, *NextSymbol1;
 		NextSection1 = GetNext (Section1);
 		if (!Section1->Mergeable) continue; // Ignore non-mergeable sections.
-		for (Symbol1 = GetFirst(Section1->Symbols); Symbol1; Symbol1 = NextSymbol1)
+		for (Symbol1 = TreeFirst(Section1->Symbols); Symbol1; Symbol1 = NextSymbol1)
 		{
 			// Compute the length of the constant.
 			OFFSET Constant1Start = Symbol1->Location, Constant1End, Constant1Length;
@@ -79,7 +79,7 @@ void MergeConstants (PROGRAM *Program)
 				SYMBOL *Symbol2, *NextSymbol2;
 				NextSection2 = GetNext (Section2);
 				if (!Section2->Mergeable) continue; // Ignore non-mergeable sections.
-				for (Symbol2 = GetFirst(Section2->Symbols); Symbol2; Symbol2 = NextSymbol2)
+				for (Symbol2 = TreeFirst(Section2->Symbols); Symbol2; Symbol2 = NextSymbol2)
 				{
 					// Compute the length of the constant.
 					OFFSET Constant2Start = Symbol2->Location, Constant2End, Constant2Length;
@@ -104,13 +104,13 @@ void MergeConstants (PROGRAM *Program)
 						SYMBOL *CurSymbol, *NextSymbol;
 						for (CurSymbol = Symbol2; CurSymbol && CurSymbol->Location == Constant2Start; CurSymbol = NextSymbol)
 						{
-							NextSymbol = GetNext (CurSymbol);
+							NextSymbol = TreeNext (CurSymbol);
 							// Don't move the section symbol.
 							if (CurSymbol == Section2->SectionSymbol) continue;
-							Unlink (Section2->Symbols, CurSymbol);
+							TreeUnlink (Section2->Symbols, CurSymbol);
 							CurSymbol->Parent = Section1;
 							CurSymbol->Location = Constant1Start;
-							InsertBefore (Section1->Symbols, CurSymbol, NextSymbol1);
+							TreeInsertBefore (Section1->Symbols, CurSymbol, NextSymbol1);
 						}
 						// Delete Constant2.
 						if (Constant2Length == Section2->Size && !NextSymbol2)
@@ -120,10 +120,10 @@ void MergeConstants (PROGRAM *Program)
 							// but if it is, we don't want the linker to segfault. Do this here,
 							// because even when not explicitly skipping it in the loop above, it
 							// won't always be caught by the loop.
-							Unlink (Section2->Symbols, Section2->SectionSymbol);
+							TreeUnlink (Section2->Symbols, Section2->SectionSymbol);
 							Section2->SectionSymbol->Parent = Section1;
 							Section2->SectionSymbol->Location = Constant1Start;
-							InsertBefore (Section1->Symbols, Section2->SectionSymbol, NextSymbol1);
+							TreeInsertBefore (Section1->Symbols, Section2->SectionSymbol, NextSymbol1);
 							// If the Section2 was the next Section1, we must update NextSection1.
 							if (Section2 == NextSection1)
 								NextSection1 = GetNext (NextSection1);
@@ -147,13 +147,13 @@ void MergeConstants (PROGRAM *Program)
 						SYMBOL *CurSymbol, *NextSymbol;
 						for (CurSymbol = Symbol1; CurSymbol && CurSymbol->Location == Constant1Start; CurSymbol = NextSymbol)
 						{
-							NextSymbol = GetNext (CurSymbol);
+							NextSymbol = TreeNext (CurSymbol);
 							// Don't move the section symbol.
 							if (CurSymbol == Section1->SectionSymbol) continue;
-							Unlink (Section1->Symbols, CurSymbol);
+							TreeUnlink (Section1->Symbols, CurSymbol);
 							CurSymbol->Parent = Section2;
 							CurSymbol->Location = Constant2Start;
-							InsertBefore (Section2->Symbols, CurSymbol, NextSymbol2);
+							TreeInsertBefore (Section2->Symbols, CurSymbol, NextSymbol2);
 						}
 						// Delete Constant1.
 						if (Constant1Length == Section1->Size && !NextSymbol1)
@@ -163,10 +163,10 @@ void MergeConstants (PROGRAM *Program)
 							// but if it is, we don't want the linker to segfault. Do this here,
 							// because even when not explicitly skipping it in the loop above, it
 							// won't always be caught by the loop.
-							Unlink (Section1->Symbols, Section1->SectionSymbol);
+							TreeUnlink (Section1->Symbols, Section1->SectionSymbol);
 							Section1->SectionSymbol->Parent = Section2;
 							Section1->SectionSymbol->Location = Constant2Start;
-							InsertBefore (Section2->Symbols, Section1->SectionSymbol, NextSymbol2);
+							TreeInsertBefore (Section2->Symbols, Section1->SectionSymbol, NextSymbol2);
 							// Free the section.
 							FreeSection (Section1);
 						}
@@ -213,24 +213,24 @@ FreeAndOutOfMem:
 							// Move the label group of Constant1 into the new section.
 							for (CurSymbol = Symbol1; CurSymbol && CurSymbol->Location == Constant1Start; CurSymbol = NextSymbol)
 							{
-								NextSymbol = GetNext (CurSymbol);
+								NextSymbol = TreeNext (CurSymbol);
 								// Don't move the section symbol.
 								if (CurSymbol == Section1->SectionSymbol) continue;
-								Unlink (Section1->Symbols, CurSymbol);
+								TreeUnlink (Section1->Symbols, CurSymbol);
 								CurSymbol->Parent = Section;
 								CurSymbol->Location = 0;
-								Append (Section->Symbols, CurSymbol);
+								TreeAppend (Section->Symbols, CurSymbol);
 							}
 							// Move the label group of Constant2 into the new section.
 							for (CurSymbol = Symbol2; CurSymbol && CurSymbol->Location == Constant2Start; CurSymbol = NextSymbol)
 							{
-								NextSymbol = GetNext (CurSymbol);
+								NextSymbol = TreeNext (CurSymbol);
 								// Don't move the section symbol.
 								if (CurSymbol == Section2->SectionSymbol) continue;
-								Unlink (Section2->Symbols, CurSymbol);
+								TreeUnlink (Section2->Symbols, CurSymbol);
 								CurSymbol->Parent = Section;
 								CurSymbol->Location = 0;
-								Append (Section->Symbols, CurSymbol);
+								TreeAppend (Section->Symbols, CurSymbol);
 							}
 						}
 						// Delete Constant1.
@@ -241,9 +241,9 @@ FreeAndOutOfMem:
 							// but if it is, we don't want the linker to segfault. Do this here,
 							// because even when not explicitly skipping it in the loop above, it
 							// won't always be caught by the loop.
-							Unlink (Section1->Symbols, Section1->SectionSymbol);
+							TreeUnlink (Section1->Symbols, Section1->SectionSymbol);
 							Section1->SectionSymbol->Parent = Section;
-							Append (Section->Symbols, Section1->SectionSymbol);
+							TreeAppend (Section->Symbols, Section1->SectionSymbol);
 							// Free the section.
 							FreeSection (Section1);
 						}
@@ -262,9 +262,9 @@ FreeAndOutOfMem:
 							// but if it is, we don't want the linker to segfault. Do this here,
 							// because even when not explicitly skipping it in the loop above, it
 							// won't always be caught by the loop.
-							Unlink (Section2->Symbols, Section2->SectionSymbol);
+							TreeUnlink (Section2->Symbols, Section2->SectionSymbol);
 							Section2->SectionSymbol->Parent = Section;
-							Append (Section->Symbols, Section2->SectionSymbol);
+							TreeAppend (Section->Symbols, Section2->SectionSymbol);
 							// If the Section2 was the next Section1, we must update NextSection1.
 							if (Section2 == NextSection1)
 								NextSection1 = GetNext (NextSection1);

+ 6 - 6
dump.c

@@ -93,12 +93,12 @@ void DumpSection (FILE *File, const char *Indent, const SECTION *Section)
 	fprintf (File, Section->Code ? "%sCode\n" : "%sData\n", Indent);
 	
 	{
-		const SEGMENT  *NextSegment = GetFirst (Section->Segments);
-		const SYMBOL   *NextSymbol  = GetFirst (Section->Symbols);
-		const RELOC    *NextReloc   = TreeFirst(Section->Relocs);
-		const ROM_CALL *NextROMCall = GetFirst (Section->ROMCalls);
-		const RAM_CALL *NextRAMCall = GetFirst (Section->RAMCalls);
-		const LIB_CALL *NextLibCall = GetFirst (Section->LibCalls);
+		const SEGMENT  *NextSegment = GetFirst  (Section->Segments);
+		const SYMBOL   *NextSymbol  = TreeFirst (Section->Symbols);
+		const RELOC    *NextReloc   = TreeFirst (Section->Relocs);
+		const ROM_CALL *NextROMCall = GetFirst  (Section->ROMCalls);
+		const RAM_CALL *NextRAMCall = GetFirst  (Section->RAMCalls);
+		const LIB_CALL *NextLibCall = GetFirst  (Section->LibCalls);
 		
 		OFFSET CurPos = 0;
 		SIZE SectionSize = Section->Size;

+ 5 - 5
export/exp_dbg.c

@@ -115,7 +115,7 @@ static void CountSectionCOFFSize (const SECTION *Section, void *UserData)
 			Size += NameLen + 1;
 	}
 
-	for_each (Symbol, Section->Symbols)
+	tree_for_each (Symbol, Section->Symbols)
 	{
 		COUNT NameLen = strlen (Symbol->Name);
 		// Symbol table entry
@@ -177,7 +177,7 @@ static void CountSymbols (const SECTION *Section, void *UserData)
 
 	(*(COUNT *)UserData)++; // section symbol
 
-	for_each (Symbol, Section->Symbols)
+	tree_for_each (Symbol, Section->Symbols)
 	{
 		(*(COUNT *)UserData)++;
 	}
@@ -299,7 +299,7 @@ static void FindCOFFSymbolNumber (const SECTION *Section, void *UserData)
 
 	((COFFSymbolNumberStruct *)UserData)->Current++; // section symbol
 
-	for_each (Symbol, Section->Symbols)
+	tree_for_each (Symbol, Section->Symbols)
 	{
 		if (((COFFSymbolNumberStruct *)UserData)->Symbol == Symbol)
 		{
@@ -418,7 +418,7 @@ static void WriteSymbolTable (const SECTION *Section, void *UserData)
 		ExportWrite (((SectionOffsets *)UserData)->File, &COFFSymbol, sizeof (COFF_SYMBOL), 1);
 	}
 
-	for_each (Symbol, Section->Symbols)
+	tree_for_each (Symbol, Section->Symbols)
 	{
 		COFF_SYMBOL COFFSymbol;
 		COUNT NameLen = strlen (Symbol->Name);
@@ -460,7 +460,7 @@ static void WriteStringTable (const SECTION *Section, void *UserData)
 		}
 	}
 
-	for_each (Symbol, Section->Symbols)
+	tree_for_each (Symbol, Section->Symbols)
 	{
 		COUNT NameLen = strlen (Symbol->Name);
 

+ 1 - 1
gcunused.c

@@ -175,7 +175,7 @@ void MarkMainSection (PROGRAM *Program)
 			continue;
 
 		// For each symbol...
-		for_each (Symbol, Section->Symbols)
+		tree_for_each (Symbol, Section->Symbols)
 		{
 			// If the name matches, we have found the right symbol.
 			if (Symbol->Exported && (!(strcmp ("__main", Symbol->Name))))

+ 1 - 1
import/imp_amig.c

@@ -647,7 +647,7 @@ BOOLEAN ImportAmigaOSFile (PROGRAM *Program, const I1 *File, SIZE FileSize, cons
 					TestInFile(ptr,I1[hunkSize]);
 					symSize = (hunkSize<MAX_SYM_LEN)?hunkSize:MAX_SYM_LEN;
 
-					for_each(symbol,currSection->Symbols) {
+					tree_for_each (symbol, currSection->Symbols) {
 						if (!strncmp(symbol->Name,(const char *)ptr,symSize) && !(ptr[symSize])) {
 							found = TRUE;
 							break;

+ 2 - 2
insert/kernel.c

@@ -509,7 +509,7 @@ BOOLEAN InsertKernelExports (SECTION *Section, BOOLEAN TrailingZeroBytes)
 	// The number of exports is equal to the highest export number + 1.
 	for_each (CurSection, Program->Sections)
 	{
-		for_each (CurSymbol, CurSection->Symbols)
+		tree_for_each (CurSymbol, CurSection->Symbols)
 		{
 			if (CurSymbol->Exported)
 			{
@@ -532,7 +532,7 @@ BOOLEAN InsertKernelExports (SECTION *Section, BOOLEAN TrailingZeroBytes)
 			for_each (CurSection, Program->Sections)
 			{
 				// For each symbol...
-				for_each (CurSymbol, CurSection->Symbols)
+				tree_for_each (CurSymbol, CurSection->Symbols)
 				{
 					// Check if it is exported.
 					if (CurSymbol->Exported)

+ 2 - 2
insert/other.c

@@ -44,7 +44,7 @@ BOOLEAN InsertNostubComments (SECTION *Section)
 	// Get the number and the highest ID of _nostub comments.
 	for_each (CurSection, Program->Sections)
 	{
-		for_each (CurSymbol, CurSection->Symbols)
+		tree_for_each (CurSymbol, CurSection->Symbols)
 		{
 			if (CurSymbol->Exported && (!(strncmp (CurSymbol->Name, SYMPF_NOSTUB_DATA, sizeof (SYMPF_NOSTUB_DATA) - 1))))
 			{
@@ -78,7 +78,7 @@ BOOLEAN InsertNostubComments (SECTION *Section)
 				for_each (CurSection, Program->Sections)
 				{
 					// For each symbol...
-					for_each (CurSymbol, CurSection->Symbols)
+					tree_for_each (CurSymbol, CurSection->Symbols)
 					{
 						// Check whether it belongs to the _nostub comment export we are looking for.
 						if (CurSymbol->Exported && (!(strncmp (CurSymbol->Name, SYMPF_NOSTUB_DATA, sizeof (SYMPF_NOSTUB_DATA) - 1))))

+ 7 - 7
manip.c

@@ -204,7 +204,7 @@ SYMBOL *CreateSectionSymbol (SECTION *Section, const char *SectionName)
 	if (!(Section->SectionSymbol))
 	{
 		// Insert the symbol at the beginning of the linked list.
-		Push (Section->Symbols, Symbol);
+		TreePush (Section->Symbols, Symbol);
 		// Mark the symbol as the section's beginning symbol.
 		Section->SectionSymbol = Symbol;
 	}
@@ -297,7 +297,7 @@ SECTION *FindStartupSection (const PROGRAM *Program, OFFSET StartupNumber)
 void InsertSymbol (SECTION *Section, SYMBOL *Symbol)
 {
 	const SYMBOL *NextSymbol = FindSymbolAtPos (Section, Symbol->Location, TRUE);
-	InsertBefore (Section->Symbols, Symbol, NextSymbol);
+	TreeInsertBefore (Section->Symbols, Symbol, NextSymbol);
 }
 
 // Increase the counters for references between the two sections, if the sections
@@ -439,7 +439,7 @@ SYMBOL *ResolveLocation (PROGRAM *Program, SECTION *Section, LOCATION *Location)
 			SYMBOL *CurSymbol;
 			
 			// For each symbol...
-			for_each (CurSymbol, CurSection->Symbols)
+			tree_for_each (CurSymbol, CurSection->Symbols)
 			{
 				// If the name matches, we have found the right symbol.
 				if (CurSymbol->Exported && (!(strcmp (Location->SymbolName, CurSymbol->Name))))
@@ -1256,11 +1256,11 @@ SYMBOL *MakeCommonSymbol (PROGRAM *Program, const char *SymName, SIZE Size, BOOL
 	{
 		// Check only for sections with uninitialized or zeroed data.
 		// Check if it has at least one symbol in it.
-		if ((!(CurSection->Data)) && (!(IsEmpty (CurSection->Symbols))))
+		if ((!(CurSection->Data)) && (!(TreeIsEmpty (CurSection->Symbols))))
 		{
 			SYMBOL *CurSymbol;
 			// For each symbol...
-			for_each (CurSymbol, CurSection->Symbols)
+			tree_for_each (CurSymbol, CurSection->Symbols)
 			{
 				// Check if the symbol name matches.
 				if (CurSymbol->Exported && (!(strcmp (CurSymbol->Name, SymName))))
@@ -1329,7 +1329,7 @@ SYMBOL *MakeCommonSymbol (PROGRAM *Program, const char *SymName, SIZE Size, BOOL
 			Symbol->Parent = Section;
 			strncpy (Symbol->Name, SymName, MAX_SYM_LEN);
 			Symbol->Exported = TRUE;
-			Append (Section->Symbols, Symbol);
+			TreeAppend (Section->Symbols, Symbol);
 			
 			// Since the new symbol is at the beginning of the section, it is
 			// sufficient as a section symbol.
@@ -1391,7 +1391,7 @@ SECTION_MARKERS *CreateSectionMarkers (SECTION_MARKERS *Marker, SECTION *Section
 		strcpy (Symbol->Name, Section->SectionSymbol->Name);
 		if (strlen (Symbol->Name) + sizeof (" end") - 1 <= MAX_SYM_LEN)
 			strcat (Symbol->Name, " end");
-		Append (Section->Symbols, Symbol);
+		TreeAppend (Section->Symbols, Symbol);
 		Marker->End = Symbol;
 		
 		return Marker;

+ 5 - 5
special.c

@@ -432,7 +432,7 @@ BOOLEAN CreateSpecialGlobalImports (PROGRAM *Program)
 		for_each (TempSection, Program->Sections)
 		{
 			SYMBOL *TempSymbol;
-			for_each (TempSymbol, TempSection->Symbols)
+			tree_for_each (TempSymbol, TempSection->Symbols)
 			{
 				if (TempSymbol->Exported && (!(strncmp (TempSymbol->Name, "_nostub_data__", sizeof ("_nostub_data__") - 1))))
 				{
@@ -838,7 +838,7 @@ BOOLEAN ResolveSpecialSymbolLocation (SECTION *Section, LOCATION *Location, BOOL
 				for_each (TempSection, Program->Sections)
 				{
 					SYMBOL *TempSymbol;
-					for_each (TempSymbol, TempSection->Symbols)
+					tree_for_each (TempSymbol, TempSection->Symbols)
 					{
 						if (TempSymbol->Exported)
 						{
@@ -1028,7 +1028,7 @@ BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLeng
 		// The number of exports is equal to the highest export number + 1.
 		for_each (TempSection, Program->Sections)
 		{
-			for_each (TempSymbol, TempSection->Symbols)
+			tree_for_each (TempSymbol, TempSection->Symbols)
 			{
 				if (TempSymbol->Exported)
 				{
@@ -1043,7 +1043,7 @@ BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLeng
 	{
 		for_each (TempSection, Program->Sections)
 		{
-			for_each (TempSymbol, TempSection->Symbols)
+			tree_for_each (TempSymbol, TempSection->Symbols)
 			{
 				if (TempSymbol->Exported && (!(strncmp (TempSymbol->Name, SYMPF_NOSTUB_DATA, sizeof (SYMPF_NOSTUB_DATA) - 1))))
 				{
@@ -1277,7 +1277,7 @@ SYMBOL *HandleAutoInsertion (SECTION *Section, const char *SymbolName)
 				Result->Location = Section->Size;
 				strncpy (Result->Name, SymbolName, MAX_SYM_LEN);
 				Result->Exported = TRUE;
-				Append (Section->Symbols, Result);
+				TreeAppend (Section->Symbols, Result);
 				
 				// Insert the data.
 				if (AppendInsertionData (Section, SymbolName + sizeof (SYMPF_BUILTIN_INSERT) - 1, Section, TRUE))