From d53658da5eb03e3538f199819621455985a39058 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 24 Jan 2016 00:00:20 -0800 Subject: [PATCH] Extern all the globals, not just the tables --- Makefile | 4 +- globals.c | 143 +++++++++++++++++++++++++++++ macrossGlobals.h | 200 ++++++++++++++++++++--------------------- slinky/Makefile | 8 +- slinky/globals.c | 63 +++++++++++++ slinky/slinkyGlobals.h | 60 ++++++------- 6 files changed, 342 insertions(+), 136 deletions(-) create mode 100644 globals.c create mode 100644 slinky/globals.c diff --git a/Makefile b/Makefile index aaf1092..fed6a77 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,14 @@ PROC =6502 OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\ -garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ +garbage.o globals.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ object.o operandStuffSD.o parserMisc.o semanticMisc.o\ statementSemantics.o structSemantics.o tokenStrings.o SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\ -expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ +expressionSemantics.c fixups.c garbage.c globals.c initialize.c lexer.c listing.c\ lookups.c macrossTables_$(PROC).c main.c object.c\ operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ diff --git a/globals.c b/globals.c new file mode 100644 index 0000000..3cc8249 --- /dev/null +++ b/globals.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1987 Fujitsu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/* + macrossGlobals.h -- Global variable definitions for the Macross + assembler. + + Chip Morningstar -- Lucasfilm Ltd. + + 1-November-1984 + +*/ + +#include "macrossTypes.h" +#include "macrossGlobals.h" + +bool backwardsCompatibleIfFlag; +bool beneathFunction; +commandLineDefineType *commandLineDefines; +int cumulativeLineNumber; +environmentType *currentEnvironment; +int currentFieldOffset; +char *currentFileName; +char *lastErrorFile; +stringType *currentFunctionName; +int currentLabelTagNumber; +int currentLineNumber; +int lastErrorLine; +identifierListType *currentLocalVariableList; +valueType currentLocationCounter; +int currentOperandNumber; +int currentReferenceDepth; +bool debug; +bool emitPrint; +bool expandMacros; +bool errorFlag; +bool expressionFailed; +bool finishOperand; +operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; +operandKindType newFixupAddressMode; +fixupListType *fixupList; +bool freeFlag; +bool freturnExit; +bool generatingFixup; +environmentType globalEnvironment; +int hackFlag; +bool haveUserStartAddress; +bool fixupStartAddress; +int includeNestingDepth; +FILE *indexFileForPass2; +FILE *input; +fileNameListType *inputFileStack; +FILE *listFileOutput; +int listingControlCounter; +bool listingOn; +int macroCallDepth; +FILE *macroFileForPass2; +int macroOrFunctionNestingDepth; +structInstanceType *newStruct; +int nextEnvironmentNumber; +int nextLabelTagNumber; +FILE *objectFileOutput; +char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; +expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; +bool performingFixups; +bool positionIndependentCodeMode; +bool produceLinkableObject; +addressType relocatableHighWaterMark; +reservationListType *reservationList; +valueType *resultOfLastFunctionCall; +valueType savedRelocatableCurrentLocationCounter; +FILE *saveFileForPass2; +bool showAllSymbolsFlag; +bool sideEffectFlag; +bool standaloneExpansionFlag; +valueType *startAddress; +int statementEvaluationDepth; +int statementListNestingDepth; +int structNestingDepth; +FILE *symbolDumpFileOutput; +bool symbolTableDumpOn; +int tabCount; +addressType targetOffset; +bool terseErrorMessages; +valueType *UndefinedValue; +symbolUsageKindType unknownSymbolTag; + +int (*lexDispatchTable[128])(); + +macroTableEntryType *macroTable[HASH_TABLE_SIZE]; + +opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; + +keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; + +conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; + +symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; + +int validSymbolValues[NUM_OF_SYM_USAGES]; + +byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE]; + +codeRegionType absoluteCodeRegion; +codeRegionType relocatableCodeRegion; +codeRegionType *codeRegions[2]; +codeBufferKindType currentCodeMode; +codeBufferType *emptyBuffer; /* ??? */ +codeBreakType *codeBreakList; +codeBreakType *lastCodeBreak; + +expressionReferenceListType *expressionReferenceList[3]; +expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; +int numberOfReferencesInList[3]; +functionDefinitionType *externalFunctionList; +functionDefinitionType *endOfExternalFunctionList; +int externalFunctionCount; + +char alphabeticCharacterTable[128]; +char alphaNumericCharacterTable[128]; +char lowerCaseCharacterTable[128]; +char numericCharacterTable[128]; + +int expressionBufferSize; +byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; diff --git a/macrossGlobals.h b/macrossGlobals.h index 21ce1c1..faa1823 100644 --- a/macrossGlobals.h +++ b/macrossGlobals.h @@ -29,84 +29,84 @@ */ -bool backwardsCompatibleIfFlag; -bool beneathFunction; -commandLineDefineType *commandLineDefines; -int cumulativeLineNumber; -environmentType *currentEnvironment; -int currentFieldOffset; -char *currentFileName; -char *lastErrorFile; -stringType *currentFunctionName; -int currentLabelTagNumber; -int currentLineNumber; -int lastErrorLine; -identifierListType *currentLocalVariableList; -valueType currentLocationCounter; -int currentOperandNumber; -int currentReferenceDepth; -bool debug; -bool emitPrint; -bool expandMacros; -bool errorFlag; -bool expressionFailed; -bool finishOperand; -operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; -operandKindType newFixupAddressMode; -fixupListType *fixupList; -bool freeFlag; -bool freturnExit; -bool generatingFixup; -environmentType globalEnvironment; -int hackFlag; -bool haveUserStartAddress; -bool fixupStartAddress; -int includeNestingDepth; -FILE *indexFileForPass2; -FILE *input; -fileNameListType *inputFileStack; -FILE *listFileOutput; -int listingControlCounter; -bool listingOn; -int macroCallDepth; -FILE *macroFileForPass2; -int macroOrFunctionNestingDepth; -structInstanceType *newStruct; -int nextEnvironmentNumber; -int nextLabelTagNumber; -FILE *objectFileOutput; -char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; -extern char pass2IndexFileName[]; -extern char pass2SourceFileName[]; -extern char pass2MacroExpansionFileName[]; -expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; -bool performingFixups; -bool positionIndependentCodeMode; -bool produceLinkableObject; -addressType relocatableHighWaterMark; -reservationListType *reservationList; -valueType *resultOfLastFunctionCall; -valueType savedRelocatableCurrentLocationCounter; -FILE *saveFileForPass2; -bool showAllSymbolsFlag; -bool sideEffectFlag; -bool standaloneExpansionFlag; -valueType *startAddress; -int statementEvaluationDepth; -int statementListNestingDepth; -int structNestingDepth; -FILE *symbolDumpFileOutput; -bool symbolTableDumpOn; -int tabCount; -addressType targetOffset; -bool terseErrorMessages; -valueType *UndefinedValue; -symbolUsageKindType unknownSymbolTag; +extern bool backwardsCompatibleIfFlag; +extern bool beneathFunction; +extern commandLineDefineType *commandLineDefines; +extern int cumulativeLineNumber; +extern environmentType *currentEnvironment; +extern int currentFieldOffset; +extern char *currentFileName; +extern char *lastErrorFile; +extern stringType *currentFunctionName; +extern int currentLabelTagNumber; +extern int currentLineNumber; +extern int lastErrorLine; +extern identifierListType *currentLocalVariableList; +extern valueType currentLocationCounter; +extern int currentOperandNumber; +extern int currentReferenceDepth; +extern bool debug; +extern bool emitPrint; +extern bool expandMacros; +extern bool errorFlag; +extern bool expressionFailed; +extern bool finishOperand; +extern operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; +extern operandKindType newFixupAddressMode; +extern fixupListType *fixupList; +extern bool freeFlag; +extern bool freturnExit; +extern bool generatingFixup; +extern environmentType globalEnvironment; +extern int hackFlag; +extern bool haveUserStartAddress; +extern bool fixupStartAddress; +extern int includeNestingDepth; +extern FILE *indexFileForPass2; +extern FILE *input; +extern fileNameListType *inputFileStack; +extern FILE *listFileOutput; +extern int listingControlCounter; +extern bool listingOn; +extern int macroCallDepth; +extern FILE *macroFileForPass2; +extern int macroOrFunctionNestingDepth; +extern structInstanceType *newStruct; +extern int nextEnvironmentNumber; +extern int nextLabelTagNumber; +extern FILE *objectFileOutput; +extern char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; +extern char pass2IndexFileName[]; +extern char pass2SourceFileName[]; +extern char pass2MacroExpansionFileName[]; +extern expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; +extern bool performingFixups; +extern bool positionIndependentCodeMode; +extern bool produceLinkableObject; +extern addressType relocatableHighWaterMark; +extern reservationListType *reservationList; +extern valueType *resultOfLastFunctionCall; +extern valueType savedRelocatableCurrentLocationCounter; +extern FILE *saveFileForPass2; +extern bool showAllSymbolsFlag; +extern bool sideEffectFlag; +extern bool standaloneExpansionFlag; +extern valueType *startAddress; +extern int statementEvaluationDepth; +extern int statementListNestingDepth; +extern int structNestingDepth; +extern FILE *symbolDumpFileOutput; +extern bool symbolTableDumpOn; +extern int tabCount; +extern addressType targetOffset; +extern bool terseErrorMessages; +extern valueType *UndefinedValue; +extern symbolUsageKindType unknownSymbolTag; #define DEFAULT_OBJECT_FILE_NAME "m.out" #define LEX_DISPATCH_TABLE_SIZE 128 -int (*lexDispatchTable[128])(); +extern int (*lexDispatchTable[128])(); #define HASH_TABLE_SIZE 512 #define HASH_TABLE_MASK 0x1FF @@ -123,50 +123,50 @@ extern struct { int symbolValue; } predefinedSymbolTable[]; -macroTableEntryType *macroTable[HASH_TABLE_SIZE]; +extern macroTableEntryType *macroTable[HASH_TABLE_SIZE]; -opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; +extern opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; extern opcodeTableEntryType theOpcodes[]; -keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; +extern keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; extern keywordTableEntryType theKeywords[]; -conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; +extern conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; extern conditionTableEntryType theConditions[]; -symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; +extern symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; extern int operandClassTable[]; extern void (*instructionActionTable[])(); -int validSymbolValues[NUM_OF_SYM_USAGES]; +extern int validSymbolValues[NUM_OF_SYM_USAGES]; -byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE]; +extern byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE]; -codeRegionType absoluteCodeRegion; -codeRegionType relocatableCodeRegion; -codeRegionType *codeRegions[2]; -codeBufferKindType currentCodeMode; -codeBufferType *emptyBuffer; /* ??? */ -codeBreakType *codeBreakList; -codeBreakType *lastCodeBreak; +extern codeRegionType absoluteCodeRegion; +extern codeRegionType relocatableCodeRegion; +extern codeRegionType *codeRegions[2]; +extern codeBufferKindType currentCodeMode; +extern codeBufferType *emptyBuffer; /* ??? */ +extern codeBreakType *codeBreakList; +extern codeBreakType *lastCodeBreak; -expressionReferenceListType *expressionReferenceList[3]; -expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; -int numberOfReferencesInList[3]; -functionDefinitionType *externalFunctionList; -functionDefinitionType *endOfExternalFunctionList; -int externalFunctionCount; +extern expressionReferenceListType *expressionReferenceList[3]; +extern expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; +extern int numberOfReferencesInList[3]; +extern functionDefinitionType *externalFunctionList; +extern functionDefinitionType *endOfExternalFunctionList; +extern int externalFunctionCount; -char alphabeticCharacterTable[128]; -char alphaNumericCharacterTable[128]; -char lowerCaseCharacterTable[128]; -char numericCharacterTable[128]; +extern char alphabeticCharacterTable[128]; +extern char alphaNumericCharacterTable[128]; +extern char lowerCaseCharacterTable[128]; +extern char numericCharacterTable[128]; -int expressionBufferSize; +extern int expressionBufferSize; #define EXPRESSION_BUFFER_LIMIT 500 -byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; +extern byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; diff --git a/slinky/Makefile b/slinky/Makefile index 6ed9978..aa566ff 100644 --- a/slinky/Makefile +++ b/slinky/Makefile @@ -1,17 +1,17 @@ .SUFFIXES: .o .c .h .run -OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o initialize.o\ +OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o globals.o initialize.o\ instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o\ write.o -SOURCES = builtins.c debugPrint.c errorStuff.c expr.c initialize.c\ +SOURCES = builtins.c debugPrint.c errorStuff.c expr.c globals.c initialize.c\ instantiate.c link.c main.c map.c poke.c read.c relocate.c slinkyTables.c\ write.c slinkyExpressions.h slinkyGlobals.h slinkyTypes.h y.tab.h -CFLAGS=-m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean +CFLAGS=-O2 -m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean .c.o: - cc $(CFLAGS) -c -g $*.c + cc $(CFLAGS) -c $*.c .c.run: cc $(CFLAGS) -o $* $*.c diff --git a/slinky/globals.c b/slinky/globals.c new file mode 100644 index 0000000..0ae8f70 --- /dev/null +++ b/slinky/globals.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1987 Fujitsu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/* + slinkyGlobals.h -- Global variables for the Slinky linker. + + Chip Morningstar -- Lucasfilm Ltd. + + 9-March-1985 +*/ + +#include "slinkyTypes.h" +#include "slinkyGlobals.h" + +bool debug; /* TRUE iff we should print debug diagnostics */ +bool errorFlag; /* TRUE iff an error occured during linking */ +bool verbose; +bool packFlag; +FILE *loadFileOutput; /* where to put the results */ +FILE *mapFileOutput; +objectFileListType *objectFileList; +objectFileListType *endOfObjectFileList; +char *currentFileName; +freeSegmentEntryType *freeSegmentList; +freeSegmentEntryType *effectiveFreeSegmentList; +addressType relocationOffset; +addressType entryPointAddress; +int entryPointMode; +expressionPCType entryPointExpression; +bool produceLoadMap; +bool leaveOffLoadFiles; +bool haveEntryPoint; +bool haveExpressionEntryPoint; +bool readExpressionEntryPoint; +symbolType **globalSymbolTable; +int globalSymbolCount; +symbolType **currentSymbolTable; +functionType *currentFunctionTable; +reservationListType *reservationList; +int totalSymbolCount; +expressionPCType pc; +addressType here; +bindingListType *localBindings; + +segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; diff --git a/slinky/slinkyGlobals.h b/slinky/slinkyGlobals.h index a85bbf0..e90cdf9 100644 --- a/slinky/slinkyGlobals.h +++ b/slinky/slinkyGlobals.h @@ -27,40 +27,40 @@ 9-March-1985 */ -bool debug; /* TRUE iff we should print debug diagnostics */ -bool errorFlag; /* TRUE iff an error occured during linking */ -bool verbose; -bool packFlag; +extern bool debug; /* TRUE iff we should print debug diagnostics */ +extern bool errorFlag; /* TRUE iff an error occured during linking */ +extern bool verbose; +extern bool packFlag; #define DEFAULT_LOAD_FILE_NAME "s.out" -FILE *loadFileOutput; /* where to put the results */ -FILE *mapFileOutput; -objectFileListType *objectFileList; -objectFileListType *endOfObjectFileList; -char *currentFileName; -freeSegmentEntryType *freeSegmentList; -freeSegmentEntryType *effectiveFreeSegmentList; -addressType relocationOffset; -addressType entryPointAddress; -int entryPointMode; -expressionPCType entryPointExpression; -bool produceLoadMap; -bool leaveOffLoadFiles; -bool haveEntryPoint; -bool haveExpressionEntryPoint; -bool readExpressionEntryPoint; -symbolType **globalSymbolTable; -int globalSymbolCount; -symbolType **currentSymbolTable; -functionType *currentFunctionTable; -reservationListType *reservationList; -int totalSymbolCount; -expressionPCType pc; -addressType here; -bindingListType *localBindings; +extern FILE *loadFileOutput; /* where to put the results */ +extern FILE *mapFileOutput; +extern objectFileListType *objectFileList; +extern objectFileListType *endOfObjectFileList; +extern char *currentFileName; +extern freeSegmentEntryType *freeSegmentList; +extern freeSegmentEntryType *effectiveFreeSegmentList; +extern addressType relocationOffset; +extern addressType entryPointAddress; +extern int entryPointMode; +extern expressionPCType entryPointExpression; +extern bool produceLoadMap; +extern bool leaveOffLoadFiles; +extern bool haveEntryPoint; +extern bool haveExpressionEntryPoint; +extern bool readExpressionEntryPoint; +extern symbolType **globalSymbolTable; +extern int globalSymbolCount; +extern symbolType **currentSymbolTable; +extern functionType *currentFunctionTable; +extern reservationListType *reservationList; +extern int totalSymbolCount; +extern expressionPCType pc; +extern addressType here; +extern bindingListType *localBindings; #define CODE_REGIONS_IN_ADDRESS_SPACE 256 #define CODE_REGION_SIZE 0x100 -segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; +extern segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; #define regionOf(addr) (addr / CODE_REGION_SIZE) extern struct {