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 diff --git a/Makefile b/Makefile index 9e34208..fc32f24 100644 --- a/Makefile +++ b/Makefile @@ -7,23 +7,35 @@ 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\ -malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.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\ -lookups.c macrossTables_$(PROC).c main.c malloc.c object.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\ 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 -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. 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 +# than yacc itself is. +YACC=bison -y +#YACC=yacc .c.o: cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) $*.c @@ -37,43 +49,7 @@ 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: 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) @@ -86,7 +62,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 @@ -105,11 +81,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) @@ -117,9 +93,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) @@ -127,8 +103,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) @@ -137,11 +111,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) @@ -153,12 +127,12 @@ 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: +clean: /bin/rm -f *.o y.output y.tab.c y.tab.h macross love: 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/actions_6502.c b/actions_6502.c index 97338db..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,11 +49,8 @@ and operand. */ - void -actionsDir1(opcode, numberOfOperands, evaluatedOperands) - opcodeTableEntryType *opcode; - int numberOfOperands; - valueType *evaluatedOperands[]; +void +actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands) { #define ZERO_PAGE_ADDRESS_BIT 0x00 #define NON_ZERO_PAGE_ADDRESS_BIT 0x08 @@ -66,10 +67,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 +77,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 +93,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 +125,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 +154,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 +175,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 +200,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 +225,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 +261,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 +297,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 +354,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 +396,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 +427,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/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/buildStuff1.c b/buildStuff1.c index 5c9bdc3..82b33be 100644 --- a/buildStuff1.c +++ b/buildStuff1.c @@ -32,15 +32,14 @@ #include "macrossTypes.h" #include "macrossGlobals.h" - -symbolTableEntryType *lookupOrEnterSymbol(); -char *saveString(); +#include "errorStuff.h" +#include "lookups.h" +#include "parserMisc.h" /* Generic routine to create statement nodes */ - statementType * -newStatement(kind, body) - statementKindType kind; - statementBodyType body; + +statementType * +newStatement(statementKindType kind, statementBodyType body) { statementType *result; @@ -62,17 +61,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 +80,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 +106,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 +124,7 @@ buildDefineStatement(name, value) } statementType * -buildDoUntilStatement(body, condition) - blockType *body; - conditionType condition; +buildDoUntilStatement(blockType *body, conditionType condition) { doUntilStatementBodyType *result; @@ -148,9 +135,7 @@ buildDoUntilStatement(body, condition) } statementType * -buildDoWhileStatement(body, condition) - blockType *body; - conditionType condition; +buildDoWhileStatement(blockType *body, conditionType condition) { doWhileStatementBodyType *result; @@ -161,9 +146,7 @@ buildDoWhileStatement(body, condition) } statementType * -buildDoStatement(body, end) - blockType *body; - doEndType *end; +buildDoStatement(blockType *body, doEndType *end) { statementType *result; @@ -178,26 +161,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 +194,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 +229,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 +248,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 +267,7 @@ buildMacroStatement(macro, arguments, body) } statementType * -buildMacroInstructionStatement(macro, operands) - macroTableEntryType *macro; - operandListType *operands; +buildMacroInstructionStatement(macroTableEntryType *macro, operandListType *operands) { instructionStatementBodyType *result; @@ -314,9 +279,7 @@ buildMacroInstructionStatement(macro, operands) } statementType * -buildMdefineStatement(name, value) - stringType *name; - expressionType *value; +buildMdefineStatement(stringType *name, expressionType *value) { mdefineStatementBodyType *result; @@ -327,9 +290,7 @@ buildMdefineStatement(name, value) } statementType * -buildMdoUntilStatement(body, condition) - blockType *body; - ExpressionType *condition; +buildMdoUntilStatement(blockType *body, struct expressionTermStruct *condition) { mdoUntilStatementBodyType *result; @@ -340,9 +301,7 @@ buildMdoUntilStatement(body, condition) } statementType * -buildMdoWhileStatement(body, condition) - blockType *body; - expressionType *condition; +buildMdoWhileStatement(blockType *body, expressionType *condition) { mdoWhileStatementBodyType *result; @@ -353,26 +312,22 @@ buildMdoWhileStatement(body, condition) } statementType * -buildMdoStatement(body, end) - blockType *body; - doEndType *end; +buildMdoStatement(blockType *body, 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); } statementType * -buildMforStatement(forExpressions, body) - forExpressionsType *forExpressions; - blockType *body; +buildMforStatement(forExpressionsType *forExpressions, blockType *body) { mforStatementBodyType *result; @@ -386,10 +341,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 +369,7 @@ buildMifStatement(head, continuation, continuationKind) } statementType * -buildMswitchStatement(switchExpression, cases) - expressionType *switchExpression; - caseListType *cases; +buildMswitchStatement(expressionType *switchExpression, caseListType *cases) { mswitchStatementBodyType *result; @@ -430,10 +380,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 +392,7 @@ buildMvariableStatement(name, value, dimension) } statementType * -buildMwhileStatement(condition, body) - expressionType *condition; - blockType *body; +buildMwhileStatement(expressionType *condition, blockType *body) { mwhileStatementBodyType *result; @@ -458,53 +403,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 +454,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 +480,7 @@ buildVariableStatement(name, value, dimension) } statementType * -buildWhileStatement(condition, body) - conditionType condition; - blockType *body; +buildWhileStatement(conditionType condition, blockType *body) { whileStatementBodyType *result; @@ -559,8 +491,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..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,8 @@ /* Fragments of statement structures */ - caseType * -buildCase(caseTags, caseBody) - expressionListType *caseTags; - blockType *caseBody; +buildCase(expressionListType *caseTags, blockType *caseBody) { caseType *result; @@ -55,9 +54,7 @@ buildCase(caseTags, caseBody) } doEndType * -buildDoEnd(condition, kindOfDoEnd) - conditionType condition; - doEndKindType kindOfDoEnd; +buildDoEnd(conditionType condition, doEndKindType kindOfDoEnd) { doEndType *result; @@ -68,10 +65,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 +77,7 @@ buildForExpressions(initExpression, testExpression, incrExpression) } ifHeadType * -buildIfHead(condition, block) - conditionType condition; - blockType *block; +buildIfHead(conditionType condition, blockType *block) { ifHeadType *result; @@ -96,9 +88,7 @@ buildIfHead(condition, block) } mdoEndType * -buildMdoEnd(condition, kindOfMdoEnd) - expressionType *condition; - doEndKindType kindOfMdoEnd; +buildMdoEnd(expressionType *condition, doEndKindType kindOfMdoEnd) { mdoEndType *result; @@ -110,9 +100,7 @@ buildMdoEnd(condition, kindOfMdoEnd) mifHeadType * -buildMifHead(condition, block) - expressionType *condition; - blockType *block; +buildMifHead(expressionType *condition, blockType *block) { mifHeadType *result; @@ -126,9 +114,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 +125,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 +137,9 @@ buildBinopTerm(binop, leftArgument, rightArgument) } functionCallTermType * -buildFunctionCall(functionName, arguments) - stringType *functionName; - operandListType *arguments; +buildFunctionCall(stringType *functionName, operandListType *arguments) { functionCallTermType *result; - symbolTableEntryType *lookupOrEnterSymbol(); result = typeAlloc(functionCallTermType); result->functionName = lookupOrEnterSymbol(functionName, @@ -169,9 +149,7 @@ buildFunctionCall(functionName, arguments) } postOpTermType * -buildPostOpTerm(postOp, postOpArgument) - postOpKindType postOp; - expressionType *postOpArgument; +buildPostOpTerm(postOpKindType postOp, expressionType *postOpArgument) { postOpTermType *result; @@ -182,9 +160,7 @@ buildPostOpTerm(postOp, postOpArgument) } preOpTermType * -buildPreOpTerm(preOp, preOpArgument) - preOpKindType preOp; - expressionType *preOpArgument; +buildPreOpTerm(preOpKindType preOp, expressionType *preOpArgument) { preOpTermType *result; @@ -195,9 +171,7 @@ buildPreOpTerm(preOp, preOpArgument) } unopTermType * -buildUnopTerm(unop, unopArgument) - unopKindType unop; - expressionType *unopArgument; +buildUnopTerm(unopKindType unop, expressionType *unopArgument) { unopTermType *result; @@ -208,16 +182,10 @@ 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(); - result = typeAlloc(expressionType); result->kindOfTerm = kindOfExpressionTerm; switch (kindOfExpressionTerm) { @@ -298,11 +266,9 @@ buildExpressionTerm(kindOfExpressionTerm, arg1, arg2, arg3) /* Other stuff */ macroTableEntryType * -buildMacroTableEntry(name) - stringType *name; +buildMacroTableEntry(stringType *name) { macroTableEntryType *result; - char *saveString(); result = typeAlloc(macroTableEntryType); result->macroName = saveString(name); @@ -313,12 +279,9 @@ buildMacroTableEntry(name) } symbolTableEntryType * -buildSymbolTableEntry(name, usage) - stringType *name; - symbolUsageKindType usage; +buildSymbolTableEntry(stringType *name, symbolUsageKindType usage) { symbolTableEntryType *result; - char *saveString(); result = typeAlloc(symbolTableEntryType); result->symbolName = saveString(name); @@ -335,10 +298,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 +311,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 +323,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 ef81ec9..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 @@ -43,14 +44,10 @@ */ argumentListHeadType * -buildArgumentList(new, rest, arrayTag) - stringType *new; - argumentListHeadType *rest; - bool arrayTag; +buildArgumentList(stringType *new, argumentListHeadType *rest, bool arrayTag) { argumentListHeadType *newListHead; argumentDefinitionListType *newArgument; - symbolTableEntryType *lookupOrEnterSymbol(); 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,16 +123,11 @@ 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(); - if (rest == NULL) { newListHead = typeAlloc(identifierListHeadType); newListHead->theSymbol = lookupOrEnterSymbol(new, usage); @@ -160,9 +148,7 @@ buildIdentifierList(new, rest, usage) } labelListHeadType * -buildLabelList(new, rest) - symbolTableEntryType *new; - labelListHeadType *rest; +buildLabelList(symbolTableEntryType *new, labelListHeadType *rest) { labelListHeadType *newLabelHead; labelListType *newLabel; @@ -187,9 +173,7 @@ buildLabelList(new, rest) } operandListHeadType * -buildOperandList(new, rest) - operandType *new; - operandListHeadType *rest; +buildOperandList(operandType *new, operandListHeadType *rest) { operandListHeadType *newListHead; @@ -213,17 +197,13 @@ buildOperandList(new, rest) } selectionListHeadType * -buildSelectionList(new, rest) - selectionListType *new; - selectionListHeadType *rest; +buildSelectionList(selectionListType *new, selectionListHeadType *rest) { - return((selectionListHeadType *) buildIdentifierList(new, 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 4fdc6b4..25d0f7a 100644 --- a/builtInFunctions.c +++ b/builtInFunctions.c @@ -30,61 +30,62 @@ #include "macrossTypes.h" #include "macrossGlobals.h" -#include +#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 + /* Helper routines to return values into the Macross expression evaluation environment */ - valueType * -makeBooleanValue(test) - int test; +valueType * +makeBooleanValue(int test) { - valueType *newValue(); return(newValue(ABSOLUTE_VALUE, test!=0, EXPRESSION_OPND)); } valueType * -makeFailureValue() +makeFailureValue(void) { - valueType *newValue(); return(newValue(FAIL, 0, EXPRESSION_OPND)); } valueType * -makeIntegerValue(integer) - int integer; +makeIntegerValue(int integer) { - valueType *newValue(); return(newValue(ABSOLUTE_VALUE, integer, EXPRESSION_OPND)); } valueType * -makeOperandValue(operand) - operandType *operand; +makeOperandValue(operandType *operand) { - valueType *newValue(); return(newValue(OPERAND_VALUE, operand, EXPRESSION_OPND)); } valueType * -makeStringValue(string) - stringType *string; +makeStringValue(stringType *string) { - valueType *newValue(); return(newValue(STRING_VALUE, string, STRING_OPND)); } valueType * -makeUndefinedValue() +makeUndefinedValue(void) { - valueType *newValue(); return(newValue(UNDEFINED_VALUE, 0, EXPRESSION_OPND)); } @@ -99,16 +100,13 @@ makeUndefinedValue() /* Return internal address mode of an operand */ valueType * -addressModeBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +addressModeBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(evaluatedParameter->addressMode)); } else { return(makeIntegerValue(-1)); @@ -117,22 +115,17 @@ 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(); - 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()); @@ -149,16 +142,13 @@ applyBIF(parameterList, kindOfFixup) /* return the length of an array */ valueType * -arrayLengthBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +arrayLengthBIF(operandListType *parameterList, 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) { @@ -192,20 +182,17 @@ 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; 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()); @@ -220,9 +207,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; @@ -232,16 +217,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()); @@ -270,18 +254,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)); @@ -289,18 +269,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)); @@ -308,16 +284,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == ABSOLUTE_VALUE)); } else { @@ -327,16 +300,15 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == BLOCK_VALUE)); } else { @@ -346,16 +318,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == BUILT_IN_FUNCTION_VALUE)); } else { @@ -365,16 +334,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == CONDITION_VALUE)); } else { @@ -384,16 +350,11 @@ 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(); - if (parameterList != NULL) { if (parameterList->kindOfOperand == EXPRESSION_OPND && (expression = parameterList->theOperand. @@ -419,15 +380,11 @@ 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(); - if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { expression = parameterList->theOperand.expressionUnion; @@ -442,16 +399,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == FIELD_VALUE)); } else { @@ -461,16 +415,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == FUNCTION_VALUE)); } else { @@ -480,16 +431,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == RELOCATABLE_VALUE || evaluatedParameter-> kindOfValue == DATA_VALUE)); @@ -500,16 +448,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == STRING_VALUE)); } else { @@ -519,16 +464,13 @@ 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; - valueType *evaluateOperand(); if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->kindOfValue == STRUCT_VALUE)); } else { @@ -538,9 +480,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; @@ -556,9 +496,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) @@ -569,9 +507,7 @@ listingOffBIF(parameterList, kindOfFixup) } valueType * -listingOnBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +listingOnBIF(operandListType *parameterList, fixupKindType kindOfFixup) { if (listingOn) { if (--listingControlCounter < 0) { @@ -590,9 +526,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; @@ -604,7 +538,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 +553,7 @@ makeArrayBIF(parameterList, kindOfFixup) parameterList = parameterList->nextOperand; for (i=0; inextOperand; } else { arrayContents[i] = NULL; @@ -635,20 +568,17 @@ 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; 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 +587,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()); @@ -675,9 +605,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; @@ -685,11 +613,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 +626,7 @@ printfBIF(parameterList, kindOfFixup) argumentCount = 0; while (parameterList != NULL && argumentCount < 20) { argument[argumentCount++] = evaluateOperand( - parameterList)->value; + parameterList)->value; parameterList = parameterList->nextOperand; } /* cretinous hack */ @@ -715,9 +642,7 @@ printfBIF(parameterList, kindOfFixup) /* Concatenate two strings */ valueType * -strcatBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strcatBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string1; @@ -726,7 +651,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 +660,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()); @@ -749,9 +674,7 @@ strcatBIF(parameterList, kindOfFixup) /* Compare two strings */ valueType * -strcmpBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strcmpBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; stringType *string1; @@ -762,7 +685,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 +694,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()); @@ -782,9 +705,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; @@ -795,7 +716,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 +725,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()); @@ -815,15 +736,13 @@ strcmplcBIF(parameterList, kindOfFixup) /* Return the length of a string */ valueType * -strlenBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +strlenBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *stringValue; 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()); @@ -833,9 +752,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; @@ -851,7 +768,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 +781,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 +800,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); @@ -913,22 +830,16 @@ 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(); - if (parameterList == NULL) { 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()); @@ -940,19 +851,16 @@ 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(); if (parameterList == NULL) { 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()); @@ -966,25 +874,21 @@ 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)); } /* 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(); - saveEnvironment = currentEnvironment; while (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { @@ -1014,15 +918,11 @@ 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(); - if (parameterList != NULL && parameterList->kindOfOperand == EXPRESSION_OPND) { expression = parameterList->theOperand.expressionUnion; @@ -1036,16 +936,12 @@ 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; - valueType *evaluateOperand(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeIntegerValue(evaluatedParameter->kindOfValue)); } else { return(makeIntegerValue(-1)); 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/builtInFunsSD_6502.c b/builtInFunsSD_6502.c index f1678e8..0bcb40f 100644 --- a/builtInFunsSD_6502.c +++ b/builtInFunsSD_6502.c @@ -32,28 +32,17 @@ #include "macrossTypes.h" #include "macrossGlobals.h" - -/* Helper functions, defined in builtInFunctions.c */ -valueType *makeBooleanValue(); -valueType *makeFailureValue(); -valueType *makeIntegerValue(); -valueType *makeOperandValue(); -valueType *makeStringValue(); -valueType *makeUndefinedValue(); - +#include "builtInFunctions.h" +#include "operandStuff.h" /* Check if operand is the accumulator */ valueType * -isARegisterBIF(parameterList, kindOfFixup) - operandListType *parameterList; - fixupKindType kindOfFixup; +isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup) { valueType *evaluatedParameter; - valueType *evaluateOperand(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == A_REGISTER_OPND)); } else { @@ -63,16 +52,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == EXPRESSION_OPND)); } else { @@ -82,16 +67,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == IMMEDIATE_OPND)); } else { @@ -101,16 +82,12 @@ 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(); - 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 == @@ -123,16 +100,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == INDIRECT_OPND)); } else { @@ -142,16 +115,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == POST_INDEXED_Y_OPND)); } else { @@ -161,16 +130,12 @@ 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(); - 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)); @@ -181,16 +146,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == X_INDEXED_OPND || evaluatedParameter->addressMode == X_SELECTED_OPND)); @@ -201,16 +162,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == X_REGISTER_OPND)); } else { @@ -220,16 +177,12 @@ 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(); - if (parameterList != NULL) { - evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); + evaluatedParameter = evaluateOperand(parameterList); return(makeBooleanValue(evaluatedParameter->addressMode == Y_INDEXED_OPND || evaluatedParameter->addressMode == Y_SELECTED_OPND)); @@ -240,16 +193,12 @@ 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(); - 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/debugPrint.c b/debugPrint.c index f44ce7e..fcde653 100644 --- a/debugPrint.c +++ b/debugPrint.c @@ -30,6 +30,7 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "debugPrint.h" #include "y.tab.h" /* @@ -42,8 +43,9 @@ int tablevel = 0; #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } /* For keeping nested structures looking pretty */ - void -tab() + +void +tab(void) { int n; @@ -60,8 +62,7 @@ tab() */ void -printAssignmentKind(assignmentKind) - assignmentKindType assignmentKind; +printAssignmentKind(assignmentKindType assignmentKind) { /* This table MUST be maintained congruently with the definition of the enumerated type 'assignmentKindType'. */ @@ -84,8 +85,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'. */ @@ -110,8 +110,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'. */ @@ -159,8 +158,7 @@ static char *statementKindTable[] = { } void -printStatementKind(kind) - statementKindType kind; +printStatementKind(statementKindType kind) { printf("%s", statementKindString(kind)); } @@ -171,8 +169,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'. */ @@ -205,8 +202,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'. */ @@ -241,8 +237,7 @@ printSymbol(symbol) } void -printArgumentDefinitionList(list) - argumentDefinitionListType *list; +printArgumentDefinitionList(argumentDefinitionListType *list) { nullPrint(list); tab(); printf("(arguments:\n"); @@ -256,11 +251,8 @@ printArgumentDefinitionList(list) } void -printBlock(block) - blockType *block; +printBlock(blockType *block) { - void printStatement(); - nullPrint(block); tab(); printf("(block:\n"); tablevel++; @@ -270,12 +262,8 @@ printBlock(block) } void -printArrayTerm(arrayTerm) - arrayTermType *arrayTerm; +printArrayTerm(arrayTermType *arrayTerm) { - void printIdentifier(); - void printExpression(); - nullPrint(arrayTerm); tab(); printf("(array\n"); tablevel++; @@ -286,10 +274,8 @@ printArrayTerm(arrayTerm) } void -printAssignmentTerm(assignmentTerm) - binopTermType *assignmentTerm; +printAssignmentTerm(binopTermType *assignmentTerm) { - void printExpression(); nullPrint(assignmentTerm); tab(); printf("(assignment ["); @@ -303,12 +289,8 @@ printAssignmentTerm(assignmentTerm) } void -printBinopTerm(binopTerm) - binopTermType *binopTerm; +printBinopTerm(binopTermType *binopTerm) { - void printIdentifier(); - void printExpression(); - nullPrint(binopTerm); tab(); printf("(binop ["); printToken(binopTerm->binop); @@ -324,11 +306,8 @@ printBinopTerm(binopTerm) } void -printFunctionCall(functionCall) - functionCallTermType *functionCall; +printFunctionCall(functionCallTermType *functionCall) { - void printOperandList(); - nullPrint(functionCall); tab(); printf("(function call %s\n", functionCall->functionName-> symbolName); @@ -339,29 +318,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 ["); @@ -374,8 +350,7 @@ printPostopTerm(postopTerm) } void -printPreopTerm(preopTerm) - preOpTermType *preopTerm; +printPreopTerm(preOpTermType *preopTerm) { nullPrint(preopTerm); tab(); printf("(preop ["); @@ -388,11 +363,8 @@ printPreopTerm(preopTerm) } void -printUnopTerm(unopTerm) - unopTermType *unopTerm; +printUnopTerm(unopTermType *unopTerm) { - void printExpression(); - nullPrint(unopTerm); tab(); printf("(unop ["); printToken(unopTerm->unop); @@ -404,8 +376,7 @@ printUnopTerm(unopTerm) } void -printExpression(expression) - expressionType *expression; +printExpression(expressionType *expression) { nullPrint(expression); tab(); printf("(expression: ["); @@ -427,7 +398,7 @@ printExpression(expression) break; case CONDITION_CODE_EXPR: - printCondition(expression->expressionTerm); + printCondition(expression->expressionTerm.conditionTypeUnion); break; case FUNCTION_CALL_EXPR: @@ -480,8 +451,7 @@ printExpression(expression) } void -printExpressionList(expressionList) - expressionListType *expressionList; +printExpressionList(expressionListType *expressionList) { while (expressionList != NULL) { printExpression(expressionList->theExpression); @@ -490,8 +460,7 @@ printExpressionList(expressionList) } void -printIdentifierList(identifierList) - identifierListType *identifierList; +printIdentifierList(identifierListType *identifierList) { nullPrint(identifierList); printSymbol(identifierList->theSymbol); @@ -505,8 +474,7 @@ printIdentifierList(identifierList) */ void -printCase(aCase) - caseType *aCase; +printCase(caseType *aCase) { tab(); printf("(case:\n"); tablevel++; if (aCase->caseTags == NULL) { @@ -523,8 +491,7 @@ printCase(aCase) } void -printCaseList(caseList) - caseListType *caseList; +printCaseList(caseListType *caseList) { tab(); printf("(cases:\n"); tablevel++; @@ -537,24 +504,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); @@ -563,16 +527,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); @@ -580,24 +542,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); @@ -605,16 +564,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); @@ -622,8 +579,7 @@ printDefineStatement(defineStatement) } void -printDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +printDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { nullPrint(doUntilStatement); printBlock(doUntilStatement->doUntilLoop); @@ -633,8 +589,7 @@ printDoUntilStatement(doUntilStatement) } void -printDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +printDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { nullPrint(doWhileStatement); printBlock(doWhileStatement->doWhileLoop); @@ -644,24 +599,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); @@ -670,8 +622,7 @@ printFunctionStatement(functionStatement) } void -printIfStatement(ifStatement) - ifStatementBodyType *ifStatement; +printIfStatement(ifStatementBodyType *ifStatement) { nullPrint(ifStatement); tab(); printf("(condition: "); @@ -686,16 +637,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) { @@ -716,16 +665,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); @@ -734,8 +681,7 @@ printMacroStatement(macroStatement) } void -printMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +printMdefineStatement(defineStatementBodyType *mdefineStatement) { nullPrint(mdefineStatement); printSymbol(mdefineStatement->theSymbol); @@ -743,8 +689,7 @@ printMdefineStatement(mdefineStatement) } void -printMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +printMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { nullPrint(mdoUntilStatement); printBlock(mdoUntilStatement->mdoUntilLoop); @@ -752,8 +697,7 @@ printMdoUntilStatement(mdoUntilStatement) } void -printMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +printMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { nullPrint(mdoWhileStatement); printBlock(mdoWhileStatement->mdoWhileLoop); @@ -761,8 +705,7 @@ printMdoWhileStatement(mdoWhileStatement) } void -printMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +printMforStatement(mforStatementBodyType *mforStatement) { nullPrint(mforStatement); printExpression(mforStatement->initExpression); @@ -772,8 +715,7 @@ printMforStatement(mforStatement) } void -printMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +printMifStatement(mifStatementBodyType *mifStatement) { nullPrint(mifStatement); printExpression(mifStatement->mifCondition); @@ -786,8 +728,7 @@ printMifStatement(mifStatement) } void -printMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +printMswitchStatement(mswitchStatementBodyType *mswitchStatement) { nullPrint(mswitchStatement); printExpression(mswitchStatement->switchExpression); @@ -795,8 +736,7 @@ printMswitchStatement(mswitchStatement) } void -printMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +printMvariableStatement(mvariableStatementBodyType *mvariableStatement) { nullPrint(mvariableStatement); printSymbol(mvariableStatement->theSymbol); @@ -804,8 +744,7 @@ printMvariableStatement(mvariableStatement) } void -printMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +printMwhileStatement(mwhileStatementBodyType *mwhileStatement) { nullPrint(mwhileStatement); printExpression(mwhileStatement->mwhileCondition); @@ -813,47 +752,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); @@ -861,24 +794,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); @@ -886,8 +816,7 @@ printVariableStatement(variableStatement) } void -printWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +printWhileStatement(whileStatementBodyType *whileStatement) { nullPrint(whileStatement); tab(); printf("(condition: "); @@ -897,16 +826,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"); @@ -920,9 +847,7 @@ printLabelList(labelList) } void -printStatementBody(kind, body) - statementKindType kind; - statementBodyType body; +printStatementBody(statementKindType kind, statementBodyType body) { switch (kind) { @@ -1085,8 +1010,7 @@ printStatementBody(kind, body) } void -printStatement(statement) - statementType *statement; +printStatement(statementType *statement) { nullPrint(statement); tab(); printf("(statement["); @@ -1107,8 +1031,7 @@ printStatement(statement) */ void -printPendingFixupList(fixupList) - fixupListType *fixupList; +printPendingFixupList(fixupListType *fixupList) { printf("fixup list: ("); tablevel++; @@ -1121,10 +1044,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", @@ -1148,7 +1068,7 @@ printCreateFixup(expression, location, kindOfFixup) */ void -printExpressionBuffer() +printExpressionBuffer(void) { int line; int i; @@ -1163,9 +1083,7 @@ printExpressionBuffer() } void -printOneCodeBuffer(codeSegment, bufferNum) - codeSegmentType *codeSegment; - int bufferNum; +printOneCodeBuffer(codeSegmentType *codeSegment, int bufferNum) { int line; int i; @@ -1193,8 +1111,7 @@ printOneCodeBuffer(codeSegment, bufferNum) } void -printCodeBufferSection(codeBufferSection) - codeRegionType *codeBufferSection; +printCodeBufferSection(codeRegionType *codeBufferSection) { bool anyCodeThereFlag; int i; @@ -1212,7 +1129,7 @@ printCodeBufferSection(codeBufferSection) } void -printCodeBuffers() +printCodeBuffers(void) { printf("absolute code:\n"); printCodeBufferSection(&absoluteCodeRegion); 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/debugPrintSD_6502.c b/debugPrintSD_6502.c index c4da64d..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,9 +40,8 @@ int tablevel; /* Fundamental nop print operation */ #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } - void -printCondition(condition) - conditionType condition; +void +printCondition(conditionType condition) { /* This table MUST be maintained congruently with the definition of the enumerated type 'conditionType'. */ @@ -70,8 +70,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 +96,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 +191,7 @@ printToken(token) } void -printOperand(operand) - operandType *operand; +printOperand(operandType *operand) { nullPrint(operand); tab(); printf("(operand: ["); @@ -204,15 +201,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 +222,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/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.h b/emitBranch.h new file mode 100644 index 0000000..b85896d --- /dev/null +++ b/emitBranch.h @@ -0,0 +1,9 @@ +#ifndef EMIT_BRANCH_H_ +#define EMIT_BRANCH_H_ + +#include "macrossTypes.h" + +void emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation); +simpleFixupListType *emitJump(valueType *target, simpleFixupListType *previousFixups); + +#endif diff --git a/emitBranch_6502.c b/emitBranch_6502.c index 1cf71e6..e4b30e3 100644 --- a/emitBranch_6502.c +++ b/emitBranch_6502.c @@ -32,16 +32,17 @@ #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. */ - void -emitRelativeBranch(condition, target, fixupLocation) - conditionType condition; - valueType *target; - valueType fixupLocation[COMPOUND_BRANCH_MAX]; +void +emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation) { int i; @@ -139,15 +140,11 @@ 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(); - #define JUMP_OPCODE 0x4C result = previousFixups; diff --git a/emitStuff.c b/emitStuff.c index 31472b6..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,10 +66,8 @@ /* incarnateCodeBuffer causes code buffer space to actually be allocated */ - void -incarnateCodeBuffer(bufferNum, bufferKind) - int bufferNum; - codeBufferKindType bufferKind; +void +incarnateCodeBuffer(int bufferNum, codeBufferKindType bufferKind) { codeSegmentType *newCodeSegment; codeBufferType *newCodeBuffer; @@ -88,9 +90,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 +131,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 +142,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 +162,7 @@ emitByte(byteValue) /* emitWord similarly emits a word */ void -emitWord(wordValue) - wordType wordValue; +emitWord(wordType wordValue) { byteToWordType convert; int loByte, hiByte; @@ -216,8 +212,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 +281,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 +307,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) @@ -329,7 +322,7 @@ emitString(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++; @@ -342,8 +335,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 +361,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 +387,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 +397,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 +407,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 +418,7 @@ pokeLongValue(location, value) relative branches */ void -pokeRelativeByteValue(location, value) - addressType location; - valueType *value; +pokeRelativeByteValue(addressType location, valueType *value) { int offset; @@ -456,9 +439,7 @@ pokeRelativeByteValue(location, value) relative branches */ void -pokeRelativeWordValue(location, value) - addressType location; - valueType *value; +pokeRelativeWordValue(addressType location, valueType *value) { int offset; @@ -475,8 +456,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 +474,7 @@ getByte(address) } void -emitRelativeByteOffset(target) - valueType *target; +emitRelativeByteOffset(valueType *target) { int saveTargetOffset; @@ -512,8 +491,7 @@ emitRelativeByteOffset(target) } void -emitRelativeWordOffset(target) - valueType *target; +emitRelativeWordOffset(valueType *target) { int saveTargetOffset; @@ -531,9 +509,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 +530,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/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.c b/encode.c index e57a792..d892d19 100644 --- a/encode.c +++ b/encode.c @@ -31,6 +31,11 @@ #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" #define nullEncode(thing) if (thing==NULL) return(TRUE); @@ -38,9 +43,8 @@ bool encodingFunction; - bool -encodeByte(aByte) - byte aByte; +bool +encodeByte(byte aByte) { if (expressionBufferSize < EXPRESSION_BUFFER_LIMIT) { expressionBuffer[expressionBufferSize++] = aByte; @@ -52,8 +56,7 @@ encodeByte(aByte) } bool -encodeBigword(bigword) - int bigword; +encodeBigword(int bigword) { int i; for (i=0; ibinop != ASSIGN_ASSIGN) { @@ -82,11 +84,8 @@ encodeAssignmentTerm(assignmentTerm) } bool -encodeBinopTerm(binopTerm) - binopTermType *binopTerm; +encodeBinopTerm(binopTermType *binopTerm) { - bool encodeExpression(); - nullEncode(binopTerm); return ( encodeByte(BINOP_TAG) && @@ -97,8 +96,7 @@ encodeBinopTerm(binopTerm) } bool -encodeCondition(condition) - conditionType condition; +encodeCondition(conditionType condition) { return( encodeByte(CONDITION_CODE_TAG) && @@ -107,8 +105,7 @@ encodeCondition(condition) } int -functionNumber(function) - functionDefinitionType *function; +functionNumber(functionDefinitionType *function) { if (function->ordinal == -1) { function->ordinal = externalFunctionCount++; @@ -125,16 +122,13 @@ functionNumber(function) } bool -encodeFunctionCall(functionCall) - functionCallTermType *functionCall; +encodeFunctionCall(functionCallTermType *functionCall) { functionDefinitionType *theFunction; int functionOrdinal; symbolInContextType *workingContext; operandListType *parameterList; - symbolInContextType *getWorkingContext(); - nullEncode(functionCall); workingContext = getWorkingContext(functionCall->functionName); if (isFunction(workingContext)) { @@ -178,14 +172,13 @@ encodeFunctionCall(functionCall) } bool -encodeHere() +encodeHere(void) { return(encodeByte(HERE_TAG)); } bool -encodeIdentifier(identifier) - symbolTableEntryType *identifier; +encodeIdentifier(symbolTableEntryType *identifier) { symbolInContextType *workingContext; environmentType *saveEnvironment; @@ -249,8 +242,7 @@ encodeIdentifier(identifier) } bool -encodeNumber(number) - numberTermType number; +encodeNumber(numberTermType number) { return( encodeByte(NUMBER_TAG) && @@ -259,8 +251,7 @@ encodeNumber(number) } bool -encodeRelocatableNumber(number) - numberTermType number; +encodeRelocatableNumber(numberTermType number) { return( encodeByte(RELOCATABLE_TAG) && @@ -269,8 +260,7 @@ encodeRelocatableNumber(number) } bool -encodeOperand(operand) - operandType *operand; +encodeOperand(operandType *operand) { switch (operand->kindOfOperand) { case EXPRESSION_OPND: @@ -280,7 +270,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: @@ -295,7 +285,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); @@ -304,8 +294,7 @@ encodeOperand(operand) } bool -encodePostopTerm(postopTerm) - postOpTermType *postopTerm; +encodePostopTerm(postOpTermType *postopTerm) { nullEncode(postopTerm); return( @@ -316,8 +305,7 @@ encodePostopTerm(postopTerm) } bool -encodePreopTerm(preopTerm) - preOpTermType *preopTerm; +encodePreopTerm(preOpTermType *preopTerm) { nullEncode(preopTerm); return( @@ -328,8 +316,7 @@ encodePreopTerm(preopTerm) } bool -encodeString(string) - stringType *string; +encodeString(stringType *string) { if (!encodeByte(STRING_TAG)) return(FALSE); @@ -341,8 +328,7 @@ encodeString(string) } bool -encodeUnopTerm(unopTerm) - unopTermType *unopTerm; +encodeUnopTerm(unopTermType *unopTerm) { nullEncode(unopTerm); return( @@ -353,8 +339,7 @@ encodeUnopTerm(unopTerm) } bool -encodeValue(value) - valueType *value; +encodeValue(valueType *value) { switch (value->kindOfValue) { case ABSOLUTE_VALUE: @@ -390,8 +375,7 @@ encodeValue(value) } bool -encodeExpression(expression) - expressionType *expression; +encodeExpression(expressionType *expression) { nullEncode(expression); switch (expression->kindOfTerm) { @@ -461,8 +445,7 @@ encodeExpression(expression) } bool -encodeAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +encodeAssertStatement(assertStatementBodyType *assertStatement) { return( encodeByte(ASSERT_TAG) && @@ -472,8 +455,7 @@ encodeAssertStatement(assertStatement) } bool -encodeFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +encodeFreturnStatement(freturnStatementBodyType *freturnStatement) { return( encodeByte(FRETURN_TAG) && @@ -482,8 +464,7 @@ encodeFreturnStatement(freturnStatement) } bool -encodeMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +encodeMdefineStatement(defineStatementBodyType *mdefineStatement) { return( encodeByte(MDEFINE_TAG) && @@ -493,8 +474,7 @@ encodeMdefineStatement(mdefineStatement) } bool -encodeMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { return( encodeByte(MDOUNTIL_TAG) && @@ -504,8 +484,7 @@ encodeMdoUntilStatement(mdoUntilStatement) } bool -encodeMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +encodeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { return( encodeByte(MDOWHILE_TAG) && @@ -515,8 +494,7 @@ encodeMdoWhileStatement(mdoWhileStatement) } bool -encodeMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +encodeMforStatement(mforStatementBodyType *mforStatement) { return( encodeByte(MFOR_TAG) && @@ -528,20 +506,18 @@ encodeMforStatement(mforStatement) } bool -encodeMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +encodeMifStatement(mifStatementBodyType *mifStatement) { return( encodeByte(MIF_TAG) && encodeExpression(mifStatement->mifCondition) && encodeBlock(mifStatement->mifConsequence) && - encodeBlock(mifStatement->mifContinuation) + encodeBlock(mifStatement->mifContinuation.mifBlockUnion) ); } bool -encodeMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +encodeMswitchStatement(mswitchStatementBodyType *mswitchStatement) { caseListType *caseList; caseType *theCase; @@ -565,8 +541,7 @@ encodeMswitchStatement(mswitchStatement) } bool -encodeMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +encodeMvariableStatement(mvariableStatementBodyType *mvariableStatement) { int length; @@ -586,8 +561,7 @@ encodeMvariableStatement(mvariableStatement) } bool -encodeMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement) { return( encodeByte(MWHILE_TAG) && @@ -597,8 +571,7 @@ encodeMwhileStatement(mwhileStatement) } bool -encodeStatement(statement) - statementType *statement; +encodeStatement(statementType *statement) { switch(statement->kindOfStatement) { @@ -638,7 +611,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)); @@ -678,8 +651,7 @@ encodeStatement(statement) } bool -encodeBlock(block) - blockType *block; +encodeBlock(blockType *block) { if (!encodeByte(BLOCK_TAG)) return(FALSE); 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.c b/errorStuff.c index a855027..371f917 100644 --- a/errorStuff.c +++ b/errorStuff.c @@ -29,6 +29,10 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "errorStuff.h" +#include "initialize.h" + +#include bool nullStatementFlag; @@ -38,34 +42,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 +230,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 +241,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(); } @@ -290,8 +291,7 @@ fatalSystemError(theError, arg1, arg2, arg3) 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); @@ -305,8 +305,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'. */ @@ -337,8 +336,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'. */ @@ -367,8 +365,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/errorStuff.h b/errorStuff.h new file mode 100644 index 0000000..5b94cbe --- /dev/null +++ b/errorStuff.h @@ -0,0 +1,20 @@ +#ifndef ERROR_STUFF_H_ +#define ERROR_STUFF_H_ + +#include "macrossTypes.h" + +#include + +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.c b/expressionSemantics.c index 7f4bef1..17db853 100644 --- a/expressionSemantics.c +++ b/expressionSemantics.c @@ -31,6 +31,19 @@ #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 operandType *dbOperand; /* safe temps for dbx hacking */ expressionType *dbExpression; @@ -60,10 +73,8 @@ 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; +anyOldThing * +arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing) { valueType *arrayValue; valueType *indexValue; @@ -71,8 +82,6 @@ arrayLookup(arrayTerm, kindOfThing) int index; stringType *string; - valueType *evaluateExpression(); - *kindOfThing = FAIL; arrayValue = evaluateExpression(arrayTerm->arrayName, NO_FIXUP); if (arrayValue->kindOfValue == FAIL) @@ -122,8 +131,7 @@ arrayLookup(arrayTerm, kindOfThing) } valueType * -evaluateArrayTerm(arrayTerm) - arrayTermType *arrayTerm; +evaluateArrayTerm(arrayTermType *arrayTerm) { anyOldThing *resultThing; valueKindType kindOfResult; @@ -133,9 +141,6 @@ evaluateArrayTerm(arrayTerm) environmentType *saveEnvironment; bool saveExpansion; - valueType *newValue(); - valueType *evaluateOperand(); - expansionOff(); resultThing = arrayLookup(arrayTerm, &kindOfResult); expansionOn(); @@ -170,9 +175,7 @@ evaluateArrayTerm(arrayTerm) } valueType * -evaluateAssignmentTerm(assignmentTerm, kindOfFixup) - binopTermType *assignmentTerm; - fixupKindType kindOfFixup; +evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup) { symbolTableEntryType *targetSymbol; valueType *target; @@ -187,15 +190,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; @@ -373,10 +367,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; @@ -386,11 +377,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; @@ -595,20 +581,14 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) } valueType * -evaluateCondition(condition) - conditionType condition; +evaluateCondition(conditionType condition) { - valueType *newValue(); - 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]. @@ -616,10 +596,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; @@ -633,10 +610,6 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) valueType *result; bool saveExpansion; - symbolInContextType *getWorkingContext(); - valueType *evaluateBuiltInFunctionCall(); - valueType *newValue(); - nullEvaluate(functionCall); sideEffectFlag = TRUE; pushEnvironment(newEnvironment); @@ -703,9 +676,8 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) } valueType * -evaluateHere() +evaluateHere(void) { - valueType *newValue(); valueType *result; expand(moreExpression("here")); @@ -716,10 +688,7 @@ evaluateHere() } valueType * -evaluateIdentifier(identifier, isTopLevel, kindOfFixup) - symbolTableEntryType *identifier; - bool isTopLevel; - fixupKindType kindOfFixup; +evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup) { symbolInContextType *workingContext; valueType *resultValue; @@ -727,11 +696,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] == '$') @@ -848,18 +812,14 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup) } valueType * -evaluateNumber(number) - numberTermType number; +evaluateNumber(numberTermType number) { - valueType *newValue(); - expand(moreExpression("0x%x", number)); return(newValue(ABSOLUTE_VALUE, number, EXPRESSION_OPND)); } valueType * -evaluatePostopTerm(postopTerm) - postOpTermType *postopTerm; +evaluatePostopTerm(postOpTermType *postopTerm) { valueType *theOperand; valueType **theOperandPtr; @@ -868,9 +828,6 @@ evaluatePostopTerm(postopTerm) symbolInContextType *workingContext; symbolTableEntryType *targetSymbol; - symbolTableEntryType *effectiveSymbol(); - symbolInContextType *getWorkingContext(); - nullEvaluate(postopTerm); sideEffectFlag = TRUE; if (postopTerm->postOpArgument->kindOfTerm == IDENTIFIER_EXPR) { @@ -929,8 +886,7 @@ evaluatePostopTerm(postopTerm) } valueType * -evaluatePreopTerm(preopTerm) - preOpTermType *preopTerm; +evaluatePreopTerm(preOpTermType *preopTerm) { valueType *theOperand; valueType *result; @@ -939,9 +895,6 @@ evaluatePreopTerm(preopTerm) symbolInContextType *workingContext; symbolTableEntryType *targetSymbol; - symbolTableEntryType *effectiveSymbol(); - symbolInContextType *getWorkingContext(); - nullEvaluate(preopTerm); sideEffectFlag = TRUE; if (preopTerm->preOpArgument->kindOfTerm == IDENTIFIER_EXPR) { @@ -1000,10 +953,8 @@ evaluatePreopTerm(preopTerm) } valueType * -evaluateString(string) - stringType *string; +evaluateString(stringType *string) { - valueType *newValue(); stringType *newString; expand(moreExpression("\"%s\"", string)); @@ -1013,9 +964,7 @@ evaluateString(string) } valueType * -evaluateUnopTerm(unopTerm, kindOfFixup) - unopTermType *unopTerm; - fixupKindType kindOfFixup; +evaluateUnopTerm(unopTermType *unopTerm, fixupKindType kindOfFixup) { valueType *theOperand; valueKindType resultKindOfValue; @@ -1023,11 +972,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, @@ -1072,11 +1016,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; @@ -1166,9 +1106,7 @@ evaluateExpressionInternally(expression, isTopLevel, kindOfFixup,isStandalone) } valueType * -evaluateExpression(expression, kindOfFixup) - expressionType *expression; - fixupKindType kindOfFixup; +evaluateExpression(expressionType *expression, fixupKindType kindOfFixup) { valueType *result; @@ -1189,8 +1127,7 @@ evaluateExpression(expression, kindOfFixup) } void -evaluateExpressionStandalone(expression) - expressionType *expression; +evaluateExpressionStandalone(expressionType *expression) { bool saveExpansion; valueType *expressionResult; @@ -1210,24 +1147,17 @@ evaluateExpressionStandalone(expression) } valueType * -evaluateDefineExpression(expression) - expressionType *expression; +evaluateDefineExpression(expressionType *expression) { - valueType *newValue(); - expressionType *generateFixupExpression(); - operandType *buildOperand(); - nullEvaluate(expression); return(newValue(OPERAND_VALUE, buildOperand(EXPRESSION_OPND, generateFixupExpression(expression)), EXPRESSION_OPND)); } valueType * -evaluateSelectionList(selectionList) - selectionListType *selectionList; +evaluateSelectionList(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..2137d13 --- /dev/null +++ b/expressionSemantics.h @@ -0,0 +1,26 @@ +#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 *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); +valueType *evaluateHere(void); +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/fixups.c b/fixups.c index 4ea7138..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,12 +65,10 @@ stringType *dbString = "graphics2.m"; The routines below collectively duplicate expressions for later evaluation. */ - expressionType * -generateFixupExpression(expression) - expressionType *expression; +expressionType * +generateFixupExpression(expressionType *expression) { expressionType *result; - expressionType *duplicateExpressionForFixup(); generatingFixup = TRUE; result = duplicateExpressionForFixup(expression, TRUE, FALSE); @@ -71,10 +77,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,16 +88,6 @@ 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(); - nullDup(expression); result = originalResult = typeAlloc(expressionType); *result = *expression; @@ -280,15 +273,12 @@ duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand) } functionCallTermType * -duplicateFunctionCall(functionCall) - functionCallTermType *functionCall; +duplicateFunctionCall(functionCallTermType *functionCall) { functionCallTermType *result; operandListType **argument; operandListType *parameterList; - operandListType *duplicateOperandForFixup(); - result = typeAlloc(functionCallTermType); result->functionName = functionCall->functionName; expand(moreExpression("%s(", symbName(functionCall->functionName))); @@ -310,8 +300,7 @@ duplicateFunctionCall(functionCall) expressionType * -duplicateArrayReference(arrayTerm) - arrayTermType *arrayTerm; +duplicateArrayReference(arrayTermType *arrayTerm) { anyOldThing *resultThing; valueKindType kindOfResult; @@ -322,10 +311,6 @@ duplicateArrayReference(arrayTerm) bool saveExpansion; operandType *newOperand; - valueType *newValue(); - operandType *duplicateOperandForFixup(); - anyOldThing *arrayLookup(); - expansionOff(); resultThing = arrayLookup(arrayTerm, &kindOfResult); expansionOn(); 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.c b/garbage.c index 74f0654..bf0866d 100644 --- a/garbage.c +++ b/garbage.c @@ -29,16 +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; - void -freeArrayTerm(arrayTerm) - arrayTermType *arrayTerm; +void +freeArrayTerm(arrayTermType *arrayTerm) { - void freeExpression(); - nullFree(arrayTerm); freeExpression(arrayTerm->arrayName); freeExpression(arrayTerm->arrayIndex); @@ -46,22 +46,16 @@ freeArrayTerm(arrayTerm) } void -freeAssignmentTerm(assignmentTerm) - binopTermType *assignmentTerm; +freeAssignmentTerm(binopTermType *assignmentTerm) { - void freeExpression(); - nullFree(assignmentTerm); freeExpression(assignmentTerm->rightArgument); free(assignmentTerm); } void -freeBinopTerm(binopTerm) - binopTermType *binopTerm; +freeBinopTerm(binopTermType *binopTerm) { - void freeExpression(); - nullFree(binopTerm); freeExpression(binopTerm->leftArgument); if (binopTerm->binop != SELECT) @@ -70,54 +64,44 @@ freeBinopTerm(binopTerm) } void -freeFunctionCall(functionCall) - functionCallTermType *functionCall; +freeFunctionCall(functionCallTermType *functionCall) { - void freeOperandList(); - nullFree(functionCall); freeOperandList(functionCall->parameters); free(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(); - nullFree(unopTerm); freeExpression(unopTerm->unopArgument); free(unopTerm); } void -freeExpression(expression) - expressionType *expression; +freeExpression(expressionType *expression) { nullFree(expression); switch (expression->kindOfTerm) { @@ -171,8 +155,7 @@ freeExpression(expression) } void -freeExpressionList(expressionList) - expressionListType *expressionList; +freeExpressionList(expressionListType *expressionList) { expressionListType *newExpressionList; @@ -185,8 +168,7 @@ freeExpressionList(expressionList) } void -freeIdentifierList(identifierList) - identifierListType *identifierList; +freeIdentifierList(identifierListType *identifierList) { identifierListType *newIdentifierList; @@ -198,25 +180,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 +203,7 @@ freeCase(aCase) } void -freeCaseList(caseList) - caseListType *caseList; +freeCaseList(caseListType *caseList) { caseListType *newCaseList; @@ -238,37 +216,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 +250,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 +271,7 @@ freeByteStatement(byteStatement) } void -freeConstrainStatement(constrainStatement) - constrainStatementBodyType *constrainStatement; +freeConstrainStatement(constrainStatementBodyType *constrainStatement) { nullFree(constrainStatement); freeExpression(constrainStatement->constraint); @@ -310,8 +280,7 @@ freeConstrainStatement(constrainStatement) } void -freeDbyteStatement(dbyteStatement) - dbyteStatementBodyType *dbyteStatement; +freeDbyteStatement(dbyteStatementBodyType *dbyteStatement) { dbyteStatementBodyType *newDbyteStatement; @@ -325,8 +294,7 @@ freeDbyteStatement(dbyteStatement) } void -freeDefineStatement(defineStatement) - defineStatementBodyType *defineStatement; +freeDefineStatement(defineStatementBodyType *defineStatement) { nullFree(defineStatement); freeExpression(defineStatement->theValue); @@ -334,8 +302,7 @@ freeDefineStatement(defineStatement) } void -freeDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +freeDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { nullFree(doUntilStatement); freeBlock(doUntilStatement->doUntilLoop); @@ -343,8 +310,7 @@ freeDoUntilStatement(doUntilStatement) } void -freeDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +freeDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { nullFree(doWhileStatement); freeBlock(doWhileStatement->doWhileLoop); @@ -352,23 +318,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 +339,7 @@ freeFunctionStatement(functionStatement) } void -freeIfStatement(ifStatement) - ifStatementBodyType *ifStatement; +freeIfStatement(ifStatementBodyType *ifStatement) { nullFree(ifStatement); if (ifStatement->consequence != NULL) @@ -389,16 +351,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 +379,7 @@ freeInstructionStatement(instructionStatement) } void -freeLongStatement(longStatement) - longStatementBodyType *longStatement; +freeLongStatement(longStatementBodyType *longStatement) { longStatementBodyType *newLongStatement; @@ -434,16 +393,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 +411,7 @@ freeMdefineStatement(mdefineStatement) } void -freeMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +freeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { nullFree(mdoUntilStatement); freeBlock(mdoUntilStatement->mdoUntilLoop); @@ -462,8 +419,7 @@ freeMdoUntilStatement(mdoUntilStatement) } void -freeMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +freeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { nullFree(mdoWhileStatement); freeBlock(mdoWhileStatement->mdoWhileLoop); @@ -472,8 +428,7 @@ freeMdoWhileStatement(mdoWhileStatement) } void -freeMifStatement(mifStatement) - mifStatementBodyType *mifStatement; +freeMifStatement(mifStatementBodyType *mifStatement) { nullFree(mifStatement); freeExpression(mifStatement->mifCondition); @@ -484,8 +439,7 @@ freeMifStatement(mifStatement) } void -freeMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +freeMswitchStatement(mswitchStatementBodyType *mswitchStatement) { freeExpression(mswitchStatement->switchExpression); freeCaseList(mswitchStatement->cases); @@ -493,8 +447,7 @@ freeMswitchStatement(mswitchStatement) } void -freeMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +freeMforStatement(mforStatementBodyType *mforStatement) { nullFree(mforStatement); freeExpression(mforStatement->initExpression); @@ -505,8 +458,7 @@ freeMforStatement(mforStatement) } void -freeMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +freeMvariableStatement(mvariableStatementBodyType *mvariableStatement) { nullFree(mvariableStatement); if ((int)mvariableStatement->theDimension != -1) @@ -516,8 +468,7 @@ freeMvariableStatement(mvariableStatement) } void -freeMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +freeMwhileStatement(mwhileStatementBodyType *mwhileStatement) { nullFree(mwhileStatement); freeExpression(mwhileStatement->mwhileCondition); @@ -526,38 +477,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 +517,7 @@ freeStringStatement(stringStatement) } void -freeStructStatement(structStatement) - structStatementBodyType *structStatement; +freeStructStatement(structStatementBodyType *structStatement) { nullFree(structStatement); freeBlock(structStatement->structBody); @@ -580,23 +525,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 +548,7 @@ freeVariableStatement(variableStatement) } void -freeWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +freeWhileStatement(whileStatementBodyType *whileStatement) { nullFree(whileStatement); freeBlock(whileStatement->whileLoop); @@ -615,8 +556,7 @@ freeWhileStatement(whileStatement) } void -freeWordStatement(wordStatement) - wordStatementBodyType *wordStatement; +freeWordStatement(wordStatementBodyType *wordStatement) { wordStatementBodyType *newWordStatement; @@ -630,9 +570,7 @@ freeWordStatement(wordStatement) } void -freeStatementBody(kind, body) - statementKindType kind; - statementBodyType body; +freeStatementBody(statementKindType kind, statementBodyType body) { switch (kind) { @@ -795,8 +733,7 @@ freeStatementBody(kind, body) } void -freeLabelList(labelList) - labelListType *labelList; +freeLabelList(labelListType *labelList) { labelListType *nextLabel; @@ -808,8 +745,7 @@ freeLabelList(labelList) } void -freeStatement(statement) - statementType *statement; +freeStatement(statementType *statement) { statementType *newStatement; @@ -824,11 +760,9 @@ freeStatement(statement) } void -freeArray(array) - arrayType *array; +freeArray(arrayType *array) { int i; - void freeValue(); if (array->arraySize > 0) { for (i=0; iarraySize; i++) @@ -839,8 +773,7 @@ freeArray(array) } void -freeValue(value) - valueType *value; +freeValue(valueType *value) { if (value->kindOfValue == STRING_VALUE) freeString(value->value); 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/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/initialize.c b/initialize.c index 3a4aa98..d02e3e9 100644 --- a/initialize.c +++ b/initialize.c @@ -29,6 +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]) @@ -38,16 +46,14 @@ static fileNameListType *bottomOfInputFileStack; 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; @@ -60,14 +66,6 @@ initializeStuff(argc, argv) char *symbolDumpFileName; bool dontUnlinkTempFiles; - void createHashTables(); - void installBuiltInFunctions(); - void installPredefinedSymbols(); - void installCommandLineDefineSymbols(); - void openFirstInputFile(); - void queueInputFile(); - void noteCommandLineDefine(); - for (i=0; i<128; i++) { lowerCaseCharacterTable[i] = i; alphabeticCharacterTable[i] = FALSE; @@ -339,7 +337,7 @@ initializeStuff(argc, 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); @@ -348,7 +346,7 @@ initializeStuff(argc, 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); @@ -358,7 +356,7 @@ initializeStuff(argc, argv) program exit */ if (expandMacros) { - if ((macroFileForPass2 = fopen(mktemp( + if ((macroFileForPass2 = fopen(mkstemp( pass2MacroExpansionFileName),"w+")) == NULL) { fatalSystemError( UNABLE_TO_OPEN_PASS_2_FILE_ERROR, @@ -379,14 +377,11 @@ initializeStuff(argc, argv) } void -installBuiltInFunctions() +installBuiltInFunctions(void) { int i; symbolTableEntryType *newFunction; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); - for (i=0; builtInFunctionTable[i].functionName!=NULL; i++) { newFunction = lookupOrEnterSymbol(builtInFunctionTable[i]. functionName, BUILT_IN_FUNCTION_SYMBOL); @@ -399,14 +394,11 @@ installBuiltInFunctions() } void -installPredefinedSymbols() +installPredefinedSymbols(void) { int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); - for (i=0; predefinedSymbolTable[i].symbolName!=NULL; i++) { newSymbol = lookupOrEnterSymbol(predefinedSymbolTable[i]. symbolName, DEFINE_SYMBOL); @@ -418,14 +410,11 @@ installPredefinedSymbols() } void -installCommandLineDefineSymbols() +installCommandLineDefineSymbols(void) { int i; symbolTableEntryType *newSymbol; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); - while (commandLineDefines != NULL) { newSymbol = lookupOrEnterSymbol(commandLineDefines->name, DEFINE_SYMBOL); @@ -437,7 +426,7 @@ installCommandLineDefineSymbols() } void -createHashTables() +createHashTables(void) { opcodeTableEntryType *newOpcodeEntry; keywordTableEntryType *newKeywordEntry; @@ -457,8 +446,7 @@ createHashTables() } void -queueInputFile(name) - char *name; +queueInputFile(char *name) { fileNameListType *newFileName; @@ -477,7 +465,7 @@ queueInputFile(name) } void -openFirstInputFile() +openFirstInputFile(void) { if (inputFileStack == NULL) { inputFileStack = typeAlloc(fileNameListType); @@ -502,8 +490,7 @@ openFirstInputFile() } bool -isDotMName(fileName) - stringType *fileName; +isDotMName(stringType *fileName) { int length; @@ -513,10 +500,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; @@ -559,15 +543,12 @@ parseCommandLineDefine(arg, name, value) } void -noteCommandLineDefine(arg) - char *arg; +noteCommandLineDefine(char *arg) { char *name; int value; commandLineDefineType *newCommandLineDefine; - bool parseCommandLineDefine(); - if (parseCommandLineDefine(arg, &name, &value)) { newCommandLineDefine = typeAlloc(commandLineDefineType); newCommandLineDefine->name = name; 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.c b/lexer.c index 5fd7807..9092678 100644 --- a/lexer.c +++ b/lexer.c @@ -30,7 +30,13 @@ #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; extern int yydebug; @@ -51,8 +57,8 @@ static int lineBufferPtr = 0; #define isNumeric(c) (numericCharacterTable[c]) #define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) - int -yylex() +int +yylex(void) { int result; @@ -66,12 +72,10 @@ yylex() } int -lexer() +lexer(void) { char c; - char skipWhitespaceAndComments(); - if ((c = skipWhitespaceAndComments()) == EOF) return(lexLiteral(c)); else @@ -79,15 +83,9 @@ lexer() } void -initializeLexDispatchTable() +initializeLexDispatchTable(void) { int c; - int lexIdentifier(); - int lexNumber(); - int lexLiteral(); - int lexCharacterConstant(); - int lexStringConstant(); - int lexOperator(); for (c = 0; c < LEX_DISPATCH_TABLE_SIZE; c++) { if (isAlphabetic(c) || c=='$') @@ -106,8 +104,7 @@ initializeLexDispatchTable() } bool -isMacrossLiteralCharacter(c) - char c; +isMacrossLiteralCharacter(char c) { return(c==':' || c==',' || c=='@' || c=='#' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || @@ -115,9 +112,7 @@ isMacrossLiteralCharacter(c) } void -snarfAlphanumericString(c, buffer) - char c; - char *buffer; +snarfAlphanumericString(char c, char *buffer) { char *bufferPtr; @@ -134,10 +129,8 @@ snarfAlphanumericString(c, buffer) char nameBuffer[MAX_NAME_SIZE+1]; int -lexIdentifier(c) - char c; +lexIdentifier(char c) { - char *saveString(); int hashValue; snarfAlphanumericString(c, nameBuffer); @@ -160,8 +153,7 @@ lexIdentifier(c) char numberBuffer[MAX_NAME_SIZE+1]; int -lexNumber(c) - char c; +lexNumber(char c) { int base; int start; @@ -188,9 +180,7 @@ lexNumber(c) } int -fancyAtoI(buffer, base) - char *buffer; - int base; +fancyAtoI(char *buffer, int base) { int value; int digit; @@ -208,8 +198,7 @@ fancyAtoI(buffer, base) } int -digitValue(c) - char c; +digitValue(char c) { if (isNumeric(c)) return(c - '0'); @@ -218,8 +207,7 @@ digitValue(c) } int -lexLiteral(c) - char c; +lexLiteral(char c) { static bool passedEnd = FALSE; @@ -239,7 +227,7 @@ lexLiteral(c) } int -lexCharacterConstant() +lexCharacterConstant(void) { char c; @@ -255,13 +243,11 @@ 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(); escaped = FALSE; c = getNextChar(); @@ -291,7 +277,7 @@ getStringCharacter(input) char stringBuffer[MAX_NAME_SIZE + 1]; int -lexStringConstant() +lexStringConstant(void) { char *stringPtr; char c; @@ -308,8 +294,7 @@ lexStringConstant() } int -lexOperator(firstC) - char firstC; +lexOperator(char firstC) { char secondC; char thirdC; @@ -346,8 +331,7 @@ lexOperator(firstC) } char -controlCharacter(c) - char c; +controlCharacter(char c) { #define CONTROL_CHARACTER_MASK (~0100) @@ -355,7 +339,7 @@ controlCharacter(c) } char -skipWhitespaceAndComments() +skipWhitespaceAndComments(void) { char c; @@ -393,7 +377,7 @@ skipWhitespaceAndComments() } int -popInputFileStack() +popInputFileStack(void) { fileNameListType *oldFile; @@ -424,8 +408,7 @@ popInputFileStack() } void -pushInputFileStack(fileName) - stringType *fileName; +pushInputFileStack(stringType *fileName) { fileNameListType *newFileName; @@ -445,7 +428,7 @@ pushInputFileStack(fileName) } void -resynchronizeInput() +resynchronizeInput(void) { char c; while ((c = getNextChar())!='\n' && c!=EOF) @@ -457,8 +440,7 @@ resynchronizeInput() static bool previousLongLineFlag = FALSE; void -saveLineForListing(line) - stringType *line; +saveLineForListing(stringType *line) { if (!previousLongLineFlag) { putw(currentLocationCounter.value, saveFileForPass2); @@ -469,7 +451,7 @@ saveLineForListing(line) } void -saveEOLForListing() +saveEOLForListing(void) { putw(-1, saveFileForPass2); putw(includeNestingDepth, saveFileForPass2); @@ -477,9 +459,7 @@ saveEOLForListing() } void -saveIndexForListing(kindOfStatement, cumulativeLineNumber) - statementKindType kindOfStatement; - int cumulativeLineNumber; +saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber) { if (!amExpanding() || !notListable(kindOfStatement)) { putw(kindOfStatement, indexFileForPass2); @@ -492,8 +472,7 @@ saveIndexForListing(kindOfStatement, cumulativeLineNumber) } void -saveEndMifForListing(cumulativeLineNumber) - int cumulativeLineNumber; +saveEndMifForListing(int cumulativeLineNumber) { putw(MIF_STATEMENT, indexFileForPass2); putw(-1, indexFileForPass2); @@ -504,13 +483,13 @@ saveEndMifForListing(cumulativeLineNumber) } void -saveListingOff() +saveListingOff(void) { saveIndexForListing(-1, cumulativeLineNumber); } void -saveListingOn() +saveListingOn(void) { if (currentCodeMode == ABSOLUTE_BUFFER) saveIndexForListing(-1, cumulativeLineNumber); @@ -519,10 +498,7 @@ saveListingOn() } char * -myfgets(buffer, length, stream) - char *buffer; - int length; - FILE *stream; +myfgets(char *buffer, int length, FILE *stream) { char *result; char c; @@ -545,7 +521,7 @@ myfgets(buffer, length, stream) } int -readAnotherLine() +readAnotherLine(void) { int result; diff --git a/lexer.h b/lexer.h new file mode 100644 index 0000000..4bdb184 --- /dev/null +++ b/lexer.h @@ -0,0 +1,34 @@ +#ifndef LEXER_H_ +#define LEXER_H_ + +#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.c b/listing.c index 7050301..fdb760b 100644 --- a/listing.c +++ b/listing.c @@ -29,6 +29,13 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "emitStuff.h" +#include "lexer.h" +#include "listing.h" +#include "semanticMisc.h" + +#include +#include static char lineBuffer1[LINE_BUFFER_SIZE]; static char lineBuffer2[LINE_BUFFER_SIZE]; @@ -41,10 +48,8 @@ static int macroDepth; static int nextMacroDepth; void -outputListing() +outputListing(void) { - void generateListing(); - rewind(saveFileForPass2); rewind(indexFileForPass2); rewind(macroFileForPass2); @@ -52,7 +57,7 @@ outputListing() } void -terminateListingFiles() +terminateListingFiles(void) { saveLineForListing("\n"); saveIndexForListing(NULL_STATEMENT, cumulativeLineNumber); @@ -94,7 +99,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; @@ -122,9 +127,6 @@ generateListing() int numberOfBytesListed; char *tempText; - void readIndexFileLine(); - void readSourceFileLine(); - sourceLineNumber = 1; alreadyListingMacroExpansion = FALSE; readSourceFileLine(&sourceAddress, &sourceDepth, sourceText, @@ -298,10 +300,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; @@ -313,11 +312,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; @@ -332,10 +327,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; @@ -354,16 +346,10 @@ 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; - void tabPrint(); - if (kind != BLOCK_STATEMENT) numberOfBytes = (numberOfBytes < 4) ? numberOfBytes : 4; @@ -411,8 +397,7 @@ printListingLine(numberOfBytes, byteAddress, text, kind) bool -isBlockOpener(statementKind) - statementKindType statementKind; +isBlockOpener(statementKindType statementKind) { return (statementKind==IF_STATEMENT || statementKind==WHILE_STATEMENT || @@ -431,8 +416,7 @@ isBlockOpener(statementKind) } bool -isBlankStatement(statementKind) - statementKindType statementKind; +isBlankStatement(statementKindType statementKind) { return( statementKind == DEFINE_STATEMENT || statementKind == NULL_STATEMENT || @@ -458,8 +442,7 @@ isBlankStatement(statementKind) } void -tabPrint(text) - stringType *text; +tabPrint(stringType *text) { int column; int spaces; @@ -480,18 +463,14 @@ tabPrint(text) } void -printNTimes(aChar, times) - char aChar; - int times; +printNTimes(char aChar, int times) { - void moreText(); - while (times-- > 0) - moreText("%c", aChar); + moreText("%c", aChar, 0, 0); } void -tabIndent() +tabIndent(void) { printNTimes('\t', tabCount); } @@ -504,58 +483,52 @@ static char labelString[LINE_BUFFER_SIZE] = { '\0' }; static char *labelStringPtr = labelString; bool -labeledLine() +labeledLine(void) { return(labelStringPtr != labelString); } 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 -moreLabel(format, arg1, arg2, arg3) - char *format; - int arg1; - int arg2; - int arg3; +moreLabel(char *format, int arg1) { - sprintf(labelStringPtr, format, arg1, arg2, arg3); + sprintf(labelStringPtr, format, arg1); labelStringPtr = labelString + strlen(labelString); } @@ -563,7 +536,7 @@ static addressType savedCurrentLocationCounterValue; static int savedIncludeNestingDepth; void -startLine() +startLine(void) { printNTimes('+', macroCallDepth); savedCurrentLocationCounterValue = currentLocationCounter.value; @@ -571,7 +544,7 @@ startLine() } void -endLine() +endLine(void) { if (amListing()) { putw(savedCurrentLocationCounterValue, macroFileForPass2); @@ -583,77 +556,69 @@ 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); + moreText("%s", expressionString, 0, 0); else - addText(toBuffer, toBufferPtr, "%s", expressionString); + addText(toBuffer, toBufferPtr, "%s", expressionString, 0, 0); flushExpressionString(); } void -expandNum(buffer, bufferPtr, n) - char *buffer; - char **bufferPtr; - int n; +expandNum(char *buffer, char **bufferPtr, int n) { - moreTextOptional(buffer, bufferPtr, "%d", n); + moreTextOptional(buffer, bufferPtr, "%d", n, 0, 0); } void -flushOperand(n) - int n; +flushOperand(int n) { - moreText("%s", operandBuffer[n]); + moreText("%s", operandBuffer[n], 0, 0); operandBuffer[n][0] = '\0'; } void -expandOperands(op) - int op; +expandOperands(int op) { int i; if (op > 0) { flushOperand(0); for (i=1; i + +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); +int printListingLine(int numberOfBytes, int byteAddress, char *text, statementKindType kind); +bool isBlockOpener(statementKindType statementKind); +bool isBlankStatement(statementKindType statementKind); +void tabPrint(stringType *text); +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, ...); +void moreLabel(char *format, int arg1); +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); +void moreExpression(char *format, ...); +void startLineMarked(void); +bool notListable(statementKindType statementKind); + +#endif diff --git a/lookups.c b/lookups.c index b2bfe07..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 @@ -37,14 +45,10 @@ */ conditionType -lookupConditionCode(s, hashValue) - char *s; - int hashValue; +lookupConditionCode(char *s, int hashValue) { conditionTableEntryType *result; - genericTableEntryType *prehashedStringLookup(); - result = (conditionTableEntryType *) prehashedStringLookup(s, conditionTable, hashValue); if (result != NULL) @@ -54,14 +58,10 @@ lookupConditionCode(s, hashValue) } int -lookupKeyword(s, hashValue) - char *s; - int hashValue; +lookupKeyword(char *s, int hashValue) { keywordTableEntryType *result; - genericTableEntryType *prehashedStringLookup(); - result = (keywordTableEntryType *) prehashedStringLookup(s, keywordTable, hashValue); if (result != NULL) @@ -71,23 +71,15 @@ lookupKeyword(s, hashValue) } macroTableEntryType * -lookupMacroName(s, hashValue) - char *s; - int hashValue; +lookupMacroName(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(); - return((macroTableEntryType *) prehashedStringLookup(s, macroTable, hashValue)); } opcodeTableEntryType * -lookupOpcode(s, hashValue) - char *s; - int hashValue; +lookupOpcode(char *s, int hashValue) { - genericTableEntryType *prehashedStringLookup(); - return((opcodeTableEntryType *) prehashedStringLookup(s, opcodeTable, hashValue)); } @@ -97,14 +89,9 @@ 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(); if (result = (symbolTableEntryType *)hashStringLookup(s,symbolTable)){ /* result->referenceCount++;*/ @@ -116,8 +103,7 @@ lookupOrEnterSymbol(s, kind) } void -pushSymbol(symbol) - symbolTableEntryType *symbol; +pushSymbol(symbolTableEntryType *symbol) { symbolInContextType *newContext; @@ -127,8 +113,7 @@ pushSymbol(symbol) } void -popSymbol(symbol) - symbolTableEntryType *symbol; +popSymbol(symbolTableEntryType *symbol) { symbolInContextType *deadContext; @@ -146,17 +131,11 @@ popSymbol(symbol) } macroTableEntryType * -createMacro(macroName) - stringType *macroName; +createMacro(stringType *macroName) { macroTableEntryType *result; symbolTableEntryType *testSymbol; - genericTableEntryType *hashStringLookup(); - genericTableEntryType *hashStringEnter(); - macroTableEntryType *buildMacroTableEntry(); - symbolTableEntryType *lookupOrEnterSymbol(); - testSymbol = lookupOrEnterSymbol(macroName, MACRO_SYMBOL); if (testSymbol->context->usage != MACRO_SYMBOL) { error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol)); @@ -179,10 +158,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 +178,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 +224,7 @@ hashStringEnter(entry, table) } int -hashString(s) - char *s; +hashString(char *s) { unsigned result; @@ -264,9 +235,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 +255,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 +273,16 @@ strcmplct(s1, s2) /* For tables: s2 is already lower case */ } void -purgeSymbol(symbol) - symbolTableEntryType *symbol; +purgeSymbol(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(); - 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,13 +295,8 @@ reincarnateSymbol(context, newUsage) */ void -pushBinding(symbol, newBinding, newUsage) - symbolTableEntryType *symbol; - valueType *newBinding; - symbolUsageKindType newUsage; +pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage) { - valueType *newValue(); - pushSymbol(symbol); if (newBinding == NULL) newBinding = newValue(FAIL, 0, EXPRESSION_OPND); @@ -347,17 +308,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,8 +322,6 @@ bindMacroArguments(argumentList, parameterList, macroName) valueType **arrayContents; int i; - valueType *newValue(); - if (argumentList == NULL) arrayTag = FALSE; else @@ -417,10 +372,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,9 +383,6 @@ bindFunctionArguments(argumentList, parameterList, functionName) valueType *firstArgument; environmentType *saveEnvironment; - valueType *evaluateOperand(); - valueType *newValue(); - if (argumentList == NULL) arrayTag = FALSE; else @@ -444,7 +393,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 +444,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; @@ -515,9 +464,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 +475,7 @@ unbindArguments(argumentList, numberToUnbind) } void -unbindLocalVariables(identifierList) - identifierListType *identifierList; +unbindLocalVariables(identifierListType *identifierList) { identifierListType *deadEntry; diff --git a/lookups.h b/lookups.h new file mode 100644 index 0000000..e61dc0a --- /dev/null +++ b/lookups.h @@ -0,0 +1,29 @@ +#ifndef LOOKUPS_H_ +#define LOOKUPS_H_ + +#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/macrossGlobals.h b/macrossGlobals.h index 1b4166b..faa1823 100644 --- a/macrossGlobals.h +++ b/macrossGlobals.h @@ -29,144 +29,144 @@ */ -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]; -char pass2IndexFileName[]; -char pass2SourceFileName[]; -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 -struct { +extern struct { stringType *functionName; valueType *(*functionEntry)(); bool isSpecialFunction; int ordinal; } builtInFunctionTable[]; -struct { +extern struct { stringType *symbolName; 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]; -opcodeTableEntryType theOpcodes[]; +extern opcodeTableEntryType theOpcodes[]; -keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; +extern keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; -keywordTableEntryType theKeywords[]; +extern keywordTableEntryType theKeywords[]; -conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; +extern conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; -conditionTableEntryType theConditions[]; +extern conditionTableEntryType theConditions[]; -symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; +extern symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; -int operandClassTable[]; +extern int operandClassTable[]; -void (*instructionActionTable[])(); +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/macrossTables_6502.c b/macrossTables_6502.c index 566e8ea..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(); -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(); - /* indexed by opcodeClass */ int (*instructionActionTable[])() = { actionsRelative, @@ -303,54 +290,6 @@ 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(); - /* Used to initialize symbols representing built-in functions */ struct { stringType *functionName; diff --git a/macrossTypes.h b/macrossTypes.h index bd39166..e145054 100644 --- a/macrossTypes.h +++ b/macrossTypes.h @@ -28,6 +28,10 @@ */ +#ifndef MACROSS_TYPES_H_ +#define MACROSS_TYPES_H_ + +#include #include /* @@ -440,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 { @@ -1093,3 +1097,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/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/main.c b/main.c index c8c089e..f050847 100644 --- a/main.c +++ b/main.c @@ -29,33 +29,40 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include "initialize.h" +#include "semanticMisc.h" +#include "y.tab.h" -main(argc, argv) - int argc; - char *argv[]; +#include + +int +main(int argc, char **argv) { #ifdef __APPLE__ char end = get_end(); #else extern char end; #endif - char *sbrk(); fflush(stdout); 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) - &end, - sbrk(0) - &end); + printf("storage high water mark 0x%x == %d\n", (void *)sbrk(0) - (void *)(&end), + (void *)sbrk(0) - (void *)(&end)); if (errorFlag) chokePukeAndDie(); - else - exit(0); + return 0; } 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 30d4a85..1d80639 100644 --- a/object.c +++ b/object.c @@ -29,25 +29,24 @@ #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 static int symbolTableSize; static int symbolTableStringSize; bool encodingFunction; void -outputObjectFile() +outputObjectFile(void) { - void outputPartition(); - void outputReferenceInfo(); - void outputSymbolTableInfo(); - void outputAbsoluteCode(); - void outputRelocatableCode(); - void outputReservations(); - void outputExpressions(); - void outputFunctions(); - void dumpSymbolTable(); - void enumerateAndCountSymbols(); - if (debug || emitPrint) printCodeBuffers(); outputPartition(); @@ -70,22 +69,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; @@ -96,15 +93,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); @@ -112,8 +107,7 @@ outputString(string) } void -outputStartAddress(startAddress) - addressType startAddress; +outputStartAddress(addressType startAddress) { outputWord(startAddress); if (produceLinkableObject) { @@ -126,15 +120,12 @@ outputStartAddress(startAddress) } void -outputRelocatableCode() +outputRelocatableCode(void) { int i; addressType codeStartAddress; addressType codeEndAddress; - void outputPseudoSegment(); - void outputBreak(); - if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue == RELOCATABLE_VALUE) outputStartAddress(startAddress->value); @@ -159,8 +150,7 @@ outputRelocatableCode() } void -outputBreak(codeBreak) - codeBreakType *codeBreak; +outputBreak(codeBreakType *codeBreak) { switch (codeBreak->kindOfBreak) { case BREAK_BREAK: @@ -183,13 +173,12 @@ outputBreak(codeBreak) } void -outputAbsoluteCode() +outputAbsoluteCode(void) { int i; int startSegment; int endSegment; int nextSegment; - void outputOneCodeBuffer(); if (haveUserStartAddress && !fixupStartAddress && startAddress-> kindOfValue==ABSOLUTE_VALUE) @@ -221,8 +210,7 @@ outputAbsoluteCode() } void -outputOneCodeBuffer(segment) - codeSegmentType *segment; +outputOneCodeBuffer(codeSegmentType *segment) { int i; @@ -236,9 +224,7 @@ outputOneCodeBuffer(segment) } void -outputPseudoSegment(codeStartAddress, codeEndAddress) - addressType codeStartAddress; - addressType codeEndAddress; +outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress) { int startSegment; int endSegment; @@ -250,9 +236,6 @@ outputPseudoSegment(codeStartAddress, codeEndAddress) int segment; codeSegmentType *segmentPtr; - void outputWord(); - void outputByte(); - outputWord(codeStartAddress); outputWord(codeEndAddress); startSegment = bufferNumber(codeStartAddress); @@ -271,8 +254,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 && @@ -287,7 +269,7 @@ isObjectSymbol(symbol) } void -enumerateAndCountSymbols() +enumerateAndCountSymbols(void) { int i; symbolTableEntryType *symb; @@ -303,7 +285,7 @@ enumerateAndCountSymbols() } int -enumerateAndCountReferences() +enumerateAndCountReferences(void) { int result; int codeMode; @@ -321,8 +303,7 @@ enumerateAndCountReferences() } void -outputReference(reference) - expressionReferenceType *reference; +outputReference(expressionReferenceType *reference) { byte funnyByte; bigWord funnyWord; @@ -344,7 +325,7 @@ outputReference(reference) static int referenceCount; void -outputReferenceInfo() +outputReferenceInfo(void) { expressionReferenceListType *theReferences; int codeMode; @@ -361,12 +342,10 @@ outputReferenceInfo() } void -outputOneSymbol(symbol) - symbolTableEntryType *symbol; +outputOneSymbol(symbolTableEntryType *symbol) { byte symbolClass; valueType *symbolValue; - valueType *evaluateIdentifier(); if (symbol->context->usage == DEFINE_SYMBOL) symbolValue = evaluateIdentifier(symbol, FALSE, NO_FIXUP_OK); @@ -388,7 +367,7 @@ outputOneSymbol(symbol) } void -outputSymbolTableInfo() +outputSymbolTableInfo(void) { int i; symbolTableEntryType *symb; @@ -402,16 +381,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 @@ -426,7 +402,7 @@ shouldDumpSymbol(symbol) } void -dumpSymbolTable() +dumpSymbolTable(void) { int i; symbolTableEntryType *symb; @@ -435,9 +411,6 @@ dumpSymbolTable() int symbolPtr; valueType *value; - valueType *evaluateIdentifier(); - void printValueTersely(); - numberOfSymbols = 0; for (i=0; inextSymbol) { @@ -503,16 +476,14 @@ dumpSymbolTable() } bool -hackableSymbol(symbol) - symbolTableEntryType *symbol; +hackableSymbol(symbolTableEntryType *symbol) { return(symbol->context->usage == DEFINE_SYMBOL || symbol->context-> usage == LABEL_SYMBOL); } void -printValueTersely(value) - valueType *value; +printValueTersely(valueType *value) { static char *valueKindTable[NUM_OF_VALUE_KINDS] = { "ABS", @@ -540,7 +511,7 @@ printValueTersely(value) } void -outputReservations() +outputReservations(void) { while (reservationList != NULL) { outputWord(reservationList->startAddress); @@ -550,7 +521,7 @@ outputReservations() } void -outputExpressionBuffer() +outputExpressionBuffer(void) { int i; @@ -562,14 +533,10 @@ outputExpressionBuffer() } void -outputOneExpression(expression) - expressionType *expression; +outputOneExpression(expressionType *expression) { expressionType *newExpression; - expressionType *generateFixupExpression(); - bool encodeExpression(); - expressionBufferSize = 0; if (expression == NULL) { encodeRelocatableNumber(0); @@ -583,7 +550,7 @@ outputOneExpression(expression) } void -outputExpressions() +outputExpressions(void) { int codeMode; expressionReferenceListType *theReferences; @@ -602,12 +569,9 @@ outputExpressions() } void -outputOneFunction(function) - functionDefinitionType *function; +outputOneFunction(functionDefinitionType *function) { argumentDefinitionListType *argumentList; - bool encodeBlock(); - int countArguments(); outputByte((byte)countArguments(function)); argumentList = function->arguments; @@ -621,7 +585,7 @@ outputOneFunction(function) } void -outputFunctions() +outputFunctions(void) { outputBigword(externalFunctionCount); encodingFunction = TRUE; 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/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/operandStuff.h b/operandStuff.h new file mode 100644 index 0000000..80582f6 --- /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 freeOperand(operandType *operand); +void expandOperand(operandKindType addressMode, char *buffer); +valueType *evaluateOperand(operandType *operand); +conditionType invertConditionCode(conditionType conditionCode); +bool shouldParenthesize(operandType *operand); + +#endif diff --git a/operandStuffSD_6502.c b/operandStuffSD_6502.c index 5e35713..7fcd60d 100644 --- a/operandStuffSD_6502.c +++ b/operandStuffSD_6502.c @@ -30,13 +30,20 @@ #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 */ operandType * -buildOperand(kindOfOperand, arg) - operandKindType kindOfOperand; - anyOldThing *arg; +buildOperand(operandKindType kindOfOperand, anyOldThing *arg) { operandType *result; @@ -116,7 +123,7 @@ buildOperand(kindOfOperand, arg) break; case BLOCK_OPND: - result->theOperand.blockUnion = (BlockOperandBodyType *) arg; + result->theOperand.blockUnion = (blockOperandBodyType *) arg; break; default: @@ -129,14 +136,10 @@ 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(); - result = typeAlloc(operandListType); result->kindOfOperand = operand->kindOfOperand; result->nextOperand = NULL; @@ -151,14 +154,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: @@ -182,8 +185,7 @@ duplicateOperandForFixup(operand, isSpecialFunctionOperand) #define nullFree(thing) if (thing == NULL) return; void -freeOperand(operand) - operandType *operand; +freeOperand(operandType *operand) { nullFree(operand); switch (operand->kindOfOperand) { @@ -195,7 +197,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 +208,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: @@ -229,8 +231,7 @@ freeOperand(operand) /* corresponds to routines in listing.c */ void -expandOperand(addressMode) - operandKindType addressMode; +expandOperand(operandKindType addressMode, char *buffer) { switch (addressMode) { case IMMEDIATE_OPND: moreText("#"); break; @@ -247,7 +248,7 @@ expandOperand(addressMode) 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 || @@ -278,17 +279,12 @@ expandOperand(addressMode) #define expansionOn() expandMacros=saveExpansion; valueType * -evaluateOperand(operand) - operandType *operand; +evaluateOperand(operandType *operand) { valueType *result; bool saveExpansion; expressionType *expression; - valueType *evaluateExpression(); - valueType *evaluateSelectionList(); - valueType *newValue(); - nullEvaluate(operand); if (operand->kindOfOperand != EXPRESSION_OPND) newFixupAddressMode = operand->kindOfOperand; @@ -301,7 +297,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) { @@ -323,7 +319,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; @@ -333,7 +329,7 @@ evaluateOperand(operand) break; case STRING_OPND: - result = newValue(STRING_VALUE, operand->theOperand, + result = newValue(STRING_VALUE, operand->theOperand.stringUnion, STRING_OPND); break; @@ -341,7 +337,7 @@ evaluateOperand(operand) if (standaloneExpansionFlag) forceExpansion(); sideEffectFlag = TRUE; - assembleBlock(operand->theOperand); + assembleBlock(operand->theOperand.blockUnion); expansionOn(); result = newValue(FAIL, 0, BLOCK_OPND); break; @@ -357,8 +353,7 @@ evaluateOperand(operand) /* from parserMisc.c */ conditionType -invertConditionCode(conditionCode) - conditionType conditionCode; +invertConditionCode(conditionType conditionCode) { #define cc (int)conditionCode @@ -375,8 +370,7 @@ invertConditionCode(conditionCode) /* from semanticMisc.c */ bool -shouldParenthesize(operand) - operandType *operand; +shouldParenthesize(operandType *operand) { expressionTermKindType kind; 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: diff --git a/parserMisc.c b/parserMisc.c index b165c0b..a4ab3e8 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -32,114 +32,115 @@ #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 statementType * -addLabelToStatement(labelList, statement) - labelListType *labelList; - statementType *statement; +addLabelToStatement(labelListType *labelList, statementType *statement) { - statementType *newStatement(); - if (statement == NULL) - statement = newStatement(NULL_STATEMENT, NULL); + statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); statement->labels = labelList; 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; +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(); } 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", - defineStatement->kindOfStatement); + defineStatement->kindOfStatement, 0, 0); defineStatement->kindOfStatement = MDEFINE_STATEMENT; return(defineStatement); } ifStatementBodyType * -extractIfBody(ifStatement) - statementType *ifStatement; +extractIfBody(statementType *ifStatement) { ifStatementBodyType *result; 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); } mifStatementBodyType * -extractMifBody(mifStatement) - statementType *mifStatement; +extractMifBody(statementType *mifStatement) { mifStatementBodyType *result; 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); } stringType * -extractString(textExpression) - operandType *textExpression; +extractString(operandType *textExpression) { stringType *result; 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); } 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 new file mode 100644 index 0000000..6835f3d --- /dev/null +++ b/parserMisc.h @@ -0,0 +1,17 @@ +#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); +statementType *convertDefineToMdefine(statementType *defineStatement); +ifStatementBodyType *extractIfBody(statementType *ifStatement); +mifStatementBodyType *extractMifBody(statementType *mifStatement); +stringType *extractString(operandType *textExpression); +void popMacroOrFunctionNestingDepth(void); +void pushMacroOrFunctionNestingDepth(void); +char *saveString(char *s); + +#endif diff --git a/semanticMisc.c b/semanticMisc.c index 7861d62..05efaa4 100644 --- a/semanticMisc.c +++ b/semanticMisc.c @@ -32,6 +32,21 @@ #include "macrossGlobals.h" #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 + #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOn() expandMacros=saveExpansion; @@ -40,20 +55,17 @@ */ bool -absoluteValue(address) - valueType *address; +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) @@ -61,8 +73,7 @@ addAttributeToSymbol(symbol, attribute) } addressType -addressValue(value) - valueType *value; +addressValue(valueType *value) { if (value->kindOfValue==STRING_VALUE || value->kindOfValue==CONDITION_VALUE || @@ -73,9 +84,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'. */ @@ -206,20 +215,17 @@ 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; bool saveExpansion; - valueType *evaluateExpression(); expansionOff(); expressionResult = evaluateExpression(expression, NO_FIXUP); @@ -238,8 +244,7 @@ booleanTest(expression) } int -countArguments(function) - functionDefinitionType *function; +countArguments(functionDefinitionType *function) { int result; argumentDefinitionListType *arguments; @@ -254,8 +259,7 @@ countArguments(function) } int -countParameters(parameterList) - operandListType *parameterList; +countParameters(operandListType *parameterList) { int result; @@ -268,9 +272,7 @@ countParameters(parameterList) } arrayType * -allocArray(size, contentsPtr) - int size; - valueType ***contentsPtr; +allocArray(int size, valueType ***contentsPtr) { arrayType *result; int i; @@ -285,9 +287,7 @@ allocArray(size, contentsPtr) } valueType * -createArray(dimension, initializers) - expressionType *dimension; - expressionListType *initializers; +createArray(expressionType *dimension, expressionListType *initializers) { int initCount; valueType *arraySizeValue; @@ -296,8 +296,6 @@ createArray(dimension, initializers) arrayType *result; int i; - valueType *newValue(); - initCount = expressionListLength(initializers); if ((int)dimension == -1) { arraySize = initCount; @@ -323,8 +321,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'. */ @@ -354,8 +351,7 @@ decrementable(value) } int -expressionListLength(expressionList) - expressionListType *expressionList; +expressionListLength(expressionListType *expressionList) { int result; @@ -368,11 +364,9 @@ expressionListLength(expressionList) } int -fieldValue(symbol) - symbolTableEntryType *symbol; +fieldValue(symbolTableEntryType *symbol) { valueType *value; - valueType *evaluateIdentifier(); value = evaluateIdentifier(symbol, FALSE, NO_FIXUP); if (value->kindOfValue != FIELD_VALUE) { @@ -384,8 +378,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'. */ @@ -415,8 +408,7 @@ incrementable(value) } int -intValue(value) - valueType *value; +intValue(valueType *value) { if (value->kindOfValue != ABSOLUTE_VALUE) { error(VALUE_IS_NOT_AN_INT_ERROR); @@ -427,8 +419,7 @@ intValue(value) } bool -isAssignable(context) - symbolInContextType *context; +isAssignable(symbolInContextType *context) { return( context->usage==ARGUMENT_SYMBOL || context->usage==VARIABLE_SYMBOL || @@ -436,15 +427,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 || @@ -453,21 +442,17 @@ isDefinable(context) } bool -isExternal(symbol) - symbolTableEntryType *symbol; +isExternal(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getBaseContext(); - context = getBaseContext(symbol); return (context!=NULL && (context->attributes & GLOBAL_ATT)!=0 && context->usage != DEAD_SYMBOL); } bool -isFailure(value) - valueType *value; +isFailure(valueType *value) { if (value == NULL) return(FALSE); @@ -476,15 +461,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) { @@ -517,8 +500,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== @@ -527,8 +509,7 @@ isLogicalOp(op) } bool -isPotentialVariable(context) - symbolInContextType *context; +isPotentialVariable(symbolInContextType *context) { return( context->usage == VARIABLE_SYMBOL || context->usage == DEAD_SYMBOL || @@ -536,33 +517,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; @@ -574,9 +548,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) @@ -603,17 +575,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 && @@ -625,9 +594,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'. */ @@ -758,25 +725,20 @@ subValueKind(leftOperand, rightOperand) } int -swab(i) - int i; +swabInt(int i) { return(((i & 0xFF) << 8) | ((i & 0xFF00) >> 8)); } valueType * -swabValue(value) - valueType *value; +swabValue(valueType *value) { - valueType *newValue(); - - return(newValue(value->kindOfValue, swab(value->value), value-> + return(newValue(value->kindOfValue, swabInt(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 ? @@ -784,15 +746,10 @@ unopValueKind(operand) } void -valueField(symbol, value) - symbolTableEntryType *symbol; - valueType *value; +valueField(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolInContextType *getWorkingContext(); - symbolTableEntryType *effectiveSymbol(); - symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); if (workingContext->usage == DEAD_SYMBOL) @@ -811,16 +768,10 @@ valueField(symbol, value) } void -valueLabel(symbol, value) - symbolTableEntryType *symbol; - valueType *value; +valueLabel(symbolTableEntryType *symbol, valueType *value) { symbolInContextType *workingContext; - symbolTableEntryType *generateLocalLabel(); - symbolInContextType *getBaseContext(); - symbolTableEntryType *effectiveSymbol(); - symbol = effectiveSymbol(symbol, &workingContext); expand(moreLabel("%s:", symbol->symbolName)); if (workingContext->usage == DEAD_SYMBOL) @@ -860,17 +811,10 @@ 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(); - if (debug || emitPrint) printCreateFixup(expression, location, kindOfFixup); newFixup = typeAlloc(fixupListType); @@ -898,11 +842,8 @@ createFixup(expression, location, kindOfFixup, codeMode, whichFixup) } void -finishUp() +finishUp(void) { - void performFixups(); - void performStartAddressFixup(); - if (listingOn) terminateListingFiles(); performFixups(fixupList); @@ -932,7 +873,7 @@ isReferenceToRemember(reference) } */ void -noteAnonymousReference() +noteAnonymousReference(void) { expressionReferenceListType *newReference; @@ -954,11 +895,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; @@ -1006,10 +943,8 @@ noteReference(expression, kindOfFixup, location, codeMode) } void -performFixups(fixups) - fixupListType *fixups; +performFixups(fixupListType *fixups) { - valueType *evaluateExpression(); valueType *valueToPoke; performingFixups = TRUE; @@ -1069,12 +1004,10 @@ performFixups(fixups) } void -performStartAddressFixup() +performStartAddressFixup(void) { expressionType *startAddressExpression; - expressionType *generateFixupExpression(); - startAddressExpression = (expressionType *)startAddress; startAddress = evaluateExpression(startAddressExpression,NO_FIXUP_OK); if (startAddress->kindOfValue == UNDEFINED_VALUE && @@ -1091,9 +1024,7 @@ performStartAddressFixup() } void -putFixupsHere(kindOfFixupsToPut, whichFixup) - fixupKindType kindOfFixupsToPut; - int whichFixup; +putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup) { int location; @@ -1184,8 +1115,7 @@ putReferencesHere(kindOfReferencesToPut, whichReference) */ void -addNewLocalVariable(symbol) - symbolTableEntryType *symbol; +addNewLocalVariable(symbolTableEntryType *symbol) { identifierListType *newLocalVariable; @@ -1196,17 +1126,13 @@ 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(); - context = getWorkingContext(symbol); saveEnvironment = currentEnvironment; while (context != NULL && context->usage == ARGUMENT_SYMBOL && @@ -1233,18 +1159,13 @@ effectiveSymbol(symbol, assignmentTargetContext) } symbolTableEntryType * -generateLocalLabel(symbol) - symbolTableEntryType *symbol; +generateLocalLabel(symbolTableEntryType *symbol) { - stringType *localLabelString(); - symbolTableEntryType *lookupOrEnterSymbol(); - return(lookupOrEnterSymbol(localLabelString(symbol), LABEL_SYMBOL)); } symbolInContextType * -getBaseContext(identifier) - symbolTableEntryType *identifier; +getBaseContext(symbolTableEntryType *identifier) { symbolInContextType *result; @@ -1256,8 +1177,7 @@ getBaseContext(identifier) } symbolInContextType * -getWorkingContext(identifier) - symbolTableEntryType *identifier; +getWorkingContext(symbolTableEntryType *identifier) { symbolInContextType *result; @@ -1271,14 +1191,11 @@ getWorkingContext(identifier) } stringType * -localLabelString(symbol) - symbolTableEntryType *symbol; +localLabelString(symbolTableEntryType *symbol) { #define TEMP_SYMBOL_SIZE_LIMIT 200 char nameUnderConstruction[TEMP_SYMBOL_SIZE_LIMIT]; - stringType *saveString(); - sprintf(nameUnderConstruction, "_%d_", localLabelTagValue(symbol)); strncat(nameUnderConstruction, &(symbName(symbol)[1]), TEMP_SYMBOL_SIZE_LIMIT); @@ -1286,14 +1203,10 @@ localLabelString(symbol) } int -localLabelTagValue(symbol) - symbolTableEntryType *symbol; +localLabelTagValue(symbolTableEntryType *symbol) { symbolInContextType *context; - symbolInContextType *getWorkingContext(); - void addNewLocalVariable(); - context = getWorkingContext(symbol); if (context == NULL) botch("local label doesn't have symbol context\n"); @@ -1308,12 +1221,9 @@ localLabelTagValue(symbol) } void -addBreak(kind, data) - codeBreakKindType kind; - int data; +addBreak(codeBreakKindType kind, int data) { codeBreakType *newBreak; - codeBreakType *buildCodeBreak(); newBreak = buildCodeBreak(kind, currentLocationCounter.value, data); if (codeBreakList == NULL) { @@ -1325,12 +1235,8 @@ addBreak(kind, data) } void -reserveAbsolute(startAddress, blockSize) - addressType startAddress; - int blockSize; +reserveAbsolute(addressType startAddress, int blockSize) { - reservationListType *buildReservation(); - if (reservationList != NULL && reservationList->startAddress + reservationList->blockSize == startAddress) reservationList->blockSize += blockSize; @@ -1340,8 +1246,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 new file mode 100644 index 0000000..e6f9211 --- /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(expressionType *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 swabInt(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); +void noteAnonymousReference(void); +void noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode); +void performFixups(fixupListType *fixups); +void performStartAddressFixup(void); +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 diff --git a/slinky/Makefile b/slinky/Makefile index 966c189..4082250 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 # slinky is not 64 bit clean +CFLAGS= -m32 # slinky is not 64 bit clean .c.o: - cc $(CFLAGS) -c -g $*.c + cc $(CFLAGS) -c $*.c .c.run: cc $(CFLAGS) -o $* $*.c @@ -19,30 +19,6 @@ CFLAGS=-m32 # slinky is not 64 bit clean 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 @@ -71,7 +47,7 @@ slinkyTables.o: slinkyTables.c slinkyTypes.h write.o: write.c slinkyGlobals.h slinkyTypes.h -cleanup: +clean: /bin/rm -f *.o slinky love: diff --git a/slinky/builtins.c b/slinky/builtins.c index c44a7bc..fb627f5 100644 --- a/slinky/builtins.c +++ b/slinky/builtins.c @@ -30,14 +30,17 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" -#include +#include "builtins.h" +#include "errorStuff.h" +#include "expr.h" +#include "link.h" +#include "relocate.h" +#include #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) @@ -45,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) @@ -84,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; @@ -108,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; @@ -144,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"); @@ -154,8 +152,7 @@ isAbsoluteValueBIF(argCount) /* Check if operand is a condition code */ bool -isConditionCodeBIF(argCount) - int argCount; +isConditionCodeBIF(int argCount) { bool result; @@ -172,8 +169,7 @@ isConditionCodeBIF(argCount) /* Check if a symbol is defined */ bool -isDefinedBIF(argCount) - int argCount; +isDefinedBIF(int argCount) { symbolType *symbol; @@ -194,8 +190,7 @@ isDefinedBIF(argCount) /* Check if a symbol is externally visible */ bool -isExternalBIF(argCount) - int argCount; +isExternalBIF(int argCount) { symbolType *symbol; @@ -216,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; @@ -240,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]; @@ -269,8 +262,7 @@ printfBIF(argCount) /* Concatenate two strings */ stringType * -strcatBIF(argCount) - int argCount; +strcatBIF(int argCount) { stringType *string1; stringType *string2; @@ -294,8 +286,7 @@ strcatBIF(argCount) /* Compare two strings */ int -strcmpBIF(argCount) - int argCount; +strcmpBIF(int argCount) { stringType *string1; stringType *string2; @@ -314,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; @@ -335,8 +324,7 @@ strcmplcBIF(argCount) /* Return the length of a string */ int -strlenBIF(argCount) - int argCount; +strlenBIF(int argCount) { if (argCount < 1) return(0); @@ -349,8 +337,7 @@ strlenBIF(argCount) /* Return a substring of a string */ char * -substrBIF(argCount) - int argCount; +substrBIF(int argCount) { stringType *string; int start; @@ -404,12 +391,10 @@ substrBIF(argCount) /* Turn a string into a symbol and return its value */ addressType -symbolLookupBIF(argCount) - int argCount; +symbolLookupBIF(int argCount) { symbolType *symbol; stringType *symbolName; - symbolType *lookupGlobalSymbol(); if (argCount < 1) { tooFewArgs(argCount, "symbolLookup"); @@ -429,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/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..461fd07 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", @@ -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/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 e4a026d..ede5892 100644 --- a/slinky/errorStuff.c +++ b/slinky/errorStuff.c @@ -29,16 +29,12 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "errorStuff.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 +75,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); +} 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..e4000b7 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,17 +44,11 @@ #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; int -getNumber() +getNumber(void) { register int result; register int i; @@ -64,7 +61,7 @@ getNumber() } addressType -evaluateArray() +evaluateArray(void) { error(ARRAY_TERM_IN_OBJECT_ERROR); skipArray(); @@ -72,7 +69,7 @@ evaluateArray() } addressType -evaluateAssert() +evaluateAssert(void) { if (!evaluateExpression()) error(ASSERT_FAILED_ERROR, pc); @@ -80,7 +77,7 @@ evaluateAssert() } addressType -evaluateBinop() +evaluateBinop(void) { int op; symbolType *leftSymbol; @@ -159,7 +156,7 @@ evaluateBinop() } addressType -evaluateBlock() +evaluateBlock(void) { while (*pc != END_TAG) { evaluateExpression(); @@ -172,7 +169,7 @@ evaluateBlock() } addressType -evaluateConditionCode() +evaluateConditionCode(void) { overByte(); error(CONDITION_CODE_EXPRESSION_ENCOUNTERED_ERROR); @@ -180,9 +177,7 @@ evaluateConditionCode() } void -pushSymbol(symbol, value) - symbolType *symbol; - addressType value; +pushSymbol(symbolType *symbol, addressType value) { bindingListType *newBinding; @@ -197,9 +192,7 @@ pushSymbol(symbol, value) } void -bindFunctionArguments(theFunction, argCount) - functionType *theFunction; - int argCount; +bindFunctionArguments(functionType *theFunction, int argCount) { argumentListType *argList; @@ -223,7 +216,7 @@ bindFunctionArguments(theFunction, argCount) } void -undoBindings() +undoBindings(void) { bindingListType *deadBinding; @@ -239,7 +232,7 @@ undoBindings() } addressType -evaluateFreturn() +evaluateFreturn(void) { hitFreturn = TRUE; functionResult = evaluateExpression(); @@ -247,7 +240,7 @@ evaluateFreturn() } addressType -evaluateBuiltinFunctionCall() +evaluateBuiltinFunctionCall(void) { int theFunction; int argCount; @@ -262,7 +255,7 @@ evaluateBuiltinFunctionCall() } addressType -evaluateFunctionCall() +evaluateFunctionCall(void) { expressionPCType savePoint; functionType *theFunction; @@ -288,13 +281,13 @@ evaluateFunctionCall() } addressType -evaluateHere() +evaluateHere(void) { return(here); } addressType -evaluateMdefine() +evaluateMdefine(void) { symbolType *symbol; @@ -303,7 +296,7 @@ evaluateMdefine() } addressType -evaluateMdoUntil() +evaluateMdoUntil(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -320,7 +313,7 @@ evaluateMdoUntil() } addressType -evaluateMdoWhile() +evaluateMdoWhile(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -337,7 +330,7 @@ evaluateMdoWhile() } addressType -evaluateMfor() +evaluateMfor(void) { expressionPCType testPoint; expressionPCType incrPoint; @@ -367,7 +360,7 @@ evaluateMfor() } addressType -evaluateMif() +evaluateMif(void) { if (evaluateExpression()) { evaluateExpression(); @@ -380,8 +373,7 @@ evaluateMif() } bool -evaluateClause(pattern) - addressType pattern; +evaluateClause(addressType pattern) { bool match; @@ -399,7 +391,7 @@ evaluateClause(pattern) } addressType -evaluateMswitch() +evaluateMswitch(void) { addressType pattern; @@ -414,7 +406,7 @@ evaluateMswitch() } addressType -evaluateMwhile() +evaluateMwhile(void) { expressionPCType testPoint; expressionPCType endPoint; @@ -433,7 +425,7 @@ evaluateMwhile() } addressType -evaluateMvariable() +evaluateMvariable(void) { symbolType *symbol; @@ -442,7 +434,7 @@ evaluateMvariable() } addressType -evaluateNumber() +evaluateNumber(void) { addressType result; int i; @@ -455,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; @@ -485,7 +477,7 @@ evaluatePostop() } addressType -evaluatePreop() +evaluatePreop(void) { int op; symbolType *target; @@ -502,7 +494,7 @@ evaluatePreop() } addressType -evaluateString() +evaluateString(void) { addressType result; @@ -513,7 +505,7 @@ evaluateString() } addressType -evaluateSymbol() +evaluateSymbol(void) { symbolType *target; @@ -522,7 +514,7 @@ evaluateSymbol() } addressType -evaluateUnop() +evaluateUnop(void) { int op; addressType arg; @@ -548,7 +540,7 @@ evaluateUnop() } addressType -evaluateExpression() +evaluateExpression(void) { if (pc == NULL) return(0); @@ -650,21 +642,21 @@ evaluateExpression() } void -skipArray() +skipArray(void) { overSymbol(); skipExpression(); } void -skipAssert() +skipAssert(void) { skipExpression(); skipString(); } void -skipBinop() +skipBinop(void) { overByte(); skipExpression(); @@ -672,7 +664,7 @@ skipBinop() } void -skipBlock() +skipBlock(void) { while (*pc != END_TAG) skipExpression(); @@ -680,7 +672,7 @@ skipBlock() } void -skipFunctionCall() +skipFunctionCall(void) { int argCount; @@ -691,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(); @@ -721,7 +713,7 @@ skipMfor() } void -skipMif() +skipMif(void) { skipExpression(); skipExpression(); @@ -729,7 +721,7 @@ skipMif() } void -skipClause() +skipClause(void) { while (*pc != BLOCK_TAG) skipExpression; @@ -737,7 +729,7 @@ skipClause() } void -skipMswitch() +skipMswitch(void) { skipExpression(); while (*pc != END_TAG) @@ -746,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/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/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/initialize.c b/slinky/initialize.c index 3905f35..dfab2a2 100644 --- a/slinky/initialize.c +++ b/slinky/initialize.c @@ -29,20 +29,24 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "initialize.h" +#include "errorStuff.h" +#include "main.h" + +#include +#include 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; @@ -52,9 +56,6 @@ initializeStuff(argc, argv) int mapFilesFound; char *mapFileName; - void queueInputFile(); - void queueLoadAddress(); - currentFileName = ""; errorFlag = FALSE; packFlag = FALSE; @@ -174,8 +175,7 @@ initializeStuff(argc, argv) void -queueInputFile(name) - char *name; +queueInputFile(char *name) { objectFileListType *newObjectFile; @@ -194,8 +194,7 @@ queueInputFile(name) } void -queueLoadAddress(addressString) - char *addressString; +queueLoadAddress(char *addressString) { int loadAddress; objectFileListType *newObjectFile; 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..4d2f5c1 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,13 +41,8 @@ #define overByte() pc++ #define nextByte(byt) (byt = *pc++) -void putSymbolPointersIntoArray(); -void putSymbolPointersIntoClause(); -void putSymbolPointersIntoExpression(); - void -putNumber(number) - int number; +putNumber(int number) { int i; for (i=0; iname; if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { @@ -152,9 +159,7 @@ internalizeOneObjectFile(objectFile) #define toLowerCase(c) (('A'<=(c)&&(c)<='Z')?((c)-'A'+'a'):(c)); bool -strcmplc(s1, s2) - char *s1; - char *s2; +strcmplc(char *s1, char *s2) { register char c1; register char c2; @@ -176,9 +181,7 @@ strcmplc(s1, s2) } bool -compareSymbols(symbol1, symbol2) - symbolType **symbol1; - symbolType **symbol2; +compareSymbols(symbolType **symbol1, symbolType **symbol2) { bool result; @@ -193,8 +196,7 @@ compareSymbols(symbol1, symbol2) } void -buildGlobalSymbolTable(inputFileList) - objectFileListType *inputFileList; +buildGlobalSymbolTable(objectFileListType *inputFileList) { int symbolCount; symbolType **symbol; @@ -226,7 +228,7 @@ buildGlobalSymbolTable(inputFileList) } bool -readem() +readem(void) { objectFileListType *inputFileList; @@ -246,8 +248,7 @@ readem() } codeSegmentHeaderType * -locateConflictingSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +locateConflictingSegment(codeSegmentHeaderType *codeSegment) { segmentListType *segmentPtr; int segmentListOffset; @@ -283,9 +284,7 @@ locateConflictingSegment(codeSegment) } void -reserveSegment(start, end) - addressType start; - addressType end; +reserveSegment(addressType start, addressType end) { freeSegmentEntryType *freeSegmentPtr; freeSegmentEntryType *previousSegmentPtr; @@ -338,8 +337,7 @@ reserveSegment(start, end) } codeSegmentHeaderType * -allocateAbsolute(codeSegment) - codeSegmentHeaderType *codeSegment; +allocateAbsolute(codeSegmentHeaderType *codeSegment) { freeSegmentEntryType *freeSegmentPtr; freeSegmentEntryType *previousSegmentPtr; @@ -389,7 +387,7 @@ allocateAbsolute(codeSegment) } void -reserveReservations() +reserveReservations(void) { while (reservationList != NULL) { reserveSegment(reservationList->startAddress, @@ -400,8 +398,7 @@ reserveReservations() } void -installSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +installSegment(codeSegmentHeaderType *codeSegment) { segmentListType *previousSegment; segmentListType *installSegmentList; @@ -436,8 +433,7 @@ installSegment(codeSegment) } void -installAbsoluteCodeSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment) { codeSegmentHeaderType *conflictingSegment; @@ -452,7 +448,7 @@ installAbsoluteCodeSegment(codeSegment) } void -linkem() +linkem(void) { if (!readem()) return; 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..c363fca 100644 --- a/slinky/main.c +++ b/slinky/main.c @@ -29,21 +29,22 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "main.h" +#include "initialize.h" +#include "link.h" -main(argc, argv) - int argc; - char *argv[]; +int +main(int argc, char **argv) { initializeStuff(argc, argv); linkem(); if (errorFlag) chokePukeAndDie(); - else - exit(0); + return 0; } void -printVersion() +printVersion(void) { printf("Slinky version 1.16.\n"); } 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..3f3eec9 100644 --- a/slinky/map.c +++ b/slinky/map.c @@ -30,16 +30,12 @@ #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) - loadMapTableEntryType *entry1; - loadMapTableEntryType *entry2; +compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2) { int result; @@ -55,7 +51,7 @@ compareLoadMapEntries(entry1, entry2) } void -outputLoadMap() +outputLoadMap(void) { loadMapTableEntryType *loadMapTable; loadMapTableEntryType *loadMapPtr; 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..53d6b57 100644 --- a/slinky/poke.c +++ b/slinky/poke.c @@ -31,33 +31,31 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "poke.h" +#include "debugPrint.h" +#include "errorStuff.h" +#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; @@ -77,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; @@ -101,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: @@ -150,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; @@ -182,7 +170,7 @@ fixupReference(reference, codeSegment) } void -pokem() +pokem(void) { objectFileListType *inputFileList; codeSegmentHeaderType *codeSegment; 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..0a8cbae 100644 --- a/slinky/read.c +++ b/slinky/read.c @@ -31,14 +31,18 @@ #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) void -fileCheck(fildes, fileName) - FILE *fildes; - char *fileName; +fileCheck(FILE *fildes, char *fileName) { if (feof(fildes)) { error(PREMATURE_EOF_ERROR, fileName); @@ -51,9 +55,7 @@ fileCheck(fildes, fileName) } wordType -readWord(file, fileName) - FILE *file; - char *fileName; +readWord(FILE *file, char *fileName) { wordType result; register char loByte; @@ -67,9 +69,7 @@ readWord(file, fileName) } byte -readByte(file, fileName) - FILE *file; - char *fileName; +readByte(FILE *file, char *fileName) { int result; @@ -80,9 +80,7 @@ readByte(file, fileName) } bigWord -readBigword(file, fileName) - FILE *file; - char *fileName; +readBigword(FILE *file, char *fileName) { register bigWord result; @@ -95,9 +93,7 @@ readBigword(file, fileName) } bigWord -read3ByteWord(file, fileName) - FILE *file; - char *fileName; +read3ByteWord(FILE *file, char *fileName) { register bigWord result; @@ -109,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; @@ -126,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); @@ -139,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; @@ -193,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) @@ -212,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; @@ -241,9 +218,7 @@ readReference(reference, fildes, fileName) } void -readReferences(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readReferences(objectFileListType *objectFile, FILE *objectFildes) { int count; int readCount; @@ -292,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) @@ -315,9 +288,7 @@ compareSymbolValues(symbol1, symbol2) } void -readSymbols(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readSymbols(objectFileListType *objectFile, FILE *objectFildes) { symbolType *symbolTable; symbolType **symbolTableIndir; @@ -359,9 +330,7 @@ readSymbols(objectFile, objectFildes) } expressionPCType -readOneExpression(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readOneExpression(objectFileListType *objectFile, FILE *objectFildes) { char *fileName; int expressionSize; @@ -386,9 +355,7 @@ readOneExpression(objectFile, objectFildes) } void -readExpressions(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readExpressions(objectFileListType *objectFile, FILE *objectFildes) { expressionPCType *expressions; int expressionCount; @@ -420,9 +387,7 @@ readExpressions(objectFile, objectFildes) } argumentListType * -readArgumentList(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readArgumentList(objectFileListType *objectFile, FILE *objectFildes) { int argumentCount; char *fileName; @@ -447,9 +412,7 @@ readArgumentList(objectFile, objectFildes) } void -readFunctions(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readFunctions(objectFileListType *objectFile, FILE *objectFildes) { functionType *functions; int functionCount; @@ -483,8 +446,7 @@ readFunctions(objectFile, objectFildes) } void -instantiateExpressionAndSymbolPointers(objectFile) - objectFileListType *objectFile; +instantiateExpressionAndSymbolPointers(objectFileListType *objectFile) { symbolType **symbolTable; expressionPCType *expressions; @@ -515,12 +477,9 @@ instantiateExpressionAndSymbolPointers(objectFile) } void -readReservations(objectFile, objectFildes) - objectFileListType *objectFile; - FILE *objectFildes; +readReservations(objectFileListType *objectFile, FILE *objectFildes) { addressType startAddress; - reservationListType *buildReservation(); if (debug) printf(" reservations\n"); @@ -532,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/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..1a2bfd9 100644 --- a/slinky/relocate.c +++ b/slinky/relocate.c @@ -30,11 +30,16 @@ #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) void -removeZeroPageFromFreeList() +removeZeroPageFromFreeList(void) { while (freeSegmentList->segmentEndAddress <= 0x100) freeSegmentList = freeSegmentList->nextFreeSegment; @@ -43,9 +48,7 @@ removeZeroPageFromFreeList() } addressType -align(address, alignment) - addressType address; - int alignment; +align(addressType address, int alignment) { if (alignment == 0) return(address); @@ -54,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); @@ -67,8 +67,7 @@ constrain(address, size, constraint) return(address); } void -moveRelocationBase(newBase) - addressType newBase; +moveRelocationBase(addressType newBase) { freeSegmentEntryType *freePtr; freeSegmentEntryType *newFreePtr; @@ -90,8 +89,7 @@ moveRelocationBase(newBase) } addressType -allocateRelocatable(codeSegment) - codeSegmentHeaderType *codeSegment; +allocateRelocatable(codeSegmentHeaderType *codeSegment) { freeSegmentEntryType *freePtr; freeSegmentEntryType *previousPtr; @@ -146,9 +144,7 @@ allocateRelocatable(codeSegment) } void -relocateOneCodeSegment(codeSegment, targetLocation) - codeSegmentHeaderType *codeSegment; - addressType targetLocation; +relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation) { int relocationOffset; @@ -170,7 +166,7 @@ relocateOneCodeSegment(codeSegment, targetLocation) } void -relocatem() +relocatem(void) { objectFileListType *inputFileList; addressType targetLocation; @@ -205,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)) || @@ -219,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 & @@ -230,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 && @@ -245,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; @@ -265,8 +252,7 @@ valueSymbol(symbol, codeSegment) } symbolType * -lookupGlobalSymbol(symbolName) - char *symbolName; +lookupGlobalSymbol(char *symbolName) { int guess; int top; @@ -295,8 +281,7 @@ lookupGlobalSymbol(symbolName) } void -valueUndefinedSymbol(symbol) - symbolType *symbol; +valueUndefinedSymbol(symbolType *symbol) { symbolType *globalSymbol; @@ -309,7 +294,7 @@ valueUndefinedSymbol(symbol) } void -valuem() +valuem(void) { objectFileListType *inputFileList; codeSegmentHeaderType *codeSegmentPtr; 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/slinkyGlobals.h b/slinky/slinkyGlobals.h index 7968834..e90cdf9 100644 --- a/slinky/slinkyGlobals.h +++ b/slinky/slinkyGlobals.h @@ -27,43 +27,43 @@ 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) -struct { +extern struct { stringType *functionName; addressType (*functionEntry)(); } builtInFunctionTable[]; 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 2d8761d..161a143 100644 --- a/slinky/slinkyTypes.h +++ b/slinky/slinkyTypes.h @@ -26,7 +26,10 @@ 8-March-1985 */ +#ifndef SLINKY_TYPES_H_ +#define SLINKY_TYPES_H_ +#include #include typedef unsigned char byte; @@ -187,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..007cb71 100644 --- a/slinky/write.c +++ b/slinky/write.c @@ -30,13 +30,14 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "write.h" #define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\ putc((aWord >> 8) & 0xFF, loadFileOutput) #define writeByte(aByte) putc(aByte & 0xFF, loadFileOutput) void -writeEntryPoint() +writeEntryPoint(void) { writeWord(entryPointAddress); writeWord(entryPointAddress); @@ -44,8 +45,7 @@ writeEntryPoint() } void -writeCodeSegment(codeSegment) - codeSegmentHeaderType *codeSegment; +writeCodeSegment(codeSegmentHeaderType *codeSegment) { int length; int i; @@ -59,7 +59,7 @@ writeCodeSegment(codeSegment) } void -writem() +writem(void) { int regionNumber; codeSegmentHeaderType *lastSegment; 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 diff --git a/statementSemantics.c b/statementSemantics.c index e93cac2..f8ea6dc 100644 --- a/statementSemantics.c +++ b/statementSemantics.c @@ -30,6 +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; @@ -49,31 +66,21 @@ bool nullStatementFlag = FALSE; #define expansionOn() expandMacros=saveExpansion; void -assembleBlock(block) - blockType *block; +assembleBlock(blockType *block) { - simpleFixupListType *assembleStatement(); - nullAssemble(block); assembleStatement(block, FALSE, NULL); } simpleFixupListType * -assembleBlockInsideIf(block, ongoingFixupList) - blockType *block; - simpleFixupListType *ongoingFixupList; +assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList) { - simpleFixupListType *assembleStatement(); - 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; @@ -89,18 +96,13 @@ operandCheck(opcode, numberOfOperands, evaluatedOperands) } void -assembleMachineInstruction(opcode, operands) - opcodeTableEntryType *opcode; - operandListType *operands; +assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands) { int i; int op; 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; @@ -141,9 +143,7 @@ assembleMachineInstruction(opcode, operands) } void -assembleMacro(macroInstruction, operands) - macroTableEntryType *macroInstruction; - operandListType *operands; +assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands) { int numberBound; identifierListType *savedLocalVariableList; @@ -187,15 +187,11 @@ assembleMacro(macroInstruction, operands) } void -assembleAlignStatement(alignStatement) - alignStatementBodyType *alignStatement; +assembleAlignStatement(alignStatementBodyType *alignStatement) { int alignment; bool saveExpansion; - int intValue(); - valueType *evaluateExpression(); - nullAssemble(alignStatement); expansionOff(); alignment = intValue(evaluateExpression(alignStatement, NO_FIXUP)); @@ -222,15 +218,12 @@ assembleAlignStatement(alignStatement) } void -assembleAssertStatement(assertStatement) - assertStatementBodyType *assertStatement; +assembleAssertStatement(assertStatementBodyType *assertStatement) { valueType *test; valueType *message; bool saveExpansion; - valueType *evaluateExpression(); - expansionOff(); test = evaluateExpression(assertStatement->condition, NO_FIXUP); expansionOn(); @@ -255,15 +248,11 @@ assembleAssertStatement(assertStatement) } void -assembleBlockStatement(blockStatement) - blockStatementBodyType *blockStatement; +assembleBlockStatement(blockStatementBodyType *blockStatement) { valueType *blockIncrement; int blockSize; - valueType *evaluateExpression(); - int intValue(); - blockSize = 0; nullAssemble(blockStatement); expand(moreText("block\t")); @@ -272,7 +261,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); } @@ -295,13 +284,10 @@ assembleBlockStatement(blockStatement) } void -assembleByteStatement(byteStatement) - byteStatementBodyType *byteStatement; +assembleByteStatement(byteStatementBodyType *byteStatement) { valueType *byteValue; - valueType *evaluateExpression(); - nullAssemble(byteStatement); expand(moreText("byte\t")); while (byteStatement != NULL) { @@ -315,15 +301,14 @@ assembleByteStatement(byteStatement) } qfree(byteValue); byteStatement = byteStatement->nextExpression; - expand((expandExpression(NULL), byteStatement != NULL ? + expand((expandExpression(NULL, NULL), byteStatement != NULL ? moreText(", ") : 0)); } expand(endLine()); } void -assembleConstrainStatement(constrainStatement) - constrainStatementBodyType *constrainStatement; +assembleConstrainStatement(constrainStatementBodyType *constrainStatement) { valueType *constraintValue; int constraint; @@ -331,8 +316,6 @@ assembleConstrainStatement(constrainStatement) addressType endAddress; bool saveExpansion; - valueType *evaluateExpression(); - expansionOff(); constraintValue = evaluateExpression(constrainStatement->constraint, NO_FIXUP); @@ -368,21 +351,17 @@ assembleConstrainStatement(constrainStatement) } void -assembleDbyteStatement(dbyteStatement) - dbyteStatementBodyType *dbyteStatement; +assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement) { valueType *wordValue; - valueType *evaluateExpression(); - valueType *swabValue(); - nullAssemble(dbyteStatement); expand(moreText("dbyte\t")); while (dbyteStatement != NULL) { 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); @@ -392,17 +371,12 @@ assembleDbyteStatement(dbyteStatement) } void -assembleDefineStatement(defineStatement) - defineStatementBodyType *defineStatement; +assembleDefineStatement(defineStatementBodyType *defineStatement) { symbolTableEntryType *symbolToDefine; symbolInContextType *contextToDefine; bool saveExpansion; - valueType *evaluateDefineExpression(); - valueType *newValue(); - symbolTableEntryType *effectiveSymbol(); - nullAssemble(defineStatement); symbolToDefine = effectiveSymbol(defineStatement->theSymbol, &contextToDefine); @@ -422,7 +396,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); @@ -437,13 +411,10 @@ assembleDefineStatement(defineStatement) } void -assembleDoUntilStatement(doUntilStatement) - doUntilStatementBodyType *doUntilStatement; +assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement) { valueType topOfLoop; - simpleFixupListType *emitJump(); - nullAssemble(doUntilStatement); topOfLoop = currentLocationCounter; if (doUntilStatement->doUntilCondition == NEVER_COND) @@ -464,13 +435,10 @@ assembleDoUntilStatement(doUntilStatement) } void -assembleDoWhileStatement(doWhileStatement) - doWhileStatementBodyType *doWhileStatement; +assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement) { valueType topOfLoop; - simpleFixupListType *emitJump(); - nullAssemble(doWhileStatement); topOfLoop = currentLocationCounter; if (doWhileStatement->doWhileCondition == ALWAYS_COND) @@ -491,15 +459,11 @@ assembleDoWhileStatement(doWhileStatement) } void -assembleExternStatement(externStatement) - externStatementBodyType *externStatement; +assembleExternStatement(externStatementBodyType *externStatement) { symbolInContextType *context; symbolTableEntryType *theSymbol; - symbolInContextType *getBaseContext(); - symbolTableEntryType *effectiveSymbol(); - expand(moreText("extern\t")); while (externStatement != NULL) { theSymbol = effectiveSymbol(externStatement->theSymbol, @@ -523,8 +487,7 @@ assembleExternStatement(externStatement) } void -assembleFreturnStatement(freturnStatement) - freturnStatementBodyType *freturnStatement; +assembleFreturnStatement(freturnStatementBodyType *freturnStatement) { freturnExit = TRUE; resultOfLastFunctionCall = evaluateExpression(freturnStatement, @@ -532,17 +495,12 @@ assembleFreturnStatement(freturnStatement) } void -assembleFunctionStatement(functionStatement) - functionStatementBodyType *functionStatement; +assembleFunctionStatement(functionStatementBodyType *functionStatement) { symbolTableEntryType *newFunctionSymbol; functionDefinitionType *newFunction; symbolInContextType *context; - symbolTableEntryType *lookupOrEnterSymbol(); - valueType *newValue(); - symbolInContextType *getBaseContext(); - nullAssemble(functionStatement); if (currentEnvironment != &globalEnvironment) { error(FUNCTION_DEFINITION_INSIDE_FUNCTION_ERROR); @@ -576,8 +534,7 @@ assembleFunctionStatement(functionStatement) } void -assembleGroupStatement(groupStatement) - blockType *groupStatement; +assembleGroupStatement(blockType *groupStatement) { expand((startLineMarked(), tabIndent(), moreText("{"), endLine(), tabCount++)); @@ -587,17 +544,11 @@ 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; - simpleFixupListType *emitJump(); - void assembleIfStatementOldStyle(); - if (backwardsCompatibleIfFlag) { assembleIfStatementOldStyle(ifStatement); return(NULL); @@ -643,14 +594,11 @@ assembleIfStatement(ifStatement, terminalIf, ongoingFixupList) } void -assembleIfStatementOldStyle(ifStatement) - ifStatementBodyType *ifStatement; +assembleIfStatementOldStyle(ifStatementBodyType *ifStatement) { valueType fixupLocation1[COMPOUND_BRANCH_MAX]; simpleFixupListType *fixupLocation2; - simpleFixupListType *emitJump(); - nullAssemble(ifStatement); if (ifStatement->ifCondition != ALWAYS_COND) { emitRelativeBranch(invertConditionCode(ifStatement-> @@ -678,14 +626,11 @@ assembleIfStatementOldStyle(ifStatement) } void -assembleIncludeStatement(includeStatement) - includeStatementBodyType *includeStatement; +assembleIncludeStatement(includeStatementBodyType *includeStatement) { stringType *fileName; valueType *possibleFileName; bool saveExpansion; - valueType *evaluateExpression(); - stringType *saveString(); expansionOff(); possibleFileName = evaluateExpression(includeStatement, NO_FIXUP); @@ -701,9 +646,7 @@ assembleIncludeStatement(includeStatement) } void -assembleInstructionStatement(instructionStatement, cumulativeLineNumber) - instructionStatementBodyType *instructionStatement; - int cumulativeLineNumber; +assembleInstructionStatement(instructionStatementBodyType *instructionStatement, int cumulativeLineNumber) { nullAssemble(instructionStatement); switch(instructionStatement->kindOfInstruction) { @@ -727,26 +670,23 @@ assembleInstructionStatement(instructionStatement, cumulativeLineNumber) default: botch("bad instruction type=%d\n", instructionStatement-> - kindOfInstruction); + kindOfInstruction, 0, 0); break; } } void -assembleLongStatement(longStatement) - longStatementBodyType *longStatement; +assembleLongStatement(longStatementBodyType *longStatement) { valueType *longValue; - valueType *evaluateExpression(); - nullAssemble(longStatement); expand(moreText("long\t")); while (longStatement != NULL) { 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); @@ -756,13 +696,10 @@ assembleLongStatement(longStatement) } void -assembleMacroStatement(macroStatement) - macroStatementBodyType *macroStatement; +assembleMacroStatement(macroStatementBodyType *macroStatement) { macroTableEntryType *newMacro; - macroTableEntryType *installMacro(); - nullAssemble(macroStatement); if (currentEnvironment != &globalEnvironment) { error(MACRO_DEFINITION_INSIDE_MACRO_ERROR); @@ -781,11 +718,9 @@ assembleMacroStatement(macroStatement) } void -assembleMdefineStatement(mdefineStatement) - defineStatementBodyType *mdefineStatement; +assembleMdefineStatement(defineStatementBodyType *mdefineStatement) { bool saveExpansion; - valueType *evaluateDefineExpression(); nullAssemble(mdefineStatement); expansionOff(); @@ -796,8 +731,7 @@ assembleMdefineStatement(mdefineStatement) } void -assembleMdoUntilStatement(mdoUntilStatement) - mdoUntilStatementBodyType *mdoUntilStatement; +assembleMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { bool saveListingOn; @@ -811,8 +745,7 @@ assembleMdoUntilStatement(mdoUntilStatement) } void -assembleMdoWhileStatement(mdoWhileStatement) - mdoWhileStatementBodyType *mdoWhileStatement; +assembleMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement) { bool saveListingOn; @@ -826,8 +759,7 @@ assembleMdoWhileStatement(mdoWhileStatement) } void -assembleMforStatement(mforStatement) - mforStatementBodyType *mforStatement; +assembleMforStatement(mforStatementBodyType *mforStatement) { bool saveListingOn; bool saveExpansion; @@ -848,9 +780,7 @@ assembleMforStatement(mforStatement) } void -assembleMifStatement(mifStatement, cumulativeLineNumber) - mifStatementBodyType *mifStatement; - int cumulativeLineNumber; +assembleMifStatement(mifStatementBodyType *mifStatement, int cumulativeLineNumber) { while (mifStatement != NULL) { if (mifStatement->mifCondition == NULL) { @@ -869,8 +799,7 @@ assembleMifStatement(mifStatement, cumulativeLineNumber) } void -assembleMswitchStatement(mswitchStatement) - mswitchStatementBodyType *mswitchStatement; +assembleMswitchStatement(mswitchStatementBodyType *mswitchStatement) { valueType *switchValue; caseListType *caseList; @@ -879,7 +808,6 @@ assembleMswitchStatement(mswitchStatement) expressionListType *tagExpressionList; valueType *tagValue; bool saveExpansion; - valueType *evaluateExpression(); expansionOff(); switchValue = evaluateExpression(mswitchStatement->switchExpression, @@ -932,16 +860,12 @@ assembleMswitchStatement(mswitchStatement) } void -assembleMvariableStatement(mvariableStatement) - mvariableStatementBodyType *mvariableStatement; +assembleMvariableStatement(mvariableStatementBodyType *mvariableStatement) { identifierListType *newLocalVariable; int initCount; bool saveExpansion; - valueType *createArray(); - int expressionListLength(); - nullAssemble(mvariableStatement); expansionOff(); if (mvariableStatement->theDimension == NULL) { @@ -970,8 +894,7 @@ assembleMvariableStatement(mvariableStatement) } void -assembleMwhileStatement(mwhileStatement) - mwhileStatementBodyType *mwhileStatement; +assembleMwhileStatement(mwhileStatementBodyType *mwhileStatement) { bool saveListingOn; @@ -985,12 +908,10 @@ assembleMwhileStatement(mwhileStatement) } void -assembleOrgStatement(orgStatement) - orgStatementBodyType *orgStatement; +assembleOrgStatement(orgStatementBodyType *orgStatement) { valueType *orgAddress; bool saveExpansion; - valueType *evaluateExpression(); nullAssemble(orgStatement); targetOffset = 0; @@ -1015,11 +936,8 @@ assembleOrgStatement(orgStatement) } void -assemblePerformStatement(performStatement) - performStatementBodyType *performStatement; +assemblePerformStatement(performStatementBodyType *performStatement) { - void evaluateExpressionStandalone(); - nullAssemble(performStatement); sideEffectFlag = FALSE; evaluateExpressionStandalone(performStatement); @@ -1028,8 +946,7 @@ assemblePerformStatement(performStatement) } void -assembleRelStatement(relStatement) - relStatementBodyType *relStatement; +assembleRelStatement(relStatementBodyType *relStatement) { targetOffset = 0; if (!relocatableValue(¤tLocationCounter)) { @@ -1042,13 +959,8 @@ assembleRelStatement(relStatement) } void -assembleStartStatement(startStatement) - startStatementBodyType *startStatement; +assembleStartStatement(startStatementBodyType *startStatement) { - valueType *evaluateExpression(); - addressType addressValue(); - expressionType *generateFixupExpression(); - nullAssemble(startStatement); expand(moreText("start\t")); if (haveUserStartAddress) { @@ -1066,7 +978,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; } @@ -1074,13 +986,10 @@ assembleStartStatement(startStatement) } void -assembleStringStatement(stringStatement) - stringStatementBodyType *stringStatement; +assembleStringStatement(stringStatementBodyType *stringStatement) { valueType *byteValue; - valueType *evaluateExpression(); - nullAssemble(stringStatement); expand(moreText("string\t")); while (stringStatement != NULL) { @@ -1095,15 +1004,14 @@ assembleStringStatement(stringStatement) } qfree(byteValue); stringStatement = stringStatement->nextExpression; - expand((expandExpression(NULL), stringStatement != NULL ? + expand((expandExpression(NULL, NULL), stringStatement != NULL ? moreText(", ") : 0)); } expand(endLine()); } void -assembleStructStatement(structStatement) - structStatementBodyType *structStatement; +assembleStructStatement(structStatementBodyType *structStatement) { nullAssemble(structStatement); if (structStatement->structBody == NULL) @@ -1113,12 +1021,10 @@ assembleStructStatement(structStatement) } void -assembleTargetStatement(targetStatement) - targetStatementBodyType *targetStatement; +assembleTargetStatement(targetStatementBodyType *targetStatement) { valueType *targetAddress; bool saveExpansion; - valueType *evaluateExpression(); nullAssemble(targetStatement); targetOffset = 0; @@ -1138,11 +1044,8 @@ assembleTargetStatement(targetStatement) } void -assembleUndefineStatement(undefineStatement) - undefineStatementBodyType *undefineStatement; +assembleUndefineStatement(undefineStatementBodyType *undefineStatement) { - symbolTableEntryType *effectiveSymbol(); - expand(moreText("undefine\t")); while (undefineStatement != NULL) { expand(moreText("%s", symbName(undefineStatement->theSymbol))); @@ -1155,17 +1058,12 @@ assembleUndefineStatement(undefineStatement) } void -assembleVariableStatement(variableStatement) - variableStatementBodyType *variableStatement; +assembleVariableStatement(variableStatementBodyType *variableStatement) { symbolTableEntryType *newVariable; symbolInContextType *contextForVariable; int initCount; - symbolTableEntryType *effectiveSymbol(); - valueType *createArray(); - int expressionListLength(); - nullAssemble(variableStatement); newVariable = effectiveSymbol(variableStatement->theSymbol, &contextForVariable); @@ -1184,7 +1082,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); @@ -1206,8 +1104,7 @@ assembleVariableStatement(variableStatement) } void -assembleWhileStatement(whileStatement) - whileStatementBodyType *whileStatement; +assembleWhileStatement(whileStatementBodyType *whileStatement) { valueType topOfLoop; valueType fixupLocation[COMPOUND_BRANCH_MAX]; @@ -1238,20 +1135,17 @@ assembleWhileStatement(whileStatement) } void -assembleWordStatement(wordStatement) - wordStatementBodyType *wordStatement; +assembleWordStatement(wordStatementBodyType *wordStatement) { valueType *word; - valueType *evaluateExpression(); - nullAssemble(wordStatement); expand(moreText("word\t")); while (wordStatement != NULL) { 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); @@ -1261,13 +1155,7 @@ assembleWordStatement(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; @@ -1468,7 +1356,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);*/ @@ -1476,11 +1364,8 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, } void -assembleLabelList(labelList) - labelListType *labelList; +assembleLabelList(labelListType *labelList) { - valueType *newValue(); - while (labelList != NULL) { if (structNestingDepth == 0) valueLabel(labelList->theLabel, @@ -1495,10 +1380,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; @@ -1522,9 +1404,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); @@ -1543,8 +1426,7 @@ assembleStatement(statement, insideIf, ongoingFixupList) } void -eatStatement(statement) - statementType *statement; +eatStatement(statementType *statement) { if (debug) { printf("assembling:\n"); diff --git a/statementSemantics.h b/statementSemantics.h new file mode 100644 index 0000000..6ccbe59 --- /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 *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 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 *instructionStatement, 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); +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.c b/structSemantics.c index 3c8badb..4891775 100644 --- a/structSemantics.c +++ b/structSemantics.c @@ -29,11 +29,16 @@ #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" void -putStructFixups(base, fixups) - int base; - fixupListType *fixups; +putStructFixups(int base, fixupListType *fixups) { fixupListType *newFixup; @@ -54,9 +59,7 @@ putStructFixups(base, fixups) } void -putStructReferences(base, references) - int base; - expressionReferenceListType *references; +putStructReferences(int base, expressionReferenceListType *references) { expressionReferenceListType *newReference; int currentMode; @@ -80,15 +83,12 @@ putStructReferences(base, references) } void -instantiateStruct(structStatement) - structStatementBodyType *structStatement; +instantiateStruct(structStatementBodyType *structStatement) { int i; int base; symbolInContextType *context; - symbolInContextType *getWorkingContext(); - #define structInstance ((structInstanceType *) context->value->value) context = getWorkingContext(structStatement->structName); @@ -112,8 +112,7 @@ instantiateStruct(structStatement) } structInstanceType * -assembleStructDefinitionBody(structBody) - structBodyType *structBody; +assembleStructDefinitionBody(structBodyType *structBody) { int i; simpleFixupListType *dummy; @@ -128,7 +127,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); @@ -144,14 +143,11 @@ assembleStructDefinitionBody(structBody) } void -assembleStructDefinition(structStatement) - structStatementBodyType *structStatement; +assembleStructDefinition(structStatementBodyType *structStatement) { symbolTableEntryType *name; symbolInContextType *context; - symbolTableEntryType *effectiveSymbol(); - name = effectiveSymbol(structStatement->structName, &context); if (context == NULL) botch("struct definition doesn't have working context\n"); 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 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. */