From bca47ce3e1333d57e43252f5c75d77b496daad62 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 00:36:58 -0800 Subject: [PATCH 01/41] Use bison as the default yacc --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9e34208..52ba3a7 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,10 @@ conditionDefs_$(PROC).h driver.c slinkyExpressions.h HEADERS = macrossTypes.h macrossGlobals.h CFLAGS=-m32 # macross is not 64 bit clean +# If yacc is notionally present on a system, it's usually actually +# bison in a compatibility mode. bison is available by name more often +# than bison itself is. +YACC=bison -o y.tab.c .c.o: cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) $*.c @@ -153,10 +157,10 @@ y.tab.o: y.tab.c $(HEADERS) cc $(CFLAGS) -c -g -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c y.tab.c y.tab.h: macross_$(PROC).y - yacc -d macross_$(PROC).y + $(YACC) -d macross_$(PROC).y y.output: macross_$(PROC).y - yacc -vd macross_$(PROC).y + $(YACC) -vd macross_$(PROC).y cleanup: /bin/rm -f *.o y.output y.tab.c y.tab.h macross From 75ff8459e50421a2f8252269a1aaa2b6f626edb6 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 01:08:06 -0800 Subject: [PATCH 02/41] Function prototypes for semanticMisc.c --- semanticMisc.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 semanticMisc.h diff --git a/semanticMisc.h b/semanticMisc.h new file mode 100644 index 0000000..f2d2aec --- /dev/null +++ b/semanticMisc.h @@ -0,0 +1,66 @@ +#ifndef SEMANTIC_MISC_H_ +#define SEMANTIC_MISC_H_ + +#include "macrossTypes.h" + +/* Miscellaneous */ +bool absoluteValue(valueType *address); +void addAttributeToSymbol(symbolTableEntryType *symbol, symbolAttributesType attribute); +addressType addressValue(valueType *value); +valueKindType addValueKind(valueType *leftOperand, valueType *rightOperand); +bool alreadyDefined(symbolInContextType *context); +bool booleanTest(expressionType *expression); +int countArguments(functionDefinitionType *function); +int countParameters(operandListType *parameterList); +arrayType *allocArray(int size, valueType ***contentsPtr); +valueType *createArray(expresionType *dimension, expressionListType *initializers); +bool decrementable(valueType *value); +int expressionListLength(expressionListType *expressionList); +int fieldValue(symbolTableEntryType *symbol); +bool incrementable(valueType *value); +int intValue(valueType *value); +bool isAssignable(symbolInContextType *context); +bool isBuiltInFunction(symbolInContextType *context); +bool isDefinable(symbolInContextType *context); +bool isExternal(symbolTableEntryType *symbol); +bool isFailure(valueType *value); +bool isFunction(symbolInContextType *context); +bool isLastStatementInBlock(statementType *statement); +bool isLogicalOp(int op); +bool isPotentialVariable(symbolInContextType *context); +bool isUndefined(valueType *value); +bool isUsable(valueType *value); +bool logicalXOR(int int1, int int2); +valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); +valueKindType opValueKind(valueType *leftOperand, valueType *rightOperand); +bool relocatableValue(valueType *address); +valueKindType selectValueKind(valueType *leftOperand, valueType *rightOperand); +valueKindType subValueKind(valueType *leftOperand, valueType *rightOperand); +int swab(int i); +valueType *swabValue(valueType *value); +valueKindType unopValueKind(valueType *operand); +void valueField(symbolTableEntryType *symbol, valueType *value); +void valueLabel(symbolTableEntryType *symbol, valueType *value); + +/* Fixups and references */ +void createFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup, codeBufferKindType codeMode, int whichFixup); +void finishUp(); +void noteAnonymousReference(); +void noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode); +void performFixups(fixupListType *fixups); +void performStartAddressFixup(); +void putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup); + +/* Contexts and dynamic symbol creation */ +void addNewLocalVariable(symbolTableEntryType *symbol); +symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); +symbolTableEntryType *generateLocalLabel(symbolTableEntryType *symbol); +symbolInContextType *getBaseContext(symbolTableEntryType *identifier); +symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); +stringType *localLabelString(symbolTableEntryType *symbol); +int localLabelTagValue(symbolTableEntryType *symbol); +void addBreak(codeBreakKindType kind, int data); +void reserveAbsolute(addressType startAddress, int blockSize); +bool listableStatement(statementKindType kind); + +#endif From cbad3bfb156e4217968d2ef551f7e78984fb84a2 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 03:51:29 -0800 Subject: [PATCH 03/41] Move Macross's local extern function references into ANSI C headers full of prototypes --- builtInFunctions.c | 97 +++++++++++++++++-------------------------- debugPrint.c | 7 +--- emitBranch.h | 16 +++++++ encode.c | 3 +- expressionSemantics.c | 52 +---------------------- expressionSemantics.h | 25 +++++++++++ lexer.c | 1 + listing.c | 24 ++++------- listing.h | 41 ++++++++++++++++++ macrossTypes.h | 5 +++ operandStuff.h | 21 ++++++++++ operandStuffSD_6502.c | 3 +- parserMisc.c | 23 ++++++---- parserMisc.h | 16 +++++++ semanticMisc.c | 5 ++- semanticMisc.h | 2 +- statementSemantics.c | 83 ++++-------------------------------- statementSemantics.h | 54 ++++++++++++++++++++++++ 18 files changed, 259 insertions(+), 219 deletions(-) create mode 100644 emitBranch.h create mode 100644 expressionSemantics.h create mode 100644 listing.h create mode 100644 operandStuff.h create mode 100644 parserMisc.h create mode 100644 statementSemantics.h diff --git a/builtInFunctions.c b/builtInFunctions.c index 4fdc6b4..c230cde 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -30,8 +30,13 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "expressionSemantics.h" +#include "operandStuff.h" +#include "semanticMisc.h" + #include + /* Helper routines to return values into the Macross expression evaluation environment @@ -41,7 +46,6 @@ makeBooleanValue(test) int test; { - valueType *newValue(); return(newValue(ABSOLUTE_VALUE, test!=0, EXPRESSION_OPND)); } @@ -49,7 +53,6 @@ makeBooleanValue(test) valueType * makeFailureValue() { - valueType *newValue(); return(newValue(FAIL, 0, EXPRESSION_OPND)); } @@ -58,7 +61,6 @@ makeFailureValue() makeIntegerValue(integer) int integer; { - valueType *newValue(); return(newValue(ABSOLUTE_VALUE, integer, EXPRESSION_OPND)); } @@ -67,7 +69,6 @@ makeIntegerValue(integer) makeOperandValue(operand) operandType *operand; { - valueType *newValue(); return(newValue(OPERAND_VALUE, operand, EXPRESSION_OPND)); } @@ -76,7 +77,6 @@ makeOperandValue(operand) makeStringValue(string) stringType *string; { - valueType *newValue(); return(newValue(STRING_VALUE, string, STRING_OPND)); } @@ -84,7 +84,6 @@ makeStringValue(string) valueType * makeUndefinedValue() { - valueType *newValue(); return(newValue(UNDEFINED_VALUE, 0, EXPRESSION_OPND)); } @@ -105,10 +104,9 @@ addressModeBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(evaluatedParameter->addressMode)); } else { return(makeIntegerValue(-1)); @@ -126,13 +124,12 @@ applyBIF(parameterList, kindOfFixup) macroTableEntryType *macroToCall; macroTableEntryType *lookupMacroName(); - valueType *evaluateOperand(); if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "apply"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "apply"); return(makeFailureValue()); @@ -154,11 +151,10 @@ arrayLengthBIF(parameterList, kindOfFixup) fixupKindType kindOfFixup; { valueType *testObjectValue; - valueType *evaluateOperand(); if (parameterList == NULL) return(makeIntegerValue(0)); - testObjectValue = evaluateOperand(parameterList, NO_FIXUP_OK); + testObjectValue = evaluateOperand(parameterList); if (testObjectValue->kindOfValue == STRING_VALUE) { return(makeIntegerValue(strlen(testObjectValue->value))); } else if (testObjectValue->kindOfValue == ARRAY_VALUE) { @@ -201,11 +197,10 @@ atasciiBIF(parameterList, kindOfFixup) stringType *string; stringType *newString; - valueType *evaluateOperand(); if (parameterList == NULL) return(makeStringValue("")); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "atascii"); return(makeFailureValue()); @@ -232,16 +227,15 @@ atasciiColorBIF(parameterList, kindOfFixup) stringType *newString; byte testChar; - valueType *evaluateOperand(); if (parameterList == NULL) return(makeStringValue("")); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); parameterList = parameterList->nextOperand; if (parameterList == NULL) { color = 0; } else { - colorValue = evaluateOperand(parameterList, NO_FIXUP); + colorValue = evaluateOperand(parameterList); if (colorValue->kindOfValue != ABSOLUTE_VALUE) { error(BAD_COLOR_ARGUMENT_TO_ATASCII_COLOR_ERROR); return(makeFailureValue()); @@ -314,10 +308,9 @@ isAbsoluteValueBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == ABSOLUTE_VALUE)); } else { @@ -333,10 +326,9 @@ isBlockBIF(parameterList, kindOfFixup) /* questionable */ { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == BLOCK_VALUE)); } else { @@ -352,10 +344,9 @@ isBuiltInFunctionBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == BUILT_IN_FUNCTION_VALUE)); } else { @@ -371,10 +362,9 @@ isConditionCodeBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == CONDITION_VALUE)); } else { @@ -448,10 +438,9 @@ isFieldBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == FIELD_VALUE)); } else { @@ -467,10 +456,9 @@ isFunctionBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == FUNCTION_VALUE)); } else { @@ -486,10 +474,9 @@ isRelocatableValueBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == RELOCATABLE_VALUE || evaluatedParameter-> kindOfValue == DATA_VALUE)); @@ -506,10 +493,9 @@ isStringBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == STRING_VALUE)); } else { @@ -525,10 +511,9 @@ isStructBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == STRUCT_VALUE)); } else { @@ -604,7 +589,7 @@ makeArrayBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "makeArray"); return(makeFailureValue()); } - lengthValue = evaluateOperand(parameterList, NO_FIXUP); + lengthValue = evaluateOperand(parameterList); if (lengthValue->kindOfValue != ABSOLUTE_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, "makeArray", 1); @@ -619,8 +604,7 @@ makeArrayBIF(parameterList, kindOfFixup) parameterList = parameterList->nextOperand; for (i=0; inextOperand; } else { arrayContents[i] = NULL; @@ -644,11 +628,10 @@ nthCharBIF(parameterList, kindOfFixup) valueType *stringValue; stringType *string; - valueType *evaluateOperand(); if (parameterList == NULL) return(makeFailureValue()); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "nthChar"); return(makeFailureValue()); @@ -657,7 +640,7 @@ nthCharBIF(parameterList, kindOfFixup) if (parameterList == NULL) { position = 0; } else { - positionValue = evaluateOperand(parameterList, NO_FIXUP); + positionValue = evaluateOperand(parameterList); if (positionValue->kindOfValue != ABSOLUTE_VALUE) { error(BAD_POSITION_ARGUMENT_TO_NTH_CHAR_ERROR); return(makeFailureValue()); @@ -685,11 +668,10 @@ printfBIF(parameterList, kindOfFixup) int argument[20]; valueType *result; - valueType *evaluateOperand(); result = makeFailureValue(); if (parameterList != NULL) { - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(PRINTF_FORMAT_IS_NOT_A_STRING_ERROR); return(result); @@ -699,7 +681,7 @@ printfBIF(parameterList, kindOfFixup) argumentCount = 0; while (parameterList != NULL && argumentCount < 20) { argument[argumentCount++] = evaluateOperand( - parameterList)->value; + parameterList)->value; parameterList = parameterList->nextOperand; } /* cretinous hack */ @@ -726,7 +708,7 @@ strcatBIF(parameterList, kindOfFixup) if (parameterList == NULL) return(makeStringValue("")); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 1); return(makeFailureValue()); @@ -735,7 +717,7 @@ strcatBIF(parameterList, kindOfFixup) parameterList = parameterList->nextOperand; if (parameterList == NULL) return(makeStringValue(string1)); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 2); return(makeFailureValue()); @@ -762,7 +744,7 @@ strcmpBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmp"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 1); return(makeFailureValue()); @@ -771,7 +753,7 @@ strcmpBIF(parameterList, kindOfFixup) parameterList = parameterList->nextOperand; if (parameterList == NULL) return(makeStringValue(string1)); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 2); return(makeFailureValue()); @@ -795,7 +777,7 @@ strcmplcBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmplc"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 1); return(makeFailureValue()); @@ -804,7 +786,7 @@ strcmplcBIF(parameterList, kindOfFixup) parameterList = parameterList->nextOperand; if (parameterList == NULL) return(makeStringValue(string1)); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 2); return(makeFailureValue()); @@ -823,7 +805,7 @@ strlenBIF(parameterList, kindOfFixup) if (parameterList == NULL) return(makeIntegerValue(-1)); - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "strlen"); return(makeFailureValue()); @@ -851,7 +833,7 @@ substrBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "substr"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "substr"); return(makeFailureValue()); @@ -864,7 +846,7 @@ substrBIF(parameterList, kindOfFixup) error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, "substr"); return(makeFailureValue()); } - startValue = evaluateOperand(parameterList, NO_FIXUP); + startValue = evaluateOperand(parameterList); if (startValue->kindOfValue != ABSOLUTE_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, "substr", 2); @@ -883,7 +865,7 @@ substrBIF(parameterList, kindOfFixup) if (backwards) length = -length; } else { - lengthValue = evaluateOperand(parameterList, NO_FIXUP); + lengthValue = evaluateOperand(parameterList); if (lengthValue->kindOfValue != ABSOLUTE_VALUE) { error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, "substr", 3); @@ -928,7 +910,7 @@ symbolLookupBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolLookup"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolLookup"); return(makeFailureValue()); @@ -952,7 +934,7 @@ symbolDefineBIF(parameterList, kindOfFixup) error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolDefine"); return(makeFailureValue()); } - stringValue = evaluateOperand(parameterList, NO_FIXUP); + stringValue = evaluateOperand(parameterList); if (stringValue->kindOfValue != STRING_VALUE) { error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolDefine"); return(makeFailureValue()); @@ -1042,10 +1024,9 @@ valueTypeBIF(parameterList, kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(evaluatedParameter->kindOfValue)); } else { return(makeIntegerValue(-1)); diff --git a/debugPrint.c b/debugPrint.c index f44ce7e..01db367 100644 --- a/debugPrint.c +++ b/debugPrint.c @@ -32,6 +32,8 @@ #include "macrossGlobals.h" #include "y.tab.h" +void printExpression(expressionType *expression); + /* Print out the parse-tree. */ @@ -274,7 +276,6 @@ printArrayTerm(arrayTerm) arrayTermType *arrayTerm; { void printIdentifier(); - void printExpression(); nullPrint(arrayTerm); tab(); printf("(array\n"); @@ -289,7 +290,6 @@ printArrayTerm(arrayTerm) printAssignmentTerm(assignmentTerm) binopTermType *assignmentTerm; { - void printExpression(); nullPrint(assignmentTerm); tab(); printf("(assignment ["); @@ -307,7 +307,6 @@ printBinopTerm(binopTerm) binopTermType *binopTerm; { void printIdentifier(); - void printExpression(); nullPrint(binopTerm); tab(); printf("(binop ["); @@ -391,8 +390,6 @@ printPreopTerm(preopTerm) printUnopTerm(unopTerm) unopTermType *unopTerm; { - void printExpression(); - nullPrint(unopTerm); tab(); printf("(unop ["); printToken(unopTerm->unop); diff --git a/emitBranch.h b/emitBranch.h new file mode 100644 index 0000000..f53d9c0 --- /dev/null +++ b/emitBranch.h @@ -0,0 +1,16 @@ +#ifndef EMIT_BRANCH_H_ +#define EMIT_BRANCH_H_ + +#include "macrossTypes.h" + +#if TARGET_CPU == CPU_6502 +void emitRelativeBranch(conditionType condition, valueType *target, valueType fixupLocation[COMPOUND_BRANCH_MAX]); +#elif TARGET_CPU == CPU_68000 +void emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation); +#else +#error Missing or invalid TARGET_CPU +#endif + +simpleFixupListType *emitJump(valueType *target, simpleFixupListType *previousFixups); + +#endif diff --git a/encode.c b/encode.c index e57a792..6776dbe 100644 --- a/encode.c +++ b/encode.c @@ -31,6 +31,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "semanticMisc.h" #include "slinkyExpressions.h" #define nullEncode(thing) if (thing==NULL) return(TRUE); @@ -133,8 +134,6 @@ encodeFunctionCall(functionCall) symbolInContextType *workingContext; operandListType *parameterList; - symbolInContextType *getWorkingContext(); - nullEncode(functionCall); workingContext = getWorkingContext(functionCall->functionName); if (isFunction(workingContext)) { diff --git a/expressionSemantics.c b/expressionSemantics.c index 7f4bef1..0a640db 100644 --- a/expressionSemantics.c +++ b/expressionSemantics.c @@ -31,6 +31,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "expressionSemantics.h" +#include "semanticMisc.h" operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; @@ -71,8 +73,6 @@ arrayLookup(arrayTerm, kindOfThing) int index; stringType *string; - valueType *evaluateExpression(); - *kindOfThing = FAIL; arrayValue = evaluateExpression(arrayTerm->arrayName, NO_FIXUP); if (arrayValue->kindOfValue == FAIL) @@ -133,9 +133,6 @@ evaluateArrayTerm(arrayTerm) environmentType *saveEnvironment; bool saveExpansion; - valueType *newValue(); - valueType *evaluateOperand(); - expansionOff(); resultThing = arrayLookup(arrayTerm, &kindOfResult); expansionOn(); @@ -187,15 +184,6 @@ evaluateAssignmentTerm(assignmentTerm, kindOfFixup) char *charPtr; char objectChar; - symbolTableEntryType *effectiveSymbol(); - valueType *evaluateExpressionInternally(); - valueKindType addValueKind(); - valueKindType selectValueKind(); - valueKindType subValueKind(); - valueKindType opValueKind(); - valueType *makeUndefinedValue(); - valueType *newValue(); - nullEvaluate(assignmentTerm); sideEffectFlag = TRUE; stringAssign = FALSE; @@ -386,11 +374,6 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) operandKindType resultAddressMode; valueType *result; - symbolInContextType *getWorkingContext(); - valueType *evaluateExpressionInternally(); - valueType *newValue(); - valueType *makeUndefinedValue(); - nullEvaluate(binopTerm); if (binopTerm->binop != SUB && binopTerm->binop != ADD) isTopLevel = FALSE; @@ -598,8 +581,6 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) evaluateCondition(condition) conditionType condition; { - valueType *newValue(); - expand(moreExpression("%s", conditionString(condition))); return(newValue(CONDITION_VALUE, condition, EXPRESSION_OPND)); } @@ -633,10 +614,6 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) valueType *result; bool saveExpansion; - symbolInContextType *getWorkingContext(); - valueType *evaluateBuiltInFunctionCall(); - valueType *newValue(); - nullEvaluate(functionCall); sideEffectFlag = TRUE; pushEnvironment(newEnvironment); @@ -705,7 +682,6 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) valueType * evaluateHere() { - valueType *newValue(); valueType *result; expand(moreExpression("here")); @@ -727,11 +703,6 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup) environmentType *saveEnvironment; bool saveExpansion; - valueType *newValue(); - valueType *evaluateOperand(); - symbolInContextType *getWorkingContext(); - symbolTableEntryType *generateLocalLabel(); - nullEvaluate(identifier); identifier->referenceCount++; if (symbName(identifier)[0] == '$') @@ -851,8 +822,6 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup) evaluateNumber(number) numberTermType number; { - valueType *newValue(); - expand(moreExpression("0x%x", number)); return(newValue(ABSOLUTE_VALUE, number, EXPRESSION_OPND)); } @@ -868,9 +837,6 @@ evaluatePostopTerm(postopTerm) symbolInContextType *workingContext; symbolTableEntryType *targetSymbol; - symbolTableEntryType *effectiveSymbol(); - symbolInContextType *getWorkingContext(); - nullEvaluate(postopTerm); sideEffectFlag = TRUE; if (postopTerm->postOpArgument->kindOfTerm == IDENTIFIER_EXPR) { @@ -939,9 +905,6 @@ evaluatePreopTerm(preopTerm) symbolInContextType *workingContext; symbolTableEntryType *targetSymbol; - symbolTableEntryType *effectiveSymbol(); - symbolInContextType *getWorkingContext(); - nullEvaluate(preopTerm); sideEffectFlag = TRUE; if (preopTerm->preOpArgument->kindOfTerm == IDENTIFIER_EXPR) { @@ -1003,7 +966,6 @@ evaluatePreopTerm(preopTerm) evaluateString(string) stringType *string; { - valueType *newValue(); stringType *newString; expand(moreExpression("\"%s\"", string)); @@ -1023,11 +985,6 @@ evaluateUnopTerm(unopTerm, kindOfFixup) operandKindType resultAddressMode; valueType *result; - valueKindType unopValueKind(); - valueType *newValue(); - valueType *evaluateExpressionInternally(); - valueType *makeUndefinedValue(); - nullEvaluate(unopTerm); expand(moreExpression("%s", tokenString(unopTerm->unop))); theOperand = evaluateExpressionInternally(unopTerm->unopArgument, @@ -1213,10 +1170,6 @@ evaluateExpressionStandalone(expression) evaluateDefineExpression(expression) expressionType *expression; { - valueType *newValue(); - expressionType *generateFixupExpression(); - operandType *buildOperand(); - nullEvaluate(expression); return(newValue(OPERAND_VALUE, buildOperand(EXPRESSION_OPND, generateFixupExpression(expression)), EXPRESSION_OPND)); @@ -1227,7 +1180,6 @@ evaluateSelectionList(selectionList) selectionListType *selectionList; { int offset; - valueType *newValue(); offset = 0; while (selectionList != NULL) { diff --git a/expressionSemantics.h b/expressionSemantics.h new file mode 100644 index 0000000..e6b004f --- /dev/null +++ b/expressionSemantics.h @@ -0,0 +1,25 @@ +#ifndef EXPRESSION_SEMANTICS_H_ +#define EXPRESSION_SEMANTICS_H_ +#include "macrossTypes.h" + +anyOldThing *arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing); +valueType *evaluateArrayTerm(arrayTermType *arrayTerm); +valueType *evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup); +valueType *evaluateBinopTerm(binopTermType *assignmentTerm, bool isTopLevel, fixupKindType kindOfFixup); +valueType *evaluateCondition(conditionType condition); +valueType *evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup); +valueType *evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone); +valueType *evaluateHere(); +valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); +valueType *evaluateNumber(numberTermType number); +valueType *evaluatePostopTerm(postOpTermType *postopTerm); +valueType *evaluatePreopTerm(preOpTermType *preopTerm); +valueType *evaluateString(stringType *string); +valueType *evaluateUnopTerm(unopTermType* unopTerm, fixupKindType kindOfFixup); +valueType *evaluateExpressionInternally(expressionType *expression, bool isToplevel, fixupKindType kindOfFixup, bool isStandalone); +valueType *evaluateExpression(expressionType *expression, fixupKindType kindOfFixup); +void evaluateExpressionStandalone(expressionType *expression); +valueType *evaluateDefineExpression(expressionType *expression); +valueType *evaluateSelectionList(selectionListType *selectionList); + +#endif diff --git a/lexer.c b/lexer.c index 5fd7807..a49c84d 100644 --- a/lexer.c +++ b/lexer.c @@ -31,6 +31,7 @@ #include "macrossGlobals.h" #include "y.tab.h" #include "lexerTables.h" +#include "parserMisc.h" extern int yylval; extern int yydebug; diff --git a/listing.c b/listing.c index 7050301..548922a 100644 --- a/listing.c +++ b/listing.c @@ -29,6 +29,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "listing.h" static char lineBuffer1[LINE_BUFFER_SIZE]; static char lineBuffer2[LINE_BUFFER_SIZE]; @@ -43,8 +44,6 @@ static int nextMacroDepth; void outputListing() { - void generateListing(); - rewind(saveFileForPass2); rewind(indexFileForPass2); rewind(macroFileForPass2); @@ -122,9 +121,6 @@ generateListing() int numberOfBytesListed; char *tempText; - void readIndexFileLine(); - void readSourceFileLine(); - sourceLineNumber = 1; alreadyListingMacroExpansion = FALSE; readSourceFileLine(&sourceAddress, &sourceDepth, sourceText, @@ -362,8 +358,6 @@ printListingLine(numberOfBytes, byteAddress, text, kind) { int i; - void tabPrint(); - if (kind != BLOCK_STATEMENT) numberOfBytes = (numberOfBytes < 4) ? numberOfBytes : 4; @@ -484,10 +478,8 @@ printNTimes(aChar, times) char aChar; int times; { - void moreText(); - while (times-- > 0) - moreText("%c", aChar); + moreText("%c", aChar, 0, 0); } void @@ -595,9 +587,9 @@ expandExpression(toBuffer, toBufferPtr) char **toBufferPtr; { if (toBuffer == NULL) - moreText("%s", expressionString); + moreText("%s", expressionString, 0, 0); else - addText(toBuffer, toBufferPtr, "%s", expressionString); + addText(toBuffer, toBufferPtr, "%s", expressionString, 0, 0); flushExpressionString(); } @@ -607,14 +599,14 @@ expandNum(buffer, bufferPtr, n) char **bufferPtr; int n; { - moreTextOptional(buffer, bufferPtr, "%d", n); + moreTextOptional(buffer, bufferPtr, "%d", n, 0, 0); } void flushOperand(n) int n; { - moreText("%s", operandBuffer[n]); + moreText("%s", operandBuffer[n], 0, 0); operandBuffer[n][0] = '\0'; } @@ -627,7 +619,7 @@ expandOperands(op) if (op > 0) { flushOperand(0); for (i=1; i /* @@ -1093,3 +1096,5 @@ typedef enum {/* horrible kludge due to C compiler bug on Sun */ /* Boy, is this macro useful! */ #define typeAlloc(type) (type *)malloc(sizeof(type)) + +#endif diff --git a/operandStuff.h b/operandStuff.h new file mode 100644 index 0000000..796d565 --- /dev/null +++ b/operandStuff.h @@ -0,0 +1,21 @@ +#ifndef OPERAND_STUFF_H_ +#define OPERAND_STUFF_H_ + +#include "macrossTypes.h" + +#if TARGET_CPU == CPU_6502 +operandType *buildOperand(operandKindType kindOfOperand, anyOldThing *arg); +#elif TARGET_CPU == CPU_68000 +operandType *buildOperand(operandKindType kindOfOperand, int arg1, int arg2, int arg3, int arg4); +#else +#error Unknown or undefined processor type +#endif + +operandListType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); +void expandOperand(operandKindType addressMode, char *buffer); +void freeOperand(operandType *operand); +valueType *evaluateOperand(operandType *operand); +conditionType invertConditionCode(conditionType conditionCode); +bool shouldParethesize(operandType *operand); + +#endif diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index 5e35713..68b860f 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -229,8 +229,9 @@ freeOperand(operand) /* corresponds to routines in listing.c */ void -expandOperand(addressMode) +expandOperand(addressMode, buffer) operandKindType addressMode; + char * buffer; { switch (addressMode) { case IMMEDIATE_OPND: moreText("#"); break; diff --git a/parserMisc.c b/parserMisc.c index b165c0b..5f96c2b 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -32,6 +32,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" #include "y.tab.h" +#include "parserMisc.h" statementType * addLabelToStatement(labelList, statement) @@ -46,12 +47,16 @@ addLabelToStatement(labelList, statement) return(statement); } +/* TODO: This should be a varargs function. In 1984 it probably wasn't + * standardized, but here in Glorious Future Year 1989 the vprintf + * function does almost exactly what we want. */ + void botch(message, arg1, arg2, arg3) char *message; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; + int arg1; + int arg2; + int arg3; { printf("Macross horrible terrible internal botch: "); printf(message, arg1, arg2, arg3); @@ -72,7 +77,7 @@ convertDefineToMdefine(defineStatement) { if (defineStatement->kindOfStatement != DEFINE_STATEMENT) botch("convertDefineToMdefine got statement kind: %d\n", - defineStatement->kindOfStatement); + defineStatement->kindOfStatement, 0, 0); defineStatement->kindOfStatement = MDEFINE_STATEMENT; return(defineStatement); } @@ -85,9 +90,9 @@ extractIfBody(ifStatement) result = ifStatement->statementBody.ifUnion; if (ifStatement->labels != NULL) - botch("extract if body with non-null labels\n"); + botch("extract if body with non-null labels\n", 0, 0, 0); else if (ifStatement->nextStatement != NULL) - botch("extract if body with non-null next\n"); + botch("extract if body with non-null next\n", 0, 0, 0); else qfree(ifStatement); return(result); @@ -101,9 +106,9 @@ extractMifBody(mifStatement) result = mifStatement->statementBody.mifUnion; if (mifStatement->labels != NULL) - botch("extract mif body with non-null labels\n"); + botch("extract mif body with non-null labels\n", 0, 0, 0); else if (mifStatement->nextStatement != NULL) - botch("extract mif body with non-null next\n"); + botch("extract mif body with non-null next\n", 0, 0, 0); else qfree(mifStatement); return(result); @@ -117,7 +122,7 @@ extractString(textExpression) if (textExpression->kindOfOperand != STRING_OPND) botch("extract string got handed an opnd kind: %d\n", - textExpression->kindOfOperand); + textExpression->kindOfOperand, 0, 0); result = textExpression->theOperand.stringUnion; qfree(textExpression); return(result); diff --git a/parserMisc.h b/parserMisc.h new file mode 100644 index 0000000..fc08c53 --- /dev/null +++ b/parserMisc.h @@ -0,0 +1,16 @@ +#ifndef PARSER_MISC_H_ +#define PARSER_MISC_H_ +#include "macrossTypes.h" + +statementType *addLabelToSatement(labelListType *labelList, statementType *statement); +void botch(char *message, int arg1, int arg2, int arg3); +void checkDefineAssignmentOperator(assignmentKindType assignmentOperator); +void convertDefineToMDefine(statementType *defineStatement); +ifStatementBodyType *extractIfBody(statementType *ifStatement); +mifStatementBodyType *extractMifBody(statementType *mifStatement); +stringType *extractString(operandType *textExpression); +void popMacroOrFunctionNestingDepth(); +void pushMacroOrFunctionNestingDepth(); +char *saveString(char *s); + +#endif diff --git a/semanticMisc.c b/semanticMisc.c index 7861d62..a2f0203 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -32,6 +32,9 @@ #include "macrossGlobals.h" #include "y.tab.h" +#include "semanticMisc.h" +#include "expressionSemantics.h" + #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOn() expandMacros=saveExpansion; @@ -219,7 +222,6 @@ booleanTest(expression) bool result; valueType *expressionResult; bool saveExpansion; - valueType *evaluateExpression(); expansionOff(); expressionResult = evaluateExpression(expression, NO_FIXUP); @@ -1009,7 +1011,6 @@ noteReference(expression, kindOfFixup, location, codeMode) performFixups(fixups) fixupListType *fixups; { - valueType *evaluateExpression(); valueType *valueToPoke; performingFixups = TRUE; diff --git a/semanticMisc.h b/semanticMisc.h index f2d2aec..b40d431 100644 --- a/semanticMisc.h +++ b/semanticMisc.h @@ -13,7 +13,7 @@ bool booleanTest(expressionType *expression); int countArguments(functionDefinitionType *function); int countParameters(operandListType *parameterList); arrayType *allocArray(int size, valueType ***contentsPtr); -valueType *createArray(expresionType *dimension, expressionListType *initializers); +valueType *createArray(expressionType *dimension, expressionListType *initializers); bool decrementable(valueType *value); int expressionListLength(expressionListType *expressionList); int fieldValue(symbolTableEntryType *symbol); diff --git a/statementSemantics.c b/statementSemantics.c index e93cac2..2f6714f 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -30,6 +30,12 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "emitBranch.h" +#include "expressionSemantics.h" +#include "operandStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" +#include "statementSemantics.h" operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; @@ -52,8 +58,6 @@ bool nullStatementFlag = FALSE; assembleBlock(block) blockType *block; { - simpleFixupListType *assembleStatement(); - nullAssemble(block); assembleStatement(block, FALSE, NULL); } @@ -63,8 +67,6 @@ assembleBlockInsideIf(block, ongoingFixupList) blockType *block; simpleFixupListType *ongoingFixupList; { - simpleFixupListType *assembleStatement(); - nullAssembleNULL(block); return(assembleStatement(block, TRUE, ongoingFixupList)); } @@ -98,9 +100,6 @@ assembleMachineInstruction(opcode, operands) valueType *evaluatedOperands[MAX_NUMBER_OF_OPERANDS]; valueType *value; - valueType *evaluateOperand(); - addressType addressValue(); - nullAssemble(opcode); expand(moreText("%s\t", opcode->mnemonic)); for (op=1; operands!=NULL && op<=opcode->maxNumberOfOperands; @@ -193,9 +192,6 @@ assembleAlignStatement(alignStatement) int alignment; bool saveExpansion; - int intValue(); - valueType *evaluateExpression(); - nullAssemble(alignStatement); expansionOff(); alignment = intValue(evaluateExpression(alignStatement, NO_FIXUP)); @@ -229,8 +225,6 @@ assembleAssertStatement(assertStatement) valueType *message; bool saveExpansion; - valueType *evaluateExpression(); - expansionOff(); test = evaluateExpression(assertStatement->condition, NO_FIXUP); expansionOn(); @@ -261,9 +255,6 @@ assembleBlockStatement(blockStatement) valueType *blockIncrement; int blockSize; - valueType *evaluateExpression(); - int intValue(); - blockSize = 0; nullAssemble(blockStatement); expand(moreText("block\t")); @@ -300,8 +291,6 @@ assembleByteStatement(byteStatement) { valueType *byteValue; - valueType *evaluateExpression(); - nullAssemble(byteStatement); expand(moreText("byte\t")); while (byteStatement != NULL) { @@ -331,8 +320,6 @@ assembleConstrainStatement(constrainStatement) addressType endAddress; bool saveExpansion; - valueType *evaluateExpression(); - expansionOff(); constraintValue = evaluateExpression(constrainStatement->constraint, NO_FIXUP); @@ -373,9 +360,6 @@ assembleDbyteStatement(dbyteStatement) { valueType *wordValue; - valueType *evaluateExpression(); - valueType *swabValue(); - nullAssemble(dbyteStatement); expand(moreText("dbyte\t")); while (dbyteStatement != NULL) { @@ -399,10 +383,6 @@ assembleDefineStatement(defineStatement) symbolInContextType *contextToDefine; bool saveExpansion; - valueType *evaluateDefineExpression(); - valueType *newValue(); - symbolTableEntryType *effectiveSymbol(); - nullAssemble(defineStatement); symbolToDefine = effectiveSymbol(defineStatement->theSymbol, &contextToDefine); @@ -442,8 +422,6 @@ assembleDoUntilStatement(doUntilStatement) { valueType topOfLoop; - simpleFixupListType *emitJump(); - nullAssemble(doUntilStatement); topOfLoop = currentLocationCounter; if (doUntilStatement->doUntilCondition == NEVER_COND) @@ -469,8 +447,6 @@ assembleDoWhileStatement(doWhileStatement) { valueType topOfLoop; - simpleFixupListType *emitJump(); - nullAssemble(doWhileStatement); topOfLoop = currentLocationCounter; if (doWhileStatement->doWhileCondition == ALWAYS_COND) @@ -497,9 +473,6 @@ assembleExternStatement(externStatement) symbolInContextType *context; symbolTableEntryType *theSymbol; - symbolInContextType *getBaseContext(); - symbolTableEntryType *effectiveSymbol(); - expand(moreText("extern\t")); while (externStatement != NULL) { theSymbol = effectiveSymbol(externStatement->theSymbol, @@ -539,10 +512,6 @@ assembleFunctionStatement(functionStatement) functionDefinitionType *newFunction; symbolInContextType *context; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); - symbolInContextType *getBaseContext(); - nullAssemble(functionStatement); if (currentEnvironment != &globalEnvironment) { error(FUNCTION_DEFINITION_INSIDE_FUNCTION_ERROR); @@ -595,9 +564,6 @@ assembleIfStatement(ifStatement, terminalIf, ongoingFixupList) valueType fixupLocation1[COMPOUND_BRANCH_MAX]; simpleFixupListType *fixupLocation2; - simpleFixupListType *emitJump(); - void assembleIfStatementOldStyle(); - if (backwardsCompatibleIfFlag) { assembleIfStatementOldStyle(ifStatement); return(NULL); @@ -649,8 +615,6 @@ assembleIfStatementOldStyle(ifStatement) valueType fixupLocation1[COMPOUND_BRANCH_MAX]; simpleFixupListType *fixupLocation2; - simpleFixupListType *emitJump(); - nullAssemble(ifStatement); if (ifStatement->ifCondition != ALWAYS_COND) { emitRelativeBranch(invertConditionCode(ifStatement-> @@ -684,8 +648,6 @@ assembleIncludeStatement(includeStatement) stringType *fileName; valueType *possibleFileName; bool saveExpansion; - valueType *evaluateExpression(); - stringType *saveString(); expansionOff(); possibleFileName = evaluateExpression(includeStatement, NO_FIXUP); @@ -727,7 +689,7 @@ assembleInstructionStatement(instructionStatement, cumulativeLineNumber) default: botch("bad instruction type=%d\n", instructionStatement-> - kindOfInstruction); + kindOfInstruction, 0, 0); break; } } @@ -738,8 +700,6 @@ assembleLongStatement(longStatement) { valueType *longValue; - valueType *evaluateExpression(); - nullAssemble(longStatement); expand(moreText("long\t")); while (longStatement != NULL) { @@ -761,8 +721,6 @@ assembleMacroStatement(macroStatement) { macroTableEntryType *newMacro; - macroTableEntryType *installMacro(); - nullAssemble(macroStatement); if (currentEnvironment != &globalEnvironment) { error(MACRO_DEFINITION_INSIDE_MACRO_ERROR); @@ -785,7 +743,6 @@ assembleMdefineStatement(mdefineStatement) defineStatementBodyType *mdefineStatement; { bool saveExpansion; - valueType *evaluateDefineExpression(); nullAssemble(mdefineStatement); expansionOff(); @@ -879,7 +836,6 @@ assembleMswitchStatement(mswitchStatement) expressionListType *tagExpressionList; valueType *tagValue; bool saveExpansion; - valueType *evaluateExpression(); expansionOff(); switchValue = evaluateExpression(mswitchStatement->switchExpression, @@ -939,9 +895,6 @@ assembleMvariableStatement(mvariableStatement) int initCount; bool saveExpansion; - valueType *createArray(); - int expressionListLength(); - nullAssemble(mvariableStatement); expansionOff(); if (mvariableStatement->theDimension == NULL) { @@ -990,7 +943,6 @@ assembleOrgStatement(orgStatement) { valueType *orgAddress; bool saveExpansion; - valueType *evaluateExpression(); nullAssemble(orgStatement); targetOffset = 0; @@ -1018,8 +970,6 @@ assembleOrgStatement(orgStatement) assemblePerformStatement(performStatement) performStatementBodyType *performStatement; { - void evaluateExpressionStandalone(); - nullAssemble(performStatement); sideEffectFlag = FALSE; evaluateExpressionStandalone(performStatement); @@ -1045,10 +995,6 @@ assembleRelStatement(relStatement) assembleStartStatement(startStatement) startStatementBodyType *startStatement; { - valueType *evaluateExpression(); - addressType addressValue(); - expressionType *generateFixupExpression(); - nullAssemble(startStatement); expand(moreText("start\t")); if (haveUserStartAddress) { @@ -1079,8 +1025,6 @@ assembleStringStatement(stringStatement) { valueType *byteValue; - valueType *evaluateExpression(); - nullAssemble(stringStatement); expand(moreText("string\t")); while (stringStatement != NULL) { @@ -1118,7 +1062,6 @@ assembleTargetStatement(targetStatement) { valueType *targetAddress; bool saveExpansion; - valueType *evaluateExpression(); nullAssemble(targetStatement); targetOffset = 0; @@ -1141,8 +1084,6 @@ assembleTargetStatement(targetStatement) assembleUndefineStatement(undefineStatement) undefineStatementBodyType *undefineStatement; { - symbolTableEntryType *effectiveSymbol(); - expand(moreText("undefine\t")); while (undefineStatement != NULL) { expand(moreText("%s", symbName(undefineStatement->theSymbol))); @@ -1162,10 +1103,6 @@ assembleVariableStatement(variableStatement) symbolInContextType *contextForVariable; int initCount; - symbolTableEntryType *effectiveSymbol(); - valueType *createArray(); - int expressionListLength(); - nullAssemble(variableStatement); newVariable = effectiveSymbol(variableStatement->theSymbol, &contextForVariable); @@ -1243,8 +1180,6 @@ assembleWordStatement(wordStatement) { valueType *word; - valueType *evaluateExpression(); - nullAssemble(wordStatement); expand(moreText("word\t")); while (wordStatement != NULL) { @@ -1468,7 +1403,7 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, break; default: - botch("assembleStatementBody doesn't know kind %d\n", kind); + botch("assembleStatementBody doesn't know kind %d\n", kind, 0, 0); break; } /* return(result);*/ @@ -1479,8 +1414,6 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, assembleLabelList(labelList) labelListType *labelList; { - valueType *newValue(); - while (labelList != NULL) { if (structNestingDepth == 0) valueLabel(labelList->theLabel, diff --git a/statementSemantics.h b/statementSemantics.h new file mode 100644 index 0000000..423c8fd --- /dev/null +++ b/statementSemantics.h @@ -0,0 +1,54 @@ +#ifndef STATEMENT_SEMANTICS_H_ +#define STATEMENT_SEMANTICS_H_ + +#include "macrossTypes.h" + +void assembleBlock(blockType *block); +simpleFixupListType *assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList); +bool operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType *evaluatedOperands[]); +void assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands); +void assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands); +void assembleAlignStatement(alignStatementBodyType *alignStatement); +void assembleAssertStatement(assertStatementBodyType *assertStatement); +void assembleBlockStatement(blockStatementBodyType *blockStatement); +void assembleByteStatement(byteStatementBodyType *byeStatement); +void assembleConstrainStatement(constrainStatementBodyType *constrainStatement); +void assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement); +void assembleDefineStatement(defineStatementBodyType *defineStatement); +void assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement); +void assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement); +void assembleExternStatement(externStatementBodyType *externStatement); +void assembleFReturnStatement(freturnStatementBodyType *freturnStatement); +void assembleFunctionStatement(functionStatementBodyType *functionStatement); +void assembleGroupStatement(blockType *groupStatement); +simpleFixupListType *assembleIfStatement(ifStatementBodyType *ifStatement, bool terminalIf, simpleFixupListType *ongoingFixupList); +void assembleIfStatementOldStyle(ifStatementBodyType *ifStatement); +void assembleIncludeStatement(includeStatementBodyType *includeStatement); +void assembleInstructionStatement(instructionStatementBodyType *Statement, int cumulativeLineNumber); +void assembleLongStatement(longStatementBodyType *longStatement); +void assembleMacroStatement(macroStatementBodyType *macroStatement); +void assembleMdefineStatement(defineStatementBodyType *mdefineStatement); +void assembleMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); +void assembleMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); +void assembleMforStatement(mforStatementBodyType *mforStatement); +void assembleMifStatement(mifStatementBodyType *mifStatement, int cumulativeLineNumber); +void assembleMswitchStatement(mswitchStatementBodyType *mswitchStatement); +void assembleMvariableStatement(mvariableStatementBodyType *mvariableStatement); +void assembleMwhileStatement(mwhileStatementBodyType *mwhileStatement); +void assembleOrgStatement(orgStatementBodyType *orgStatement); +void assemblePerformStatement(performStatementBodyType *performStatement); +void assembleRelStatement(relStatementBodyType *relStatement); +void assembleStartStatement(startStatementBodyType *startStatement); +void assembleStringStatement(stringStatementBodyType *stringStatement); +void assembleStructStatement(structStatementBodyType *structStatement); +void assembleTargetStatement(targetStatementBodyType *targetStatement); +void assembleUndefineStatement(undefineStatementBodyType *undefineStatement); +void assembleVariableStatement(variableStatementBodyType *variableStatement); +void assembleWhileStatement(whileStatementBodyType *whileStatement); +void assembleWordStatement(wordStatementBodyType *wordStatement); +bool assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList); +void assembleLabelList(labelListType *labelList); +simpleFixupListType *assembleStatement(statementType *statement, bool insideIf, simpleFixupListType *ongoingFixupList); +void eatStatement(statementType *statement); + +#endif From 6e13fae5a533bc811e7fbdc5f9a103a8cb1eb36a Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 03:51:43 -0800 Subject: [PATCH 04/41] Remove circular dependency --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52ba3a7..3c9d3c0 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ move: .mark date >/net/kessel/u0/chip/macross/prof/.mark date >opt/.mark -macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ +macrossTypes.h: operandDefs_$(PROC).h operandBody_$(PROC).h\ conditionDefs_$(PROC).h actions.o: actions_$(PROC).c $(HEADERS) From 0c3b134ab9791bc40355ca6e4e110e66a0df4a30 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 04:04:14 -0800 Subject: [PATCH 05/41] Update source-to-header dependencies --- Makefile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 3c9d3c0..d86f63f 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,9 @@ lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ -conditionDefs_$(PROC).h driver.c slinkyExpressions.h +conditionDefs_$(PROC).h driver.c slinkyExpressions.h\ +operandStuff.h statementSemantics.h listing.h parserMisc.h\ +emitBranch.h semanticMisc.h expressionSemantics.h HEADERS = macrossTypes.h macrossGlobals.h @@ -90,7 +92,7 @@ buildStuff2.o: buildStuff2.c $(HEADERS) buildStuff3.o: buildStuff3.c $(HEADERS) -builtInFunctions.o: builtInFunctions.c $(HEADERS) +builtInFunctions.o: builtInFunctions.c $(HEADERS) expressionSemantics.h operandStuff.h semanticMisc.h builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c @@ -109,11 +111,11 @@ emitBranch.o: emitBranch_$(PROC).c $(HEADERS) emitStuff.o: emitStuff.c $(HEADERS) cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) emitStuff.c -encode.o: encode.c $(HEADERS) +encode.o: encode.c $(HEADERS) y.tab.h semanticMisc.h slinkyExpressions.h errorStuff.o: errorStuff.c $(HEADERS) -expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) +expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) expressionSemantics.h semanticMisc.h fixups.o: fixups.c $(HEADERS) @@ -121,9 +123,9 @@ garbage.o: garbage.c y.tab.h $(HEADERS) initialize.o: initialize.c $(HEADERS) -lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) +lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) parserMisc.h -listing.o: listing.c $(HEADERS) +listing.o: listing.c $(HEADERS) listing.h lookups.o: lookups.c $(HEADERS) @@ -141,11 +143,11 @@ operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c mv operandStuffSD_$(PROC).o operandStuffSD.o -parserMisc.o: parserMisc.c y.tab.h $(HEADERS) +parserMisc.o: parserMisc.c y.tab.h $(HEADERS) parserMisc.h -semanticMisc.o: semanticMisc.c $(HEADERS) +semanticMisc.o: semanticMisc.c $(HEADERS) semanticMisc.h expressionSemantics.h -statementSemantics.o: statementSemantics.c $(HEADERS) +statementSemantics.o: statementSemantics.c $(HEADERS) emitBranch.h expressionSemantics.h operandStuff.h parserMisc.h semanticMisc.h statementSemantics.h structSemantics.o: structSemantics.c $(HEADERS) From 7fb5312423fe68425fd62ababa06608597077532 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 15:41:05 +0100 Subject: [PATCH 06/41] Use extern keyword in declarations of arrays with unspecified size --- macrossGlobals.h | 20 ++++++++++---------- slinky/slinkyGlobals.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/macrossGlobals.h b/macrossGlobals.h index 1b4166b..21ce1c1 100644 --- a/macrossGlobals.h +++ b/macrossGlobals.h @@ -76,9 +76,9 @@ int nextEnvironmentNumber; int nextLabelTagNumber; FILE *objectFileOutput; char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; -char pass2IndexFileName[]; -char pass2SourceFileName[]; -char pass2MacroExpansionFileName[]; +extern char pass2IndexFileName[]; +extern char pass2SourceFileName[]; +extern char pass2MacroExpansionFileName[]; expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; bool performingFixups; bool positionIndependentCodeMode; @@ -111,14 +111,14 @@ int (*lexDispatchTable[128])(); #define HASH_TABLE_SIZE 512 #define HASH_TABLE_MASK 0x1FF -struct { +extern struct { stringType *functionName; valueType *(*functionEntry)(); bool isSpecialFunction; int ordinal; } builtInFunctionTable[]; -struct { +extern struct { stringType *symbolName; int symbolValue; } predefinedSymbolTable[]; @@ -127,21 +127,21 @@ macroTableEntryType *macroTable[HASH_TABLE_SIZE]; opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; -opcodeTableEntryType theOpcodes[]; +extern opcodeTableEntryType theOpcodes[]; keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; -keywordTableEntryType theKeywords[]; +extern keywordTableEntryType theKeywords[]; conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; -conditionTableEntryType theConditions[]; +extern conditionTableEntryType theConditions[]; symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; -int operandClassTable[]; +extern int operandClassTable[]; -void (*instructionActionTable[])(); +extern void (*instructionActionTable[])(); int validSymbolValues[NUM_OF_SYM_USAGES]; diff --git a/slinky/slinkyGlobals.h b/slinky/slinkyGlobals.h index 7968834..a85bbf0 100644 --- a/slinky/slinkyGlobals.h +++ b/slinky/slinkyGlobals.h @@ -63,7 +63,7 @@ bindingListType *localBindings; segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; #define regionOf(addr) (addr / CODE_REGION_SIZE) -struct { +extern struct { stringType *functionName; addressType (*functionEntry)(); } builtInFunctionTable[]; From ff868a98cb2427c9fb9fd1ad8dbb3bc62a56aca8 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 15:45:36 +0100 Subject: [PATCH 07/41] Use standard malloc --- Makefile | 6 ++---- macrossTypes.h | 1 + slinky/slinkyTypes.h | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d86f63f..b215580 100644 --- a/Makefile +++ b/Makefile @@ -8,14 +8,14 @@ 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\ -malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.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\ -lookups.c macrossTables_$(PROC).c main.c malloc.c object.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\ macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ @@ -133,8 +133,6 @@ macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c mv macrossTables_$(PROC).o macrossTables.o -malloc.o: malloc.c - main.o: main.c $(HEADERS) object.o: object.c $(HEADERS) diff --git a/macrossTypes.h b/macrossTypes.h index d8d5faa..22a85cf 100644 --- a/macrossTypes.h +++ b/macrossTypes.h @@ -31,6 +31,7 @@ #ifndef MACROSS_TYPES_H_ #define MACROSS_TYPES_H_ +#include #include /* diff --git a/slinky/slinkyTypes.h b/slinky/slinkyTypes.h index 2d8761d..2f41f51 100644 --- a/slinky/slinkyTypes.h +++ b/slinky/slinkyTypes.h @@ -27,6 +27,7 @@ 8-March-1985 */ +#include #include typedef unsigned char byte; From dfaf0498596f559256903f489571dbb3fc9d7d7a Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 15:48:25 +0100 Subject: [PATCH 08/41] Include instead of --- builtInFunctions.c | 2 +- slinky/builtins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtInFunctions.c b/builtInFunctions.c index c230cde..bc24f92 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -34,7 +34,7 @@ #include "operandStuff.h" #include "semanticMisc.h" -#include +#include /* diff --git a/slinky/builtins.c b/slinky/builtins.c index c44a7bc..38b22a5 100644 --- a/slinky/builtins.c +++ b/slinky/builtins.c @@ -30,7 +30,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" -#include +#include #define getSymbol() ((symbolType *)getNumber()) From 8e5376efd9204392eff8d3f5b7031b010af8b788 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 15:53:00 +0100 Subject: [PATCH 09/41] Add missing includes --- expressionSemantics.c | 2 ++ initialize.c | 2 ++ listing.c | 2 ++ object.c | 2 ++ parserMisc.c | 2 ++ semanticMisc.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/expressionSemantics.c b/expressionSemantics.c index 0a640db..201a0df 100644 --- a/expressionSemantics.c +++ b/expressionSemantics.c @@ -34,6 +34,8 @@ #include "expressionSemantics.h" #include "semanticMisc.h" +#include + operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; symbolTableEntryType *dbSymbol; diff --git a/initialize.c b/initialize.c index 3a4aa98..e7deac7 100644 --- a/initialize.c +++ b/initialize.c @@ -30,6 +30,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include + #define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) extern int yydebug; diff --git a/listing.c b/listing.c index 548922a..2395e27 100644 --- a/listing.c +++ b/listing.c @@ -31,6 +31,8 @@ #include "macrossGlobals.h" #include "listing.h" +#include + static char lineBuffer1[LINE_BUFFER_SIZE]; static char lineBuffer2[LINE_BUFFER_SIZE]; int cumulativeLineNumber = 0; diff --git a/object.c b/object.c index 30d4a85..02e5338 100644 --- a/object.c +++ b/object.c @@ -30,6 +30,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include + static int symbolTableSize; static int symbolTableStringSize; bool encodingFunction; diff --git a/parserMisc.c b/parserMisc.c index 5f96c2b..51982a4 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -34,6 +34,8 @@ #include "y.tab.h" #include "parserMisc.h" +#include + statementType * addLabelToStatement(labelList, statement) labelListType *labelList; diff --git a/semanticMisc.c b/semanticMisc.c index a2f0203..885ef6b 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -35,6 +35,8 @@ #include "semanticMisc.h" #include "expressionSemantics.h" +#include + #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOn() expandMacros=saveExpansion; From e8b97b38d73d792cb0ecb739ace6ff38c490354f Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 16:35:02 +0100 Subject: [PATCH 10/41] assembleStatement: fix use-after-free --- statementSemantics.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/statementSemantics.c b/statementSemantics.c index 2f6714f..1924d44 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -1455,9 +1455,10 @@ assembleStatement(statement, insideIf, ongoingFixupList) statement->statementBody, statement-> cumulativeLineNumber, insideIf && isLastStatementInBlock(statement), &result)) { + statementType *next = statement->nextStatement; if (freeFlag && statementEvaluationDepth == 1) freeStatement(statement); - statement = statement->nextStatement; + statement = next; } else { if (freeFlag && statementEvaluationDepth == 1) freeStatement(statement); From c594490db9f2f1712274bb1357882b184f894db5 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:35:49 +0100 Subject: [PATCH 11/41] Convert macross error-handling functions to varargs --- errorStuff.c | 75 ++++++++++++++++++++++++++-------------------------- parserMisc.c | 12 ++++----- parserMisc.h | 2 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/errorStuff.c b/errorStuff.c index a855027..968fe56 100644 --- a/errorStuff.c +++ b/errorStuff.c @@ -30,6 +30,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include + bool nullStatementFlag; /* puntOnError handles syntax errors and the like encountered during parsing @@ -38,34 +40,28 @@ bool nullStatementFlag; from the booboo. */ void -puntOnError(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +puntOnError(errorType theError, ...) { + va_list ap; char c; - void error(); while ((c = getc(input))!='\n' && c!=EOF) ; ungetc(c, input); - error(theError, arg1, arg2, arg3); + + va_start(ap, theError); + verror(theError, ap); + va_end(ap); } /* printErrorMessage is the general error message handler */ void -printErrorMessage(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +printErrorMessage(errorType theError, va_list ap) { /* This table MUST be maintained congruently with the definition of the enumerated type 'errorType'. */ - void fatalError(); static bool dying = FALSE; static char *errorMessageStrings[] = { @@ -232,7 +228,7 @@ printErrorMessage(theError, arg1, arg2, arg3) lastErrorLine = currentLineNumber; printf("\"%s\", line %d: ", currentFileName, currentLineNumber -1); - printf(errorMessageStrings[(int)theError], arg1, arg2, arg3); + vprintf(errorMessageStrings[(int)theError], ap); printf("\n"); fflush(stdout); } @@ -243,45 +239,48 @@ printErrorMessage(theError, arg1, arg2, arg3) } void -error(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +error(errorType theError, ...) { - printErrorMessage(theError, arg1, arg2, arg3); + va_list ap; + va_start(ap, theError); + printErrorMessage(theError, ap); + va_end(ap); errorFlag = TRUE; } void -warning(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +verror(errorType theError, va_list ap) { - printErrorMessage(theError, arg1, arg2, arg3); + printErrorMessage(theError, ap); + errorFlag = TRUE; } void -fatalError(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +warning(errorType theError, ...) { - printErrorMessage(theError, arg1, arg2, arg3); + va_list ap; + va_start(ap, theError); + printErrorMessage(theError, ap); + va_end(ap); +} + + void +fatalError(errorType theError, ...) +{ + va_list ap; + va_start(ap, theError); + printErrorMessage(theError, ap); + va_end(ap); chokePukeAndDie(); } void -fatalSystemError(theError, arg1, arg2, arg3) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +fatalSystemError(errorType theError, ...) { - printErrorMessage(theError, arg1, arg2, arg3); + va_list ap; + va_start(ap, theError); + printErrorMessage(theError, ap); + va_end(ap); perror("Unix says"); chokePukeAndDie(); } diff --git a/parserMisc.c b/parserMisc.c index 51982a4..5ec73a9 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -34,6 +34,7 @@ #include "y.tab.h" #include "parserMisc.h" +#include #include statementType * @@ -54,14 +55,13 @@ addLabelToStatement(labelList, statement) * function does almost exactly what we want. */ void -botch(message, arg1, arg2, arg3) - char *message; - int arg1; - int arg2; - int arg3; +botch(char *message, ...) { + va_list ap; printf("Macross horrible terrible internal botch: "); - printf(message, arg1, arg2, arg3); + va_start(ap, message); + vprintf(message, ap); + va_end(ap); chokePukeAndDie(); } diff --git a/parserMisc.h b/parserMisc.h index fc08c53..c2ed5d0 100644 --- a/parserMisc.h +++ b/parserMisc.h @@ -3,7 +3,7 @@ #include "macrossTypes.h" statementType *addLabelToSatement(labelListType *labelList, statementType *statement); -void botch(char *message, int arg1, int arg2, int arg3); +void botch(char *message, ...); void checkDefineAssignmentOperator(assignmentKindType assignmentOperator); void convertDefineToMDefine(statementType *defineStatement); ifStatementBodyType *extractIfBody(statementType *ifStatement); From ad1aa82bcd880f3a1cf37b8179261a7fea55ac88 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:38:30 +0100 Subject: [PATCH 12/41] Avoid C++ style comments protoize chokes on them --- garbage.c | 2 +- macrossTypes.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/garbage.c b/garbage.c index 74f0654..2660acb 100644 --- a/garbage.c +++ b/garbage.c @@ -443,7 +443,7 @@ freeMacroStatement(macroStatement) void freeMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; // MIST: shouldn't this be "mdefineStatementBodyType"? + defineStatementBodyType *mdefineStatement; /* MIST: shouldn't this be "mdefineStatementBodyType"? */ { valueType *freeDefineExpression(); diff --git a/macrossTypes.h b/macrossTypes.h index 22a85cf..e145054 100644 --- a/macrossTypes.h +++ b/macrossTypes.h @@ -444,7 +444,7 @@ typedef union expressionTermBodyUnion { valueType *valueUnion; symbolTableEntryType *symbolTableUnion; conditionType conditionTypeUnion; - void *expressionUnion; // this should be expressionTermType, but there's a cycle + void *expressionUnion; /* this should be expressionTermType, but there's a cycle */ } expressionTermBodyType; typedef struct expressionTermStruct { From 0e03424ec1020afef3f7b87b118756ccb5a9732d Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:42:40 +0100 Subject: [PATCH 13/41] moreLabel is always used with one argument --- listing.c | 6 ++---- listing.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/listing.c b/listing.c index 2395e27..874374b 100644 --- a/listing.c +++ b/listing.c @@ -543,13 +543,11 @@ moreText(format, arg1, arg2, arg3) } void -moreLabel(format, arg1, arg2, arg3) +moreLabel(format, arg1) char *format; int arg1; - int arg2; - int arg3; { - sprintf(labelStringPtr, format, arg1, arg2, arg3); + sprintf(labelStringPtr, format, arg1); labelStringPtr = labelString + strlen(labelString); } diff --git a/listing.h b/listing.h index 418ab95..0721910 100644 --- a/listing.h +++ b/listing.h @@ -22,7 +22,7 @@ bool labeledLine(); void addText(char *buffer, char **bufferPtr, char *format, int arg1, int arg2, int arg3); void moreTextOptional(char *buffer, char **bufferPtr, char *format, int arg1, int arg2, int arg3); void moreText(char *format, int arg1, int arg2, int arg3); -void moreLabel(char *format, int arg1, int arg2, int arg3); +void moreLabel(char *format, int arg1); void startLine(); void endLine(); void flushExpressionString(); From 19d7cb724c15151d161923cafaa76d9801437be7 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:48:33 +0100 Subject: [PATCH 14/41] Convert macross listing functions to varargs --- listing.c | 60 +++++++++++++++++++++++++++---------------------------- listing.h | 8 ++++---- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/listing.c b/listing.c index 874374b..983ad96 100644 --- a/listing.c +++ b/listing.c @@ -31,6 +31,7 @@ #include "macrossGlobals.h" #include "listing.h" +#include #include static char lineBuffer1[LINE_BUFFER_SIZE]; @@ -504,42 +505,40 @@ labeledLine() } void -addText(buffer, bufferPtr, format, arg1, arg2, arg3) - char *buffer; - char **bufferPtr; - char *format; - int arg1; - int arg2; - int arg3; +vaddText(char *buffer, char **bufferPtr, char *format, va_list ap) { - sprintf(*bufferPtr, format, arg1, arg2, arg3); - *bufferPtr = buffer + strlen(buffer); + vsprintf(*bufferPtr, format, ap); + *bufferPtr = buffer = strlen(buffer); } void -moreTextOptional(buffer, bufferPtr, format, arg1, arg2, arg3) - char *buffer; - char **bufferPtr; - char *format; - int arg1; - int arg2; - int arg3; +addText(char *buffer, char **bufferPtr, char *format, ...) { + va_list ap; + va_start(ap, format); + vaddText(buffer, bufferPtr, format, ap); + va_end(ap); +} + + void +moreTextOptional(char *buffer, char **bufferPtr, char *format, ...) +{ + va_list ap; + va_start(ap, format); if (buffer == NULL) - addText(expansionString, &expansionStringPtr, format, arg1, - arg2, arg3); + vaddText(expansionString, &expansionStringPtr, format, ap); else - addText(buffer, bufferPtr, format, arg1, arg2, arg3); + vaddText(buffer, bufferPtr, format, ap); + va_end(ap); } void -moreText(format, arg1, arg2, arg3) - char *format; - int arg1; - int arg2; - int arg3; +moreText(char *format, ...) { - addText(expansionString, &expansionStringPtr, format, arg1,arg2,arg3); + va_list ap; + va_start(ap, format); + addText(expansionString, &expansionStringPtr, format, ap); + va_end(ap); } void @@ -634,13 +633,12 @@ expandLabel() } void -moreExpression(format, arg1, arg2, arg3) - char *format; - int arg1; - int arg2; - int arg3; +moreExpression(char *format, ...) { - sprintf(expressionStringPtr, format, arg1, arg2, arg3); + va_list ap; + va_start(ap, format); + vsprintf(expressionStringPtr, format, ap); + va_end(ap); expressionStringPtr = expressionString + strlen(expressionString); } diff --git a/listing.h b/listing.h index 0721910..3e94aa7 100644 --- a/listing.h +++ b/listing.h @@ -19,9 +19,9 @@ void tabPrint(stringType *text); void printNTimes (char aChar, int times); void tabIndent(); bool labeledLine(); -void addText(char *buffer, char **bufferPtr, char *format, int arg1, int arg2, int arg3); -void moreTextOptional(char *buffer, char **bufferPtr, char *format, int arg1, int arg2, int arg3); -void moreText(char *format, int arg1, int arg2, int arg3); +void addText(char *buffer, char **bufferPtr, char *format, ...); +void moreTextOptional(char *buffer, char **bufferPtr, char *format, ...); +void moreText(char *format, ...); void moreLabel(char *format, int arg1); void startLine(); void endLine(); @@ -31,7 +31,7 @@ void expandNum(char *buffer, char **bufferPtr, int n); void flushOperand(int n); void expandOperands(int op); void expandLabel(); -void moreExpression(char *format, int arg1, int arg2, int arg3); +void moreExpression(char *format, ...); void startLineMarked(); bool notListable(statementKindType statementKind); From 230697962070d65dac477e51afdcca1f49a0f5ec Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:52:08 +0100 Subject: [PATCH 15/41] expandExpression takes two arguments --- operandStuffSD_6502.c | 2 +- statementSemantics.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index 68b860f..13c8815 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -248,7 +248,7 @@ expandOperand(addressMode, buffer) case PRE_SELECTED_X_OPND: moreText("@x"); break; default: break; } - expandExpression(NULL); + expandExpression(NULL, NULL); if (addressMode == POST_INDEXED_Y_OPND || addressMode == PRE_INDEXED_X_OPND || addressMode == X_INDEXED_OPND || diff --git a/statementSemantics.c b/statementSemantics.c index 1924d44..b74b394 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -263,7 +263,7 @@ assembleBlockStatement(blockStatement) theExpression, NO_FIXUP); blockSize += intValue(blockIncrement); blockStatement = blockStatement->nextExpression; - expand((expandExpression(NULL), blockStatement!=NULL ? + expand((expandExpression(NULL, NULL), blockStatement!=NULL ? moreText(", ") : 0)); qfree(blockIncrement); } @@ -304,7 +304,7 @@ assembleByteStatement(byteStatement) } qfree(byteValue); byteStatement = byteStatement->nextExpression; - expand((expandExpression(NULL), byteStatement != NULL ? + expand((expandExpression(NULL, NULL), byteStatement != NULL ? moreText(", ") : 0)); } expand(endLine()); @@ -366,7 +366,7 @@ assembleDbyteStatement(dbyteStatement) wordValue = swabValue(evaluateExpression(dbyteStatement-> theExpression, DBYTE_FIXUP)); dbyteStatement = dbyteStatement->nextExpression; - expand((expandExpression(NULL), dbyteStatement != NULL ? + expand((expandExpression(NULL, NULL), dbyteStatement != NULL ? moreText(", ") : 0)); putFixupsHere(DBYTE_FIXUP, 0); emitWordValue(wordValue); @@ -402,7 +402,7 @@ assembleDefineStatement(defineStatement) evaluateDefineExpression( defineStatement->theValue); contextToDefine->usage = DEFINE_SYMBOL; - expand(expandExpression(NULL)); + expand(expandExpression(NULL, NULL)); } else contextToDefine->value = newValue(FAIL, 0, EXPRESSION_OPND); @@ -706,7 +706,7 @@ assembleLongStatement(longStatement) longValue = evaluateExpression(longStatement->theExpression, LONG_FIXUP); longStatement = longStatement->nextExpression; - expand((expandExpression(NULL), longStatement != NULL ? + expand((expandExpression(NULL, NULL), longStatement != NULL ? moreText(", ") : 0)); putFixupsHere(LONG_FIXUP, 0); emitLongValue(longValue); @@ -1012,7 +1012,7 @@ assembleStartStatement(startStatement) expand((moreText("*fail*"), endLine())); error(BAD_START_ADDRESS_ERROR); } else { - expand((expandExpression(NULL), endLine())); + expand((expandExpression(NULL, NULL), endLine())); haveUserStartAddress = TRUE; fixupStartAddress = FALSE; } @@ -1039,7 +1039,7 @@ assembleStringStatement(stringStatement) } qfree(byteValue); stringStatement = stringStatement->nextExpression; - expand((expandExpression(NULL), stringStatement != NULL ? + expand((expandExpression(NULL, NULL), stringStatement != NULL ? moreText(", ") : 0)); } expand(endLine()); @@ -1121,7 +1121,7 @@ assembleVariableStatement(variableStatement) theValue)) == 1) { contextForVariable->value = evaluateExpression( variableStatement->theValue->theExpression, NO_FIXUP); - expand(expandExpression(NULL)); + expand(expandExpression(NULL, NULL)); } else { if (initCount > 1) error(TOO_MANY_VARIABLE_INITIALIZERS_ERROR); @@ -1186,7 +1186,7 @@ assembleWordStatement(wordStatement) word = evaluateExpression(wordStatement->theExpression, WORD_FIXUP); wordStatement = wordStatement->nextExpression; - expand((expandExpression(NULL), wordStatement != NULL ? + expand((expandExpression(NULL, NULL), wordStatement != NULL ? moreText(", ") : 0)); putFixupsHere(WORD_FIXUP, 0); emitWordValue(word); From 086027b1b50a34d4df48a83ba85e52af038a0a2e Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 18:11:23 +0100 Subject: [PATCH 16/41] XXX Missing parameter in call to assembleStatementBody assembleStatementBody has five parameters: assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, ifFixupList) statementKindType kind; statementBodyType body; int cumulativeLineNumber; bool worryAboutIf; simpleFixupListType **ifFixupList; but here it is called with only four. The third parameter is missing. I randomly inserted a 0. --- structSemantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structSemantics.c b/structSemantics.c index 3c8badb..e1fb67a 100644 --- a/structSemantics.c +++ b/structSemantics.c @@ -128,7 +128,7 @@ assembleStructDefinitionBody(structBody) expand(listableStatement(structBody->kindOfStatement) ? (expandLabel(), tabIndent()) : 0); assembleStatementBody(structBody->kindOfStatement, - structBody->statementBody, FALSE, &dummy); + structBody->statementBody, 0 /* random guess */, FALSE, &dummy); if (currentFieldOffset > MAXIMUM_ALLOWED_STRUCT_SIZE) { error(STRUCT_TOO_BIG_ERROR); return(NULL); From c968f1bed4742a5af607f3ebd057e020199bd329 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 18:24:14 +0100 Subject: [PATCH 17/41] evaluateOperand takes only a single argument --- builtInFunsSD_6502.c | 22 +++++++++---------- builtInFunsSD_68000.c | 50 +++++++++++++++++++++---------------------- lookups.c | 4 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/builtInFunsSD_6502.c b/builtInFunsSD_6502.c index f1678e8..9363cfd 100644 --- a/builtInFunsSD_6502.c +++ b/builtInFunsSD_6502.c @@ -53,7 +53,7 @@ isARegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == A_REGISTER_OPND)); } else { @@ -72,7 +72,7 @@ isDirectModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == EXPRESSION_OPND)); } else { @@ -91,7 +91,7 @@ isImmediateModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == IMMEDIATE_OPND)); } else { @@ -110,7 +110,7 @@ isIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == X_INDEXED_OPND || evaluatedParameter->addressMode == Y_INDEXED_OPND || evaluatedParameter->addressMode == @@ -132,7 +132,7 @@ isIndirectModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == INDIRECT_OPND)); } else { @@ -151,7 +151,7 @@ isPostIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == POST_INDEXED_Y_OPND)); } else { @@ -170,7 +170,7 @@ isPreIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == PRE_INDEXED_X_OPND || evaluatedParameter-> addressMode == PRE_SELECTED_X_OPND)); @@ -190,7 +190,7 @@ isXIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == X_INDEXED_OPND || evaluatedParameter->addressMode == X_SELECTED_OPND)); @@ -210,7 +210,7 @@ isXRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == X_REGISTER_OPND)); } else { @@ -229,7 +229,7 @@ isYIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == Y_INDEXED_OPND || evaluatedParameter->addressMode == Y_SELECTED_OPND)); @@ -249,7 +249,7 @@ isYRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == Y_REGISTER_OPND)); } else { diff --git a/builtInFunsSD_68000.c b/builtInFunsSD_68000.c index 3e8f072..dd4be1c 100644 --- a/builtInFunsSD_68000.c +++ b/builtInFunsSD_68000.c @@ -53,7 +53,7 @@ getAddressRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(getAddressRegister( evaluatedParameter->addressMode))); } else { @@ -72,7 +72,7 @@ getDataRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(getDataRegister(evaluatedParameter-> addressMode))); } else { @@ -91,7 +91,7 @@ getIndexRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(getIndexRegister(evaluatedParameter-> addressMode))); } else { @@ -110,7 +110,7 @@ getRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(getRegister(evaluatedParameter-> addressMode))); } else { @@ -129,7 +129,7 @@ getWLBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(getWL(evaluatedParameter-> addressMode))); } else { @@ -148,7 +148,7 @@ isAbsoluteModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == ABSOLUTE_SHORT_OPND || operandKindField(evaluatedParameter->addressMode) == @@ -169,7 +169,7 @@ isAbsoluteLongModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == ABSOLUTE_LONG_OPND)); } else { @@ -188,7 +188,7 @@ isAbsoluteShortModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == ABSOLUTE_SHORT_OPND)); } else { @@ -207,7 +207,7 @@ isARegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == A_REGISTER_OPND)); } else { @@ -226,7 +226,7 @@ isCCRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == CC_REGISTER_OPND)); } else { @@ -245,7 +245,7 @@ isControlRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == CONTROL_REGISTER_OPND)); } else { @@ -264,7 +264,7 @@ isDRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == D_REGISTER_OPND)); } else { @@ -283,7 +283,7 @@ isDFCRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == CONTROL_REGISTER_OPND && getRegister(evaluatedParameter->addressMode) == @@ -304,7 +304,7 @@ isDisplacementModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == DISPLACEMENT_OPND)); } else { @@ -323,7 +323,7 @@ isImmediateModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == IMMEDIATE_OPND)); } else { @@ -342,7 +342,7 @@ isIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == INDEXED_OPND)); } else { @@ -361,7 +361,7 @@ isIndirectModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == A_REGISTER_INDIRECT_OPND)); } else { @@ -380,7 +380,7 @@ isPCDisplacementModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == PC_DISPLACEMENT_OPND)); } else { @@ -399,7 +399,7 @@ isPCIndexedModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == PC_INDEXED_OPND)); } else { @@ -418,7 +418,7 @@ isPostincrementModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == POSTINCREMENT_OPND)); } else { @@ -437,7 +437,7 @@ isPredecrementModeBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == PREDECREMENT_OPND)); } else { @@ -456,7 +456,7 @@ isSFCRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == CONTROL_REGISTER_OPND && getRegister(evaluatedParameter->addressMode) == @@ -477,7 +477,7 @@ isStatusRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == STATUS_REGISTER_OPND)); } else { @@ -496,7 +496,7 @@ isUSPBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == USP_REGISTER_OPND)); } else { @@ -515,7 +515,7 @@ isVBRegisterBIF(parameterList, kindOfFixup) valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(operandKindField(evaluatedParameter-> addressMode) == CONTROL_REGISTER_OPND && getRegister(evaluatedParameter->addressMode) == diff --git a/lookups.c b/lookups.c index b2bfe07..216dd83 100644 --- a/lookups.c +++ b/lookups.c @@ -444,7 +444,7 @@ bindFunctionArguments(argumentList, parameterList, functionName) nextArgument!=NULL) && parameterList!=NULL) { saveEnvironment = currentEnvironment; currentEnvironment = currentEnvironment->previousEnvironment; - argument = evaluateOperand(parameterList, NO_FIXUP); + argument = evaluateOperand(parameterList); currentEnvironment = saveEnvironment; if (firstArgument == NULL) firstArgument = argument; @@ -495,7 +495,7 @@ bindFunctionArguments(argumentList, parameterList, functionName) saveEnvironment = currentEnvironment; currentEnvironment = currentEnvironment-> previousEnvironment; - argument = evaluateOperand(parameterList, NO_FIXUP); + argument = evaluateOperand(parameterList); currentEnvironment = saveEnvironment; if (firstArgument == NULL) firstArgument = argument; From 9123e36a38ad3742e7c1be02f6e13fdcfa5d9424 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 18:34:23 +0100 Subject: [PATCH 18/41] printExpression: select the right field of the union for CONDITION_CODE_EXPR The other branches are good. --- debugPrint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugPrint.c b/debugPrint.c index 01db367..1d9ebaa 100644 --- a/debugPrint.c +++ b/debugPrint.c @@ -424,7 +424,7 @@ printExpression(expression) break; case CONDITION_CODE_EXPR: - printCondition(expression->expressionTerm); + printCondition(expression->expressionTerm.conditionTypeUnion); break; case FUNCTION_CALL_EXPR: From 606dfd1650283de0c6673910203a66dc2aa692e3 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 18:47:57 +0100 Subject: [PATCH 19/41] addLabelToStatement: correctly create a dummy statementBodyType --- parserMisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parserMisc.c b/parserMisc.c index 5ec73a9..c8cfa71 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -45,7 +45,7 @@ addLabelToStatement(labelList, statement) statementType *newStatement(); if (statement == NULL) - statement = newStatement(NULL_STATEMENT, NULL); + statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); statement->labels = labelList; return(statement); } From 9124a65c9845357f07ca9dd93e36c72165c2089b Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 19:12:10 +0100 Subject: [PATCH 20/41] buildMdoStatement: seems to have wrong argument type --- buildStuff1.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buildStuff1.c b/buildStuff1.c index 5c9bdc3..695bffc 100644 --- a/buildStuff1.c +++ b/buildStuff1.c @@ -355,16 +355,16 @@ buildMdoWhileStatement(body, condition) statementType * buildMdoStatement(body, end) blockType *body; - doEndType *end; + mdoEndType *end; { statementType *result; - if (end->doEndKind == UNTIL_END) - result = buildMdoUntilStatement(body, end->doEndCondition); - else if (end->doEndKind == WHILE_END) - result = buildMdoWhileStatement(body, end->doEndCondition); + if (end->mdoEndKind == UNTIL_END) + result = buildMdoUntilStatement(body, end->mdoEndCondition); + else if (end->mdoEndKind == WHILE_END) + result = buildMdoWhileStatement(body, end->mdoEndCondition); else - botch("bad mdo-end kind: %d\n", end->doEndCondition); + botch("bad mdo-end kind: %d\n", end->mdoEndCondition); qfree(end); return(result); } From 773dba638dd904ee6c9a4e1425e3baaf581badd8 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 19:13:43 +0100 Subject: [PATCH 21/41] XXX missing argument for buildIdentifierList buildIdentifierList takes three arguments. All other call sites use unknownSymbolTag, do that here as well (just a guess). --- buildStuff3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildStuff3.c b/buildStuff3.c index ef81ec9..3816934 100644 --- a/buildStuff3.c +++ b/buildStuff3.c @@ -217,7 +217,7 @@ buildSelectionList(new, rest) selectionListType *new; selectionListHeadType *rest; { - return((selectionListHeadType *) buildIdentifierList(new, rest)); + return((selectionListHeadType *) buildIdentifierList(new, rest, unknownSymbolTag /* random guess */)); } statementListHeadType * From b9748cbe0e8343a327e4155262fa3db8f312db53 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 19:16:21 +0100 Subject: [PATCH 22/41] Use the right member of union arguments so that everything typechecks --- builtInFunctions.c | 4 ++-- debugPrintSD_6502.c | 24 ++++++++++++------------ encode.c | 8 ++++---- operandStuffSD_6502.c | 20 ++++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/builtInFunctions.c b/builtInFunctions.c index bc24f92..da15088 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -948,9 +948,9 @@ symbolDefineBIF(parameterList, kindOfFixup) return(makeFailureValue()); } else { syntheticDefineStatement = buildDefineStatement(stringValue-> - value, parameterList->theOperand); + value, parameterList->theOperand.expressionUnion); } - assembleDefineStatement(syntheticDefineStatement->statementBody); + assembleDefineStatement(syntheticDefineStatement->statementBody.defineUnion); freeStatement(syntheticDefineStatement); return(makeBooleanValue(TRUE)); } diff --git a/debugPrintSD_6502.c b/debugPrintSD_6502.c index c4da64d..d6b8cd1 100644 --- a/debugPrintSD_6502.c +++ b/debugPrintSD_6502.c @@ -204,15 +204,15 @@ printOperand(operand) switch (operand->kindOfOperand) { case EXPRESSION_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.expressionUnion); break; case IMMEDIATE_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.immediateUnion); break; case INDIRECT_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.indirectUnion); break; case A_REGISTER_OPND: @@ -225,39 +225,39 @@ printOperand(operand) break; case POST_INDEXED_Y_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.postIndexedYUnion); break; case PRE_INDEXED_X_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.preIndexedXUnion); break; case X_INDEXED_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.xIndexedUnion); break; case Y_INDEXED_OPND: - printExpression(operand->theOperand); + printExpression(operand->theOperand.yIndexedUnion); break; case X_SELECTED_OPND: - printIdentifierList(operand->theOperand); + printIdentifierList(operand->theOperand.xSelectedUnion); break; case Y_SELECTED_OPND: - printIdentifierList(operand->theOperand); + printIdentifierList(operand->theOperand.ySelectedUnion); break; case PRE_SELECTED_X_OPND: - printIdentifierList(operand->theOperand); + printIdentifierList(operand->theOperand.preSelectedUnion); break; case STRING_OPND: - tab(); printf("(string: \"%s\")\n", operand->theOperand); + tab(); printf("(string: \"%s\")\n", operand->theOperand.stringUnion); break; case BLOCK_OPND: - printBlock(operand->theOperand); + printBlock(operand->theOperand.blockUnion); break; default: diff --git a/encode.c b/encode.c index 6776dbe..06df4cf 100644 --- a/encode.c +++ b/encode.c @@ -279,7 +279,7 @@ encodeOperand(operand) case PRE_INDEXED_X_OPND: case X_INDEXED_OPND: case Y_INDEXED_OPND: - return(encodeExpression(operand->theOperand)); + return(encodeExpression(operand->theOperand.expressionUnion)); case A_REGISTER_OPND: case X_REGISTER_OPND: @@ -294,7 +294,7 @@ encodeOperand(operand) return(FALSE); case STRING_OPND: - return(encodeString(operand->theOperand)); + return(encodeString(operand->theOperand.stringUnion)); case BLOCK_OPND: error(BLOCK_OPERAND_IN_OBJECT_EXPRESSION_ERROR); @@ -534,7 +534,7 @@ encodeMifStatement(mifStatement) encodeByte(MIF_TAG) && encodeExpression(mifStatement->mifCondition) && encodeBlock(mifStatement->mifConsequence) && - encodeBlock(mifStatement->mifContinuation) + encodeBlock(mifStatement->mifContinuation.mifBlockUnion) ); } @@ -637,7 +637,7 @@ encodeStatement(statement) return(encodeFreturnStatement(statement->statementBody.freturnUnion)); case GROUP_STATEMENT: - return(encodeBlock(statement->statementBody)); + return(encodeBlock(statement->statementBody.groupUnion)); case MDEFINE_STATEMENT: return(encodeMdefineStatement(statement->statementBody.defineUnion)); diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index 13c8815..8f204dc 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -151,14 +151,14 @@ duplicateOperandForFixup(operand, isSpecialFunctionOperand) case X_INDEXED_OPND: case Y_INDEXED_OPND: result->theOperand.expressionUnion = - duplicateExpressionForFixup(operand->theOperand, + duplicateExpressionForFixup(operand->theOperand.expressionUnion, FALSE, isSpecialFunctionOperand); break; case X_SELECTED_OPND: case Y_SELECTED_OPND: case PRE_SELECTED_X_OPND: result->theOperand.expressionUnion = - duplicateExpressionForFixup(operand->theOperand, + duplicateExpressionForFixup(operand->theOperand.xSelectedUnion, FALSE, isSpecialFunctionOperand); break; case A_REGISTER_OPND: @@ -195,7 +195,7 @@ freeOperand(operand) case PRE_INDEXED_X_OPND: case X_INDEXED_OPND: case Y_INDEXED_OPND: - freeExpression(operand->theOperand); + freeExpression(operand->theOperand.expressionUnion); break; case A_REGISTER_OPND: @@ -206,15 +206,15 @@ freeOperand(operand) case X_SELECTED_OPND: case Y_SELECTED_OPND: case PRE_SELECTED_X_OPND: - freeSelectionList(operand->theOperand); + freeSelectionList(operand->theOperand.xSelectedUnion); break; case STRING_OPND: - freeString(operand->theOperand); + freeString(operand->theOperand.stringUnion); break; case BLOCK_OPND: - freeBlock(operand->theOperand); + freeBlock(operand->theOperand.blockUnion); break; default: @@ -302,7 +302,7 @@ evaluateOperand(operand) case PRE_INDEXED_X_OPND: case X_INDEXED_OPND: case Y_INDEXED_OPND: - result = evaluateExpression(operand->theOperand, + result = evaluateExpression(operand->theOperand.expressionUnion, performingFixups ? NO_FIXUP : OPERAND_FIXUP); if (operand->kindOfOperand != EXPRESSION_OPND) { if (result->addressMode != EXPRESSION_OPND) { @@ -324,7 +324,7 @@ evaluateOperand(operand) case X_SELECTED_OPND: case Y_SELECTED_OPND: case PRE_SELECTED_X_OPND: - result = evaluateSelectionList(operand->theOperand); + result = evaluateSelectionList(operand->theOperand.xSelectedUnion); if (result->addressMode != EXPRESSION_OPND) { error(BAD_ADDRESS_MODE_ERROR); result->kindOfValue = FAIL; @@ -334,7 +334,7 @@ evaluateOperand(operand) break; case STRING_OPND: - result = newValue(STRING_VALUE, operand->theOperand, + result = newValue(STRING_VALUE, operand->theOperand.stringUnion, STRING_OPND); break; @@ -342,7 +342,7 @@ evaluateOperand(operand) if (standaloneExpansionFlag) forceExpansion(); sideEffectFlag = TRUE; - assembleBlock(operand->theOperand); + assembleBlock(operand->theOperand.blockUnion); expansionOn(); result = newValue(FAIL, 0, BLOCK_OPND); break; From e10a35e3e1e35862705b12a04c39af827f4e8583 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 19:18:42 +0100 Subject: [PATCH 23/41] Protoize command: protoize -c '-m32 -DTARGET_CPU=CPU_6502' -g $(ls *.c | grep -v 68) --- actions_6502.c | 107 ++++++------------ buildStuff1.c | 164 +++++++++------------------- buildStuff2.c | 90 +++++---------- buildStuff3.c | 38 ++----- builtInFunctions.c | 195 +++++++++++---------------------- builtInFunsSD_6502.c | 78 +++++-------- debugPrint.c | 232 ++++++++++++++------------------------- debugPrintSD_6502.c | 20 ++-- driver.c | 3 +- emitBranch_6502.c | 21 ++-- emitStuff.c | 83 ++++++-------- encode.c | 105 ++++++++---------- errorStuff.c | 19 ++-- expressionSemantics.c | 97 ++++++++--------- expressionSemantics.h | 2 +- fixups.c | 52 ++++----- garbage.c | 199 ++++++++++++---------------------- initialize.c | 72 ++++++------ lexer.c | 112 ++++++++++--------- listing.c | 87 ++++++--------- listing.h | 20 ++-- lookups.c | 135 ++++++++++------------- macrossTables_6502.c | 122 ++++++++++----------- main.c | 14 ++- malloc.c | 19 +--- object.c | 134 +++++++++++------------ operandStuffSD_6502.c | 45 ++++---- parserMisc.c | 34 +++--- parserMisc.h | 4 +- semanticMisc.c | 247 ++++++++++++++++-------------------------- semanticMisc.h | 6 +- statementSemantics.c | 192 +++++++++++++++----------------- structSemantics.c | 37 ++++--- tokenStrings_6502.c | 6 +- 34 files changed, 1130 insertions(+), 1661 deletions(-) diff --git a/actions_6502.c b/actions_6502.c index 97338db..2f5f21e 100644 --- a/actions_6502.c +++ b/actions_6502.c @@ -45,11 +45,19 @@ and operand. */ - void -actionsDir1(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; + +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) { #define ZERO_PAGE_ADDRESS_BIT 0x00 #define NON_ZERO_PAGE_ADDRESS_BIT 0x08 @@ -66,10 +74,7 @@ actionsDir1(opcode, numberOfOperands, evaluatedOperands) } void -actionsDir2(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDir2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { if (wordCheck(address)) { emitByte(binary); @@ -79,10 +84,7 @@ actionsDir2(opcode, numberOfOperands, evaluatedOperands) } void -actionsDirIndir(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDirIndir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define DIRECT_ADDRESS_BIT 0x00 #define INDIRECT_ADDRESS_BIT 0x20 @@ -98,10 +100,7 @@ actionsDirIndir(opcode, numberOfOperands, evaluatedOperands) } void -actionsDirX1(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDirX1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define DIRECT_ADDRESS_ZERO_PAGE_BITS_X1 0x04 #define A_REGISTER_BITS_X1 0x08 @@ -133,10 +132,7 @@ actionsDirX1(opcode, numberOfOperands, evaluatedOperands) } void -actionsDirX2(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDirX2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define DIRECT_ADDRESS_ZERO_PAGE_BITS_X2 0x00 #define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_X2 0x08 @@ -165,10 +161,7 @@ actionsDirX2(opcode, numberOfOperands, evaluatedOperands) } void -actionsDirX3(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDirX3(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { if (class == EXPRESSION_OPND) { if (isByteAddress(operand) && isDefined(operand)) { @@ -189,10 +182,7 @@ actionsDirX3(opcode, numberOfOperands, evaluatedOperands) } void -actionsDirY(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define DIRECT_ADDRESS_ZERO_PAGE_BITS_Y 0x00 #define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_Y 0x08 @@ -217,10 +207,7 @@ actionsDirY(opcode, numberOfOperands, evaluatedOperands) } void -actionsImmDir(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsImmDir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define IMMEDIATE_DATA_BITS_ID 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_ID 0x04 @@ -245,10 +232,7 @@ actionsImmDir(opcode, numberOfOperands, evaluatedOperands) } void -actionsImmDirX(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsImmDirX(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define IMMEDIATE_DATA_BITS_IX 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_IX 0x04 @@ -284,10 +268,7 @@ actionsImmDirX(opcode, numberOfOperands, evaluatedOperands) } void -actionsImmDirY(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsImmDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define IMMEDIATE_DATA_BITS_IY 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_IY 0x04 @@ -323,10 +304,7 @@ actionsImmDirY(opcode, numberOfOperands, evaluatedOperands) } void -actionsImmIndex(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsImmIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define PRE_INDEXED_BITS_A 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_A 0x04 @@ -383,10 +361,7 @@ actionsImmIndex(opcode, numberOfOperands, evaluatedOperands) } void -actionsIndex(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { if (class == EXPRESSION_OPND) { if (isByteAddress(operand) && isDefined(operand)) { @@ -428,19 +403,13 @@ actionsIndex(opcode, numberOfOperands, evaluatedOperands) } void -actionsNone(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsNone(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { emitByte(binary); } void -actionsRelative(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +actionsRelative(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { int offset; @@ -465,43 +434,37 @@ actionsRelative(opcode, numberOfOperands, evaluatedOperands) */ bool -isByte(value) - int value; +isByte(int value) { return (-129kindOfValue==ABSOLUTE_VALUE && isByte(value->value)); } bool -isWord(value) - int value; +isWord(int value) { return (-32769kindOfValue!=UNDEFINED_VALUE); } diff --git a/buildStuff1.c b/buildStuff1.c index 695bffc..0287c2f 100644 --- a/buildStuff1.c +++ b/buildStuff1.c @@ -33,14 +33,16 @@ #include "macrossTypes.h" #include "macrossGlobals.h" -symbolTableEntryType *lookupOrEnterSymbol(); -char *saveString(); +symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); +char *saveString(char *s); /* Generic routine to create statement nodes */ - statementType * -newStatement(kind, body) - statementKindType kind; - statementBodyType body; + +extern void botch (char *message, ...); +extern void error (errorType theError, ...); + +statementType * +newStatement(statementKindType kind, statementBodyType body) { statementType *result; @@ -62,17 +64,14 @@ newStatement(kind, body) */ statementType * -buildAlignStatement(expression) - expressionType *expression; +buildAlignStatement(expressionType *expression) { return(newStatement(ALIGN_STATEMENT, (statementBodyType) expression)); } statementType * -buildAssertStatement(condition, message) - expressionType *condition; - expressionType *message; +buildAssertStatement(expressionType *condition, expressionType *message) { assertStatementBodyType *result; @@ -84,25 +83,21 @@ buildAssertStatement(condition, message) } statementType * -buildBlockStatement(expressionList) - expressionListType *expressionList; +buildBlockStatement(expressionListType *expressionList) { return(newStatement(BLOCK_STATEMENT, (statementBodyType) expressionList)); } statementType * -buildByteStatement(expressionList) - expressionListType *expressionList; +buildByteStatement(expressionListType *expressionList) { return(newStatement(BYTE_STATEMENT, (statementBodyType) expressionList)); } statementType * -buildConstrainStatement(expression, block) - expressionType *expression; - blockType *block; +buildConstrainStatement(expressionType *expression, blockType *block) { constrainStatementBodyType *result; @@ -114,17 +109,14 @@ buildConstrainStatement(expression, block) } statementType * -buildDbyteStatement(expressionList) - expressionListType *expressionList; +buildDbyteStatement(expressionListType *expressionList) { return(newStatement(DBYTE_STATEMENT, (statementBodyType) expressionList)); } statementType * -buildDefineStatement(name, value) - stringType *name; - expressionType *value; +buildDefineStatement(stringType *name, expressionType *value) { defineStatementBodyType *result; @@ -135,9 +127,7 @@ buildDefineStatement(name, value) } statementType * -buildDoUntilStatement(body, condition) - blockType *body; - conditionType condition; +buildDoUntilStatement(blockType *body, conditionType condition) { doUntilStatementBodyType *result; @@ -148,9 +138,7 @@ buildDoUntilStatement(body, condition) } statementType * -buildDoWhileStatement(body, condition) - blockType *body; - conditionType condition; +buildDoWhileStatement(blockType *body, conditionType condition) { doWhileStatementBodyType *result; @@ -161,9 +149,7 @@ buildDoWhileStatement(body, condition) } statementType * -buildDoStatement(body, end) - blockType *body; - doEndType *end; +buildDoStatement(blockType *body, doEndType *end) { statementType *result; @@ -178,26 +164,21 @@ buildDoStatement(body, end) } statementType * -buildExternStatement(identifierList) - identifierListType *identifierList; +buildExternStatement(identifierListType *identifierList) { return(newStatement(EXTERN_STATEMENT, (statementBodyType) identifierList)); } statementType * -buildFreturnStatement(expression) - expressionType *expression; +buildFreturnStatement(expressionType *expression) { return(newStatement(FRETURN_STATEMENT, (statementBodyType) expression)); } statementType * -buildFunctionStatement(name, arguments, body) - stringType *name; - argumentDefinitionListType *arguments; - blockType *body; +buildFunctionStatement(stringType *name, argumentDefinitionListType *arguments, blockType *body) { functionStatementBodyType *result; symbolTableEntryType *testSymbol; @@ -216,18 +197,14 @@ buildFunctionStatement(name, arguments, body) } statementType * -buildGroupStatement(block) - blockType *block; +buildGroupStatement(blockType *block) { return(newStatement(GROUP_STATEMENT, (statementBodyType) block)); } statementType * -buildIfStatement(head, continuation, continuationKind) - ifHeadType *head; - ifContinuationType continuation; - ifContinuationKindType continuationKind; +buildIfStatement(ifHeadType *head, ifContinuationType continuation, ifContinuationKindType continuationKind) { ifStatementBodyType *result; @@ -255,17 +232,14 @@ buildIfStatement(head, continuation, continuationKind) } statementType * -buildIncludeStatement(filename) - expressionType *filename; +buildIncludeStatement(expressionType *filename) { return(newStatement(INCLUDE_STATEMENT, (statementBodyType) filename)); } statementType * -buildInstructionStatement(opcode, operands) - opcodeTableEntryType *opcode; - operandListType *operands; +buildInstructionStatement(opcodeTableEntryType *opcode, operandListType *operands) { instructionStatementBodyType *result; @@ -277,18 +251,14 @@ buildInstructionStatement(opcode, operands) } statementType * -buildLongStatement(expressionList) - expressionListType *expressionList; +buildLongStatement(expressionListType *expressionList) { return(newStatement(LONG_STATEMENT, (statementBodyType) expressionList)); } statementType * -buildMacroStatement(macro, arguments, body) - macroTableEntryType *macro; - argumentDefinitionListType *arguments; - blockType *body; +buildMacroStatement(macroTableEntryType *macro, argumentDefinitionListType *arguments, blockType *body) { macroStatementBodyType *result; @@ -300,9 +270,7 @@ buildMacroStatement(macro, arguments, body) } statementType * -buildMacroInstructionStatement(macro, operands) - macroTableEntryType *macro; - operandListType *operands; +buildMacroInstructionStatement(macroTableEntryType *macro, operandListType *operands) { instructionStatementBodyType *result; @@ -314,9 +282,7 @@ buildMacroInstructionStatement(macro, operands) } statementType * -buildMdefineStatement(name, value) - stringType *name; - expressionType *value; +buildMdefineStatement(stringType *name, expressionType *value) { mdefineStatementBodyType *result; @@ -327,9 +293,7 @@ buildMdefineStatement(name, value) } statementType * -buildMdoUntilStatement(body, condition) - blockType *body; - ExpressionType *condition; +buildMdoUntilStatement(blockType *body, struct expressionTermStruct *condition) { mdoUntilStatementBodyType *result; @@ -340,9 +304,7 @@ buildMdoUntilStatement(body, condition) } statementType * -buildMdoWhileStatement(body, condition) - blockType *body; - expressionType *condition; +buildMdoWhileStatement(blockType *body, expressionType *condition) { mdoWhileStatementBodyType *result; @@ -353,9 +315,7 @@ buildMdoWhileStatement(body, condition) } statementType * -buildMdoStatement(body, end) - blockType *body; - mdoEndType *end; +buildMdoStatement(blockType *body, mdoEndType *end) { statementType *result; @@ -370,9 +330,7 @@ buildMdoStatement(body, end) } statementType * -buildMforStatement(forExpressions, body) - forExpressionsType *forExpressions; - blockType *body; +buildMforStatement(forExpressionsType *forExpressions, blockType *body) { mforStatementBodyType *result; @@ -386,10 +344,7 @@ buildMforStatement(forExpressions, body) } statementType * -buildMifStatement(head, continuation, continuationKind) - mifHeadType *head; - mifContinuationType continuation; - ifContinuationKindType continuationKind; +buildMifStatement(mifHeadType *head, mifContinuationType continuation, ifContinuationKindType continuationKind) { mifStatementBodyType *result; @@ -417,9 +372,7 @@ buildMifStatement(head, continuation, continuationKind) } statementType * -buildMswitchStatement(switchExpression, cases) - expressionType *switchExpression; - caseListType *cases; +buildMswitchStatement(expressionType *switchExpression, caseListType *cases) { mswitchStatementBodyType *result; @@ -430,10 +383,7 @@ buildMswitchStatement(switchExpression, cases) } statementType * -buildMvariableStatement(name, value, dimension) - stringType *name; - expressionListType *value; - expressionType *dimension; +buildMvariableStatement(stringType *name, expressionListType *value, expressionType *dimension) { mvariableStatementBodyType *result; @@ -445,9 +395,7 @@ buildMvariableStatement(name, value, dimension) } statementType * -buildMwhileStatement(condition, body) - expressionType *condition; - blockType *body; +buildMwhileStatement(expressionType *condition, blockType *body) { mwhileStatementBodyType *result; @@ -458,53 +406,47 @@ buildMwhileStatement(condition, body) } statementType * -buildNullStatement() +buildNullStatement(void) { return(newStatement(NULL_STATEMENT, (statementBodyType){ .ifUnion = NULL })); } statementType * -buildOrgStatement(expression) - expressionType *expression; +buildOrgStatement(expressionType *expression) { return(newStatement(ORG_STATEMENT, (statementBodyType) expression)); } statementType * -buildPerformStatement(expression) - expressionType *expression; +buildPerformStatement(expressionType *expression) { return(newStatement(PERFORM_STATEMENT, (statementBodyType) expression)); } statementType * -buildRelStatement() +buildRelStatement(void) { return(newStatement(REL_STATEMENT, (statementBodyType){ .ifUnion = NULL })); } statementType * -buildStartStatement(expression) - expressionType *expression; +buildStartStatement(expressionType *expression) { return(newStatement(START_STATEMENT, (statementBodyType) expression)); } statementType * -buildStringStatement(expressionList) - expressionListType *expressionList; +buildStringStatement(expressionListType *expressionList) { return(newStatement(STRING_STATEMENT, (statementBodyType) expressionList)); } statementType * -buildStructStatement(name, body) - symbolTableEntryType *name; - blockType *body; +buildStructStatement(symbolTableEntryType *name, blockType *body) { structStatementBodyType *result; @@ -515,26 +457,21 @@ buildStructStatement(name, body) } statementType * -buildTargetStatement(expression) - expressionType *expression; +buildTargetStatement(expressionType *expression) { return(newStatement(TARGET_STATEMENT, (statementBodyType) expression)); } statementType * -buildUndefineStatement(identifierList) - identifierListType *identifierList; +buildUndefineStatement(identifierListType *identifierList) { return(newStatement(UNDEFINE_STATEMENT, (statementBodyType) identifierList)); } statementType * -buildVariableStatement(name, value, dimension) - stringType *name; - expressionListType *value; - expressionType *dimension; +buildVariableStatement(stringType *name, expressionListType *value, expressionType *dimension) { variableStatementBodyType *result; @@ -546,9 +483,7 @@ buildVariableStatement(name, value, dimension) } statementType * -buildWhileStatement(condition, body) - conditionType condition; - blockType *body; +buildWhileStatement(conditionType condition, blockType *body) { whileStatementBodyType *result; @@ -559,8 +494,7 @@ buildWhileStatement(condition, body) } statementType * -buildWordStatement(expressionList) - expressionListType *expressionList; +buildWordStatement(expressionListType *expressionList) { return(newStatement(WORD_STATEMENT, (statementBodyType) expressionList)); diff --git a/buildStuff2.c b/buildStuff2.c index f5b283a..cd9a640 100644 --- a/buildStuff2.c +++ b/buildStuff2.c @@ -41,10 +41,11 @@ /* Fragments of statement structures */ - caseType * -buildCase(caseTags, caseBody) - expressionListType *caseTags; - blockType *caseBody; + +extern void botch (char *message, ...); + +caseType * +buildCase(expressionListType *caseTags, blockType *caseBody) { caseType *result; @@ -55,9 +56,7 @@ buildCase(caseTags, caseBody) } doEndType * -buildDoEnd(condition, kindOfDoEnd) - conditionType condition; - doEndKindType kindOfDoEnd; +buildDoEnd(conditionType condition, doEndKindType kindOfDoEnd) { doEndType *result; @@ -68,10 +67,7 @@ buildDoEnd(condition, kindOfDoEnd) } forExpressionsType * -buildForExpressions(initExpression, testExpression, incrExpression) - expressionType *initExpression; - expressionType *testExpression; - expressionType *incrExpression; +buildForExpressions(expressionType *initExpression, expressionType *testExpression, expressionType *incrExpression) { forExpressionsType *result; @@ -83,9 +79,7 @@ buildForExpressions(initExpression, testExpression, incrExpression) } ifHeadType * -buildIfHead(condition, block) - conditionType condition; - blockType *block; +buildIfHead(conditionType condition, blockType *block) { ifHeadType *result; @@ -96,9 +90,7 @@ buildIfHead(condition, block) } mdoEndType * -buildMdoEnd(condition, kindOfMdoEnd) - expressionType *condition; - doEndKindType kindOfMdoEnd; +buildMdoEnd(expressionType *condition, doEndKindType kindOfMdoEnd) { mdoEndType *result; @@ -110,9 +102,7 @@ buildMdoEnd(condition, kindOfMdoEnd) mifHeadType * -buildMifHead(condition, block) - expressionType *condition; - blockType *block; +buildMifHead(expressionType *condition, blockType *block) { mifHeadType *result; @@ -126,9 +116,7 @@ buildMifHead(condition, block) /* Fragments of expression structures */ arrayTermType * -buildArrayTerm(array, index) - expressionType *array; - expressionType *index; +buildArrayTerm(expressionType *array, expressionType *index) { arrayTermType *result; @@ -139,10 +127,7 @@ buildArrayTerm(array, index) } binopTermType * -buildBinopTerm(binop, leftArgument, rightArgument) - binopKindType binop; - expressionType *leftArgument; - expressionType *rightArgument; +buildBinopTerm(binopKindType binop, expressionType *leftArgument, expressionType *rightArgument) { binopTermType *result; @@ -154,12 +139,10 @@ buildBinopTerm(binop, leftArgument, rightArgument) } functionCallTermType * -buildFunctionCall(functionName, arguments) - stringType *functionName; - operandListType *arguments; +buildFunctionCall(stringType *functionName, operandListType *arguments) { functionCallTermType *result; - symbolTableEntryType *lookupOrEnterSymbol(); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); result = typeAlloc(functionCallTermType); result->functionName = lookupOrEnterSymbol(functionName, @@ -169,9 +152,7 @@ buildFunctionCall(functionName, arguments) } postOpTermType * -buildPostOpTerm(postOp, postOpArgument) - postOpKindType postOp; - expressionType *postOpArgument; +buildPostOpTerm(postOpKindType postOp, expressionType *postOpArgument) { postOpTermType *result; @@ -182,9 +163,7 @@ buildPostOpTerm(postOp, postOpArgument) } preOpTermType * -buildPreOpTerm(preOp, preOpArgument) - preOpKindType preOp; - expressionType *preOpArgument; +buildPreOpTerm(preOpKindType preOp, expressionType *preOpArgument) { preOpTermType *result; @@ -195,9 +174,7 @@ buildPreOpTerm(preOp, preOpArgument) } unopTermType * -buildUnopTerm(unop, unopArgument) - unopKindType unop; - expressionType *unopArgument; +buildUnopTerm(unopKindType unop, expressionType *unopArgument) { unopTermType *result; @@ -208,15 +185,11 @@ buildUnopTerm(unop, unopArgument) } expressionTermType * -buildExpressionTerm(kindOfExpressionTerm, arg1, arg2, arg3) - expressionTermKindType kindOfExpressionTerm; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; +buildExpressionTerm(expressionTermKindType kindOfExpressionTerm, anyOldThing *arg1, anyOldThing *arg2, anyOldThing *arg3) { expressionType *result; - symbolTableEntryType *lookupOrEnterSymbol(); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); result = typeAlloc(expressionType); result->kindOfTerm = kindOfExpressionTerm; @@ -298,11 +271,10 @@ buildExpressionTerm(kindOfExpressionTerm, arg1, arg2, arg3) /* Other stuff */ macroTableEntryType * -buildMacroTableEntry(name) - stringType *name; +buildMacroTableEntry(stringType *name) { macroTableEntryType *result; - char *saveString(); + char *saveString(char *s); result = typeAlloc(macroTableEntryType); result->macroName = saveString(name); @@ -313,12 +285,10 @@ buildMacroTableEntry(name) } symbolTableEntryType * -buildSymbolTableEntry(name, usage) - stringType *name; - symbolUsageKindType usage; +buildSymbolTableEntry(stringType *name, symbolUsageKindType usage) { symbolTableEntryType *result; - char *saveString(); + char *saveString(char *s); result = typeAlloc(symbolTableEntryType); result->symbolName = saveString(name); @@ -335,10 +305,7 @@ buildSymbolTableEntry(name, usage) } codeBreakType * -buildCodeBreak(kind, address, data) - codeBreakKindType kind; - addressType address; - int data; +buildCodeBreak(codeBreakKindType kind, addressType address, int data) { codeBreakType *result; @@ -351,10 +318,7 @@ buildCodeBreak(kind, address, data) } reservationListType * -buildReservation(startAddress, blockSize, nextReservation) - addressType startAddress; - int blockSize; - reservationListType *nextReservation; +buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation) { reservationListType *result; @@ -366,9 +330,7 @@ buildReservation(startAddress, blockSize, nextReservation) } simpleFixupListType * -buildSimpleFixupList(locationToFixup, previousList) - valueType locationToFixup; - simpleFixupListType *previousList; +buildSimpleFixupList(valueType locationToFixup, simpleFixupListType *previousList) { simpleFixupListType *result; diff --git a/buildStuff3.c b/buildStuff3.c index 3816934..0819cf1 100644 --- a/buildStuff3.c +++ b/buildStuff3.c @@ -43,14 +43,11 @@ */ argumentListHeadType * -buildArgumentList(new, rest, arrayTag) - stringType *new; - argumentListHeadType *rest; - bool arrayTag; +buildArgumentList(stringType *new, argumentListHeadType *rest, bool arrayTag) { argumentListHeadType *newListHead; argumentDefinitionListType *newArgument; - symbolTableEntryType *lookupOrEnterSymbol(); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); if (rest == NULL) { newListHead = typeAlloc(argumentListHeadType); @@ -76,9 +73,7 @@ buildArgumentList(new, rest, arrayTag) } caseListHeadType * -buildCaseList(new, rest) - caseType *new; - caseListHeadType *rest; +buildCaseList(caseType *new, caseListHeadType *rest) { caseListHeadType *newListHead; caseListType *newCase; @@ -103,9 +98,7 @@ buildCaseList(new, rest) } expressionListHeadType * -buildExpressionList(new, rest) - expressionType *new; - expressionListHeadType *rest; +buildExpressionList(expressionType *new, expressionListHeadType *rest) { expressionListHeadType *newListHead; expressionListType *newListEntry; @@ -130,15 +123,12 @@ buildExpressionList(new, rest) } identifierListHeadType * -buildIdentifierList(new, rest, usage) - stringType *new; - identifierListHeadType *rest; - symbolUsageKindType usage; +buildIdentifierList(stringType *new, identifierListHeadType *rest, symbolUsageKindType usage) { identifierListType *newListEntry; identifierListHeadType *newListHead; - symbolTableEntryType *lookupOrEnterSymbol(); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); if (rest == NULL) { newListHead = typeAlloc(identifierListHeadType); @@ -160,9 +150,7 @@ buildIdentifierList(new, rest, usage) } labelListHeadType * -buildLabelList(new, rest) - symbolTableEntryType *new; - labelListHeadType *rest; +buildLabelList(symbolTableEntryType *new, labelListHeadType *rest) { labelListHeadType *newLabelHead; labelListType *newLabel; @@ -187,9 +175,7 @@ buildLabelList(new, rest) } operandListHeadType * -buildOperandList(new, rest) - operandType *new; - operandListHeadType *rest; +buildOperandList(operandType *new, operandListHeadType *rest) { operandListHeadType *newListHead; @@ -213,17 +199,13 @@ buildOperandList(new, rest) } selectionListHeadType * -buildSelectionList(new, rest) - selectionListType *new; - selectionListHeadType *rest; +buildSelectionList(selectionListType *new, selectionListHeadType *rest) { return((selectionListHeadType *) buildIdentifierList(new, rest, unknownSymbolTag /* random guess */)); } statementListHeadType * -buildStatementList(new, rest) - statementType *new; - statementListHeadType *rest; +buildStatementList(statementType *new, statementListHeadType *rest) { statementListHeadType *newListHead; diff --git a/builtInFunctions.c b/builtInFunctions.c index da15088..547e6fc 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -42,47 +42,54 @@ environment */ - valueType * -makeBooleanValue(test) - int test; + +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) { return(newValue(ABSOLUTE_VALUE, test!=0, EXPRESSION_OPND)); } valueType * -makeFailureValue() +makeFailureValue(void) { return(newValue(FAIL, 0, EXPRESSION_OPND)); } valueType * -makeIntegerValue(integer) - int integer; +makeIntegerValue(int integer) { return(newValue(ABSOLUTE_VALUE, integer, EXPRESSION_OPND)); } valueType * -makeOperandValue(operand) - operandType *operand; +makeOperandValue(operandType *operand) { return(newValue(OPERAND_VALUE, operand, EXPRESSION_OPND)); } valueType * -makeStringValue(string) - stringType *string; +makeStringValue(stringType *string) { return(newValue(STRING_VALUE, string, STRING_OPND)); } valueType * -makeUndefinedValue() +makeUndefinedValue(void) { return(newValue(UNDEFINED_VALUE, 0, EXPRESSION_OPND)); @@ -98,9 +105,7 @@ makeUndefinedValue() /* Return internal address mode of an operand */ valueType * -addressModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +addressModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -115,15 +120,13 @@ addressModeBIF(parameterList, kindOfFixup) /* Call a macro where the macro name is obtained dynamically from a string */ valueType * -applyBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +applyBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *macroToLookup; macroTableEntryType *macroToCall; - macroTableEntryType *lookupMacroName(); + macroTableEntryType *lookupMacroName(char *s, int hashValue); if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "apply"); @@ -146,9 +149,7 @@ applyBIF(parameterList, kindOfFixup) /* return the length of an array */ valueType * -arrayLengthBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +arrayLengthBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *testObjectValue; @@ -188,9 +189,7 @@ static char atasciiTable[] = { /* 0xFFs will become 0x00s on output */ /* Convert a string to ATASCII */ valueType * -atasciiBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +atasciiBIF(operandListType *parameterList, fixupKindType kindOfFixup) { int i; valueType *stringValue; @@ -215,9 +214,7 @@ atasciiBIF(parameterList, kindOfFixup) /* Convert a string to ATASCII while setting high-order color bits */ valueType * -atasciiColorBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +atasciiColorBIF(operandListType *parameterList, fixupKindType kindOfFixup) { int i; valueType *stringValue; @@ -264,18 +261,14 @@ atasciiColorBIF(parameterList, kindOfFixup) /* Turn debug mode off and on */ valueType * -debugModeOffBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +debugModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup) { debug = FALSE; return(makeBooleanValue(FALSE)); } valueType * -debugModeOnBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +debugModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup) { debug = TRUE; return(makeBooleanValue(TRUE)); @@ -283,18 +276,14 @@ debugModeOnBIF(parameterList, kindOfFixup) /* Turn display of code emission off and on */ valueType * -emitModeOffBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +emitModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup) { emitPrint = FALSE; return(makeBooleanValue(FALSE)); } valueType * -emitModeOnBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +emitModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup) { emitPrint = TRUE; return(makeBooleanValue(TRUE)); @@ -302,9 +291,7 @@ emitModeOnBIF(parameterList, kindOfFixup) /* Check if an operand is absolute (as opposed to relocatable) */ valueType * -isAbsoluteValueBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isAbsoluteValueBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -320,9 +307,9 @@ isAbsoluteValueBIF(parameterList, kindOfFixup) /* Check if operand is code block */ valueType * -isBlockBIF(parameterList, kindOfFixup) /* questionable */ - operandListType *parameterList; - fixupKindType kindOfFixup; +isBlockBIF(operandListType *parameterList, fixupKindType kindOfFixup) /* questionable */ + + { valueType *evaluatedParameter; @@ -338,9 +325,7 @@ isBlockBIF(parameterList, kindOfFixup) /* questionable */ /* Check if operand is a BIF */ valueType * -isBuiltInFunctionBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isBuiltInFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -356,9 +341,7 @@ isBuiltInFunctionBIF(parameterList, kindOfFixup) /* Check if operand is a condition code */ valueType * -isConditionCodeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isConditionCodeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -374,15 +357,13 @@ isConditionCodeBIF(parameterList, kindOfFixup) /* Check if a symbol is defined */ valueType * -isDefinedBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup) { expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(); - symbolTableEntryType *effectiveSymbol(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); + symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); if (parameterList != NULL) { if (parameterList->kindOfOperand == EXPRESSION_OPND && @@ -409,14 +390,12 @@ isDefinedBIF(parameterList, kindOfFixup) /* Check if a symbol is externally visible */ valueType * -isExternalBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup) { expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { @@ -432,9 +411,7 @@ isExternalBIF(parameterList, kindOfFixup) /* Check if an operand is a struct field */ valueType * -isFieldBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isFieldBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -450,9 +427,7 @@ isFieldBIF(parameterList, kindOfFixup) /* Check if an operand is a user-defined function */ valueType * -isFunctionBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -468,9 +443,7 @@ isFunctionBIF(parameterList, kindOfFixup) /* Check if an operand value is relocatable */ valueType * -isRelocatableValueBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isRelocatableValueBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -487,9 +460,7 @@ isRelocatableValueBIF(parameterList, kindOfFixup) /* Check if an operand is a string */ valueType * -isStringBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isStringBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -505,9 +476,7 @@ isStringBIF(parameterList, kindOfFixup) /* Check if an operand is a struct */ valueType * -isStructBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isStructBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; @@ -523,9 +492,7 @@ isStructBIF(parameterList, kindOfFixup) /* Check if an operand is a symbol */ valueType * -isSymbolBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isSymbolBIF(operandListType *parameterList, fixupKindType kindOfFixup) { expressionType *expression; @@ -541,9 +508,7 @@ isSymbolBIF(parameterList, kindOfFixup) /* Turn listing off and on */ valueType * -listingOffBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +listingOffBIF(operandListType *parameterList, fixupKindType kindOfFixup) { if (listingOn) { if (!listingControlCounter) @@ -554,9 +519,7 @@ listingOffBIF(parameterList, kindOfFixup) } valueType * -listingOnBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +listingOnBIF(operandListType *parameterList, fixupKindType kindOfFixup) { if (listingOn) { if (--listingControlCounter < 0) { @@ -575,9 +538,7 @@ listingOnBIF(parameterList, kindOfFixup) /* Generate an array on the fly */ valueType * -makeArrayBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +makeArrayBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *lengthValue; int length; @@ -619,9 +580,7 @@ makeArrayBIF(parameterList, kindOfFixup) /* Return the Nth character of a string (as an integer) */ valueType * -nthCharBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +nthCharBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *positionValue; int position; @@ -658,9 +617,7 @@ nthCharBIF(parameterList, kindOfFixup) /* Pass stuff through to stdio's 'printf' function */ valueType * -printfBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +printfBIF(operandListType *parameterList, fixupKindType kindOfFixup) { stringType *formatString; valueType *stringValue; @@ -697,9 +654,7 @@ printfBIF(parameterList, kindOfFixup) /* Concatenate two strings */ valueType * -strcatBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strcatBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string1; @@ -731,9 +686,7 @@ strcatBIF(parameterList, kindOfFixup) /* Compare two strings */ valueType * -strcmpBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strcmpBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string1; @@ -764,9 +717,7 @@ strcmpBIF(parameterList, kindOfFixup) /* Compare two strings in a case-independent fashion */ valueType * -strcmplcBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strcmplcBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string1; @@ -797,9 +748,7 @@ strcmplcBIF(parameterList, kindOfFixup) /* Return the length of a string */ valueType * -strlenBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strlenBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; @@ -815,9 +764,7 @@ strlenBIF(parameterList, kindOfFixup) /* Return a substring of a string */ valueType * -substrBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +substrBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string; @@ -895,16 +842,14 @@ substrBIF(parameterList, kindOfFixup) /* Turn a string into a symbol */ valueType * -symbolLookupBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *identifierToLookup; - expressionTermType *buildExpressionTerm(); - operandType *buildOperand(); - valueType *evaluateIdentifier(); + 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"); @@ -922,13 +867,11 @@ symbolLookupBIF(parameterList, kindOfFixup) /* Define a string as a symbol */ valueType * -symbolDefineBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; statementType *syntheticDefineStatement; - statementType *buildDefineStatement(); + statementType *buildDefineStatement(stringType *name, expressionType *value); if (parameterList == NULL) { error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolDefine"); @@ -957,15 +900,13 @@ symbolDefineBIF(parameterList, kindOfFixup) /* Turn a symbol into a string */ valueType * -symbolNameBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup) { expressionType *expression; symbolInContextType *context; environmentType *saveEnvironment; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); saveEnvironment = currentEnvironment; while (parameterList != NULL && parameterList->kindOfOperand == @@ -996,14 +937,12 @@ symbolNameBIF(parameterList, kindOfFixup) /* Return internal form of what sort of symbol a symbol is */ valueType * -symbolUsageBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup) { expressionType *expression; symbolInContextType *context; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { @@ -1018,9 +957,7 @@ symbolUsageBIF(parameterList, kindOfFixup) /* Return internal form of what sort of value a value is */ valueType * -valueTypeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; diff --git a/builtInFunsSD_6502.c b/builtInFunsSD_6502.c index 9363cfd..cc2981a 100644 --- a/builtInFunsSD_6502.c +++ b/builtInFunsSD_6502.c @@ -34,23 +34,21 @@ #include "macrossGlobals.h" /* Helper functions, defined in builtInFunctions.c */ -valueType *makeBooleanValue(); -valueType *makeFailureValue(); -valueType *makeIntegerValue(); -valueType *makeOperandValue(); -valueType *makeStringValue(); -valueType *makeUndefinedValue(); +valueType *makeBooleanValue(int test); +valueType *makeFailureValue(void); +valueType *makeIntegerValue(int integer); +valueType *makeOperandValue(operandType *operand); +valueType *makeStringValue(stringType *string); +valueType *makeUndefinedValue(void); /* Check if operand is the accumulator */ valueType * -isARegisterBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -63,13 +61,11 @@ isARegisterBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is DIRECT */ valueType * -isDirectModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isDirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -82,13 +78,11 @@ isDirectModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is IMMEDIATE */ valueType * -isImmediateModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isImmediateModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -101,13 +95,11 @@ isImmediateModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is INDEXED (either X or Y) */ valueType * -isIndexedModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -123,13 +115,11 @@ isIndexedModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is INDIRECT */ valueType * -isIndirectModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isIndirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -142,13 +132,11 @@ isIndirectModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is POST-INDEXED */ valueType * -isPostIndexedModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isPostIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -161,13 +149,11 @@ isPostIndexedModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is PRE-INDEXED */ valueType * -isPreIndexedModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isPreIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -181,13 +167,11 @@ isPreIndexedModeBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is X-INDEXED */ valueType * -isXIndexedModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -201,13 +185,11 @@ isXIndexedModeBIF(parameterList, kindOfFixup) /* Check if an operand is the X index register */ valueType * -isXRegisterBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -220,13 +202,11 @@ isXRegisterBIF(parameterList, kindOfFixup) /* Check if an operand's address mode is Y-INDEXED */ valueType * -isYIndexedModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); @@ -240,13 +220,11 @@ isYIndexedModeBIF(parameterList, kindOfFixup) /* Check if an operand is the Y index register */ valueType * -isYRegisterBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); + valueType *evaluateOperand(operandType *operand); if (parameterList != NULL) { evaluatedParameter = evaluateOperand(parameterList); diff --git a/debugPrint.c b/debugPrint.c index 1d9ebaa..8ca4884 100644 --- a/debugPrint.c +++ b/debugPrint.c @@ -44,8 +44,14 @@ int tablevel = 0; #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } /* For keeping nested structures looking pretty */ - void -tab() + +extern void printOperandKind (operandKindType kind); +extern void printToken (int token); +extern void printCondition (conditionType condition); +extern void printOperand (operandType *operand); + +void +tab(void) { int n; @@ -62,8 +68,7 @@ tab() */ void -printAssignmentKind(assignmentKind) - assignmentKindType assignmentKind; +printAssignmentKind(assignmentKindType assignmentKind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'assignmentKindType'. */ @@ -86,8 +91,7 @@ printAssignmentKind(assignmentKind) } void -printExpressionKind(kind) - expressionTermKindType kind; +printExpressionKind(expressionTermKindType kind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'expressionTermKindType'. */ @@ -112,8 +116,7 @@ printExpressionKind(kind) } stringType * -statementKindString(kind) - statementKindType kind; +statementKindString(statementKindType kind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'statementKindType'. */ @@ -161,8 +164,7 @@ static char *statementKindTable[] = { } void -printStatementKind(kind) - statementKindType kind; +printStatementKind(statementKindType kind) { printf("%s", statementKindString(kind)); } @@ -173,8 +175,7 @@ printStatementKind(kind) */ void -printValue(value) - valueType *value; +printValue(valueType *value) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -207,8 +208,7 @@ printValue(value) } void -printSymbol(symbol) - symbolTableEntryType *symbol; +printSymbol(symbolTableEntryType *symbol) { /* This table MUST be maintained congruent with the definition of the enumerated type 'symbolUsageKindType'. */ @@ -243,8 +243,7 @@ printSymbol(symbol) } void -printArgumentDefinitionList(list) - argumentDefinitionListType *list; +printArgumentDefinitionList(argumentDefinitionListType *list) { nullPrint(list); tab(); printf("(arguments:\n"); @@ -258,10 +257,9 @@ printArgumentDefinitionList(list) } void -printBlock(block) - blockType *block; +printBlock(blockType *block) { - void printStatement(); + void printStatement(statementType *statement); nullPrint(block); tab(); printf("(block:\n"); @@ -272,10 +270,9 @@ printBlock(block) } void -printArrayTerm(arrayTerm) - arrayTermType *arrayTerm; +printArrayTerm(arrayTermType *arrayTerm) { - void printIdentifier(); + void printIdentifier(symbolTableEntryType *identifier); nullPrint(arrayTerm); tab(); printf("(array\n"); @@ -287,8 +284,7 @@ printArrayTerm(arrayTerm) } void -printAssignmentTerm(assignmentTerm) - binopTermType *assignmentTerm; +printAssignmentTerm(binopTermType *assignmentTerm) { nullPrint(assignmentTerm); @@ -303,10 +299,9 @@ printAssignmentTerm(assignmentTerm) } void -printBinopTerm(binopTerm) - binopTermType *binopTerm; +printBinopTerm(binopTermType *binopTerm) { - void printIdentifier(); + void printIdentifier(symbolTableEntryType *identifier); nullPrint(binopTerm); tab(); printf("(binop ["); @@ -323,10 +318,9 @@ printBinopTerm(binopTerm) } void -printFunctionCall(functionCall) - functionCallTermType *functionCall; +printFunctionCall(functionCallTermType *functionCall) { - void printOperandList(); + void printOperandList(operandListType *operandList); nullPrint(functionCall); tab(); printf("(function call %s\n", functionCall->functionName-> @@ -338,29 +332,26 @@ printFunctionCall(functionCall) } void -printHere() +printHere(void) { tab(); printf("(here)\n"); } void -printIdentifier(identifier) - symbolTableEntryType *identifier; +printIdentifier(symbolTableEntryType *identifier) { nullPrint(identifier); printSymbol(identifier); } void -printNumber(number) - numberTermType number; +printNumber(numberTermType number) { tab(); printf("(number: %d)\n", number); } void -printPostopTerm(postopTerm) - postOpTermType *postopTerm; +printPostopTerm(postOpTermType *postopTerm) { nullPrint(postopTerm); tab(); printf("(postop ["); @@ -373,8 +364,7 @@ printPostopTerm(postopTerm) } void -printPreopTerm(preopTerm) - preOpTermType *preopTerm; +printPreopTerm(preOpTermType *preopTerm) { nullPrint(preopTerm); tab(); printf("(preop ["); @@ -387,8 +377,7 @@ printPreopTerm(preopTerm) } void -printUnopTerm(unopTerm) - unopTermType *unopTerm; +printUnopTerm(unopTermType *unopTerm) { nullPrint(unopTerm); tab(); printf("(unop ["); @@ -401,8 +390,7 @@ printUnopTerm(unopTerm) } void -printExpression(expression) - expressionType *expression; +printExpression(expressionType *expression) { nullPrint(expression); tab(); printf("(expression: ["); @@ -477,8 +465,7 @@ printExpression(expression) } void -printExpressionList(expressionList) - expressionListType *expressionList; +printExpressionList(expressionListType *expressionList) { while (expressionList != NULL) { printExpression(expressionList->theExpression); @@ -487,8 +474,7 @@ printExpressionList(expressionList) } void -printIdentifierList(identifierList) - identifierListType *identifierList; +printIdentifierList(identifierListType *identifierList) { nullPrint(identifierList); printSymbol(identifierList->theSymbol); @@ -502,8 +488,7 @@ printIdentifierList(identifierList) */ void -printCase(aCase) - caseType *aCase; +printCase(caseType *aCase) { tab(); printf("(case:\n"); tablevel++; if (aCase->caseTags == NULL) { @@ -520,8 +505,7 @@ printCase(aCase) } void -printCaseList(caseList) - caseListType *caseList; +printCaseList(caseListType *caseList) { tab(); printf("(cases:\n"); tablevel++; @@ -534,24 +518,21 @@ printCaseList(caseList) } void -printMacro(macroInstruction) - macroTableEntryType *macroInstruction; +printMacro(macroTableEntryType *macroInstruction) { nullPrint(macroInstruction); tab(); printf("(macro: %s)\n", macroInstruction->macroName); } void -printOpcode(opcode) - opcodeTableEntryType *opcode; +printOpcode(opcodeTableEntryType *opcode) { nullPrint(opcode); tab(); printf("(opcode: %s)\n", opcode->mnemonic); } void -printOperandList(operandList) - operandListType *operandList; +printOperandList(operandListType *operandList) { nullPrint(operandList); printOperand(operandList); @@ -560,16 +541,14 @@ printOperandList(operandList) } void -printAlignStatement(alignStatement) - alignStatementBodyType *alignStatement; +printAlignStatement(alignStatementBodyType *alignStatement) { nullPrint(alignStatement); printExpression(alignStatement); } void -printAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +printAssertStatement(assertStatementBodyType *assertStatement) { nullPrint(assertStatement); printExpression(assertStatement->condition); @@ -577,24 +556,21 @@ printAssertStatement(assertStatement) } void -printBlockStatement(blockStatement) - blockStatementBodyType *blockStatement; +printBlockStatement(blockStatementBodyType *blockStatement) { nullPrint(blockStatement); printExpressionList(blockStatement); } void -printByteStatement(byteStatement) - byteStatementBodyType *byteStatement; +printByteStatement(byteStatementBodyType *byteStatement) { nullPrint(byteStatement); printExpressionList(byteStatement); } void -printConstrainStatement(constrainStatement) - constrainStatementBodyType *constrainStatement; +printConstrainStatement(constrainStatementBodyType *constrainStatement) { nullPrint(constrainStatement); printExpression(constrainStatement->constraint); @@ -602,16 +578,14 @@ printConstrainStatement(constrainStatement) } void -printDbyteStatement(dbyteStatement) - dbyteStatementBodyType *dbyteStatement; +printDbyteStatement(dbyteStatementBodyType *dbyteStatement) { nullPrint(dbyteStatement); printExpressionList(dbyteStatement); } void -printDefineStatement(defineStatement) - defineStatementBodyType *defineStatement; +printDefineStatement(defineStatementBodyType *defineStatement) { nullPrint(defineStatement); printSymbol(defineStatement->theSymbol); @@ -619,8 +593,7 @@ printDefineStatement(defineStatement) } void -printDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +printDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { nullPrint(doUntilStatement); printBlock(doUntilStatement->doUntilLoop); @@ -630,8 +603,7 @@ printDoUntilStatement(doUntilStatement) } void -printDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +printDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { nullPrint(doWhileStatement); printBlock(doWhileStatement->doWhileLoop); @@ -641,24 +613,21 @@ printDoWhileStatement(doWhileStatement) } void -printExternStatement(externStatement) - externStatementBodyType *externStatement; +printExternStatement(externStatementBodyType *externStatement) { nullPrint(externStatement); printIdentifierList(externStatement); } void -printFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +printFreturnStatement(freturnStatementBodyType *freturnStatement) { nullPrint(freturnStatement); printExpression(freturnStatement); } void -printFunctionStatement(functionStatement) - functionStatementBodyType *functionStatement; +printFunctionStatement(functionStatementBodyType *functionStatement) { nullPrint(functionStatement); tab();printf("(function name: %s)\n",functionStatement->functionName); @@ -667,8 +636,7 @@ printFunctionStatement(functionStatement) } void -printIfStatement(ifStatement) - ifStatementBodyType *ifStatement; +printIfStatement(ifStatementBodyType *ifStatement) { nullPrint(ifStatement); tab(); printf("(condition: "); @@ -683,16 +651,14 @@ printIfStatement(ifStatement) } void -printIncludeStatement(includeStatement) - includeStatementBodyType *includeStatement; +printIncludeStatement(includeStatementBodyType *includeStatement) { nullPrint(includeStatement); printExpression(includeStatement); } void -printInstructionStatement(instructionStatement) - instructionStatementBodyType *instructionStatement; +printInstructionStatement(instructionStatementBodyType *instructionStatement) { nullPrint(instructionStatement); switch(instructionStatement->kindOfInstruction) { @@ -713,16 +679,14 @@ printInstructionStatement(instructionStatement) } void -printLongStatement(longStatement) - longStatementBodyType *longStatement; +printLongStatement(longStatementBodyType *longStatement) { nullPrint(longStatement); printExpressionList(longStatement); } void -printMacroStatement(macroStatement) - macroStatementBodyType *macroStatement; +printMacroStatement(macroStatementBodyType *macroStatement) { nullPrint(macroStatement); tab(); printf("(macro name: %s)\n", macroStatement->theMacro); @@ -731,8 +695,7 @@ printMacroStatement(macroStatement) } void -printMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +printMdefineStatement(defineStatementBodyType *mdefineStatement) { nullPrint(mdefineStatement); printSymbol(mdefineStatement->theSymbol); @@ -740,8 +703,7 @@ printMdefineStatement(mdefineStatement) } void -printMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +printMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { nullPrint(mdoUntilStatement); printBlock(mdoUntilStatement->mdoUntilLoop); @@ -749,8 +711,7 @@ printMdoUntilStatement(mdoUntilStatement) } void -printMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +printMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { nullPrint(mdoWhileStatement); printBlock(mdoWhileStatement->mdoWhileLoop); @@ -758,8 +719,7 @@ printMdoWhileStatement(mdoWhileStatement) } void -printMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +printMforStatement(mforStatementBodyType *mforStatement) { nullPrint(mforStatement); printExpression(mforStatement->initExpression); @@ -769,8 +729,7 @@ printMforStatement(mforStatement) } void -printMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +printMifStatement(mifStatementBodyType *mifStatement) { nullPrint(mifStatement); printExpression(mifStatement->mifCondition); @@ -783,8 +742,7 @@ printMifStatement(mifStatement) } void -printMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +printMswitchStatement(mswitchStatementBodyType *mswitchStatement) { nullPrint(mswitchStatement); printExpression(mswitchStatement->switchExpression); @@ -792,8 +750,7 @@ printMswitchStatement(mswitchStatement) } void -printMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +printMvariableStatement(mvariableStatementBodyType *mvariableStatement) { nullPrint(mvariableStatement); printSymbol(mvariableStatement->theSymbol); @@ -801,8 +758,7 @@ printMvariableStatement(mvariableStatement) } void -printMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +printMwhileStatement(mwhileStatementBodyType *mwhileStatement) { nullPrint(mwhileStatement); printExpression(mwhileStatement->mwhileCondition); @@ -810,47 +766,41 @@ printMwhileStatement(mwhileStatement) } void -printOrgStatement(orgStatement) - orgStatementBodyType *orgStatement; +printOrgStatement(orgStatementBodyType *orgStatement) { nullPrint(orgStatement); printExpression(orgStatement); } void -printPerformStatement(performStatement) - performStatementBodyType *performStatement; +printPerformStatement(performStatementBodyType *performStatement) { nullPrint(performStatement); printExpression(performStatement); } void -printRelStatement(relStatement) - relStatementBodyType *relStatement; +printRelStatement(relStatementBodyType *relStatement) { /* there's nothing here... */ } void -printStartStatement(startStatement) - startStatementBodyType *startStatement; +printStartStatement(startStatementBodyType *startStatement) { nullPrint(startStatement); printExpression(startStatement); } void -printStringStatement(stringStatement) - stringStatementBodyType *stringStatement; +printStringStatement(stringStatementBodyType *stringStatement) { nullPrint(stringStatement); printExpressionList(stringStatement); } void -printStructStatement(structStatement) - structStatementBodyType *structStatement; +printStructStatement(structStatementBodyType *structStatement) { nullPrint(structStatement); printSymbol(structStatement->structName); @@ -858,24 +808,21 @@ printStructStatement(structStatement) } void -printTargetStatement(targetStatement) - targetStatementBodyType *targetStatement; +printTargetStatement(targetStatementBodyType *targetStatement) { nullPrint(targetStatement); printExpression(targetStatement); } void -printUndefineStatement(undefineStatement) - undefineStatementBodyType *undefineStatement; +printUndefineStatement(undefineStatementBodyType *undefineStatement) { nullPrint(undefineStatement); printIdentifierList(undefineStatement); } void -printVariableStatement(variableStatement) - variableStatementBodyType *variableStatement; +printVariableStatement(variableStatementBodyType *variableStatement) { nullPrint(variableStatement); printSymbol(variableStatement->theSymbol); @@ -883,8 +830,7 @@ printVariableStatement(variableStatement) } void -printWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +printWhileStatement(whileStatementBodyType *whileStatement) { nullPrint(whileStatement); tab(); printf("(condition: "); @@ -894,16 +840,14 @@ printWhileStatement(whileStatement) } void -printWordStatement(wordStatement) - wordStatementBodyType *wordStatement; +printWordStatement(wordStatementBodyType *wordStatement) { nullPrint(wordStatement); printExpressionList(wordStatement); } void -printLabelList(labelList) - labelListType *labelList; +printLabelList(labelListType *labelList) { nullPrint(labelList); tab(); printf("(\n"); @@ -917,9 +861,7 @@ printLabelList(labelList) } void -printStatementBody(kind, body) - statementKindType kind; - statementBodyType body; +printStatementBody(statementKindType kind, statementBodyType body) { switch (kind) { @@ -1082,8 +1024,7 @@ printStatementBody(kind, body) } void -printStatement(statement) - statementType *statement; +printStatement(statementType *statement) { nullPrint(statement); tab(); printf("(statement["); @@ -1104,8 +1045,7 @@ printStatement(statement) */ void -printPendingFixupList(fixupList) - fixupListType *fixupList; +printPendingFixupList(fixupListType *fixupList) { printf("fixup list: ("); tablevel++; @@ -1118,10 +1058,7 @@ printPendingFixupList(fixupList) } void -printCreateFixup(expression, location, kindOfFixup) - expressionType *expression; - addressType location; - fixupKindType kindOfFixup; +printCreateFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup) { static char *fixupStringTable[] = { "BYTE FIXUP", @@ -1145,7 +1082,7 @@ printCreateFixup(expression, location, kindOfFixup) */ void -printExpressionBuffer() +printExpressionBuffer(void) { int line; int i; @@ -1160,9 +1097,7 @@ printExpressionBuffer() } void -printOneCodeBuffer(codeSegment, bufferNum) - codeSegmentType *codeSegment; - int bufferNum; +printOneCodeBuffer(codeSegmentType *codeSegment, int bufferNum) { int line; int i; @@ -1190,8 +1125,7 @@ printOneCodeBuffer(codeSegment, bufferNum) } void -printCodeBufferSection(codeBufferSection) - codeRegionType *codeBufferSection; +printCodeBufferSection(codeRegionType *codeBufferSection) { bool anyCodeThereFlag; int i; @@ -1209,7 +1143,7 @@ printCodeBufferSection(codeBufferSection) } void -printCodeBuffers() +printCodeBuffers(void) { printf("absolute code:\n"); printCodeBufferSection(&absoluteCodeRegion); diff --git a/debugPrintSD_6502.c b/debugPrintSD_6502.c index d6b8cd1..234ad7d 100644 --- a/debugPrintSD_6502.c +++ b/debugPrintSD_6502.c @@ -39,9 +39,14 @@ int tablevel; /* Fundamental nop print operation */ #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } - void -printCondition(condition) - conditionType condition; + +extern void tab (void); +extern void printExpression (expressionType *expression); +extern void printIdentifierList (identifierListType *identifierList); +extern void printBlock (blockType *block); + +void +printCondition(conditionType condition) { /* This table MUST be maintained congruently with the definition of the enumerated type 'conditionType'. */ @@ -70,8 +75,7 @@ printCondition(condition) } void -printOperandKind(kind) - operandKindType kind; +printOperandKind(operandKindType kind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'operandKindType'. */ @@ -97,8 +101,7 @@ printOperandKind(kind) } void -printToken(token) - int token; +printToken(int token) { /* This table MUST be maintained congruently with the set of '#define's in the file 'y.tab.h' as produced by yacc. */ @@ -193,8 +196,7 @@ printToken(token) } void -printOperand(operand) - operandType *operand; +printOperand(operandType *operand) { nullPrint(operand); tab(); printf("(operand: ["); diff --git a/driver.c b/driver.c index 7edef93..ad1c084 100644 --- a/driver.c +++ b/driver.c @@ -38,8 +38,7 @@ char *m68000 = "68000"; char **mlist; -main(argc, argv) - char **argv; +main(int argc, char **argv) { char *processor = m6502; int i; diff --git a/emitBranch_6502.c b/emitBranch_6502.c index 1cf71e6..6cd2d29 100644 --- a/emitBranch_6502.c +++ b/emitBranch_6502.c @@ -37,11 +37,16 @@ branching from the current location given a condition to branch upon and a target address. */ - void -emitRelativeBranch(condition, target, fixupLocation) - conditionType condition; - valueType *target; - valueType fixupLocation[COMPOUND_BRANCH_MAX]; + +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) { int i; @@ -139,14 +144,12 @@ emitRelativeBranch(condition, target, fixupLocation) /* emitJump emits a 6502 jump instruction given the target address */ simpleFixupListType * -emitJump(target, previousFixups) - valueType *target; - simpleFixupListType *previousFixups; +emitJump(valueType *target, simpleFixupListType *previousFixups) { simpleFixupListType *result; valueType picFixup[COMPOUND_BRANCH_MAX]; - simpleFixupListType *buildSimpleFixupList(); + simpleFixupListType *buildSimpleFixupList(valueType locationToFixup, simpleFixupListType *previousList); #define JUMP_OPCODE 0x4C diff --git a/emitStuff.c b/emitStuff.c index 31472b6..c100d6d 100644 --- a/emitStuff.c +++ b/emitStuff.c @@ -62,10 +62,19 @@ /* incarnateCodeBuffer causes code buffer space to actually be allocated */ - void -incarnateCodeBuffer(bufferNum, bufferKind) - int bufferNum; - codeBufferKindType bufferKind; + +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) { codeSegmentType *newCodeSegment; codeBufferType *newCodeBuffer; @@ -88,9 +97,7 @@ incarnateCodeBuffer(bufferNum, bufferKind) care to make sure said buffer actually exists before using it. */ void -putByte(address, byteValue) - addressType address; - byte byteValue; +putByte(addressType address, byte byteValue) { int bufferNum; int bufferPos; @@ -131,9 +138,7 @@ putByte(address, byteValue) buffer */ void -mapByte(address, byteValue) - int address; - byte byteValue; +mapByte(int address, byte byteValue) { if (address < MAXIMUM_ALLOWED_STRUCT_SIZE) structScratchBuffer[address] = byteValue; @@ -144,8 +149,7 @@ mapByte(address, byteValue) code buffer or the current struct assembly buffer */ void -emitByte(byteValue) - byte byteValue; +emitByte(byte byteValue) { if (debug || emitPrint) if (structNestingDepth == 0) @@ -165,8 +169,7 @@ emitByte(byteValue) /* emitWord similarly emits a word */ void -emitWord(wordValue) - wordType wordValue; +emitWord(wordType wordValue) { byteToWordType convert; int loByte, hiByte; @@ -216,8 +219,7 @@ emitWord(wordValue) /* emitLong similarly emits a long */ void -emitLong(longValue) - longType longValue; +emitLong(longType longValue) { byteToLongType convert; int loByte, secondByte, thirdByte, hiByte; @@ -286,8 +288,7 @@ emitLong(longValue) /* emitByteValue takes the byte to be emitted out of a 'valueType' */ void -emitByteValue(byteValue) - valueType *byteValue; +emitByteValue(valueType *byteValue) { if (byteValue->kindOfValue == ABSOLUTE_VALUE || byteValue->kindOfValue == RELOCATABLE_VALUE || byteValue->kindOfValue == UNDEFINED_VALUE) { @@ -313,8 +314,7 @@ emitByteValue(byteValue) /* emitString similarly spits out a string of bytes */ void -emitString(string) - stringType *string; +emitString(stringType *string) { if (debug || emitPrint) if (structNestingDepth == 0) @@ -342,8 +342,7 @@ emitString(string) /* emitWordValue emits a word out of a 'valueType' */ void -emitWordValue(wordValue) - valueType *wordValue; +emitWordValue(valueType *wordValue) { if (wordValue->kindOfValue == ABSOLUTE_VALUE || wordValue->kindOfValue == RELOCATABLE_VALUE || wordValue->kindOfValue == UNDEFINED_VALUE) { @@ -369,8 +368,7 @@ emitWordValue(wordValue) /* emitLongValue emits a long out of a 'valueType' */ void -emitLongValue(longValue) - valueType *longValue; +emitLongValue(valueType *longValue) { if (longValue->kindOfValue == ABSOLUTE_VALUE || longValue->kindOfValue == RELOCATABLE_VALUE || longValue->kindOfValue == UNDEFINED_VALUE) { @@ -396,9 +394,7 @@ emitLongValue(longValue) /* pokeByteValue is like 'emitByte' but it's random access */ void -pokeByteValue(location, value) - addressType location; - valueType *value; +pokeByteValue(addressType location, valueType *value) { currentLocationCounter.value = location; emitByteValue(value); @@ -408,9 +404,7 @@ pokeByteValue(location, value) /* ditto pokeWordValue */ void -pokeWordValue(location, value) - addressType location; - valueType *value; +pokeWordValue(addressType location, valueType *value) { currentLocationCounter.value = location; emitWordValue(value); @@ -420,9 +414,7 @@ pokeWordValue(location, value) /* ditto pokeLongValue */ void -pokeLongValue(location, value) - addressType location; - valueType *value; +pokeLongValue(addressType location, valueType *value) { currentLocationCounter.value = location; emitLongValue(value); @@ -433,9 +425,7 @@ pokeLongValue(location, value) relative branches */ void -pokeRelativeByteValue(location, value) - addressType location; - valueType *value; +pokeRelativeByteValue(addressType location, valueType *value) { int offset; @@ -456,9 +446,7 @@ pokeRelativeByteValue(location, value) relative branches */ void -pokeRelativeWordValue(location, value) - addressType location; - valueType *value; +pokeRelativeWordValue(addressType location, valueType *value) { int offset; @@ -475,8 +463,7 @@ pokeRelativeWordValue(location, value) /* getByte fetches a byte back out of the labyrinth of code buffers */ byte -getByte(address) - addressType address; +getByte(addressType address) { int bufferNum; int bufferPos; @@ -494,8 +481,7 @@ getByte(address) } void -emitRelativeByteOffset(target) - valueType *target; +emitRelativeByteOffset(valueType *target) { int saveTargetOffset; @@ -512,8 +498,7 @@ emitRelativeByteOffset(target) } void -emitRelativeWordOffset(target) - valueType *target; +emitRelativeWordOffset(valueType *target) { int saveTargetOffset; @@ -531,9 +516,7 @@ emitRelativeWordOffset(target) has become known. */ void -fixupBranch(location, target) - valueType location[COMPOUND_BRANCH_MAX]; - valueType target; +fixupBranch(valueType *location, valueType target) { valueType saveCurrentLocation; int saveTargetOffset; @@ -554,9 +537,7 @@ fixupBranch(location, target) /* fixupJump similarly repairs a jump */ void -fixupJump(locations, target) - simpleFixupListType *locations; - valueType target; +fixupJump(simpleFixupListType *locations, valueType target) { valueType saveCurrentLocation; simpleFixupListType *oldLocation; diff --git a/encode.c b/encode.c index 06df4cf..b44c4f8 100644 --- a/encode.c +++ b/encode.c @@ -39,9 +39,20 @@ bool encodingFunction; - bool -encodeByte(aByte) - byte aByte; + +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) { if (expressionBufferSize < EXPRESSION_BUFFER_LIMIT) { expressionBuffer[expressionBufferSize++] = aByte; @@ -53,8 +64,7 @@ encodeByte(aByte) } bool -encodeBigword(bigword) - int bigword; +encodeBigword(int bigword) { int i; for (i=0; ibinop != ASSIGN_ASSIGN) { @@ -83,10 +92,9 @@ encodeAssignmentTerm(assignmentTerm) } bool -encodeBinopTerm(binopTerm) - binopTermType *binopTerm; +encodeBinopTerm(binopTermType *binopTerm) { - bool encodeExpression(); + bool encodeExpression(expressionType *expression); nullEncode(binopTerm); return ( @@ -98,8 +106,7 @@ encodeBinopTerm(binopTerm) } bool -encodeCondition(condition) - conditionType condition; +encodeCondition(conditionType condition) { return( encodeByte(CONDITION_CODE_TAG) && @@ -108,8 +115,7 @@ encodeCondition(condition) } int -functionNumber(function) - functionDefinitionType *function; +functionNumber(functionDefinitionType *function) { if (function->ordinal == -1) { function->ordinal = externalFunctionCount++; @@ -126,8 +132,7 @@ functionNumber(function) } bool -encodeFunctionCall(functionCall) - functionCallTermType *functionCall; +encodeFunctionCall(functionCallTermType *functionCall) { functionDefinitionType *theFunction; int functionOrdinal; @@ -177,14 +182,13 @@ encodeFunctionCall(functionCall) } bool -encodeHere() +encodeHere(void) { return(encodeByte(HERE_TAG)); } bool -encodeIdentifier(identifier) - symbolTableEntryType *identifier; +encodeIdentifier(symbolTableEntryType *identifier) { symbolInContextType *workingContext; environmentType *saveEnvironment; @@ -248,8 +252,7 @@ encodeIdentifier(identifier) } bool -encodeNumber(number) - numberTermType number; +encodeNumber(numberTermType number) { return( encodeByte(NUMBER_TAG) && @@ -258,8 +261,7 @@ encodeNumber(number) } bool -encodeRelocatableNumber(number) - numberTermType number; +encodeRelocatableNumber(numberTermType number) { return( encodeByte(RELOCATABLE_TAG) && @@ -268,8 +270,7 @@ encodeRelocatableNumber(number) } bool -encodeOperand(operand) - operandType *operand; +encodeOperand(operandType *operand) { switch (operand->kindOfOperand) { case EXPRESSION_OPND: @@ -303,8 +304,7 @@ encodeOperand(operand) } bool -encodePostopTerm(postopTerm) - postOpTermType *postopTerm; +encodePostopTerm(postOpTermType *postopTerm) { nullEncode(postopTerm); return( @@ -315,8 +315,7 @@ encodePostopTerm(postopTerm) } bool -encodePreopTerm(preopTerm) - preOpTermType *preopTerm; +encodePreopTerm(preOpTermType *preopTerm) { nullEncode(preopTerm); return( @@ -327,8 +326,7 @@ encodePreopTerm(preopTerm) } bool -encodeString(string) - stringType *string; +encodeString(stringType *string) { if (!encodeByte(STRING_TAG)) return(FALSE); @@ -340,8 +338,7 @@ encodeString(string) } bool -encodeUnopTerm(unopTerm) - unopTermType *unopTerm; +encodeUnopTerm(unopTermType *unopTerm) { nullEncode(unopTerm); return( @@ -352,8 +349,7 @@ encodeUnopTerm(unopTerm) } bool -encodeValue(value) - valueType *value; +encodeValue(valueType *value) { switch (value->kindOfValue) { case ABSOLUTE_VALUE: @@ -389,8 +385,7 @@ encodeValue(value) } bool -encodeExpression(expression) - expressionType *expression; +encodeExpression(expressionType *expression) { nullEncode(expression); switch (expression->kindOfTerm) { @@ -460,8 +455,7 @@ encodeExpression(expression) } bool -encodeAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +encodeAssertStatement(assertStatementBodyType *assertStatement) { return( encodeByte(ASSERT_TAG) && @@ -471,8 +465,7 @@ encodeAssertStatement(assertStatement) } bool -encodeFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +encodeFreturnStatement(freturnStatementBodyType *freturnStatement) { return( encodeByte(FRETURN_TAG) && @@ -481,8 +474,7 @@ encodeFreturnStatement(freturnStatement) } bool -encodeMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +encodeMdefineStatement(defineStatementBodyType *mdefineStatement) { return( encodeByte(MDEFINE_TAG) && @@ -492,8 +484,7 @@ encodeMdefineStatement(mdefineStatement) } bool -encodeMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { return( encodeByte(MDOUNTIL_TAG) && @@ -503,8 +494,7 @@ encodeMdoUntilStatement(mdoUntilStatement) } bool -encodeMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +encodeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { return( encodeByte(MDOWHILE_TAG) && @@ -514,8 +504,7 @@ encodeMdoWhileStatement(mdoWhileStatement) } bool -encodeMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +encodeMforStatement(mforStatementBodyType *mforStatement) { return( encodeByte(MFOR_TAG) && @@ -527,8 +516,7 @@ encodeMforStatement(mforStatement) } bool -encodeMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +encodeMifStatement(mifStatementBodyType *mifStatement) { return( encodeByte(MIF_TAG) && @@ -539,8 +527,7 @@ encodeMifStatement(mifStatement) } bool -encodeMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +encodeMswitchStatement(mswitchStatementBodyType *mswitchStatement) { caseListType *caseList; caseType *theCase; @@ -564,8 +551,7 @@ encodeMswitchStatement(mswitchStatement) } bool -encodeMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +encodeMvariableStatement(mvariableStatementBodyType *mvariableStatement) { int length; @@ -585,8 +571,7 @@ encodeMvariableStatement(mvariableStatement) } bool -encodeMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement) { return( encodeByte(MWHILE_TAG) && @@ -596,8 +581,7 @@ encodeMwhileStatement(mwhileStatement) } bool -encodeStatement(statement) - statementType *statement; +encodeStatement(statementType *statement) { switch(statement->kindOfStatement) { @@ -677,8 +661,7 @@ encodeStatement(statement) } bool -encodeBlock(block) - blockType *block; +encodeBlock(blockType *block) { if (!encodeByte(BLOCK_TAG)) return(FALSE); diff --git a/errorStuff.c b/errorStuff.c index 968fe56..a2d064d 100644 --- a/errorStuff.c +++ b/errorStuff.c @@ -39,7 +39,12 @@ bool nullStatementFlag; input up to the end of the line, in a (probably futile) effort to recover from the booboo. */ - void + +void verror (errorType theError, va_list ap); +void fatalError (errorType theError, ...); +extern void chokePukeAndDie (void); + +void puntOnError(errorType theError, ...) { va_list ap; @@ -289,8 +294,7 @@ fatalSystemError(errorType theError, ...) the error message as a string (this is almost always 'syntax error'). */ void -yyerror(s) - char *s; +yyerror(char *s) { printf("\"%s\", line %d: %s\n", currentFileName, currentLineNumber,s); fflush(stdout); @@ -304,8 +308,7 @@ yyerror(s) in a sentence). */ char * -usageString(usageKind) - symbolUsageKindType usageKind; +usageString(symbolUsageKindType usageKind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'symbolUsageKindType'. */ @@ -336,8 +339,7 @@ usageString(usageKind) /* valueKindString similarly deals with the different kinds of values. */ char * -valueKindString(valueKind) - valueKindType valueKind; +valueKindString(valueKindType valueKind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -366,8 +368,7 @@ valueKindString(valueKind) /* assignmentString similarly handles assignments */ char * -assignmentString(assignment) - assignmentKindType assignment; +assignmentString(assignmentKindType assignment) { /* This table MUST be maintained congruently with the definition of the enumerated type 'assignmentKindType'. */ diff --git a/expressionSemantics.c b/expressionSemantics.c index 201a0df..a861662 100644 --- a/expressionSemantics.c +++ b/expressionSemantics.c @@ -64,10 +64,32 @@ stringType *dbString; #define moreStuff(f) (generatingFixup ? moreExpression(f) : moreText(f)) #define moreStuff1(f,x) (generatingFixup? moreExpression(f,x) : moreText(f,x)) - anyOldThing * -arrayLookup(arrayTerm, kindOfThing) - arrayTermType *arrayTerm; - valueKindType *kindOfThing; + +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) { valueType *arrayValue; valueType *indexValue; @@ -124,8 +146,7 @@ arrayLookup(arrayTerm, kindOfThing) } valueType * -evaluateArrayTerm(arrayTerm) - arrayTermType *arrayTerm; +evaluateArrayTerm(arrayTermType *arrayTerm) { anyOldThing *resultThing; valueKindType kindOfResult; @@ -169,9 +190,7 @@ evaluateArrayTerm(arrayTerm) } valueType * -evaluateAssignmentTerm(assignmentTerm, kindOfFixup) - binopTermType *assignmentTerm; - fixupKindType kindOfFixup; +evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup) { symbolTableEntryType *targetSymbol; valueType *target; @@ -363,10 +382,7 @@ evaluateAssignmentTerm(assignmentTerm, kindOfFixup) } valueType * -evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) - binopTermType *binopTerm; - bool isTopLevel; - fixupKindType kindOfFixup; +evaluateBinopTerm(binopTermType *binopTerm, bool isTopLevel, fixupKindType kindOfFixup) { valueType *leftOperand; valueType *rightOperand; @@ -580,18 +596,14 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) } valueType * -evaluateCondition(condition) - conditionType condition; +evaluateCondition(conditionType condition) { expand(moreExpression("%s", conditionString(condition))); return(newValue(CONDITION_VALUE, condition, EXPRESSION_OPND)); } valueType * -evaluateBuiltInFunctionCall(workingContext, parameters, kindOfFixup) - symbolInContextType *workingContext; - operandListType *parameters; - fixupKindType kindOfFixup; +evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup) { sideEffectFlag = TRUE; return((*builtInFunctionTable[workingContext->value->value]. @@ -599,10 +611,7 @@ evaluateBuiltInFunctionCall(workingContext, parameters, kindOfFixup) } valueType * -evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) - functionCallTermType *functionCall; - fixupKindType kindOfFixup; - bool isStandalone; +evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone) { functionDefinitionType *theFunction; int numberBound; @@ -682,7 +691,7 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) } valueType * -evaluateHere() +evaluateHere(void) { valueType *result; @@ -694,10 +703,7 @@ evaluateHere() } valueType * -evaluateIdentifier(identifier, isTopLevel, kindOfFixup) - symbolTableEntryType *identifier; - bool isTopLevel; - fixupKindType kindOfFixup; +evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup) { symbolInContextType *workingContext; valueType *resultValue; @@ -821,16 +827,14 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup) } valueType * -evaluateNumber(number) - numberTermType number; +evaluateNumber(numberTermType number) { expand(moreExpression("0x%x", number)); return(newValue(ABSOLUTE_VALUE, number, EXPRESSION_OPND)); } valueType * -evaluatePostopTerm(postopTerm) - postOpTermType *postopTerm; +evaluatePostopTerm(postOpTermType *postopTerm) { valueType *theOperand; valueType **theOperandPtr; @@ -897,8 +901,7 @@ evaluatePostopTerm(postopTerm) } valueType * -evaluatePreopTerm(preopTerm) - preOpTermType *preopTerm; +evaluatePreopTerm(preOpTermType *preopTerm) { valueType *theOperand; valueType *result; @@ -965,8 +968,7 @@ evaluatePreopTerm(preopTerm) } valueType * -evaluateString(string) - stringType *string; +evaluateString(stringType *string) { stringType *newString; @@ -977,9 +979,7 @@ evaluateString(string) } valueType * -evaluateUnopTerm(unopTerm, kindOfFixup) - unopTermType *unopTerm; - fixupKindType kindOfFixup; +evaluateUnopTerm(unopTermType *unopTerm, fixupKindType kindOfFixup) { valueType *theOperand; valueKindType resultKindOfValue; @@ -1031,11 +1031,7 @@ evaluateUnopTerm(unopTerm, kindOfFixup) } valueType * -evaluateExpressionInternally(expression, isTopLevel, kindOfFixup,isStandalone) - expressionType *expression; - bool isTopLevel; - fixupKindType kindOfFixup; - bool isStandalone; +evaluateExpressionInternally(expressionType *expression, bool isTopLevel, fixupKindType kindOfFixup, bool isStandalone) { valueType *result; @@ -1125,9 +1121,7 @@ evaluateExpressionInternally(expression, isTopLevel, kindOfFixup,isStandalone) } valueType * -evaluateExpression(expression, kindOfFixup) - expressionType *expression; - fixupKindType kindOfFixup; +evaluateExpression(expressionType *expression, fixupKindType kindOfFixup) { valueType *result; @@ -1148,8 +1142,7 @@ evaluateExpression(expression, kindOfFixup) } void -evaluateExpressionStandalone(expression) - expressionType *expression; +evaluateExpressionStandalone(expressionType *expression) { bool saveExpansion; valueType *expressionResult; @@ -1169,8 +1162,7 @@ evaluateExpressionStandalone(expression) } valueType * -evaluateDefineExpression(expression) - expressionType *expression; +evaluateDefineExpression(expressionType *expression) { nullEvaluate(expression); return(newValue(OPERAND_VALUE, buildOperand(EXPRESSION_OPND, @@ -1178,8 +1170,7 @@ evaluateDefineExpression(expression) } valueType * -evaluateSelectionList(selectionList) - selectionListType *selectionList; +evaluateSelectionList(selectionListType *selectionList) { int offset; diff --git a/expressionSemantics.h b/expressionSemantics.h index e6b004f..cd3edae 100644 --- a/expressionSemantics.h +++ b/expressionSemantics.h @@ -9,7 +9,7 @@ valueType *evaluateBinopTerm(binopTermType *assignmentTerm, bool isTopLevel, fix valueType *evaluateCondition(conditionType condition); valueType *evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup); valueType *evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone); -valueType *evaluateHere(); +valueType *evaluateHere(void); valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); valueType *evaluateNumber(numberTermType number); valueType *evaluatePostopTerm(postOpTermType *postopTerm); diff --git a/fixups.c b/fixups.c index 4ea7138..5ee9e35 100644 --- a/fixups.c +++ b/fixups.c @@ -57,12 +57,19 @@ stringType *dbString = "graphics2.m"; The routines below collectively duplicate expressions for later evaluation. */ - expressionType * -generateFixupExpression(expression) - expressionType *expression; + +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 *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); generatingFixup = TRUE; result = duplicateExpressionForFixup(expression, TRUE, FALSE); @@ -71,10 +78,7 @@ generateFixupExpression(expression) } expressionType * -duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand) - expressionType *expression; - bool isTopLevel; - bool isSpecialFunctionOperand; +duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand) { expressionType *result; expressionType *originalResult; @@ -85,15 +89,15 @@ duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand) environmentType *saveEnvironment; bool saveExpansion; - operandType *duplicateOperandForFixup(); - symbolInContextType *getWorkingContext(); - functionCallTermType *duplicateFunctionCall(); - expressionType *duplicateArrayReference(); - valueType *evaluateIdentifier(); - valueType *evaluateHere(); - valueType *newValue(); - symbolTableEntryType *generateLocalLabel(); - stringType *saveString(); + 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); @@ -280,14 +284,13 @@ duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand) } functionCallTermType * -duplicateFunctionCall(functionCall) - functionCallTermType *functionCall; +duplicateFunctionCall(functionCallTermType *functionCall) { functionCallTermType *result; operandListType **argument; operandListType *parameterList; - operandListType *duplicateOperandForFixup(); + operandListType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); result = typeAlloc(functionCallTermType); result->functionName = functionCall->functionName; @@ -310,8 +313,7 @@ duplicateFunctionCall(functionCall) expressionType * -duplicateArrayReference(arrayTerm) - arrayTermType *arrayTerm; +duplicateArrayReference(arrayTermType *arrayTerm) { anyOldThing *resultThing; valueKindType kindOfResult; @@ -322,9 +324,9 @@ duplicateArrayReference(arrayTerm) bool saveExpansion; operandType *newOperand; - valueType *newValue(); - operandType *duplicateOperandForFixup(); - anyOldThing *arrayLookup(); + 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); diff --git a/garbage.c b/garbage.c index 2660acb..bb9705d 100644 --- a/garbage.c +++ b/garbage.c @@ -33,11 +33,14 @@ #define nullFree(thing) if (thing == NULL) return; - void -freeArrayTerm(arrayTerm) - arrayTermType *arrayTerm; + +extern void botch (char *message, ...); +extern void freeOperand (operandType *operand); + +void +freeArrayTerm(arrayTermType *arrayTerm) { - void freeExpression(); + void freeExpression(expressionType *expression); nullFree(arrayTerm); freeExpression(arrayTerm->arrayName); @@ -46,10 +49,9 @@ freeArrayTerm(arrayTerm) } void -freeAssignmentTerm(assignmentTerm) - binopTermType *assignmentTerm; +freeAssignmentTerm(binopTermType *assignmentTerm) { - void freeExpression(); + void freeExpression(expressionType *expression); nullFree(assignmentTerm); freeExpression(assignmentTerm->rightArgument); @@ -57,10 +59,9 @@ freeAssignmentTerm(assignmentTerm) } void -freeBinopTerm(binopTerm) - binopTermType *binopTerm; +freeBinopTerm(binopTermType *binopTerm) { - void freeExpression(); + void freeExpression(expressionType *expression); nullFree(binopTerm); freeExpression(binopTerm->leftArgument); @@ -70,10 +71,9 @@ freeBinopTerm(binopTerm) } void -freeFunctionCall(functionCall) - functionCallTermType *functionCall; +freeFunctionCall(functionCallTermType *functionCall) { - void freeOperandList(); + void freeOperandList(operandListType *operandList); nullFree(functionCall); freeOperandList(functionCall->parameters); @@ -81,34 +81,30 @@ freeFunctionCall(functionCall) } void -freePostopTerm(postopTerm) - postOpTermType *postopTerm; +freePostopTerm(postOpTermType *postopTerm) { nullFree(postopTerm); free(postopTerm); } void -freePreopTerm(preopTerm) - preOpTermType *preopTerm; +freePreopTerm(preOpTermType *preopTerm) { nullFree(preopTerm); free(preopTerm); } void -freeString(string) - stringType *string; +freeString(stringType *string) { nullFree(string); free(string); } void -freeUnopTerm(unopTerm) - unopTermType *unopTerm; +freeUnopTerm(unopTermType *unopTerm) { - void freeExpression(); + void freeExpression(expressionType *expression); nullFree(unopTerm); freeExpression(unopTerm->unopArgument); @@ -116,8 +112,7 @@ freeUnopTerm(unopTerm) } void -freeExpression(expression) - expressionType *expression; +freeExpression(expressionType *expression) { nullFree(expression); switch (expression->kindOfTerm) { @@ -171,8 +166,7 @@ freeExpression(expression) } void -freeExpressionList(expressionList) - expressionListType *expressionList; +freeExpressionList(expressionListType *expressionList) { expressionListType *newExpressionList; @@ -185,8 +179,7 @@ freeExpressionList(expressionList) } void -freeIdentifierList(identifierList) - identifierListType *identifierList; +freeIdentifierList(identifierListType *identifierList) { identifierListType *newIdentifierList; @@ -198,25 +191,22 @@ freeIdentifierList(identifierList) } void -freeSelectionList(selectionList) - selectionListType *selectionList; +freeSelectionList(selectionListType *selectionList) { freeIdentifierList(selectionList); } void -freeBlock(block) - blockType *block; +freeBlock(blockType *block) { - void freeStatement(); + void freeStatement(statementType *statement); nullFree(block); freeStatement(block); } void -freeCase(aCase) - caseType *aCase; +freeCase(caseType *aCase) { freeExpressionList(aCase->caseTags); freeBlock(aCase->caseBody); @@ -224,8 +214,7 @@ freeCase(aCase) } void -freeCaseList(caseList) - caseListType *caseList; +freeCaseList(caseListType *caseList) { caseListType *newCaseList; @@ -238,37 +227,32 @@ freeCaseList(caseList) } void -freeOperandList(operandList) - operandListType *operandList; +freeOperandList(operandListType *operandList) { freeOperand(operandList); } void -freeMacro(operands) - operandListType *operands; +freeMacro(operandListType *operands) { freeOperandList(operands); } void -freeMachineInstruction(operands) - operandListType *operands; +freeMachineInstruction(operandListType *operands) { freeOperandList(operands); } void -freeAlignStatement(alignStatement) - alignStatementBodyType *alignStatement; +freeAlignStatement(alignStatementBodyType *alignStatement) { nullFree(alignStatement); freeExpression(alignStatement); } void -freeAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +freeAssertStatement(assertStatementBodyType *assertStatement) { nullFree(assertStatement); freeExpression(assertStatement->condition); @@ -277,16 +261,14 @@ freeAssertStatement(assertStatement) } void -freeBlockStatement(blockStatement) - blockStatementBodyType *blockStatement; +freeBlockStatement(blockStatementBodyType *blockStatement) { nullFree(blockStatement); freeExpressionList(blockStatement); } void -freeByteStatement(byteStatement) - byteStatementBodyType *byteStatement; +freeByteStatement(byteStatementBodyType *byteStatement) { byteStatementBodyType *newByteStatement; @@ -300,8 +282,7 @@ freeByteStatement(byteStatement) } void -freeConstrainStatement(constrainStatement) - constrainStatementBodyType *constrainStatement; +freeConstrainStatement(constrainStatementBodyType *constrainStatement) { nullFree(constrainStatement); freeExpression(constrainStatement->constraint); @@ -310,8 +291,7 @@ freeConstrainStatement(constrainStatement) } void -freeDbyteStatement(dbyteStatement) - dbyteStatementBodyType *dbyteStatement; +freeDbyteStatement(dbyteStatementBodyType *dbyteStatement) { dbyteStatementBodyType *newDbyteStatement; @@ -325,8 +305,7 @@ freeDbyteStatement(dbyteStatement) } void -freeDefineStatement(defineStatement) - defineStatementBodyType *defineStatement; +freeDefineStatement(defineStatementBodyType *defineStatement) { nullFree(defineStatement); freeExpression(defineStatement->theValue); @@ -334,8 +313,7 @@ freeDefineStatement(defineStatement) } void -freeDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +freeDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { nullFree(doUntilStatement); freeBlock(doUntilStatement->doUntilLoop); @@ -343,8 +321,7 @@ freeDoUntilStatement(doUntilStatement) } void -freeDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +freeDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { nullFree(doWhileStatement); freeBlock(doWhileStatement->doWhileLoop); @@ -352,23 +329,20 @@ freeDoWhileStatement(doWhileStatement) } void -freeExternStatement(externStatement) - externStatementBodyType *externStatement; +freeExternStatement(externStatementBodyType *externStatement) { freeIdentifierList(externStatement); } void -freeFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +freeFreturnStatement(freturnStatementBodyType *freturnStatement) { nullFree(freturnStatement); freeExpression(freturnStatement); } void -freeFunctionStatement(functionStatement) - functionStatementBodyType *functionStatement; +freeFunctionStatement(functionStatementBodyType *functionStatement) { nullFree(functionStatement); free(functionStatement->functionName); @@ -376,8 +350,7 @@ freeFunctionStatement(functionStatement) } void -freeIfStatement(ifStatement) - ifStatementBodyType *ifStatement; +freeIfStatement(ifStatementBodyType *ifStatement) { nullFree(ifStatement); if (ifStatement->consequence != NULL) @@ -389,16 +362,14 @@ freeIfStatement(ifStatement) } void -freeIncludeStatement(includeStatement) - includeStatementBodyType *includeStatement; +freeIncludeStatement(includeStatementBodyType *includeStatement) { nullFree(includeStatement); freeExpression(includeStatement); } void -freeInstructionStatement(instructionStatement) - instructionStatementBodyType *instructionStatement; +freeInstructionStatement(instructionStatementBodyType *instructionStatement) { nullFree(instructionStatement); switch(instructionStatement->kindOfInstruction) { @@ -419,8 +390,7 @@ freeInstructionStatement(instructionStatement) } void -freeLongStatement(longStatement) - longStatementBodyType *longStatement; +freeLongStatement(longStatementBodyType *longStatement) { longStatementBodyType *newLongStatement; @@ -434,16 +404,15 @@ freeLongStatement(longStatement) } void -freeMacroStatement(macroStatement) - macroStatementBodyType *macroStatement; +freeMacroStatement(macroStatementBodyType *macroStatement) { nullFree(macroStatement); free(macroStatement); } void -freeMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; /* MIST: shouldn't this be "mdefineStatementBodyType"? */ +freeMdefineStatement(defineStatementBodyType *mdefineStatement) + /* MIST: shouldn't this be "mdefineStatementBodyType"? */ { valueType *freeDefineExpression(); @@ -453,8 +422,7 @@ freeMdefineStatement(mdefineStatement) } void -freeMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +freeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { nullFree(mdoUntilStatement); freeBlock(mdoUntilStatement->mdoUntilLoop); @@ -462,8 +430,7 @@ freeMdoUntilStatement(mdoUntilStatement) } void -freeMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +freeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { nullFree(mdoWhileStatement); freeBlock(mdoWhileStatement->mdoWhileLoop); @@ -472,8 +439,7 @@ freeMdoWhileStatement(mdoWhileStatement) } void -freeMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +freeMifStatement(mifStatementBodyType *mifStatement) { nullFree(mifStatement); freeExpression(mifStatement->mifCondition); @@ -484,8 +450,7 @@ freeMifStatement(mifStatement) } void -freeMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +freeMswitchStatement(mswitchStatementBodyType *mswitchStatement) { freeExpression(mswitchStatement->switchExpression); freeCaseList(mswitchStatement->cases); @@ -493,8 +458,7 @@ freeMswitchStatement(mswitchStatement) } void -freeMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +freeMforStatement(mforStatementBodyType *mforStatement) { nullFree(mforStatement); freeExpression(mforStatement->initExpression); @@ -505,8 +469,7 @@ freeMforStatement(mforStatement) } void -freeMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +freeMvariableStatement(mvariableStatementBodyType *mvariableStatement) { nullFree(mvariableStatement); if ((int)mvariableStatement->theDimension != -1) @@ -516,8 +479,7 @@ freeMvariableStatement(mvariableStatement) } void -freeMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +freeMwhileStatement(mwhileStatementBodyType *mwhileStatement) { nullFree(mwhileStatement); freeExpression(mwhileStatement->mwhileCondition); @@ -526,38 +488,33 @@ freeMwhileStatement(mwhileStatement) } void -freeOrgStatement(orgStatement) - orgStatementBodyType *orgStatement; +freeOrgStatement(orgStatementBodyType *orgStatement) { nullFree(orgStatement); freeExpression(orgStatement); } void -freePerformStatement(performStatement) - performStatementBodyType *performStatement; +freePerformStatement(performStatementBodyType *performStatement) { nullFree(performStatement); freeExpression(performStatement); } void -freeRelStatement(relStatement) - relStatementBodyType *relStatement; +freeRelStatement(relStatementBodyType *relStatement) { } void -freeStartStatement(startStatement) - startStatementBodyType *startStatement; +freeStartStatement(startStatementBodyType *startStatement) { nullFree(startStatement); freeExpression(startStatement); } void -freeStringStatement(stringStatement) - stringStatementBodyType *stringStatement; +freeStringStatement(stringStatementBodyType *stringStatement) { stringStatementBodyType *newStringStatement; @@ -571,8 +528,7 @@ freeStringStatement(stringStatement) } void -freeStructStatement(structStatement) - structStatementBodyType *structStatement; +freeStructStatement(structStatementBodyType *structStatement) { nullFree(structStatement); freeBlock(structStatement->structBody); @@ -580,23 +536,20 @@ freeStructStatement(structStatement) } void -freeTargetStatement(targetStatement) - targetStatementBodyType *targetStatement; +freeTargetStatement(targetStatementBodyType *targetStatement) { nullFree(targetStatement); freeExpression(targetStatement); } void -freeUndefineStatement(undefineStatement) - undefineStatementBodyType *undefineStatement; +freeUndefineStatement(undefineStatementBodyType *undefineStatement) { freeIdentifierList(undefineStatement); } void -freeVariableStatement(variableStatement) - variableStatementBodyType *variableStatement; +freeVariableStatement(variableStatementBodyType *variableStatement) { nullFree(variableStatement); if ((int)variableStatement->theDimension != -1) @@ -606,8 +559,7 @@ freeVariableStatement(variableStatement) } void -freeWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +freeWhileStatement(whileStatementBodyType *whileStatement) { nullFree(whileStatement); freeBlock(whileStatement->whileLoop); @@ -615,8 +567,7 @@ freeWhileStatement(whileStatement) } void -freeWordStatement(wordStatement) - wordStatementBodyType *wordStatement; +freeWordStatement(wordStatementBodyType *wordStatement) { wordStatementBodyType *newWordStatement; @@ -630,9 +581,7 @@ freeWordStatement(wordStatement) } void -freeStatementBody(kind, body) - statementKindType kind; - statementBodyType body; +freeStatementBody(statementKindType kind, statementBodyType body) { switch (kind) { @@ -795,8 +744,7 @@ freeStatementBody(kind, body) } void -freeLabelList(labelList) - labelListType *labelList; +freeLabelList(labelListType *labelList) { labelListType *nextLabel; @@ -808,8 +756,7 @@ freeLabelList(labelList) } void -freeStatement(statement) - statementType *statement; +freeStatement(statementType *statement) { statementType *newStatement; @@ -824,11 +771,10 @@ freeStatement(statement) } void -freeArray(array) - arrayType *array; +freeArray(arrayType *array) { int i; - void freeValue(); + void freeValue(valueType *value); if (array->arraySize > 0) { for (i=0; iarraySize; i++) @@ -839,8 +785,7 @@ freeArray(array) } void -freeValue(value) - valueType *value; +freeValue(valueType *value) { if (value->kindOfValue == STRING_VALUE) freeString(value->value); diff --git a/initialize.c b/initialize.c index e7deac7..1333f42 100644 --- a/initialize.c +++ b/initialize.c @@ -39,17 +39,27 @@ extern int yydebug; static fileNameListType *bottomOfInputFileStack; static char *outputFileName; - void -chokePukeAndDie() + +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 +chokePukeAndDie(void) { unlink(outputFileName); exit(1); } void -initializeStuff(argc, argv) - int argc; - char *argv[]; +initializeStuff(int argc, char **argv) { int i; int j; @@ -62,13 +72,13 @@ initializeStuff(argc, argv) char *symbolDumpFileName; bool dontUnlinkTempFiles; - void createHashTables(); - void installBuiltInFunctions(); - void installPredefinedSymbols(); - void installCommandLineDefineSymbols(); - void openFirstInputFile(); - void queueInputFile(); - void noteCommandLineDefine(); + 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; @@ -381,13 +391,13 @@ initializeStuff(argc, argv) } void -installBuiltInFunctions() +installBuiltInFunctions(void) { int i; symbolTableEntryType *newFunction; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); + 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]. @@ -401,13 +411,13 @@ installBuiltInFunctions() } void -installPredefinedSymbols() +installPredefinedSymbols(void) { int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); + 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]. @@ -420,13 +430,13 @@ installPredefinedSymbols() } void -installCommandLineDefineSymbols() +installCommandLineDefineSymbols(void) { int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); while (commandLineDefines != NULL) { newSymbol = lookupOrEnterSymbol(commandLineDefines->name, @@ -439,7 +449,7 @@ installCommandLineDefineSymbols() } void -createHashTables() +createHashTables(void) { opcodeTableEntryType *newOpcodeEntry; keywordTableEntryType *newKeywordEntry; @@ -459,8 +469,7 @@ createHashTables() } void -queueInputFile(name) - char *name; +queueInputFile(char *name) { fileNameListType *newFileName; @@ -479,7 +488,7 @@ queueInputFile(name) } void -openFirstInputFile() +openFirstInputFile(void) { if (inputFileStack == NULL) { inputFileStack = typeAlloc(fileNameListType); @@ -504,8 +513,7 @@ openFirstInputFile() } bool -isDotMName(fileName) - stringType *fileName; +isDotMName(stringType *fileName) { int length; @@ -515,10 +523,7 @@ isDotMName(fileName) } bool -parseCommandLineDefine(arg, name, value) - char *arg; - char **name; - int *value; +parseCommandLineDefine(char *arg, char **name, int *value) { char *ptr; char c; @@ -561,14 +566,13 @@ parseCommandLineDefine(arg, name, value) } void -noteCommandLineDefine(arg) - char *arg; +noteCommandLineDefine(char *arg) { char *name; int value; commandLineDefineType *newCommandLineDefine; - bool parseCommandLineDefine(); + bool parseCommandLineDefine(char *arg, char **name, int *value); if (parseCommandLineDefine(arg, &name, &value)) { newCommandLineDefine = typeAlloc(commandLineDefineType); diff --git a/lexer.c b/lexer.c index a49c84d..6368c38 100644 --- a/lexer.c +++ b/lexer.c @@ -52,8 +52,26 @@ static int lineBufferPtr = 0; #define isNumeric(c) (numericCharacterTable[c]) #define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) - int -yylex() + +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) { int result; @@ -67,11 +85,11 @@ yylex() } int -lexer() +lexer(void) { char c; - char skipWhitespaceAndComments(); + char skipWhitespaceAndComments(void); if ((c = skipWhitespaceAndComments()) == EOF) return(lexLiteral(c)); @@ -80,15 +98,15 @@ lexer() } void -initializeLexDispatchTable() +initializeLexDispatchTable(void) { int c; - int lexIdentifier(); - int lexNumber(); - int lexLiteral(); - int lexCharacterConstant(); - int lexStringConstant(); - int lexOperator(); + 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=='$') @@ -107,8 +125,7 @@ initializeLexDispatchTable() } bool -isMacrossLiteralCharacter(c) - char c; +isMacrossLiteralCharacter(char c) { return(c==':' || c==',' || c=='@' || c=='#' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || @@ -116,9 +133,7 @@ isMacrossLiteralCharacter(c) } void -snarfAlphanumericString(c, buffer) - char c; - char *buffer; +snarfAlphanumericString(char c, char *buffer) { char *bufferPtr; @@ -135,10 +150,9 @@ snarfAlphanumericString(c, buffer) char nameBuffer[MAX_NAME_SIZE+1]; int -lexIdentifier(c) - char c; +lexIdentifier(char c) { - char *saveString(); + char *saveString(char *s); int hashValue; snarfAlphanumericString(c, nameBuffer); @@ -161,8 +175,7 @@ lexIdentifier(c) char numberBuffer[MAX_NAME_SIZE+1]; int -lexNumber(c) - char c; +lexNumber(char c) { int base; int start; @@ -189,9 +202,7 @@ lexNumber(c) } int -fancyAtoI(buffer, base) - char *buffer; - int base; +fancyAtoI(char *buffer, int base) { int value; int digit; @@ -209,8 +220,7 @@ fancyAtoI(buffer, base) } int -digitValue(c) - char c; +digitValue(char c) { if (isNumeric(c)) return(c - '0'); @@ -219,8 +229,7 @@ digitValue(c) } int -lexLiteral(c) - char c; +lexLiteral(char c) { static bool passedEnd = FALSE; @@ -240,7 +249,7 @@ lexLiteral(c) } int -lexCharacterConstant() +lexCharacterConstant(void) { char c; @@ -256,13 +265,12 @@ lexCharacterConstant() bool escaped; /* true if last string character read was an escape code. */ int -getStringCharacter(input) - FILE *input; +getStringCharacter(FILE *input) { char c; char *numberPtr; int result; - char controlCharacter(); + char controlCharacter(char c); escaped = FALSE; c = getNextChar(); @@ -292,7 +300,7 @@ getStringCharacter(input) char stringBuffer[MAX_NAME_SIZE + 1]; int -lexStringConstant() +lexStringConstant(void) { char *stringPtr; char c; @@ -309,8 +317,7 @@ lexStringConstant() } int -lexOperator(firstC) - char firstC; +lexOperator(char firstC) { char secondC; char thirdC; @@ -347,8 +354,7 @@ lexOperator(firstC) } char -controlCharacter(c) - char c; +controlCharacter(char c) { #define CONTROL_CHARACTER_MASK (~0100) @@ -356,7 +362,7 @@ controlCharacter(c) } char -skipWhitespaceAndComments() +skipWhitespaceAndComments(void) { char c; @@ -394,7 +400,7 @@ skipWhitespaceAndComments() } int -popInputFileStack() +popInputFileStack(void) { fileNameListType *oldFile; @@ -425,8 +431,7 @@ popInputFileStack() } void -pushInputFileStack(fileName) - stringType *fileName; +pushInputFileStack(stringType *fileName) { fileNameListType *newFileName; @@ -446,7 +451,7 @@ pushInputFileStack(fileName) } void -resynchronizeInput() +resynchronizeInput(void) { char c; while ((c = getNextChar())!='\n' && c!=EOF) @@ -458,8 +463,7 @@ resynchronizeInput() static bool previousLongLineFlag = FALSE; void -saveLineForListing(line) - stringType *line; +saveLineForListing(stringType *line) { if (!previousLongLineFlag) { putw(currentLocationCounter.value, saveFileForPass2); @@ -470,7 +474,7 @@ saveLineForListing(line) } void -saveEOLForListing() +saveEOLForListing(void) { putw(-1, saveFileForPass2); putw(includeNestingDepth, saveFileForPass2); @@ -478,9 +482,7 @@ saveEOLForListing() } void -saveIndexForListing(kindOfStatement, cumulativeLineNumber) - statementKindType kindOfStatement; - int cumulativeLineNumber; +saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber) { if (!amExpanding() || !notListable(kindOfStatement)) { putw(kindOfStatement, indexFileForPass2); @@ -493,8 +495,7 @@ saveIndexForListing(kindOfStatement, cumulativeLineNumber) } void -saveEndMifForListing(cumulativeLineNumber) - int cumulativeLineNumber; +saveEndMifForListing(int cumulativeLineNumber) { putw(MIF_STATEMENT, indexFileForPass2); putw(-1, indexFileForPass2); @@ -505,13 +506,13 @@ saveEndMifForListing(cumulativeLineNumber) } void -saveListingOff() +saveListingOff(void) { saveIndexForListing(-1, cumulativeLineNumber); } void -saveListingOn() +saveListingOn(void) { if (currentCodeMode == ABSOLUTE_BUFFER) saveIndexForListing(-1, cumulativeLineNumber); @@ -520,10 +521,7 @@ saveListingOn() } char * -myfgets(buffer, length, stream) - char *buffer; - int length; - FILE *stream; +myfgets(char *buffer, int length, FILE *stream) { char *result; char c; @@ -546,7 +544,7 @@ myfgets(buffer, length, stream) } int -readAnotherLine() +readAnotherLine(void) { int result; diff --git a/listing.c b/listing.c index 983ad96..d065289 100644 --- a/listing.c +++ b/listing.c @@ -44,8 +44,16 @@ static int nextMacroAddress; static int macroDepth; static int nextMacroDepth; - void -outputListing() + +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 +outputListing(void) { rewind(saveFileForPass2); rewind(indexFileForPass2); @@ -54,7 +62,7 @@ outputListing() } void -terminateListingFiles() +terminateListingFiles(void) { saveLineForListing("\n"); saveIndexForListing(NULL_STATEMENT, cumulativeLineNumber); @@ -96,7 +104,7 @@ terminateListingFiles() /* This is the most horrible piece of code I have ever written in my entire life -- cbm */ void -generateListing() +generateListing(void) { int sourceAddress; int sourceDepth; @@ -297,10 +305,7 @@ generateListing() bool longLineFlag; /* defined in lexer.c */ int -printMacroLine(numberOfBytes, byteAddress, kind) - int numberOfBytes; - int byteAddress; - statementKindType kind; +printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind) { macroAddress = nextMacroAddress; macroDepth = nextMacroDepth; @@ -312,11 +317,7 @@ printMacroLine(numberOfBytes, byteAddress, kind) } void -readSourceFileLine(sourceAddressPtr, sourceDepthPtr, lineBuffer, file) - int *sourceAddressPtr; - int *sourceDepthPtr; - char lineBuffer[]; - FILE *file; +readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char *lineBuffer, FILE *file) { char c; @@ -331,10 +332,7 @@ readSourceFileLine(sourceAddressPtr, sourceDepthPtr, lineBuffer, file) } void -readIndexFileLine(statementKindPtr, indexAddressPtr, indexLineNumberPtr) - statementKindType *statementKindPtr; - int *indexAddressPtr; - int *indexLineNumberPtr; +readIndexFileLine(statementKindType *statementKindPtr, int *indexAddressPtr, int *indexLineNumberPtr) { statementKindType statementKindRead; int indexAddressRead; @@ -353,11 +351,7 @@ readIndexFileLine(statementKindPtr, indexAddressPtr, indexLineNumberPtr) } int -printListingLine(numberOfBytes, byteAddress, text, kind) - int numberOfBytes; - int byteAddress; - char *text; - statementKindType kind; +printListingLine(int numberOfBytes, int byteAddress, char *text, statementKindType kind) { int i; @@ -408,8 +402,7 @@ printListingLine(numberOfBytes, byteAddress, text, kind) bool -isBlockOpener(statementKind) - statementKindType statementKind; +isBlockOpener(statementKindType statementKind) { return (statementKind==IF_STATEMENT || statementKind==WHILE_STATEMENT || @@ -428,8 +421,7 @@ isBlockOpener(statementKind) } bool -isBlankStatement(statementKind) - statementKindType statementKind; +isBlankStatement(statementKindType statementKind) { return( statementKind == DEFINE_STATEMENT || statementKind == NULL_STATEMENT || @@ -455,8 +447,7 @@ isBlankStatement(statementKind) } void -tabPrint(text) - stringType *text; +tabPrint(stringType *text) { int column; int spaces; @@ -477,16 +468,14 @@ tabPrint(text) } void -printNTimes(aChar, times) - char aChar; - int times; +printNTimes(char aChar, int times) { while (times-- > 0) moreText("%c", aChar, 0, 0); } void -tabIndent() +tabIndent(void) { printNTimes('\t', tabCount); } @@ -499,7 +488,7 @@ static char labelString[LINE_BUFFER_SIZE] = { '\0' }; static char *labelStringPtr = labelString; bool -labeledLine() +labeledLine(void) { return(labelStringPtr != labelString); } @@ -542,9 +531,7 @@ moreText(char *format, ...) } void -moreLabel(format, arg1) - char *format; - int arg1; +moreLabel(char *format, int arg1) { sprintf(labelStringPtr, format, arg1); labelStringPtr = labelString + strlen(labelString); @@ -554,7 +541,7 @@ static addressType savedCurrentLocationCounterValue; static int savedIncludeNestingDepth; void -startLine() +startLine(void) { printNTimes('+', macroCallDepth); savedCurrentLocationCounterValue = currentLocationCounter.value; @@ -562,7 +549,7 @@ startLine() } void -endLine() +endLine(void) { if (amListing()) { putw(savedCurrentLocationCounterValue, macroFileForPass2); @@ -574,16 +561,14 @@ endLine() } void -flushExpressionString() +flushExpressionString(void) { expressionStringPtr = expressionString; *expressionStringPtr = '\0'; } void -expandExpression(toBuffer, toBufferPtr) - char *toBuffer; - char **toBufferPtr; +expandExpression(char *toBuffer, char **toBufferPtr) { if (toBuffer == NULL) moreText("%s", expressionString, 0, 0); @@ -593,25 +578,20 @@ expandExpression(toBuffer, toBufferPtr) } void -expandNum(buffer, bufferPtr, n) - char *buffer; - char **bufferPtr; - int n; +expandNum(char *buffer, char **bufferPtr, int n) { moreTextOptional(buffer, bufferPtr, "%d", n, 0, 0); } void -flushOperand(n) - int n; +flushOperand(int n) { moreText("%s", operandBuffer[n], 0, 0); operandBuffer[n][0] = '\0'; } void -expandOperands(op) - int op; +expandOperands(int op) { int i; @@ -625,7 +605,7 @@ expandOperands(op) } void -expandLabel() +expandLabel(void) { moreText("%s", labelString, 0, 0); labelStringPtr = labelString; @@ -643,7 +623,7 @@ moreExpression(char *format, ...) } void -startLineMarked() +startLineMarked(void) { startLine(); if (amListing()) @@ -651,8 +631,7 @@ startLineMarked() } bool -notListable(statementKind) - statementKindType statementKind; +notListable(statementKindType statementKind) { return(!listableStatement(statementKind) && statementKind != INSTRUCTION_STATEMENT && diff --git a/listing.h b/listing.h index 3e94aa7..58ec521 100644 --- a/listing.h +++ b/listing.h @@ -6,9 +6,9 @@ * Glorious Future Year 1989 the vprintf function does almost exactly * what we want. */ -void outputListing(); -void terminateListingFiles(); -void generateListing(); +void outputListing(void); +void terminateListingFiles(void); +void generateListing(void); int printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind); void readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char lineBuffer[], FILE *file); void readIndexFileLine(statementKindType *statementKindPtr, int *indexAddressPtr, int *indexLineNumberPtr); @@ -17,22 +17,22 @@ bool isBlockOpener(statementKindType statementKind); bool isBlankStatment(statementKindType statementKind); void tabPrint(stringType *text); void printNTimes (char aChar, int times); -void tabIndent(); -bool labeledLine(); +void tabIndent(void); +bool labeledLine(void); void addText(char *buffer, char **bufferPtr, char *format, ...); void moreTextOptional(char *buffer, char **bufferPtr, char *format, ...); void moreText(char *format, ...); void moreLabel(char *format, int arg1); -void startLine(); -void endLine(); -void flushExpressionString(); +void startLine(void); +void endLine(void); +void flushExpressionString(void); void expandExpression(char *toBuffer, char **toBufferPtr); void expandNum(char *buffer, char **bufferPtr, int n); void flushOperand(int n); void expandOperands(int op); -void expandLabel(); +void expandLabel(void); void moreExpression(char *format, ...); -void startLineMarked(); +void startLineMarked(void); bool notListable(statementKindType statementKind); #endif diff --git a/lookups.c b/lookups.c index 216dd83..b286916 100644 --- a/lookups.c +++ b/lookups.c @@ -36,14 +36,24 @@ lists that are sorted alphabetically. */ - conditionType -lookupConditionCode(s, hashValue) - char *s; - int hashValue; + +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 +lookupConditionCode(char *s, int hashValue) { conditionTableEntryType *result; - genericTableEntryType *prehashedStringLookup(); + genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); result = (conditionTableEntryType *) prehashedStringLookup(s, conditionTable, hashValue); @@ -54,13 +64,11 @@ lookupConditionCode(s, hashValue) } int -lookupKeyword(s, hashValue) - char *s; - int hashValue; +lookupKeyword(char *s, int hashValue) { keywordTableEntryType *result; - genericTableEntryType *prehashedStringLookup(); + genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); result = (keywordTableEntryType *) prehashedStringLookup(s, keywordTable, hashValue); @@ -71,22 +79,18 @@ lookupKeyword(s, hashValue) } macroTableEntryType * -lookupMacroName(s, hashValue) - char *s; - int hashValue; +lookupMacroName(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(); + genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); return((macroTableEntryType *) prehashedStringLookup(s, macroTable, hashValue)); } opcodeTableEntryType * -lookupOpcode(s, hashValue) - char *s; - int hashValue; +lookupOpcode(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(); + genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); return((opcodeTableEntryType *) prehashedStringLookup(s, opcodeTable, hashValue)); @@ -97,14 +101,12 @@ lookupOpcode(s, hashValue) the given kind and return *that* */ symbolTableEntryType * -lookupOrEnterSymbol(s, kind) - stringType *s; - symbolUsageKindType kind; +lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind) { symbolTableEntryType *result; - genericTableEntryType *hashStringLookup(); - genericTableEntryType *hashStringEnter(); - symbolTableEntryType *buildSymbolTableEntry(); + 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++;*/ @@ -116,8 +118,7 @@ lookupOrEnterSymbol(s, kind) } void -pushSymbol(symbol) - symbolTableEntryType *symbol; +pushSymbol(symbolTableEntryType *symbol) { symbolInContextType *newContext; @@ -127,8 +128,7 @@ pushSymbol(symbol) } void -popSymbol(symbol) - symbolTableEntryType *symbol; +popSymbol(symbolTableEntryType *symbol) { symbolInContextType *deadContext; @@ -146,16 +146,15 @@ popSymbol(symbol) } macroTableEntryType * -createMacro(macroName) - stringType *macroName; +createMacro(stringType *macroName) { macroTableEntryType *result; symbolTableEntryType *testSymbol; - genericTableEntryType *hashStringLookup(); - genericTableEntryType *hashStringEnter(); - macroTableEntryType *buildMacroTableEntry(); - symbolTableEntryType *lookupOrEnterSymbol(); + 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) { @@ -179,10 +178,7 @@ createMacro(macroName) */ genericTableEntryType * -prehashedStringLookup(s, table, hashValue) - char *s; - genericTableEntryType *table[]; - int hashValue; +prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue) { genericTableEntryType *result; int test; @@ -202,17 +198,13 @@ prehashedStringLookup(s, table, hashValue) } genericTableEntryType * -hashStringLookup(s, table) - char *s; - genericTableEntryType *table[]; +hashStringLookup(char *s, genericTableEntryType **table) { return(prehashedStringLookup(s, table, hashString(s))); } genericTableEntryType * -hashStringEnter(entry, table) - genericTableEntryType *entry; - genericTableEntryType *table[]; +hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table) { genericTableEntryType *result; genericTableEntryType *oldResult; @@ -252,8 +244,7 @@ hashStringEnter(entry, table) } int -hashString(s) - char *s; +hashString(char *s) { unsigned result; @@ -264,9 +255,9 @@ hashString(s) } bool -strcmplc(s1, s2) /* string compare in lower case */ - char *s1; /* heavily optimized version */ - char *s2; +strcmplc(char *s1, char *s2) /* string compare in lower case */ + /* heavily optimized version */ + { char c1; int result; @@ -284,9 +275,9 @@ strcmplc(s1, s2) /* string compare in lower case */ } bool -strcmplct(s1, s2) /* For tables: s2 is already lower case */ - char *s1; /* heavily optimized version. */ - char *s2; +strcmplct(char *s1, char *s2) /* For tables: s2 is already lower case */ + /* heavily optimized version. */ + { char c1; int result; @@ -302,21 +293,18 @@ strcmplct(s1, s2) /* For tables: s2 is already lower case */ } void -purgeSymbol(symbol) - symbolTableEntryType *symbol; +purgeSymbol(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); if ((context = getWorkingContext(symbol)) != NULL) context->usage = DEAD_SYMBOL; } void -reincarnateSymbol(context, newUsage) - symbolInContextType *context; - symbolUsageKindType newUsage; +reincarnateSymbol(symbolInContextType *context, symbolUsageKindType newUsage) { context->attributes = 0; dupValue(context->value, UndefinedValue); @@ -329,12 +317,9 @@ reincarnateSymbol(context, newUsage) */ void -pushBinding(symbol, newBinding, newUsage) - symbolTableEntryType *symbol; - valueType *newBinding; - symbolUsageKindType newUsage; +pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage) { - valueType *newValue(); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); pushSymbol(symbol); if (newBinding == NULL) @@ -347,17 +332,13 @@ pushBinding(symbol, newBinding, newUsage) } void -popBinding(symbol) - symbolTableEntryType *symbol; +popBinding(symbolTableEntryType *symbol) { popSymbol(symbol); } int /* returns number of bindings completed, negative this if failure */ -bindMacroArguments(argumentList, parameterList, macroName) - argumentDefinitionListType *argumentList; - operandListType *parameterList; - stringType *macroName; +bindMacroArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName) { int numberBound; bool arrayTag; @@ -365,7 +346,7 @@ bindMacroArguments(argumentList, parameterList, macroName) valueType **arrayContents; int i; - valueType *newValue(); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); if (argumentList == NULL) arrayTag = FALSE; @@ -417,10 +398,7 @@ bindMacroArguments(argumentList, parameterList, macroName) } int /* returns number of bindings completed, negative this if failure */ -bindFunctionArguments(argumentList, parameterList, functionName) - argumentDefinitionListType *argumentList; - operandListType *parameterList; - stringType *functionName; +bindFunctionArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName) { valueType *argument; bool arrayTag; @@ -431,8 +409,8 @@ bindFunctionArguments(argumentList, parameterList, functionName) valueType *firstArgument; environmentType *saveEnvironment; - valueType *evaluateOperand(); - valueType *newValue(); + valueType *evaluateOperand(operandType *operand); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); if (argumentList == NULL) arrayTag = FALSE; @@ -515,9 +493,7 @@ bindFunctionArguments(argumentList, parameterList, functionName) } void -unbindArguments(argumentList, numberToUnbind) - argumentDefinitionListType *argumentList; - int numberToUnbind; +unbindArguments(argumentDefinitionListType *argumentList, int numberToUnbind) { while (argumentList != NULL && numberToUnbind-- > 0) { popBinding(argumentList->theArgument); @@ -528,8 +504,7 @@ unbindArguments(argumentList, numberToUnbind) } void -unbindLocalVariables(identifierList) - identifierListType *identifierList; +unbindLocalVariables(identifierListType *identifierList) { identifierListType *deadEntry; diff --git a/macrossTables_6502.c b/macrossTables_6502.c index 566e8ea..e31a1e2 100644 --- a/macrossTables_6502.c +++ b/macrossTables_6502.c @@ -205,20 +205,20 @@ int operandClassTable[] = { /* indexed by operandKindType */ BLOCK_OPND_BIT, }; -int actionsRelative(); -int actionsDir1(); -int actionsDir2(); -int actionsDirIndir(); -int actionsDirX1(); -int actionsDirX2(); -int actionsDirX3(); -int actionsDirY(); -int actionsImmDir(); -int actionsImmDirX(); -int actionsImmDirY(); -int actionsNone(); -int actionsIndex(); -int actionsImmIndex(); +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[])() = { @@ -303,53 +303,53 @@ valueType undefinedValueValue = { UNDEFINED_VALUE, 0, EXPRESSION_OPND }; valueType *UndefinedValue = &undefinedValueValue; -valueType *addressModeBIF(); -valueType *applyBIF(); -valueType *arrayLengthBIF(); -valueType *atasciiBIF(); -valueType *atasciiColorBIF(); -valueType *debugModeOffBIF(); -valueType *debugModeOnBIF(); -valueType *emitModeOffBIF(); -valueType *emitModeOnBIF(); -valueType *isAbsoluteValueBIF(); -valueType *isARegisterBIF(); -valueType *isBlockBIF(); -valueType *isBuiltInFunctionBIF(); -valueType *isConditionCodeBIF(); -valueType *isDefinedBIF(); -valueType *isDirectModeBIF(); -valueType *isExternalBIF(); -valueType *isFieldBIF(); -valueType *isFunctionBIF(); -valueType *isImmediateModeBIF(); -valueType *isIndexedModeBIF(); -valueType *isIndirectModeBIF(); -valueType *isPostIndexedModeBIF(); -valueType *isPreIndexedModeBIF(); -valueType *isRelocatableValueBIF(); -valueType *isStringBIF(); -valueType *isStructBIF(); -valueType *isSymbolBIF(); -valueType *isXIndexedModeBIF(); -valueType *isXRegisterBIF(); -valueType *isYIndexedModeBIF(); -valueType *isYRegisterBIF(); -valueType *listingOffBIF(); -valueType *listingOnBIF(); -valueType *makeArrayBIF(); -valueType *nthCharBIF(); -valueType *printfBIF(); -valueType *strcatBIF(); -valueType *strcmpBIF(); -valueType *strcmplcBIF(); -valueType *strlenBIF(); -valueType *substrBIF(); -valueType *symbolDefineBIF(); -valueType *symbolLookupBIF(); -valueType *symbolNameBIF(); -valueType *symbolUsageBIF(); -valueType *valueTypeBIF(); +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 { diff --git a/main.c b/main.c index c8c089e..800d818 100644 --- a/main.c +++ b/main.c @@ -30,16 +30,20 @@ #include "macrossTypes.h" #include "macrossGlobals.h" -main(argc, argv) - int argc; - char *argv[]; + +extern void initializeStuff (int argc, char **argv); +extern int yyparse (void); +extern void finishUp (void); +extern void chokePukeAndDie (void); + +main(int argc, char **argv) { #ifdef __APPLE__ char end = get_end(); #else extern char end; #endif - char *sbrk(); + char *sbrk(int); fflush(stdout); initializeStuff(argc, argv); @@ -55,7 +59,7 @@ main(argc, argv) } void -printVersion() +printVersion(void) { printf("Macross %s version 4.20.\n", TARGET_CPU_STRING); } diff --git a/malloc.c b/malloc.c index 14023b1..b3d4d43 100644 --- a/malloc.c +++ b/malloc.c @@ -80,7 +80,7 @@ union overhead { */ #define NBUCKETS 30 static union overhead *nextf[NBUCKETS]; -extern char *sbrk(); +extern char *sbrk(int); #ifdef MSTATS /* @@ -109,8 +109,7 @@ static void morecore(int); static int findbucket(union overhead *, int); char * -malloc(nbytes) - register unsigned nbytes; +malloc(register unsigned int nbytes) { register union overhead *p; register int bucket = 0; @@ -160,8 +159,7 @@ malloc(nbytes) * Allocate more memory to the indicated bucket. */ static void -morecore(bucket) - register bucket; +morecore(register int bucket) { register union overhead *op; register int rnu; /* 2^rnu bytes will be requested */ @@ -209,8 +207,7 @@ morecore(bucket) } void -free(cp) - char *cp; +free(char *cp) { register int size; register union overhead *op; @@ -252,9 +249,7 @@ free(cp) int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */ char * -realloc(cp, nbytes) - char *cp; - unsigned nbytes; +realloc(char *cp, unsigned int nbytes) { register u_int onb; union overhead *op; @@ -304,9 +299,7 @@ realloc(cp, nbytes) * Return bucket number, or -1 if not found. */ static -findbucket(freep, srchlen) - union overhead *freep; - int srchlen; +findbucket(union overhead *freep, int srchlen) { register union overhead *p; register int i, j; diff --git a/object.c b/object.c index 02e5338..eb21beb 100644 --- a/object.c +++ b/object.c @@ -36,19 +36,28 @@ static int symbolTableSize; static int symbolTableStringSize; bool encodingFunction; - void -outputObjectFile() + +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 +outputObjectFile(void) { - void outputPartition(); - void outputReferenceInfo(); - void outputSymbolTableInfo(); - void outputAbsoluteCode(); - void outputRelocatableCode(); - void outputReservations(); - void outputExpressions(); - void outputFunctions(); - void dumpSymbolTable(); - void enumerateAndCountSymbols(); + 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(); @@ -72,22 +81,20 @@ outputObjectFile() } void -outputWord(aWord) - int aWord; +outputWord(int aWord) { putc(aWord & 0xFF, objectFileOutput); putc((aWord >> 8) & 0xFF, objectFileOutput); } void -outputPartition() +outputPartition(void) { outputWord(0xFFFF); } void -outputBigword(bigword) - unsigned long bigword; +outputBigword(long unsigned int bigword) { int i; @@ -98,15 +105,13 @@ outputBigword(bigword) } void -outputByte(aByte) - byte aByte; +outputByte(byte aByte) { putc(aByte, objectFileOutput); } void -outputString(string) - stringType *string; +outputString(stringType *string) { do { putc(*string, objectFileOutput); @@ -114,8 +119,7 @@ outputString(string) } void -outputStartAddress(startAddress) - addressType startAddress; +outputStartAddress(addressType startAddress) { outputWord(startAddress); if (produceLinkableObject) { @@ -128,14 +132,14 @@ outputStartAddress(startAddress) } void -outputRelocatableCode() +outputRelocatableCode(void) { int i; addressType codeStartAddress; addressType codeEndAddress; - void outputPseudoSegment(); - void outputBreak(); + void outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress); + void outputBreak(codeBreakType *codeBreak); if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue == RELOCATABLE_VALUE) @@ -161,8 +165,7 @@ outputRelocatableCode() } void -outputBreak(codeBreak) - codeBreakType *codeBreak; +outputBreak(codeBreakType *codeBreak) { switch (codeBreak->kindOfBreak) { case BREAK_BREAK: @@ -185,13 +188,13 @@ outputBreak(codeBreak) } void -outputAbsoluteCode() +outputAbsoluteCode(void) { int i; int startSegment; int endSegment; int nextSegment; - void outputOneCodeBuffer(); + void outputOneCodeBuffer(codeSegmentType *segment); if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue==ABSOLUTE_VALUE) @@ -223,8 +226,7 @@ outputAbsoluteCode() } void -outputOneCodeBuffer(segment) - codeSegmentType *segment; +outputOneCodeBuffer(codeSegmentType *segment) { int i; @@ -238,9 +240,7 @@ outputOneCodeBuffer(segment) } void -outputPseudoSegment(codeStartAddress, codeEndAddress) - addressType codeStartAddress; - addressType codeEndAddress; +outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress) { int startSegment; int endSegment; @@ -252,8 +252,8 @@ outputPseudoSegment(codeStartAddress, codeEndAddress) int segment; codeSegmentType *segmentPtr; - void outputWord(); - void outputByte(); + void outputWord(int aWord); + void outputByte(byte aByte); outputWord(codeStartAddress); outputWord(codeEndAddress); @@ -273,8 +273,7 @@ outputPseudoSegment(codeStartAddress, codeEndAddress) } bool -isObjectSymbol(symbol) - symbolTableEntryType *symbol; +isObjectSymbol(symbolTableEntryType *symbol) { return(symbol != NULL && symbol->context->value != NULL && symbol->context->value->kindOfValue != FUNCTION_VALUE && @@ -289,7 +288,7 @@ isObjectSymbol(symbol) } void -enumerateAndCountSymbols() +enumerateAndCountSymbols(void) { int i; symbolTableEntryType *symb; @@ -305,7 +304,7 @@ enumerateAndCountSymbols() } int -enumerateAndCountReferences() +enumerateAndCountReferences(void) { int result; int codeMode; @@ -323,8 +322,7 @@ enumerateAndCountReferences() } void -outputReference(reference) - expressionReferenceType *reference; +outputReference(expressionReferenceType *reference) { byte funnyByte; bigWord funnyWord; @@ -346,7 +344,7 @@ outputReference(reference) static int referenceCount; void -outputReferenceInfo() +outputReferenceInfo(void) { expressionReferenceListType *theReferences; int codeMode; @@ -363,12 +361,11 @@ outputReferenceInfo() } void -outputOneSymbol(symbol) - symbolTableEntryType *symbol; +outputOneSymbol(symbolTableEntryType *symbol) { byte symbolClass; valueType *symbolValue; - valueType *evaluateIdentifier(); + valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); if (symbol->context->usage == DEFINE_SYMBOL) symbolValue = evaluateIdentifier(symbol, FALSE, NO_FIXUP_OK); @@ -390,7 +387,7 @@ outputOneSymbol(symbol) } void -outputSymbolTableInfo() +outputSymbolTableInfo(void) { int i; symbolTableEntryType *symb; @@ -404,16 +401,13 @@ outputSymbolTableInfo() } int -symbolCompare(symbol1, symbol2) - symbolTableEntryType **symbol1; - symbolTableEntryType **symbol2; +symbolCompare(symbolTableEntryType **symbol1, symbolTableEntryType **symbol2) { return(strcmplc((*symbol1)->symbolName, (*symbol2)->symbolName)); } bool -shouldDumpSymbol(symbol) - symbolTableEntryType *symbol; +shouldDumpSymbol(symbolTableEntryType *symbol) { return(symbolTableDumpOn == 2 || (symbol->context->usage != BUILT_IN_FUNCTION_SYMBOL @@ -428,7 +422,7 @@ shouldDumpSymbol(symbol) } void -dumpSymbolTable() +dumpSymbolTable(void) { int i; symbolTableEntryType *symb; @@ -437,8 +431,8 @@ dumpSymbolTable() int symbolPtr; valueType *value; - valueType *evaluateIdentifier(); - void printValueTersely(); + valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); + void printValueTersely(valueType *value); numberOfSymbols = 0; for (i=0; icontext->usage == DEFINE_SYMBOL || symbol->context-> usage == LABEL_SYMBOL); } void -printValueTersely(value) - valueType *value; +printValueTersely(valueType *value) { static char *valueKindTable[NUM_OF_VALUE_KINDS] = { "ABS", @@ -542,7 +534,7 @@ printValueTersely(value) } void -outputReservations() +outputReservations(void) { while (reservationList != NULL) { outputWord(reservationList->startAddress); @@ -552,7 +544,7 @@ outputReservations() } void -outputExpressionBuffer() +outputExpressionBuffer(void) { int i; @@ -564,13 +556,12 @@ outputExpressionBuffer() } void -outputOneExpression(expression) - expressionType *expression; +outputOneExpression(expressionType *expression) { expressionType *newExpression; - expressionType *generateFixupExpression(); - bool encodeExpression(); + expressionType *generateFixupExpression(expressionType *expression); + bool encodeExpression(expressionType *expression); expressionBufferSize = 0; if (expression == NULL) { @@ -585,7 +576,7 @@ outputOneExpression(expression) } void -outputExpressions() +outputExpressions(void) { int codeMode; expressionReferenceListType *theReferences; @@ -604,12 +595,11 @@ outputExpressions() } void -outputOneFunction(function) - functionDefinitionType *function; +outputOneFunction(functionDefinitionType *function) { argumentDefinitionListType *argumentList; - bool encodeBlock(); - int countArguments(); + bool encodeBlock(blockType *block); + int countArguments(functionDefinitionType *function); outputByte((byte)countArguments(function)); argumentList = function->arguments; @@ -623,7 +613,7 @@ outputOneFunction(function) } void -outputFunctions() +outputFunctions(void) { outputBigword(externalFunctionCount); encodingFunction = TRUE; diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index 8f204dc..bb4b811 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -33,10 +33,19 @@ /* corresponds to routines in buildStuff2.c */ - operandType * -buildOperand(kindOfOperand, arg) - operandKindType kindOfOperand; - anyOldThing *arg; + +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 * +buildOperand(operandKindType kindOfOperand, anyOldThing *arg) { operandType *result; @@ -129,13 +138,11 @@ buildOperand(kindOfOperand, arg) /* corresponds to routines in fixups.c */ operandListType * -duplicateOperandForFixup(operand, isSpecialFunctionOperand) - operandListType *operand; - bool isSpecialFunctionOperand; +duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand) { operandListType *result; - expressionType *duplicateExpressionForFixup(); + expressionType *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); result = typeAlloc(operandListType); result->kindOfOperand = operand->kindOfOperand; @@ -182,8 +189,7 @@ duplicateOperandForFixup(operand, isSpecialFunctionOperand) #define nullFree(thing) if (thing == NULL) return; void -freeOperand(operand) - operandType *operand; +freeOperand(operandType *operand) { nullFree(operand); switch (operand->kindOfOperand) { @@ -229,9 +235,7 @@ freeOperand(operand) /* corresponds to routines in listing.c */ void -expandOperand(addressMode, buffer) - operandKindType addressMode; - char * buffer; +expandOperand(operandKindType addressMode, char *buffer) { switch (addressMode) { case IMMEDIATE_OPND: moreText("#"); break; @@ -279,16 +283,15 @@ expandOperand(addressMode, buffer) #define expansionOn() expandMacros=saveExpansion; valueType * -evaluateOperand(operand) - operandType *operand; +evaluateOperand(operandType *operand) { valueType *result; bool saveExpansion; expressionType *expression; - valueType *evaluateExpression(); - valueType *evaluateSelectionList(); - valueType *newValue(); + 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) @@ -358,8 +361,7 @@ evaluateOperand(operand) /* from parserMisc.c */ conditionType -invertConditionCode(conditionCode) - conditionType conditionCode; +invertConditionCode(conditionType conditionCode) { #define cc (int)conditionCode @@ -376,8 +378,7 @@ invertConditionCode(conditionCode) /* from semanticMisc.c */ bool -shouldParenthesize(operand) - operandType *operand; +shouldParenthesize(operandType *operand) { expressionTermKindType kind; diff --git a/parserMisc.c b/parserMisc.c index c8cfa71..d26fa9c 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -37,12 +37,14 @@ #include #include - statementType * -addLabelToStatement(labelList, statement) - labelListType *labelList; - statementType *statement; + +extern void chokePukeAndDie (void); +extern void puntOnError (errorType theError, ...); + +statementType * +addLabelToStatement(labelListType *labelList, statementType *statement) { - statementType *newStatement(); + statementType *newStatement(statementKindType kind, statementBodyType body); if (statement == NULL) statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); @@ -66,16 +68,14 @@ botch(char *message, ...) } void -checkDefineAssignmentOperator(assignmentOperator) - assignmentKindType assignmentOperator; +checkDefineAssignmentOperator(assignmentKindType assignmentOperator) { if (assignmentOperator != ASSIGN_ASSIGN) puntOnError(DEFINE_ASSIGNMENT_WRONG_ERROR); } statementType * -convertDefineToMdefine(defineStatement) - statementType *defineStatement; +convertDefineToMdefine(statementType *defineStatement) { if (defineStatement->kindOfStatement != DEFINE_STATEMENT) botch("convertDefineToMdefine got statement kind: %d\n", @@ -85,8 +85,7 @@ convertDefineToMdefine(defineStatement) } ifStatementBodyType * -extractIfBody(ifStatement) - statementType *ifStatement; +extractIfBody(statementType *ifStatement) { ifStatementBodyType *result; @@ -101,8 +100,7 @@ extractIfBody(ifStatement) } mifStatementBodyType * -extractMifBody(mifStatement) - statementType *mifStatement; +extractMifBody(statementType *mifStatement) { mifStatementBodyType *result; @@ -117,8 +115,7 @@ extractMifBody(mifStatement) } stringType * -extractString(textExpression) - operandType *textExpression; +extractString(operandType *textExpression) { stringType *result; @@ -131,22 +128,21 @@ extractString(textExpression) } void -popMacroOrFunctionNestingDepth() +popMacroOrFunctionNestingDepth(void) { if (--macroOrFunctionNestingDepth == 0) unknownSymbolTag = UNKNOWN_SYMBOL; } void -pushMacroOrFunctionNestingDepth() +pushMacroOrFunctionNestingDepth(void) { macroOrFunctionNestingDepth++; unknownSymbolTag = NESTED_UNKNOWN_SYMBOL; } char * -saveString(s) - char *s; +saveString(char *s) { char *result; diff --git a/parserMisc.h b/parserMisc.h index c2ed5d0..533186c 100644 --- a/parserMisc.h +++ b/parserMisc.h @@ -9,8 +9,8 @@ void convertDefineToMDefine(statementType *defineStatement); ifStatementBodyType *extractIfBody(statementType *ifStatement); mifStatementBodyType *extractMifBody(statementType *mifStatement); stringType *extractString(operandType *textExpression); -void popMacroOrFunctionNestingDepth(); -void pushMacroOrFunctionNestingDepth(); +void popMacroOrFunctionNestingDepth(void); +void pushMacroOrFunctionNestingDepth(void); char *saveString(char *s); #endif diff --git a/semanticMisc.c b/semanticMisc.c index 885ef6b..ed3094c 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -44,21 +44,37 @@ These are miscellaneous routines called by the primary semantics routines. */ - bool -absoluteValue(address) - valueType *address; + +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 +absoluteValue(valueType *address) { return(address->kindOfValue == ABSOLUTE_VALUE); } void -addAttributeToSymbol(symbol, attribute) - symbolTableEntryType *symbol; - symbolAttributesType attribute; +addAttributeToSymbol(symbolTableEntryType *symbol, symbolAttributesType attribute) { symbolInContextType *context; - symbolInContextType *getBaseContext(); + symbolInContextType *getBaseContext(symbolTableEntryType *identifier); context = getBaseContext(symbol); if (context != NULL) @@ -66,8 +82,7 @@ addAttributeToSymbol(symbol, attribute) } addressType -addressValue(value) - valueType *value; +addressValue(valueType *value) { if (value->kindOfValue==STRING_VALUE || value->kindOfValue==CONDITION_VALUE || @@ -78,9 +93,7 @@ addressValue(value) } valueKindType -addValueKind(leftOperand, rightOperand) - valueType *leftOperand; - valueType *rightOperand; +addValueKind(valueType *leftOperand, valueType *rightOperand) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -211,15 +224,13 @@ addValueKind(leftOperand, rightOperand) } bool -alreadyDefined(context) - symbolInContextType *context; +alreadyDefined(symbolInContextType *context) { return((context->attributes & DEFINED_VARIABLE_ATT) != 0); } bool -booleanTest(expression) - expressionType *expression; +booleanTest(expressionType *expression) { bool result; valueType *expressionResult; @@ -242,8 +253,7 @@ booleanTest(expression) } int -countArguments(function) - functionDefinitionType *function; +countArguments(functionDefinitionType *function) { int result; argumentDefinitionListType *arguments; @@ -258,8 +268,7 @@ countArguments(function) } int -countParameters(parameterList) - operandListType *parameterList; +countParameters(operandListType *parameterList) { int result; @@ -272,9 +281,7 @@ countParameters(parameterList) } arrayType * -allocArray(size, contentsPtr) - int size; - valueType ***contentsPtr; +allocArray(int size, valueType ***contentsPtr) { arrayType *result; int i; @@ -289,9 +296,7 @@ allocArray(size, contentsPtr) } valueType * -createArray(dimension, initializers) - expressionType *dimension; - expressionListType *initializers; +createArray(expressionType *dimension, expressionListType *initializers) { int initCount; valueType *arraySizeValue; @@ -300,7 +305,7 @@ createArray(dimension, initializers) arrayType *result; int i; - valueType *newValue(); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); initCount = expressionListLength(initializers); if ((int)dimension == -1) { @@ -327,8 +332,7 @@ createArray(dimension, initializers) } bool -decrementable(value) - valueType *value; +decrementable(valueType *value) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -358,8 +362,7 @@ decrementable(value) } int -expressionListLength(expressionList) - expressionListType *expressionList; +expressionListLength(expressionListType *expressionList) { int result; @@ -372,11 +375,10 @@ expressionListLength(expressionList) } int -fieldValue(symbol) - symbolTableEntryType *symbol; +fieldValue(symbolTableEntryType *symbol) { valueType *value; - valueType *evaluateIdentifier(); + valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); value = evaluateIdentifier(symbol, FALSE, NO_FIXUP); if (value->kindOfValue != FIELD_VALUE) { @@ -388,8 +390,7 @@ fieldValue(symbol) } bool -incrementable(value) - valueType *value; +incrementable(valueType *value) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -419,8 +420,7 @@ incrementable(value) } int -intValue(value) - valueType *value; +intValue(valueType *value) { if (value->kindOfValue != ABSOLUTE_VALUE) { error(VALUE_IS_NOT_AN_INT_ERROR); @@ -431,8 +431,7 @@ intValue(value) } bool -isAssignable(context) - symbolInContextType *context; +isAssignable(symbolInContextType *context) { return( context->usage==ARGUMENT_SYMBOL || context->usage==VARIABLE_SYMBOL || @@ -440,15 +439,13 @@ isAssignable(context) } bool -isBuiltInFunction(context) - symbolInContextType *context; +isBuiltInFunction(symbolInContextType *context) { return(context!=NULL && context->usage==BUILT_IN_FUNCTION_SYMBOL); } bool -isDefinable(context) - symbolInContextType *context; +isDefinable(symbolInContextType *context) { return( context->usage==DEFINE_SYMBOL || context->usage==DEAD_SYMBOL || @@ -457,12 +454,11 @@ isDefinable(context) } bool -isExternal(symbol) - symbolTableEntryType *symbol; +isExternal(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getBaseContext(); + symbolInContextType *getBaseContext(symbolTableEntryType *identifier); context = getBaseContext(symbol); return (context!=NULL && (context->attributes & GLOBAL_ATT)!=0 && @@ -470,8 +466,7 @@ isExternal(symbol) } bool -isFailure(value) - valueType *value; +isFailure(valueType *value) { if (value == NULL) return(FALSE); @@ -480,15 +475,13 @@ isFailure(value) } bool -isFunction(context) - symbolInContextType *context; +isFunction(symbolInContextType *context) { return(context!=NULL && context->usage==FUNCTION_SYMBOL); } bool -isLastStatementInBlock(statement) - statementType *statement; +isLastStatementInBlock(statementType *statement) { statement = statement->nextStatement; while (statement != NULL) { @@ -521,8 +514,7 @@ isLastStatementInBlock(statement) } bool -isLogicalOp(op) - int op; +isLogicalOp(int op) { return (op==EQUAL_TO || op==GREATER_THAN || op== GREATER_THAN_OR_EQUAL_TO || op==LESS_THAN || op== @@ -531,8 +523,7 @@ isLogicalOp(op) } bool -isPotentialVariable(context) - symbolInContextType *context; +isPotentialVariable(symbolInContextType *context) { return( context->usage == VARIABLE_SYMBOL || context->usage == DEAD_SYMBOL || @@ -540,33 +531,26 @@ isPotentialVariable(context) } bool -isUndefined(value) - valueType *value; +isUndefined(valueType *value) { return(value==NULL || value->kindOfValue==UNDEFINED_VALUE); } bool -isUsable(value) - valueType *value; +isUsable(valueType *value) { return(value!=NULL && value->kindOfValue!=UNDEFINED_VALUE && value->kindOfValue!=FAIL); } bool -logicalXOR(int1, int2) - int int1; - int int2; +logicalXOR(int int1, int int2) { return((int1 && !int2) || (int2 && !int1)); } valueType * -newValue(kindOfValue, value, addressMode) - valueKindType kindOfValue; - int value; - operandKindType addressMode; +newValue(valueKindType kindOfValue, int value, operandKindType addressMode) { valueType *result; @@ -578,9 +562,7 @@ newValue(kindOfValue, value, addressMode) } valueKindType -opValueKind(leftOperand, rightOperand) - valueType *leftOperand; - valueType *rightOperand; +opValueKind(valueType *leftOperand, valueType *rightOperand) { if (leftOperand->kindOfValue==ABSOLUTE_VALUE && rightOperand-> kindOfValue==ABSOLUTE_VALUE) @@ -607,17 +589,14 @@ opValueKind(leftOperand, rightOperand) } bool -relocatableValue(address) - valueType *address; +relocatableValue(valueType *address) { return( address->kindOfValue==DATA_VALUE || address->kindOfValue==RELOCATABLE_VALUE ); } valueKindType -selectValueKind(leftOperand, rightOperand) - valueType *leftOperand; - valueType *rightOperand; +selectValueKind(valueType *leftOperand, valueType *rightOperand) { if (rightOperand->kindOfValue!=FIELD_VALUE || (leftOperand->kindOfValue!=ABSOLUTE_VALUE && @@ -629,9 +608,7 @@ selectValueKind(leftOperand, rightOperand) } valueKindType -subValueKind(leftOperand, rightOperand) - valueType *leftOperand; - valueType *rightOperand; +subValueKind(valueType *leftOperand, valueType *rightOperand) { /* This table MUST be maintained congruently with the definition of the enumerated type 'valueKindType'. */ @@ -762,25 +739,22 @@ subValueKind(leftOperand, rightOperand) } int -swab(i) - int i; +swab(int i) { return(((i & 0xFF) << 8) | ((i & 0xFF00) >> 8)); } valueType * -swabValue(value) - valueType *value; +swabValue(valueType *value) { - valueType *newValue(); + valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); return(newValue(value->kindOfValue, swab(value->value), value-> addressMode)); } valueKindType -unopValueKind(operand) - valueType *operand; +unopValueKind(valueType *operand) { return(operand->kindOfValue==ABSOLUTE_VALUE || operand->kindOfValue== UNDEFINED_VALUE || operand->kindOfValue==RELOCATABLE_VALUE ? @@ -788,14 +762,12 @@ unopValueKind(operand) } void -valueField(symbol, value) - symbolTableEntryType *symbol; - valueType *value; +valueField(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolInContextType *getWorkingContext(); - symbolTableEntryType *effectiveSymbol(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); + symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); @@ -815,15 +787,13 @@ valueField(symbol, value) } void -valueLabel(symbol, value) - symbolTableEntryType *symbol; - valueType *value; +valueLabel(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolTableEntryType *generateLocalLabel(); - symbolInContextType *getBaseContext(); - symbolTableEntryType *effectiveSymbol(); + symbolTableEntryType *generateLocalLabel(symbolTableEntryType *symbol); + symbolInContextType *getBaseContext(symbolTableEntryType *identifier); + symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); @@ -864,16 +834,11 @@ valueLabel(symbol, value) */ void -createFixup(expression, location, kindOfFixup, codeMode, whichFixup) - expressionType *expression; - addressType location; - fixupKindType kindOfFixup; - codeBufferKindType codeMode; - int whichFixup; +createFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup, codeBufferKindType codeMode, int whichFixup) { fixupListType *newFixup; - expressionType *generateFixupExpression(); + expressionType *generateFixupExpression(expressionType *expression); if (debug || emitPrint) printCreateFixup(expression, location, kindOfFixup); @@ -902,10 +867,10 @@ createFixup(expression, location, kindOfFixup, codeMode, whichFixup) } void -finishUp() +finishUp(void) { - void performFixups(); - void performStartAddressFixup(); + void performFixups(fixupListType *fixups); + void performStartAddressFixup(void); if (listingOn) terminateListingFiles(); @@ -936,7 +901,7 @@ isReferenceToRemember(reference) } */ void -noteAnonymousReference() +noteAnonymousReference(void) { expressionReferenceListType *newReference; @@ -958,11 +923,7 @@ noteAnonymousReference() } void -noteReference(expression, kindOfFixup, location, codeMode) - expressionType *expression; - fixupKindType kindOfFixup; - addressType location; - codeBufferKindType codeMode; +noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode) { expressionReferenceListType *newReference; @@ -1010,8 +971,7 @@ noteReference(expression, kindOfFixup, location, codeMode) } void -performFixups(fixups) - fixupListType *fixups; +performFixups(fixupListType *fixups) { valueType *valueToPoke; @@ -1072,11 +1032,11 @@ performFixups(fixups) } void -performStartAddressFixup() +performStartAddressFixup(void) { expressionType *startAddressExpression; - expressionType *generateFixupExpression(); + expressionType *generateFixupExpression(expressionType *expression); startAddressExpression = (expressionType *)startAddress; startAddress = evaluateExpression(startAddressExpression,NO_FIXUP_OK); @@ -1094,9 +1054,7 @@ performStartAddressFixup() } void -putFixupsHere(kindOfFixupsToPut, whichFixup) - fixupKindType kindOfFixupsToPut; - int whichFixup; +putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup) { int location; @@ -1187,8 +1145,7 @@ putReferencesHere(kindOfReferencesToPut, whichReference) */ void -addNewLocalVariable(symbol) - symbolTableEntryType *symbol; +addNewLocalVariable(symbolTableEntryType *symbol) { identifierListType *newLocalVariable; @@ -1199,16 +1156,14 @@ addNewLocalVariable(symbol) } symbolTableEntryType * -effectiveSymbol(symbol, assignmentTargetContext) - symbolTableEntryType *symbol; - symbolInContextType **assignmentTargetContext; +effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext) { symbolInContextType *context; operandType *operand; expressionType *expression; environmentType *saveEnvironment; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); context = getWorkingContext(symbol); saveEnvironment = currentEnvironment; @@ -1236,18 +1191,16 @@ effectiveSymbol(symbol, assignmentTargetContext) } symbolTableEntryType * -generateLocalLabel(symbol) - symbolTableEntryType *symbol; +generateLocalLabel(symbolTableEntryType *symbol) { - stringType *localLabelString(); - symbolTableEntryType *lookupOrEnterSymbol(); + stringType *localLabelString(symbolTableEntryType *symbol); + symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); return(lookupOrEnterSymbol(localLabelString(symbol), LABEL_SYMBOL)); } symbolInContextType * -getBaseContext(identifier) - symbolTableEntryType *identifier; +getBaseContext(symbolTableEntryType *identifier) { symbolInContextType *result; @@ -1259,8 +1212,7 @@ getBaseContext(identifier) } symbolInContextType * -getWorkingContext(identifier) - symbolTableEntryType *identifier; +getWorkingContext(symbolTableEntryType *identifier) { symbolInContextType *result; @@ -1274,13 +1226,12 @@ getWorkingContext(identifier) } stringType * -localLabelString(symbol) - symbolTableEntryType *symbol; +localLabelString(symbolTableEntryType *symbol) { #define TEMP_SYMBOL_SIZE_LIMIT 200 char nameUnderConstruction[TEMP_SYMBOL_SIZE_LIMIT]; - stringType *saveString(); + stringType *saveString(char *s); sprintf(nameUnderConstruction, "_%d_", localLabelTagValue(symbol)); strncat(nameUnderConstruction, &(symbName(symbol)[1]), @@ -1289,13 +1240,12 @@ localLabelString(symbol) } int -localLabelTagValue(symbol) - symbolTableEntryType *symbol; +localLabelTagValue(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(); - void addNewLocalVariable(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); + void addNewLocalVariable(symbolTableEntryType *symbol); context = getWorkingContext(symbol); if (context == NULL) @@ -1311,12 +1261,10 @@ localLabelTagValue(symbol) } void -addBreak(kind, data) - codeBreakKindType kind; - int data; +addBreak(codeBreakKindType kind, int data) { codeBreakType *newBreak; - codeBreakType *buildCodeBreak(); + codeBreakType *buildCodeBreak(codeBreakKindType kind, addressType address, int data); newBreak = buildCodeBreak(kind, currentLocationCounter.value, data); if (codeBreakList == NULL) { @@ -1328,11 +1276,9 @@ addBreak(kind, data) } void -reserveAbsolute(startAddress, blockSize) - addressType startAddress; - int blockSize; +reserveAbsolute(addressType startAddress, int blockSize) { - reservationListType *buildReservation(); + reservationListType *buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation); if (reservationList != NULL && reservationList->startAddress + reservationList->blockSize == startAddress) @@ -1343,8 +1289,7 @@ reserveAbsolute(startAddress, blockSize) } bool -listableStatement(kind) - statementKindType kind; +listableStatement(statementKindType kind) { return( kind == ALIGN_STATEMENT || kind == BLOCK_STATEMENT || kind == BYTE_STATEMENT || kind == CONSTRAIN_STATEMENT || diff --git a/semanticMisc.h b/semanticMisc.h index b40d431..0533c35 100644 --- a/semanticMisc.h +++ b/semanticMisc.h @@ -44,11 +44,11 @@ void valueLabel(symbolTableEntryType *symbol, valueType *value); /* Fixups and references */ void createFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup, codeBufferKindType codeMode, int whichFixup); -void finishUp(); -void noteAnonymousReference(); +void finishUp(void); +void noteAnonymousReference(void); void noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode); void performFixups(fixupListType *fixups); -void performStartAddressFixup(); +void performStartAddressFixup(void); void putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup); /* Contexts and dynamic symbol creation */ diff --git a/statementSemantics.c b/statementSemantics.c index b74b394..45b7853 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -54,28 +54,63 @@ bool nullStatementFlag = FALSE; #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOn() expandMacros=saveExpansion; - void -assembleBlock(block) - blockType *block; + +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 +assembleBlock(blockType *block) { nullAssemble(block); assembleStatement(block, FALSE, NULL); } simpleFixupListType * -assembleBlockInsideIf(block, ongoingFixupList) - blockType *block; - simpleFixupListType *ongoingFixupList; +assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList) { nullAssembleNULL(block); return(assembleStatement(block, TRUE, ongoingFixupList)); } bool -operandCheck(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { int i; @@ -91,9 +126,7 @@ operandCheck(opcode, numberOfOperands, evaluatedOperands) } void -assembleMachineInstruction(opcode, operands) - opcodeTableEntryType *opcode; - operandListType *operands; +assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands) { int i; int op; @@ -140,9 +173,7 @@ assembleMachineInstruction(opcode, operands) } void -assembleMacro(macroInstruction, operands) - macroTableEntryType *macroInstruction; - operandListType *operands; +assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands) { int numberBound; identifierListType *savedLocalVariableList; @@ -186,8 +217,7 @@ assembleMacro(macroInstruction, operands) } void -assembleAlignStatement(alignStatement) - alignStatementBodyType *alignStatement; +assembleAlignStatement(alignStatementBodyType *alignStatement) { int alignment; bool saveExpansion; @@ -218,8 +248,7 @@ assembleAlignStatement(alignStatement) } void -assembleAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +assembleAssertStatement(assertStatementBodyType *assertStatement) { valueType *test; valueType *message; @@ -249,8 +278,7 @@ assembleAssertStatement(assertStatement) } void -assembleBlockStatement(blockStatement) - blockStatementBodyType *blockStatement; +assembleBlockStatement(blockStatementBodyType *blockStatement) { valueType *blockIncrement; int blockSize; @@ -286,8 +314,7 @@ assembleBlockStatement(blockStatement) } void -assembleByteStatement(byteStatement) - byteStatementBodyType *byteStatement; +assembleByteStatement(byteStatementBodyType *byteStatement) { valueType *byteValue; @@ -311,8 +338,7 @@ assembleByteStatement(byteStatement) } void -assembleConstrainStatement(constrainStatement) - constrainStatementBodyType *constrainStatement; +assembleConstrainStatement(constrainStatementBodyType *constrainStatement) { valueType *constraintValue; int constraint; @@ -355,8 +381,7 @@ assembleConstrainStatement(constrainStatement) } void -assembleDbyteStatement(dbyteStatement) - dbyteStatementBodyType *dbyteStatement; +assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement) { valueType *wordValue; @@ -376,8 +401,7 @@ assembleDbyteStatement(dbyteStatement) } void -assembleDefineStatement(defineStatement) - defineStatementBodyType *defineStatement; +assembleDefineStatement(defineStatementBodyType *defineStatement) { symbolTableEntryType *symbolToDefine; symbolInContextType *contextToDefine; @@ -417,8 +441,7 @@ assembleDefineStatement(defineStatement) } void -assembleDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { valueType topOfLoop; @@ -442,8 +465,7 @@ assembleDoUntilStatement(doUntilStatement) } void -assembleDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { valueType topOfLoop; @@ -467,8 +489,7 @@ assembleDoWhileStatement(doWhileStatement) } void -assembleExternStatement(externStatement) - externStatementBodyType *externStatement; +assembleExternStatement(externStatementBodyType *externStatement) { symbolInContextType *context; symbolTableEntryType *theSymbol; @@ -496,8 +517,7 @@ assembleExternStatement(externStatement) } void -assembleFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +assembleFreturnStatement(freturnStatementBodyType *freturnStatement) { freturnExit = TRUE; resultOfLastFunctionCall = evaluateExpression(freturnStatement, @@ -505,8 +525,7 @@ assembleFreturnStatement(freturnStatement) } void -assembleFunctionStatement(functionStatement) - functionStatementBodyType *functionStatement; +assembleFunctionStatement(functionStatementBodyType *functionStatement) { symbolTableEntryType *newFunctionSymbol; functionDefinitionType *newFunction; @@ -545,8 +564,7 @@ assembleFunctionStatement(functionStatement) } void -assembleGroupStatement(groupStatement) - blockType *groupStatement; +assembleGroupStatement(blockType *groupStatement) { expand((startLineMarked(), tabIndent(), moreText("{"), endLine(), tabCount++)); @@ -556,10 +574,7 @@ assembleGroupStatement(groupStatement) } simpleFixupListType * -assembleIfStatement(ifStatement, terminalIf, ongoingFixupList) - ifStatementBodyType *ifStatement; - bool terminalIf; - simpleFixupListType *ongoingFixupList; +assembleIfStatement(ifStatementBodyType *ifStatement, bool terminalIf, simpleFixupListType *ongoingFixupList) { valueType fixupLocation1[COMPOUND_BRANCH_MAX]; simpleFixupListType *fixupLocation2; @@ -609,8 +624,7 @@ assembleIfStatement(ifStatement, terminalIf, ongoingFixupList) } void -assembleIfStatementOldStyle(ifStatement) - ifStatementBodyType *ifStatement; +assembleIfStatementOldStyle(ifStatementBodyType *ifStatement) { valueType fixupLocation1[COMPOUND_BRANCH_MAX]; simpleFixupListType *fixupLocation2; @@ -642,8 +656,7 @@ assembleIfStatementOldStyle(ifStatement) } void -assembleIncludeStatement(includeStatement) - includeStatementBodyType *includeStatement; +assembleIncludeStatement(includeStatementBodyType *includeStatement) { stringType *fileName; valueType *possibleFileName; @@ -663,9 +676,7 @@ assembleIncludeStatement(includeStatement) } void -assembleInstructionStatement(instructionStatement, cumulativeLineNumber) - instructionStatementBodyType *instructionStatement; - int cumulativeLineNumber; +assembleInstructionStatement(instructionStatementBodyType *instructionStatement, int cumulativeLineNumber) { nullAssemble(instructionStatement); switch(instructionStatement->kindOfInstruction) { @@ -695,8 +706,7 @@ assembleInstructionStatement(instructionStatement, cumulativeLineNumber) } void -assembleLongStatement(longStatement) - longStatementBodyType *longStatement; +assembleLongStatement(longStatementBodyType *longStatement) { valueType *longValue; @@ -716,8 +726,7 @@ assembleLongStatement(longStatement) } void -assembleMacroStatement(macroStatement) - macroStatementBodyType *macroStatement; +assembleMacroStatement(macroStatementBodyType *macroStatement) { macroTableEntryType *newMacro; @@ -739,8 +748,7 @@ assembleMacroStatement(macroStatement) } void -assembleMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +assembleMdefineStatement(defineStatementBodyType *mdefineStatement) { bool saveExpansion; @@ -753,8 +761,7 @@ assembleMdefineStatement(mdefineStatement) } void -assembleMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +assembleMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { bool saveListingOn; @@ -768,8 +775,7 @@ assembleMdoUntilStatement(mdoUntilStatement) } void -assembleMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +assembleMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { bool saveListingOn; @@ -783,8 +789,7 @@ assembleMdoWhileStatement(mdoWhileStatement) } void -assembleMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +assembleMforStatement(mforStatementBodyType *mforStatement) { bool saveListingOn; bool saveExpansion; @@ -805,9 +810,7 @@ assembleMforStatement(mforStatement) } void -assembleMifStatement(mifStatement, cumulativeLineNumber) - mifStatementBodyType *mifStatement; - int cumulativeLineNumber; +assembleMifStatement(mifStatementBodyType *mifStatement, int cumulativeLineNumber) { while (mifStatement != NULL) { if (mifStatement->mifCondition == NULL) { @@ -826,8 +829,7 @@ assembleMifStatement(mifStatement, cumulativeLineNumber) } void -assembleMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +assembleMswitchStatement(mswitchStatementBodyType *mswitchStatement) { valueType *switchValue; caseListType *caseList; @@ -888,8 +890,7 @@ assembleMswitchStatement(mswitchStatement) } void -assembleMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +assembleMvariableStatement(mvariableStatementBodyType *mvariableStatement) { identifierListType *newLocalVariable; int initCount; @@ -923,8 +924,7 @@ assembleMvariableStatement(mvariableStatement) } void -assembleMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +assembleMwhileStatement(mwhileStatementBodyType *mwhileStatement) { bool saveListingOn; @@ -938,8 +938,7 @@ assembleMwhileStatement(mwhileStatement) } void -assembleOrgStatement(orgStatement) - orgStatementBodyType *orgStatement; +assembleOrgStatement(orgStatementBodyType *orgStatement) { valueType *orgAddress; bool saveExpansion; @@ -967,8 +966,7 @@ assembleOrgStatement(orgStatement) } void -assemblePerformStatement(performStatement) - performStatementBodyType *performStatement; +assemblePerformStatement(performStatementBodyType *performStatement) { nullAssemble(performStatement); sideEffectFlag = FALSE; @@ -978,8 +976,7 @@ assemblePerformStatement(performStatement) } void -assembleRelStatement(relStatement) - relStatementBodyType *relStatement; +assembleRelStatement(relStatementBodyType *relStatement) { targetOffset = 0; if (!relocatableValue(¤tLocationCounter)) { @@ -992,8 +989,7 @@ assembleRelStatement(relStatement) } void -assembleStartStatement(startStatement) - startStatementBodyType *startStatement; +assembleStartStatement(startStatementBodyType *startStatement) { nullAssemble(startStatement); expand(moreText("start\t")); @@ -1020,8 +1016,7 @@ assembleStartStatement(startStatement) } void -assembleStringStatement(stringStatement) - stringStatementBodyType *stringStatement; +assembleStringStatement(stringStatementBodyType *stringStatement) { valueType *byteValue; @@ -1046,8 +1041,7 @@ assembleStringStatement(stringStatement) } void -assembleStructStatement(structStatement) - structStatementBodyType *structStatement; +assembleStructStatement(structStatementBodyType *structStatement) { nullAssemble(structStatement); if (structStatement->structBody == NULL) @@ -1057,8 +1051,7 @@ assembleStructStatement(structStatement) } void -assembleTargetStatement(targetStatement) - targetStatementBodyType *targetStatement; +assembleTargetStatement(targetStatementBodyType *targetStatement) { valueType *targetAddress; bool saveExpansion; @@ -1081,8 +1074,7 @@ assembleTargetStatement(targetStatement) } void -assembleUndefineStatement(undefineStatement) - undefineStatementBodyType *undefineStatement; +assembleUndefineStatement(undefineStatementBodyType *undefineStatement) { expand(moreText("undefine\t")); while (undefineStatement != NULL) { @@ -1096,8 +1088,7 @@ assembleUndefineStatement(undefineStatement) } void -assembleVariableStatement(variableStatement) - variableStatementBodyType *variableStatement; +assembleVariableStatement(variableStatementBodyType *variableStatement) { symbolTableEntryType *newVariable; symbolInContextType *contextForVariable; @@ -1143,8 +1134,7 @@ assembleVariableStatement(variableStatement) } void -assembleWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +assembleWhileStatement(whileStatementBodyType *whileStatement) { valueType topOfLoop; valueType fixupLocation[COMPOUND_BRANCH_MAX]; @@ -1175,8 +1165,7 @@ assembleWhileStatement(whileStatement) } void -assembleWordStatement(wordStatement) - wordStatementBodyType *wordStatement; +assembleWordStatement(wordStatementBodyType *wordStatement) { valueType *word; @@ -1411,8 +1400,7 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, } void -assembleLabelList(labelList) - labelListType *labelList; +assembleLabelList(labelListType *labelList) { while (labelList != NULL) { if (structNestingDepth == 0) @@ -1428,10 +1416,7 @@ assembleLabelList(labelList) } simpleFixupListType * -assembleStatement(statement, insideIf, ongoingFixupList) - statementType *statement; - bool insideIf; - simpleFixupListType *ongoingFixupList; +assembleStatement(statementType *statement, bool insideIf, simpleFixupListType *ongoingFixupList) { char *saveFileName; int saveLineNumber; @@ -1477,8 +1462,7 @@ assembleStatement(statement, insideIf, ongoingFixupList) } void -eatStatement(statement) - statementType *statement; +eatStatement(statementType *statement) { if (debug) { printf("assembling:\n"); diff --git a/structSemantics.c b/structSemantics.c index e1fb67a..eef4b44 100644 --- a/structSemantics.c +++ b/structSemantics.c @@ -30,10 +30,22 @@ #include "macrossTypes.h" #include "macrossGlobals.h" - void -putStructFixups(base, fixups) - int base; - fixupListType *fixups; + +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 +putStructFixups(int base, fixupListType *fixups) { fixupListType *newFixup; @@ -54,9 +66,7 @@ putStructFixups(base, fixups) } void -putStructReferences(base, references) - int base; - expressionReferenceListType *references; +putStructReferences(int base, expressionReferenceListType *references) { expressionReferenceListType *newReference; int currentMode; @@ -80,14 +90,13 @@ putStructReferences(base, references) } void -instantiateStruct(structStatement) - structStatementBodyType *structStatement; +instantiateStruct(structStatementBodyType *structStatement) { int i; int base; symbolInContextType *context; - symbolInContextType *getWorkingContext(); + symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); #define structInstance ((structInstanceType *) context->value->value) @@ -112,8 +121,7 @@ instantiateStruct(structStatement) } structInstanceType * -assembleStructDefinitionBody(structBody) - structBodyType *structBody; +assembleStructDefinitionBody(structBodyType *structBody) { int i; simpleFixupListType *dummy; @@ -144,13 +152,12 @@ assembleStructDefinitionBody(structBody) } void -assembleStructDefinition(structStatement) - structStatementBodyType *structStatement; +assembleStructDefinition(structStatementBodyType *structStatement) { symbolTableEntryType *name; symbolInContextType *context; - symbolTableEntryType *effectiveSymbol(); + symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); name = effectiveSymbol(structStatement->structName, &context); if (context == NULL) diff --git a/tokenStrings_6502.c b/tokenStrings_6502.c index 127b364..d80b809 100644 --- a/tokenStrings_6502.c +++ b/tokenStrings_6502.c @@ -34,8 +34,7 @@ /* conditionString similarly deals with condition codes */ char * -conditionString(condition) - conditionType condition; +conditionString(conditionType condition) { /* This table MUST be maintained congruently with the definition of the enumerated type 'conditionType' */ @@ -67,8 +66,7 @@ conditionString(condition) /* tokenString similarly deals with parser tokens */ char * -tokenString(token) - int token; +tokenString(int token) { /* This table MUST be maintained congruently with the token definitions in the file 'y.tab.h' as output by yacc. */ From deb5d06fbac39494a0785ed1c943621b3c2690bf Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 20:16:21 +0100 Subject: [PATCH 24/41] Remove obsolete kludge --- operandBody_6502.h | 6 +----- operandBody_68000.h | 6 +----- operandStuffSD_6502.c | 2 +- operandStuffSD_68000.c | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/operandBody_6502.h b/operandBody_6502.h index 952adcd..e0ab9f7 100644 --- a/operandBody_6502.h +++ b/operandBody_6502.h @@ -57,10 +57,6 @@ typedef selectionListType ySelectedOperandBodyType; typedef selectionListType preSelectedOperandBodyType; -#define BlockOperandBodyType anyOldThing /* kludge */ -/* doing above right confuses compiler as it is a forward reference inside - yon union: */ - typedef union { expressionOperandBodyType *expressionUnion; immediateOperandBodyType *immediateUnion; @@ -76,5 +72,5 @@ typedef union { ySelectedOperandBodyType *ySelectedUnion; preSelectedOperandBodyType *preSelectedUnion; stringOperandBodyType *stringUnion; - BlockOperandBodyType *blockUnion; + blockOperandBodyType *blockUnion; } operandBodyType; diff --git a/operandBody_68000.h b/operandBody_68000.h index aaea76c..4d99ad1 100644 --- a/operandBody_68000.h +++ b/operandBody_68000.h @@ -69,14 +69,10 @@ typedef nullType uspRegisterOperandBodyType; typedef nullType controlRegisterOperandBodyType; -#define BlockOperandBodyType anyOldThing /* kludge */ -/* doing above right confuses compiler as it is a forward reference inside - yon union: */ - typedef union { expressionOperandBodyType *expressionUnion; stringOperandBodyType *stringUnion; - BlockOperandBodyType *blockUnion; + blockOperandBodyType *blockUnion; dRegisterOperandBodyType *dRegisterUnion; aRegisterOperandBodyType *aRegisterUnion; aRegisterIndirectOperandBodyType *aRegisterIndirectUnion; diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index bb4b811..c085d11 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -125,7 +125,7 @@ buildOperand(operandKindType kindOfOperand, anyOldThing *arg) break; case BLOCK_OPND: - result->theOperand.blockUnion = (BlockOperandBodyType *) arg; + result->theOperand.blockUnion = (blockOperandBodyType *) arg; break; default: diff --git a/operandStuffSD_68000.c b/operandStuffSD_68000.c index 7d51fd0..689ac8d 100644 --- a/operandStuffSD_68000.c +++ b/operandStuffSD_68000.c @@ -59,7 +59,7 @@ buildOperand(kindOfOperand, arg1, arg2, arg3, arg4) break; case BLOCK_OPND: - result->theOperand.blockUnion = (BlockOperandBodyType *) arg1; + result->theOperand.blockUnion = (blockOperandBodyType *) arg1; break; case D_REGISTER_OPND: From 29f102cdf1f06a11c02603486c518f2a9ecba6de Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 20:18:41 +0100 Subject: [PATCH 25/41] emitString: comparison between pointer and integer --- emitStuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emitStuff.c b/emitStuff.c index c100d6d..3786b3e 100644 --- a/emitStuff.c +++ b/emitStuff.c @@ -329,7 +329,7 @@ emitString(stringType *string) nuls in strings, so to speak. We assume that the character 0xFF is not likely to be needed since ASCII (and ATASCII) is a seven bit character code. */ - while (*string != NULL) + while (*string != 0) if ((*string & 0xFF) == 0xFF) { emitByte('\0'); string++; From e60db078d26e01cba3c50d8a22973f157c9f9341 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 15:56:01 -0800 Subject: [PATCH 26/41] Use mkstemp instead of mktemp - mktemp is intrinsically unsafe. --- initialize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/initialize.c b/initialize.c index 1333f42..e7ad14d 100644 --- a/initialize.c +++ b/initialize.c @@ -351,7 +351,7 @@ initializeStuff(int argc, char **argv) installCommandLineDefineSymbols(); if (listingOn) { - if ((saveFileForPass2 = fopen(mktemp(pass2SourceFileName), + if ((saveFileForPass2 = fopen(mkstemp(pass2SourceFileName), "w+")) == NULL) { fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR, pass2SourceFileName); @@ -360,7 +360,7 @@ initializeStuff(int argc, char **argv) unlink(pass2SourceFileName); /* will take effect on program exit */ - if ((indexFileForPass2 = fopen(mktemp(pass2IndexFileName), + if ((indexFileForPass2 = fopen(mkstemp(pass2IndexFileName), "w+")) == NULL) { fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR, pass2IndexFileName); @@ -370,7 +370,7 @@ initializeStuff(int argc, char **argv) program exit */ if (expandMacros) { - if ((macroFileForPass2 = fopen(mktemp( + if ((macroFileForPass2 = fopen(mkstemp( pass2MacroExpansionFileName),"w+")) == NULL) { fatalSystemError( UNABLE_TO_OPEN_PASS_2_FILE_ERROR, From 3e49dc61f0a693123026b323c741a11294ce2db2 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 16:01:46 -0800 Subject: [PATCH 27/41] Main should have a return value --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 800d818..ae211a1 100644 --- a/main.c +++ b/main.c @@ -36,6 +36,7 @@ extern int yyparse (void); extern void finishUp (void); extern void chokePukeAndDie (void); +int main(int argc, char **argv) { #ifdef __APPLE__ @@ -54,8 +55,7 @@ main(int argc, char **argv) sbrk(0) - &end); if (errorFlag) chokePukeAndDie(); - else - exit(0); + return 0; } void From 77e0ca257816ff0ea05dc2aa73e7bfd2a4958899 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 17:24:28 -0800 Subject: [PATCH 28/41] Remove all warnings that aren't int- or pointer-conversion --- buildStuff.h | 80 +++++++++++++++++++++++++++++++++++++++ errorStuff.h | 16 ++++++++ lexer.h | 32 ++++++++++++++++ lookups.h | 27 +++++++++++++ macross_6502.y | 100 +++++++++++++++++++++++++++++++++---------------- parserMisc.h | 2 +- 6 files changed, 223 insertions(+), 34 deletions(-) create mode 100644 buildStuff.h create mode 100644 errorStuff.h create mode 100644 lexer.h create mode 100644 lookups.h diff --git a/buildStuff.h b/buildStuff.h new file mode 100644 index 0000000..32af9d2 --- /dev/null +++ b/buildStuff.h @@ -0,0 +1,80 @@ +#ifndef BUILD_STUFF_H_ +#define BUILD_STUFF_H_ + +#include "macrossTypes.h" + +/* buildStuff1.c */ +statementType *newStatement (statementKindType kind, statementBodyType body); +statementType *buildAlignStatement (expressionType *expression); +statementType *buildAssertStatement (expressionType *condition, expressionType *message); +statementType *buildBlockStatement (expressionListType *expressionList); +statementType *buildByteStatement (expressionListType *expressionList); +statementType *buildConstrainStatement (expressionType *expression, blockType *block); +statementType *buildDbyteStatement (expressionListType *expressionList); +statementType *buildDefineStatement (stringType *name, expressionType *value); +statementType *buildDoUntilStatement (blockType *body, conditionType condition); +statementType *buildDoWhileStatement (blockType *body, conditionType condition); +statementType *buildDoStatement (blockType *body, doEndType *end); +statementType *buildExternStatement (identifierListType *identifierList); +statementType *buildFreturnStatement (expressionType *expression); +statementType *buildFunctionStatement (stringType *name, argumentDefinitionListType *arguments, blockType *body); +statementType *buildGroupStatement (blockType *block); +statementType *buildIfStatement (ifHeadType *head, ifContinuationType continuation, ifContinuationKindType continuationKind); +statementType *buildIncludeStatement (expressionType *filename); +statementType *buildInstructionStatement (opcodeTableEntryType *opcode, operandListType *operands); +statementType *buildLongStatement (expressionListType *expressionList); +statementType *buildMacroStatement (macroTableEntryType *macro, argumentDefinitionListType *arguments, blockType *body); +statementType *buildMacroInstructionStatement (macroTableEntryType *macro, operandListType *operands); +statementType *buildMdefineStatement (stringType *name, expressionType *value); +statementType *buildMdoUntilStatement (blockType *body, struct expressionTermStruct *condition); +statementType *buildMdoWhileStatement (blockType *body, expressionType *condition); +statementType *buildMdoStatement (blockType *body, mdoEndType *end); +statementType *buildMforStatement (forExpressionsType *forExpressions, blockType *body); +statementType *buildMifStatement (mifHeadType *head, mifContinuationType continuation, ifContinuationKindType continuationKind); +statementType *buildMswitchStatement (expressionType *switchExpression, caseListType *cases); +statementType *buildMvariableStatement (stringType *name, expressionListType *value, expressionType *dimension); +statementType *buildMwhileStatement (expressionType *condition, blockType *body); +statementType *buildNullStatement (void); +statementType *buildOrgStatement (expressionType *expression); +statementType *buildPerformStatement (expressionType *expression); +statementType *buildRelStatement (void); +statementType *buildStartStatement (expressionType *expression); +statementType *buildStringStatement (expressionListType *expressionList); +statementType *buildStructStatement (symbolTableEntryType *name, blockType *body); +statementType *buildTargetStatement (expressionType *expression); +statementType *buildUndefineStatement (identifierListType *identifierList); +statementType *buildVariableStatement (stringType *name, expressionListType *value, expressionType *dimension); +statementType *buildWhileStatement (conditionType condition, blockType *body); +statementType *buildWordStatement (expressionListType *expressionList); + +/* buildStuff2.c */ +caseType *buildCase (expressionListType *caseTags, blockType *caseBody); +doEndType *buildDoEnd (conditionType condition, doEndKindType kindOfDoEnd); +forExpressionsType *buildForExpressions (expressionType *initExpression, expressionType *testExpression, expressionType *incrExpression); +ifHeadType *buildIfHead (conditionType condition, blockType *block); +mdoEndType *buildMdoEnd (expressionType *condition, doEndKindType kindOfMdoEnd); +mifHeadType *buildMifHead (expressionType *condition, blockType *block); +arrayTermType *buildArrayTerm (expressionType *array, expressionType *index); +binopTermType *buildBinopTerm (binopKindType binop, expressionType *leftArgument, expressionType *rightArgument); +functionCallTermType *buildFunctionCall (stringType *functionName, operandListType *arguments); +postOpTermType *buildPostOpTerm (postOpKindType postOp, expressionType *postOpArgument); +preOpTermType *buildPreOpTerm (preOpKindType preOp, expressionType *preOpArgument); +unopTermType *buildUnopTerm (unopKindType unop, expressionType *unopArgument); +expressionTermType *buildExpressionTerm (expressionTermKindType kindOfExpressionTerm, anyOldThing *arg1, anyOldThing *arg2, anyOldThing *arg3); +macroTableEntryType *buildMacroTableEntry (stringType *name); +symbolTableEntryType *buildSymbolTableEntry (stringType *name, symbolUsageKindType usage); +codeBreakType *buildCodeBreak (codeBreakKindType kind, addressType address, int data); +reservationListType *buildReservation (addressType startAddress, int blockSize, reservationListType *nextReservation); +simpleFixupListType *buildSimpleFixupList (valueType locationToFixup, simpleFixupListType *previousList); + +/* buildStuff3.c */ +argumentListHeadType *buildArgumentList (stringType *new, argumentListHeadType *rest, bool arrayTag); +caseListHeadType *buildCaseList (caseType *new, caseListHeadType *rest); +expressionListHeadType *buildExpressionList (expressionType *new, expressionListHeadType *rest); +identifierListHeadType *buildIdentifierList (stringType *new, identifierListHeadType *rest, symbolUsageKindType usage); +labelListHeadType *buildLabelList (symbolTableEntryType *new, labelListHeadType *rest); +operandListHeadType *buildOperandList (operandType *new, operandListHeadType *rest); +selectionListHeadType *buildSelectionList (selectionListType *new, selectionListHeadType *rest); +statementListHeadType *buildStatementList (statementType *new, statementListHeadType *rest); + +#endif diff --git a/errorStuff.h b/errorStuff.h new file mode 100644 index 0000000..4381169 --- /dev/null +++ b/errorStuff.h @@ -0,0 +1,16 @@ +#ifndef ERROR_STUFF_H_ +#define ERROR_STUFF_H_ + +void puntOnError (errorType theError, ...); +void printErrorMessage (errorType theError, va_list ap); +void error (errorType theError, ...); +void verror (errorType theError, va_list ap); +void warning (errorType theError, ...); +void fatalError (errorType theError, ...); +void fatalSystemError (errorType theError, ...); +void yyerror (char *s); +char *usageString (symbolUsageKindType usageKind); +char *valueKindString (valueKindType valueKind); +char *assignmentString (assignmentKindType assignment); + +#endif diff --git a/lexer.h b/lexer.h new file mode 100644 index 0000000..a3f3031 --- /dev/null +++ b/lexer.h @@ -0,0 +1,32 @@ +#ifndef LEXER_H_ +#define LEXER_H_ + +int yylex (void); +int lexer (void); +void initializeLexDispatchTable (void); +bool isMacrossLiteralCharacter (char c); +void snarfAlphanumericString (char c, char *buffer); +int lexIdentifier (char c); +int lexNumber (char c); +int fancyAtoI (char *buffer, int base); +int digitValue (char c); +int lexLiteral (char c); +int lexCharacterConstant (void); +int getStringCharacter (FILE *input); +int lexStringConstant (void); +int lexOperator (char firstC); +char controlCharacter (char c); +char skipWhitespaceAndComments (void); +int popInputFileStack (void); +void pushInputFileStack (stringType *fileName); +void resynchronizeInput (void); +void saveLineForListing (stringType *line); +void saveEOLForListing (void); +void saveIndexForListing (statementKindType kindOfStatement, int cumulativeLineNumber); +void saveEndMifForListing (int cumulativeLineNumber); +void saveListingOff (void); +void saveListingOn (void); +char *myfgets (char *buffer, int length, FILE *stream); +int readAnotherLine (void); + +#endif diff --git a/lookups.h b/lookups.h new file mode 100644 index 0000000..e9b2a0a --- /dev/null +++ b/lookups.h @@ -0,0 +1,27 @@ +#ifndef LOOKUPS_H_ +#define LOOKUPS_H_ + +conditionType lookupConditionCode (char *s, int hashValue); +int lookupKeyword (char *s, int hashValue); +macroTableEntryType *lookupMacroName (char *s, int hashValue); +opcodeTableEntryType *lookupOpcode (char *s, int hashValue); +symbolTableEntryType *lookupOrEnterSymbol (stringType *s, symbolUsageKindType kind); +void pushSymbol (symbolTableEntryType *symbol); +void popSymbol (symbolTableEntryType *symbol); +macroTableEntryType *createMacro (stringType *macroName); +genericTableEntryType *prehashedStringLookup (char *s, genericTableEntryType **table, int hashValue); +genericTableEntryType *hashStringLookup (char *s, genericTableEntryType **table); +genericTableEntryType *hashStringEnter (genericTableEntryType *entry, genericTableEntryType **table); +int hashString (char *s); +bool strcmplc (char *s1, char *s2); +bool strcmplct (char *s1, char *s2); +void purgeSymbol (symbolTableEntryType *symbol); +void reincarnateSymbol (symbolInContextType *context, symbolUsageKindType newUsage); +void pushBinding (symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); +void popBinding (symbolTableEntryType *symbol); +int bindMacroArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName); +int bindFunctionArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName); +void unbindArguments (argumentDefinitionListType *argumentList, int numberToUnbind); +void unbindLocalVariables (identifierListType *identifierList); + +#endif diff --git a/macross_6502.y b/macross_6502.y index 7e0ffb1..1ae08d8 100644 --- a/macross_6502.y +++ b/macross_6502.y @@ -31,6 +31,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "buildStuff.h" +#include "errorStuff.h" +#include "lexer.h" +#include "lookups.h" +#include "operandStuff.h" +#include "parserMisc.h" +#include "semanticMisc.h" +#include "statementSemantics.h" %} @@ -119,7 +127,8 @@ eolList: EOL statementList: statement { if (statementListNestingDepth == 0) { - $$ = eatStatement($1); + eatStatement($1); + $$ = NULL; } else { $$ = buildStatementList($1, NULL); } @@ -127,7 +136,8 @@ statementList: statement | statementList EOL statement { if (statementListNestingDepth == 0) { - $$ = eatStatement($3); + eatStatement($3); + $$ = NULL; } else { $$ = buildStatementList($3, $1); } @@ -223,15 +233,21 @@ labelableStatement: ifStatement: IF _ ifHead { - $$ = buildIfStatement($3, NULL, NO_CONTINUATION); + ifContinuationType noCont; + noCont.blockUnion=NULL; + $$ = buildIfStatement($3, noCont, NO_CONTINUATION); } | IF _ ifHead elsePart { - $$ = buildIfStatement($3, $4, ELSE_CONTINUATION); + ifContinuationType cont; + cont.blockUnion=$4; + $$ = buildIfStatement($3, cont, ELSE_CONTINUATION); } | IF _ ifHead elseIf { - $$ = buildIfStatement($3, $4, ELSEIF_CONTINUATION); + ifContinuationType cont; + cont.blockUnion=$4; + $$ = buildIfStatement($3, cont, ELSEIF_CONTINUATION); } ; @@ -271,15 +287,21 @@ elseIf: ELSE _ ifStatement } | ELSEIF _ ifHead { - $$ = extractIfBody(buildIfStatement($3, NULL, NO_CONTINUATION)); + ifContinuationType noCont; + noCont.blockUnion = NULL; + $$ = extractIfBody(buildIfStatement($3, noCont, NO_CONTINUATION)); } | ELSEIF _ ifHead elsePart { - $$ = extractIfBody(buildIfStatement($3, $4, ELSE_CONTINUATION)); + ifContinuationType cont; + cont.blockUnion = $4; + $$ = extractIfBody(buildIfStatement($3, cont, ELSE_CONTINUATION)); } | ELSEIF _ ifHead elseIf { - $$ = extractIfBody(buildIfStatement($3, $4, ELSEIF_CONTINUATION)); + ifContinuationType cont; + cont.blockUnion = $4; + $$ = extractIfBody(buildIfStatement($3, cont, ELSEIF_CONTINUATION)); } ; @@ -657,15 +679,21 @@ macroDefineStatement: macroIfStatement: MIF _ mIfHead { - $$ = buildMifStatement($3, NULL, NO_CONTINUATION); + mifContinuationType noCont; + noCont.mifBlockUnion = NULL; + $$ = buildMifStatement($3, noCont, NO_CONTINUATION); } | MIF _ mIfHead mElsePart { - $$ = buildMifStatement($3, $4, ELSE_CONTINUATION); + mifContinuationType cont; + cont.mifBlockUnion = $4; + $$ = buildMifStatement($3, cont, ELSE_CONTINUATION); } | MIF _ mIfHead mElseIf { - $$ = buildMifStatement($3, $4, ELSEIF_CONTINUATION); + mifContinuationType cont; + cont.mifBlockUnion = $4; + $$ = buildMifStatement($3, cont, ELSEIF_CONTINUATION); } ; @@ -693,15 +721,21 @@ mElseIf: MELSE _ macroIfStatement } | MELSEIF _ mIfHead { - $$ = extractMifBody(buildMifStatement($3, NULL, NO_CONTINUATION)); + mifContinuationType noCont; + noCont.mifBlockUnion = NULL; + $$ = extractMifBody(buildMifStatement($3, noCont, NO_CONTINUATION)); } | MELSEIF _ mIfHead mElsePart { - $$ = extractMifBody(buildMifStatement($3, $4, ELSE_CONTINUATION)); + mifContinuationType cont; + cont.mifBlockUnion = $4; + $$ = extractMifBody(buildMifStatement($3, cont, ELSE_CONTINUATION)); } | MELSEIF _ mIfHead mElseIf { - $$ = extractMifBody(buildMifStatement($3, $4, ELSEIF_CONTINUATION)); + mifContinuationType cont; + cont.mifBlockUnion = $4; + $$ = extractMifBody(buildMifStatement($3, cont, ELSEIF_CONTINUATION)); } ; @@ -943,18 +977,18 @@ selectionList: SELECT _ Identifier array: variable '[' _ expression _ ']' { - $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4); + $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4, NULL); } | array '[' _ expression _ ']' { - $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4); + $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4, NULL); } ; variable: Identifier { $$ = buildExpressionTerm(IDENTIFIER_EXPR, lookupOrEnterSymbol($1, - unknownSymbolTag)); + unknownSymbolTag), NULL, NULL); } ; @@ -968,47 +1002,47 @@ expression: lvalue } | functionCall { - $$ = buildExpressionTerm(FUNCTION_CALL_EXPR, $1); + $$ = buildExpressionTerm(FUNCTION_CALL_EXPR, $1, NULL, NULL); } | Number { - $$ = buildExpressionTerm(NUMBER_EXPR, $1); + $$ = buildExpressionTerm(NUMBER_EXPR, $1, NULL, NULL); } | ConditionCode { - $$ = buildExpressionTerm(CONDITION_CODE_EXPR, $1); + $$ = buildExpressionTerm(CONDITION_CODE_EXPR, $1, NULL, NULL); } | HERE { - $$ = buildExpressionTerm(HERE_EXPR); + $$ = buildExpressionTerm(HERE_EXPR, NULL, NULL, NULL); } | TextString { - $$ = buildExpressionTerm(STRING_EXPR, $1); + $$ = buildExpressionTerm(STRING_EXPR, $1, NULL, NULL); } | '(' _ expression _ ')' { - $$ = buildExpressionTerm(SUBEXPRESSION_EXPR, $3); + $$ = buildExpressionTerm(SUBEXPRESSION_EXPR, $3, NULL, NULL); } | SUB _ expression %prec UNARY_MINUS { - $$ = buildExpressionTerm(UNOP_EXPR, UNARY_MINUS, $3); + $$ = buildExpressionTerm(UNOP_EXPR, UNARY_MINUS, $3, NULL); } | LOGICAL_NOT _ expression { - $$ = buildExpressionTerm(UNOP_EXPR, LOGICAL_NOT, $3); + $$ = buildExpressionTerm(UNOP_EXPR, LOGICAL_NOT, $3, NULL); } | BITWISE_NOT _ expression { - $$ = buildExpressionTerm(UNOP_EXPR, BITWISE_NOT, $3); + $$ = buildExpressionTerm(UNOP_EXPR, BITWISE_NOT, $3, NULL); } | DIV _ expression %prec LO_BYTE { - $$ = buildExpressionTerm(UNOP_EXPR, LO_BYTE, $3); + $$ = buildExpressionTerm(UNOP_EXPR, LO_BYTE, $3, NULL); } | HI_BYTE _ expression { - $$ = buildExpressionTerm(UNOP_EXPR, HI_BYTE, $3); + $$ = buildExpressionTerm(UNOP_EXPR, HI_BYTE, $3, NULL); } | expression MUL _ expression { @@ -1052,7 +1086,7 @@ expression: lvalue } | expression GREATER_THAN_OR_EQUAL_TO _ expression { - $$ = buildExpressionTerm(BINOP_EXPR, GREATER_THAN_OR_EQUAL_TO, $1,$4); + $$ = buildExpressionTerm(BINOP_EXPR, GREATER_THAN_OR_EQUAL_TO, $1, $4); } | expression EQUAL_TO _ expression { @@ -1097,19 +1131,19 @@ expression: lvalue } | lvalue INCREMENT { - $$ = buildExpressionTerm(POSTOP_EXPR, INCREMENT, $1); + $$ = buildExpressionTerm(POSTOP_EXPR, INCREMENT, $1, NULL); } | lvalue DECREMENT { - $$ = buildExpressionTerm(POSTOP_EXPR, DECREMENT, $1); + $$ = buildExpressionTerm(POSTOP_EXPR, DECREMENT, $1, NULL); } | INCREMENT _ lvalue { - $$ = buildExpressionTerm(PREOP_EXPR, INCREMENT, $3); + $$ = buildExpressionTerm(PREOP_EXPR, INCREMENT, $3, NULL); } | DECREMENT _ lvalue { - $$ = buildExpressionTerm(PREOP_EXPR, DECREMENT, $3); + $$ = buildExpressionTerm(PREOP_EXPR, DECREMENT, $3, NULL); } ; diff --git a/parserMisc.h b/parserMisc.h index 533186c..9984ce7 100644 --- a/parserMisc.h +++ b/parserMisc.h @@ -2,7 +2,7 @@ #define PARSER_MISC_H_ #include "macrossTypes.h" -statementType *addLabelToSatement(labelListType *labelList, statementType *statement); +statementType *addLabelToStatement(labelListType *labelList, statementType *statement); void botch(char *message, ...); void checkDefineAssignmentOperator(assignmentKindType assignmentOperator); void convertDefineToMDefine(statementType *defineStatement); From c62c0fba3ad693901f721e6df17aa249335b6c84 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 17:45:47 -0800 Subject: [PATCH 29/41] Hide warnings, improve Makefile comments --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b215580..753b9a4 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,16 @@ emitBranch.h semanticMisc.h expressionSemantics.h HEADERS = macrossTypes.h macrossGlobals.h -CFLAGS=-m32 # macross is not 64 bit clean +# Macross is not 64-bit clean and it does a lot of silent downcasting +# to simulate subclasses and uses int and void * interchangably a +# bunch. +CFLAGS=-m32 -Wno-int-conversion -Wno-incompatible-pointer-types + # If yacc is notionally present on a system, it's usually actually # bison in a compatibility mode. bison is available by name more often -# than bison itself is. -YACC=bison -o y.tab.c +# than yacc itself is. +YACC=bison -y +#YACC=yacc .c.o: cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) $*.c From 7e126cbfe6bffcd83b57ff229c5a62d0c016ddf6 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 17:47:11 -0800 Subject: [PATCH 30/41] Create a .gitignore file --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..131c6fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*~ +y.tab.c +y.tab.h +macross +slinky/slinky From a98186c8f501c3cb86ecbfe55f9d9258199229f8 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 18:38:39 -0800 Subject: [PATCH 31/41] Full header information extracted from gcc -aux-info --- actions.h | 29 +++++++++++++++ builtInFunctions.h | 63 +++++++++++++++++++++++++++++++ debugPrint.h | 86 +++++++++++++++++++++++++++++++++++++++++++ emitBranch.h | 7 ---- emitStuff.h | 27 ++++++++++++++ encode.h | 37 +++++++++++++++++++ errorStuff.h | 24 ++++++------ expressionSemantics.h | 7 ++-- fixups.h | 11 ++++++ garbage.h | 66 +++++++++++++++++++++++++++++++++ initialize.h | 21 +++++++++++ lexer.h | 56 ++++++++++++++-------------- listing.h | 15 +++----- lookups.h | 46 ++++++++++++----------- object.h | 37 +++++++++++++++++++ operandStuff.h | 4 +- parserMisc.h | 3 +- statementSemantics.h | 10 ++--- structSemantics.h | 12 ++++++ tokenStrings.h | 9 +++++ 20 files changed, 482 insertions(+), 88 deletions(-) create mode 100644 actions.h create mode 100644 builtInFunctions.h create mode 100644 debugPrint.h create mode 100644 emitStuff.h create mode 100644 encode.h create mode 100644 fixups.h create mode 100644 garbage.h create mode 100644 initialize.h create mode 100644 object.h create mode 100644 structSemantics.h create mode 100644 tokenStrings.h diff --git a/actions.h b/actions.h new file mode 100644 index 0000000..372ee76 --- /dev/null +++ b/actions.h @@ -0,0 +1,29 @@ +#ifndef ACTIONS_H_ +#define ACTIONS_H_ + +#include "macrossTypes.h" + +void actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDir2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDirIndir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDirX1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDirX2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDirX3(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsImmDir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsImmDirX(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsImmDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsImmIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsNone(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +void actionsRelative(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); +bool isByte(int value); +bool isByteOffset(int value); +bool isWordOffset(int value); +bool isByteAddress(valueType *value); +bool isWord(int value); +bool byteCheck(int value); +bool wordCheck(int value); +bool isDefined(valueType *value); + +#endif diff --git a/builtInFunctions.h b/builtInFunctions.h new file mode 100644 index 0000000..a853083 --- /dev/null +++ b/builtInFunctions.h @@ -0,0 +1,63 @@ +#ifndef BUILT_IN_FUNCTIONS_H_ +#define BUILT_IN_FUNCTIONS_H_ + +#include "macrossTypes.h" + +/* Platform-independent */ +valueType *makeBooleanValue(int test); +valueType *makeFailureValue(void); +valueType *makeIntegerValue(int integer); +valueType *makeOperandValue(operandType *operand); +valueType *makeStringValue(stringType *string); +valueType *makeUndefinedValue(void); +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 *isBlockBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isBuiltInFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isConditionCodeBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isFieldBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isFunctionBIF(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 *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 *symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup); + +/* 6502-specific */ +valueType *isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isDirectModeBIF(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 *isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); +valueType *isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); + +#endif diff --git a/debugPrint.h b/debugPrint.h new file mode 100644 index 0000000..24af614 --- /dev/null +++ b/debugPrint.h @@ -0,0 +1,86 @@ +#ifndef DEBUG_PRINT_H_ +#define DEBUG_PRINT_H_ + +#include "macrossTypes.h" + +/* Platform-independent */ +void tab(void); +void printAssignmentKind(assignmentKindType assignmentKind); +void printExpressionKind(expressionTermKindType kind); +stringType *statementKindString(statementKindType kind); +void printStatementKind(statementKindType kind); +void printValue(valueType *value); +void printSymbol(symbolTableEntryType *symbol); +void printArgumentDefinitionList(argumentDefinitionListType *list); +void printBlock(blockType *block); +void printArrayTerm(arrayTermType *arrayTerm); +void printAssignmentTerm(binopTermType *assignmentTerm); +void printBinopTerm(binopTermType *binopTerm); +void printFunctionCall(functionCallTermType *functionCall); +void printHere(void); +void printIdentifier(symbolTableEntryType *identifier); +void printNumber(numberTermType number); +void printPostopTerm(postOpTermType *postopTerm); +void printPreopTerm(preOpTermType *preopTerm); +void printUnopTerm(unopTermType *unopTerm); +void printExpression(expressionType *expression); +void printExpressionList(expressionListType *expressionList); +void printIdentifierList(identifierListType *identifierList); +void printCase(caseType *aCase); +void printCaseList(caseListType *caseList); +void printMacro(macroTableEntryType *macroInstruction); +void printOpcode(opcodeTableEntryType *opcode); +void printOperandList(operandListType *operandList); +void printAlignStatement(alignStatementBodyType *alignStatement); +void printAssertStatement(assertStatementBodyType *assertStatement); +void printBlockStatement(blockStatementBodyType *blockStatement); +void printByteStatement(byteStatementBodyType *byteStatement); +void printConstrainStatement(constrainStatementBodyType *constrainStatement); +void printDbyteStatement(dbyteStatementBodyType *dbyteStatement); +void printDefineStatement(defineStatementBodyType *defineStatement); +void printDoUntilStatement(doUntilStatementBodyType *doUntilStatement); +void printDoWhileStatement(doWhileStatementBodyType *doWhileStatement); +void printExternStatement(externStatementBodyType *externStatement); +void printFreturnStatement(freturnStatementBodyType *freturnStatement); +void printFunctionStatement(functionStatementBodyType *functionStatement); +void printIfStatement(ifStatementBodyType *ifStatement); +void printIncludeStatement(includeStatementBodyType *includeStatement); +void printInstructionStatement(instructionStatementBodyType *instructionStatement); +void printLongStatement(longStatementBodyType *longStatement); +void printMacroStatement(macroStatementBodyType *macroStatement); +void printMdefineStatement(defineStatementBodyType *mdefineStatement); +void printMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); +void printMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); +void printMforStatement(mforStatementBodyType *mforStatement); +void printMifStatement(mifStatementBodyType *mifStatement); +void printMswitchStatement(mswitchStatementBodyType *mswitchStatement); +void printMvariableStatement(mvariableStatementBodyType *mvariableStatement); +void printMwhileStatement(mwhileStatementBodyType *mwhileStatement); +void printOrgStatement(orgStatementBodyType *orgStatement); +void printPerformStatement(performStatementBodyType *performStatement); +void printRelStatement(relStatementBodyType *relStatement); +void printStartStatement(startStatementBodyType *startStatement); +void printStringStatement(stringStatementBodyType *stringStatement); +void printStructStatement(structStatementBodyType *structStatement); +void printTargetStatement(targetStatementBodyType *targetStatement); +void printUndefineStatement(undefineStatementBodyType *undefineStatement); +void printVariableStatement(variableStatementBodyType *variableStatement); +void printWhileStatement(whileStatementBodyType *whileStatement); +void printWordStatement(wordStatementBodyType *wordStatement); +void printLabelList(labelListType *labelList); +void printStatementBody(statementKindType kind, statementBodyType body); +void printStatement(statementType *statement); +void printPendingFixupList(fixupListType *fixupList); +void printCreateFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup); +void printExpressionBuffer(void); +void printOneCodeBuffer(codeSegmentType *codeSegment, int bufferNum); +void printCodeBufferSection(codeRegionType *codeBufferSection); +void printCodeBuffers(void); + +/* Platform-specific */ +void printCondition(conditionType condition); +void printOperandKind(operandKindType kind); +void printToken(int token); +void printOperand(operandType *operand); + +#endif diff --git a/emitBranch.h b/emitBranch.h index f53d9c0..b85896d 100644 --- a/emitBranch.h +++ b/emitBranch.h @@ -3,14 +3,7 @@ #include "macrossTypes.h" -#if TARGET_CPU == CPU_6502 -void emitRelativeBranch(conditionType condition, valueType *target, valueType fixupLocation[COMPOUND_BRANCH_MAX]); -#elif TARGET_CPU == CPU_68000 void emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation); -#else -#error Missing or invalid TARGET_CPU -#endif - simpleFixupListType *emitJump(valueType *target, simpleFixupListType *previousFixups); #endif diff --git a/emitStuff.h b/emitStuff.h new file mode 100644 index 0000000..2028c3a --- /dev/null +++ b/emitStuff.h @@ -0,0 +1,27 @@ +#ifndef EMIT_STUFF_H_ +#define EMIT_STUFF_H_ + +#include "macrossTypes.h" + +void incarnateCodeBuffer(int bufferNum, codeBufferKindType bufferKind); +void putByte(addressType address, byte byteValue); +void mapByte(int address, byte byteValue); +void emitByte(byte byteValue); +void emitWord(wordType wordValue); +void emitLong(longType longValue); +void emitByteValue(valueType *byteValue); +void emitString(stringType *string); +void emitWordValue(valueType *wordValue); +void emitLongValue(valueType *longValue); +void pokeByteValue(addressType location, valueType *value); +void pokeWordValue(addressType location, valueType *value); +void pokeLongValue(addressType location, valueType *value); +void pokeRelativeByteValue(addressType location, valueType *value); +void pokeRelativeWordValue(addressType location, valueType *value); +byte getByte(addressType address); +void emitRelativeByteOffset(valueType *target); +void emitRelativeWordOffset(valueType *target); +void fixupBranch(valueType *location, valueType target); +void fixupJump(simpleFixupListType *locations, valueType target); + +#endif diff --git a/encode.h b/encode.h new file mode 100644 index 0000000..51a9db9 --- /dev/null +++ b/encode.h @@ -0,0 +1,37 @@ +#ifndef ENCODE_H_ +#define ENCODE_H_ + +#include "macrossTypes.h" + +bool encodeByte(byte aByte); +bool encodeBigword(int bigword); +bool encodeAssignmentTerm(binopTermType *assignmentTerm); +bool encodeBinopTerm(binopTermType *binopTerm); +bool encodeCondition(conditionType condition); +int functionNumber(functionDefinitionType *function); +bool encodeFunctionCall(functionCallTermType *functionCall); +bool encodeHere(void); +bool encodeIdentifier(symbolTableEntryType *identifier); +bool encodeNumber(numberTermType number); +bool encodeRelocatableNumber(numberTermType number); +bool encodeOperand(operandType *operand); +bool encodePostopTerm(postOpTermType *postopTerm); +bool encodePreopTerm(preOpTermType *preopTerm); +bool encodeString(stringType *string); +bool encodeUnopTerm(unopTermType *unopTerm); +bool encodeValue(valueType *value); +bool encodeExpression(expressionType *expression); +bool encodeAssertStatement(assertStatementBodyType *assertStatement); +bool encodeFreturnStatement(freturnStatementBodyType *freturnStatement); +bool encodeMdefineStatement(defineStatementBodyType *mdefineStatement); +bool encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); +bool encodeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); +bool encodeMforStatement(mforStatementBodyType *mforStatement); +bool encodeMifStatement(mifStatementBodyType *mifStatement); +bool encodeMswitchStatement(mswitchStatementBodyType *mswitchStatement); +bool encodeMvariableStatement(mvariableStatementBodyType *mvariableStatement); +bool encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement); +bool encodeStatement(statementType *statement); +bool encodeBlock(blockType *block); + +#endif diff --git a/errorStuff.h b/errorStuff.h index 4381169..8605c5f 100644 --- a/errorStuff.h +++ b/errorStuff.h @@ -1,16 +1,18 @@ #ifndef ERROR_STUFF_H_ #define ERROR_STUFF_H_ -void puntOnError (errorType theError, ...); -void printErrorMessage (errorType theError, va_list ap); -void error (errorType theError, ...); -void verror (errorType theError, va_list ap); -void warning (errorType theError, ...); -void fatalError (errorType theError, ...); -void fatalSystemError (errorType theError, ...); -void yyerror (char *s); -char *usageString (symbolUsageKindType usageKind); -char *valueKindString (valueKindType valueKind); -char *assignmentString (assignmentKindType assignment); +#include "macrossTypes.h" + +void puntOnError(errorType theError, ...); +void printErrorMessage(errorType theError, va_list ap); +void error(errorType theError, ...); +void verror(errorType theError, va_list ap); +void warning(errorType theError, ...); +void fatalError(errorType theError, ...); +void fatalSystemError(errorType theError, ...); +void yyerror(char *s); +char *usageString(symbolUsageKindType usageKind); +char *valueKindString(valueKindType valueKind); +char *assignmentString(assignmentKindType assignment); #endif diff --git a/expressionSemantics.h b/expressionSemantics.h index cd3edae..2137d13 100644 --- a/expressionSemantics.h +++ b/expressionSemantics.h @@ -1,11 +1,12 @@ #ifndef EXPRESSION_SEMANTICS_H_ #define EXPRESSION_SEMANTICS_H_ + #include "macrossTypes.h" anyOldThing *arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing); valueType *evaluateArrayTerm(arrayTermType *arrayTerm); valueType *evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup); -valueType *evaluateBinopTerm(binopTermType *assignmentTerm, bool isTopLevel, fixupKindType kindOfFixup); +valueType *evaluateBinopTerm(binopTermType *binopTerm, bool isTopLevel, fixupKindType kindOfFixup); valueType *evaluateCondition(conditionType condition); valueType *evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup); valueType *evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone); @@ -15,8 +16,8 @@ valueType *evaluateNumber(numberTermType number); valueType *evaluatePostopTerm(postOpTermType *postopTerm); valueType *evaluatePreopTerm(preOpTermType *preopTerm); valueType *evaluateString(stringType *string); -valueType *evaluateUnopTerm(unopTermType* unopTerm, fixupKindType kindOfFixup); -valueType *evaluateExpressionInternally(expressionType *expression, bool isToplevel, fixupKindType kindOfFixup, bool isStandalone); +valueType *evaluateUnopTerm(unopTermType *unopTerm, fixupKindType kindOfFixup); +valueType *evaluateExpressionInternally(expressionType *expression, bool isTopLevel, fixupKindType kindOfFixup, bool isStandalone); valueType *evaluateExpression(expressionType *expression, fixupKindType kindOfFixup); void evaluateExpressionStandalone(expressionType *expression); valueType *evaluateDefineExpression(expressionType *expression); diff --git a/fixups.h b/fixups.h new file mode 100644 index 0000000..b01f5c5 --- /dev/null +++ b/fixups.h @@ -0,0 +1,11 @@ +#ifndef FIXUPS_H_ +#define FIXUPS_H_ + +#include "macrossTypes.h" + +expressionType *generateFixupExpression(expressionType *expression); +expressionType *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); +functionCallTermType *duplicateFunctionCall(functionCallTermType *functionCall); +expressionType *duplicateArrayReference(arrayTermType *arrayTerm); + +#endif diff --git a/garbage.h b/garbage.h new file mode 100644 index 0000000..68f2138 --- /dev/null +++ b/garbage.h @@ -0,0 +1,66 @@ +#ifndef GARBAGE_H_ +#define GARBAGE_H_ + +#include "macrossTypes.h" + +void freeArrayTerm(arrayTermType *arrayTerm); +void freeAssignmentTerm(binopTermType *assignmentTerm); +void freeBinopTerm(binopTermType *binopTerm); +void freeFunctionCall(functionCallTermType *functionCall); +void freePostopTerm(postOpTermType *postopTerm); +void freePreopTerm(preOpTermType *preopTerm); +void freeString(stringType *string); +void freeUnopTerm(unopTermType *unopTerm); +void freeExpression(expressionType *expression); +void freeExpressionList(expressionListType *expressionList); +void freeIdentifierList(identifierListType *identifierList); +void freeSelectionList(selectionListType *selectionList); +void freeBlock(blockType *block); +void freeCase(caseType *aCase); +void freeCaseList(caseListType *caseList); +void freeOperandList(operandListType *operandList); +void freeMacro(operandListType *operands); +void freeMachineInstruction(operandListType *operands); +void freeAlignStatement(alignStatementBodyType *alignStatement); +void freeAssertStatement(assertStatementBodyType *assertStatement); +void freeBlockStatement(blockStatementBodyType *blockStatement); +void freeByteStatement(byteStatementBodyType *byteStatement); +void freeConstrainStatement(constrainStatementBodyType *constrainStatement); +void freeDbyteStatement(dbyteStatementBodyType *dbyteStatement); +void freeDefineStatement(defineStatementBodyType *defineStatement); +void freeDoUntilStatement(doUntilStatementBodyType *doUntilStatement); +void freeDoWhileStatement(doWhileStatementBodyType *doWhileStatement); +void freeExternStatement(externStatementBodyType *externStatement); +void freeFreturnStatement(freturnStatementBodyType *freturnStatement); +void freeFunctionStatement(functionStatementBodyType *functionStatement); +void freeIfStatement(ifStatementBodyType *ifStatement); +void freeIncludeStatement(includeStatementBodyType *includeStatement); +void freeInstructionStatement(instructionStatementBodyType *instructionStatement); +void freeLongStatement(longStatementBodyType *longStatement); +void freeMacroStatement(macroStatementBodyType *macroStatement); +void freeMdefineStatement(defineStatementBodyType *mdefineStatement); +void freeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); +void freeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); +void freeMifStatement(mifStatementBodyType *mifStatement); +void freeMswitchStatement(mswitchStatementBodyType *mswitchStatement); +void freeMforStatement(mforStatementBodyType *mforStatement); +void freeMvariableStatement(mvariableStatementBodyType *mvariableStatement); +void freeMwhileStatement(mwhileStatementBodyType *mwhileStatement); +void freeOrgStatement(orgStatementBodyType *orgStatement); +void freePerformStatement(performStatementBodyType *performStatement); +void freeRelStatement(relStatementBodyType *relStatement); +void freeStartStatement(startStatementBodyType *startStatement); +void freeStringStatement(stringStatementBodyType *stringStatement); +void freeStructStatement(structStatementBodyType *structStatement); +void freeTargetStatement(targetStatementBodyType *targetStatement); +void freeUndefineStatement(undefineStatementBodyType *undefineStatement); +void freeVariableStatement(variableStatementBodyType *variableStatement); +void freeWhileStatement(whileStatementBodyType *whileStatement); +void freeWordStatement(wordStatementBodyType *wordStatement); +void freeStatementBody(statementKindType kind, statementBodyType body); +void freeLabelList(labelListType *labelList); +void freeStatement(statementType *statement); +void freeArray(arrayType *array); +void freeValue(valueType *value); + +#endif diff --git a/initialize.h b/initialize.h new file mode 100644 index 0000000..1dd376c --- /dev/null +++ b/initialize.h @@ -0,0 +1,21 @@ +#ifndef INITIALIZE_H_ +#define INITIALIZE_H_ + +#include "macrossTypes.h" + +void chokePukeAndDie(void); +void initializeStuff(int argc, char **argv); +void installBuiltInFunctions(void); +void installPredefinedSymbols(void); +void installCommandLineDefineSymbols(void); +void createHashTables(void); +void queueInputFile(char *name); +void openFirstInputFile(void); +bool isDotMName(stringType *fileName); +bool parseCommandLineDefine(char *arg, char **name, int *value); +void noteCommandLineDefine(char *arg); + +/* Actually defined in main.c */ +void printVersion(void); + +#endif diff --git a/lexer.h b/lexer.h index a3f3031..4bdb184 100644 --- a/lexer.h +++ b/lexer.h @@ -1,32 +1,34 @@ #ifndef LEXER_H_ #define LEXER_H_ -int yylex (void); -int lexer (void); -void initializeLexDispatchTable (void); -bool isMacrossLiteralCharacter (char c); -void snarfAlphanumericString (char c, char *buffer); -int lexIdentifier (char c); -int lexNumber (char c); -int fancyAtoI (char *buffer, int base); -int digitValue (char c); -int lexLiteral (char c); -int lexCharacterConstant (void); -int getStringCharacter (FILE *input); -int lexStringConstant (void); -int lexOperator (char firstC); -char controlCharacter (char c); -char skipWhitespaceAndComments (void); -int popInputFileStack (void); -void pushInputFileStack (stringType *fileName); -void resynchronizeInput (void); -void saveLineForListing (stringType *line); -void saveEOLForListing (void); -void saveIndexForListing (statementKindType kindOfStatement, int cumulativeLineNumber); -void saveEndMifForListing (int cumulativeLineNumber); -void saveListingOff (void); -void saveListingOn (void); -char *myfgets (char *buffer, int length, FILE *stream); -int readAnotherLine (void); +#include "macrossTypes.h" + +int yylex(void); +int lexer(void); +void initializeLexDispatchTable(void); +bool isMacrossLiteralCharacter(char c); +void snarfAlphanumericString(char c, char *buffer); +int lexIdentifier(char c); +int lexNumber(char c); +int fancyAtoI(char *buffer, int base); +int digitValue(char c); +int lexLiteral(char c); +int lexCharacterConstant(void); +int getStringCharacter(FILE *input); +int lexStringConstant(void); +int lexOperator(char firstC); +char controlCharacter(char c); +char skipWhitespaceAndComments(void); +int popInputFileStack(void); +void pushInputFileStack(stringType *fileName); +void resynchronizeInput(void); +void saveLineForListing(stringType *line); +void saveEOLForListing(void); +void saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber); +void saveEndMifForListing(int cumulativeLineNumber); +void saveListingOff(void); +void saveListingOn(void); +char *myfgets(char *buffer, int length, FILE *stream); +int readAnotherLine(void); #endif diff --git a/listing.h b/listing.h index 58ec521..2512d4a 100644 --- a/listing.h +++ b/listing.h @@ -1,24 +1,22 @@ #ifndef LISTING_H_ #define LISTING_H_ -/* TODO: Functions here that have "format" arguments should actually - * be varargs. In 1984 it probably wasn't standardized, but here in - * Glorious Future Year 1989 the vprintf function does almost exactly - * what we want. */ +#include "macrossTypes.h" void outputListing(void); void terminateListingFiles(void); void generateListing(void); int printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind); -void readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char lineBuffer[], FILE *file); +void readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char *lineBuffer, FILE *file); void readIndexFileLine(statementKindType *statementKindPtr, int *indexAddressPtr, int *indexLineNumberPtr); int printListingLine(int numberOfBytes, int byteAddress, char *text, statementKindType kind); bool isBlockOpener(statementKindType statementKind); -bool isBlankStatment(statementKindType statementKind); +bool isBlankStatement(statementKindType statementKind); void tabPrint(stringType *text); -void printNTimes (char aChar, int times); +void printNTimes(char aChar, int times); void tabIndent(void); bool labeledLine(void); +void vaddText(char *buffer, char **bufferPtr, char *format, va_list ap); void addText(char *buffer, char **bufferPtr, char *format, ...); void moreTextOptional(char *buffer, char **bufferPtr, char *format, ...); void moreText(char *format, ...); @@ -36,6 +34,3 @@ void startLineMarked(void); bool notListable(statementKindType statementKind); #endif - - - diff --git a/lookups.h b/lookups.h index e9b2a0a..e61dc0a 100644 --- a/lookups.h +++ b/lookups.h @@ -1,27 +1,29 @@ #ifndef LOOKUPS_H_ #define LOOKUPS_H_ -conditionType lookupConditionCode (char *s, int hashValue); -int lookupKeyword (char *s, int hashValue); -macroTableEntryType *lookupMacroName (char *s, int hashValue); -opcodeTableEntryType *lookupOpcode (char *s, int hashValue); -symbolTableEntryType *lookupOrEnterSymbol (stringType *s, symbolUsageKindType kind); -void pushSymbol (symbolTableEntryType *symbol); -void popSymbol (symbolTableEntryType *symbol); -macroTableEntryType *createMacro (stringType *macroName); -genericTableEntryType *prehashedStringLookup (char *s, genericTableEntryType **table, int hashValue); -genericTableEntryType *hashStringLookup (char *s, genericTableEntryType **table); -genericTableEntryType *hashStringEnter (genericTableEntryType *entry, genericTableEntryType **table); -int hashString (char *s); -bool strcmplc (char *s1, char *s2); -bool strcmplct (char *s1, char *s2); -void purgeSymbol (symbolTableEntryType *symbol); -void reincarnateSymbol (symbolInContextType *context, symbolUsageKindType newUsage); -void pushBinding (symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); -void popBinding (symbolTableEntryType *symbol); -int bindMacroArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName); -int bindFunctionArguments (argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName); -void unbindArguments (argumentDefinitionListType *argumentList, int numberToUnbind); -void unbindLocalVariables (identifierListType *identifierList); +#include "macrossTypes.h" + +conditionType lookupConditionCode(char *s, int hashValue); +int lookupKeyword(char *s, int hashValue); +macroTableEntryType *lookupMacroName(char *s, int hashValue); +opcodeTableEntryType *lookupOpcode(char *s, int hashValue); +symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); +void pushSymbol(symbolTableEntryType *symbol); +void popSymbol(symbolTableEntryType *symbol); +macroTableEntryType *createMacro(stringType *macroName); +genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); +genericTableEntryType *hashStringLookup(char *s, genericTableEntryType **table); +genericTableEntryType *hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table); +int hashString(char *s); +bool strcmplc(char *s1, char *s2); +bool strcmplct(char *s1, char *s2); +void purgeSymbol(symbolTableEntryType *symbol); +void reincarnateSymbol(symbolInContextType *context, symbolUsageKindType newUsage); +void pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); +void popBinding(symbolTableEntryType *symbol); +int bindMacroArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName); +int bindFunctionArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName); +void unbindArguments(argumentDefinitionListType *argumentList, int numberToUnbind); +void unbindLocalVariables(identifierListType *identifierList); #endif diff --git a/object.h b/object.h new file mode 100644 index 0000000..955b636 --- /dev/null +++ b/object.h @@ -0,0 +1,37 @@ +#ifndef OBJECT_H_ +#define OBJECT_H_ + +#include "macrossTypes.h" + +void outputObjectFile(void); +void outputWord(int aWord); +void outputPartition(void); +void outputBigword(long unsigned int bigword); +void outputByte(byte aByte); +void outputString(stringType *string); +void outputStartAddress(addressType startAddress); +void outputRelocatableCode(void); +void outputBreak(codeBreakType *codeBreak); +void outputAbsoluteCode(void); +void outputOneCodeBuffer(codeSegmentType *segment); +void outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress); +bool isObjectSymbol(symbolTableEntryType *symbol); +void enumerateAndCountSymbols(void); +int enumerateAndCountReferences(void); +void outputReference(expressionReferenceType *reference); +void outputReferenceInfo(void); +void outputOneSymbol(symbolTableEntryType *symbol); +void outputSymbolTableInfo(void); +int symbolCompare(symbolTableEntryType **symbol1, symbolTableEntryType **symbol2); +bool shouldDumpSymbol(symbolTableEntryType *symbol); +void dumpSymbolTable(void); +bool hackableSymbol(symbolTableEntryType *symbol); +void printValueTersely(valueType *value); +void outputReservations(void); +void outputExpressionBuffer(void); +void outputOneExpression(expressionType *expression); +void outputExpressions(void); +void outputOneFunction(functionDefinitionType *function); +void outputFunctions(void); + +#endif diff --git a/operandStuff.h b/operandStuff.h index 796d565..80582f6 100644 --- a/operandStuff.h +++ b/operandStuff.h @@ -12,10 +12,10 @@ operandType *buildOperand(operandKindType kindOfOperand, int arg1, int arg2, int #endif operandListType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); -void expandOperand(operandKindType addressMode, char *buffer); void freeOperand(operandType *operand); +void expandOperand(operandKindType addressMode, char *buffer); valueType *evaluateOperand(operandType *operand); conditionType invertConditionCode(conditionType conditionCode); -bool shouldParethesize(operandType *operand); +bool shouldParenthesize(operandType *operand); #endif diff --git a/parserMisc.h b/parserMisc.h index 9984ce7..6835f3d 100644 --- a/parserMisc.h +++ b/parserMisc.h @@ -1,11 +1,12 @@ #ifndef PARSER_MISC_H_ #define PARSER_MISC_H_ + #include "macrossTypes.h" statementType *addLabelToStatement(labelListType *labelList, statementType *statement); void botch(char *message, ...); void checkDefineAssignmentOperator(assignmentKindType assignmentOperator); -void convertDefineToMDefine(statementType *defineStatement); +statementType *convertDefineToMdefine(statementType *defineStatement); ifStatementBodyType *extractIfBody(statementType *ifStatement); mifStatementBodyType *extractMifBody(statementType *mifStatement); stringType *extractString(operandType *textExpression); diff --git a/statementSemantics.h b/statementSemantics.h index 423c8fd..6ccbe59 100644 --- a/statementSemantics.h +++ b/statementSemantics.h @@ -5,26 +5,26 @@ void assembleBlock(blockType *block); simpleFixupListType *assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList); -bool operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType *evaluatedOperands[]); +bool operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); void assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands); void assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands); void assembleAlignStatement(alignStatementBodyType *alignStatement); void assembleAssertStatement(assertStatementBodyType *assertStatement); void assembleBlockStatement(blockStatementBodyType *blockStatement); -void assembleByteStatement(byteStatementBodyType *byeStatement); +void assembleByteStatement(byteStatementBodyType *byteStatement); void assembleConstrainStatement(constrainStatementBodyType *constrainStatement); void assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement); void assembleDefineStatement(defineStatementBodyType *defineStatement); void assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement); void assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement); void assembleExternStatement(externStatementBodyType *externStatement); -void assembleFReturnStatement(freturnStatementBodyType *freturnStatement); +void assembleFreturnStatement(freturnStatementBodyType *freturnStatement); void assembleFunctionStatement(functionStatementBodyType *functionStatement); void assembleGroupStatement(blockType *groupStatement); simpleFixupListType *assembleIfStatement(ifStatementBodyType *ifStatement, bool terminalIf, simpleFixupListType *ongoingFixupList); void assembleIfStatementOldStyle(ifStatementBodyType *ifStatement); void assembleIncludeStatement(includeStatementBodyType *includeStatement); -void assembleInstructionStatement(instructionStatementBodyType *Statement, int cumulativeLineNumber); +void assembleInstructionStatement(instructionStatementBodyType *instructionStatement, int cumulativeLineNumber); void assembleLongStatement(longStatementBodyType *longStatement); void assembleMacroStatement(macroStatementBodyType *macroStatement); void assembleMdefineStatement(defineStatementBodyType *mdefineStatement); @@ -46,9 +46,9 @@ void assembleUndefineStatement(undefineStatementBodyType *undefineStatement); void assembleVariableStatement(variableStatementBodyType *variableStatement); void assembleWhileStatement(whileStatementBodyType *whileStatement); void assembleWordStatement(wordStatementBodyType *wordStatement); -bool assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList); void assembleLabelList(labelListType *labelList); simpleFixupListType *assembleStatement(statementType *statement, bool insideIf, simpleFixupListType *ongoingFixupList); +bool assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList); void eatStatement(statementType *statement); #endif diff --git a/structSemantics.h b/structSemantics.h new file mode 100644 index 0000000..a623eb4 --- /dev/null +++ b/structSemantics.h @@ -0,0 +1,12 @@ +#ifndef STRUCT_SEMANTICS_H_ +#define STRUCT_SEMANTICS_H_ + +#include "macrossTypes.h" + +void putStructFixups(int base, fixupListType *fixups); +void putStructReferences(int base, expressionReferenceListType *references); +void instantiateStruct(structStatementBodyType *structStatement); +structInstanceType *assembleStructDefinitionBody(structBodyType *structBody); +void assembleStructDefinition(structStatementBodyType *structStatement); + +#endif diff --git a/tokenStrings.h b/tokenStrings.h new file mode 100644 index 0000000..2d7cf53 --- /dev/null +++ b/tokenStrings.h @@ -0,0 +1,9 @@ +#ifndef TOKEN_STRINGS_6502_H_ +#define TOKEN_STRINGS_6502_H_ + +#include "macrossTypes.h" + +char *conditionString(conditionType condition); +char *tokenString(int token); + +#endif From 0b99475ead50b157eb815a5a275dd7d3a08a0cab Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 21:50:12 -0800 Subject: [PATCH 32/41] 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"); From 4c56782718c9868a65872335e7247c703e245b17 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 21:51:21 -0800 Subject: [PATCH 33/41] Change make cleanup to more conventional make clean --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 753b9a4..aaf1092 100644 --- a/Makefile +++ b/Makefile @@ -167,7 +167,7 @@ y.tab.c y.tab.h: macross_$(PROC).y y.output: macross_$(PROC).y $(YACC) -vd macross_$(PROC).y -cleanup: +clean: /bin/rm -f *.o y.output y.tab.c y.tab.h macross love: From 4ab0baafe671a50c5b10bcbfa36434b7d6e300fc Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 22:37:08 -0800 Subject: [PATCH 34/41] Use varargs for errors in Slinky --- slinky/errorStuff.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/slinky/errorStuff.c b/slinky/errorStuff.c index e4a026d..4166f81 100644 --- a/slinky/errorStuff.c +++ b/slinky/errorStuff.c @@ -30,15 +30,10 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" - void -error(theError, arg1, arg2, arg3, arg4, arg5, arg6) - errorType theError; - anyOldThing *arg1; - anyOldThing *arg2; - anyOldThing *arg3; - anyOldThing *arg4; - anyOldThing *arg5; - anyOldThing *arg6; +#include + + static void +verror(errorType theError, va_list ap) { /* This table MUST be maintained congruently with the definition of the enumerated type 'errorType'. */ @@ -79,8 +74,16 @@ error(theError, arg1, arg2, arg3, arg4, arg5, arg6) }; printf("\"%s\": ", currentFileName); - printf(errorMessageStrings[(int)theError], arg1, arg2, arg3, arg4, - arg5, arg6); + vprintf(errorMessageStrings[(int)theError], ap); printf("\n"); errorFlag = TRUE; } + + void +error(errorType theError, ...) +{ + va_list ap; + va_start(ap, theError); + verror(theError, ap); + va_end(ap); +} From cefd64ed6fe999cb42696528bbba1796ec04ba87 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 22:53:59 -0800 Subject: [PATCH 35/41] Bring Slinky makefile in line with Macross --- slinky/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slinky/Makefile b/slinky/Makefile index 966c189..6ed9978 100644 --- a/slinky/Makefile +++ b/slinky/Makefile @@ -8,7 +8,7 @@ SOURCES = builtins.c debugPrint.c errorStuff.c expr.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 # slinky is not 64 bit clean +CFLAGS=-m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean .c.o: cc $(CFLAGS) -c -g $*.c @@ -71,7 +71,7 @@ slinkyTables.o: slinkyTables.c slinkyTypes.h write.o: write.c slinkyGlobals.h slinkyTypes.h -cleanup: +clean: /bin/rm -f *.o slinky love: From fa1c08008e644a5d99579134525503fb1acc9fe7 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 22:57:12 -0800 Subject: [PATCH 36/41] Push everything into headers for Slinky --- slinky/builtins.c | 6 ++++- slinky/builtins.h | 24 ++++++++++++++++++ slinky/debugPrint.c | 2 +- slinky/debugPrint.h | 14 +++++++++++ slinky/errorStuff.c | 1 + slinky/errorStuff.h | 8 ++++++ slinky/expr.c | 9 +++---- slinky/expr.h | 57 +++++++++++++++++++++++++++++++++++++++++++ slinky/initialize.c | 9 ++++--- slinky/initialize.h | 11 +++++++++ slinky/instantiate.c | 7 +++--- slinky/instantiate.h | 29 ++++++++++++++++++++++ slinky/link.c | 10 +++++++- slinky/link.h | 19 +++++++++++++++ slinky/main.c | 7 ++++-- slinky/main.h | 8 ++++++ slinky/map.c | 8 +++--- slinky/map.h | 14 +++++++++++ slinky/poke.c | 4 +++ slinky/poke.h | 15 ++++++++++++ slinky/read.c | 7 +++++- slinky/read.h | 28 +++++++++++++++++++++ slinky/relocate.c | 5 ++++ slinky/relocate.h | 22 +++++++++++++++++ slinky/slinkyTables.c | 18 +------------- slinky/slinkyTables.h | 7 ++++++ slinky/slinkyTypes.h | 4 +++ slinky/write.c | 1 + slinky/write.h | 10 ++++++++ 29 files changed, 323 insertions(+), 41 deletions(-) create mode 100644 slinky/builtins.h create mode 100644 slinky/debugPrint.h create mode 100644 slinky/errorStuff.h create mode 100644 slinky/expr.h create mode 100644 slinky/initialize.h create mode 100644 slinky/instantiate.h create mode 100644 slinky/link.h create mode 100644 slinky/main.h create mode 100644 slinky/map.h create mode 100644 slinky/poke.h create mode 100644 slinky/read.h create mode 100644 slinky/relocate.h create mode 100644 slinky/slinkyTables.h create mode 100644 slinky/write.h diff --git a/slinky/builtins.c b/slinky/builtins.c index 38b22a5..2fd9e6e 100644 --- a/slinky/builtins.c +++ b/slinky/builtins.c @@ -30,6 +30,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "builtins.h" +#include "errorStuff.h" +#include "expr.h" +#include "link.h" +#include "relocate.h" #include #define getSymbol() ((symbolType *)getNumber()) @@ -409,7 +414,6 @@ symbolLookupBIF(argCount) { symbolType *symbol; stringType *symbolName; - symbolType *lookupGlobalSymbol(); if (argCount < 1) { tooFewArgs(argCount, "symbolLookup"); diff --git a/slinky/builtins.h b/slinky/builtins.h new file mode 100644 index 0000000..703914e --- /dev/null +++ b/slinky/builtins.h @@ -0,0 +1,24 @@ +#ifndef BUILTINS_H_ +#define BUILTINS_H_ + +#include "slinkyTypes.h" + +void tooFewArgs(int argCount, stringType *name); +void tooManyArgs(int argCount, stringType *name); +stringType *atasciiBIF(int argCount); +stringType *atasciiColorBIF(int argCount); +bool isAbsoluteValueBIF(int argCount); +bool isConditionCodeBIF(int argCount); +bool isDefinedBIF(int argCount); +bool isExternalBIF(int argCount); +int nthCharBIF(int argCount); +int printfBIF(int argCount); +stringType *strcatBIF(int argCount); +int strcmpBIF(int argCount); +int strcmplcBIF(int argCount); +int strlenBIF(int argCount); +char *substrBIF(int argCount); +addressType symbolLookupBIF(int argCount); +stringType *symbolNameBIF(int argCount); + +#endif diff --git a/slinky/debugPrint.c b/slinky/debugPrint.c index 87048e9..add444b 100644 --- a/slinky/debugPrint.c +++ b/slinky/debugPrint.c @@ -31,7 +31,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" - +#include "debugPrint.h" static char *modeStrings[2] = { "abs", diff --git a/slinky/debugPrint.h b/slinky/debugPrint.h new file mode 100644 index 0000000..8112886 --- /dev/null +++ b/slinky/debugPrint.h @@ -0,0 +1,14 @@ +#ifndef DEBUG_PRINT_H_ +#define DEBUG_PRINT_H_ + +#include "slinkyTypes.h" + +void printCode(int startAddress, int endAddress, int mode); +void printReference(expressionReferenceType *reference); +void printReferenceFixup(expressionReferenceType *reference); +void printSymbol(int symbolTag, symbolType *symbol); +void printLoadMapSymbol(symbolType *symbol); +void printGlobalSymbols(void); +void printExpression(expressionPCType expression, int length); + +#endif diff --git a/slinky/errorStuff.c b/slinky/errorStuff.c index 4166f81..ede5892 100644 --- a/slinky/errorStuff.c +++ b/slinky/errorStuff.c @@ -29,6 +29,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "errorStuff.h" #include diff --git a/slinky/errorStuff.h b/slinky/errorStuff.h new file mode 100644 index 0000000..f1ec7c5 --- /dev/null +++ b/slinky/errorStuff.h @@ -0,0 +1,8 @@ +#ifndef ERROR_STUFF_H_ +#define ERROR_STUFF_H_ + +#include "slinkyTypes.h" + +void error(errorType theError, ...); + +#endif diff --git a/slinky/expr.c b/slinky/expr.c index 3eb59c7..6673f4b 100644 --- a/slinky/expr.c +++ b/slinky/expr.c @@ -30,6 +30,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "expr.h" +#include "errorStuff.h" +#include "initialize.h" #include "y.tab.h" #define overSymbol() (pc+=sizeof(symbolType *)) @@ -41,12 +44,6 @@ #define nextByte(byt) (byt = *pc++) #define intOp(byt) (byt+256) -addressType evaluateExpression(); -void skipArray(); -void skipClause(); -void skipString(); -void skipExpression(); - static bool hitFreturn = FALSE; static addressType functionResult; diff --git a/slinky/expr.h b/slinky/expr.h new file mode 100644 index 0000000..4321f9a --- /dev/null +++ b/slinky/expr.h @@ -0,0 +1,57 @@ +#ifndef EXPR_H_ +#define EXPR_H_ + +#include "slinkyTypes.h" + +int getNumber(void); +addressType evaluateArray(void); +addressType evaluateAssert(void); +addressType evaluateBinop(void); +addressType evaluateBlock(void); +addressType evaluateConditionCode(void); +void pushSymbol(symbolType *symbol, addressType value); +void bindFunctionArguments(functionType *theFunction, int argCount); +void undoBindings(void); +addressType evaluateFreturn(void); +addressType evaluateBuiltinFunctionCall(void); +addressType evaluateFunctionCall(void); +addressType evaluateHere(void); +addressType evaluateMdefine(void); +addressType evaluateMdoUntil(void); +addressType evaluateMdoWhile(void); +addressType evaluateMfor(void); +addressType evaluateMif(void); +bool evaluateClause(addressType pattern); +addressType evaluateMswitch(void); +addressType evaluateMwhile(void); +addressType evaluateMvariable(void); +addressType evaluateNumber(void); +addressType evaluateRelocatableNumber(void); +addressType evaluatePerform(void); +addressType evaluatePostop(void); +addressType evaluatePreop(void); +addressType evaluateString(void); +addressType evaluateSymbol(void); +addressType evaluateUnop(void); +addressType evaluateExpression(void); +void skipArray(void); +void skipAssert(void); +void skipBinop(void); +void skipBlock(void); +void skipFunctionCall(void); +void skipMdefine(void); +void skipMdoUntil(void); +void skipMdoWhile(void); +void skipMfor(void); +void skipMif(void); +void skipClause(void); +void skipMswitch(void); +void skipMvariable(void); +void skipMwhile(void); +void skipPostop(void); +void skipPreop(void); +void skipString(void); +void skipUnop(void); +void skipExpression(void); + +#endif diff --git a/slinky/initialize.c b/slinky/initialize.c index 3905f35..c0bfcf5 100644 --- a/slinky/initialize.c +++ b/slinky/initialize.c @@ -29,6 +29,12 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "initialize.h" +#include "errorStuff.h" +#include "main.h" + +#include +#include static char *outputFileName; @@ -52,9 +58,6 @@ initializeStuff(argc, argv) int mapFilesFound; char *mapFileName; - void queueInputFile(); - void queueLoadAddress(); - currentFileName = ""; errorFlag = FALSE; packFlag = FALSE; diff --git a/slinky/initialize.h b/slinky/initialize.h new file mode 100644 index 0000000..2d3de4a --- /dev/null +++ b/slinky/initialize.h @@ -0,0 +1,11 @@ +#ifndef INITIALIZE_H_ +#define INITIALIZE_H_ + +#include "slinkyTypes.h" + +void chokePukeAndDie(void); +void initializeStuff(int argc, char **argv); +void queueInputFile(char *name); +void queueLoadAddress(char *addressString); + +#endif diff --git a/slinky/instantiate.c b/slinky/instantiate.c index 65fc4b1..05bc646 100644 --- a/slinky/instantiate.c +++ b/slinky/instantiate.c @@ -31,6 +31,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "errorStuff.h" +#include "expr.h" +#include "instantiate.h" #include "y.tab.h" #define overFunction() (pc+=sizeof(functionType *)) @@ -38,10 +41,6 @@ #define overByte() pc++ #define nextByte(byt) (byt = *pc++) -void putSymbolPointersIntoArray(); -void putSymbolPointersIntoClause(); -void putSymbolPointersIntoExpression(); - void putNumber(number) int number; diff --git a/slinky/instantiate.h b/slinky/instantiate.h new file mode 100644 index 0000000..78571ca --- /dev/null +++ b/slinky/instantiate.h @@ -0,0 +1,29 @@ +#ifndef INSTANTIATE_H_ +#define INSTANTIATE_H_ + +#include "slinkyTypes.h" + +void putNumber(int number); +void instantiateSymbol(void); +void instantiateFunction(void); +void putSymbolPointersIntoArray(void); +void putSymbolPointersIntoAssert(void); +void putSymbolPointersIntoBinop(void); +void putSymbolPointersIntoBlock(void); +void putSymbolPointersIntoBuiltinFunctionCall(void); +void putSymbolPointersIntoFunctionCall(void); +void putSymbolPointersIntoMdefine(void); +void putSymbolPointersIntoMdoUntil(void); +void putSymbolPointersIntoMdoWhile(void); +void putSymbolPointersIntoMfor(void); +void putSymbolPointersIntoMif(void); +void putSymbolPointersIntoClause(void); +void putSymbolPointersIntoMswitch(void); +void putSymbolPointersIntoMvariable(void); +void putSymbolPointersIntoMwhile(void); +void putSymbolPointersIntoPostop(void); +void putSymbolPointersIntoPreop(void); +void putSymbolPointersIntoUnop(void); +void putSymbolPointersIntoExpression(void); + +#endif diff --git a/slinky/link.c b/slinky/link.c index 2900ef6..5059186 100644 --- a/slinky/link.c +++ b/slinky/link.c @@ -29,6 +29,15 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "link.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "instantiate.h" +#include "poke.h" +#include "read.h" +#include "relocate.h" +#include "write.h" + /*#define readWord(f,fn) ((getc(f) & 0xFF) | ((getc(f) & 0xFF)<<8))*/ /* @@ -102,7 +111,6 @@ internalizeOneObjectFile(objectFile) int mode; addressType startAddress; addressType endAddress; - bool compareSymbolValues(); currentFileName = objectFile->name; if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { diff --git a/slinky/link.h b/slinky/link.h new file mode 100644 index 0000000..2eceb1e --- /dev/null +++ b/slinky/link.h @@ -0,0 +1,19 @@ +#ifndef LINK_H_ +#define LINK_H_ + +#include "slinkyTypes.h" + +bool internalizeOneObjectFile(objectFileListType *objectFile); +bool strcmplc(char *s1, char *s2); +bool compareSymbols(symbolType **symbol1, symbolType **symbol2); +void buildGlobalSymbolTable(objectFileListType *inputFileList); +bool readem(void); +codeSegmentHeaderType *locateConflictingSegment(codeSegmentHeaderType *codeSegment); +void reserveSegment(addressType start, addressType end); +codeSegmentHeaderType *allocateAbsolute(codeSegmentHeaderType *codeSegment); +void reserveReservations(void); +void installSegment(codeSegmentHeaderType *codeSegment); +void installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment); +void linkem(void); + +#endif diff --git a/slinky/main.c b/slinky/main.c index abcc6a9..89455e7 100644 --- a/slinky/main.c +++ b/slinky/main.c @@ -29,7 +29,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "main.h" +#include "initialize.h" +#include "link.h" +int main(argc, argv) int argc; char *argv[]; @@ -38,8 +42,7 @@ main(argc, argv) linkem(); if (errorFlag) chokePukeAndDie(); - else - exit(0); + return 0; } void diff --git a/slinky/main.h b/slinky/main.h new file mode 100644 index 0000000..c102f42 --- /dev/null +++ b/slinky/main.h @@ -0,0 +1,8 @@ +#ifndef MAIN_H_ +#define MAIN_H_ + +#include "slinkyTypes.h" + +void printVersion(void); + +#endif diff --git a/slinky/map.c b/slinky/map.c index 41f0c5c..dab44a1 100644 --- a/slinky/map.c +++ b/slinky/map.c @@ -30,11 +30,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" - -typedef struct { - symbolType *symbol; - stringType *fileName; - } loadMapTableEntryType; +#include "map.h" +#include "debugPrint.h" +#include "link.h" int compareLoadMapEntries(entry1, entry2) diff --git a/slinky/map.h b/slinky/map.h new file mode 100644 index 0000000..294344f --- /dev/null +++ b/slinky/map.h @@ -0,0 +1,14 @@ +#ifndef MAP_H_ +#define MAP_H_ + +#include "slinkyTypes.h" + +typedef struct { + symbolType *symbol; + stringType *fileName; + } loadMapTableEntryType; + +int compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2); +void outputLoadMap(void); + +#endif diff --git a/slinky/poke.c b/slinky/poke.c index 94b7b27..89fac42 100644 --- a/slinky/poke.c +++ b/slinky/poke.c @@ -31,6 +31,10 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "poke.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "expr.h" bool isWordSized(value) diff --git a/slinky/poke.h b/slinky/poke.h new file mode 100644 index 0000000..94c69bd --- /dev/null +++ b/slinky/poke.h @@ -0,0 +1,15 @@ +#ifndef POKE_H_ +#define POKE_H_ + +#include "slinkyTypes.h" + +bool isWordSized(int value); +bool isByteSized(int value); +bool isByteOffset(int value); +int computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset); +int getBaseValue(byte *codeBuffer, int offset, int referenceKind); +void pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress); +void fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment); +void pokem(void); + +#endif diff --git a/slinky/read.c b/slinky/read.c index 242cc4a..aab35b0 100644 --- a/slinky/read.c +++ b/slinky/read.c @@ -31,6 +31,12 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "read.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "initialize.h" +#include "instantiate.h" +#include "link.h" #define isAbsolute(symbol) (((symbol)->symbolClass & SYMBOL_ABSOLUTE) != 0) #define isRelocatable(symbol) (((symbol)->symbolClass &SYMBOL_RELOCATABLE)!=0) @@ -520,7 +526,6 @@ readReservations(objectFile, objectFildes) FILE *objectFildes; { addressType startAddress; - reservationListType *buildReservation(); if (debug) printf(" reservations\n"); diff --git a/slinky/read.h b/slinky/read.h new file mode 100644 index 0000000..a88557a --- /dev/null +++ b/slinky/read.h @@ -0,0 +1,28 @@ +#ifndef READ_H_ +#define READ_H_ + +#include "slinkyTypes.h" + +void fileCheck(FILE *fildes, char *fileName); +wordType readWord(FILE *file, char *fileName); +byte readByte(FILE *file, char *fileName); +bigWord readBigword(FILE *file, char *fileName); +bigWord read3ByteWord(FILE *file, char *fileName); +int readString(char *buffer, FILE *fildes, char *fileName); +void readChunk(byte *buffer, int numberOfBytes, FILE *fildes, char *fileName); +void readCode(addressType startAddress, addressType endAddress, int mode, objectFileListType *objectFile, FILE *objectFildes); +bool compareReferences(expressionReferenceType *reference1, expressionReferenceType *reference2); +void sortReferences(expressionReferenceType *theReferences, int numberOfReferences); +void readReference(expressionReferenceType *reference, FILE *fildes, char *fileName); +void readReferences(objectFileListType *objectFile, FILE *objectFildes); +bool compareSymbolValues(symbolType **symbol1, symbolType **symbol2); +void readSymbols(objectFileListType *objectFile, FILE *objectFildes); +expressionPCType readOneExpression(objectFileListType *objectFile, FILE *objectFildes); +void readExpressions(objectFileListType *objectFile, FILE *objectFildes); +argumentListType *readArgumentList(objectFileListType *objectFile, FILE *objectFildes); +void readFunctions(objectFileListType *objectFile, FILE *objectFildes); +void instantiateExpressionAndSymbolPointers(objectFileListType *objectFile); +void readReservations(objectFileListType *objectFile, FILE *objectFildes); +reservationListType *buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation); + +#endif diff --git a/slinky/relocate.c b/slinky/relocate.c index c04f95b..a108d8a 100644 --- a/slinky/relocate.c +++ b/slinky/relocate.c @@ -30,6 +30,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "relocate.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "link.h" +#include "map.h" #define isUndefined(symbol) (((symbol)->symbolClass & ~SYMBOL_EXTERNAL) == 0) diff --git a/slinky/relocate.h b/slinky/relocate.h new file mode 100644 index 0000000..ebdcf9f --- /dev/null +++ b/slinky/relocate.h @@ -0,0 +1,22 @@ +#ifndef RELOCATE_H_ +#define RELOCATE_H_ + +#include "slinkyTypes.h" + +void removeZeroPageFromFreeList(void); +addressType align(addressType address, int alignment); +addressType constrain(addressType address, int size, addressType constraint); +void moveRelocationBase(addressType newBase); +addressType allocateRelocatable(codeSegmentHeaderType *codeSegment); +void relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation); +void relocatem(void); +codeSegmentHeaderType *matchModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); +bool matchedModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); +codeSegmentHeaderType *synchronizeCodeSegment(symbolType *symbol, codeSegmentHeaderType *codeSegment); +void handleGlobalSymbol(symbolType *symbol); +void valueSymbol(symbolType *symbol, codeSegmentHeaderType *codeSegment); +symbolType *lookupGlobalSymbol(char *symbolName); +void valueUndefinedSymbol(symbolType *symbol); +void valuem(void); + +#endif diff --git a/slinky/slinkyTables.c b/slinky/slinkyTables.c index d4ecc71..6146fb5 100644 --- a/slinky/slinkyTables.c +++ b/slinky/slinkyTables.c @@ -28,23 +28,7 @@ */ #include "slinkyTypes.h" - -addressType atasciiBIF(); -addressType atasciiColorBIF(); -addressType isAbsoluteValueBIF(); -addressType isConditionCodeBIF(); -addressType isDefinedBIF(); -addressType isExternalBIF(); -addressType nthCharBIF(); -addressType printfBIF(); -addressType strcatBIF(); -addressType strcmpBIF(); -addressType strcmplcBIF(); -addressType strlenBIF(); -addressType substrBIF(); -addressType symbolDefineBIF(); -addressType symbolLookupBIF(); -addressType symbolNameBIF(); +#include "builtins.h" /* Used to initialize symbols representing built-in functions */ struct { diff --git a/slinky/slinkyTables.h b/slinky/slinkyTables.h new file mode 100644 index 0000000..30ca7e3 --- /dev/null +++ b/slinky/slinkyTables.h @@ -0,0 +1,7 @@ +#ifndef SLINKY_TABLES_H_ +#define SLINKY_TABLES_H_ + +#include "slinkyTypes.h" + + +#endif diff --git a/slinky/slinkyTypes.h b/slinky/slinkyTypes.h index 2f41f51..161a143 100644 --- a/slinky/slinkyTypes.h +++ b/slinky/slinkyTypes.h @@ -26,6 +26,8 @@ 8-March-1985 */ +#ifndef SLINKY_TYPES_H_ +#define SLINKY_TYPES_H_ #include #include @@ -188,3 +190,5 @@ typedef enum { #define typeAlloc(type) (type *)malloc(sizeof(type)) #define typeAllocBlock(type, size) (type *)malloc(sizeof(type) * (size)) + +#endif diff --git a/slinky/write.c b/slinky/write.c index b73b8e9..740e923 100644 --- a/slinky/write.c +++ b/slinky/write.c @@ -30,6 +30,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "write.h" #define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\ putc((aWord >> 8) & 0xFF, loadFileOutput) diff --git a/slinky/write.h b/slinky/write.h new file mode 100644 index 0000000..e4b616c --- /dev/null +++ b/slinky/write.h @@ -0,0 +1,10 @@ +#ifndef WRITE_H_ +#define WRITE_H_ + +#include "slinkyTypes.h" + +void writeEntryPoint(void); +void writeCodeSegment(codeSegmentHeaderType *codeSegment); +void writem(void); + +#endif From 693c15a2a8a5bdd7d21a94be92b3e27affcb2f31 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 23 Jan 2016 23:13:44 -0800 Subject: [PATCH 37/41] Protoize. --- slinky/builtins.c | 54 +++++++--------------- slinky/debugPrint.c | 24 +++------- slinky/expr.c | 105 +++++++++++++++++++++---------------------- slinky/initialize.c | 12 ++--- slinky/instantiate.c | 45 +++++++++---------- slinky/link.c | 36 +++++---------- slinky/main.c | 6 +-- slinky/map.c | 6 +-- slinky/poke.c | 32 ++++--------- slinky/read.c | 91 +++++++++---------------------------- slinky/relocate.c | 50 +++++++-------------- slinky/write.c | 7 ++- 12 files changed, 163 insertions(+), 305 deletions(-) diff --git a/slinky/builtins.c b/slinky/builtins.c index 2fd9e6e..fb627f5 100644 --- a/slinky/builtins.c +++ b/slinky/builtins.c @@ -40,9 +40,7 @@ #define getSymbol() ((symbolType *)getNumber()) void -tooFewArgs(argCount, name) - int argCount; - stringType *name; +tooFewArgs(int argCount, stringType *name) { error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, name); while (argCount-- > 0) @@ -50,9 +48,7 @@ tooFewArgs(argCount, name) } void -tooManyArgs(argCount, name) - int argCount; - stringType *name; +tooManyArgs(int argCount, stringType *name) { error(TOO_MANY_ARGUMENTS_TO_BIF_ERROR, name); while (argCount-- > 0) @@ -89,8 +85,7 @@ static char atasciiTable[] = { /* 0xFFs will become 0x00s on output */ /* Convert a string to ATASCII */ stringType * -atasciiBIF(argCount) - int argCount; +atasciiBIF(int argCount) { stringType *string; stringType *newString; @@ -113,8 +108,7 @@ atasciiBIF(argCount) /* Convert a string to ATASCII while setting high-order color bits */ stringType * -atasciiColorBIF(argCount) - int argCount; +atasciiColorBIF(int argCount) { stringType *string; stringType *newString; @@ -149,8 +143,7 @@ atasciiColorBIF(argCount) /* Check if an operand is absolute (as opposed to relocatable) */ bool -isAbsoluteValueBIF(argCount) - int argCount; +isAbsoluteValueBIF(int argCount) { if (argCount > 1) tooManyArgs(argCount, "isAbsoluteValue"); @@ -159,8 +152,7 @@ isAbsoluteValueBIF(argCount) /* Check if operand is a condition code */ bool -isConditionCodeBIF(argCount) - int argCount; +isConditionCodeBIF(int argCount) { bool result; @@ -177,8 +169,7 @@ isConditionCodeBIF(argCount) /* Check if a symbol is defined */ bool -isDefinedBIF(argCount) - int argCount; +isDefinedBIF(int argCount) { symbolType *symbol; @@ -199,8 +190,7 @@ isDefinedBIF(argCount) /* Check if a symbol is externally visible */ bool -isExternalBIF(argCount) - int argCount; +isExternalBIF(int argCount) { symbolType *symbol; @@ -221,8 +211,7 @@ isExternalBIF(argCount) /* Return the Nth character of a string (as an integer) */ int -nthCharBIF(argCount) - int argCount; +nthCharBIF(int argCount) { stringType *string; int position; @@ -245,8 +234,7 @@ nthCharBIF(argCount) /* Pass stuff through to stdio's 'printf' function */ int -printfBIF(argCount) - int argCount; +printfBIF(int argCount) { stringType *formatString; int argument[20]; @@ -274,8 +262,7 @@ printfBIF(argCount) /* Concatenate two strings */ stringType * -strcatBIF(argCount) - int argCount; +strcatBIF(int argCount) { stringType *string1; stringType *string2; @@ -299,8 +286,7 @@ strcatBIF(argCount) /* Compare two strings */ int -strcmpBIF(argCount) - int argCount; +strcmpBIF(int argCount) { stringType *string1; stringType *string2; @@ -319,9 +305,7 @@ strcmpBIF(argCount) /* Compare two strings in a case-independent fashion */ int -strcmplcBIF(argCount) - int argCount; - +strcmplcBIF(int argCount) { stringType *string1; stringType *string2; @@ -340,8 +324,7 @@ strcmplcBIF(argCount) /* Return the length of a string */ int -strlenBIF(argCount) - int argCount; +strlenBIF(int argCount) { if (argCount < 1) return(0); @@ -354,8 +337,7 @@ strlenBIF(argCount) /* Return a substring of a string */ char * -substrBIF(argCount) - int argCount; +substrBIF(int argCount) { stringType *string; int start; @@ -409,8 +391,7 @@ substrBIF(argCount) /* Turn a string into a symbol and return its value */ addressType -symbolLookupBIF(argCount) - int argCount; +symbolLookupBIF(int argCount) { symbolType *symbol; stringType *symbolName; @@ -433,8 +414,7 @@ symbolLookupBIF(argCount) /* Turn a symbol into a string */ stringType * -symbolNameBIF(argCount) - int argCount; +symbolNameBIF(int argCount) { symbolType *symbol; diff --git a/slinky/debugPrint.c b/slinky/debugPrint.c index add444b..461fd07 100644 --- a/slinky/debugPrint.c +++ b/slinky/debugPrint.c @@ -64,18 +64,14 @@ static char *symbolStrings[6] = { }; void -printCode(startAddress, endAddress, mode) - int startAddress; - int endAddress; - int mode; +printCode(int startAddress, int endAddress, int mode) { printf(" Code: 0x%04x:0x%04x %s\n", startAddress, endAddress, modeStrings[mode]); } void -printReference(reference) - expressionReferenceType *reference; +printReference(expressionReferenceType *reference) { printf(" Ref : 0x%04x (%s %s %s %s) expression #%d\n", reference-> referenceAddress, modeStrings[reference->referenceMode], @@ -85,8 +81,7 @@ printReference(reference) } void -printReferenceFixup(reference) - expressionReferenceType *reference; +printReferenceFixup(expressionReferenceType *reference) { printf(" Ref : 0x%04x (%s %s %s %s) expression=0x%x\n", reference->referenceAddress, modeStrings[reference-> @@ -97,9 +92,7 @@ printReferenceFixup(reference) } void -printSymbol(symbolTag, symbol) - int symbolTag; - symbolType *symbol; +printSymbol(int symbolTag, symbolType *symbol) { printf(" Symb: %3d %s 0x%04x \"%s\"\n", symbolTag, symbolStrings[ symbol->symbolClass], symbol->symbolValue, @@ -107,15 +100,14 @@ printSymbol(symbolTag, symbol) } void -printLoadMapSymbol(symbol) - symbolType *symbol; +printLoadMapSymbol(symbolType *symbol) { fprintf(mapFileOutput, "%-20s 0x%04x %s ", symbol->symbolName, symbol->symbolValue, symbolStrings[symbol->symbolClass]); } void -printGlobalSymbols() +printGlobalSymbols(void) { int symbolCount; @@ -128,9 +120,7 @@ printGlobalSymbols() } void -printExpression(expression, length) - expressionPCType expression; - int length; +printExpression(expressionPCType expression, int length) { int line; int i; diff --git a/slinky/expr.c b/slinky/expr.c index 6673f4b..e4000b7 100644 --- a/slinky/expr.c +++ b/slinky/expr.c @@ -48,7 +48,7 @@ static bool hitFreturn = FALSE; static addressType functionResult; int -getNumber() +getNumber(void) { register int result; register int i; @@ -61,7 +61,7 @@ getNumber() } addressType -evaluateArray() +evaluateArray(void) { error(ARRAY_TERM_IN_OBJECT_ERROR); skipArray(); @@ -69,7 +69,7 @@ evaluateArray() } addressType -evaluateAssert() +evaluateAssert(void) { if (!evaluateExpression()) error(ASSERT_FAILED_ERROR, pc); @@ -77,7 +77,7 @@ evaluateAssert() } addressType -evaluateBinop() +evaluateBinop(void) { int op; symbolType *leftSymbol; @@ -156,7 +156,7 @@ evaluateBinop() } addressType -evaluateBlock() +evaluateBlock(void) { while (*pc != END_TAG) { evaluateExpression(); @@ -169,7 +169,7 @@ evaluateBlock() } addressType -evaluateConditionCode() +evaluateConditionCode(void) { overByte(); error(CONDITION_CODE_EXPRESSION_ENCOUNTERED_ERROR); @@ -177,9 +177,7 @@ evaluateConditionCode() } void -pushSymbol(symbol, value) - symbolType *symbol; - addressType value; +pushSymbol(symbolType *symbol, addressType value) { bindingListType *newBinding; @@ -194,9 +192,7 @@ pushSymbol(symbol, value) } void -bindFunctionArguments(theFunction, argCount) - functionType *theFunction; - int argCount; +bindFunctionArguments(functionType *theFunction, int argCount) { argumentListType *argList; @@ -220,7 +216,7 @@ bindFunctionArguments(theFunction, argCount) } void -undoBindings() +undoBindings(void) { bindingListType *deadBinding; @@ -236,7 +232,7 @@ undoBindings() } addressType -evaluateFreturn() +evaluateFreturn(void) { hitFreturn = TRUE; functionResult = evaluateExpression(); @@ -244,7 +240,7 @@ evaluateFreturn() } addressType -evaluateBuiltinFunctionCall() +evaluateBuiltinFunctionCall(void) { int theFunction; int argCount; @@ -259,7 +255,7 @@ evaluateBuiltinFunctionCall() } addressType -evaluateFunctionCall() +evaluateFunctionCall(void) { expressionPCType savePoint; functionType *theFunction; @@ -285,13 +281,13 @@ evaluateFunctionCall() } addressType -evaluateHere() +evaluateHere(void) { return(here); } addressType -evaluateMdefine() +evaluateMdefine(void) { symbolType *symbol; @@ -300,7 +296,7 @@ evaluateMdefine() } addressType -evaluateMdoUntil() +evaluateMdoUntil(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -317,7 +313,7 @@ evaluateMdoUntil() } addressType -evaluateMdoWhile() +evaluateMdoWhile(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -334,7 +330,7 @@ evaluateMdoWhile() } addressType -evaluateMfor() +evaluateMfor(void) { expressionPCType testPoint; expressionPCType incrPoint; @@ -364,7 +360,7 @@ evaluateMfor() } addressType -evaluateMif() +evaluateMif(void) { if (evaluateExpression()) { evaluateExpression(); @@ -377,8 +373,7 @@ evaluateMif() } bool -evaluateClause(pattern) - addressType pattern; +evaluateClause(addressType pattern) { bool match; @@ -396,7 +391,7 @@ evaluateClause(pattern) } addressType -evaluateMswitch() +evaluateMswitch(void) { addressType pattern; @@ -411,7 +406,7 @@ evaluateMswitch() } addressType -evaluateMwhile() +evaluateMwhile(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -430,7 +425,7 @@ evaluateMwhile() } addressType -evaluateMvariable() +evaluateMvariable(void) { symbolType *symbol; @@ -439,7 +434,7 @@ evaluateMvariable() } addressType -evaluateNumber() +evaluateNumber(void) { addressType result; int i; @@ -452,20 +447,20 @@ evaluateNumber() } addressType -evaluateRelocatableNumber() +evaluateRelocatableNumber(void) { return(evaluateNumber() + relocationOffset); } addressType -evaluatePerform() +evaluatePerform(void) { evaluateExpression(); return(0); } addressType -evaluatePostop() +evaluatePostop(void) { int op; symbolType *target; @@ -482,7 +477,7 @@ evaluatePostop() } addressType -evaluatePreop() +evaluatePreop(void) { int op; symbolType *target; @@ -499,7 +494,7 @@ evaluatePreop() } addressType -evaluateString() +evaluateString(void) { addressType result; @@ -510,7 +505,7 @@ evaluateString() } addressType -evaluateSymbol() +evaluateSymbol(void) { symbolType *target; @@ -519,7 +514,7 @@ evaluateSymbol() } addressType -evaluateUnop() +evaluateUnop(void) { int op; addressType arg; @@ -545,7 +540,7 @@ evaluateUnop() } addressType -evaluateExpression() +evaluateExpression(void) { if (pc == NULL) return(0); @@ -647,21 +642,21 @@ evaluateExpression() } void -skipArray() +skipArray(void) { overSymbol(); skipExpression(); } void -skipAssert() +skipAssert(void) { skipExpression(); skipString(); } void -skipBinop() +skipBinop(void) { overByte(); skipExpression(); @@ -669,7 +664,7 @@ skipBinop() } void -skipBlock() +skipBlock(void) { while (*pc != END_TAG) skipExpression(); @@ -677,7 +672,7 @@ skipBlock() } void -skipFunctionCall() +skipFunctionCall(void) { int argCount; @@ -688,28 +683,28 @@ skipFunctionCall() } void -skipMdefine() +skipMdefine(void) { overSymbol(); skipExpression(); } void -skipMdoUntil() +skipMdoUntil(void) { skipExpression(); skipExpression(); } void -skipMdoWhile() +skipMdoWhile(void) { skipExpression(); skipExpression(); } void -skipMfor() +skipMfor(void) { skipExpression(); skipExpression(); @@ -718,7 +713,7 @@ skipMfor() } void -skipMif() +skipMif(void) { skipExpression(); skipExpression(); @@ -726,7 +721,7 @@ skipMif() } void -skipClause() +skipClause(void) { while (*pc != BLOCK_TAG) skipExpression; @@ -734,7 +729,7 @@ skipClause() } void -skipMswitch() +skipMswitch(void) { skipExpression(); while (*pc != END_TAG) @@ -743,49 +738,49 @@ skipMswitch() } void -skipMvariable() +skipMvariable(void) { overSymbol(); skipExpression(); } void -skipMwhile() +skipMwhile(void) { skipExpression(); skipExpression(); } void -skipPostop() +skipPostop(void) { overByte(); skipExpression(); } void -skipPreop() +skipPreop(void) { overByte(); skipExpression(); } void -skipString() +skipString(void) { while (*pc++ != '\0') ; } void -skipUnop() +skipUnop(void) { overByte(); skipExpression(); } void -skipExpression() +skipExpression(void) { if (pc == NULL) return; diff --git a/slinky/initialize.c b/slinky/initialize.c index c0bfcf5..dfab2a2 100644 --- a/slinky/initialize.c +++ b/slinky/initialize.c @@ -39,16 +39,14 @@ static char *outputFileName; void -chokePukeAndDie() +chokePukeAndDie(void) { unlink(outputFileName); exit(1); } void -initializeStuff(argc, argv) - int argc; - char *argv[]; +initializeStuff(int argc, char **argv) { int i; int j; @@ -177,8 +175,7 @@ initializeStuff(argc, argv) void -queueInputFile(name) - char *name; +queueInputFile(char *name) { objectFileListType *newObjectFile; @@ -197,8 +194,7 @@ queueInputFile(name) } void -queueLoadAddress(addressString) - char *addressString; +queueLoadAddress(char *addressString) { int loadAddress; objectFileListType *newObjectFile; diff --git a/slinky/instantiate.c b/slinky/instantiate.c index 05bc646..4d2f5c1 100644 --- a/slinky/instantiate.c +++ b/slinky/instantiate.c @@ -42,8 +42,7 @@ #define nextByte(byt) (byt = *pc++) void -putNumber(number) - int number; +putNumber(int number) { int i; for (i=0; istartAddress, @@ -408,8 +398,7 @@ reserveReservations() } void -installSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +installSegment(codeSegmentHeaderType *codeSegment) { segmentListType *previousSegment; segmentListType *installSegmentList; @@ -444,8 +433,7 @@ installSegment(codeSegment) } void -installAbsoluteCodeSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment) { codeSegmentHeaderType *conflictingSegment; @@ -460,7 +448,7 @@ installAbsoluteCodeSegment(codeSegment) } void -linkem() +linkem(void) { if (!readem()) return; diff --git a/slinky/main.c b/slinky/main.c index 89455e7..c363fca 100644 --- a/slinky/main.c +++ b/slinky/main.c @@ -34,9 +34,7 @@ #include "link.h" int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char **argv) { initializeStuff(argc, argv); linkem(); @@ -46,7 +44,7 @@ main(argc, argv) } void -printVersion() +printVersion(void) { printf("Slinky version 1.16.\n"); } diff --git a/slinky/map.c b/slinky/map.c index dab44a1..3f3eec9 100644 --- a/slinky/map.c +++ b/slinky/map.c @@ -35,9 +35,7 @@ #include "link.h" int -compareLoadMapEntries(entry1, entry2) - loadMapTableEntryType *entry1; - loadMapTableEntryType *entry2; +compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2) { int result; @@ -53,7 +51,7 @@ compareLoadMapEntries(entry1, entry2) } void -outputLoadMap() +outputLoadMap(void) { loadMapTableEntryType *loadMapTable; loadMapTableEntryType *loadMapPtr; diff --git a/slinky/poke.c b/slinky/poke.c index 89fac42..53d6b57 100644 --- a/slinky/poke.c +++ b/slinky/poke.c @@ -37,31 +37,25 @@ #include "expr.h" bool -isWordSized(value) - int value; +isWordSized(int value) { return (-32768<=value && value<=65535); } bool -isByteSized(value) - int value; +isByteSized(int value) { return (-128<=value && value<=255); } bool -isByteOffset(value) - int value; +isByteOffset(int value) { return (-128<=value && value<=127); } int -computeRelativeValue(valueToPoke, codeSegment, offset) - int valueToPoke; - codeSegmentHeaderType *codeSegment; - int offset; +computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset) { int fromLocation; int result; @@ -81,10 +75,7 @@ computeRelativeValue(valueToPoke, codeSegment, offset) } int -getBaseValue(codeBuffer, offset, referenceKind) - byte codeBuffer[]; - int offset; - int referenceKind; +getBaseValue(byte *codeBuffer, int offset, int referenceKind) { int result; @@ -105,12 +96,7 @@ getBaseValue(codeBuffer, offset, referenceKind) } void -pokeValue(value, codeBuffer, offset, referenceKind, trueAddress) - int value; - byte codeBuffer[]; - int offset; - int referenceKind; - int trueAddress; +pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress) { switch (referenceKind) { case REF_BYTE: @@ -154,9 +140,7 @@ pokeValue(value, codeBuffer, offset, referenceKind, trueAddress) } void -fixupReference(reference, codeSegment) - expressionReferenceType *reference; - codeSegmentHeaderType *codeSegment; +fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment) { int offset; addressType baseValue; @@ -186,7 +170,7 @@ fixupReference(reference, codeSegment) } void -pokem() +pokem(void) { objectFileListType *inputFileList; codeSegmentHeaderType *codeSegment; diff --git a/slinky/read.c b/slinky/read.c index aab35b0..0a8cbae 100644 --- a/slinky/read.c +++ b/slinky/read.c @@ -42,9 +42,7 @@ #define isRelocatable(symbol) (((symbol)->symbolClass &SYMBOL_RELOCATABLE)!=0) void -fileCheck(fildes, fileName) - FILE *fildes; - char *fileName; +fileCheck(FILE *fildes, char *fileName) { if (feof(fildes)) { error(PREMATURE_EOF_ERROR, fileName); @@ -57,9 +55,7 @@ fileCheck(fildes, fileName) } wordType -readWord(file, fileName) - FILE *file; - char *fileName; +readWord(FILE *file, char *fileName) { wordType result; register char loByte; @@ -73,9 +69,7 @@ readWord(file, fileName) } byte -readByte(file, fileName) - FILE *file; - char *fileName; +readByte(FILE *file, char *fileName) { int result; @@ -86,9 +80,7 @@ readByte(file, fileName) } bigWord -readBigword(file, fileName) - FILE *file; - char *fileName; +readBigword(FILE *file, char *fileName) { register bigWord result; @@ -101,9 +93,7 @@ readBigword(file, fileName) } bigWord -read3ByteWord(file, fileName) - FILE *file; - char *fileName; +read3ByteWord(FILE *file, char *fileName) { register bigWord result; @@ -115,10 +105,7 @@ read3ByteWord(file, fileName) } int -readString(buffer, fildes, fileName) - char *buffer; - FILE *fildes; - char *fileName; +readString(char *buffer, FILE *fildes, char *fileName) { register char c; register char *scratchBuffer; @@ -132,11 +119,7 @@ readString(buffer, fildes, fileName) } void -readChunk(buffer, numberOfBytes, fildes, fileName) - byte *buffer; - int numberOfBytes; - FILE *fildes; - char *fileName; +readChunk(byte *buffer, int numberOfBytes, FILE *fildes, char *fileName) { do { *buffer++ = getc(fildes); @@ -145,12 +128,7 @@ readChunk(buffer, numberOfBytes, fildes, fileName) } void -readCode(startAddress, endAddress, mode, objectFile, objectFildes) - addressType startAddress; - addressType endAddress; - int mode; - objectFileListType *objectFile; - FILE *objectFildes; +readCode(addressType startAddress, addressType endAddress, int mode, objectFileListType *objectFile, FILE *objectFildes) { int size; byte *codeBuffer; @@ -199,9 +177,7 @@ readCode(startAddress, endAddress, mode, objectFile, objectFildes) } bool -compareReferences(reference1, reference2) - expressionReferenceType *reference1; - expressionReferenceType *reference2; +compareReferences(expressionReferenceType *reference1, expressionReferenceType *reference2) { if (reference1->referenceMode == MODE_ABSOLUTE && reference2-> referenceMode == MODE_RELOCATABLE) @@ -218,19 +194,14 @@ compareReferences(reference1, reference2) } void -sortReferences(theReferences, numberOfReferences) - expressionReferenceType *theReferences; - int numberOfReferences; +sortReferences(expressionReferenceType *theReferences, int numberOfReferences) { qsort(theReferences, numberOfReferences, sizeof(expressionReferenceType), compareReferences); } void -readReference(reference, fildes, fileName) - expressionReferenceType *reference; - FILE *fildes; - char *fileName; +readReference(expressionReferenceType *reference, FILE *fildes, char *fileName) { register byte funnyByte; @@ -247,9 +218,7 @@ readReference(reference, fildes, fileName) } void -readReferences(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readReferences(objectFileListType *objectFile, FILE *objectFildes) { int count; int readCount; @@ -298,9 +267,7 @@ readReferences(objectFile, objectFildes) } bool -compareSymbolValues(symbol1, symbol2) - symbolType **symbol1; - symbolType **symbol2; +compareSymbolValues(symbolType **symbol1, symbolType **symbol2) { if ((isAbsolute(*symbol1) && !isAbsolute(*symbol2)) || (isRelocatable(*symbol1) && !isRelocatable(*symbol2) @@ -321,9 +288,7 @@ compareSymbolValues(symbol1, symbol2) } void -readSymbols(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readSymbols(objectFileListType *objectFile, FILE *objectFildes) { symbolType *symbolTable; symbolType **symbolTableIndir; @@ -365,9 +330,7 @@ readSymbols(objectFile, objectFildes) } expressionPCType -readOneExpression(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readOneExpression(objectFileListType *objectFile, FILE *objectFildes) { char *fileName; int expressionSize; @@ -392,9 +355,7 @@ readOneExpression(objectFile, objectFildes) } void -readExpressions(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readExpressions(objectFileListType *objectFile, FILE *objectFildes) { expressionPCType *expressions; int expressionCount; @@ -426,9 +387,7 @@ readExpressions(objectFile, objectFildes) } argumentListType * -readArgumentList(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readArgumentList(objectFileListType *objectFile, FILE *objectFildes) { int argumentCount; char *fileName; @@ -453,9 +412,7 @@ readArgumentList(objectFile, objectFildes) } void -readFunctions(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readFunctions(objectFileListType *objectFile, FILE *objectFildes) { functionType *functions; int functionCount; @@ -489,8 +446,7 @@ readFunctions(objectFile, objectFildes) } void -instantiateExpressionAndSymbolPointers(objectFile) - objectFileListType *objectFile; +instantiateExpressionAndSymbolPointers(objectFileListType *objectFile) { symbolType **symbolTable; expressionPCType *expressions; @@ -521,9 +477,7 @@ instantiateExpressionAndSymbolPointers(objectFile) } void -readReservations(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readReservations(objectFileListType *objectFile, FILE *objectFildes) { addressType startAddress; @@ -537,10 +491,7 @@ readReservations(objectFile, objectFildes) } reservationListType * -buildReservation(startAddress, blockSize, nextReservation) - addressType startAddress; - int blockSize; - reservationListType *nextReservation; +buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation) { reservationListType *result; diff --git a/slinky/relocate.c b/slinky/relocate.c index a108d8a..1a2bfd9 100644 --- a/slinky/relocate.c +++ b/slinky/relocate.c @@ -39,7 +39,7 @@ #define isUndefined(symbol) (((symbol)->symbolClass & ~SYMBOL_EXTERNAL) == 0) void -removeZeroPageFromFreeList() +removeZeroPageFromFreeList(void) { while (freeSegmentList->segmentEndAddress <= 0x100) freeSegmentList = freeSegmentList->nextFreeSegment; @@ -48,9 +48,7 @@ removeZeroPageFromFreeList() } addressType -align(address, alignment) - addressType address; - int alignment; +align(addressType address, int alignment) { if (alignment == 0) return(address); @@ -59,10 +57,7 @@ align(address, alignment) } addressType -constrain(address, size, constraint) - addressType address; - int size; - addressType constraint; +constrain(addressType address, int size, addressType constraint) { if (constraint == 0) return(address); @@ -72,8 +67,7 @@ constrain(address, size, constraint) return(address); } void -moveRelocationBase(newBase) - addressType newBase; +moveRelocationBase(addressType newBase) { freeSegmentEntryType *freePtr; freeSegmentEntryType *newFreePtr; @@ -95,8 +89,7 @@ moveRelocationBase(newBase) } addressType -allocateRelocatable(codeSegment) - codeSegmentHeaderType *codeSegment; +allocateRelocatable(codeSegmentHeaderType *codeSegment) { freeSegmentEntryType *freePtr; freeSegmentEntryType *previousPtr; @@ -151,9 +144,7 @@ allocateRelocatable(codeSegment) } void -relocateOneCodeSegment(codeSegment, targetLocation) - codeSegmentHeaderType *codeSegment; - addressType targetLocation; +relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation) { int relocationOffset; @@ -175,7 +166,7 @@ relocateOneCodeSegment(codeSegment, targetLocation) } void -relocatem() +relocatem(void) { objectFileListType *inputFileList; addressType targetLocation; @@ -210,9 +201,7 @@ relocatem() } codeSegmentHeaderType * -matchModes(symbol, codeSegment) - symbolType *symbol; - codeSegmentHeaderType *codeSegment; +matchModes(symbolType *symbol, codeSegmentHeaderType *codeSegment) { while (codeSegment!=NULL && ((codeSegment->segmentMode==MODE_ABSOLUTE && !(symbol->symbolClass & SYMBOL_ABSOLUTE)) || @@ -224,9 +213,7 @@ matchModes(symbol, codeSegment) } bool -matchedModes(symbol, codeSegment) - symbolType *symbol; - codeSegmentHeaderType *codeSegment; +matchedModes(symbolType *symbol, codeSegmentHeaderType *codeSegment) { return(((symbol->symbolClass & SYMBOL_ABSOLUTE) && codeSegment-> segmentMode == MODE_ABSOLUTE) || ((symbol->symbolClass & @@ -235,9 +222,7 @@ matchedModes(symbol, codeSegment) } codeSegmentHeaderType * -synchronizeCodeSegment(symbol, codeSegment) - symbolType *symbol; - codeSegmentHeaderType *codeSegment; +synchronizeCodeSegment(symbolType *symbol, codeSegmentHeaderType *codeSegment) { codeSegment = matchModes(symbol, codeSegment); while (codeSegment != NULL && codeSegment->nextSegment != NULL && @@ -250,15 +235,12 @@ synchronizeCodeSegment(symbol, codeSegment) } void -handleGlobalSymbol(symbol) - symbolType *symbol; +handleGlobalSymbol(symbolType *symbol) { } void -valueSymbol(symbol, codeSegment) - symbolType *symbol; - codeSegmentHeaderType *codeSegment; +valueSymbol(symbolType *symbol, codeSegmentHeaderType *codeSegment) { if (symbol->symbolClass & SYMBOL_ABSOLUTE) { return; @@ -270,8 +252,7 @@ valueSymbol(symbol, codeSegment) } symbolType * -lookupGlobalSymbol(symbolName) - char *symbolName; +lookupGlobalSymbol(char *symbolName) { int guess; int top; @@ -300,8 +281,7 @@ lookupGlobalSymbol(symbolName) } void -valueUndefinedSymbol(symbol) - symbolType *symbol; +valueUndefinedSymbol(symbolType *symbol) { symbolType *globalSymbol; @@ -314,7 +294,7 @@ valueUndefinedSymbol(symbol) } void -valuem() +valuem(void) { objectFileListType *inputFileList; codeSegmentHeaderType *codeSegmentPtr; diff --git a/slinky/write.c b/slinky/write.c index 740e923..007cb71 100644 --- a/slinky/write.c +++ b/slinky/write.c @@ -37,7 +37,7 @@ #define writeByte(aByte) putc(aByte & 0xFF, loadFileOutput) void -writeEntryPoint() +writeEntryPoint(void) { writeWord(entryPointAddress); writeWord(entryPointAddress); @@ -45,8 +45,7 @@ writeEntryPoint() } void -writeCodeSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +writeCodeSegment(codeSegmentHeaderType *codeSegment) { int length; int i; @@ -60,7 +59,7 @@ writeCodeSegment(codeSegment) } void -writem() +writem(void) { int regionNumber; codeSegmentHeaderType *lastSegment; From d53658da5eb03e3538f199819621455985a39058 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 24 Jan 2016 00:00:20 -0800 Subject: [PATCH 38/41] 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 { From c2dff5c4c33beddd3caaf577b2cc7a5ba2923251 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 24 Jan 2016 00:04:00 -0800 Subject: [PATCH 39/41] Remove cruft and gcc-5-only flags from Makefiles --- Makefile | 41 +++-------------------------------------- slinky/Makefile | 26 +------------------------- 2 files changed, 4 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index fed6a77..fc32f24 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,9 @@ HEADERS = macrossTypes.h macrossGlobals.h # Macross is not 64-bit clean and it does a lot of silent downcasting # to simulate subclasses and uses int and void * interchangably a -# bunch. -CFLAGS=-m32 -Wno-int-conversion -Wno-incompatible-pointer-types +# bunch. gcc calls these the int-conversion and +# incompatible-pointer-types warnings. +CFLAGS=-m32 # If yacc is notionally present on a system, it's usually actually # bison in a compatibility mode. bison is available by name more often @@ -48,42 +49,6 @@ macross: $(OBJECTS) driver: driver.c cc $(CFLAGS) -o driver driver.c -update: .mark - kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & - -install: macross - cp macross /u1/gg/bin/macross_tmp - strip /u1/gg/bin/macross_tmp - mv /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old - mv /u1/gg/bin/macross_tmp /u1/gg/bin/macross_$(PROC) - cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin - cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin - cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin - -dinstall: driver - cp driver /u1/gg/bin/driver_tmp - strip /u1/gg/bin/driver_tmp - mv /u1/gg/bin/driver_tmp /u1/gg/bin/driver/macross - cp /u1/gg/bin/driver /net/mycroft/u1/gg/bin/macross - cp /u1/gg/bin/driver /net/shem/u1/gg/bin/macross - cp /u1/gg/bin/driver /net/weyr/u1/gg/bin/macross - -change: - rm *.o - rm *.tab.* - cp Makefile_68000 Makefile - -move: .mark - -.mark: $(SOURCES) - cp $? /net/kessel/u0/chip/macross - cp $? /net/kessel/u0/chip/macross/prof - cp $? opt - date >.mark - date >/net/kessel/u0/chip/macross/.mark - date >/net/kessel/u0/chip/macross/prof/.mark - date >opt/.mark - macrossTypes.h: operandDefs_$(PROC).h operandBody_$(PROC).h\ conditionDefs_$(PROC).h diff --git a/slinky/Makefile b/slinky/Makefile index aa566ff..4082250 100644 --- a/slinky/Makefile +++ b/slinky/Makefile @@ -8,7 +8,7 @@ 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=-O2 -m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean +CFLAGS= -m32 # slinky is not 64 bit clean .c.o: cc $(CFLAGS) -c $*.c @@ -19,30 +19,6 @@ CFLAGS=-O2 -m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is slinky: $(OBJECTS) cc $(CFLAGS) -g -o slinky $(OBJECTS) -update: .mark - kessel "(cd /u0/chip/macross/slinky; make slinky >&errorfyle)" & - -move: .mark - -.mark: $(SOURCES) -# cp $? /net/kessel/u0/chip/macross/slinky - cp $? /net/kessel/u0/chip/macross/slinky -# cp $? /net/kessel/u0/chip/macross/slinky/prof - cp $? /net/kessel/u0/chip/macross/slinky/prof - cp $? opt - date >.mark -# date >/net/kessel/u0/chip/macross/slinky/.mark - date >/net/kessel/u0/chip/macross/slinky/.mark -# date >/net/kessel/u0/chip/macross/slinky/prof/.mark - date >/net/kessel/u0/chip/macross/slinky/prof/.mark - date >opt/.mark - -install: slinky - cp slinky /u1/gg/bin/slinky_tmp - strip /u1/gg/bin/slinky_tmp - mv /u1/gg/bin/slinky /u1/gg/bin/sliny.old - mv /u1/gg/bin/slinky_tmp /u1/gg/bin/slinky - builtins.o: builtins.c slinkyGlobals.h slinkyTypes.h slinkyExpressions.h debugPrint.o: debugPrint.c slinkyGlobals.h slinkyTypes.h From d2d8ab6bfc7891bb0380113404c68cf9ce182483 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 24 Jan 2016 00:10:35 -0800 Subject: [PATCH 40/41] rename swab to avoid conflict with string.h --- semanticMisc.c | 4 ++-- semanticMisc.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/semanticMisc.c b/semanticMisc.c index 644e264..05efaa4 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -725,7 +725,7 @@ subValueKind(valueType *leftOperand, valueType *rightOperand) } int -swab(int i) +swabInt(int i) { return(((i & 0xFF) << 8) | ((i & 0xFF00) >> 8)); } @@ -733,7 +733,7 @@ swab(int i) valueType * swabValue(valueType *value) { - return(newValue(value->kindOfValue, swab(value->value), value-> + return(newValue(value->kindOfValue, swabInt(value->value), value-> addressMode)); } diff --git a/semanticMisc.h b/semanticMisc.h index 0533c35..e6f9211 100644 --- a/semanticMisc.h +++ b/semanticMisc.h @@ -36,7 +36,7 @@ valueKindType opValueKind(valueType *leftOperand, valueType *rightOperand); bool relocatableValue(valueType *address); valueKindType selectValueKind(valueType *leftOperand, valueType *rightOperand); valueKindType subValueKind(valueType *leftOperand, valueType *rightOperand); -int swab(int i); +int swabInt(int i); valueType *swabValue(valueType *value); valueKindType unopValueKind(valueType *operand); void valueField(symbolTableEntryType *symbol, valueType *value); From 877c4bfacc5b5ab29270995ea0d1d1e6cc086c50 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 24 Jan 2016 15:56:45 -0800 Subject: [PATCH 41/41] Extra headers and casts so it can compile with the -ansi flag --- errorStuff.h | 2 ++ listing.h | 2 ++ main.c | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/errorStuff.h b/errorStuff.h index 8605c5f..5b94cbe 100644 --- a/errorStuff.h +++ b/errorStuff.h @@ -3,6 +3,8 @@ #include "macrossTypes.h" +#include + void puntOnError(errorType theError, ...); void printErrorMessage(errorType theError, va_list ap); void error(errorType theError, ...); diff --git a/listing.h b/listing.h index 2512d4a..181e5de 100644 --- a/listing.h +++ b/listing.h @@ -3,6 +3,8 @@ #include "macrossTypes.h" +#include + void outputListing(void); void terminateListingFiles(void); void generateListing(void); diff --git a/main.c b/main.c index 7226ecb..f050847 100644 --- a/main.c +++ b/main.c @@ -48,9 +48,14 @@ main(int argc, char **argv) initializeStuff(argc, argv); yyparse(); finishUp(); + /* sbrk() ends up having different signatures depending on compiler + * flags and system. We cast here out of an abundance of caution. + * This, and the "end" variable above, are both just for this one + * diagnostic, so if they're causing your build trouble, they can + * be safely deleted. --mcm */ if (emitPrint) - printf("storage high water mark 0x%x == %d\n", sbrk(0) - (void *)(&end), - sbrk(0) - (void *)(&end)); + printf("storage high water mark 0x%x == %d\n", (void *)sbrk(0) - (void *)(&end), + (void *)sbrk(0) - (void *)(&end)); if (errorFlag) chokePukeAndDie(); return 0;