From 0b99475ead50b157eb815a5a275dd7d3a08a0cab Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 21:50:12 -0800 Subject: [PATCH] Move function declarations out of the .c files and use the generated .h files instead --- actions_6502.c | 15 +++------- buildStuff1.c | 9 ++---- buildStuff2.c | 13 ++------- buildStuff3.c | 4 +-- builtInFunctions.c | 34 ++++------------------ builtInFunsSD_6502.c | 33 ++-------------------- debugPrint.c | 16 +---------- debugPrintSD_6502.c | 7 +---- emitBranch_6502.c | 14 +++------- emitStuff.c | 15 +++------- encode.c | 18 +++--------- errorStuff.c | 9 ++---- expressionSemantics.c | 33 ++++++---------------- fixups.c | 33 ++++++---------------- garbage.c | 18 ++---------- initialize.c | 39 +++++--------------------- lexer.c | 33 ++++------------------ listing.c | 13 +++------ lookups.c | 47 ++++++------------------------- macrossTables_6502.c | 65 ++----------------------------------------- main.c | 14 ++++------ object.c | 46 ++++++------------------------ operandStuffSD_6502.c | 28 +++++++------------ parserMisc.c | 12 ++++---- semanticMisc.c | 65 ++++++++----------------------------------- statementSemantics.c | 62 +++++++++-------------------------------- structSemantics.c | 27 ++++++------------ 27 files changed, 145 insertions(+), 577 deletions(-) diff --git a/actions_6502.c b/actions_6502.c index 2f5f21e..db5aeda 100644 --- a/actions_6502.c +++ b/actions_6502.c @@ -30,6 +30,10 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "actions.h" +#include "emitStuff.h" +#include "errorStuff.h" +#include "semanticMisc.h" #define operand (evaluatedOperands[0]) #define address (evaluatedOperands[0])->value @@ -45,17 +49,6 @@ and operand. */ - -bool isByteAddress (valueType *value); -bool isDefined (valueType *value); -extern void emitByte (byte byteValue); -bool wordCheck (int value); -extern void putFixupsHere (fixupKindType kindOfFixupsToPut, int whichFixup); -extern void emitWord (wordType wordValue); -bool byteCheck (int value); -bool isByteOffset (int value); -extern void error (errorType theError, ...); - void actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { diff --git a/buildStuff1.c b/buildStuff1.c index 0287c2f..82b33be 100644 --- a/buildStuff1.c +++ b/buildStuff1.c @@ -32,15 +32,12 @@ #include "macrossTypes.h" #include "macrossGlobals.h" - -symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); -char *saveString(char *s); +#include "errorStuff.h" +#include "lookups.h" +#include "parserMisc.h" /* Generic routine to create statement nodes */ -extern void botch (char *message, ...); -extern void error (errorType theError, ...); - statementType * newStatement(statementKindType kind, statementBodyType body) { diff --git a/buildStuff2.c b/buildStuff2.c index cd9a640..420193e 100644 --- a/buildStuff2.c +++ b/buildStuff2.c @@ -32,6 +32,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "lookups.h" +#include "parserMisc.h" /* These are all the miscellaneous routines for building pieces of parse-tree @@ -40,11 +42,7 @@ /* Fragments of statement structures */ - - -extern void botch (char *message, ...); - -caseType * + caseType * buildCase(expressionListType *caseTags, blockType *caseBody) { caseType *result; @@ -142,7 +140,6 @@ buildBinopTerm(binopKindType binop, expressionType *leftArgument, expressionType buildFunctionCall(stringType *functionName, operandListType *arguments) { functionCallTermType *result; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); result = typeAlloc(functionCallTermType); result->functionName = lookupOrEnterSymbol(functionName, @@ -189,8 +186,6 @@ buildExpressionTerm(expressionTermKindType kindOfExpressionTerm, anyOldThing *ar { expressionType *result; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - result = typeAlloc(expressionType); result->kindOfTerm = kindOfExpressionTerm; switch (kindOfExpressionTerm) { @@ -274,7 +269,6 @@ buildExpressionTerm(expressionTermKindType kindOfExpressionTerm, anyOldThing *ar buildMacroTableEntry(stringType *name) { macroTableEntryType *result; - char *saveString(char *s); result = typeAlloc(macroTableEntryType); result->macroName = saveString(name); @@ -288,7 +282,6 @@ buildMacroTableEntry(stringType *name) buildSymbolTableEntry(stringType *name, symbolUsageKindType usage) { symbolTableEntryType *result; - char *saveString(char *s); result = typeAlloc(symbolTableEntryType); result->symbolName = saveString(name); diff --git a/buildStuff3.c b/buildStuff3.c index 0819cf1..0e192a1 100644 --- a/buildStuff3.c +++ b/buildStuff3.c @@ -31,6 +31,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "lookups.h" /* These routines all build list-type structures. Since yacc likes to build @@ -47,7 +48,6 @@ buildArgumentList(stringType *new, argumentListHeadType *rest, bool arrayTag) { argumentListHeadType *newListHead; argumentDefinitionListType *newArgument; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); if (rest == NULL) { newListHead = typeAlloc(argumentListHeadType); @@ -128,8 +128,6 @@ buildIdentifierList(stringType *new, identifierListHeadType *rest, symbolUsageKi identifierListType *newListEntry; identifierListHeadType *newListHead; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - if (rest == NULL) { newListHead = typeAlloc(identifierListHeadType); newListHead->theSymbol = lookupOrEnterSymbol(new, usage); diff --git a/builtInFunctions.c b/builtInFunctions.c index 547e6fc..25d0f7a 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -30,9 +30,15 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "buildStuff.h" +#include "errorStuff.h" #include "expressionSemantics.h" +#include "garbage.h" +#include "lexer.h" +#include "lookups.h" #include "operandStuff.h" #include "semanticMisc.h" +#include "statementSemantics.h" #include @@ -42,17 +48,6 @@ environment */ - -extern void error (errorType theError, ...); -extern int hashString (char *s); -extern void assembleMacro (macroTableEntryType *macroInstruction, operandListType *operands); -extern void saveListingOff (void); -extern void saveListingOn (void); -extern bool strcmplc (char *s1, char *s2); -extern symbolTableEntryType *lookupOrEnterSymbol (stringType *s, symbolUsageKindType kind); -extern void assembleDefineStatement (defineStatementBodyType *defineStatement); -extern void freeStatement (statementType *statement); - valueType * makeBooleanValue(int test) { @@ -126,8 +121,6 @@ applyBIF(operandListType *parameterList, fixupKindType kindOfFixup) stringType *macroToLookup; macroTableEntryType *macroToCall; - macroTableEntryType *lookupMacroName(char *s, int hashValue); - if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "apply"); return(makeFailureValue()); @@ -362,9 +355,6 @@ isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup) expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); - if (parameterList != NULL) { if (parameterList->kindOfOperand == EXPRESSION_OPND && (expression = parameterList->theOperand. @@ -395,8 +385,6 @@ isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup) expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { expression = parameterList->theOperand.expressionUnion; @@ -847,10 +835,6 @@ symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup) valueType *stringValue; stringType *identifierToLookup; - expressionTermType *buildExpressionTerm(expressionTermKindType kindOfExpressionTerm, anyOldThing *arg1, anyOldThing *arg2, anyOldThing *arg3); - operandType *buildOperand(operandKindType kindOfOperand, anyOldThing *arg); - valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); - if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolLookup"); return(makeFailureValue()); @@ -871,7 +855,6 @@ symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; statementType *syntheticDefineStatement; - statementType *buildDefineStatement(stringType *name, expressionType *value); if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolDefine"); @@ -906,8 +889,6 @@ symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup) symbolInContextType *context; environmentType *saveEnvironment; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - saveEnvironment = currentEnvironment; while (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { @@ -942,8 +923,6 @@ symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup) expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { expression = parameterList->theOperand.expressionUnion; @@ -961,7 +940,6 @@ valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(evaluatedParameter->kindOfValue)); diff --git a/builtInFunsSD_6502.c b/builtInFunsSD_6502.c index cc2981a..0bcb40f 100644 --- a/builtInFunsSD_6502.c +++ b/builtInFunsSD_6502.c @@ -32,15 +32,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" - -/* Helper functions, defined in builtInFunctions.c */ -valueType *makeBooleanValue(int test); -valueType *makeFailureValue(void); -valueType *makeIntegerValue(int integer); -valueType *makeOperandValue(operandType *operand); -valueType *makeStringValue(stringType *string); -valueType *makeUndefinedValue(void); - +#include "builtInFunctions.h" +#include "operandStuff.h" /* Check if operand is the accumulator */ valueType * @@ -48,8 +41,6 @@ isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -65,8 +56,6 @@ isDirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -82,8 +71,6 @@ isImmediateModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -99,8 +86,6 @@ isIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -119,8 +104,6 @@ isIndirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -136,8 +119,6 @@ isPostIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -153,8 +134,6 @@ isPreIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -171,8 +150,6 @@ isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -189,8 +166,6 @@ isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -206,8 +181,6 @@ isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == @@ -224,8 +197,6 @@ isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(operandType *operand); - if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == diff --git a/debugPrint.c b/debugPrint.c index 8ca4884..fcde653 100644 --- a/debugPrint.c +++ b/debugPrint.c @@ -30,10 +30,9 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "debugPrint.h" #include "y.tab.h" -void printExpression(expressionType *expression); - /* Print out the parse-tree. */ @@ -44,11 +43,6 @@ int tablevel = 0; #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } /* For keeping nested structures looking pretty */ - -extern void printOperandKind (operandKindType kind); -extern void printToken (int token); -extern void printCondition (conditionType condition); -extern void printOperand (operandType *operand); void tab(void) @@ -259,8 +253,6 @@ printArgumentDefinitionList(argumentDefinitionListType *list) void printBlock(blockType *block) { - void printStatement(statementType *statement); - nullPrint(block); tab(); printf("(block:\n"); tablevel++; @@ -272,8 +264,6 @@ printBlock(blockType *block) void printArrayTerm(arrayTermType *arrayTerm) { - void printIdentifier(symbolTableEntryType *identifier); - nullPrint(arrayTerm); tab(); printf("(array\n"); tablevel++; @@ -301,8 +291,6 @@ printAssignmentTerm(binopTermType *assignmentTerm) void printBinopTerm(binopTermType *binopTerm) { - void printIdentifier(symbolTableEntryType *identifier); - nullPrint(binopTerm); tab(); printf("(binop ["); printToken(binopTerm->binop); @@ -320,8 +308,6 @@ printBinopTerm(binopTermType *binopTerm) void printFunctionCall(functionCallTermType *functionCall) { - void printOperandList(operandListType *operandList); - nullPrint(functionCall); tab(); printf("(function call %s\n", functionCall->functionName-> symbolName); diff --git a/debugPrintSD_6502.c b/debugPrintSD_6502.c index 234ad7d..f5d8554 100644 --- a/debugPrintSD_6502.c +++ b/debugPrintSD_6502.c @@ -31,6 +31,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "debugPrint.h" #include "y.tab.h" @@ -39,12 +40,6 @@ int tablevel; /* Fundamental nop print operation */ #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } - -extern void tab (void); -extern void printExpression (expressionType *expression); -extern void printIdentifierList (identifierListType *identifierList); -extern void printBlock (blockType *block); - void printCondition(conditionType condition) { diff --git a/emitBranch_6502.c b/emitBranch_6502.c index 6cd2d29..e4b30e3 100644 --- a/emitBranch_6502.c +++ b/emitBranch_6502.c @@ -32,19 +32,15 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "buildStuff.h" +#include "emitStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" /* emitRelativeBranch emits a relative branch instruction for the 6502, branching from the current location given a condition to branch upon and a target address. */ - -extern void emitByte (byte byteValue); -extern void emitRelativeByteOffset (valueType *target); -extern void botch (char *message, ...); -extern void emitWord (wordType wordValue); -extern void noteAnonymousReference (void); -extern void emitWordValue (valueType *wordValue); - void emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation) { @@ -149,8 +145,6 @@ emitJump(valueType *target, simpleFixupListType *previousFixups) simpleFixupListType *result; valueType picFixup[COMPOUND_BRANCH_MAX]; - simpleFixupListType *buildSimpleFixupList(valueType locationToFixup, simpleFixupListType *previousList); - #define JUMP_OPCODE 0x4C result = previousFixups; diff --git a/emitStuff.c b/emitStuff.c index 3786b3e..4b9e8b5 100644 --- a/emitStuff.c +++ b/emitStuff.c @@ -30,6 +30,10 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "actions.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "semanticMisc.h" /* Emitted code is stored in places that are allocated dynamically as they @@ -62,17 +66,6 @@ /* incarnateCodeBuffer causes code buffer space to actually be allocated */ - -extern void fatalError (errorType theError, ...); -extern bool byteCheck (int value); -extern void printValue (valueType *value); -extern void error (errorType theError, ...); -extern char *valueKindString (valueKindType valueKind); -extern bool wordCheck (int value); -extern bool isByteOffset (int value); -extern bool isWordOffset (int value); -extern void noteAnonymousReference (void); - void incarnateCodeBuffer(int bufferNum, codeBufferKindType bufferKind) { diff --git a/encode.c b/encode.c index b44c4f8..d892d19 100644 --- a/encode.c +++ b/encode.c @@ -31,6 +31,10 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "encode.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "parserMisc.h" #include "semanticMisc.h" #include "slinkyExpressions.h" @@ -39,18 +43,6 @@ bool encodingFunction; - -extern void error (errorType theError, ...); -bool encodeIdentifier (symbolTableEntryType *identifier); -bool encodeExpression (expressionType *expression); -bool encodeValue (valueType *value); -bool encodeOperand (operandType *operand); -bool encodeString (stringType *string); -extern char *valueKindString (valueKindType valueKind); -extern void botch (char *message, ...); -bool encodeBlock (blockType *block); -extern stringType *statementKindString (statementKindType kind); - bool encodeByte(byte aByte) { @@ -94,8 +86,6 @@ encodeAssignmentTerm(binopTermType *assignmentTerm) bool encodeBinopTerm(binopTermType *binopTerm) { - bool encodeExpression(expressionType *expression); - nullEncode(binopTerm); return ( encodeByte(BINOP_TAG) && diff --git a/errorStuff.c b/errorStuff.c index a2d064d..371f917 100644 --- a/errorStuff.c +++ b/errorStuff.c @@ -29,6 +29,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "errorStuff.h" +#include "initialize.h" #include @@ -39,12 +41,7 @@ bool nullStatementFlag; input up to the end of the line, in a (probably futile) effort to recover from the booboo. */ - -void verror (errorType theError, va_list ap); -void fatalError (errorType theError, ...); -extern void chokePukeAndDie (void); - -void + void puntOnError(errorType theError, ...) { va_list ap; diff --git a/expressionSemantics.c b/expressionSemantics.c index a861662..17db853 100644 --- a/expressionSemantics.c +++ b/expressionSemantics.c @@ -31,8 +31,17 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "builtInFunctions.h" +#include "errorStuff.h" #include "expressionSemantics.h" +#include "fixups.h" +#include "listing.h" +#include "lookups.h" +#include "operandStuff.h" +#include "parserMisc.h" #include "semanticMisc.h" +#include "statementSemantics.h" +#include "tokenStrings.h" #include @@ -64,30 +73,6 @@ stringType *dbString; #define moreStuff(f) (generatingFixup ? moreExpression(f) : moreText(f)) #define moreStuff1(f,x) (generatingFixup? moreExpression(f,x) : moreText(f,x)) - -extern void error (errorType theError, ...); -extern char *valueKindString (valueKindType valueKind); -extern void moreExpression (char *format, ...); -extern valueType *evaluateOperand (operandType *operand); -extern char *tokenString (int token); -extern char *assignmentString (assignmentKindType assignment); -extern char *usageString (symbolUsageKindType usageKind); -extern valueType *makeUndefinedValue (void); -extern void botch (char *message, ...); -extern char *conditionString (conditionType condition); -extern int bindFunctionArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName); -extern void assembleBlock (blockType *block); -extern void unbindArguments (argumentDefinitionListType *argumentList, int numberToUnbind); -extern void unbindLocalVariables (identifierListType *identifierList); -extern void reincarnateSymbol (symbolInContextType *context, symbolUsageKindType newUsage); -extern bool shouldParenthesize (operandType *operand); -extern void moreText (char *format, ...); -extern void endLine (void); -extern void tabIndent (void); -extern void flushExpressionString (void); -extern operandType *buildOperand (operandKindType kindOfOperand, anyOldThing *arg); -extern expressionType *generateFixupExpression (expressionType *expression); - anyOldThing * arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing) { diff --git a/fixups.c b/fixups.c index 5ee9e35..f661dc4 100644 --- a/fixups.c +++ b/fixups.c @@ -30,6 +30,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "errorStuff.h" +#include "expressionSemantics.h" +#include "fixups.h" +#include "listing.h" +#include "operandStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" +#include "tokenStrings.h" operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; @@ -57,19 +65,10 @@ stringType *dbString = "graphics2.m"; The routines below collectively duplicate expressions for later evaluation. */ - -extern void moreExpression (char *format, ...); -extern bool isUndefined (valueType *value); -extern char *tokenString (int token); -extern void error (errorType theError, ...); -extern char *conditionString (conditionType condition); -extern void botch (char *message, ...); - expressionType * generateFixupExpression(expressionType *expression) { expressionType *result; - expressionType *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); generatingFixup = TRUE; result = duplicateExpressionForFixup(expression, TRUE, FALSE); @@ -89,16 +88,6 @@ duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool is environmentType *saveEnvironment; bool saveExpansion; - operandType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - functionCallTermType *duplicateFunctionCall(functionCallTermType *functionCall); - expressionType *duplicateArrayReference(arrayTermType *arrayTerm); - valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); - valueType *evaluateHere(void); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - symbolTableEntryType *generateLocalLabel(symbolTableEntryType *symbol); - stringType *saveString(char *s); - nullDup(expression); result = originalResult = typeAlloc(expressionType); *result = *expression; @@ -290,8 +279,6 @@ duplicateFunctionCall(functionCallTermType *functionCall) operandListType **argument; operandListType *parameterList; - operandListType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); - result = typeAlloc(functionCallTermType); result->functionName = functionCall->functionName; expand(moreExpression("%s(", symbName(functionCall->functionName))); @@ -324,10 +311,6 @@ duplicateArrayReference(arrayTermType *arrayTerm) bool saveExpansion; operandType *newOperand; - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - operandType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); - anyOldThing *arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing); - expansionOff(); resultThing = arrayLookup(arrayTerm, &kindOfResult); expansionOn(); diff --git a/garbage.c b/garbage.c index bb9705d..bf0866d 100644 --- a/garbage.c +++ b/garbage.c @@ -29,19 +29,16 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "garbage.h" +#include "operandStuff.h" +#include "parserMisc.h" #include "y.tab.h" #define nullFree(thing) if (thing == NULL) return; - -extern void botch (char *message, ...); -extern void freeOperand (operandType *operand); - void freeArrayTerm(arrayTermType *arrayTerm) { - void freeExpression(expressionType *expression); - nullFree(arrayTerm); freeExpression(arrayTerm->arrayName); freeExpression(arrayTerm->arrayIndex); @@ -51,8 +48,6 @@ freeArrayTerm(arrayTermType *arrayTerm) void freeAssignmentTerm(binopTermType *assignmentTerm) { - void freeExpression(expressionType *expression); - nullFree(assignmentTerm); freeExpression(assignmentTerm->rightArgument); free(assignmentTerm); @@ -61,8 +56,6 @@ freeAssignmentTerm(binopTermType *assignmentTerm) void freeBinopTerm(binopTermType *binopTerm) { - void freeExpression(expressionType *expression); - nullFree(binopTerm); freeExpression(binopTerm->leftArgument); if (binopTerm->binop != SELECT) @@ -73,8 +66,6 @@ freeBinopTerm(binopTermType *binopTerm) void freeFunctionCall(functionCallTermType *functionCall) { - void freeOperandList(operandListType *operandList); - nullFree(functionCall); freeOperandList(functionCall->parameters); free(functionCall); @@ -104,8 +95,6 @@ freeString(stringType *string) void freeUnopTerm(unopTermType *unopTerm) { - void freeExpression(expressionType *expression); - nullFree(unopTerm); freeExpression(unopTerm->unopArgument); free(unopTerm); @@ -774,7 +763,6 @@ freeStatement(statementType *statement) freeArray(arrayType *array) { int i; - void freeValue(valueType *value); if (array->arraySize > 0) { for (i=0; iarraySize; i++) diff --git a/initialize.c b/initialize.c index e7ad14d..d02e3e9 100644 --- a/initialize.c +++ b/initialize.c @@ -29,8 +29,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "initialize.h" +#include "errorStuff.h" +#include "lexer.h" +#include "lookups.h" +#include "semanticMisc.h" #include +#include #define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) @@ -39,19 +45,7 @@ extern int yydebug; static fileNameListType *bottomOfInputFileStack; static char *outputFileName; - -extern int unlink (const char *); -bool isDotMName (stringType *fileName); -extern void fatalError (errorType theError, ...); -extern void printVersion (void); -extern void warning (errorType theError, ...); -extern void fatalSystemError (errorType theError, ...); -extern void initializeLexDispatchTable (void); -extern genericTableEntryType *hashStringEnter (genericTableEntryType *entry, genericTableEntryType **table); -extern int fancyAtoI (char *buffer, int base); -extern void error (errorType theError, ...); - -void + void chokePukeAndDie(void) { unlink(outputFileName); @@ -72,14 +66,6 @@ initializeStuff(int argc, char **argv) char *symbolDumpFileName; bool dontUnlinkTempFiles; - void createHashTables(void); - void installBuiltInFunctions(void); - void installPredefinedSymbols(void); - void installCommandLineDefineSymbols(void); - void openFirstInputFile(void); - void queueInputFile(char *name); - void noteCommandLineDefine(char *arg); - for (i=0; i<128; i++) { lowerCaseCharacterTable[i] = i; alphabeticCharacterTable[i] = FALSE; @@ -396,9 +382,6 @@ installBuiltInFunctions(void) int i; symbolTableEntryType *newFunction; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - for (i=0; builtInFunctionTable[i].functionName!=NULL; i++) { newFunction = lookupOrEnterSymbol(builtInFunctionTable[i]. functionName, BUILT_IN_FUNCTION_SYMBOL); @@ -416,9 +399,6 @@ installPredefinedSymbols(void) int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - for (i=0; predefinedSymbolTable[i].symbolName!=NULL; i++) { newSymbol = lookupOrEnterSymbol(predefinedSymbolTable[i]. symbolName, DEFINE_SYMBOL); @@ -435,9 +415,6 @@ installCommandLineDefineSymbols(void) int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - while (commandLineDefines != NULL) { newSymbol = lookupOrEnterSymbol(commandLineDefines->name, DEFINE_SYMBOL); @@ -572,8 +549,6 @@ noteCommandLineDefine(char *arg) int value; commandLineDefineType *newCommandLineDefine; - bool parseCommandLineDefine(char *arg, char **name, int *value); - if (parseCommandLineDefine(arg, &name, &value)) { newCommandLineDefine = typeAlloc(commandLineDefineType); newCommandLineDefine->name = name; diff --git a/lexer.c b/lexer.c index 6368c38..9092678 100644 --- a/lexer.c +++ b/lexer.c @@ -30,7 +30,12 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "lexer.h" #include "lexerTables.h" +#include "listing.h" +#include "lookups.h" #include "parserMisc.h" extern int yylval; @@ -52,24 +57,6 @@ static int lineBufferPtr = 0; #define isNumeric(c) (numericCharacterTable[c]) #define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) - -int lexer (void); -extern void printToken (int token); -int lexLiteral (char c); -bool isMacrossLiteralCharacter (char c); -int readAnotherLine (void); -extern int hashString (char *s); -extern opcodeTableEntryType *lookupOpcode (char *s, int hashValue); -extern int lookupKeyword (char *s, int hashValue); -extern conditionType lookupConditionCode (char *s, int hashValue); -extern macroTableEntryType *lookupMacroName (char *s, int hashValue); -int fancyAtoI (char *buffer, int base); -int digitValue (char c); -extern void error (errorType theError, ...); -int getStringCharacter (FILE *input); -extern void fatalSystemError (errorType theError, ...); -extern bool notListable (statementKindType statementKind); - int yylex(void) { @@ -89,8 +76,6 @@ lexer(void) { char c; - char skipWhitespaceAndComments(void); - if ((c = skipWhitespaceAndComments()) == EOF) return(lexLiteral(c)); else @@ -101,12 +86,6 @@ lexer(void) initializeLexDispatchTable(void) { int c; - int lexIdentifier(char c); - int lexNumber(char c); - int lexLiteral(char c); - int lexCharacterConstant(void); - int lexStringConstant(void); - int lexOperator(char firstC); for (c = 0; c < LEX_DISPATCH_TABLE_SIZE; c++) { if (isAlphabetic(c) || c=='$') @@ -152,7 +131,6 @@ char nameBuffer[MAX_NAME_SIZE+1]; int lexIdentifier(char c) { - char *saveString(char *s); int hashValue; snarfAlphanumericString(c, nameBuffer); @@ -270,7 +248,6 @@ getStringCharacter(FILE *input) char c; char *numberPtr; int result; - char controlCharacter(char c); escaped = FALSE; c = getNextChar(); diff --git a/listing.c b/listing.c index d065289..fdb760b 100644 --- a/listing.c +++ b/listing.c @@ -29,7 +29,10 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "emitStuff.h" +#include "lexer.h" #include "listing.h" +#include "semanticMisc.h" #include #include @@ -44,15 +47,7 @@ static int nextMacroAddress; static int macroDepth; static int nextMacroDepth; - -extern void saveLineForListing (stringType *line); -extern void saveIndexForListing (statementKindType kindOfStatement, int cumulativeLineNumber); -extern char *myfgets (char *buffer, int length, FILE *stream); -bool isBlankStatement (statementKindType statementKind); -extern byte getByte (addressType address); -extern bool listableStatement (statementKindType kind); - -void + void outputListing(void) { rewind(saveFileForPass2); diff --git a/lookups.c b/lookups.c index b286916..8b009ee 100644 --- a/lookups.c +++ b/lookups.c @@ -29,6 +29,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "buildStuff.h" +#include "errorStuff.h" +#include "garbage.h" +#include "listing.h" +#include "lookups.h" +#include "operandStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" /* These routines all do basically the same thing. Various kinds of keywords @@ -36,25 +44,11 @@ lists that are sorted alphabetically. */ - -extern void botch (char *message, ...); -extern void freeValue (valueType *value); -extern void error (errorType theError, ...); -bool strcmplc (char *s1, char *s2); -int hashString (char *s); -extern int countParameters (operandListType *parameterList); -extern arrayType *allocArray (int size, valueType ***contentsPtr); -extern bool isUsable (valueType *value); -extern void moreExpression (char *format, ...); -extern bool isUndefined (valueType *value); - -conditionType + conditionType lookupConditionCode(char *s, int hashValue) { conditionTableEntryType *result; - genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); - result = (conditionTableEntryType *) prehashedStringLookup(s, conditionTable, hashValue); if (result != NULL) @@ -68,8 +62,6 @@ lookupKeyword(char *s, int hashValue) { keywordTableEntryType *result; - genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); - result = (keywordTableEntryType *) prehashedStringLookup(s, keywordTable, hashValue); if (result != NULL) @@ -81,8 +73,6 @@ lookupKeyword(char *s, int hashValue) macroTableEntryType * lookupMacroName(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); - return((macroTableEntryType *) prehashedStringLookup(s, macroTable, hashValue)); } @@ -90,8 +80,6 @@ lookupMacroName(char *s, int hashValue) opcodeTableEntryType * lookupOpcode(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); - return((opcodeTableEntryType *) prehashedStringLookup(s, opcodeTable, hashValue)); } @@ -104,9 +92,6 @@ lookupOpcode(char *s, int hashValue) lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind) { symbolTableEntryType *result; - genericTableEntryType *hashStringLookup(char *s, genericTableEntryType **table); - genericTableEntryType *hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table); - symbolTableEntryType *buildSymbolTableEntry(stringType *name, symbolUsageKindType usage); if (result = (symbolTableEntryType *)hashStringLookup(s,symbolTable)){ /* result->referenceCount++;*/ @@ -151,11 +136,6 @@ createMacro(stringType *macroName) macroTableEntryType *result; symbolTableEntryType *testSymbol; - genericTableEntryType *hashStringLookup(char *s, genericTableEntryType **table); - genericTableEntryType *hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table); - macroTableEntryType *buildMacroTableEntry(stringType *name); - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - testSymbol = lookupOrEnterSymbol(macroName, MACRO_SYMBOL); if (testSymbol->context->usage != MACRO_SYMBOL) { error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol)); @@ -297,8 +277,6 @@ purgeSymbol(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - if ((context = getWorkingContext(symbol)) != NULL) context->usage = DEAD_SYMBOL; } @@ -319,8 +297,6 @@ reincarnateSymbol(symbolInContextType *context, symbolUsageKindType newUsage) void pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage) { - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - pushSymbol(symbol); if (newBinding == NULL) newBinding = newValue(FAIL, 0, EXPRESSION_OPND); @@ -346,8 +322,6 @@ bindMacroArguments(argumentDefinitionListType *argumentList, operandListType *pa valueType **arrayContents; int i; - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - if (argumentList == NULL) arrayTag = FALSE; else @@ -409,9 +383,6 @@ bindFunctionArguments(argumentDefinitionListType *argumentList, operandListType valueType *firstArgument; environmentType *saveEnvironment; - valueType *evaluateOperand(operandType *operand); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - if (argumentList == NULL) arrayTag = FALSE; else diff --git a/macrossTables_6502.c b/macrossTables_6502.c index e31a1e2..d33c561 100644 --- a/macrossTables_6502.c +++ b/macrossTables_6502.c @@ -29,6 +29,8 @@ */ #include "macrossTypes.h" +#include "actions.h" +#include "builtInFunctions.h" #include "y.tab.h" /* All those NULLs are used to string together lists after this all gets @@ -205,21 +207,6 @@ int operandClassTable[] = { /* indexed by operandKindType */ BLOCK_OPND_BIT, }; -int actionsRelative(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDir2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDirIndir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDirX1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDirX2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDirX3(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsImmDir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsImmDirX(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsImmDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsNone(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); -int actionsImmIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); - /* indexed by opcodeClass */ int (*instructionActionTable[])() = { actionsRelative, @@ -303,54 +290,6 @@ valueType undefinedValueValue = { UNDEFINED_VALUE, 0, EXPRESSION_OPND }; valueType *UndefinedValue = &undefinedValueValue; -valueType *addressModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *applyBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *arrayLengthBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *atasciiBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *atasciiColorBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *debugModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *debugModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *emitModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *emitModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isAbsoluteValueBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isBlockBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isBuiltInFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isConditionCodeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isDirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isFieldBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isImmediateModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isIndirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isPostIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isPreIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isRelocatableValueBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isStringBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isStructBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isSymbolBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *listingOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *listingOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *makeArrayBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *nthCharBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *printfBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *strcatBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *strcmpBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *strcmplcBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *strlenBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *substrBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup); -valueType *valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup); - /* Used to initialize symbols representing built-in functions */ struct { stringType *functionName; diff --git a/main.c b/main.c index ae211a1..7226ecb 100644 --- a/main.c +++ b/main.c @@ -29,12 +29,11 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "initialize.h" +#include "semanticMisc.h" +#include "y.tab.h" - -extern void initializeStuff (int argc, char **argv); -extern int yyparse (void); -extern void finishUp (void); -extern void chokePukeAndDie (void); +#include int main(int argc, char **argv) @@ -44,15 +43,14 @@ main(int argc, char **argv) #else extern char end; #endif - char *sbrk(int); fflush(stdout); initializeStuff(argc, argv); yyparse(); finishUp(); if (emitPrint) - printf("storage high water mark 0x%x == %d\n", sbrk(0) - &end, - sbrk(0) - &end); + printf("storage high water mark 0x%x == %d\n", sbrk(0) - (void *)(&end), + sbrk(0) - (void *)(&end)); if (errorFlag) chokePukeAndDie(); return 0; diff --git a/object.c b/object.c index eb21beb..1d80639 100644 --- a/object.c +++ b/object.c @@ -29,6 +29,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "debugPrint.h" +#include "encode.h" +#include "expressionSemantics.h" +#include "fixups.h" +#include "garbage.h" +#include "lookups.h" +#include "object.h" +#include "semanticMisc.h" #include @@ -36,29 +44,9 @@ static int symbolTableSize; static int symbolTableStringSize; bool encodingFunction; - -extern void printCodeBuffers (void); -extern bool isExternal (symbolTableEntryType *symbol); -extern bool strcmplc (char *s1, char *s2); -bool hackableSymbol (symbolTableEntryType *symbol); -extern void printExpressionBuffer (void); -extern bool encodeRelocatableNumber (numberTermType number); -extern void freeExpression (expressionType *expression); - -void + void outputObjectFile(void) { - void outputPartition(void); - void outputReferenceInfo(void); - void outputSymbolTableInfo(void); - void outputAbsoluteCode(void); - void outputRelocatableCode(void); - void outputReservations(void); - void outputExpressions(void); - void outputFunctions(void); - void dumpSymbolTable(void); - void enumerateAndCountSymbols(void); - if (debug || emitPrint) printCodeBuffers(); outputPartition(); @@ -138,9 +126,6 @@ outputRelocatableCode(void) addressType codeStartAddress; addressType codeEndAddress; - void outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress); - void outputBreak(codeBreakType *codeBreak); - if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue == RELOCATABLE_VALUE) outputStartAddress(startAddress->value); @@ -194,7 +179,6 @@ outputAbsoluteCode(void) int startSegment; int endSegment; int nextSegment; - void outputOneCodeBuffer(codeSegmentType *segment); if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue==ABSOLUTE_VALUE) @@ -252,9 +236,6 @@ outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress) int segment; codeSegmentType *segmentPtr; - void outputWord(int aWord); - void outputByte(byte aByte); - outputWord(codeStartAddress); outputWord(codeEndAddress); startSegment = bufferNumber(codeStartAddress); @@ -365,7 +346,6 @@ outputOneSymbol(symbolTableEntryType *symbol) { byte symbolClass; valueType *symbolValue; - valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); if (symbol->context->usage == DEFINE_SYMBOL) symbolValue = evaluateIdentifier(symbol, FALSE, NO_FIXUP_OK); @@ -431,9 +411,6 @@ dumpSymbolTable(void) int symbolPtr; valueType *value; - valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); - void printValueTersely(valueType *value); - numberOfSymbols = 0; for (i=0; inextSymbol) { @@ -560,9 +537,6 @@ outputOneExpression(expressionType *expression) { expressionType *newExpression; - expressionType *generateFixupExpression(expressionType *expression); - bool encodeExpression(expressionType *expression); - expressionBufferSize = 0; if (expression == NULL) { encodeRelocatableNumber(0); @@ -598,8 +572,6 @@ outputExpressions(void) outputOneFunction(functionDefinitionType *function) { argumentDefinitionListType *argumentList; - bool encodeBlock(blockType *block); - int countArguments(functionDefinitionType *function); outputByte((byte)countArguments(function)); argumentList = function->arguments; diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index c085d11..7fcd60d 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -30,21 +30,19 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "errorStuff.h" +#include "expressionSemantics.h" +#include "fixups.h" +#include "garbage.h" +#include "listing.h" +#include "operandStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" +#include "statementSemantics.h" /* corresponds to routines in buildStuff2.c */ - -extern void botch (char *message, ...); -extern void error (errorType theError, ...); -extern void freeExpression (expressionType *expression); -extern void freeSelectionList (selectionListType *selectionList); -extern void freeString (stringType *string); -extern void freeBlock (blockType *block); -extern void moreText (char *format, ...); -extern void expandExpression (char *toBuffer, char **toBufferPtr); -extern void assembleBlock (blockType *block); - -operandType * + operandType * buildOperand(operandKindType kindOfOperand, anyOldThing *arg) { operandType *result; @@ -142,8 +140,6 @@ duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand { operandListType *result; - expressionType *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); - result = typeAlloc(operandListType); result->kindOfOperand = operand->kindOfOperand; result->nextOperand = NULL; @@ -289,10 +285,6 @@ evaluateOperand(operandType *operand) bool saveExpansion; expressionType *expression; - valueType *evaluateExpression(expressionType *expression, fixupKindType kindOfFixup); - valueType *evaluateSelectionList(selectionListType *selectionList); - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - nullEvaluate(operand); if (operand->kindOfOperand != EXPRESSION_OPND) newFixupAddressMode = operand->kindOfOperand; diff --git a/parserMisc.c b/parserMisc.c index d26fa9c..a4ab3e8 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -32,20 +32,18 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "buildStuff.h" +#include "fixups.h" +#include "initialize.h" +#include "errorStuff.h" #include "parserMisc.h" #include #include - -extern void chokePukeAndDie (void); -extern void puntOnError (errorType theError, ...); - -statementType * + statementType * addLabelToStatement(labelListType *labelList, statementType *statement) { - statementType *newStatement(statementKindType kind, statementBodyType body); - if (statement == NULL) statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); statement->labels = labelList; diff --git a/semanticMisc.c b/semanticMisc.c index ed3094c..644e264 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -33,7 +33,17 @@ #include "y.tab.h" #include "semanticMisc.h" +#include "buildStuff.h" +#include "debugPrint.h" +#include "emitStuff.h" +#include "errorStuff.h" #include "expressionSemantics.h" +#include "fixups.h" +#include "listing.h" +#include "lookups.h" +#include "object.h" +#include "operandStuff.h" +#include "parserMisc.h" #include @@ -44,26 +54,7 @@ These are miscellaneous routines called by the primary semantics routines. */ - -extern void error (errorType theError, ...); -extern char *valueKindString (valueKindType valueKind); -extern void moreLabel (char *format, int arg1); -extern void reincarnateSymbol (symbolInContextType *context, symbolUsageKindType newUsage); -extern void printCreateFixup (expressionType *expression, addressType location, fixupKindType kindOfFixup); -extern void flushExpressionString (void); -extern void expandOperand (operandKindType addressMode, char *buffer); -extern void terminateListingFiles (void); -extern void outputObjectFile (void); -extern void outputListing (void); -extern void botch (char *message, ...); -extern void pokeByteValue (addressType location, valueType *value); -extern void pokeWordValue (addressType location, valueType *value); -extern void pokeLongValue (addressType location, valueType *value); -extern void pokeRelativeByteValue (addressType location, valueType *value); -extern void pokeRelativeWordValue (addressType location, valueType *value); -extern void pushBinding (symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); - -bool + bool absoluteValue(valueType *address) { return(address->kindOfValue == ABSOLUTE_VALUE); @@ -305,8 +296,6 @@ createArray(expressionType *dimension, expressionListType *initializers) arrayType *result; int i; - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - initCount = expressionListLength(initializers); if ((int)dimension == -1) { arraySize = initCount; @@ -378,7 +367,6 @@ expressionListLength(expressionListType *expressionList) fieldValue(symbolTableEntryType *symbol) { valueType *value; - valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); value = evaluateIdentifier(symbol, FALSE, NO_FIXUP); if (value->kindOfValue != FIELD_VALUE) { @@ -458,8 +446,6 @@ isExternal(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getBaseContext(symbolTableEntryType *identifier); - context = getBaseContext(symbol); return (context!=NULL && (context->attributes & GLOBAL_ATT)!=0 && context->usage != DEAD_SYMBOL); @@ -747,8 +733,6 @@ swab(int i) valueType * swabValue(valueType *value) { - valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); - return(newValue(value->kindOfValue, swab(value->value), value-> addressMode)); } @@ -766,9 +750,6 @@ valueField(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); - symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); if (workingContext->usage == DEAD_SYMBOL) @@ -791,10 +772,6 @@ valueLabel(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolTableEntryType *generateLocalLabel(symbolTableEntryType *symbol); - symbolInContextType *getBaseContext(symbolTableEntryType *identifier); - symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); - symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); if (workingContext->usage == DEAD_SYMBOL) @@ -838,8 +815,6 @@ createFixup(expressionType *expression, addressType location, fixupKindType kind { fixupListType *newFixup; - expressionType *generateFixupExpression(expressionType *expression); - if (debug || emitPrint) printCreateFixup(expression, location, kindOfFixup); newFixup = typeAlloc(fixupListType); @@ -869,9 +844,6 @@ createFixup(expressionType *expression, addressType location, fixupKindType kind void finishUp(void) { - void performFixups(fixupListType *fixups); - void performStartAddressFixup(void); - if (listingOn) terminateListingFiles(); performFixups(fixupList); @@ -1036,8 +1008,6 @@ performStartAddressFixup(void) { expressionType *startAddressExpression; - expressionType *generateFixupExpression(expressionType *expression); - startAddressExpression = (expressionType *)startAddress; startAddress = evaluateExpression(startAddressExpression,NO_FIXUP_OK); if (startAddress->kindOfValue == UNDEFINED_VALUE && @@ -1163,8 +1133,6 @@ effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTa expressionType *expression; environmentType *saveEnvironment; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - context = getWorkingContext(symbol); saveEnvironment = currentEnvironment; while (context != NULL && context->usage == ARGUMENT_SYMBOL && @@ -1193,9 +1161,6 @@ effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTa symbolTableEntryType * generateLocalLabel(symbolTableEntryType *symbol) { - stringType *localLabelString(symbolTableEntryType *symbol); - symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); - return(lookupOrEnterSymbol(localLabelString(symbol), LABEL_SYMBOL)); } @@ -1231,8 +1196,6 @@ localLabelString(symbolTableEntryType *symbol) #define TEMP_SYMBOL_SIZE_LIMIT 200 char nameUnderConstruction[TEMP_SYMBOL_SIZE_LIMIT]; - stringType *saveString(char *s); - sprintf(nameUnderConstruction, "_%d_", localLabelTagValue(symbol)); strncat(nameUnderConstruction, &(symbName(symbol)[1]), TEMP_SYMBOL_SIZE_LIMIT); @@ -1244,9 +1207,6 @@ localLabelTagValue(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - void addNewLocalVariable(symbolTableEntryType *symbol); - context = getWorkingContext(symbol); if (context == NULL) botch("local label doesn't have symbol context\n"); @@ -1264,7 +1224,6 @@ localLabelTagValue(symbolTableEntryType *symbol) addBreak(codeBreakKindType kind, int data) { codeBreakType *newBreak; - codeBreakType *buildCodeBreak(codeBreakKindType kind, addressType address, int data); newBreak = buildCodeBreak(kind, currentLocationCounter.value, data); if (codeBreakList == NULL) { @@ -1278,8 +1237,6 @@ addBreak(codeBreakKindType kind, int data) void reserveAbsolute(addressType startAddress, int blockSize) { - reservationListType *buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation); - if (reservationList != NULL && reservationList->startAddress + reservationList->blockSize == startAddress) reservationList->blockSize += blockSize; diff --git a/statementSemantics.c b/statementSemantics.c index 45b7853..f8ea6dc 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -30,12 +30,23 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "actions.h" +#include "debugPrint.h" #include "emitBranch.h" +#include "emitStuff.h" +#include "errorStuff.h" #include "expressionSemantics.h" +#include "fixups.h" +#include "garbage.h" +#include "lexer.h" +#include "listing.h" +#include "lookups.h" #include "operandStuff.h" #include "parserMisc.h" #include "semanticMisc.h" #include "statementSemantics.h" +#include "structSemantics.h" +#include "tokenStrings.h" operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; @@ -54,48 +65,7 @@ bool nullStatementFlag = FALSE; #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOn() expandMacros=saveExpansion; - -extern void error (errorType theError, ...); -extern void moreText (char *format, ...); -extern void expandOperands (int op); -extern void endLine (void); -extern int bindMacroArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName); -extern void unbindArguments (argumentDefinitionListType *argumentList, int numberToUnbind); -extern void unbindLocalVariables (identifierListType *identifierList); -extern void expandExpression (char *toBuffer, char **toBufferPtr); -extern void emitByte (byte byteValue); -extern void emitString (stringType *string); -extern void emitByteValue (valueType *byteValue); -extern void startLineMarked (void); -extern void tabIndent (void); -extern void emitWordValue (valueType *wordValue); -extern void reincarnateSymbol (symbolInContextType *context, symbolUsageKindType newUsage); -extern char *conditionString (conditionType condition); -extern char *usageString (symbolUsageKindType usageKind); -extern symbolTableEntryType *lookupOrEnterSymbol (stringType *s, symbolUsageKindType kind); -extern bool isDefined (valueType *value); -extern void fixupBranch (valueType *location, valueType target); -extern void fixupJump (simpleFixupListType *locations, valueType target); -extern void pushInputFileStack (stringType *fileName); -extern void saveIndexForListing (statementKindType kindOfStatement, int cumulativeLineNumber); -extern void startLine (void); -extern void expandLabel (void); -extern void emitLongValue (valueType *longValue); -extern void pushBinding (symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); -extern void saveEndMifForListing (int cumulativeLineNumber); -extern char *valueKindString (valueKindType valueKind); -extern bool strcmplc (char *s1, char *s2); -extern void warning (errorType theError, ...); -extern expressionType *generateFixupExpression (expressionType *expression); -extern void instantiateStruct (structStatementBodyType *structStatement); -extern void assembleStructDefinition (structStatementBodyType *structStatement); -extern void purgeSymbol (symbolTableEntryType *symbol); -extern bool labeledLine (void); -extern void flushExpressionString (void); -extern void freeStatement (statementType *statement); -extern void printStatement (statementType *statement); - -void + void assembleBlock(blockType *block) { nullAssemble(block); @@ -1185,13 +1155,7 @@ assembleWordStatement(wordStatementBodyType *wordStatement) } bool -assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, - ifFixupList) - statementKindType kind; - statementBodyType body; - int cumulativeLineNumber; - bool worryAboutIf; - simpleFixupListType **ifFixupList; +assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList) { bool result; diff --git a/structSemantics.c b/structSemantics.c index eef4b44..4891775 100644 --- a/structSemantics.c +++ b/structSemantics.c @@ -29,22 +29,15 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "emitStuff.h" +#include "errorStuff.h" +#include "listing.h" +#include "parserMisc.h" +#include "semanticMisc.h" +#include "statementSemantics.h" +#include "structSemantics.h" - -extern void botch (char *message, ...); -extern void error (errorType theError, ...); -extern void moreText (char *format, ...); -extern void endLine (void); -extern void emitByte (byte byteValue); -extern bool listableStatement (statementKindType kind); -extern void startLine (void); -extern void assembleLabelList (labelListType *labelList); -extern void expandLabel (void); -extern void tabIndent (void); -extern bool assembleStatementBody (statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList); -extern void startLineMarked (void); - -void + void putStructFixups(int base, fixupListType *fixups) { fixupListType *newFixup; @@ -96,8 +89,6 @@ instantiateStruct(structStatementBodyType *structStatement) int base; symbolInContextType *context; - symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); - #define structInstance ((structInstanceType *) context->value->value) context = getWorkingContext(structStatement->structName); @@ -157,8 +148,6 @@ assembleStructDefinition(structStatementBodyType *structStatement) symbolTableEntryType *name; symbolInContextType *context; - symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); - name = effectiveSymbol(structStatement->structName, &context); if (context == NULL) botch("struct definition doesn't have working context\n");