Merge pull request #5 from michaelcmartin/ansi-c

Ansi C conversion
This commit is contained in:
Michael Steil 2016-01-25 07:35:52 -08:00
commit 4cc8c97be5
94 changed files with 2776 additions and 2734 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.o
*~
y.tab.c
y.tab.h
macross
slinky/slinky

View File

@ -7,23 +7,35 @@ PROC =6502
OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\
buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\
emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\ emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\
garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ garbage.o globals.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\
malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ object.o operandStuffSD.o parserMisc.o semanticMisc.o\
statementSemantics.o structSemantics.o tokenStrings.o statementSemantics.o structSemantics.o tokenStrings.o
SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\
buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\
debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\ debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\
expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ expressionSemantics.c fixups.c garbage.c globals.c initialize.c lexer.c listing.c\
lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ lookups.c macrossTables_$(PROC).c main.c object.c\
operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\
structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\
macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).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 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: .c.o:
cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) $*.c cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) $*.c
@ -37,43 +49,7 @@ macross: $(OBJECTS)
driver: driver.c driver: driver.c
cc $(CFLAGS) -o driver driver.c cc $(CFLAGS) -o driver driver.c
update: .mark macrossTypes.h: operandDefs_$(PROC).h operandBody_$(PROC).h\
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\
conditionDefs_$(PROC).h conditionDefs_$(PROC).h
actions.o: actions_$(PROC).c $(HEADERS) actions.o: actions_$(PROC).c $(HEADERS)
@ -86,7 +62,7 @@ buildStuff2.o: buildStuff2.c $(HEADERS)
buildStuff3.o: buildStuff3.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) builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS)
cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 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) emitStuff.o: emitStuff.c $(HEADERS)
cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) emitStuff.c 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) 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) fixups.o: fixups.c $(HEADERS)
@ -117,9 +93,9 @@ garbage.o: garbage.c y.tab.h $(HEADERS)
initialize.o: initialize.c $(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) 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 cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c
mv macrossTables_$(PROC).o macrossTables.o mv macrossTables_$(PROC).o macrossTables.o
malloc.o: malloc.c
main.o: main.c $(HEADERS) main.o: main.c $(HEADERS)
object.o: object.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 cc $(CFLAGS) -c -g -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c
mv operandStuffSD_$(PROC).o operandStuffSD.o 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) 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 cc $(CFLAGS) -c -g -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c
y.tab.c y.tab.h: macross_$(PROC).y y.tab.c y.tab.h: macross_$(PROC).y
yacc -d macross_$(PROC).y $(YACC) -d macross_$(PROC).y
y.output: 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 /bin/rm -f *.o y.output y.tab.c y.tab.h macross
love: love:

29
actions.h Normal file
View File

@ -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

View File

@ -30,6 +30,10 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "actions.h"
#include "emitStuff.h"
#include "errorStuff.h"
#include "semanticMisc.h"
#define operand (evaluatedOperands[0]) #define operand (evaluatedOperands[0])
#define address (evaluatedOperands[0])->value #define address (evaluatedOperands[0])->value
@ -45,11 +49,8 @@
and operand. and operand.
*/ */
void void
actionsDir1(opcode, numberOfOperands, evaluatedOperands) actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define ZERO_PAGE_ADDRESS_BIT 0x00 #define ZERO_PAGE_ADDRESS_BIT 0x00
#define NON_ZERO_PAGE_ADDRESS_BIT 0x08 #define NON_ZERO_PAGE_ADDRESS_BIT 0x08
@ -66,10 +67,7 @@ actionsDir1(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDir2(opcode, numberOfOperands, evaluatedOperands) actionsDir2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
if (wordCheck(address)) { if (wordCheck(address)) {
emitByte(binary); emitByte(binary);
@ -79,10 +77,7 @@ actionsDir2(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDirIndir(opcode, numberOfOperands, evaluatedOperands) actionsDirIndir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define DIRECT_ADDRESS_BIT 0x00 #define DIRECT_ADDRESS_BIT 0x00
#define INDIRECT_ADDRESS_BIT 0x20 #define INDIRECT_ADDRESS_BIT 0x20
@ -98,10 +93,7 @@ actionsDirIndir(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDirX1(opcode, numberOfOperands, evaluatedOperands) actionsDirX1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_X1 0x04 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_X1 0x04
#define A_REGISTER_BITS_X1 0x08 #define A_REGISTER_BITS_X1 0x08
@ -133,10 +125,7 @@ actionsDirX1(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDirX2(opcode, numberOfOperands, evaluatedOperands) actionsDirX2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_X2 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_X2 0x00
#define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_X2 0x08 #define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_X2 0x08
@ -165,10 +154,7 @@ actionsDirX2(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDirX3(opcode, numberOfOperands, evaluatedOperands) actionsDirX3(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
if (class == EXPRESSION_OPND) { if (class == EXPRESSION_OPND) {
if (isByteAddress(operand) && isDefined(operand)) { if (isByteAddress(operand) && isDefined(operand)) {
@ -189,10 +175,7 @@ actionsDirX3(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsDirY(opcode, numberOfOperands, evaluatedOperands) actionsDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_Y 0x00 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_Y 0x00
#define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_Y 0x08 #define DIRECT_ADDRESS_NON_ZERO_PAGE_BITS_Y 0x08
@ -217,10 +200,7 @@ actionsDirY(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsImmDir(opcode, numberOfOperands, evaluatedOperands) actionsImmDir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define IMMEDIATE_DATA_BITS_ID 0x00 #define IMMEDIATE_DATA_BITS_ID 0x00
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_ID 0x04 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_ID 0x04
@ -245,10 +225,7 @@ actionsImmDir(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsImmDirX(opcode, numberOfOperands, evaluatedOperands) actionsImmDirX(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define IMMEDIATE_DATA_BITS_IX 0x00 #define IMMEDIATE_DATA_BITS_IX 0x00
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_IX 0x04 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_IX 0x04
@ -284,10 +261,7 @@ actionsImmDirX(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsImmDirY(opcode, numberOfOperands, evaluatedOperands) actionsImmDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define IMMEDIATE_DATA_BITS_IY 0x00 #define IMMEDIATE_DATA_BITS_IY 0x00
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_IY 0x04 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_IY 0x04
@ -323,10 +297,7 @@ actionsImmDirY(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsImmIndex(opcode, numberOfOperands, evaluatedOperands) actionsImmIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
#define PRE_INDEXED_BITS_A 0x00 #define PRE_INDEXED_BITS_A 0x00
#define DIRECT_ADDRESS_ZERO_PAGE_BITS_A 0x04 #define DIRECT_ADDRESS_ZERO_PAGE_BITS_A 0x04
@ -383,10 +354,7 @@ actionsImmIndex(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsIndex(opcode, numberOfOperands, evaluatedOperands) actionsIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
if (class == EXPRESSION_OPND) { if (class == EXPRESSION_OPND) {
if (isByteAddress(operand) && isDefined(operand)) { if (isByteAddress(operand) && isDefined(operand)) {
@ -428,19 +396,13 @@ actionsIndex(opcode, numberOfOperands, evaluatedOperands)
} }
void void
actionsNone(opcode, numberOfOperands, evaluatedOperands) actionsNone(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
emitByte(binary); emitByte(binary);
} }
void void
actionsRelative(opcode, numberOfOperands, evaluatedOperands) actionsRelative(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
int offset; int offset;
@ -465,43 +427,37 @@ actionsRelative(opcode, numberOfOperands, evaluatedOperands)
*/ */
bool bool
isByte(value) isByte(int value)
int value;
{ {
return (-129<value && value<256); return (-129<value && value<256);
} }
bool bool
isByteOffset(value) isByteOffset(int value)
int value;
{ {
return (-129<value && value<128); return (-129<value && value<128);
} }
bool bool
isWordOffset(value) isWordOffset(int value)
int value;
{ {
return (-32769<value && value<32768); return (-32769<value && value<32768);
} }
bool bool
isByteAddress(value) isByteAddress(valueType *value)
valueType *value;
{ {
return(value->kindOfValue==ABSOLUTE_VALUE && isByte(value->value)); return(value->kindOfValue==ABSOLUTE_VALUE && isByte(value->value));
} }
bool bool
isWord(value) isWord(int value)
int value;
{ {
return (-32769<value && value<65536); return (-32769<value && value<65536);
} }
bool bool
byteCheck(value) byteCheck(int value)
int value;
{ {
if (isByte(value)) { if (isByte(value)) {
return(TRUE); return(TRUE);
@ -512,8 +468,7 @@ byteCheck(value)
} }
bool bool
wordCheck(value) wordCheck(int value)
int value;
{ {
if (isWord(value)) { if (isWord(value)) {
return(TRUE); return(TRUE);
@ -525,8 +480,7 @@ wordCheck(value)
} }
bool bool
isDefined(value) isDefined(valueType *value)
valueType *value;
{ {
return(value!=NULL && value->kindOfValue!=UNDEFINED_VALUE); return(value!=NULL && value->kindOfValue!=UNDEFINED_VALUE);
} }

80
buildStuff.h Normal file
View File

@ -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

View File

@ -32,15 +32,14 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "errorStuff.h"
symbolTableEntryType *lookupOrEnterSymbol(); #include "lookups.h"
char *saveString(); #include "parserMisc.h"
/* Generic routine to create statement nodes */ /* Generic routine to create statement nodes */
statementType *
newStatement(kind, body) statementType *
statementKindType kind; newStatement(statementKindType kind, statementBodyType body)
statementBodyType body;
{ {
statementType *result; statementType *result;
@ -62,17 +61,14 @@ newStatement(kind, body)
*/ */
statementType * statementType *
buildAlignStatement(expression) buildAlignStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(ALIGN_STATEMENT, return(newStatement(ALIGN_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildAssertStatement(condition, message) buildAssertStatement(expressionType *condition, expressionType *message)
expressionType *condition;
expressionType *message;
{ {
assertStatementBodyType *result; assertStatementBodyType *result;
@ -84,25 +80,21 @@ buildAssertStatement(condition, message)
} }
statementType * statementType *
buildBlockStatement(expressionList) buildBlockStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(BLOCK_STATEMENT, return(newStatement(BLOCK_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));
} }
statementType * statementType *
buildByteStatement(expressionList) buildByteStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(BYTE_STATEMENT, return(newStatement(BYTE_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));
} }
statementType * statementType *
buildConstrainStatement(expression, block) buildConstrainStatement(expressionType *expression, blockType *block)
expressionType *expression;
blockType *block;
{ {
constrainStatementBodyType *result; constrainStatementBodyType *result;
@ -114,17 +106,14 @@ buildConstrainStatement(expression, block)
} }
statementType * statementType *
buildDbyteStatement(expressionList) buildDbyteStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(DBYTE_STATEMENT, return(newStatement(DBYTE_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));
} }
statementType * statementType *
buildDefineStatement(name, value) buildDefineStatement(stringType *name, expressionType *value)
stringType *name;
expressionType *value;
{ {
defineStatementBodyType *result; defineStatementBodyType *result;
@ -135,9 +124,7 @@ buildDefineStatement(name, value)
} }
statementType * statementType *
buildDoUntilStatement(body, condition) buildDoUntilStatement(blockType *body, conditionType condition)
blockType *body;
conditionType condition;
{ {
doUntilStatementBodyType *result; doUntilStatementBodyType *result;
@ -148,9 +135,7 @@ buildDoUntilStatement(body, condition)
} }
statementType * statementType *
buildDoWhileStatement(body, condition) buildDoWhileStatement(blockType *body, conditionType condition)
blockType *body;
conditionType condition;
{ {
doWhileStatementBodyType *result; doWhileStatementBodyType *result;
@ -161,9 +146,7 @@ buildDoWhileStatement(body, condition)
} }
statementType * statementType *
buildDoStatement(body, end) buildDoStatement(blockType *body, doEndType *end)
blockType *body;
doEndType *end;
{ {
statementType *result; statementType *result;
@ -178,26 +161,21 @@ buildDoStatement(body, end)
} }
statementType * statementType *
buildExternStatement(identifierList) buildExternStatement(identifierListType *identifierList)
identifierListType *identifierList;
{ {
return(newStatement(EXTERN_STATEMENT, return(newStatement(EXTERN_STATEMENT,
(statementBodyType) identifierList)); (statementBodyType) identifierList));
} }
statementType * statementType *
buildFreturnStatement(expression) buildFreturnStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(FRETURN_STATEMENT, return(newStatement(FRETURN_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildFunctionStatement(name, arguments, body) buildFunctionStatement(stringType *name, argumentDefinitionListType *arguments, blockType *body)
stringType *name;
argumentDefinitionListType *arguments;
blockType *body;
{ {
functionStatementBodyType *result; functionStatementBodyType *result;
symbolTableEntryType *testSymbol; symbolTableEntryType *testSymbol;
@ -216,18 +194,14 @@ buildFunctionStatement(name, arguments, body)
} }
statementType * statementType *
buildGroupStatement(block) buildGroupStatement(blockType *block)
blockType *block;
{ {
return(newStatement(GROUP_STATEMENT, return(newStatement(GROUP_STATEMENT,
(statementBodyType) block)); (statementBodyType) block));
} }
statementType * statementType *
buildIfStatement(head, continuation, continuationKind) buildIfStatement(ifHeadType *head, ifContinuationType continuation, ifContinuationKindType continuationKind)
ifHeadType *head;
ifContinuationType continuation;
ifContinuationKindType continuationKind;
{ {
ifStatementBodyType *result; ifStatementBodyType *result;
@ -255,17 +229,14 @@ buildIfStatement(head, continuation, continuationKind)
} }
statementType * statementType *
buildIncludeStatement(filename) buildIncludeStatement(expressionType *filename)
expressionType *filename;
{ {
return(newStatement(INCLUDE_STATEMENT, return(newStatement(INCLUDE_STATEMENT,
(statementBodyType) filename)); (statementBodyType) filename));
} }
statementType * statementType *
buildInstructionStatement(opcode, operands) buildInstructionStatement(opcodeTableEntryType *opcode, operandListType *operands)
opcodeTableEntryType *opcode;
operandListType *operands;
{ {
instructionStatementBodyType *result; instructionStatementBodyType *result;
@ -277,18 +248,14 @@ buildInstructionStatement(opcode, operands)
} }
statementType * statementType *
buildLongStatement(expressionList) buildLongStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(LONG_STATEMENT, return(newStatement(LONG_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));
} }
statementType * statementType *
buildMacroStatement(macro, arguments, body) buildMacroStatement(macroTableEntryType *macro, argumentDefinitionListType *arguments, blockType *body)
macroTableEntryType *macro;
argumentDefinitionListType *arguments;
blockType *body;
{ {
macroStatementBodyType *result; macroStatementBodyType *result;
@ -300,9 +267,7 @@ buildMacroStatement(macro, arguments, body)
} }
statementType * statementType *
buildMacroInstructionStatement(macro, operands) buildMacroInstructionStatement(macroTableEntryType *macro, operandListType *operands)
macroTableEntryType *macro;
operandListType *operands;
{ {
instructionStatementBodyType *result; instructionStatementBodyType *result;
@ -314,9 +279,7 @@ buildMacroInstructionStatement(macro, operands)
} }
statementType * statementType *
buildMdefineStatement(name, value) buildMdefineStatement(stringType *name, expressionType *value)
stringType *name;
expressionType *value;
{ {
mdefineStatementBodyType *result; mdefineStatementBodyType *result;
@ -327,9 +290,7 @@ buildMdefineStatement(name, value)
} }
statementType * statementType *
buildMdoUntilStatement(body, condition) buildMdoUntilStatement(blockType *body, struct expressionTermStruct *condition)
blockType *body;
ExpressionType *condition;
{ {
mdoUntilStatementBodyType *result; mdoUntilStatementBodyType *result;
@ -340,9 +301,7 @@ buildMdoUntilStatement(body, condition)
} }
statementType * statementType *
buildMdoWhileStatement(body, condition) buildMdoWhileStatement(blockType *body, expressionType *condition)
blockType *body;
expressionType *condition;
{ {
mdoWhileStatementBodyType *result; mdoWhileStatementBodyType *result;
@ -353,26 +312,22 @@ buildMdoWhileStatement(body, condition)
} }
statementType * statementType *
buildMdoStatement(body, end) buildMdoStatement(blockType *body, mdoEndType *end)
blockType *body;
doEndType *end;
{ {
statementType *result; statementType *result;
if (end->doEndKind == UNTIL_END) if (end->mdoEndKind == UNTIL_END)
result = buildMdoUntilStatement(body, end->doEndCondition); result = buildMdoUntilStatement(body, end->mdoEndCondition);
else if (end->doEndKind == WHILE_END) else if (end->mdoEndKind == WHILE_END)
result = buildMdoWhileStatement(body, end->doEndCondition); result = buildMdoWhileStatement(body, end->mdoEndCondition);
else else
botch("bad mdo-end kind: %d\n", end->doEndCondition); botch("bad mdo-end kind: %d\n", end->mdoEndCondition);
qfree(end); qfree(end);
return(result); return(result);
} }
statementType * statementType *
buildMforStatement(forExpressions, body) buildMforStatement(forExpressionsType *forExpressions, blockType *body)
forExpressionsType *forExpressions;
blockType *body;
{ {
mforStatementBodyType *result; mforStatementBodyType *result;
@ -386,10 +341,7 @@ buildMforStatement(forExpressions, body)
} }
statementType * statementType *
buildMifStatement(head, continuation, continuationKind) buildMifStatement(mifHeadType *head, mifContinuationType continuation, ifContinuationKindType continuationKind)
mifHeadType *head;
mifContinuationType continuation;
ifContinuationKindType continuationKind;
{ {
mifStatementBodyType *result; mifStatementBodyType *result;
@ -417,9 +369,7 @@ buildMifStatement(head, continuation, continuationKind)
} }
statementType * statementType *
buildMswitchStatement(switchExpression, cases) buildMswitchStatement(expressionType *switchExpression, caseListType *cases)
expressionType *switchExpression;
caseListType *cases;
{ {
mswitchStatementBodyType *result; mswitchStatementBodyType *result;
@ -430,10 +380,7 @@ buildMswitchStatement(switchExpression, cases)
} }
statementType * statementType *
buildMvariableStatement(name, value, dimension) buildMvariableStatement(stringType *name, expressionListType *value, expressionType *dimension)
stringType *name;
expressionListType *value;
expressionType *dimension;
{ {
mvariableStatementBodyType *result; mvariableStatementBodyType *result;
@ -445,9 +392,7 @@ buildMvariableStatement(name, value, dimension)
} }
statementType * statementType *
buildMwhileStatement(condition, body) buildMwhileStatement(expressionType *condition, blockType *body)
expressionType *condition;
blockType *body;
{ {
mwhileStatementBodyType *result; mwhileStatementBodyType *result;
@ -458,53 +403,47 @@ buildMwhileStatement(condition, body)
} }
statementType * statementType *
buildNullStatement() buildNullStatement(void)
{ {
return(newStatement(NULL_STATEMENT, (statementBodyType){ .ifUnion = NULL })); return(newStatement(NULL_STATEMENT, (statementBodyType){ .ifUnion = NULL }));
} }
statementType * statementType *
buildOrgStatement(expression) buildOrgStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(ORG_STATEMENT, return(newStatement(ORG_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildPerformStatement(expression) buildPerformStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(PERFORM_STATEMENT, return(newStatement(PERFORM_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildRelStatement() buildRelStatement(void)
{ {
return(newStatement(REL_STATEMENT, (statementBodyType){ .ifUnion = NULL })); return(newStatement(REL_STATEMENT, (statementBodyType){ .ifUnion = NULL }));
} }
statementType * statementType *
buildStartStatement(expression) buildStartStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(START_STATEMENT, return(newStatement(START_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildStringStatement(expressionList) buildStringStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(STRING_STATEMENT, return(newStatement(STRING_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));
} }
statementType * statementType *
buildStructStatement(name, body) buildStructStatement(symbolTableEntryType *name, blockType *body)
symbolTableEntryType *name;
blockType *body;
{ {
structStatementBodyType *result; structStatementBodyType *result;
@ -515,26 +454,21 @@ buildStructStatement(name, body)
} }
statementType * statementType *
buildTargetStatement(expression) buildTargetStatement(expressionType *expression)
expressionType *expression;
{ {
return(newStatement(TARGET_STATEMENT, return(newStatement(TARGET_STATEMENT,
(statementBodyType) expression)); (statementBodyType) expression));
} }
statementType * statementType *
buildUndefineStatement(identifierList) buildUndefineStatement(identifierListType *identifierList)
identifierListType *identifierList;
{ {
return(newStatement(UNDEFINE_STATEMENT, return(newStatement(UNDEFINE_STATEMENT,
(statementBodyType) identifierList)); (statementBodyType) identifierList));
} }
statementType * statementType *
buildVariableStatement(name, value, dimension) buildVariableStatement(stringType *name, expressionListType *value, expressionType *dimension)
stringType *name;
expressionListType *value;
expressionType *dimension;
{ {
variableStatementBodyType *result; variableStatementBodyType *result;
@ -546,9 +480,7 @@ buildVariableStatement(name, value, dimension)
} }
statementType * statementType *
buildWhileStatement(condition, body) buildWhileStatement(conditionType condition, blockType *body)
conditionType condition;
blockType *body;
{ {
whileStatementBodyType *result; whileStatementBodyType *result;
@ -559,8 +491,7 @@ buildWhileStatement(condition, body)
} }
statementType * statementType *
buildWordStatement(expressionList) buildWordStatement(expressionListType *expressionList)
expressionListType *expressionList;
{ {
return(newStatement(WORD_STATEMENT, return(newStatement(WORD_STATEMENT,
(statementBodyType) expressionList)); (statementBodyType) expressionList));

View File

@ -32,6 +32,8 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "lookups.h"
#include "parserMisc.h"
/* /*
These are all the miscellaneous routines for building pieces of parse-tree These are all the miscellaneous routines for building pieces of parse-tree
@ -40,11 +42,8 @@
/* Fragments of statement structures */ /* Fragments of statement structures */
caseType * caseType *
buildCase(caseTags, caseBody) buildCase(expressionListType *caseTags, blockType *caseBody)
expressionListType *caseTags;
blockType *caseBody;
{ {
caseType *result; caseType *result;
@ -55,9 +54,7 @@ buildCase(caseTags, caseBody)
} }
doEndType * doEndType *
buildDoEnd(condition, kindOfDoEnd) buildDoEnd(conditionType condition, doEndKindType kindOfDoEnd)
conditionType condition;
doEndKindType kindOfDoEnd;
{ {
doEndType *result; doEndType *result;
@ -68,10 +65,7 @@ buildDoEnd(condition, kindOfDoEnd)
} }
forExpressionsType * forExpressionsType *
buildForExpressions(initExpression, testExpression, incrExpression) buildForExpressions(expressionType *initExpression, expressionType *testExpression, expressionType *incrExpression)
expressionType *initExpression;
expressionType *testExpression;
expressionType *incrExpression;
{ {
forExpressionsType *result; forExpressionsType *result;
@ -83,9 +77,7 @@ buildForExpressions(initExpression, testExpression, incrExpression)
} }
ifHeadType * ifHeadType *
buildIfHead(condition, block) buildIfHead(conditionType condition, blockType *block)
conditionType condition;
blockType *block;
{ {
ifHeadType *result; ifHeadType *result;
@ -96,9 +88,7 @@ buildIfHead(condition, block)
} }
mdoEndType * mdoEndType *
buildMdoEnd(condition, kindOfMdoEnd) buildMdoEnd(expressionType *condition, doEndKindType kindOfMdoEnd)
expressionType *condition;
doEndKindType kindOfMdoEnd;
{ {
mdoEndType *result; mdoEndType *result;
@ -110,9 +100,7 @@ buildMdoEnd(condition, kindOfMdoEnd)
mifHeadType * mifHeadType *
buildMifHead(condition, block) buildMifHead(expressionType *condition, blockType *block)
expressionType *condition;
blockType *block;
{ {
mifHeadType *result; mifHeadType *result;
@ -126,9 +114,7 @@ buildMifHead(condition, block)
/* Fragments of expression structures */ /* Fragments of expression structures */
arrayTermType * arrayTermType *
buildArrayTerm(array, index) buildArrayTerm(expressionType *array, expressionType *index)
expressionType *array;
expressionType *index;
{ {
arrayTermType *result; arrayTermType *result;
@ -139,10 +125,7 @@ buildArrayTerm(array, index)
} }
binopTermType * binopTermType *
buildBinopTerm(binop, leftArgument, rightArgument) buildBinopTerm(binopKindType binop, expressionType *leftArgument, expressionType *rightArgument)
binopKindType binop;
expressionType *leftArgument;
expressionType *rightArgument;
{ {
binopTermType *result; binopTermType *result;
@ -154,12 +137,9 @@ buildBinopTerm(binop, leftArgument, rightArgument)
} }
functionCallTermType * functionCallTermType *
buildFunctionCall(functionName, arguments) buildFunctionCall(stringType *functionName, operandListType *arguments)
stringType *functionName;
operandListType *arguments;
{ {
functionCallTermType *result; functionCallTermType *result;
symbolTableEntryType *lookupOrEnterSymbol();
result = typeAlloc(functionCallTermType); result = typeAlloc(functionCallTermType);
result->functionName = lookupOrEnterSymbol(functionName, result->functionName = lookupOrEnterSymbol(functionName,
@ -169,9 +149,7 @@ buildFunctionCall(functionName, arguments)
} }
postOpTermType * postOpTermType *
buildPostOpTerm(postOp, postOpArgument) buildPostOpTerm(postOpKindType postOp, expressionType *postOpArgument)
postOpKindType postOp;
expressionType *postOpArgument;
{ {
postOpTermType *result; postOpTermType *result;
@ -182,9 +160,7 @@ buildPostOpTerm(postOp, postOpArgument)
} }
preOpTermType * preOpTermType *
buildPreOpTerm(preOp, preOpArgument) buildPreOpTerm(preOpKindType preOp, expressionType *preOpArgument)
preOpKindType preOp;
expressionType *preOpArgument;
{ {
preOpTermType *result; preOpTermType *result;
@ -195,9 +171,7 @@ buildPreOpTerm(preOp, preOpArgument)
} }
unopTermType * unopTermType *
buildUnopTerm(unop, unopArgument) buildUnopTerm(unopKindType unop, expressionType *unopArgument)
unopKindType unop;
expressionType *unopArgument;
{ {
unopTermType *result; unopTermType *result;
@ -208,16 +182,10 @@ buildUnopTerm(unop, unopArgument)
} }
expressionTermType * expressionTermType *
buildExpressionTerm(kindOfExpressionTerm, arg1, arg2, arg3) buildExpressionTerm(expressionTermKindType kindOfExpressionTerm, anyOldThing *arg1, anyOldThing *arg2, anyOldThing *arg3)
expressionTermKindType kindOfExpressionTerm;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
expressionType *result; expressionType *result;
symbolTableEntryType *lookupOrEnterSymbol();
result = typeAlloc(expressionType); result = typeAlloc(expressionType);
result->kindOfTerm = kindOfExpressionTerm; result->kindOfTerm = kindOfExpressionTerm;
switch (kindOfExpressionTerm) { switch (kindOfExpressionTerm) {
@ -298,11 +266,9 @@ buildExpressionTerm(kindOfExpressionTerm, arg1, arg2, arg3)
/* Other stuff */ /* Other stuff */
macroTableEntryType * macroTableEntryType *
buildMacroTableEntry(name) buildMacroTableEntry(stringType *name)
stringType *name;
{ {
macroTableEntryType *result; macroTableEntryType *result;
char *saveString();
result = typeAlloc(macroTableEntryType); result = typeAlloc(macroTableEntryType);
result->macroName = saveString(name); result->macroName = saveString(name);
@ -313,12 +279,9 @@ buildMacroTableEntry(name)
} }
symbolTableEntryType * symbolTableEntryType *
buildSymbolTableEntry(name, usage) buildSymbolTableEntry(stringType *name, symbolUsageKindType usage)
stringType *name;
symbolUsageKindType usage;
{ {
symbolTableEntryType *result; symbolTableEntryType *result;
char *saveString();
result = typeAlloc(symbolTableEntryType); result = typeAlloc(symbolTableEntryType);
result->symbolName = saveString(name); result->symbolName = saveString(name);
@ -335,10 +298,7 @@ buildSymbolTableEntry(name, usage)
} }
codeBreakType * codeBreakType *
buildCodeBreak(kind, address, data) buildCodeBreak(codeBreakKindType kind, addressType address, int data)
codeBreakKindType kind;
addressType address;
int data;
{ {
codeBreakType *result; codeBreakType *result;
@ -351,10 +311,7 @@ buildCodeBreak(kind, address, data)
} }
reservationListType * reservationListType *
buildReservation(startAddress, blockSize, nextReservation) buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation)
addressType startAddress;
int blockSize;
reservationListType *nextReservation;
{ {
reservationListType *result; reservationListType *result;
@ -366,9 +323,7 @@ buildReservation(startAddress, blockSize, nextReservation)
} }
simpleFixupListType * simpleFixupListType *
buildSimpleFixupList(locationToFixup, previousList) buildSimpleFixupList(valueType locationToFixup, simpleFixupListType *previousList)
valueType locationToFixup;
simpleFixupListType *previousList;
{ {
simpleFixupListType *result; simpleFixupListType *result;

View File

@ -31,6 +31,7 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "lookups.h"
/* /*
These routines all build list-type structures. Since yacc likes to build These routines all build list-type structures. Since yacc likes to build
@ -43,14 +44,10 @@
*/ */
argumentListHeadType * argumentListHeadType *
buildArgumentList(new, rest, arrayTag) buildArgumentList(stringType *new, argumentListHeadType *rest, bool arrayTag)
stringType *new;
argumentListHeadType *rest;
bool arrayTag;
{ {
argumentListHeadType *newListHead; argumentListHeadType *newListHead;
argumentDefinitionListType *newArgument; argumentDefinitionListType *newArgument;
symbolTableEntryType *lookupOrEnterSymbol();
if (rest == NULL) { if (rest == NULL) {
newListHead = typeAlloc(argumentListHeadType); newListHead = typeAlloc(argumentListHeadType);
@ -76,9 +73,7 @@ buildArgumentList(new, rest, arrayTag)
} }
caseListHeadType * caseListHeadType *
buildCaseList(new, rest) buildCaseList(caseType *new, caseListHeadType *rest)
caseType *new;
caseListHeadType *rest;
{ {
caseListHeadType *newListHead; caseListHeadType *newListHead;
caseListType *newCase; caseListType *newCase;
@ -103,9 +98,7 @@ buildCaseList(new, rest)
} }
expressionListHeadType * expressionListHeadType *
buildExpressionList(new, rest) buildExpressionList(expressionType *new, expressionListHeadType *rest)
expressionType *new;
expressionListHeadType *rest;
{ {
expressionListHeadType *newListHead; expressionListHeadType *newListHead;
expressionListType *newListEntry; expressionListType *newListEntry;
@ -130,16 +123,11 @@ buildExpressionList(new, rest)
} }
identifierListHeadType * identifierListHeadType *
buildIdentifierList(new, rest, usage) buildIdentifierList(stringType *new, identifierListHeadType *rest, symbolUsageKindType usage)
stringType *new;
identifierListHeadType *rest;
symbolUsageKindType usage;
{ {
identifierListType *newListEntry; identifierListType *newListEntry;
identifierListHeadType *newListHead; identifierListHeadType *newListHead;
symbolTableEntryType *lookupOrEnterSymbol();
if (rest == NULL) { if (rest == NULL) {
newListHead = typeAlloc(identifierListHeadType); newListHead = typeAlloc(identifierListHeadType);
newListHead->theSymbol = lookupOrEnterSymbol(new, usage); newListHead->theSymbol = lookupOrEnterSymbol(new, usage);
@ -160,9 +148,7 @@ buildIdentifierList(new, rest, usage)
} }
labelListHeadType * labelListHeadType *
buildLabelList(new, rest) buildLabelList(symbolTableEntryType *new, labelListHeadType *rest)
symbolTableEntryType *new;
labelListHeadType *rest;
{ {
labelListHeadType *newLabelHead; labelListHeadType *newLabelHead;
labelListType *newLabel; labelListType *newLabel;
@ -187,9 +173,7 @@ buildLabelList(new, rest)
} }
operandListHeadType * operandListHeadType *
buildOperandList(new, rest) buildOperandList(operandType *new, operandListHeadType *rest)
operandType *new;
operandListHeadType *rest;
{ {
operandListHeadType *newListHead; operandListHeadType *newListHead;
@ -213,17 +197,13 @@ buildOperandList(new, rest)
} }
selectionListHeadType * selectionListHeadType *
buildSelectionList(new, rest) buildSelectionList(selectionListType *new, selectionListHeadType *rest)
selectionListType *new;
selectionListHeadType *rest;
{ {
return((selectionListHeadType *) buildIdentifierList(new, rest)); return((selectionListHeadType *) buildIdentifierList(new, rest, unknownSymbolTag /* random guess */));
} }
statementListHeadType * statementListHeadType *
buildStatementList(new, rest) buildStatementList(statementType *new, statementListHeadType *rest)
statementType *new;
statementListHeadType *rest;
{ {
statementListHeadType *newListHead; statementListHeadType *newListHead;

View File

@ -30,61 +30,62 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include <strings.h> #include "buildStuff.h"
#include "errorStuff.h"
#include "expressionSemantics.h"
#include "garbage.h"
#include "lexer.h"
#include "lookups.h"
#include "operandStuff.h"
#include "semanticMisc.h"
#include "statementSemantics.h"
#include <string.h>
/* /*
Helper routines to return values into the Macross expression evaluation Helper routines to return values into the Macross expression evaluation
environment environment
*/ */
valueType * valueType *
makeBooleanValue(test) makeBooleanValue(int test)
int test;
{ {
valueType *newValue();
return(newValue(ABSOLUTE_VALUE, test!=0, EXPRESSION_OPND)); return(newValue(ABSOLUTE_VALUE, test!=0, EXPRESSION_OPND));
} }
valueType * valueType *
makeFailureValue() makeFailureValue(void)
{ {
valueType *newValue();
return(newValue(FAIL, 0, EXPRESSION_OPND)); return(newValue(FAIL, 0, EXPRESSION_OPND));
} }
valueType * valueType *
makeIntegerValue(integer) makeIntegerValue(int integer)
int integer;
{ {
valueType *newValue();
return(newValue(ABSOLUTE_VALUE, integer, EXPRESSION_OPND)); return(newValue(ABSOLUTE_VALUE, integer, EXPRESSION_OPND));
} }
valueType * valueType *
makeOperandValue(operand) makeOperandValue(operandType *operand)
operandType *operand;
{ {
valueType *newValue();
return(newValue(OPERAND_VALUE, operand, EXPRESSION_OPND)); return(newValue(OPERAND_VALUE, operand, EXPRESSION_OPND));
} }
valueType * valueType *
makeStringValue(string) makeStringValue(stringType *string)
stringType *string;
{ {
valueType *newValue();
return(newValue(STRING_VALUE, string, STRING_OPND)); return(newValue(STRING_VALUE, string, STRING_OPND));
} }
valueType * valueType *
makeUndefinedValue() makeUndefinedValue(void)
{ {
valueType *newValue();
return(newValue(UNDEFINED_VALUE, 0, EXPRESSION_OPND)); return(newValue(UNDEFINED_VALUE, 0, EXPRESSION_OPND));
} }
@ -99,16 +100,13 @@ makeUndefinedValue()
/* Return internal address mode of an operand */ /* Return internal address mode of an operand */
valueType * valueType *
addressModeBIF(parameterList, kindOfFixup) addressModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(evaluatedParameter->addressMode)); return(makeIntegerValue(evaluatedParameter->addressMode));
} else { } else {
return(makeIntegerValue(-1)); return(makeIntegerValue(-1));
@ -117,22 +115,17 @@ addressModeBIF(parameterList, kindOfFixup)
/* Call a macro where the macro name is obtained dynamically from a string */ /* Call a macro where the macro name is obtained dynamically from a string */
valueType * valueType *
applyBIF(parameterList, kindOfFixup) applyBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *macroToLookup; stringType *macroToLookup;
macroTableEntryType *macroToCall; macroTableEntryType *macroToCall;
macroTableEntryType *lookupMacroName();
valueType *evaluateOperand();
if (parameterList == NULL) { if (parameterList == NULL) {
error(NO_ARGUMENTS_TO_BIF_ERROR, "apply"); error(NO_ARGUMENTS_TO_BIF_ERROR, "apply");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "apply"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "apply");
return(makeFailureValue()); return(makeFailureValue());
@ -149,16 +142,13 @@ applyBIF(parameterList, kindOfFixup)
/* return the length of an array */ /* return the length of an array */
valueType * valueType *
arrayLengthBIF(parameterList, kindOfFixup) arrayLengthBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *testObjectValue; valueType *testObjectValue;
valueType *evaluateOperand();
if (parameterList == NULL) if (parameterList == NULL)
return(makeIntegerValue(0)); return(makeIntegerValue(0));
testObjectValue = evaluateOperand(parameterList, NO_FIXUP_OK); testObjectValue = evaluateOperand(parameterList);
if (testObjectValue->kindOfValue == STRING_VALUE) { if (testObjectValue->kindOfValue == STRING_VALUE) {
return(makeIntegerValue(strlen(testObjectValue->value))); return(makeIntegerValue(strlen(testObjectValue->value)));
} else if (testObjectValue->kindOfValue == ARRAY_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 */ /* Convert a string to ATASCII */
valueType * valueType *
atasciiBIF(parameterList, kindOfFixup) atasciiBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
int i; int i;
valueType *stringValue; valueType *stringValue;
stringType *string; stringType *string;
stringType *newString; stringType *newString;
valueType *evaluateOperand();
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue("")); return(makeStringValue(""));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "atascii"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "atascii");
return(makeFailureValue()); return(makeFailureValue());
@ -220,9 +207,7 @@ atasciiBIF(parameterList, kindOfFixup)
/* Convert a string to ATASCII while setting high-order color bits */ /* Convert a string to ATASCII while setting high-order color bits */
valueType * valueType *
atasciiColorBIF(parameterList, kindOfFixup) atasciiColorBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
int i; int i;
valueType *stringValue; valueType *stringValue;
@ -232,16 +217,15 @@ atasciiColorBIF(parameterList, kindOfFixup)
stringType *newString; stringType *newString;
byte testChar; byte testChar;
valueType *evaluateOperand();
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue("")); return(makeStringValue(""));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
if (parameterList == NULL) { if (parameterList == NULL) {
color = 0; color = 0;
} else { } else {
colorValue = evaluateOperand(parameterList, NO_FIXUP); colorValue = evaluateOperand(parameterList);
if (colorValue->kindOfValue != ABSOLUTE_VALUE) { if (colorValue->kindOfValue != ABSOLUTE_VALUE) {
error(BAD_COLOR_ARGUMENT_TO_ATASCII_COLOR_ERROR); error(BAD_COLOR_ARGUMENT_TO_ATASCII_COLOR_ERROR);
return(makeFailureValue()); return(makeFailureValue());
@ -270,18 +254,14 @@ atasciiColorBIF(parameterList, kindOfFixup)
/* Turn debug mode off and on */ /* Turn debug mode off and on */
valueType * valueType *
debugModeOffBIF(parameterList, kindOfFixup) debugModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
debug = FALSE; debug = FALSE;
return(makeBooleanValue(FALSE)); return(makeBooleanValue(FALSE));
} }
valueType * valueType *
debugModeOnBIF(parameterList, kindOfFixup) debugModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
debug = TRUE; debug = TRUE;
return(makeBooleanValue(TRUE)); return(makeBooleanValue(TRUE));
@ -289,18 +269,14 @@ debugModeOnBIF(parameterList, kindOfFixup)
/* Turn display of code emission off and on */ /* Turn display of code emission off and on */
valueType * valueType *
emitModeOffBIF(parameterList, kindOfFixup) emitModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
emitPrint = FALSE; emitPrint = FALSE;
return(makeBooleanValue(FALSE)); return(makeBooleanValue(FALSE));
} }
valueType * valueType *
emitModeOnBIF(parameterList, kindOfFixup) emitModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
emitPrint = TRUE; emitPrint = TRUE;
return(makeBooleanValue(TRUE)); return(makeBooleanValue(TRUE));
@ -308,16 +284,13 @@ emitModeOnBIF(parameterList, kindOfFixup)
/* Check if an operand is absolute (as opposed to relocatable) */ /* Check if an operand is absolute (as opposed to relocatable) */
valueType * valueType *
isAbsoluteValueBIF(parameterList, kindOfFixup) isAbsoluteValueBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
ABSOLUTE_VALUE)); ABSOLUTE_VALUE));
} else { } else {
@ -327,16 +300,15 @@ isAbsoluteValueBIF(parameterList, kindOfFixup)
/* Check if operand is code block */ /* Check if operand is code block */
valueType * valueType *
isBlockBIF(parameterList, kindOfFixup) /* questionable */ isBlockBIF(operandListType *parameterList, fixupKindType kindOfFixup) /* questionable */
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
BLOCK_VALUE)); BLOCK_VALUE));
} else { } else {
@ -346,16 +318,13 @@ isBlockBIF(parameterList, kindOfFixup) /* questionable */
/* Check if operand is a BIF */ /* Check if operand is a BIF */
valueType * valueType *
isBuiltInFunctionBIF(parameterList, kindOfFixup) isBuiltInFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
BUILT_IN_FUNCTION_VALUE)); BUILT_IN_FUNCTION_VALUE));
} else { } else {
@ -365,16 +334,13 @@ isBuiltInFunctionBIF(parameterList, kindOfFixup)
/* Check if operand is a condition code */ /* Check if operand is a condition code */
valueType * valueType *
isConditionCodeBIF(parameterList, kindOfFixup) isConditionCodeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
CONDITION_VALUE)); CONDITION_VALUE));
} else { } else {
@ -384,16 +350,11 @@ isConditionCodeBIF(parameterList, kindOfFixup)
/* Check if a symbol is defined */ /* Check if a symbol is defined */
valueType * valueType *
isDefinedBIF(parameterList, kindOfFixup) isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
expressionType *expression; expressionType *expression;
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
symbolTableEntryType *effectiveSymbol();
if (parameterList != NULL) { if (parameterList != NULL) {
if (parameterList->kindOfOperand == EXPRESSION_OPND && if (parameterList->kindOfOperand == EXPRESSION_OPND &&
(expression = parameterList->theOperand. (expression = parameterList->theOperand.
@ -419,15 +380,11 @@ isDefinedBIF(parameterList, kindOfFixup)
/* Check if a symbol is externally visible */ /* Check if a symbol is externally visible */
valueType * valueType *
isExternalBIF(parameterList, kindOfFixup) isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
expressionType *expression; expressionType *expression;
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
if (parameterList != NULL && parameterList->kindOfOperand == if (parameterList != NULL && parameterList->kindOfOperand ==
EXPRESSION_OPND) { EXPRESSION_OPND) {
expression = parameterList->theOperand.expressionUnion; expression = parameterList->theOperand.expressionUnion;
@ -442,16 +399,13 @@ isExternalBIF(parameterList, kindOfFixup)
/* Check if an operand is a struct field */ /* Check if an operand is a struct field */
valueType * valueType *
isFieldBIF(parameterList, kindOfFixup) isFieldBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
FIELD_VALUE)); FIELD_VALUE));
} else { } else {
@ -461,16 +415,13 @@ isFieldBIF(parameterList, kindOfFixup)
/* Check if an operand is a user-defined function */ /* Check if an operand is a user-defined function */
valueType * valueType *
isFunctionBIF(parameterList, kindOfFixup) isFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
FUNCTION_VALUE)); FUNCTION_VALUE));
} else { } else {
@ -480,16 +431,13 @@ isFunctionBIF(parameterList, kindOfFixup)
/* Check if an operand value is relocatable */ /* Check if an operand value is relocatable */
valueType * valueType *
isRelocatableValueBIF(parameterList, kindOfFixup) isRelocatableValueBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
RELOCATABLE_VALUE || evaluatedParameter-> RELOCATABLE_VALUE || evaluatedParameter->
kindOfValue == DATA_VALUE)); kindOfValue == DATA_VALUE));
@ -500,16 +448,13 @@ isRelocatableValueBIF(parameterList, kindOfFixup)
/* Check if an operand is a string */ /* Check if an operand is a string */
valueType * valueType *
isStringBIF(parameterList, kindOfFixup) isStringBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
STRING_VALUE)); STRING_VALUE));
} else { } else {
@ -519,16 +464,13 @@ isStringBIF(parameterList, kindOfFixup)
/* Check if an operand is a struct */ /* Check if an operand is a struct */
valueType * valueType *
isStructBIF(parameterList, kindOfFixup) isStructBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->kindOfValue == return(makeBooleanValue(evaluatedParameter->kindOfValue ==
STRUCT_VALUE)); STRUCT_VALUE));
} else { } else {
@ -538,9 +480,7 @@ isStructBIF(parameterList, kindOfFixup)
/* Check if an operand is a symbol */ /* Check if an operand is a symbol */
valueType * valueType *
isSymbolBIF(parameterList, kindOfFixup) isSymbolBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
expressionType *expression; expressionType *expression;
@ -556,9 +496,7 @@ isSymbolBIF(parameterList, kindOfFixup)
/* Turn listing off and on */ /* Turn listing off and on */
valueType * valueType *
listingOffBIF(parameterList, kindOfFixup) listingOffBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
if (listingOn) { if (listingOn) {
if (!listingControlCounter) if (!listingControlCounter)
@ -569,9 +507,7 @@ listingOffBIF(parameterList, kindOfFixup)
} }
valueType * valueType *
listingOnBIF(parameterList, kindOfFixup) listingOnBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
if (listingOn) { if (listingOn) {
if (--listingControlCounter < 0) { if (--listingControlCounter < 0) {
@ -590,9 +526,7 @@ listingOnBIF(parameterList, kindOfFixup)
/* Generate an array on the fly */ /* Generate an array on the fly */
valueType * valueType *
makeArrayBIF(parameterList, kindOfFixup) makeArrayBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *lengthValue; valueType *lengthValue;
int length; int length;
@ -604,7 +538,7 @@ makeArrayBIF(parameterList, kindOfFixup)
error(NO_ARGUMENTS_TO_BIF_ERROR, "makeArray"); error(NO_ARGUMENTS_TO_BIF_ERROR, "makeArray");
return(makeFailureValue()); return(makeFailureValue());
} }
lengthValue = evaluateOperand(parameterList, NO_FIXUP); lengthValue = evaluateOperand(parameterList);
if (lengthValue->kindOfValue != ABSOLUTE_VALUE) { if (lengthValue->kindOfValue != ABSOLUTE_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR,
"makeArray", 1); "makeArray", 1);
@ -619,8 +553,7 @@ makeArrayBIF(parameterList, kindOfFixup)
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
for (i=0; i<length; ++i) { for (i=0; i<length; ++i) {
if (parameterList != NULL) { if (parameterList != NULL) {
arrayContents[i] = evaluateOperand(parameterList, arrayContents[i] = evaluateOperand(parameterList);
NO_FIXUP);
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
} else { } else {
arrayContents[i] = NULL; arrayContents[i] = NULL;
@ -635,20 +568,17 @@ makeArrayBIF(parameterList, kindOfFixup)
/* Return the Nth character of a string (as an integer) */ /* Return the Nth character of a string (as an integer) */
valueType * valueType *
nthCharBIF(parameterList, kindOfFixup) nthCharBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *positionValue; valueType *positionValue;
int position; int position;
valueType *stringValue; valueType *stringValue;
stringType *string; stringType *string;
valueType *evaluateOperand();
if (parameterList == NULL) if (parameterList == NULL)
return(makeFailureValue()); return(makeFailureValue());
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "nthChar"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "nthChar");
return(makeFailureValue()); return(makeFailureValue());
@ -657,7 +587,7 @@ nthCharBIF(parameterList, kindOfFixup)
if (parameterList == NULL) { if (parameterList == NULL) {
position = 0; position = 0;
} else { } else {
positionValue = evaluateOperand(parameterList, NO_FIXUP); positionValue = evaluateOperand(parameterList);
if (positionValue->kindOfValue != ABSOLUTE_VALUE) { if (positionValue->kindOfValue != ABSOLUTE_VALUE) {
error(BAD_POSITION_ARGUMENT_TO_NTH_CHAR_ERROR); error(BAD_POSITION_ARGUMENT_TO_NTH_CHAR_ERROR);
return(makeFailureValue()); return(makeFailureValue());
@ -675,9 +605,7 @@ nthCharBIF(parameterList, kindOfFixup)
/* Pass stuff through to stdio's 'printf' function */ /* Pass stuff through to stdio's 'printf' function */
valueType * valueType *
printfBIF(parameterList, kindOfFixup) printfBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
stringType *formatString; stringType *formatString;
valueType *stringValue; valueType *stringValue;
@ -685,11 +613,10 @@ printfBIF(parameterList, kindOfFixup)
int argument[20]; int argument[20];
valueType *result; valueType *result;
valueType *evaluateOperand();
result = makeFailureValue(); result = makeFailureValue();
if (parameterList != NULL) { if (parameterList != NULL) {
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(PRINTF_FORMAT_IS_NOT_A_STRING_ERROR); error(PRINTF_FORMAT_IS_NOT_A_STRING_ERROR);
return(result); return(result);
@ -699,7 +626,7 @@ printfBIF(parameterList, kindOfFixup)
argumentCount = 0; argumentCount = 0;
while (parameterList != NULL && argumentCount < 20) { while (parameterList != NULL && argumentCount < 20) {
argument[argumentCount++] = evaluateOperand( argument[argumentCount++] = evaluateOperand(
parameterList)->value; parameterList)->value;
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
} }
/* cretinous hack */ /* cretinous hack */
@ -715,9 +642,7 @@ printfBIF(parameterList, kindOfFixup)
/* Concatenate two strings */ /* Concatenate two strings */
valueType * valueType *
strcatBIF(parameterList, kindOfFixup) strcatBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *string1; stringType *string1;
@ -726,7 +651,7 @@ strcatBIF(parameterList, kindOfFixup)
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue("")); return(makeStringValue(""));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 1); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 1);
return(makeFailureValue()); return(makeFailureValue());
@ -735,7 +660,7 @@ strcatBIF(parameterList, kindOfFixup)
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue(string1)); return(makeStringValue(string1));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 2); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcat", 2);
return(makeFailureValue()); return(makeFailureValue());
@ -749,9 +674,7 @@ strcatBIF(parameterList, kindOfFixup)
/* Compare two strings */ /* Compare two strings */
valueType * valueType *
strcmpBIF(parameterList, kindOfFixup) strcmpBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *string1; stringType *string1;
@ -762,7 +685,7 @@ strcmpBIF(parameterList, kindOfFixup)
error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmp"); error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmp");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 1); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 1);
return(makeFailureValue()); return(makeFailureValue());
@ -771,7 +694,7 @@ strcmpBIF(parameterList, kindOfFixup)
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue(string1)); return(makeStringValue(string1));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 2); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmp", 2);
return(makeFailureValue()); return(makeFailureValue());
@ -782,9 +705,7 @@ strcmpBIF(parameterList, kindOfFixup)
/* Compare two strings in a case-independent fashion */ /* Compare two strings in a case-independent fashion */
valueType * valueType *
strcmplcBIF(parameterList, kindOfFixup) strcmplcBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *string1; stringType *string1;
@ -795,7 +716,7 @@ strcmplcBIF(parameterList, kindOfFixup)
error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmplc"); error(NO_ARGUMENTS_TO_BIF_ERROR, "strcmplc");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 1); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 1);
return(makeFailureValue()); return(makeFailureValue());
@ -804,7 +725,7 @@ strcmplcBIF(parameterList, kindOfFixup)
parameterList = parameterList->nextOperand; parameterList = parameterList->nextOperand;
if (parameterList == NULL) if (parameterList == NULL)
return(makeStringValue(string1)); return(makeStringValue(string1));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 2); error(BIF_NTH_ARGUMENT_IS_NOT_A_STRING_ERROR, "strcmplc", 2);
return(makeFailureValue()); return(makeFailureValue());
@ -815,15 +736,13 @@ strcmplcBIF(parameterList, kindOfFixup)
/* Return the length of a string */ /* Return the length of a string */
valueType * valueType *
strlenBIF(parameterList, kindOfFixup) strlenBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
if (parameterList == NULL) if (parameterList == NULL)
return(makeIntegerValue(-1)); return(makeIntegerValue(-1));
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "strlen"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "strlen");
return(makeFailureValue()); return(makeFailureValue());
@ -833,9 +752,7 @@ strlenBIF(parameterList, kindOfFixup)
/* Return a substring of a string */ /* Return a substring of a string */
valueType * valueType *
substrBIF(parameterList, kindOfFixup) substrBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *string; stringType *string;
@ -851,7 +768,7 @@ substrBIF(parameterList, kindOfFixup)
error(NO_ARGUMENTS_TO_BIF_ERROR, "substr"); error(NO_ARGUMENTS_TO_BIF_ERROR, "substr");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "substr"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "substr");
return(makeFailureValue()); return(makeFailureValue());
@ -864,7 +781,7 @@ substrBIF(parameterList, kindOfFixup)
error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, "substr"); error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, "substr");
return(makeFailureValue()); return(makeFailureValue());
} }
startValue = evaluateOperand(parameterList, NO_FIXUP); startValue = evaluateOperand(parameterList);
if (startValue->kindOfValue != ABSOLUTE_VALUE) { if (startValue->kindOfValue != ABSOLUTE_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, "substr", error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, "substr",
2); 2);
@ -883,7 +800,7 @@ substrBIF(parameterList, kindOfFixup)
if (backwards) if (backwards)
length = -length; length = -length;
} else { } else {
lengthValue = evaluateOperand(parameterList, NO_FIXUP); lengthValue = evaluateOperand(parameterList);
if (lengthValue->kindOfValue != ABSOLUTE_VALUE) { if (lengthValue->kindOfValue != ABSOLUTE_VALUE) {
error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR, error(BIF_NTH_ARGUMENT_IS_NOT_ABSOLUTE_VALUE_ERROR,
"substr", 3); "substr", 3);
@ -913,22 +830,16 @@ substrBIF(parameterList, kindOfFixup)
/* Turn a string into a symbol */ /* Turn a string into a symbol */
valueType * valueType *
symbolLookupBIF(parameterList, kindOfFixup) symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
stringType *identifierToLookup; stringType *identifierToLookup;
expressionTermType *buildExpressionTerm();
operandType *buildOperand();
valueType *evaluateIdentifier();
if (parameterList == NULL) { if (parameterList == NULL) {
error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolLookup"); error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolLookup");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolLookup"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolLookup");
return(makeFailureValue()); return(makeFailureValue());
@ -940,19 +851,16 @@ symbolLookupBIF(parameterList, kindOfFixup)
/* Define a string as a symbol */ /* Define a string as a symbol */
valueType * valueType *
symbolDefineBIF(parameterList, kindOfFixup) symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *stringValue; valueType *stringValue;
statementType *syntheticDefineStatement; statementType *syntheticDefineStatement;
statementType *buildDefineStatement();
if (parameterList == NULL) { if (parameterList == NULL) {
error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolDefine"); error(NO_ARGUMENTS_TO_BIF_ERROR, "symbolDefine");
return(makeFailureValue()); return(makeFailureValue());
} }
stringValue = evaluateOperand(parameterList, NO_FIXUP); stringValue = evaluateOperand(parameterList);
if (stringValue->kindOfValue != STRING_VALUE) { if (stringValue->kindOfValue != STRING_VALUE) {
error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolDefine"); error(BIF_ARGUMENT_IS_NOT_A_STRING_ERROR, "symbolDefine");
return(makeFailureValue()); return(makeFailureValue());
@ -966,25 +874,21 @@ symbolDefineBIF(parameterList, kindOfFixup)
return(makeFailureValue()); return(makeFailureValue());
} else { } else {
syntheticDefineStatement = buildDefineStatement(stringValue-> syntheticDefineStatement = buildDefineStatement(stringValue->
value, parameterList->theOperand); value, parameterList->theOperand.expressionUnion);
} }
assembleDefineStatement(syntheticDefineStatement->statementBody); assembleDefineStatement(syntheticDefineStatement->statementBody.defineUnion);
freeStatement(syntheticDefineStatement); freeStatement(syntheticDefineStatement);
return(makeBooleanValue(TRUE)); return(makeBooleanValue(TRUE));
} }
/* Turn a symbol into a string */ /* Turn a symbol into a string */
valueType * valueType *
symbolNameBIF(parameterList, kindOfFixup) symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
expressionType *expression; expressionType *expression;
symbolInContextType *context; symbolInContextType *context;
environmentType *saveEnvironment; environmentType *saveEnvironment;
symbolInContextType *getWorkingContext();
saveEnvironment = currentEnvironment; saveEnvironment = currentEnvironment;
while (parameterList != NULL && parameterList->kindOfOperand == while (parameterList != NULL && parameterList->kindOfOperand ==
EXPRESSION_OPND) { EXPRESSION_OPND) {
@ -1014,15 +918,11 @@ symbolNameBIF(parameterList, kindOfFixup)
/* Return internal form of what sort of symbol a symbol is */ /* Return internal form of what sort of symbol a symbol is */
valueType * valueType *
symbolUsageBIF(parameterList, kindOfFixup) symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
expressionType *expression; expressionType *expression;
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
if (parameterList != NULL && parameterList->kindOfOperand == if (parameterList != NULL && parameterList->kindOfOperand ==
EXPRESSION_OPND) { EXPRESSION_OPND) {
expression = parameterList->theOperand.expressionUnion; expression = parameterList->theOperand.expressionUnion;
@ -1036,16 +936,12 @@ symbolUsageBIF(parameterList, kindOfFixup)
/* Return internal form of what sort of value a value is */ /* Return internal form of what sort of value a value is */
valueType * valueType *
valueTypeBIF(parameterList, kindOfFixup) valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(evaluatedParameter->kindOfValue)); return(makeIntegerValue(evaluatedParameter->kindOfValue));
} else { } else {
return(makeIntegerValue(-1)); return(makeIntegerValue(-1));

63
builtInFunctions.h Normal file
View File

@ -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

View File

@ -32,28 +32,17 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "builtInFunctions.h"
/* Helper functions, defined in builtInFunctions.c */ #include "operandStuff.h"
valueType *makeBooleanValue();
valueType *makeFailureValue();
valueType *makeIntegerValue();
valueType *makeOperandValue();
valueType *makeStringValue();
valueType *makeUndefinedValue();
/* Check if operand is the accumulator */ /* Check if operand is the accumulator */
valueType * valueType *
isARegisterBIF(parameterList, kindOfFixup) isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
A_REGISTER_OPND)); A_REGISTER_OPND));
} else { } else {
@ -63,16 +52,12 @@ isARegisterBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is DIRECT */ /* Check if an operand's address mode is DIRECT */
valueType * valueType *
isDirectModeBIF(parameterList, kindOfFixup) isDirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
EXPRESSION_OPND)); EXPRESSION_OPND));
} else { } else {
@ -82,16 +67,12 @@ isDirectModeBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is IMMEDIATE */ /* Check if an operand's address mode is IMMEDIATE */
valueType * valueType *
isImmediateModeBIF(parameterList, kindOfFixup) isImmediateModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
IMMEDIATE_OPND)); IMMEDIATE_OPND));
} else { } else {
@ -101,16 +82,12 @@ isImmediateModeBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is INDEXED (either X or Y) */ /* Check if an operand's address mode is INDEXED (either X or Y) */
valueType * valueType *
isIndexedModeBIF(parameterList, kindOfFixup) isIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
X_INDEXED_OPND || evaluatedParameter->addressMode == X_INDEXED_OPND || evaluatedParameter->addressMode ==
Y_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 */ /* Check if an operand's address mode is INDIRECT */
valueType * valueType *
isIndirectModeBIF(parameterList, kindOfFixup) isIndirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
INDIRECT_OPND)); INDIRECT_OPND));
} else { } else {
@ -142,16 +115,12 @@ isIndirectModeBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is POST-INDEXED */ /* Check if an operand's address mode is POST-INDEXED */
valueType * valueType *
isPostIndexedModeBIF(parameterList, kindOfFixup) isPostIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
POST_INDEXED_Y_OPND)); POST_INDEXED_Y_OPND));
} else { } else {
@ -161,16 +130,12 @@ isPostIndexedModeBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is PRE-INDEXED */ /* Check if an operand's address mode is PRE-INDEXED */
valueType * valueType *
isPreIndexedModeBIF(parameterList, kindOfFixup) isPreIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
PRE_INDEXED_X_OPND || evaluatedParameter-> PRE_INDEXED_X_OPND || evaluatedParameter->
addressMode == PRE_SELECTED_X_OPND)); addressMode == PRE_SELECTED_X_OPND));
@ -181,16 +146,12 @@ isPreIndexedModeBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is X-INDEXED */ /* Check if an operand's address mode is X-INDEXED */
valueType * valueType *
isXIndexedModeBIF(parameterList, kindOfFixup) isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
X_INDEXED_OPND || evaluatedParameter->addressMode == X_INDEXED_OPND || evaluatedParameter->addressMode ==
X_SELECTED_OPND)); X_SELECTED_OPND));
@ -201,16 +162,12 @@ isXIndexedModeBIF(parameterList, kindOfFixup)
/* Check if an operand is the X index register */ /* Check if an operand is the X index register */
valueType * valueType *
isXRegisterBIF(parameterList, kindOfFixup) isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
X_REGISTER_OPND)); X_REGISTER_OPND));
} else { } else {
@ -220,16 +177,12 @@ isXRegisterBIF(parameterList, kindOfFixup)
/* Check if an operand's address mode is Y-INDEXED */ /* Check if an operand's address mode is Y-INDEXED */
valueType * valueType *
isYIndexedModeBIF(parameterList, kindOfFixup) isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
Y_INDEXED_OPND || evaluatedParameter->addressMode == Y_INDEXED_OPND || evaluatedParameter->addressMode ==
Y_SELECTED_OPND)); Y_SELECTED_OPND));
@ -240,16 +193,12 @@ isYIndexedModeBIF(parameterList, kindOfFixup)
/* Check if an operand is the Y index register */ /* Check if an operand is the Y index register */
valueType * valueType *
isYRegisterBIF(parameterList, kindOfFixup) isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup)
operandListType *parameterList;
fixupKindType kindOfFixup;
{ {
valueType *evaluatedParameter; valueType *evaluatedParameter;
valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(evaluatedParameter->addressMode == return(makeBooleanValue(evaluatedParameter->addressMode ==
Y_REGISTER_OPND)); Y_REGISTER_OPND));
} else { } else {

View File

@ -53,7 +53,7 @@ getAddressRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(getAddressRegister( return(makeIntegerValue(getAddressRegister(
evaluatedParameter->addressMode))); evaluatedParameter->addressMode)));
} else { } else {
@ -72,7 +72,7 @@ getDataRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(getDataRegister(evaluatedParameter-> return(makeIntegerValue(getDataRegister(evaluatedParameter->
addressMode))); addressMode)));
} else { } else {
@ -91,7 +91,7 @@ getIndexRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(getIndexRegister(evaluatedParameter-> return(makeIntegerValue(getIndexRegister(evaluatedParameter->
addressMode))); addressMode)));
} else { } else {
@ -110,7 +110,7 @@ getRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(getRegister(evaluatedParameter-> return(makeIntegerValue(getRegister(evaluatedParameter->
addressMode))); addressMode)));
} else { } else {
@ -129,7 +129,7 @@ getWLBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeIntegerValue(getWL(evaluatedParameter-> return(makeIntegerValue(getWL(evaluatedParameter->
addressMode))); addressMode)));
} else { } else {
@ -148,7 +148,7 @@ isAbsoluteModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == ABSOLUTE_SHORT_OPND || addressMode) == ABSOLUTE_SHORT_OPND ||
operandKindField(evaluatedParameter->addressMode) == operandKindField(evaluatedParameter->addressMode) ==
@ -169,7 +169,7 @@ isAbsoluteLongModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == ABSOLUTE_LONG_OPND)); addressMode) == ABSOLUTE_LONG_OPND));
} else { } else {
@ -188,7 +188,7 @@ isAbsoluteShortModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == ABSOLUTE_SHORT_OPND)); addressMode) == ABSOLUTE_SHORT_OPND));
} else { } else {
@ -207,7 +207,7 @@ isARegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == A_REGISTER_OPND)); addressMode) == A_REGISTER_OPND));
} else { } else {
@ -226,7 +226,7 @@ isCCRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == CC_REGISTER_OPND)); addressMode) == CC_REGISTER_OPND));
} else { } else {
@ -245,7 +245,7 @@ isControlRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == CONTROL_REGISTER_OPND)); addressMode) == CONTROL_REGISTER_OPND));
} else { } else {
@ -264,7 +264,7 @@ isDRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == D_REGISTER_OPND)); addressMode) == D_REGISTER_OPND));
} else { } else {
@ -283,7 +283,7 @@ isDFCRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == CONTROL_REGISTER_OPND && addressMode) == CONTROL_REGISTER_OPND &&
getRegister(evaluatedParameter->addressMode) == getRegister(evaluatedParameter->addressMode) ==
@ -304,7 +304,7 @@ isDisplacementModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == DISPLACEMENT_OPND)); addressMode) == DISPLACEMENT_OPND));
} else { } else {
@ -323,7 +323,7 @@ isImmediateModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == IMMEDIATE_OPND)); addressMode) == IMMEDIATE_OPND));
} else { } else {
@ -342,7 +342,7 @@ isIndexedModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == INDEXED_OPND)); addressMode) == INDEXED_OPND));
} else { } else {
@ -361,7 +361,7 @@ isIndirectModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == A_REGISTER_INDIRECT_OPND)); addressMode) == A_REGISTER_INDIRECT_OPND));
} else { } else {
@ -380,7 +380,7 @@ isPCDisplacementModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == PC_DISPLACEMENT_OPND)); addressMode) == PC_DISPLACEMENT_OPND));
} else { } else {
@ -399,7 +399,7 @@ isPCIndexedModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == PC_INDEXED_OPND)); addressMode) == PC_INDEXED_OPND));
} else { } else {
@ -418,7 +418,7 @@ isPostincrementModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == POSTINCREMENT_OPND)); addressMode) == POSTINCREMENT_OPND));
} else { } else {
@ -437,7 +437,7 @@ isPredecrementModeBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == PREDECREMENT_OPND)); addressMode) == PREDECREMENT_OPND));
} else { } else {
@ -456,7 +456,7 @@ isSFCRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == CONTROL_REGISTER_OPND && addressMode) == CONTROL_REGISTER_OPND &&
getRegister(evaluatedParameter->addressMode) == getRegister(evaluatedParameter->addressMode) ==
@ -477,7 +477,7 @@ isStatusRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == STATUS_REGISTER_OPND)); addressMode) == STATUS_REGISTER_OPND));
} else { } else {
@ -496,7 +496,7 @@ isUSPBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == USP_REGISTER_OPND)); addressMode) == USP_REGISTER_OPND));
} else { } else {
@ -515,7 +515,7 @@ isVBRegisterBIF(parameterList, kindOfFixup)
valueType *evaluateOperand(); valueType *evaluateOperand();
if (parameterList != NULL) { if (parameterList != NULL) {
evaluatedParameter = evaluateOperand(parameterList, NO_FIXUP); evaluatedParameter = evaluateOperand(parameterList);
return(makeBooleanValue(operandKindField(evaluatedParameter-> return(makeBooleanValue(operandKindField(evaluatedParameter->
addressMode) == CONTROL_REGISTER_OPND && addressMode) == CONTROL_REGISTER_OPND &&
getRegister(evaluatedParameter->addressMode) == getRegister(evaluatedParameter->addressMode) ==

View File

@ -30,6 +30,7 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "debugPrint.h"
#include "y.tab.h" #include "y.tab.h"
/* /*
@ -42,8 +43,9 @@ int tablevel = 0;
#define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; }
/* For keeping nested structures looking pretty */ /* For keeping nested structures looking pretty */
void
tab() void
tab(void)
{ {
int n; int n;
@ -60,8 +62,7 @@ tab()
*/ */
void void
printAssignmentKind(assignmentKind) printAssignmentKind(assignmentKindType assignmentKind)
assignmentKindType assignmentKind;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'assignmentKindType'. */ enumerated type 'assignmentKindType'. */
@ -84,8 +85,7 @@ printAssignmentKind(assignmentKind)
} }
void void
printExpressionKind(kind) printExpressionKind(expressionTermKindType kind)
expressionTermKindType kind;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'expressionTermKindType'. */ enumerated type 'expressionTermKindType'. */
@ -110,8 +110,7 @@ printExpressionKind(kind)
} }
stringType * stringType *
statementKindString(kind) statementKindString(statementKindType kind)
statementKindType kind;
{ {
/* This table MUST be maintained congruently with the definition of /* This table MUST be maintained congruently with the definition of
the enumerated type 'statementKindType'. */ the enumerated type 'statementKindType'. */
@ -159,8 +158,7 @@ static char *statementKindTable[] = {
} }
void void
printStatementKind(kind) printStatementKind(statementKindType kind)
statementKindType kind;
{ {
printf("%s", statementKindString(kind)); printf("%s", statementKindString(kind));
} }
@ -171,8 +169,7 @@ printStatementKind(kind)
*/ */
void void
printValue(value) printValue(valueType *value)
valueType *value;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -205,8 +202,7 @@ printValue(value)
} }
void void
printSymbol(symbol) printSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
/* This table MUST be maintained congruent with the definition of the /* This table MUST be maintained congruent with the definition of the
enumerated type 'symbolUsageKindType'. */ enumerated type 'symbolUsageKindType'. */
@ -241,8 +237,7 @@ printSymbol(symbol)
} }
void void
printArgumentDefinitionList(list) printArgumentDefinitionList(argumentDefinitionListType *list)
argumentDefinitionListType *list;
{ {
nullPrint(list); nullPrint(list);
tab(); printf("(arguments:\n"); tab(); printf("(arguments:\n");
@ -256,11 +251,8 @@ printArgumentDefinitionList(list)
} }
void void
printBlock(block) printBlock(blockType *block)
blockType *block;
{ {
void printStatement();
nullPrint(block); nullPrint(block);
tab(); printf("(block:\n"); tab(); printf("(block:\n");
tablevel++; tablevel++;
@ -270,12 +262,8 @@ printBlock(block)
} }
void void
printArrayTerm(arrayTerm) printArrayTerm(arrayTermType *arrayTerm)
arrayTermType *arrayTerm;
{ {
void printIdentifier();
void printExpression();
nullPrint(arrayTerm); nullPrint(arrayTerm);
tab(); printf("(array\n"); tab(); printf("(array\n");
tablevel++; tablevel++;
@ -286,10 +274,8 @@ printArrayTerm(arrayTerm)
} }
void void
printAssignmentTerm(assignmentTerm) printAssignmentTerm(binopTermType *assignmentTerm)
binopTermType *assignmentTerm;
{ {
void printExpression();
nullPrint(assignmentTerm); nullPrint(assignmentTerm);
tab(); printf("(assignment ["); tab(); printf("(assignment [");
@ -303,12 +289,8 @@ printAssignmentTerm(assignmentTerm)
} }
void void
printBinopTerm(binopTerm) printBinopTerm(binopTermType *binopTerm)
binopTermType *binopTerm;
{ {
void printIdentifier();
void printExpression();
nullPrint(binopTerm); nullPrint(binopTerm);
tab(); printf("(binop ["); tab(); printf("(binop [");
printToken(binopTerm->binop); printToken(binopTerm->binop);
@ -324,11 +306,8 @@ printBinopTerm(binopTerm)
} }
void void
printFunctionCall(functionCall) printFunctionCall(functionCallTermType *functionCall)
functionCallTermType *functionCall;
{ {
void printOperandList();
nullPrint(functionCall); nullPrint(functionCall);
tab(); printf("(function call %s\n", functionCall->functionName-> tab(); printf("(function call %s\n", functionCall->functionName->
symbolName); symbolName);
@ -339,29 +318,26 @@ printFunctionCall(functionCall)
} }
void void
printHere() printHere(void)
{ {
tab(); printf("(here)\n"); tab(); printf("(here)\n");
} }
void void
printIdentifier(identifier) printIdentifier(symbolTableEntryType *identifier)
symbolTableEntryType *identifier;
{ {
nullPrint(identifier); nullPrint(identifier);
printSymbol(identifier); printSymbol(identifier);
} }
void void
printNumber(number) printNumber(numberTermType number)
numberTermType number;
{ {
tab(); printf("(number: %d)\n", number); tab(); printf("(number: %d)\n", number);
} }
void void
printPostopTerm(postopTerm) printPostopTerm(postOpTermType *postopTerm)
postOpTermType *postopTerm;
{ {
nullPrint(postopTerm); nullPrint(postopTerm);
tab(); printf("(postop ["); tab(); printf("(postop [");
@ -374,8 +350,7 @@ printPostopTerm(postopTerm)
} }
void void
printPreopTerm(preopTerm) printPreopTerm(preOpTermType *preopTerm)
preOpTermType *preopTerm;
{ {
nullPrint(preopTerm); nullPrint(preopTerm);
tab(); printf("(preop ["); tab(); printf("(preop [");
@ -388,11 +363,8 @@ printPreopTerm(preopTerm)
} }
void void
printUnopTerm(unopTerm) printUnopTerm(unopTermType *unopTerm)
unopTermType *unopTerm;
{ {
void printExpression();
nullPrint(unopTerm); nullPrint(unopTerm);
tab(); printf("(unop ["); tab(); printf("(unop [");
printToken(unopTerm->unop); printToken(unopTerm->unop);
@ -404,8 +376,7 @@ printUnopTerm(unopTerm)
} }
void void
printExpression(expression) printExpression(expressionType *expression)
expressionType *expression;
{ {
nullPrint(expression); nullPrint(expression);
tab(); printf("(expression: ["); tab(); printf("(expression: [");
@ -427,7 +398,7 @@ printExpression(expression)
break; break;
case CONDITION_CODE_EXPR: case CONDITION_CODE_EXPR:
printCondition(expression->expressionTerm); printCondition(expression->expressionTerm.conditionTypeUnion);
break; break;
case FUNCTION_CALL_EXPR: case FUNCTION_CALL_EXPR:
@ -480,8 +451,7 @@ printExpression(expression)
} }
void void
printExpressionList(expressionList) printExpressionList(expressionListType *expressionList)
expressionListType *expressionList;
{ {
while (expressionList != NULL) { while (expressionList != NULL) {
printExpression(expressionList->theExpression); printExpression(expressionList->theExpression);
@ -490,8 +460,7 @@ printExpressionList(expressionList)
} }
void void
printIdentifierList(identifierList) printIdentifierList(identifierListType *identifierList)
identifierListType *identifierList;
{ {
nullPrint(identifierList); nullPrint(identifierList);
printSymbol(identifierList->theSymbol); printSymbol(identifierList->theSymbol);
@ -505,8 +474,7 @@ printIdentifierList(identifierList)
*/ */
void void
printCase(aCase) printCase(caseType *aCase)
caseType *aCase;
{ {
tab(); printf("(case:\n"); tablevel++; tab(); printf("(case:\n"); tablevel++;
if (aCase->caseTags == NULL) { if (aCase->caseTags == NULL) {
@ -523,8 +491,7 @@ printCase(aCase)
} }
void void
printCaseList(caseList) printCaseList(caseListType *caseList)
caseListType *caseList;
{ {
tab(); printf("(cases:\n"); tab(); printf("(cases:\n");
tablevel++; tablevel++;
@ -537,24 +504,21 @@ printCaseList(caseList)
} }
void void
printMacro(macroInstruction) printMacro(macroTableEntryType *macroInstruction)
macroTableEntryType *macroInstruction;
{ {
nullPrint(macroInstruction); nullPrint(macroInstruction);
tab(); printf("(macro: %s)\n", macroInstruction->macroName); tab(); printf("(macro: %s)\n", macroInstruction->macroName);
} }
void void
printOpcode(opcode) printOpcode(opcodeTableEntryType *opcode)
opcodeTableEntryType *opcode;
{ {
nullPrint(opcode); nullPrint(opcode);
tab(); printf("(opcode: %s)\n", opcode->mnemonic); tab(); printf("(opcode: %s)\n", opcode->mnemonic);
} }
void void
printOperandList(operandList) printOperandList(operandListType *operandList)
operandListType *operandList;
{ {
nullPrint(operandList); nullPrint(operandList);
printOperand(operandList); printOperand(operandList);
@ -563,16 +527,14 @@ printOperandList(operandList)
} }
void void
printAlignStatement(alignStatement) printAlignStatement(alignStatementBodyType *alignStatement)
alignStatementBodyType *alignStatement;
{ {
nullPrint(alignStatement); nullPrint(alignStatement);
printExpression(alignStatement); printExpression(alignStatement);
} }
void void
printAssertStatement(assertStatement) printAssertStatement(assertStatementBodyType *assertStatement)
assertStatementBodyType *assertStatement;
{ {
nullPrint(assertStatement); nullPrint(assertStatement);
printExpression(assertStatement->condition); printExpression(assertStatement->condition);
@ -580,24 +542,21 @@ printAssertStatement(assertStatement)
} }
void void
printBlockStatement(blockStatement) printBlockStatement(blockStatementBodyType *blockStatement)
blockStatementBodyType *blockStatement;
{ {
nullPrint(blockStatement); nullPrint(blockStatement);
printExpressionList(blockStatement); printExpressionList(blockStatement);
} }
void void
printByteStatement(byteStatement) printByteStatement(byteStatementBodyType *byteStatement)
byteStatementBodyType *byteStatement;
{ {
nullPrint(byteStatement); nullPrint(byteStatement);
printExpressionList(byteStatement); printExpressionList(byteStatement);
} }
void void
printConstrainStatement(constrainStatement) printConstrainStatement(constrainStatementBodyType *constrainStatement)
constrainStatementBodyType *constrainStatement;
{ {
nullPrint(constrainStatement); nullPrint(constrainStatement);
printExpression(constrainStatement->constraint); printExpression(constrainStatement->constraint);
@ -605,16 +564,14 @@ printConstrainStatement(constrainStatement)
} }
void void
printDbyteStatement(dbyteStatement) printDbyteStatement(dbyteStatementBodyType *dbyteStatement)
dbyteStatementBodyType *dbyteStatement;
{ {
nullPrint(dbyteStatement); nullPrint(dbyteStatement);
printExpressionList(dbyteStatement); printExpressionList(dbyteStatement);
} }
void void
printDefineStatement(defineStatement) printDefineStatement(defineStatementBodyType *defineStatement)
defineStatementBodyType *defineStatement;
{ {
nullPrint(defineStatement); nullPrint(defineStatement);
printSymbol(defineStatement->theSymbol); printSymbol(defineStatement->theSymbol);
@ -622,8 +579,7 @@ printDefineStatement(defineStatement)
} }
void void
printDoUntilStatement(doUntilStatement) printDoUntilStatement(doUntilStatementBodyType *doUntilStatement)
doUntilStatementBodyType *doUntilStatement;
{ {
nullPrint(doUntilStatement); nullPrint(doUntilStatement);
printBlock(doUntilStatement->doUntilLoop); printBlock(doUntilStatement->doUntilLoop);
@ -633,8 +589,7 @@ printDoUntilStatement(doUntilStatement)
} }
void void
printDoWhileStatement(doWhileStatement) printDoWhileStatement(doWhileStatementBodyType *doWhileStatement)
doWhileStatementBodyType *doWhileStatement;
{ {
nullPrint(doWhileStatement); nullPrint(doWhileStatement);
printBlock(doWhileStatement->doWhileLoop); printBlock(doWhileStatement->doWhileLoop);
@ -644,24 +599,21 @@ printDoWhileStatement(doWhileStatement)
} }
void void
printExternStatement(externStatement) printExternStatement(externStatementBodyType *externStatement)
externStatementBodyType *externStatement;
{ {
nullPrint(externStatement); nullPrint(externStatement);
printIdentifierList(externStatement); printIdentifierList(externStatement);
} }
void void
printFreturnStatement(freturnStatement) printFreturnStatement(freturnStatementBodyType *freturnStatement)
freturnStatementBodyType *freturnStatement;
{ {
nullPrint(freturnStatement); nullPrint(freturnStatement);
printExpression(freturnStatement); printExpression(freturnStatement);
} }
void void
printFunctionStatement(functionStatement) printFunctionStatement(functionStatementBodyType *functionStatement)
functionStatementBodyType *functionStatement;
{ {
nullPrint(functionStatement); nullPrint(functionStatement);
tab();printf("(function name: %s)\n",functionStatement->functionName); tab();printf("(function name: %s)\n",functionStatement->functionName);
@ -670,8 +622,7 @@ printFunctionStatement(functionStatement)
} }
void void
printIfStatement(ifStatement) printIfStatement(ifStatementBodyType *ifStatement)
ifStatementBodyType *ifStatement;
{ {
nullPrint(ifStatement); nullPrint(ifStatement);
tab(); printf("(condition: "); tab(); printf("(condition: ");
@ -686,16 +637,14 @@ printIfStatement(ifStatement)
} }
void void
printIncludeStatement(includeStatement) printIncludeStatement(includeStatementBodyType *includeStatement)
includeStatementBodyType *includeStatement;
{ {
nullPrint(includeStatement); nullPrint(includeStatement);
printExpression(includeStatement); printExpression(includeStatement);
} }
void void
printInstructionStatement(instructionStatement) printInstructionStatement(instructionStatementBodyType *instructionStatement)
instructionStatementBodyType *instructionStatement;
{ {
nullPrint(instructionStatement); nullPrint(instructionStatement);
switch(instructionStatement->kindOfInstruction) { switch(instructionStatement->kindOfInstruction) {
@ -716,16 +665,14 @@ printInstructionStatement(instructionStatement)
} }
void void
printLongStatement(longStatement) printLongStatement(longStatementBodyType *longStatement)
longStatementBodyType *longStatement;
{ {
nullPrint(longStatement); nullPrint(longStatement);
printExpressionList(longStatement); printExpressionList(longStatement);
} }
void void
printMacroStatement(macroStatement) printMacroStatement(macroStatementBodyType *macroStatement)
macroStatementBodyType *macroStatement;
{ {
nullPrint(macroStatement); nullPrint(macroStatement);
tab(); printf("(macro name: %s)\n", macroStatement->theMacro); tab(); printf("(macro name: %s)\n", macroStatement->theMacro);
@ -734,8 +681,7 @@ printMacroStatement(macroStatement)
} }
void void
printMdefineStatement(mdefineStatement) printMdefineStatement(defineStatementBodyType *mdefineStatement)
defineStatementBodyType *mdefineStatement;
{ {
nullPrint(mdefineStatement); nullPrint(mdefineStatement);
printSymbol(mdefineStatement->theSymbol); printSymbol(mdefineStatement->theSymbol);
@ -743,8 +689,7 @@ printMdefineStatement(mdefineStatement)
} }
void void
printMdoUntilStatement(mdoUntilStatement) printMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement)
mdoUntilStatementBodyType *mdoUntilStatement;
{ {
nullPrint(mdoUntilStatement); nullPrint(mdoUntilStatement);
printBlock(mdoUntilStatement->mdoUntilLoop); printBlock(mdoUntilStatement->mdoUntilLoop);
@ -752,8 +697,7 @@ printMdoUntilStatement(mdoUntilStatement)
} }
void void
printMdoWhileStatement(mdoWhileStatement) printMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement)
mdoWhileStatementBodyType *mdoWhileStatement;
{ {
nullPrint(mdoWhileStatement); nullPrint(mdoWhileStatement);
printBlock(mdoWhileStatement->mdoWhileLoop); printBlock(mdoWhileStatement->mdoWhileLoop);
@ -761,8 +705,7 @@ printMdoWhileStatement(mdoWhileStatement)
} }
void void
printMforStatement(mforStatement) printMforStatement(mforStatementBodyType *mforStatement)
mforStatementBodyType *mforStatement;
{ {
nullPrint(mforStatement); nullPrint(mforStatement);
printExpression(mforStatement->initExpression); printExpression(mforStatement->initExpression);
@ -772,8 +715,7 @@ printMforStatement(mforStatement)
} }
void void
printMifStatement(mifStatement) printMifStatement(mifStatementBodyType *mifStatement)
mifStatementBodyType *mifStatement;
{ {
nullPrint(mifStatement); nullPrint(mifStatement);
printExpression(mifStatement->mifCondition); printExpression(mifStatement->mifCondition);
@ -786,8 +728,7 @@ printMifStatement(mifStatement)
} }
void void
printMswitchStatement(mswitchStatement) printMswitchStatement(mswitchStatementBodyType *mswitchStatement)
mswitchStatementBodyType *mswitchStatement;
{ {
nullPrint(mswitchStatement); nullPrint(mswitchStatement);
printExpression(mswitchStatement->switchExpression); printExpression(mswitchStatement->switchExpression);
@ -795,8 +736,7 @@ printMswitchStatement(mswitchStatement)
} }
void void
printMvariableStatement(mvariableStatement) printMvariableStatement(mvariableStatementBodyType *mvariableStatement)
mvariableStatementBodyType *mvariableStatement;
{ {
nullPrint(mvariableStatement); nullPrint(mvariableStatement);
printSymbol(mvariableStatement->theSymbol); printSymbol(mvariableStatement->theSymbol);
@ -804,8 +744,7 @@ printMvariableStatement(mvariableStatement)
} }
void void
printMwhileStatement(mwhileStatement) printMwhileStatement(mwhileStatementBodyType *mwhileStatement)
mwhileStatementBodyType *mwhileStatement;
{ {
nullPrint(mwhileStatement); nullPrint(mwhileStatement);
printExpression(mwhileStatement->mwhileCondition); printExpression(mwhileStatement->mwhileCondition);
@ -813,47 +752,41 @@ printMwhileStatement(mwhileStatement)
} }
void void
printOrgStatement(orgStatement) printOrgStatement(orgStatementBodyType *orgStatement)
orgStatementBodyType *orgStatement;
{ {
nullPrint(orgStatement); nullPrint(orgStatement);
printExpression(orgStatement); printExpression(orgStatement);
} }
void void
printPerformStatement(performStatement) printPerformStatement(performStatementBodyType *performStatement)
performStatementBodyType *performStatement;
{ {
nullPrint(performStatement); nullPrint(performStatement);
printExpression(performStatement); printExpression(performStatement);
} }
void void
printRelStatement(relStatement) printRelStatement(relStatementBodyType *relStatement)
relStatementBodyType *relStatement;
{ {
/* there's nothing here... */ /* there's nothing here... */
} }
void void
printStartStatement(startStatement) printStartStatement(startStatementBodyType *startStatement)
startStatementBodyType *startStatement;
{ {
nullPrint(startStatement); nullPrint(startStatement);
printExpression(startStatement); printExpression(startStatement);
} }
void void
printStringStatement(stringStatement) printStringStatement(stringStatementBodyType *stringStatement)
stringStatementBodyType *stringStatement;
{ {
nullPrint(stringStatement); nullPrint(stringStatement);
printExpressionList(stringStatement); printExpressionList(stringStatement);
} }
void void
printStructStatement(structStatement) printStructStatement(structStatementBodyType *structStatement)
structStatementBodyType *structStatement;
{ {
nullPrint(structStatement); nullPrint(structStatement);
printSymbol(structStatement->structName); printSymbol(structStatement->structName);
@ -861,24 +794,21 @@ printStructStatement(structStatement)
} }
void void
printTargetStatement(targetStatement) printTargetStatement(targetStatementBodyType *targetStatement)
targetStatementBodyType *targetStatement;
{ {
nullPrint(targetStatement); nullPrint(targetStatement);
printExpression(targetStatement); printExpression(targetStatement);
} }
void void
printUndefineStatement(undefineStatement) printUndefineStatement(undefineStatementBodyType *undefineStatement)
undefineStatementBodyType *undefineStatement;
{ {
nullPrint(undefineStatement); nullPrint(undefineStatement);
printIdentifierList(undefineStatement); printIdentifierList(undefineStatement);
} }
void void
printVariableStatement(variableStatement) printVariableStatement(variableStatementBodyType *variableStatement)
variableStatementBodyType *variableStatement;
{ {
nullPrint(variableStatement); nullPrint(variableStatement);
printSymbol(variableStatement->theSymbol); printSymbol(variableStatement->theSymbol);
@ -886,8 +816,7 @@ printVariableStatement(variableStatement)
} }
void void
printWhileStatement(whileStatement) printWhileStatement(whileStatementBodyType *whileStatement)
whileStatementBodyType *whileStatement;
{ {
nullPrint(whileStatement); nullPrint(whileStatement);
tab(); printf("(condition: "); tab(); printf("(condition: ");
@ -897,16 +826,14 @@ printWhileStatement(whileStatement)
} }
void void
printWordStatement(wordStatement) printWordStatement(wordStatementBodyType *wordStatement)
wordStatementBodyType *wordStatement;
{ {
nullPrint(wordStatement); nullPrint(wordStatement);
printExpressionList(wordStatement); printExpressionList(wordStatement);
} }
void void
printLabelList(labelList) printLabelList(labelListType *labelList)
labelListType *labelList;
{ {
nullPrint(labelList); nullPrint(labelList);
tab(); printf("(\n"); tab(); printf("(\n");
@ -920,9 +847,7 @@ printLabelList(labelList)
} }
void void
printStatementBody(kind, body) printStatementBody(statementKindType kind, statementBodyType body)
statementKindType kind;
statementBodyType body;
{ {
switch (kind) { switch (kind) {
@ -1085,8 +1010,7 @@ printStatementBody(kind, body)
} }
void void
printStatement(statement) printStatement(statementType *statement)
statementType *statement;
{ {
nullPrint(statement); nullPrint(statement);
tab(); printf("(statement["); tab(); printf("(statement[");
@ -1107,8 +1031,7 @@ printStatement(statement)
*/ */
void void
printPendingFixupList(fixupList) printPendingFixupList(fixupListType *fixupList)
fixupListType *fixupList;
{ {
printf("fixup list: ("); printf("fixup list: (");
tablevel++; tablevel++;
@ -1121,10 +1044,7 @@ printPendingFixupList(fixupList)
} }
void void
printCreateFixup(expression, location, kindOfFixup) printCreateFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup)
expressionType *expression;
addressType location;
fixupKindType kindOfFixup;
{ {
static char *fixupStringTable[] = { static char *fixupStringTable[] = {
"BYTE FIXUP", "BYTE FIXUP",
@ -1148,7 +1068,7 @@ printCreateFixup(expression, location, kindOfFixup)
*/ */
void void
printExpressionBuffer() printExpressionBuffer(void)
{ {
int line; int line;
int i; int i;
@ -1163,9 +1083,7 @@ printExpressionBuffer()
} }
void void
printOneCodeBuffer(codeSegment, bufferNum) printOneCodeBuffer(codeSegmentType *codeSegment, int bufferNum)
codeSegmentType *codeSegment;
int bufferNum;
{ {
int line; int line;
int i; int i;
@ -1193,8 +1111,7 @@ printOneCodeBuffer(codeSegment, bufferNum)
} }
void void
printCodeBufferSection(codeBufferSection) printCodeBufferSection(codeRegionType *codeBufferSection)
codeRegionType *codeBufferSection;
{ {
bool anyCodeThereFlag; bool anyCodeThereFlag;
int i; int i;
@ -1212,7 +1129,7 @@ printCodeBufferSection(codeBufferSection)
} }
void void
printCodeBuffers() printCodeBuffers(void)
{ {
printf("absolute code:\n"); printf("absolute code:\n");
printCodeBufferSection(&absoluteCodeRegion); printCodeBufferSection(&absoluteCodeRegion);

86
debugPrint.h Normal file
View File

@ -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

View File

@ -31,6 +31,7 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "debugPrint.h"
#include "y.tab.h" #include "y.tab.h"
@ -39,9 +40,8 @@ int tablevel;
/* Fundamental nop print operation */ /* Fundamental nop print operation */
#define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; } #define nullPrint(thing) if (thing==NULL) { tab(); printf("()\n"); return; }
void void
printCondition(condition) printCondition(conditionType condition)
conditionType condition;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'conditionType'. */ enumerated type 'conditionType'. */
@ -70,8 +70,7 @@ printCondition(condition)
} }
void void
printOperandKind(kind) printOperandKind(operandKindType kind)
operandKindType kind;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'operandKindType'. */ enumerated type 'operandKindType'. */
@ -97,8 +96,7 @@ printOperandKind(kind)
} }
void void
printToken(token) printToken(int token)
int token;
{ {
/* This table MUST be maintained congruently with the set of '#define's in /* This table MUST be maintained congruently with the set of '#define's in
the file 'y.tab.h' as produced by yacc. */ the file 'y.tab.h' as produced by yacc. */
@ -193,8 +191,7 @@ printToken(token)
} }
void void
printOperand(operand) printOperand(operandType *operand)
operandType *operand;
{ {
nullPrint(operand); nullPrint(operand);
tab(); printf("(operand: ["); tab(); printf("(operand: [");
@ -204,15 +201,15 @@ printOperand(operand)
switch (operand->kindOfOperand) { switch (operand->kindOfOperand) {
case EXPRESSION_OPND: case EXPRESSION_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.expressionUnion);
break; break;
case IMMEDIATE_OPND: case IMMEDIATE_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.immediateUnion);
break; break;
case INDIRECT_OPND: case INDIRECT_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.indirectUnion);
break; break;
case A_REGISTER_OPND: case A_REGISTER_OPND:
@ -225,39 +222,39 @@ printOperand(operand)
break; break;
case POST_INDEXED_Y_OPND: case POST_INDEXED_Y_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.postIndexedYUnion);
break; break;
case PRE_INDEXED_X_OPND: case PRE_INDEXED_X_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.preIndexedXUnion);
break; break;
case X_INDEXED_OPND: case X_INDEXED_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.xIndexedUnion);
break; break;
case Y_INDEXED_OPND: case Y_INDEXED_OPND:
printExpression(operand->theOperand); printExpression(operand->theOperand.yIndexedUnion);
break; break;
case X_SELECTED_OPND: case X_SELECTED_OPND:
printIdentifierList(operand->theOperand); printIdentifierList(operand->theOperand.xSelectedUnion);
break; break;
case Y_SELECTED_OPND: case Y_SELECTED_OPND:
printIdentifierList(operand->theOperand); printIdentifierList(operand->theOperand.ySelectedUnion);
break; break;
case PRE_SELECTED_X_OPND: case PRE_SELECTED_X_OPND:
printIdentifierList(operand->theOperand); printIdentifierList(operand->theOperand.preSelectedUnion);
break; break;
case STRING_OPND: case STRING_OPND:
tab(); printf("(string: \"%s\")\n", operand->theOperand); tab(); printf("(string: \"%s\")\n", operand->theOperand.stringUnion);
break; break;
case BLOCK_OPND: case BLOCK_OPND:
printBlock(operand->theOperand); printBlock(operand->theOperand.blockUnion);
break; break;
default: default:

View File

@ -38,8 +38,7 @@ char *m68000 = "68000";
char **mlist; char **mlist;
main(argc, argv) main(int argc, char **argv)
char **argv;
{ {
char *processor = m6502; char *processor = m6502;
int i; int i;

9
emitBranch.h Normal file
View File

@ -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

View File

@ -32,16 +32,17 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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, /* emitRelativeBranch emits a relative branch instruction for the 6502,
branching from the current location given a condition to branch upon and a branching from the current location given a condition to branch upon and a
target address. */ target address. */
void void
emitRelativeBranch(condition, target, fixupLocation) emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation)
conditionType condition;
valueType *target;
valueType fixupLocation[COMPOUND_BRANCH_MAX];
{ {
int i; int i;
@ -139,15 +140,11 @@ emitRelativeBranch(condition, target, fixupLocation)
/* emitJump emits a 6502 jump instruction given the target address */ /* emitJump emits a 6502 jump instruction given the target address */
simpleFixupListType * simpleFixupListType *
emitJump(target, previousFixups) emitJump(valueType *target, simpleFixupListType *previousFixups)
valueType *target;
simpleFixupListType *previousFixups;
{ {
simpleFixupListType *result; simpleFixupListType *result;
valueType picFixup[COMPOUND_BRANCH_MAX]; valueType picFixup[COMPOUND_BRANCH_MAX];
simpleFixupListType *buildSimpleFixupList();
#define JUMP_OPCODE 0x4C #define JUMP_OPCODE 0x4C
result = previousFixups; result = previousFixups;

View File

@ -30,6 +30,10 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 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 */ /* incarnateCodeBuffer causes code buffer space to actually be allocated */
void void
incarnateCodeBuffer(bufferNum, bufferKind) incarnateCodeBuffer(int bufferNum, codeBufferKindType bufferKind)
int bufferNum;
codeBufferKindType bufferKind;
{ {
codeSegmentType *newCodeSegment; codeSegmentType *newCodeSegment;
codeBufferType *newCodeBuffer; codeBufferType *newCodeBuffer;
@ -88,9 +90,7 @@ incarnateCodeBuffer(bufferNum, bufferKind)
care to make sure said buffer actually exists before using it. */ care to make sure said buffer actually exists before using it. */
void void
putByte(address, byteValue) putByte(addressType address, byte byteValue)
addressType address;
byte byteValue;
{ {
int bufferNum; int bufferNum;
int bufferPos; int bufferPos;
@ -131,9 +131,7 @@ putByte(address, byteValue)
buffer */ buffer */
void void
mapByte(address, byteValue) mapByte(int address, byte byteValue)
int address;
byte byteValue;
{ {
if (address < MAXIMUM_ALLOWED_STRUCT_SIZE) if (address < MAXIMUM_ALLOWED_STRUCT_SIZE)
structScratchBuffer[address] = byteValue; structScratchBuffer[address] = byteValue;
@ -144,8 +142,7 @@ mapByte(address, byteValue)
code buffer or the current struct assembly buffer */ code buffer or the current struct assembly buffer */
void void
emitByte(byteValue) emitByte(byte byteValue)
byte byteValue;
{ {
if (debug || emitPrint) if (debug || emitPrint)
if (structNestingDepth == 0) if (structNestingDepth == 0)
@ -165,8 +162,7 @@ emitByte(byteValue)
/* emitWord similarly emits a word */ /* emitWord similarly emits a word */
void void
emitWord(wordValue) emitWord(wordType wordValue)
wordType wordValue;
{ {
byteToWordType convert; byteToWordType convert;
int loByte, hiByte; int loByte, hiByte;
@ -216,8 +212,7 @@ emitWord(wordValue)
/* emitLong similarly emits a long */ /* emitLong similarly emits a long */
void void
emitLong(longValue) emitLong(longType longValue)
longType longValue;
{ {
byteToLongType convert; byteToLongType convert;
int loByte, secondByte, thirdByte, hiByte; int loByte, secondByte, thirdByte, hiByte;
@ -286,8 +281,7 @@ emitLong(longValue)
/* emitByteValue takes the byte to be emitted out of a 'valueType' */ /* emitByteValue takes the byte to be emitted out of a 'valueType' */
void void
emitByteValue(byteValue) emitByteValue(valueType *byteValue)
valueType *byteValue;
{ {
if (byteValue->kindOfValue == ABSOLUTE_VALUE || byteValue->kindOfValue == if (byteValue->kindOfValue == ABSOLUTE_VALUE || byteValue->kindOfValue ==
RELOCATABLE_VALUE || byteValue->kindOfValue == UNDEFINED_VALUE) { RELOCATABLE_VALUE || byteValue->kindOfValue == UNDEFINED_VALUE) {
@ -313,8 +307,7 @@ emitByteValue(byteValue)
/* emitString similarly spits out a string of bytes */ /* emitString similarly spits out a string of bytes */
void void
emitString(string) emitString(stringType *string)
stringType *string;
{ {
if (debug || emitPrint) if (debug || emitPrint)
if (structNestingDepth == 0) if (structNestingDepth == 0)
@ -329,7 +322,7 @@ emitString(string)
nuls in strings, so to speak. We assume that the character 0xFF is not 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 likely to be needed since ASCII (and ATASCII) is a seven bit character
code. */ code. */
while (*string != NULL) while (*string != 0)
if ((*string & 0xFF) == 0xFF) { if ((*string & 0xFF) == 0xFF) {
emitByte('\0'); emitByte('\0');
string++; string++;
@ -342,8 +335,7 @@ emitString(string)
/* emitWordValue emits a word out of a 'valueType' */ /* emitWordValue emits a word out of a 'valueType' */
void void
emitWordValue(wordValue) emitWordValue(valueType *wordValue)
valueType *wordValue;
{ {
if (wordValue->kindOfValue == ABSOLUTE_VALUE || wordValue->kindOfValue == if (wordValue->kindOfValue == ABSOLUTE_VALUE || wordValue->kindOfValue ==
RELOCATABLE_VALUE || wordValue->kindOfValue == UNDEFINED_VALUE) { RELOCATABLE_VALUE || wordValue->kindOfValue == UNDEFINED_VALUE) {
@ -369,8 +361,7 @@ emitWordValue(wordValue)
/* emitLongValue emits a long out of a 'valueType' */ /* emitLongValue emits a long out of a 'valueType' */
void void
emitLongValue(longValue) emitLongValue(valueType *longValue)
valueType *longValue;
{ {
if (longValue->kindOfValue == ABSOLUTE_VALUE || longValue->kindOfValue == if (longValue->kindOfValue == ABSOLUTE_VALUE || longValue->kindOfValue ==
RELOCATABLE_VALUE || longValue->kindOfValue == UNDEFINED_VALUE) { RELOCATABLE_VALUE || longValue->kindOfValue == UNDEFINED_VALUE) {
@ -396,9 +387,7 @@ emitLongValue(longValue)
/* pokeByteValue is like 'emitByte' but it's random access */ /* pokeByteValue is like 'emitByte' but it's random access */
void void
pokeByteValue(location, value) pokeByteValue(addressType location, valueType *value)
addressType location;
valueType *value;
{ {
currentLocationCounter.value = location; currentLocationCounter.value = location;
emitByteValue(value); emitByteValue(value);
@ -408,9 +397,7 @@ pokeByteValue(location, value)
/* ditto pokeWordValue */ /* ditto pokeWordValue */
void void
pokeWordValue(location, value) pokeWordValue(addressType location, valueType *value)
addressType location;
valueType *value;
{ {
currentLocationCounter.value = location; currentLocationCounter.value = location;
emitWordValue(value); emitWordValue(value);
@ -420,9 +407,7 @@ pokeWordValue(location, value)
/* ditto pokeLongValue */ /* ditto pokeLongValue */
void void
pokeLongValue(location, value) pokeLongValue(addressType location, valueType *value)
addressType location;
valueType *value;
{ {
currentLocationCounter.value = location; currentLocationCounter.value = location;
emitLongValue(value); emitLongValue(value);
@ -433,9 +418,7 @@ pokeLongValue(location, value)
relative branches */ relative branches */
void void
pokeRelativeByteValue(location, value) pokeRelativeByteValue(addressType location, valueType *value)
addressType location;
valueType *value;
{ {
int offset; int offset;
@ -456,9 +439,7 @@ pokeRelativeByteValue(location, value)
relative branches */ relative branches */
void void
pokeRelativeWordValue(location, value) pokeRelativeWordValue(addressType location, valueType *value)
addressType location;
valueType *value;
{ {
int offset; int offset;
@ -475,8 +456,7 @@ pokeRelativeWordValue(location, value)
/* getByte fetches a byte back out of the labyrinth of code buffers */ /* getByte fetches a byte back out of the labyrinth of code buffers */
byte byte
getByte(address) getByte(addressType address)
addressType address;
{ {
int bufferNum; int bufferNum;
int bufferPos; int bufferPos;
@ -494,8 +474,7 @@ getByte(address)
} }
void void
emitRelativeByteOffset(target) emitRelativeByteOffset(valueType *target)
valueType *target;
{ {
int saveTargetOffset; int saveTargetOffset;
@ -512,8 +491,7 @@ emitRelativeByteOffset(target)
} }
void void
emitRelativeWordOffset(target) emitRelativeWordOffset(valueType *target)
valueType *target;
{ {
int saveTargetOffset; int saveTargetOffset;
@ -531,9 +509,7 @@ emitRelativeWordOffset(target)
has become known. */ has become known. */
void void
fixupBranch(location, target) fixupBranch(valueType *location, valueType target)
valueType location[COMPOUND_BRANCH_MAX];
valueType target;
{ {
valueType saveCurrentLocation; valueType saveCurrentLocation;
int saveTargetOffset; int saveTargetOffset;
@ -554,9 +530,7 @@ fixupBranch(location, target)
/* fixupJump similarly repairs a jump */ /* fixupJump similarly repairs a jump */
void void
fixupJump(locations, target) fixupJump(simpleFixupListType *locations, valueType target)
simpleFixupListType *locations;
valueType target;
{ {
valueType saveCurrentLocation; valueType saveCurrentLocation;
simpleFixupListType *oldLocation; simpleFixupListType *oldLocation;

27
emitStuff.h Normal file
View File

@ -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

108
encode.c
View File

@ -31,6 +31,11 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "y.tab.h" #include "y.tab.h"
#include "encode.h"
#include "debugPrint.h"
#include "errorStuff.h"
#include "parserMisc.h"
#include "semanticMisc.h"
#include "slinkyExpressions.h" #include "slinkyExpressions.h"
#define nullEncode(thing) if (thing==NULL) return(TRUE); #define nullEncode(thing) if (thing==NULL) return(TRUE);
@ -38,9 +43,8 @@
bool encodingFunction; bool encodingFunction;
bool bool
encodeByte(aByte) encodeByte(byte aByte)
byte aByte;
{ {
if (expressionBufferSize < EXPRESSION_BUFFER_LIMIT) { if (expressionBufferSize < EXPRESSION_BUFFER_LIMIT) {
expressionBuffer[expressionBufferSize++] = aByte; expressionBuffer[expressionBufferSize++] = aByte;
@ -52,8 +56,7 @@ encodeByte(aByte)
} }
bool bool
encodeBigword(bigword) encodeBigword(int bigword)
int bigword;
{ {
int i; int i;
for (i=0; i<sizeof(int); ++i) { for (i=0; i<sizeof(int); ++i) {
@ -65,8 +68,7 @@ encodeBigword(bigword)
} }
bool bool
encodeAssignmentTerm(assignmentTerm) encodeAssignmentTerm(binopTermType *assignmentTerm)
binopTermType *assignmentTerm;
{ {
nullEncode(assignmentTerm); nullEncode(assignmentTerm);
if ((assignmentKindType)assignmentTerm->binop != ASSIGN_ASSIGN) { if ((assignmentKindType)assignmentTerm->binop != ASSIGN_ASSIGN) {
@ -82,11 +84,8 @@ encodeAssignmentTerm(assignmentTerm)
} }
bool bool
encodeBinopTerm(binopTerm) encodeBinopTerm(binopTermType *binopTerm)
binopTermType *binopTerm;
{ {
bool encodeExpression();
nullEncode(binopTerm); nullEncode(binopTerm);
return ( return (
encodeByte(BINOP_TAG) && encodeByte(BINOP_TAG) &&
@ -97,8 +96,7 @@ encodeBinopTerm(binopTerm)
} }
bool bool
encodeCondition(condition) encodeCondition(conditionType condition)
conditionType condition;
{ {
return( return(
encodeByte(CONDITION_CODE_TAG) && encodeByte(CONDITION_CODE_TAG) &&
@ -107,8 +105,7 @@ encodeCondition(condition)
} }
int int
functionNumber(function) functionNumber(functionDefinitionType *function)
functionDefinitionType *function;
{ {
if (function->ordinal == -1) { if (function->ordinal == -1) {
function->ordinal = externalFunctionCount++; function->ordinal = externalFunctionCount++;
@ -125,16 +122,13 @@ functionNumber(function)
} }
bool bool
encodeFunctionCall(functionCall) encodeFunctionCall(functionCallTermType *functionCall)
functionCallTermType *functionCall;
{ {
functionDefinitionType *theFunction; functionDefinitionType *theFunction;
int functionOrdinal; int functionOrdinal;
symbolInContextType *workingContext; symbolInContextType *workingContext;
operandListType *parameterList; operandListType *parameterList;
symbolInContextType *getWorkingContext();
nullEncode(functionCall); nullEncode(functionCall);
workingContext = getWorkingContext(functionCall->functionName); workingContext = getWorkingContext(functionCall->functionName);
if (isFunction(workingContext)) { if (isFunction(workingContext)) {
@ -178,14 +172,13 @@ encodeFunctionCall(functionCall)
} }
bool bool
encodeHere() encodeHere(void)
{ {
return(encodeByte(HERE_TAG)); return(encodeByte(HERE_TAG));
} }
bool bool
encodeIdentifier(identifier) encodeIdentifier(symbolTableEntryType *identifier)
symbolTableEntryType *identifier;
{ {
symbolInContextType *workingContext; symbolInContextType *workingContext;
environmentType *saveEnvironment; environmentType *saveEnvironment;
@ -249,8 +242,7 @@ encodeIdentifier(identifier)
} }
bool bool
encodeNumber(number) encodeNumber(numberTermType number)
numberTermType number;
{ {
return( return(
encodeByte(NUMBER_TAG) && encodeByte(NUMBER_TAG) &&
@ -259,8 +251,7 @@ encodeNumber(number)
} }
bool bool
encodeRelocatableNumber(number) encodeRelocatableNumber(numberTermType number)
numberTermType number;
{ {
return( return(
encodeByte(RELOCATABLE_TAG) && encodeByte(RELOCATABLE_TAG) &&
@ -269,8 +260,7 @@ encodeRelocatableNumber(number)
} }
bool bool
encodeOperand(operand) encodeOperand(operandType *operand)
operandType *operand;
{ {
switch (operand->kindOfOperand) { switch (operand->kindOfOperand) {
case EXPRESSION_OPND: case EXPRESSION_OPND:
@ -280,7 +270,7 @@ encodeOperand(operand)
case PRE_INDEXED_X_OPND: case PRE_INDEXED_X_OPND:
case X_INDEXED_OPND: case X_INDEXED_OPND:
case Y_INDEXED_OPND: case Y_INDEXED_OPND:
return(encodeExpression(operand->theOperand)); return(encodeExpression(operand->theOperand.expressionUnion));
case A_REGISTER_OPND: case A_REGISTER_OPND:
case X_REGISTER_OPND: case X_REGISTER_OPND:
@ -295,7 +285,7 @@ encodeOperand(operand)
return(FALSE); return(FALSE);
case STRING_OPND: case STRING_OPND:
return(encodeString(operand->theOperand)); return(encodeString(operand->theOperand.stringUnion));
case BLOCK_OPND: case BLOCK_OPND:
error(BLOCK_OPERAND_IN_OBJECT_EXPRESSION_ERROR); error(BLOCK_OPERAND_IN_OBJECT_EXPRESSION_ERROR);
@ -304,8 +294,7 @@ encodeOperand(operand)
} }
bool bool
encodePostopTerm(postopTerm) encodePostopTerm(postOpTermType *postopTerm)
postOpTermType *postopTerm;
{ {
nullEncode(postopTerm); nullEncode(postopTerm);
return( return(
@ -316,8 +305,7 @@ encodePostopTerm(postopTerm)
} }
bool bool
encodePreopTerm(preopTerm) encodePreopTerm(preOpTermType *preopTerm)
preOpTermType *preopTerm;
{ {
nullEncode(preopTerm); nullEncode(preopTerm);
return( return(
@ -328,8 +316,7 @@ encodePreopTerm(preopTerm)
} }
bool bool
encodeString(string) encodeString(stringType *string)
stringType *string;
{ {
if (!encodeByte(STRING_TAG)) if (!encodeByte(STRING_TAG))
return(FALSE); return(FALSE);
@ -341,8 +328,7 @@ encodeString(string)
} }
bool bool
encodeUnopTerm(unopTerm) encodeUnopTerm(unopTermType *unopTerm)
unopTermType *unopTerm;
{ {
nullEncode(unopTerm); nullEncode(unopTerm);
return( return(
@ -353,8 +339,7 @@ encodeUnopTerm(unopTerm)
} }
bool bool
encodeValue(value) encodeValue(valueType *value)
valueType *value;
{ {
switch (value->kindOfValue) { switch (value->kindOfValue) {
case ABSOLUTE_VALUE: case ABSOLUTE_VALUE:
@ -390,8 +375,7 @@ encodeValue(value)
} }
bool bool
encodeExpression(expression) encodeExpression(expressionType *expression)
expressionType *expression;
{ {
nullEncode(expression); nullEncode(expression);
switch (expression->kindOfTerm) { switch (expression->kindOfTerm) {
@ -461,8 +445,7 @@ encodeExpression(expression)
} }
bool bool
encodeAssertStatement(assertStatement) encodeAssertStatement(assertStatementBodyType *assertStatement)
assertStatementBodyType *assertStatement;
{ {
return( return(
encodeByte(ASSERT_TAG) && encodeByte(ASSERT_TAG) &&
@ -472,8 +455,7 @@ encodeAssertStatement(assertStatement)
} }
bool bool
encodeFreturnStatement(freturnStatement) encodeFreturnStatement(freturnStatementBodyType *freturnStatement)
freturnStatementBodyType *freturnStatement;
{ {
return( return(
encodeByte(FRETURN_TAG) && encodeByte(FRETURN_TAG) &&
@ -482,8 +464,7 @@ encodeFreturnStatement(freturnStatement)
} }
bool bool
encodeMdefineStatement(mdefineStatement) encodeMdefineStatement(defineStatementBodyType *mdefineStatement)
defineStatementBodyType *mdefineStatement;
{ {
return( return(
encodeByte(MDEFINE_TAG) && encodeByte(MDEFINE_TAG) &&
@ -493,8 +474,7 @@ encodeMdefineStatement(mdefineStatement)
} }
bool bool
encodeMdoUntilStatement(mdoUntilStatement) encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement)
mdoUntilStatementBodyType *mdoUntilStatement;
{ {
return( return(
encodeByte(MDOUNTIL_TAG) && encodeByte(MDOUNTIL_TAG) &&
@ -504,8 +484,7 @@ encodeMdoUntilStatement(mdoUntilStatement)
} }
bool bool
encodeMdoWhileStatement(mdoWhileStatement) encodeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement)
mdoWhileStatementBodyType *mdoWhileStatement;
{ {
return( return(
encodeByte(MDOWHILE_TAG) && encodeByte(MDOWHILE_TAG) &&
@ -515,8 +494,7 @@ encodeMdoWhileStatement(mdoWhileStatement)
} }
bool bool
encodeMforStatement(mforStatement) encodeMforStatement(mforStatementBodyType *mforStatement)
mforStatementBodyType *mforStatement;
{ {
return( return(
encodeByte(MFOR_TAG) && encodeByte(MFOR_TAG) &&
@ -528,20 +506,18 @@ encodeMforStatement(mforStatement)
} }
bool bool
encodeMifStatement(mifStatement) encodeMifStatement(mifStatementBodyType *mifStatement)
mifStatementBodyType *mifStatement;
{ {
return( return(
encodeByte(MIF_TAG) && encodeByte(MIF_TAG) &&
encodeExpression(mifStatement->mifCondition) && encodeExpression(mifStatement->mifCondition) &&
encodeBlock(mifStatement->mifConsequence) && encodeBlock(mifStatement->mifConsequence) &&
encodeBlock(mifStatement->mifContinuation) encodeBlock(mifStatement->mifContinuation.mifBlockUnion)
); );
} }
bool bool
encodeMswitchStatement(mswitchStatement) encodeMswitchStatement(mswitchStatementBodyType *mswitchStatement)
mswitchStatementBodyType *mswitchStatement;
{ {
caseListType *caseList; caseListType *caseList;
caseType *theCase; caseType *theCase;
@ -565,8 +541,7 @@ encodeMswitchStatement(mswitchStatement)
} }
bool bool
encodeMvariableStatement(mvariableStatement) encodeMvariableStatement(mvariableStatementBodyType *mvariableStatement)
mvariableStatementBodyType *mvariableStatement;
{ {
int length; int length;
@ -586,8 +561,7 @@ encodeMvariableStatement(mvariableStatement)
} }
bool bool
encodeMwhileStatement(mwhileStatement) encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement)
mwhileStatementBodyType *mwhileStatement;
{ {
return( return(
encodeByte(MWHILE_TAG) && encodeByte(MWHILE_TAG) &&
@ -597,8 +571,7 @@ encodeMwhileStatement(mwhileStatement)
} }
bool bool
encodeStatement(statement) encodeStatement(statementType *statement)
statementType *statement;
{ {
switch(statement->kindOfStatement) { switch(statement->kindOfStatement) {
@ -638,7 +611,7 @@ encodeStatement(statement)
return(encodeFreturnStatement(statement->statementBody.freturnUnion)); return(encodeFreturnStatement(statement->statementBody.freturnUnion));
case GROUP_STATEMENT: case GROUP_STATEMENT:
return(encodeBlock(statement->statementBody)); return(encodeBlock(statement->statementBody.groupUnion));
case MDEFINE_STATEMENT: case MDEFINE_STATEMENT:
return(encodeMdefineStatement(statement->statementBody.defineUnion)); return(encodeMdefineStatement(statement->statementBody.defineUnion));
@ -678,8 +651,7 @@ encodeStatement(statement)
} }
bool bool
encodeBlock(block) encodeBlock(blockType *block)
blockType *block;
{ {
if (!encodeByte(BLOCK_TAG)) if (!encodeByte(BLOCK_TAG))
return(FALSE); return(FALSE);

37
encode.h Normal file
View File

@ -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

View File

@ -29,6 +29,10 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "errorStuff.h"
#include "initialize.h"
#include <stdarg.h>
bool nullStatementFlag; bool nullStatementFlag;
@ -38,34 +42,28 @@ bool nullStatementFlag;
from the booboo. */ from the booboo. */
void void
puntOnError(theError, arg1, arg2, arg3) puntOnError(errorType theError, ...)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
va_list ap;
char c; char c;
void error();
while ((c = getc(input))!='\n' && c!=EOF) while ((c = getc(input))!='\n' && c!=EOF)
; ;
ungetc(c, input); 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 */ /* printErrorMessage is the general error message handler */
void void
printErrorMessage(theError, arg1, arg2, arg3) printErrorMessage(errorType theError, va_list ap)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'errorType'. */ enumerated type 'errorType'. */
void fatalError();
static bool dying = FALSE; static bool dying = FALSE;
static char *errorMessageStrings[] = { static char *errorMessageStrings[] = {
@ -232,7 +230,7 @@ printErrorMessage(theError, arg1, arg2, arg3)
lastErrorLine = currentLineNumber; lastErrorLine = currentLineNumber;
printf("\"%s\", line %d: ", currentFileName, currentLineNumber printf("\"%s\", line %d: ", currentFileName, currentLineNumber
-1); -1);
printf(errorMessageStrings[(int)theError], arg1, arg2, arg3); vprintf(errorMessageStrings[(int)theError], ap);
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
} }
@ -243,45 +241,48 @@ printErrorMessage(theError, arg1, arg2, arg3)
} }
void void
error(theError, arg1, arg2, arg3) error(errorType theError, ...)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
printErrorMessage(theError, arg1, arg2, arg3); va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
errorFlag = TRUE; errorFlag = TRUE;
} }
void void
warning(theError, arg1, arg2, arg3) verror(errorType theError, va_list ap)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
printErrorMessage(theError, arg1, arg2, arg3); printErrorMessage(theError, ap);
errorFlag = TRUE;
} }
void void
fatalError(theError, arg1, arg2, arg3) warning(errorType theError, ...)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
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(); chokePukeAndDie();
} }
void void
fatalSystemError(theError, arg1, arg2, arg3) fatalSystemError(errorType theError, ...)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
printErrorMessage(theError, arg1, arg2, arg3); va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
perror("Unix says"); perror("Unix says");
chokePukeAndDie(); chokePukeAndDie();
} }
@ -290,8 +291,7 @@ fatalSystemError(theError, arg1, arg2, arg3)
the error message as a string (this is almost always 'syntax error'). */ the error message as a string (this is almost always 'syntax error'). */
void void
yyerror(s) yyerror(char *s)
char *s;
{ {
printf("\"%s\", line %d: %s\n", currentFileName, currentLineNumber,s); printf("\"%s\", line %d: %s\n", currentFileName, currentLineNumber,s);
fflush(stdout); fflush(stdout);
@ -305,8 +305,7 @@ yyerror(s)
in a sentence). */ in a sentence). */
char * char *
usageString(usageKind) usageString(symbolUsageKindType usageKind)
symbolUsageKindType usageKind;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'symbolUsageKindType'. */ enumerated type 'symbolUsageKindType'. */
@ -337,8 +336,7 @@ usageString(usageKind)
/* valueKindString similarly deals with the different kinds of values. */ /* valueKindString similarly deals with the different kinds of values. */
char * char *
valueKindString(valueKind) valueKindString(valueKindType valueKind)
valueKindType valueKind;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -367,8 +365,7 @@ valueKindString(valueKind)
/* assignmentString similarly handles assignments */ /* assignmentString similarly handles assignments */
char * char *
assignmentString(assignment) assignmentString(assignmentKindType assignment)
assignmentKindType assignment;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'assignmentKindType'. */ enumerated type 'assignmentKindType'. */

20
errorStuff.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef ERROR_STUFF_H_
#define ERROR_STUFF_H_
#include "macrossTypes.h"
#include <stdarg.h>
void puntOnError(errorType theError, ...);
void printErrorMessage(errorType theError, va_list ap);
void error(errorType theError, ...);
void verror(errorType theError, va_list ap);
void warning(errorType theError, ...);
void fatalError(errorType theError, ...);
void fatalSystemError(errorType theError, ...);
void yyerror(char *s);
char *usageString(symbolUsageKindType usageKind);
char *valueKindString(valueKindType valueKind);
char *assignmentString(assignmentKindType assignment);
#endif

View File

@ -31,6 +31,19 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "y.tab.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 <string.h>
operandType *dbOperand; /* safe temps for dbx hacking */ operandType *dbOperand; /* safe temps for dbx hacking */
expressionType *dbExpression; expressionType *dbExpression;
@ -60,10 +73,8 @@ stringType *dbString;
#define moreStuff(f) (generatingFixup ? moreExpression(f) : moreText(f)) #define moreStuff(f) (generatingFixup ? moreExpression(f) : moreText(f))
#define moreStuff1(f,x) (generatingFixup? moreExpression(f,x) : moreText(f,x)) #define moreStuff1(f,x) (generatingFixup? moreExpression(f,x) : moreText(f,x))
anyOldThing * anyOldThing *
arrayLookup(arrayTerm, kindOfThing) arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing)
arrayTermType *arrayTerm;
valueKindType *kindOfThing;
{ {
valueType *arrayValue; valueType *arrayValue;
valueType *indexValue; valueType *indexValue;
@ -71,8 +82,6 @@ arrayLookup(arrayTerm, kindOfThing)
int index; int index;
stringType *string; stringType *string;
valueType *evaluateExpression();
*kindOfThing = FAIL; *kindOfThing = FAIL;
arrayValue = evaluateExpression(arrayTerm->arrayName, NO_FIXUP); arrayValue = evaluateExpression(arrayTerm->arrayName, NO_FIXUP);
if (arrayValue->kindOfValue == FAIL) if (arrayValue->kindOfValue == FAIL)
@ -122,8 +131,7 @@ arrayLookup(arrayTerm, kindOfThing)
} }
valueType * valueType *
evaluateArrayTerm(arrayTerm) evaluateArrayTerm(arrayTermType *arrayTerm)
arrayTermType *arrayTerm;
{ {
anyOldThing *resultThing; anyOldThing *resultThing;
valueKindType kindOfResult; valueKindType kindOfResult;
@ -133,9 +141,6 @@ evaluateArrayTerm(arrayTerm)
environmentType *saveEnvironment; environmentType *saveEnvironment;
bool saveExpansion; bool saveExpansion;
valueType *newValue();
valueType *evaluateOperand();
expansionOff(); expansionOff();
resultThing = arrayLookup(arrayTerm, &kindOfResult); resultThing = arrayLookup(arrayTerm, &kindOfResult);
expansionOn(); expansionOn();
@ -170,9 +175,7 @@ evaluateArrayTerm(arrayTerm)
} }
valueType * valueType *
evaluateAssignmentTerm(assignmentTerm, kindOfFixup) evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup)
binopTermType *assignmentTerm;
fixupKindType kindOfFixup;
{ {
symbolTableEntryType *targetSymbol; symbolTableEntryType *targetSymbol;
valueType *target; valueType *target;
@ -187,15 +190,6 @@ evaluateAssignmentTerm(assignmentTerm, kindOfFixup)
char *charPtr; char *charPtr;
char objectChar; char objectChar;
symbolTableEntryType *effectiveSymbol();
valueType *evaluateExpressionInternally();
valueKindType addValueKind();
valueKindType selectValueKind();
valueKindType subValueKind();
valueKindType opValueKind();
valueType *makeUndefinedValue();
valueType *newValue();
nullEvaluate(assignmentTerm); nullEvaluate(assignmentTerm);
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
stringAssign = FALSE; stringAssign = FALSE;
@ -373,10 +367,7 @@ evaluateAssignmentTerm(assignmentTerm, kindOfFixup)
} }
valueType * valueType *
evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup) evaluateBinopTerm(binopTermType *binopTerm, bool isTopLevel, fixupKindType kindOfFixup)
binopTermType *binopTerm;
bool isTopLevel;
fixupKindType kindOfFixup;
{ {
valueType *leftOperand; valueType *leftOperand;
valueType *rightOperand; valueType *rightOperand;
@ -386,11 +377,6 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup)
operandKindType resultAddressMode; operandKindType resultAddressMode;
valueType *result; valueType *result;
symbolInContextType *getWorkingContext();
valueType *evaluateExpressionInternally();
valueType *newValue();
valueType *makeUndefinedValue();
nullEvaluate(binopTerm); nullEvaluate(binopTerm);
if (binopTerm->binop != SUB && binopTerm->binop != ADD) if (binopTerm->binop != SUB && binopTerm->binop != ADD)
isTopLevel = FALSE; isTopLevel = FALSE;
@ -595,20 +581,14 @@ evaluateBinopTerm(binopTerm, isTopLevel, kindOfFixup)
} }
valueType * valueType *
evaluateCondition(condition) evaluateCondition(conditionType condition)
conditionType condition;
{ {
valueType *newValue();
expand(moreExpression("%s", conditionString(condition))); expand(moreExpression("%s", conditionString(condition)));
return(newValue(CONDITION_VALUE, condition, EXPRESSION_OPND)); return(newValue(CONDITION_VALUE, condition, EXPRESSION_OPND));
} }
valueType * valueType *
evaluateBuiltInFunctionCall(workingContext, parameters, kindOfFixup) evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup)
symbolInContextType *workingContext;
operandListType *parameters;
fixupKindType kindOfFixup;
{ {
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
return((*builtInFunctionTable[workingContext->value->value]. return((*builtInFunctionTable[workingContext->value->value].
@ -616,10 +596,7 @@ evaluateBuiltInFunctionCall(workingContext, parameters, kindOfFixup)
} }
valueType * valueType *
evaluateFunctionCall(functionCall, kindOfFixup, isStandalone) evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone)
functionCallTermType *functionCall;
fixupKindType kindOfFixup;
bool isStandalone;
{ {
functionDefinitionType *theFunction; functionDefinitionType *theFunction;
int numberBound; int numberBound;
@ -633,10 +610,6 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone)
valueType *result; valueType *result;
bool saveExpansion; bool saveExpansion;
symbolInContextType *getWorkingContext();
valueType *evaluateBuiltInFunctionCall();
valueType *newValue();
nullEvaluate(functionCall); nullEvaluate(functionCall);
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
pushEnvironment(newEnvironment); pushEnvironment(newEnvironment);
@ -703,9 +676,8 @@ evaluateFunctionCall(functionCall, kindOfFixup, isStandalone)
} }
valueType * valueType *
evaluateHere() evaluateHere(void)
{ {
valueType *newValue();
valueType *result; valueType *result;
expand(moreExpression("here")); expand(moreExpression("here"));
@ -716,10 +688,7 @@ evaluateHere()
} }
valueType * valueType *
evaluateIdentifier(identifier, isTopLevel, kindOfFixup) evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup)
symbolTableEntryType *identifier;
bool isTopLevel;
fixupKindType kindOfFixup;
{ {
symbolInContextType *workingContext; symbolInContextType *workingContext;
valueType *resultValue; valueType *resultValue;
@ -727,11 +696,6 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup)
environmentType *saveEnvironment; environmentType *saveEnvironment;
bool saveExpansion; bool saveExpansion;
valueType *newValue();
valueType *evaluateOperand();
symbolInContextType *getWorkingContext();
symbolTableEntryType *generateLocalLabel();
nullEvaluate(identifier); nullEvaluate(identifier);
identifier->referenceCount++; identifier->referenceCount++;
if (symbName(identifier)[0] == '$') if (symbName(identifier)[0] == '$')
@ -848,18 +812,14 @@ evaluateIdentifier(identifier, isTopLevel, kindOfFixup)
} }
valueType * valueType *
evaluateNumber(number) evaluateNumber(numberTermType number)
numberTermType number;
{ {
valueType *newValue();
expand(moreExpression("0x%x", number)); expand(moreExpression("0x%x", number));
return(newValue(ABSOLUTE_VALUE, number, EXPRESSION_OPND)); return(newValue(ABSOLUTE_VALUE, number, EXPRESSION_OPND));
} }
valueType * valueType *
evaluatePostopTerm(postopTerm) evaluatePostopTerm(postOpTermType *postopTerm)
postOpTermType *postopTerm;
{ {
valueType *theOperand; valueType *theOperand;
valueType **theOperandPtr; valueType **theOperandPtr;
@ -868,9 +828,6 @@ evaluatePostopTerm(postopTerm)
symbolInContextType *workingContext; symbolInContextType *workingContext;
symbolTableEntryType *targetSymbol; symbolTableEntryType *targetSymbol;
symbolTableEntryType *effectiveSymbol();
symbolInContextType *getWorkingContext();
nullEvaluate(postopTerm); nullEvaluate(postopTerm);
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
if (postopTerm->postOpArgument->kindOfTerm == IDENTIFIER_EXPR) { if (postopTerm->postOpArgument->kindOfTerm == IDENTIFIER_EXPR) {
@ -929,8 +886,7 @@ evaluatePostopTerm(postopTerm)
} }
valueType * valueType *
evaluatePreopTerm(preopTerm) evaluatePreopTerm(preOpTermType *preopTerm)
preOpTermType *preopTerm;
{ {
valueType *theOperand; valueType *theOperand;
valueType *result; valueType *result;
@ -939,9 +895,6 @@ evaluatePreopTerm(preopTerm)
symbolInContextType *workingContext; symbolInContextType *workingContext;
symbolTableEntryType *targetSymbol; symbolTableEntryType *targetSymbol;
symbolTableEntryType *effectiveSymbol();
symbolInContextType *getWorkingContext();
nullEvaluate(preopTerm); nullEvaluate(preopTerm);
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
if (preopTerm->preOpArgument->kindOfTerm == IDENTIFIER_EXPR) { if (preopTerm->preOpArgument->kindOfTerm == IDENTIFIER_EXPR) {
@ -1000,10 +953,8 @@ evaluatePreopTerm(preopTerm)
} }
valueType * valueType *
evaluateString(string) evaluateString(stringType *string)
stringType *string;
{ {
valueType *newValue();
stringType *newString; stringType *newString;
expand(moreExpression("\"%s\"", string)); expand(moreExpression("\"%s\"", string));
@ -1013,9 +964,7 @@ evaluateString(string)
} }
valueType * valueType *
evaluateUnopTerm(unopTerm, kindOfFixup) evaluateUnopTerm(unopTermType *unopTerm, fixupKindType kindOfFixup)
unopTermType *unopTerm;
fixupKindType kindOfFixup;
{ {
valueType *theOperand; valueType *theOperand;
valueKindType resultKindOfValue; valueKindType resultKindOfValue;
@ -1023,11 +972,6 @@ evaluateUnopTerm(unopTerm, kindOfFixup)
operandKindType resultAddressMode; operandKindType resultAddressMode;
valueType *result; valueType *result;
valueKindType unopValueKind();
valueType *newValue();
valueType *evaluateExpressionInternally();
valueType *makeUndefinedValue();
nullEvaluate(unopTerm); nullEvaluate(unopTerm);
expand(moreExpression("%s", tokenString(unopTerm->unop))); expand(moreExpression("%s", tokenString(unopTerm->unop)));
theOperand = evaluateExpressionInternally(unopTerm->unopArgument, theOperand = evaluateExpressionInternally(unopTerm->unopArgument,
@ -1072,11 +1016,7 @@ evaluateUnopTerm(unopTerm, kindOfFixup)
} }
valueType * valueType *
evaluateExpressionInternally(expression, isTopLevel, kindOfFixup,isStandalone) evaluateExpressionInternally(expressionType *expression, bool isTopLevel, fixupKindType kindOfFixup, bool isStandalone)
expressionType *expression;
bool isTopLevel;
fixupKindType kindOfFixup;
bool isStandalone;
{ {
valueType *result; valueType *result;
@ -1166,9 +1106,7 @@ evaluateExpressionInternally(expression, isTopLevel, kindOfFixup,isStandalone)
} }
valueType * valueType *
evaluateExpression(expression, kindOfFixup) evaluateExpression(expressionType *expression, fixupKindType kindOfFixup)
expressionType *expression;
fixupKindType kindOfFixup;
{ {
valueType *result; valueType *result;
@ -1189,8 +1127,7 @@ evaluateExpression(expression, kindOfFixup)
} }
void void
evaluateExpressionStandalone(expression) evaluateExpressionStandalone(expressionType *expression)
expressionType *expression;
{ {
bool saveExpansion; bool saveExpansion;
valueType *expressionResult; valueType *expressionResult;
@ -1210,24 +1147,17 @@ evaluateExpressionStandalone(expression)
} }
valueType * valueType *
evaluateDefineExpression(expression) evaluateDefineExpression(expressionType *expression)
expressionType *expression;
{ {
valueType *newValue();
expressionType *generateFixupExpression();
operandType *buildOperand();
nullEvaluate(expression); nullEvaluate(expression);
return(newValue(OPERAND_VALUE, buildOperand(EXPRESSION_OPND, return(newValue(OPERAND_VALUE, buildOperand(EXPRESSION_OPND,
generateFixupExpression(expression)), EXPRESSION_OPND)); generateFixupExpression(expression)), EXPRESSION_OPND));
} }
valueType * valueType *
evaluateSelectionList(selectionList) evaluateSelectionList(selectionListType *selectionList)
selectionListType *selectionList;
{ {
int offset; int offset;
valueType *newValue();
offset = 0; offset = 0;
while (selectionList != NULL) { while (selectionList != NULL) {

26
expressionSemantics.h Normal file
View File

@ -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

View File

@ -30,6 +30,14 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 */ operandType *dbOperand; /* safe temps for dbx hacking */
expressionType *dbExpression; expressionType *dbExpression;
@ -57,12 +65,10 @@ stringType *dbString = "graphics2.m";
The routines below collectively duplicate expressions for later evaluation. The routines below collectively duplicate expressions for later evaluation.
*/ */
expressionType * expressionType *
generateFixupExpression(expression) generateFixupExpression(expressionType *expression)
expressionType *expression;
{ {
expressionType *result; expressionType *result;
expressionType *duplicateExpressionForFixup();
generatingFixup = TRUE; generatingFixup = TRUE;
result = duplicateExpressionForFixup(expression, TRUE, FALSE); result = duplicateExpressionForFixup(expression, TRUE, FALSE);
@ -71,10 +77,7 @@ generateFixupExpression(expression)
} }
expressionType * expressionType *
duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand) duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand)
expressionType *expression;
bool isTopLevel;
bool isSpecialFunctionOperand;
{ {
expressionType *result; expressionType *result;
expressionType *originalResult; expressionType *originalResult;
@ -85,16 +88,6 @@ duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand)
environmentType *saveEnvironment; environmentType *saveEnvironment;
bool saveExpansion; bool saveExpansion;
operandType *duplicateOperandForFixup();
symbolInContextType *getWorkingContext();
functionCallTermType *duplicateFunctionCall();
expressionType *duplicateArrayReference();
valueType *evaluateIdentifier();
valueType *evaluateHere();
valueType *newValue();
symbolTableEntryType *generateLocalLabel();
stringType *saveString();
nullDup(expression); nullDup(expression);
result = originalResult = typeAlloc(expressionType); result = originalResult = typeAlloc(expressionType);
*result = *expression; *result = *expression;
@ -280,15 +273,12 @@ duplicateExpressionForFixup(expression, isTopLevel, isSpecialFunctionOperand)
} }
functionCallTermType * functionCallTermType *
duplicateFunctionCall(functionCall) duplicateFunctionCall(functionCallTermType *functionCall)
functionCallTermType *functionCall;
{ {
functionCallTermType *result; functionCallTermType *result;
operandListType **argument; operandListType **argument;
operandListType *parameterList; operandListType *parameterList;
operandListType *duplicateOperandForFixup();
result = typeAlloc(functionCallTermType); result = typeAlloc(functionCallTermType);
result->functionName = functionCall->functionName; result->functionName = functionCall->functionName;
expand(moreExpression("%s(", symbName(functionCall->functionName))); expand(moreExpression("%s(", symbName(functionCall->functionName)));
@ -310,8 +300,7 @@ duplicateFunctionCall(functionCall)
expressionType * expressionType *
duplicateArrayReference(arrayTerm) duplicateArrayReference(arrayTermType *arrayTerm)
arrayTermType *arrayTerm;
{ {
anyOldThing *resultThing; anyOldThing *resultThing;
valueKindType kindOfResult; valueKindType kindOfResult;
@ -322,10 +311,6 @@ duplicateArrayReference(arrayTerm)
bool saveExpansion; bool saveExpansion;
operandType *newOperand; operandType *newOperand;
valueType *newValue();
operandType *duplicateOperandForFixup();
anyOldThing *arrayLookup();
expansionOff(); expansionOff();
resultThing = arrayLookup(arrayTerm, &kindOfResult); resultThing = arrayLookup(arrayTerm, &kindOfResult);
expansionOn(); expansionOn();

11
fixups.h Normal file
View File

@ -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

197
garbage.c
View File

@ -29,16 +29,16 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "garbage.h"
#include "operandStuff.h"
#include "parserMisc.h"
#include "y.tab.h" #include "y.tab.h"
#define nullFree(thing) if (thing == NULL) return; #define nullFree(thing) if (thing == NULL) return;
void void
freeArrayTerm(arrayTerm) freeArrayTerm(arrayTermType *arrayTerm)
arrayTermType *arrayTerm;
{ {
void freeExpression();
nullFree(arrayTerm); nullFree(arrayTerm);
freeExpression(arrayTerm->arrayName); freeExpression(arrayTerm->arrayName);
freeExpression(arrayTerm->arrayIndex); freeExpression(arrayTerm->arrayIndex);
@ -46,22 +46,16 @@ freeArrayTerm(arrayTerm)
} }
void void
freeAssignmentTerm(assignmentTerm) freeAssignmentTerm(binopTermType *assignmentTerm)
binopTermType *assignmentTerm;
{ {
void freeExpression();
nullFree(assignmentTerm); nullFree(assignmentTerm);
freeExpression(assignmentTerm->rightArgument); freeExpression(assignmentTerm->rightArgument);
free(assignmentTerm); free(assignmentTerm);
} }
void void
freeBinopTerm(binopTerm) freeBinopTerm(binopTermType *binopTerm)
binopTermType *binopTerm;
{ {
void freeExpression();
nullFree(binopTerm); nullFree(binopTerm);
freeExpression(binopTerm->leftArgument); freeExpression(binopTerm->leftArgument);
if (binopTerm->binop != SELECT) if (binopTerm->binop != SELECT)
@ -70,54 +64,44 @@ freeBinopTerm(binopTerm)
} }
void void
freeFunctionCall(functionCall) freeFunctionCall(functionCallTermType *functionCall)
functionCallTermType *functionCall;
{ {
void freeOperandList();
nullFree(functionCall); nullFree(functionCall);
freeOperandList(functionCall->parameters); freeOperandList(functionCall->parameters);
free(functionCall); free(functionCall);
} }
void void
freePostopTerm(postopTerm) freePostopTerm(postOpTermType *postopTerm)
postOpTermType *postopTerm;
{ {
nullFree(postopTerm); nullFree(postopTerm);
free(postopTerm); free(postopTerm);
} }
void void
freePreopTerm(preopTerm) freePreopTerm(preOpTermType *preopTerm)
preOpTermType *preopTerm;
{ {
nullFree(preopTerm); nullFree(preopTerm);
free(preopTerm); free(preopTerm);
} }
void void
freeString(string) freeString(stringType *string)
stringType *string;
{ {
nullFree(string); nullFree(string);
free(string); free(string);
} }
void void
freeUnopTerm(unopTerm) freeUnopTerm(unopTermType *unopTerm)
unopTermType *unopTerm;
{ {
void freeExpression();
nullFree(unopTerm); nullFree(unopTerm);
freeExpression(unopTerm->unopArgument); freeExpression(unopTerm->unopArgument);
free(unopTerm); free(unopTerm);
} }
void void
freeExpression(expression) freeExpression(expressionType *expression)
expressionType *expression;
{ {
nullFree(expression); nullFree(expression);
switch (expression->kindOfTerm) { switch (expression->kindOfTerm) {
@ -171,8 +155,7 @@ freeExpression(expression)
} }
void void
freeExpressionList(expressionList) freeExpressionList(expressionListType *expressionList)
expressionListType *expressionList;
{ {
expressionListType *newExpressionList; expressionListType *newExpressionList;
@ -185,8 +168,7 @@ freeExpressionList(expressionList)
} }
void void
freeIdentifierList(identifierList) freeIdentifierList(identifierListType *identifierList)
identifierListType *identifierList;
{ {
identifierListType *newIdentifierList; identifierListType *newIdentifierList;
@ -198,25 +180,22 @@ freeIdentifierList(identifierList)
} }
void void
freeSelectionList(selectionList) freeSelectionList(selectionListType *selectionList)
selectionListType *selectionList;
{ {
freeIdentifierList(selectionList); freeIdentifierList(selectionList);
} }
void void
freeBlock(block) freeBlock(blockType *block)
blockType *block;
{ {
void freeStatement(); void freeStatement(statementType *statement);
nullFree(block); nullFree(block);
freeStatement(block); freeStatement(block);
} }
void void
freeCase(aCase) freeCase(caseType *aCase)
caseType *aCase;
{ {
freeExpressionList(aCase->caseTags); freeExpressionList(aCase->caseTags);
freeBlock(aCase->caseBody); freeBlock(aCase->caseBody);
@ -224,8 +203,7 @@ freeCase(aCase)
} }
void void
freeCaseList(caseList) freeCaseList(caseListType *caseList)
caseListType *caseList;
{ {
caseListType *newCaseList; caseListType *newCaseList;
@ -238,37 +216,32 @@ freeCaseList(caseList)
} }
void void
freeOperandList(operandList) freeOperandList(operandListType *operandList)
operandListType *operandList;
{ {
freeOperand(operandList); freeOperand(operandList);
} }
void void
freeMacro(operands) freeMacro(operandListType *operands)
operandListType *operands;
{ {
freeOperandList(operands); freeOperandList(operands);
} }
void void
freeMachineInstruction(operands) freeMachineInstruction(operandListType *operands)
operandListType *operands;
{ {
freeOperandList(operands); freeOperandList(operands);
} }
void void
freeAlignStatement(alignStatement) freeAlignStatement(alignStatementBodyType *alignStatement)
alignStatementBodyType *alignStatement;
{ {
nullFree(alignStatement); nullFree(alignStatement);
freeExpression(alignStatement); freeExpression(alignStatement);
} }
void void
freeAssertStatement(assertStatement) freeAssertStatement(assertStatementBodyType *assertStatement)
assertStatementBodyType *assertStatement;
{ {
nullFree(assertStatement); nullFree(assertStatement);
freeExpression(assertStatement->condition); freeExpression(assertStatement->condition);
@ -277,16 +250,14 @@ freeAssertStatement(assertStatement)
} }
void void
freeBlockStatement(blockStatement) freeBlockStatement(blockStatementBodyType *blockStatement)
blockStatementBodyType *blockStatement;
{ {
nullFree(blockStatement); nullFree(blockStatement);
freeExpressionList(blockStatement); freeExpressionList(blockStatement);
} }
void void
freeByteStatement(byteStatement) freeByteStatement(byteStatementBodyType *byteStatement)
byteStatementBodyType *byteStatement;
{ {
byteStatementBodyType *newByteStatement; byteStatementBodyType *newByteStatement;
@ -300,8 +271,7 @@ freeByteStatement(byteStatement)
} }
void void
freeConstrainStatement(constrainStatement) freeConstrainStatement(constrainStatementBodyType *constrainStatement)
constrainStatementBodyType *constrainStatement;
{ {
nullFree(constrainStatement); nullFree(constrainStatement);
freeExpression(constrainStatement->constraint); freeExpression(constrainStatement->constraint);
@ -310,8 +280,7 @@ freeConstrainStatement(constrainStatement)
} }
void void
freeDbyteStatement(dbyteStatement) freeDbyteStatement(dbyteStatementBodyType *dbyteStatement)
dbyteStatementBodyType *dbyteStatement;
{ {
dbyteStatementBodyType *newDbyteStatement; dbyteStatementBodyType *newDbyteStatement;
@ -325,8 +294,7 @@ freeDbyteStatement(dbyteStatement)
} }
void void
freeDefineStatement(defineStatement) freeDefineStatement(defineStatementBodyType *defineStatement)
defineStatementBodyType *defineStatement;
{ {
nullFree(defineStatement); nullFree(defineStatement);
freeExpression(defineStatement->theValue); freeExpression(defineStatement->theValue);
@ -334,8 +302,7 @@ freeDefineStatement(defineStatement)
} }
void void
freeDoUntilStatement(doUntilStatement) freeDoUntilStatement(doUntilStatementBodyType *doUntilStatement)
doUntilStatementBodyType *doUntilStatement;
{ {
nullFree(doUntilStatement); nullFree(doUntilStatement);
freeBlock(doUntilStatement->doUntilLoop); freeBlock(doUntilStatement->doUntilLoop);
@ -343,8 +310,7 @@ freeDoUntilStatement(doUntilStatement)
} }
void void
freeDoWhileStatement(doWhileStatement) freeDoWhileStatement(doWhileStatementBodyType *doWhileStatement)
doWhileStatementBodyType *doWhileStatement;
{ {
nullFree(doWhileStatement); nullFree(doWhileStatement);
freeBlock(doWhileStatement->doWhileLoop); freeBlock(doWhileStatement->doWhileLoop);
@ -352,23 +318,20 @@ freeDoWhileStatement(doWhileStatement)
} }
void void
freeExternStatement(externStatement) freeExternStatement(externStatementBodyType *externStatement)
externStatementBodyType *externStatement;
{ {
freeIdentifierList(externStatement); freeIdentifierList(externStatement);
} }
void void
freeFreturnStatement(freturnStatement) freeFreturnStatement(freturnStatementBodyType *freturnStatement)
freturnStatementBodyType *freturnStatement;
{ {
nullFree(freturnStatement); nullFree(freturnStatement);
freeExpression(freturnStatement); freeExpression(freturnStatement);
} }
void void
freeFunctionStatement(functionStatement) freeFunctionStatement(functionStatementBodyType *functionStatement)
functionStatementBodyType *functionStatement;
{ {
nullFree(functionStatement); nullFree(functionStatement);
free(functionStatement->functionName); free(functionStatement->functionName);
@ -376,8 +339,7 @@ freeFunctionStatement(functionStatement)
} }
void void
freeIfStatement(ifStatement) freeIfStatement(ifStatementBodyType *ifStatement)
ifStatementBodyType *ifStatement;
{ {
nullFree(ifStatement); nullFree(ifStatement);
if (ifStatement->consequence != NULL) if (ifStatement->consequence != NULL)
@ -389,16 +351,14 @@ freeIfStatement(ifStatement)
} }
void void
freeIncludeStatement(includeStatement) freeIncludeStatement(includeStatementBodyType *includeStatement)
includeStatementBodyType *includeStatement;
{ {
nullFree(includeStatement); nullFree(includeStatement);
freeExpression(includeStatement); freeExpression(includeStatement);
} }
void void
freeInstructionStatement(instructionStatement) freeInstructionStatement(instructionStatementBodyType *instructionStatement)
instructionStatementBodyType *instructionStatement;
{ {
nullFree(instructionStatement); nullFree(instructionStatement);
switch(instructionStatement->kindOfInstruction) { switch(instructionStatement->kindOfInstruction) {
@ -419,8 +379,7 @@ freeInstructionStatement(instructionStatement)
} }
void void
freeLongStatement(longStatement) freeLongStatement(longStatementBodyType *longStatement)
longStatementBodyType *longStatement;
{ {
longStatementBodyType *newLongStatement; longStatementBodyType *newLongStatement;
@ -434,16 +393,15 @@ freeLongStatement(longStatement)
} }
void void
freeMacroStatement(macroStatement) freeMacroStatement(macroStatementBodyType *macroStatement)
macroStatementBodyType *macroStatement;
{ {
nullFree(macroStatement); nullFree(macroStatement);
free(macroStatement); free(macroStatement);
} }
void void
freeMdefineStatement(mdefineStatement) freeMdefineStatement(defineStatementBodyType *mdefineStatement)
defineStatementBodyType *mdefineStatement; // MIST: shouldn't this be "mdefineStatementBodyType"? /* MIST: shouldn't this be "mdefineStatementBodyType"? */
{ {
valueType *freeDefineExpression(); valueType *freeDefineExpression();
@ -453,8 +411,7 @@ freeMdefineStatement(mdefineStatement)
} }
void void
freeMdoUntilStatement(mdoUntilStatement) freeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement)
mdoUntilStatementBodyType *mdoUntilStatement;
{ {
nullFree(mdoUntilStatement); nullFree(mdoUntilStatement);
freeBlock(mdoUntilStatement->mdoUntilLoop); freeBlock(mdoUntilStatement->mdoUntilLoop);
@ -462,8 +419,7 @@ freeMdoUntilStatement(mdoUntilStatement)
} }
void void
freeMdoWhileStatement(mdoWhileStatement) freeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement)
mdoWhileStatementBodyType *mdoWhileStatement;
{ {
nullFree(mdoWhileStatement); nullFree(mdoWhileStatement);
freeBlock(mdoWhileStatement->mdoWhileLoop); freeBlock(mdoWhileStatement->mdoWhileLoop);
@ -472,8 +428,7 @@ freeMdoWhileStatement(mdoWhileStatement)
} }
void void
freeMifStatement(mifStatement) freeMifStatement(mifStatementBodyType *mifStatement)
mifStatementBodyType *mifStatement;
{ {
nullFree(mifStatement); nullFree(mifStatement);
freeExpression(mifStatement->mifCondition); freeExpression(mifStatement->mifCondition);
@ -484,8 +439,7 @@ freeMifStatement(mifStatement)
} }
void void
freeMswitchStatement(mswitchStatement) freeMswitchStatement(mswitchStatementBodyType *mswitchStatement)
mswitchStatementBodyType *mswitchStatement;
{ {
freeExpression(mswitchStatement->switchExpression); freeExpression(mswitchStatement->switchExpression);
freeCaseList(mswitchStatement->cases); freeCaseList(mswitchStatement->cases);
@ -493,8 +447,7 @@ freeMswitchStatement(mswitchStatement)
} }
void void
freeMforStatement(mforStatement) freeMforStatement(mforStatementBodyType *mforStatement)
mforStatementBodyType *mforStatement;
{ {
nullFree(mforStatement); nullFree(mforStatement);
freeExpression(mforStatement->initExpression); freeExpression(mforStatement->initExpression);
@ -505,8 +458,7 @@ freeMforStatement(mforStatement)
} }
void void
freeMvariableStatement(mvariableStatement) freeMvariableStatement(mvariableStatementBodyType *mvariableStatement)
mvariableStatementBodyType *mvariableStatement;
{ {
nullFree(mvariableStatement); nullFree(mvariableStatement);
if ((int)mvariableStatement->theDimension != -1) if ((int)mvariableStatement->theDimension != -1)
@ -516,8 +468,7 @@ freeMvariableStatement(mvariableStatement)
} }
void void
freeMwhileStatement(mwhileStatement) freeMwhileStatement(mwhileStatementBodyType *mwhileStatement)
mwhileStatementBodyType *mwhileStatement;
{ {
nullFree(mwhileStatement); nullFree(mwhileStatement);
freeExpression(mwhileStatement->mwhileCondition); freeExpression(mwhileStatement->mwhileCondition);
@ -526,38 +477,33 @@ freeMwhileStatement(mwhileStatement)
} }
void void
freeOrgStatement(orgStatement) freeOrgStatement(orgStatementBodyType *orgStatement)
orgStatementBodyType *orgStatement;
{ {
nullFree(orgStatement); nullFree(orgStatement);
freeExpression(orgStatement); freeExpression(orgStatement);
} }
void void
freePerformStatement(performStatement) freePerformStatement(performStatementBodyType *performStatement)
performStatementBodyType *performStatement;
{ {
nullFree(performStatement); nullFree(performStatement);
freeExpression(performStatement); freeExpression(performStatement);
} }
void void
freeRelStatement(relStatement) freeRelStatement(relStatementBodyType *relStatement)
relStatementBodyType *relStatement;
{ {
} }
void void
freeStartStatement(startStatement) freeStartStatement(startStatementBodyType *startStatement)
startStatementBodyType *startStatement;
{ {
nullFree(startStatement); nullFree(startStatement);
freeExpression(startStatement); freeExpression(startStatement);
} }
void void
freeStringStatement(stringStatement) freeStringStatement(stringStatementBodyType *stringStatement)
stringStatementBodyType *stringStatement;
{ {
stringStatementBodyType *newStringStatement; stringStatementBodyType *newStringStatement;
@ -571,8 +517,7 @@ freeStringStatement(stringStatement)
} }
void void
freeStructStatement(structStatement) freeStructStatement(structStatementBodyType *structStatement)
structStatementBodyType *structStatement;
{ {
nullFree(structStatement); nullFree(structStatement);
freeBlock(structStatement->structBody); freeBlock(structStatement->structBody);
@ -580,23 +525,20 @@ freeStructStatement(structStatement)
} }
void void
freeTargetStatement(targetStatement) freeTargetStatement(targetStatementBodyType *targetStatement)
targetStatementBodyType *targetStatement;
{ {
nullFree(targetStatement); nullFree(targetStatement);
freeExpression(targetStatement); freeExpression(targetStatement);
} }
void void
freeUndefineStatement(undefineStatement) freeUndefineStatement(undefineStatementBodyType *undefineStatement)
undefineStatementBodyType *undefineStatement;
{ {
freeIdentifierList(undefineStatement); freeIdentifierList(undefineStatement);
} }
void void
freeVariableStatement(variableStatement) freeVariableStatement(variableStatementBodyType *variableStatement)
variableStatementBodyType *variableStatement;
{ {
nullFree(variableStatement); nullFree(variableStatement);
if ((int)variableStatement->theDimension != -1) if ((int)variableStatement->theDimension != -1)
@ -606,8 +548,7 @@ freeVariableStatement(variableStatement)
} }
void void
freeWhileStatement(whileStatement) freeWhileStatement(whileStatementBodyType *whileStatement)
whileStatementBodyType *whileStatement;
{ {
nullFree(whileStatement); nullFree(whileStatement);
freeBlock(whileStatement->whileLoop); freeBlock(whileStatement->whileLoop);
@ -615,8 +556,7 @@ freeWhileStatement(whileStatement)
} }
void void
freeWordStatement(wordStatement) freeWordStatement(wordStatementBodyType *wordStatement)
wordStatementBodyType *wordStatement;
{ {
wordStatementBodyType *newWordStatement; wordStatementBodyType *newWordStatement;
@ -630,9 +570,7 @@ freeWordStatement(wordStatement)
} }
void void
freeStatementBody(kind, body) freeStatementBody(statementKindType kind, statementBodyType body)
statementKindType kind;
statementBodyType body;
{ {
switch (kind) { switch (kind) {
@ -795,8 +733,7 @@ freeStatementBody(kind, body)
} }
void void
freeLabelList(labelList) freeLabelList(labelListType *labelList)
labelListType *labelList;
{ {
labelListType *nextLabel; labelListType *nextLabel;
@ -808,8 +745,7 @@ freeLabelList(labelList)
} }
void void
freeStatement(statement) freeStatement(statementType *statement)
statementType *statement;
{ {
statementType *newStatement; statementType *newStatement;
@ -824,11 +760,9 @@ freeStatement(statement)
} }
void void
freeArray(array) freeArray(arrayType *array)
arrayType *array;
{ {
int i; int i;
void freeValue();
if (array->arraySize > 0) { if (array->arraySize > 0) {
for (i=0; i<array->arraySize; i++) for (i=0; i<array->arraySize; i++)
@ -839,8 +773,7 @@ freeArray(array)
} }
void void
freeValue(value) freeValue(valueType *value)
valueType *value;
{ {
if (value->kindOfValue == STRING_VALUE) if (value->kindOfValue == STRING_VALUE)
freeString(value->value); freeString(value->value);

66
garbage.h Normal file
View File

@ -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

143
globals.c Normal file
View File

@ -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];

View File

@ -29,6 +29,14 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "initialize.h"
#include "errorStuff.h"
#include "lexer.h"
#include "lookups.h"
#include "semanticMisc.h"
#include <string.h>
#include <unistd.h>
#define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) #define isAlphaNumeric(c) (alphaNumericCharacterTable[c])
@ -38,16 +46,14 @@ static fileNameListType *bottomOfInputFileStack;
static char *outputFileName; static char *outputFileName;
void void
chokePukeAndDie() chokePukeAndDie(void)
{ {
unlink(outputFileName); unlink(outputFileName);
exit(1); exit(1);
} }
void void
initializeStuff(argc, argv) initializeStuff(int argc, char **argv)
int argc;
char *argv[];
{ {
int i; int i;
int j; int j;
@ -60,14 +66,6 @@ initializeStuff(argc, argv)
char *symbolDumpFileName; char *symbolDumpFileName;
bool dontUnlinkTempFiles; bool dontUnlinkTempFiles;
void createHashTables();
void installBuiltInFunctions();
void installPredefinedSymbols();
void installCommandLineDefineSymbols();
void openFirstInputFile();
void queueInputFile();
void noteCommandLineDefine();
for (i=0; i<128; i++) { for (i=0; i<128; i++) {
lowerCaseCharacterTable[i] = i; lowerCaseCharacterTable[i] = i;
alphabeticCharacterTable[i] = FALSE; alphabeticCharacterTable[i] = FALSE;
@ -339,7 +337,7 @@ initializeStuff(argc, argv)
installCommandLineDefineSymbols(); installCommandLineDefineSymbols();
if (listingOn) { if (listingOn) {
if ((saveFileForPass2 = fopen(mktemp(pass2SourceFileName), if ((saveFileForPass2 = fopen(mkstemp(pass2SourceFileName),
"w+")) == NULL) { "w+")) == NULL) {
fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR, fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR,
pass2SourceFileName); pass2SourceFileName);
@ -348,7 +346,7 @@ initializeStuff(argc, argv)
unlink(pass2SourceFileName); /* will take effect on unlink(pass2SourceFileName); /* will take effect on
program exit */ program exit */
if ((indexFileForPass2 = fopen(mktemp(pass2IndexFileName), if ((indexFileForPass2 = fopen(mkstemp(pass2IndexFileName),
"w+")) == NULL) { "w+")) == NULL) {
fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR, fatalSystemError(UNABLE_TO_OPEN_PASS_2_FILE_ERROR,
pass2IndexFileName); pass2IndexFileName);
@ -358,7 +356,7 @@ initializeStuff(argc, argv)
program exit */ program exit */
if (expandMacros) { if (expandMacros) {
if ((macroFileForPass2 = fopen(mktemp( if ((macroFileForPass2 = fopen(mkstemp(
pass2MacroExpansionFileName),"w+")) == NULL) { pass2MacroExpansionFileName),"w+")) == NULL) {
fatalSystemError( fatalSystemError(
UNABLE_TO_OPEN_PASS_2_FILE_ERROR, UNABLE_TO_OPEN_PASS_2_FILE_ERROR,
@ -379,14 +377,11 @@ initializeStuff(argc, argv)
} }
void void
installBuiltInFunctions() installBuiltInFunctions(void)
{ {
int i; int i;
symbolTableEntryType *newFunction; symbolTableEntryType *newFunction;
symbolTableEntryType *lookupOrEnterSymbol();
valueType *newValue();
for (i=0; builtInFunctionTable[i].functionName!=NULL; i++) { for (i=0; builtInFunctionTable[i].functionName!=NULL; i++) {
newFunction = lookupOrEnterSymbol(builtInFunctionTable[i]. newFunction = lookupOrEnterSymbol(builtInFunctionTable[i].
functionName, BUILT_IN_FUNCTION_SYMBOL); functionName, BUILT_IN_FUNCTION_SYMBOL);
@ -399,14 +394,11 @@ installBuiltInFunctions()
} }
void void
installPredefinedSymbols() installPredefinedSymbols(void)
{ {
int i; int i;
symbolTableEntryType *newSymbol; symbolTableEntryType *newSymbol;
symbolTableEntryType *lookupOrEnterSymbol();
valueType *newValue();
for (i=0; predefinedSymbolTable[i].symbolName!=NULL; i++) { for (i=0; predefinedSymbolTable[i].symbolName!=NULL; i++) {
newSymbol = lookupOrEnterSymbol(predefinedSymbolTable[i]. newSymbol = lookupOrEnterSymbol(predefinedSymbolTable[i].
symbolName, DEFINE_SYMBOL); symbolName, DEFINE_SYMBOL);
@ -418,14 +410,11 @@ installPredefinedSymbols()
} }
void void
installCommandLineDefineSymbols() installCommandLineDefineSymbols(void)
{ {
int i; int i;
symbolTableEntryType *newSymbol; symbolTableEntryType *newSymbol;
symbolTableEntryType *lookupOrEnterSymbol();
valueType *newValue();
while (commandLineDefines != NULL) { while (commandLineDefines != NULL) {
newSymbol = lookupOrEnterSymbol(commandLineDefines->name, newSymbol = lookupOrEnterSymbol(commandLineDefines->name,
DEFINE_SYMBOL); DEFINE_SYMBOL);
@ -437,7 +426,7 @@ installCommandLineDefineSymbols()
} }
void void
createHashTables() createHashTables(void)
{ {
opcodeTableEntryType *newOpcodeEntry; opcodeTableEntryType *newOpcodeEntry;
keywordTableEntryType *newKeywordEntry; keywordTableEntryType *newKeywordEntry;
@ -457,8 +446,7 @@ createHashTables()
} }
void void
queueInputFile(name) queueInputFile(char *name)
char *name;
{ {
fileNameListType *newFileName; fileNameListType *newFileName;
@ -477,7 +465,7 @@ queueInputFile(name)
} }
void void
openFirstInputFile() openFirstInputFile(void)
{ {
if (inputFileStack == NULL) { if (inputFileStack == NULL) {
inputFileStack = typeAlloc(fileNameListType); inputFileStack = typeAlloc(fileNameListType);
@ -502,8 +490,7 @@ openFirstInputFile()
} }
bool bool
isDotMName(fileName) isDotMName(stringType *fileName)
stringType *fileName;
{ {
int length; int length;
@ -513,10 +500,7 @@ isDotMName(fileName)
} }
bool bool
parseCommandLineDefine(arg, name, value) parseCommandLineDefine(char *arg, char **name, int *value)
char *arg;
char **name;
int *value;
{ {
char *ptr; char *ptr;
char c; char c;
@ -559,15 +543,12 @@ parseCommandLineDefine(arg, name, value)
} }
void void
noteCommandLineDefine(arg) noteCommandLineDefine(char *arg)
char *arg;
{ {
char *name; char *name;
int value; int value;
commandLineDefineType *newCommandLineDefine; commandLineDefineType *newCommandLineDefine;
bool parseCommandLineDefine();
if (parseCommandLineDefine(arg, &name, &value)) { if (parseCommandLineDefine(arg, &name, &value)) {
newCommandLineDefine = typeAlloc(commandLineDefineType); newCommandLineDefine = typeAlloc(commandLineDefineType);
newCommandLineDefine->name = name; newCommandLineDefine->name = name;

21
initialize.h Normal file
View File

@ -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

92
lexer.c
View File

@ -30,7 +30,13 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "y.tab.h" #include "y.tab.h"
#include "debugPrint.h"
#include "errorStuff.h"
#include "lexer.h"
#include "lexerTables.h" #include "lexerTables.h"
#include "listing.h"
#include "lookups.h"
#include "parserMisc.h"
extern int yylval; extern int yylval;
extern int yydebug; extern int yydebug;
@ -51,8 +57,8 @@ static int lineBufferPtr = 0;
#define isNumeric(c) (numericCharacterTable[c]) #define isNumeric(c) (numericCharacterTable[c])
#define isAlphaNumeric(c) (alphaNumericCharacterTable[c]) #define isAlphaNumeric(c) (alphaNumericCharacterTable[c])
int int
yylex() yylex(void)
{ {
int result; int result;
@ -66,12 +72,10 @@ yylex()
} }
int int
lexer() lexer(void)
{ {
char c; char c;
char skipWhitespaceAndComments();
if ((c = skipWhitespaceAndComments()) == EOF) if ((c = skipWhitespaceAndComments()) == EOF)
return(lexLiteral(c)); return(lexLiteral(c));
else else
@ -79,15 +83,9 @@ lexer()
} }
void void
initializeLexDispatchTable() initializeLexDispatchTable(void)
{ {
int c; int c;
int lexIdentifier();
int lexNumber();
int lexLiteral();
int lexCharacterConstant();
int lexStringConstant();
int lexOperator();
for (c = 0; c < LEX_DISPATCH_TABLE_SIZE; c++) { for (c = 0; c < LEX_DISPATCH_TABLE_SIZE; c++) {
if (isAlphabetic(c) || c=='$') if (isAlphabetic(c) || c=='$')
@ -106,8 +104,7 @@ initializeLexDispatchTable()
} }
bool bool
isMacrossLiteralCharacter(c) isMacrossLiteralCharacter(char c)
char c;
{ {
return(c==':' || c==',' || c=='@' || c=='#' || return(c==':' || c==',' || c=='@' || c=='#' ||
c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' ||
@ -115,9 +112,7 @@ isMacrossLiteralCharacter(c)
} }
void void
snarfAlphanumericString(c, buffer) snarfAlphanumericString(char c, char *buffer)
char c;
char *buffer;
{ {
char *bufferPtr; char *bufferPtr;
@ -134,10 +129,8 @@ snarfAlphanumericString(c, buffer)
char nameBuffer[MAX_NAME_SIZE+1]; char nameBuffer[MAX_NAME_SIZE+1];
int int
lexIdentifier(c) lexIdentifier(char c)
char c;
{ {
char *saveString();
int hashValue; int hashValue;
snarfAlphanumericString(c, nameBuffer); snarfAlphanumericString(c, nameBuffer);
@ -160,8 +153,7 @@ lexIdentifier(c)
char numberBuffer[MAX_NAME_SIZE+1]; char numberBuffer[MAX_NAME_SIZE+1];
int int
lexNumber(c) lexNumber(char c)
char c;
{ {
int base; int base;
int start; int start;
@ -188,9 +180,7 @@ lexNumber(c)
} }
int int
fancyAtoI(buffer, base) fancyAtoI(char *buffer, int base)
char *buffer;
int base;
{ {
int value; int value;
int digit; int digit;
@ -208,8 +198,7 @@ fancyAtoI(buffer, base)
} }
int int
digitValue(c) digitValue(char c)
char c;
{ {
if (isNumeric(c)) if (isNumeric(c))
return(c - '0'); return(c - '0');
@ -218,8 +207,7 @@ digitValue(c)
} }
int int
lexLiteral(c) lexLiteral(char c)
char c;
{ {
static bool passedEnd = FALSE; static bool passedEnd = FALSE;
@ -239,7 +227,7 @@ lexLiteral(c)
} }
int int
lexCharacterConstant() lexCharacterConstant(void)
{ {
char c; char c;
@ -255,13 +243,11 @@ lexCharacterConstant()
bool escaped; /* true if last string character read was an escape bool escaped; /* true if last string character read was an escape
code. */ code. */
int int
getStringCharacter(input) getStringCharacter(FILE *input)
FILE *input;
{ {
char c; char c;
char *numberPtr; char *numberPtr;
int result; int result;
char controlCharacter();
escaped = FALSE; escaped = FALSE;
c = getNextChar(); c = getNextChar();
@ -291,7 +277,7 @@ getStringCharacter(input)
char stringBuffer[MAX_NAME_SIZE + 1]; char stringBuffer[MAX_NAME_SIZE + 1];
int int
lexStringConstant() lexStringConstant(void)
{ {
char *stringPtr; char *stringPtr;
char c; char c;
@ -308,8 +294,7 @@ lexStringConstant()
} }
int int
lexOperator(firstC) lexOperator(char firstC)
char firstC;
{ {
char secondC; char secondC;
char thirdC; char thirdC;
@ -346,8 +331,7 @@ lexOperator(firstC)
} }
char char
controlCharacter(c) controlCharacter(char c)
char c;
{ {
#define CONTROL_CHARACTER_MASK (~0100) #define CONTROL_CHARACTER_MASK (~0100)
@ -355,7 +339,7 @@ controlCharacter(c)
} }
char char
skipWhitespaceAndComments() skipWhitespaceAndComments(void)
{ {
char c; char c;
@ -393,7 +377,7 @@ skipWhitespaceAndComments()
} }
int int
popInputFileStack() popInputFileStack(void)
{ {
fileNameListType *oldFile; fileNameListType *oldFile;
@ -424,8 +408,7 @@ popInputFileStack()
} }
void void
pushInputFileStack(fileName) pushInputFileStack(stringType *fileName)
stringType *fileName;
{ {
fileNameListType *newFileName; fileNameListType *newFileName;
@ -445,7 +428,7 @@ pushInputFileStack(fileName)
} }
void void
resynchronizeInput() resynchronizeInput(void)
{ {
char c; char c;
while ((c = getNextChar())!='\n' && c!=EOF) while ((c = getNextChar())!='\n' && c!=EOF)
@ -457,8 +440,7 @@ resynchronizeInput()
static bool previousLongLineFlag = FALSE; static bool previousLongLineFlag = FALSE;
void void
saveLineForListing(line) saveLineForListing(stringType *line)
stringType *line;
{ {
if (!previousLongLineFlag) { if (!previousLongLineFlag) {
putw(currentLocationCounter.value, saveFileForPass2); putw(currentLocationCounter.value, saveFileForPass2);
@ -469,7 +451,7 @@ saveLineForListing(line)
} }
void void
saveEOLForListing() saveEOLForListing(void)
{ {
putw(-1, saveFileForPass2); putw(-1, saveFileForPass2);
putw(includeNestingDepth, saveFileForPass2); putw(includeNestingDepth, saveFileForPass2);
@ -477,9 +459,7 @@ saveEOLForListing()
} }
void void
saveIndexForListing(kindOfStatement, cumulativeLineNumber) saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber)
statementKindType kindOfStatement;
int cumulativeLineNumber;
{ {
if (!amExpanding() || !notListable(kindOfStatement)) { if (!amExpanding() || !notListable(kindOfStatement)) {
putw(kindOfStatement, indexFileForPass2); putw(kindOfStatement, indexFileForPass2);
@ -492,8 +472,7 @@ saveIndexForListing(kindOfStatement, cumulativeLineNumber)
} }
void void
saveEndMifForListing(cumulativeLineNumber) saveEndMifForListing(int cumulativeLineNumber)
int cumulativeLineNumber;
{ {
putw(MIF_STATEMENT, indexFileForPass2); putw(MIF_STATEMENT, indexFileForPass2);
putw(-1, indexFileForPass2); putw(-1, indexFileForPass2);
@ -504,13 +483,13 @@ saveEndMifForListing(cumulativeLineNumber)
} }
void void
saveListingOff() saveListingOff(void)
{ {
saveIndexForListing(-1, cumulativeLineNumber); saveIndexForListing(-1, cumulativeLineNumber);
} }
void void
saveListingOn() saveListingOn(void)
{ {
if (currentCodeMode == ABSOLUTE_BUFFER) if (currentCodeMode == ABSOLUTE_BUFFER)
saveIndexForListing(-1, cumulativeLineNumber); saveIndexForListing(-1, cumulativeLineNumber);
@ -519,10 +498,7 @@ saveListingOn()
} }
char * char *
myfgets(buffer, length, stream) myfgets(char *buffer, int length, FILE *stream)
char *buffer;
int length;
FILE *stream;
{ {
char *result; char *result;
char c; char c;
@ -545,7 +521,7 @@ myfgets(buffer, length, stream)
} }
int int
readAnotherLine() readAnotherLine(void)
{ {
int result; int result;

34
lexer.h Normal file
View File

@ -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

170
listing.c
View File

@ -29,6 +29,13 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "emitStuff.h"
#include "lexer.h"
#include "listing.h"
#include "semanticMisc.h"
#include <stdarg.h>
#include <string.h>
static char lineBuffer1[LINE_BUFFER_SIZE]; static char lineBuffer1[LINE_BUFFER_SIZE];
static char lineBuffer2[LINE_BUFFER_SIZE]; static char lineBuffer2[LINE_BUFFER_SIZE];
@ -41,10 +48,8 @@ static int macroDepth;
static int nextMacroDepth; static int nextMacroDepth;
void void
outputListing() outputListing(void)
{ {
void generateListing();
rewind(saveFileForPass2); rewind(saveFileForPass2);
rewind(indexFileForPass2); rewind(indexFileForPass2);
rewind(macroFileForPass2); rewind(macroFileForPass2);
@ -52,7 +57,7 @@ outputListing()
} }
void void
terminateListingFiles() terminateListingFiles(void)
{ {
saveLineForListing("\n"); saveLineForListing("\n");
saveIndexForListing(NULL_STATEMENT, cumulativeLineNumber); saveIndexForListing(NULL_STATEMENT, cumulativeLineNumber);
@ -94,7 +99,7 @@ terminateListingFiles()
/* This is the most horrible piece of code I have ever written in my entire /* This is the most horrible piece of code I have ever written in my entire
life -- cbm */ life -- cbm */
void void
generateListing() generateListing(void)
{ {
int sourceAddress; int sourceAddress;
int sourceDepth; int sourceDepth;
@ -122,9 +127,6 @@ generateListing()
int numberOfBytesListed; int numberOfBytesListed;
char *tempText; char *tempText;
void readIndexFileLine();
void readSourceFileLine();
sourceLineNumber = 1; sourceLineNumber = 1;
alreadyListingMacroExpansion = FALSE; alreadyListingMacroExpansion = FALSE;
readSourceFileLine(&sourceAddress, &sourceDepth, sourceText, readSourceFileLine(&sourceAddress, &sourceDepth, sourceText,
@ -298,10 +300,7 @@ generateListing()
bool longLineFlag; /* defined in lexer.c */ bool longLineFlag; /* defined in lexer.c */
int int
printMacroLine(numberOfBytes, byteAddress, kind) printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind)
int numberOfBytes;
int byteAddress;
statementKindType kind;
{ {
macroAddress = nextMacroAddress; macroAddress = nextMacroAddress;
macroDepth = nextMacroDepth; macroDepth = nextMacroDepth;
@ -313,11 +312,7 @@ printMacroLine(numberOfBytes, byteAddress, kind)
} }
void void
readSourceFileLine(sourceAddressPtr, sourceDepthPtr, lineBuffer, file) readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char *lineBuffer, FILE *file)
int *sourceAddressPtr;
int *sourceDepthPtr;
char lineBuffer[];
FILE *file;
{ {
char c; char c;
@ -332,10 +327,7 @@ readSourceFileLine(sourceAddressPtr, sourceDepthPtr, lineBuffer, file)
} }
void void
readIndexFileLine(statementKindPtr, indexAddressPtr, indexLineNumberPtr) readIndexFileLine(statementKindType *statementKindPtr, int *indexAddressPtr, int *indexLineNumberPtr)
statementKindType *statementKindPtr;
int *indexAddressPtr;
int *indexLineNumberPtr;
{ {
statementKindType statementKindRead; statementKindType statementKindRead;
int indexAddressRead; int indexAddressRead;
@ -354,16 +346,10 @@ readIndexFileLine(statementKindPtr, indexAddressPtr, indexLineNumberPtr)
} }
int int
printListingLine(numberOfBytes, byteAddress, text, kind) printListingLine(int numberOfBytes, int byteAddress, char *text, statementKindType kind)
int numberOfBytes;
int byteAddress;
char *text;
statementKindType kind;
{ {
int i; int i;
void tabPrint();
if (kind != BLOCK_STATEMENT) if (kind != BLOCK_STATEMENT)
numberOfBytes = (numberOfBytes < 4) ? numberOfBytes : 4; numberOfBytes = (numberOfBytes < 4) ? numberOfBytes : 4;
@ -411,8 +397,7 @@ printListingLine(numberOfBytes, byteAddress, text, kind)
bool bool
isBlockOpener(statementKind) isBlockOpener(statementKindType statementKind)
statementKindType statementKind;
{ {
return (statementKind==IF_STATEMENT || return (statementKind==IF_STATEMENT ||
statementKind==WHILE_STATEMENT || statementKind==WHILE_STATEMENT ||
@ -431,8 +416,7 @@ isBlockOpener(statementKind)
} }
bool bool
isBlankStatement(statementKind) isBlankStatement(statementKindType statementKind)
statementKindType statementKind;
{ {
return( statementKind == DEFINE_STATEMENT || return( statementKind == DEFINE_STATEMENT ||
statementKind == NULL_STATEMENT || statementKind == NULL_STATEMENT ||
@ -458,8 +442,7 @@ isBlankStatement(statementKind)
} }
void void
tabPrint(text) tabPrint(stringType *text)
stringType *text;
{ {
int column; int column;
int spaces; int spaces;
@ -480,18 +463,14 @@ tabPrint(text)
} }
void void
printNTimes(aChar, times) printNTimes(char aChar, int times)
char aChar;
int times;
{ {
void moreText();
while (times-- > 0) while (times-- > 0)
moreText("%c", aChar); moreText("%c", aChar, 0, 0);
} }
void void
tabIndent() tabIndent(void)
{ {
printNTimes('\t', tabCount); printNTimes('\t', tabCount);
} }
@ -504,58 +483,52 @@ static char labelString[LINE_BUFFER_SIZE] = { '\0' };
static char *labelStringPtr = labelString; static char *labelStringPtr = labelString;
bool bool
labeledLine() labeledLine(void)
{ {
return(labelStringPtr != labelString); return(labelStringPtr != labelString);
} }
void void
addText(buffer, bufferPtr, format, arg1, arg2, arg3) vaddText(char *buffer, char **bufferPtr, char *format, va_list ap)
char *buffer;
char **bufferPtr;
char *format;
int arg1;
int arg2;
int arg3;
{ {
sprintf(*bufferPtr, format, arg1, arg2, arg3); vsprintf(*bufferPtr, format, ap);
*bufferPtr = buffer + strlen(buffer); *bufferPtr = buffer = strlen(buffer);
} }
void void
moreTextOptional(buffer, bufferPtr, format, arg1, arg2, arg3) addText(char *buffer, char **bufferPtr, char *format, ...)
char *buffer;
char **bufferPtr;
char *format;
int arg1;
int arg2;
int arg3;
{ {
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) if (buffer == NULL)
addText(expansionString, &expansionStringPtr, format, arg1, vaddText(expansionString, &expansionStringPtr, format, ap);
arg2, arg3);
else else
addText(buffer, bufferPtr, format, arg1, arg2, arg3); vaddText(buffer, bufferPtr, format, ap);
va_end(ap);
} }
void void
moreText(format, arg1, arg2, arg3) moreText(char *format, ...)
char *format;
int arg1;
int arg2;
int arg3;
{ {
addText(expansionString, &expansionStringPtr, format, arg1,arg2,arg3); va_list ap;
va_start(ap, format);
addText(expansionString, &expansionStringPtr, format, ap);
va_end(ap);
} }
void void
moreLabel(format, arg1, arg2, arg3) moreLabel(char *format, int arg1)
char *format;
int arg1;
int arg2;
int arg3;
{ {
sprintf(labelStringPtr, format, arg1, arg2, arg3); sprintf(labelStringPtr, format, arg1);
labelStringPtr = labelString + strlen(labelString); labelStringPtr = labelString + strlen(labelString);
} }
@ -563,7 +536,7 @@ static addressType savedCurrentLocationCounterValue;
static int savedIncludeNestingDepth; static int savedIncludeNestingDepth;
void void
startLine() startLine(void)
{ {
printNTimes('+', macroCallDepth); printNTimes('+', macroCallDepth);
savedCurrentLocationCounterValue = currentLocationCounter.value; savedCurrentLocationCounterValue = currentLocationCounter.value;
@ -571,7 +544,7 @@ startLine()
} }
void void
endLine() endLine(void)
{ {
if (amListing()) { if (amListing()) {
putw(savedCurrentLocationCounterValue, macroFileForPass2); putw(savedCurrentLocationCounterValue, macroFileForPass2);
@ -583,77 +556,69 @@ endLine()
} }
void void
flushExpressionString() flushExpressionString(void)
{ {
expressionStringPtr = expressionString; expressionStringPtr = expressionString;
*expressionStringPtr = '\0'; *expressionStringPtr = '\0';
} }
void void
expandExpression(toBuffer, toBufferPtr) expandExpression(char *toBuffer, char **toBufferPtr)
char *toBuffer;
char **toBufferPtr;
{ {
if (toBuffer == NULL) if (toBuffer == NULL)
moreText("%s", expressionString); moreText("%s", expressionString, 0, 0);
else else
addText(toBuffer, toBufferPtr, "%s", expressionString); addText(toBuffer, toBufferPtr, "%s", expressionString, 0, 0);
flushExpressionString(); flushExpressionString();
} }
void void
expandNum(buffer, bufferPtr, n) expandNum(char *buffer, char **bufferPtr, int n)
char *buffer;
char **bufferPtr;
int n;
{ {
moreTextOptional(buffer, bufferPtr, "%d", n); moreTextOptional(buffer, bufferPtr, "%d", n, 0, 0);
} }
void void
flushOperand(n) flushOperand(int n)
int n;
{ {
moreText("%s", operandBuffer[n]); moreText("%s", operandBuffer[n], 0, 0);
operandBuffer[n][0] = '\0'; operandBuffer[n][0] = '\0';
} }
void void
expandOperands(op) expandOperands(int op)
int op;
{ {
int i; int i;
if (op > 0) { if (op > 0) {
flushOperand(0); flushOperand(0);
for (i=1; i<op; i++) { for (i=1; i<op; i++) {
moreText(", "); moreText(", ", 0, 0, 0);
flushOperand(i); flushOperand(i);
} }
} }
} }
void void
expandLabel() expandLabel(void)
{ {
moreText("%s", labelString); moreText("%s", labelString, 0, 0);
labelStringPtr = labelString; labelStringPtr = labelString;
*labelStringPtr = '\0'; *labelStringPtr = '\0';
} }
void void
moreExpression(format, arg1, arg2, arg3) moreExpression(char *format, ...)
char *format;
int arg1;
int arg2;
int arg3;
{ {
sprintf(expressionStringPtr, format, arg1, arg2, arg3); va_list ap;
va_start(ap, format);
vsprintf(expressionStringPtr, format, ap);
va_end(ap);
expressionStringPtr = expressionString + strlen(expressionString); expressionStringPtr = expressionString + strlen(expressionString);
} }
void void
startLineMarked() startLineMarked(void)
{ {
startLine(); startLine();
if (amListing()) if (amListing())
@ -661,8 +626,7 @@ startLineMarked()
} }
bool bool
notListable(statementKind) notListable(statementKindType statementKind)
statementKindType statementKind;
{ {
return(!listableStatement(statementKind) && return(!listableStatement(statementKind) &&
statementKind != INSTRUCTION_STATEMENT && statementKind != INSTRUCTION_STATEMENT &&

38
listing.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef LISTING_H_
#define LISTING_H_
#include "macrossTypes.h"
#include <stdarg.h>
void outputListing(void);
void terminateListingFiles(void);
void generateListing(void);
int printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind);
void readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char *lineBuffer, FILE *file);
void 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

126
lookups.c
View File

@ -29,6 +29,14 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 These routines all do basically the same thing. Various kinds of keywords
@ -37,14 +45,10 @@
*/ */
conditionType conditionType
lookupConditionCode(s, hashValue) lookupConditionCode(char *s, int hashValue)
char *s;
int hashValue;
{ {
conditionTableEntryType *result; conditionTableEntryType *result;
genericTableEntryType *prehashedStringLookup();
result = (conditionTableEntryType *) prehashedStringLookup(s, result = (conditionTableEntryType *) prehashedStringLookup(s,
conditionTable, hashValue); conditionTable, hashValue);
if (result != NULL) if (result != NULL)
@ -54,14 +58,10 @@ lookupConditionCode(s, hashValue)
} }
int int
lookupKeyword(s, hashValue) lookupKeyword(char *s, int hashValue)
char *s;
int hashValue;
{ {
keywordTableEntryType *result; keywordTableEntryType *result;
genericTableEntryType *prehashedStringLookup();
result = (keywordTableEntryType *) prehashedStringLookup(s, result = (keywordTableEntryType *) prehashedStringLookup(s,
keywordTable, hashValue); keywordTable, hashValue);
if (result != NULL) if (result != NULL)
@ -71,23 +71,15 @@ lookupKeyword(s, hashValue)
} }
macroTableEntryType * macroTableEntryType *
lookupMacroName(s, hashValue) lookupMacroName(char *s, int hashValue)
char *s;
int hashValue;
{ {
genericTableEntryType *prehashedStringLookup();
return((macroTableEntryType *) prehashedStringLookup(s, macroTable, return((macroTableEntryType *) prehashedStringLookup(s, macroTable,
hashValue)); hashValue));
} }
opcodeTableEntryType * opcodeTableEntryType *
lookupOpcode(s, hashValue) lookupOpcode(char *s, int hashValue)
char *s;
int hashValue;
{ {
genericTableEntryType *prehashedStringLookup();
return((opcodeTableEntryType *) prehashedStringLookup(s, return((opcodeTableEntryType *) prehashedStringLookup(s,
opcodeTable, hashValue)); opcodeTable, hashValue));
} }
@ -97,14 +89,9 @@ lookupOpcode(s, hashValue)
the given kind and return *that* */ the given kind and return *that* */
symbolTableEntryType * symbolTableEntryType *
lookupOrEnterSymbol(s, kind) lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind)
stringType *s;
symbolUsageKindType kind;
{ {
symbolTableEntryType *result; symbolTableEntryType *result;
genericTableEntryType *hashStringLookup();
genericTableEntryType *hashStringEnter();
symbolTableEntryType *buildSymbolTableEntry();
if (result = (symbolTableEntryType *)hashStringLookup(s,symbolTable)){ if (result = (symbolTableEntryType *)hashStringLookup(s,symbolTable)){
/* result->referenceCount++;*/ /* result->referenceCount++;*/
@ -116,8 +103,7 @@ lookupOrEnterSymbol(s, kind)
} }
void void
pushSymbol(symbol) pushSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
symbolInContextType *newContext; symbolInContextType *newContext;
@ -127,8 +113,7 @@ pushSymbol(symbol)
} }
void void
popSymbol(symbol) popSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
symbolInContextType *deadContext; symbolInContextType *deadContext;
@ -146,17 +131,11 @@ popSymbol(symbol)
} }
macroTableEntryType * macroTableEntryType *
createMacro(macroName) createMacro(stringType *macroName)
stringType *macroName;
{ {
macroTableEntryType *result; macroTableEntryType *result;
symbolTableEntryType *testSymbol; symbolTableEntryType *testSymbol;
genericTableEntryType *hashStringLookup();
genericTableEntryType *hashStringEnter();
macroTableEntryType *buildMacroTableEntry();
symbolTableEntryType *lookupOrEnterSymbol();
testSymbol = lookupOrEnterSymbol(macroName, MACRO_SYMBOL); testSymbol = lookupOrEnterSymbol(macroName, MACRO_SYMBOL);
if (testSymbol->context->usage != MACRO_SYMBOL) { if (testSymbol->context->usage != MACRO_SYMBOL) {
error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol)); error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol));
@ -179,10 +158,7 @@ createMacro(macroName)
*/ */
genericTableEntryType * genericTableEntryType *
prehashedStringLookup(s, table, hashValue) prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue)
char *s;
genericTableEntryType *table[];
int hashValue;
{ {
genericTableEntryType *result; genericTableEntryType *result;
int test; int test;
@ -202,17 +178,13 @@ prehashedStringLookup(s, table, hashValue)
} }
genericTableEntryType * genericTableEntryType *
hashStringLookup(s, table) hashStringLookup(char *s, genericTableEntryType **table)
char *s;
genericTableEntryType *table[];
{ {
return(prehashedStringLookup(s, table, hashString(s))); return(prehashedStringLookup(s, table, hashString(s)));
} }
genericTableEntryType * genericTableEntryType *
hashStringEnter(entry, table) hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table)
genericTableEntryType *entry;
genericTableEntryType *table[];
{ {
genericTableEntryType *result; genericTableEntryType *result;
genericTableEntryType *oldResult; genericTableEntryType *oldResult;
@ -252,8 +224,7 @@ hashStringEnter(entry, table)
} }
int int
hashString(s) hashString(char *s)
char *s;
{ {
unsigned result; unsigned result;
@ -264,9 +235,9 @@ hashString(s)
} }
bool bool
strcmplc(s1, s2) /* string compare in lower case */ strcmplc(char *s1, char *s2) /* string compare in lower case */
char *s1; /* heavily optimized version */ /* heavily optimized version */
char *s2;
{ {
char c1; char c1;
int result; int result;
@ -284,9 +255,9 @@ strcmplc(s1, s2) /* string compare in lower case */
} }
bool bool
strcmplct(s1, s2) /* For tables: s2 is already lower case */ strcmplct(char *s1, char *s2) /* For tables: s2 is already lower case */
char *s1; /* heavily optimized version. */ /* heavily optimized version. */
char *s2;
{ {
char c1; char c1;
int result; int result;
@ -302,21 +273,16 @@ strcmplct(s1, s2) /* For tables: s2 is already lower case */
} }
void void
purgeSymbol(symbol) purgeSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
if ((context = getWorkingContext(symbol)) != NULL) if ((context = getWorkingContext(symbol)) != NULL)
context->usage = DEAD_SYMBOL; context->usage = DEAD_SYMBOL;
} }
void void
reincarnateSymbol(context, newUsage) reincarnateSymbol(symbolInContextType *context, symbolUsageKindType newUsage)
symbolInContextType *context;
symbolUsageKindType newUsage;
{ {
context->attributes = 0; context->attributes = 0;
dupValue(context->value, UndefinedValue); dupValue(context->value, UndefinedValue);
@ -329,13 +295,8 @@ reincarnateSymbol(context, newUsage)
*/ */
void void
pushBinding(symbol, newBinding, newUsage) pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage)
symbolTableEntryType *symbol;
valueType *newBinding;
symbolUsageKindType newUsage;
{ {
valueType *newValue();
pushSymbol(symbol); pushSymbol(symbol);
if (newBinding == NULL) if (newBinding == NULL)
newBinding = newValue(FAIL, 0, EXPRESSION_OPND); newBinding = newValue(FAIL, 0, EXPRESSION_OPND);
@ -347,17 +308,13 @@ pushBinding(symbol, newBinding, newUsage)
} }
void void
popBinding(symbol) popBinding(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
popSymbol(symbol); popSymbol(symbol);
} }
int /* returns number of bindings completed, negative this if failure */ int /* returns number of bindings completed, negative this if failure */
bindMacroArguments(argumentList, parameterList, macroName) bindMacroArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName)
argumentDefinitionListType *argumentList;
operandListType *parameterList;
stringType *macroName;
{ {
int numberBound; int numberBound;
bool arrayTag; bool arrayTag;
@ -365,8 +322,6 @@ bindMacroArguments(argumentList, parameterList, macroName)
valueType **arrayContents; valueType **arrayContents;
int i; int i;
valueType *newValue();
if (argumentList == NULL) if (argumentList == NULL)
arrayTag = FALSE; arrayTag = FALSE;
else else
@ -417,10 +372,7 @@ bindMacroArguments(argumentList, parameterList, macroName)
} }
int /* returns number of bindings completed, negative this if failure */ int /* returns number of bindings completed, negative this if failure */
bindFunctionArguments(argumentList, parameterList, functionName) bindFunctionArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName)
argumentDefinitionListType *argumentList;
operandListType *parameterList;
stringType *functionName;
{ {
valueType *argument; valueType *argument;
bool arrayTag; bool arrayTag;
@ -431,9 +383,6 @@ bindFunctionArguments(argumentList, parameterList, functionName)
valueType *firstArgument; valueType *firstArgument;
environmentType *saveEnvironment; environmentType *saveEnvironment;
valueType *evaluateOperand();
valueType *newValue();
if (argumentList == NULL) if (argumentList == NULL)
arrayTag = FALSE; arrayTag = FALSE;
else else
@ -444,7 +393,7 @@ bindFunctionArguments(argumentList, parameterList, functionName)
nextArgument!=NULL) && parameterList!=NULL) { nextArgument!=NULL) && parameterList!=NULL) {
saveEnvironment = currentEnvironment; saveEnvironment = currentEnvironment;
currentEnvironment = currentEnvironment->previousEnvironment; currentEnvironment = currentEnvironment->previousEnvironment;
argument = evaluateOperand(parameterList, NO_FIXUP); argument = evaluateOperand(parameterList);
currentEnvironment = saveEnvironment; currentEnvironment = saveEnvironment;
if (firstArgument == NULL) if (firstArgument == NULL)
firstArgument = argument; firstArgument = argument;
@ -495,7 +444,7 @@ bindFunctionArguments(argumentList, parameterList, functionName)
saveEnvironment = currentEnvironment; saveEnvironment = currentEnvironment;
currentEnvironment = currentEnvironment-> currentEnvironment = currentEnvironment->
previousEnvironment; previousEnvironment;
argument = evaluateOperand(parameterList, NO_FIXUP); argument = evaluateOperand(parameterList);
currentEnvironment = saveEnvironment; currentEnvironment = saveEnvironment;
if (firstArgument == NULL) if (firstArgument == NULL)
firstArgument = argument; firstArgument = argument;
@ -515,9 +464,7 @@ bindFunctionArguments(argumentList, parameterList, functionName)
} }
void void
unbindArguments(argumentList, numberToUnbind) unbindArguments(argumentDefinitionListType *argumentList, int numberToUnbind)
argumentDefinitionListType *argumentList;
int numberToUnbind;
{ {
while (argumentList != NULL && numberToUnbind-- > 0) { while (argumentList != NULL && numberToUnbind-- > 0) {
popBinding(argumentList->theArgument); popBinding(argumentList->theArgument);
@ -528,8 +475,7 @@ unbindArguments(argumentList, numberToUnbind)
} }
void void
unbindLocalVariables(identifierList) unbindLocalVariables(identifierListType *identifierList)
identifierListType *identifierList;
{ {
identifierListType *deadEntry; identifierListType *deadEntry;

29
lookups.h Normal file
View File

@ -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

View File

@ -29,144 +29,144 @@
*/ */
bool backwardsCompatibleIfFlag; extern bool backwardsCompatibleIfFlag;
bool beneathFunction; extern bool beneathFunction;
commandLineDefineType *commandLineDefines; extern commandLineDefineType *commandLineDefines;
int cumulativeLineNumber; extern int cumulativeLineNumber;
environmentType *currentEnvironment; extern environmentType *currentEnvironment;
int currentFieldOffset; extern int currentFieldOffset;
char *currentFileName; extern char *currentFileName;
char *lastErrorFile; extern char *lastErrorFile;
stringType *currentFunctionName; extern stringType *currentFunctionName;
int currentLabelTagNumber; extern int currentLabelTagNumber;
int currentLineNumber; extern int currentLineNumber;
int lastErrorLine; extern int lastErrorLine;
identifierListType *currentLocalVariableList; extern identifierListType *currentLocalVariableList;
valueType currentLocationCounter; extern valueType currentLocationCounter;
int currentOperandNumber; extern int currentOperandNumber;
int currentReferenceDepth; extern int currentReferenceDepth;
bool debug; extern bool debug;
bool emitPrint; extern bool emitPrint;
bool expandMacros; extern bool expandMacros;
bool errorFlag; extern bool errorFlag;
bool expressionFailed; extern bool expressionFailed;
bool finishOperand; extern bool finishOperand;
operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; extern operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS];
operandKindType newFixupAddressMode; extern operandKindType newFixupAddressMode;
fixupListType *fixupList; extern fixupListType *fixupList;
bool freeFlag; extern bool freeFlag;
bool freturnExit; extern bool freturnExit;
bool generatingFixup; extern bool generatingFixup;
environmentType globalEnvironment; extern environmentType globalEnvironment;
int hackFlag; extern int hackFlag;
bool haveUserStartAddress; extern bool haveUserStartAddress;
bool fixupStartAddress; extern bool fixupStartAddress;
int includeNestingDepth; extern int includeNestingDepth;
FILE *indexFileForPass2; extern FILE *indexFileForPass2;
FILE *input; extern FILE *input;
fileNameListType *inputFileStack; extern fileNameListType *inputFileStack;
FILE *listFileOutput; extern FILE *listFileOutput;
int listingControlCounter; extern int listingControlCounter;
bool listingOn; extern bool listingOn;
int macroCallDepth; extern int macroCallDepth;
FILE *macroFileForPass2; extern FILE *macroFileForPass2;
int macroOrFunctionNestingDepth; extern int macroOrFunctionNestingDepth;
structInstanceType *newStruct; extern structInstanceType *newStruct;
int nextEnvironmentNumber; extern int nextEnvironmentNumber;
int nextLabelTagNumber; extern int nextLabelTagNumber;
FILE *objectFileOutput; extern FILE *objectFileOutput;
char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; extern char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE];
char pass2IndexFileName[]; extern char pass2IndexFileName[];
char pass2SourceFileName[]; extern char pass2SourceFileName[];
char pass2MacroExpansionFileName[]; extern char pass2MacroExpansionFileName[];
expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; extern expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS];
bool performingFixups; extern bool performingFixups;
bool positionIndependentCodeMode; extern bool positionIndependentCodeMode;
bool produceLinkableObject; extern bool produceLinkableObject;
addressType relocatableHighWaterMark; extern addressType relocatableHighWaterMark;
reservationListType *reservationList; extern reservationListType *reservationList;
valueType *resultOfLastFunctionCall; extern valueType *resultOfLastFunctionCall;
valueType savedRelocatableCurrentLocationCounter; extern valueType savedRelocatableCurrentLocationCounter;
FILE *saveFileForPass2; extern FILE *saveFileForPass2;
bool showAllSymbolsFlag; extern bool showAllSymbolsFlag;
bool sideEffectFlag; extern bool sideEffectFlag;
bool standaloneExpansionFlag; extern bool standaloneExpansionFlag;
valueType *startAddress; extern valueType *startAddress;
int statementEvaluationDepth; extern int statementEvaluationDepth;
int statementListNestingDepth; extern int statementListNestingDepth;
int structNestingDepth; extern int structNestingDepth;
FILE *symbolDumpFileOutput; extern FILE *symbolDumpFileOutput;
bool symbolTableDumpOn; extern bool symbolTableDumpOn;
int tabCount; extern int tabCount;
addressType targetOffset; extern addressType targetOffset;
bool terseErrorMessages; extern bool terseErrorMessages;
valueType *UndefinedValue; extern valueType *UndefinedValue;
symbolUsageKindType unknownSymbolTag; extern symbolUsageKindType unknownSymbolTag;
#define DEFAULT_OBJECT_FILE_NAME "m.out" #define DEFAULT_OBJECT_FILE_NAME "m.out"
#define LEX_DISPATCH_TABLE_SIZE 128 #define LEX_DISPATCH_TABLE_SIZE 128
int (*lexDispatchTable[128])(); extern int (*lexDispatchTable[128])();
#define HASH_TABLE_SIZE 512 #define HASH_TABLE_SIZE 512
#define HASH_TABLE_MASK 0x1FF #define HASH_TABLE_MASK 0x1FF
struct { extern struct {
stringType *functionName; stringType *functionName;
valueType *(*functionEntry)(); valueType *(*functionEntry)();
bool isSpecialFunction; bool isSpecialFunction;
int ordinal; int ordinal;
} builtInFunctionTable[]; } builtInFunctionTable[];
struct { extern struct {
stringType *symbolName; stringType *symbolName;
int symbolValue; int symbolValue;
} predefinedSymbolTable[]; } 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; extern codeRegionType absoluteCodeRegion;
codeRegionType relocatableCodeRegion; extern codeRegionType relocatableCodeRegion;
codeRegionType *codeRegions[2]; extern codeRegionType *codeRegions[2];
codeBufferKindType currentCodeMode; extern codeBufferKindType currentCodeMode;
codeBufferType *emptyBuffer; /* ??? */ extern codeBufferType *emptyBuffer; /* ??? */
codeBreakType *codeBreakList; extern codeBreakType *codeBreakList;
codeBreakType *lastCodeBreak; extern codeBreakType *lastCodeBreak;
expressionReferenceListType *expressionReferenceList[3]; extern expressionReferenceListType *expressionReferenceList[3];
expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; extern expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS];
int numberOfReferencesInList[3]; extern int numberOfReferencesInList[3];
functionDefinitionType *externalFunctionList; extern functionDefinitionType *externalFunctionList;
functionDefinitionType *endOfExternalFunctionList; extern functionDefinitionType *endOfExternalFunctionList;
int externalFunctionCount; extern int externalFunctionCount;
char alphabeticCharacterTable[128]; extern char alphabeticCharacterTable[128];
char alphaNumericCharacterTable[128]; extern char alphaNumericCharacterTable[128];
char lowerCaseCharacterTable[128]; extern char lowerCaseCharacterTable[128];
char numericCharacterTable[128]; extern char numericCharacterTable[128];
int expressionBufferSize; extern int expressionBufferSize;
#define EXPRESSION_BUFFER_LIMIT 500 #define EXPRESSION_BUFFER_LIMIT 500
byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; extern byte expressionBuffer[EXPRESSION_BUFFER_LIMIT];

View File

@ -29,6 +29,8 @@
*/ */
#include "macrossTypes.h" #include "macrossTypes.h"
#include "actions.h"
#include "builtInFunctions.h"
#include "y.tab.h" #include "y.tab.h"
/* All those NULLs are used to string together lists after this all gets /* 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, 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 */ /* indexed by opcodeClass */
int (*instructionActionTable[])() = { int (*instructionActionTable[])() = {
actionsRelative, actionsRelative,
@ -303,54 +290,6 @@ valueType undefinedValueValue = { UNDEFINED_VALUE, 0,
EXPRESSION_OPND }; EXPRESSION_OPND };
valueType *UndefinedValue = &undefinedValueValue; 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 */ /* Used to initialize symbols representing built-in functions */
struct { struct {
stringType *functionName; stringType *functionName;

View File

@ -28,6 +28,10 @@
*/ */
#ifndef MACROSS_TYPES_H_
#define MACROSS_TYPES_H_
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
/* /*
@ -440,7 +444,7 @@ typedef union expressionTermBodyUnion {
valueType *valueUnion; valueType *valueUnion;
symbolTableEntryType *symbolTableUnion; symbolTableEntryType *symbolTableUnion;
conditionType conditionTypeUnion; 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; } expressionTermBodyType;
typedef struct expressionTermStruct { typedef struct expressionTermStruct {
@ -1093,3 +1097,5 @@ typedef enum {/* horrible kludge due to C compiler bug on Sun */
/* Boy, is this macro useful! */ /* Boy, is this macro useful! */
#define typeAlloc(type) (type *)malloc(sizeof(type)) #define typeAlloc(type) (type *)malloc(sizeof(type))
#endif

View File

@ -31,6 +31,14 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 statementList: statement
{ {
if (statementListNestingDepth == 0) { if (statementListNestingDepth == 0) {
$$ = eatStatement($1); eatStatement($1);
$$ = NULL;
} else { } else {
$$ = buildStatementList($1, NULL); $$ = buildStatementList($1, NULL);
} }
@ -127,7 +136,8 @@ statementList: statement
| statementList EOL statement | statementList EOL statement
{ {
if (statementListNestingDepth == 0) { if (statementListNestingDepth == 0) {
$$ = eatStatement($3); eatStatement($3);
$$ = NULL;
} else { } else {
$$ = buildStatementList($3, $1); $$ = buildStatementList($3, $1);
} }
@ -223,15 +233,21 @@ labelableStatement:
ifStatement: IF _ ifHead ifStatement: IF _ ifHead
{ {
$$ = buildIfStatement($3, NULL, NO_CONTINUATION); ifContinuationType noCont;
noCont.blockUnion=NULL;
$$ = buildIfStatement($3, noCont, NO_CONTINUATION);
} }
| IF _ ifHead elsePart | IF _ ifHead elsePart
{ {
$$ = buildIfStatement($3, $4, ELSE_CONTINUATION); ifContinuationType cont;
cont.blockUnion=$4;
$$ = buildIfStatement($3, cont, ELSE_CONTINUATION);
} }
| IF _ ifHead elseIf | 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 | ELSEIF _ ifHead
{ {
$$ = extractIfBody(buildIfStatement($3, NULL, NO_CONTINUATION)); ifContinuationType noCont;
noCont.blockUnion = NULL;
$$ = extractIfBody(buildIfStatement($3, noCont, NO_CONTINUATION));
} }
| ELSEIF _ ifHead elsePart | ELSEIF _ ifHead elsePart
{ {
$$ = extractIfBody(buildIfStatement($3, $4, ELSE_CONTINUATION)); ifContinuationType cont;
cont.blockUnion = $4;
$$ = extractIfBody(buildIfStatement($3, cont, ELSE_CONTINUATION));
} }
| ELSEIF _ ifHead elseIf | 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: macroIfStatement:
MIF _ mIfHead MIF _ mIfHead
{ {
$$ = buildMifStatement($3, NULL, NO_CONTINUATION); mifContinuationType noCont;
noCont.mifBlockUnion = NULL;
$$ = buildMifStatement($3, noCont, NO_CONTINUATION);
} }
| MIF _ mIfHead mElsePart | MIF _ mIfHead mElsePart
{ {
$$ = buildMifStatement($3, $4, ELSE_CONTINUATION); mifContinuationType cont;
cont.mifBlockUnion = $4;
$$ = buildMifStatement($3, cont, ELSE_CONTINUATION);
} }
| MIF _ mIfHead mElseIf | 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 | MELSEIF _ mIfHead
{ {
$$ = extractMifBody(buildMifStatement($3, NULL, NO_CONTINUATION)); mifContinuationType noCont;
noCont.mifBlockUnion = NULL;
$$ = extractMifBody(buildMifStatement($3, noCont, NO_CONTINUATION));
} }
| MELSEIF _ mIfHead mElsePart | MELSEIF _ mIfHead mElsePart
{ {
$$ = extractMifBody(buildMifStatement($3, $4, ELSE_CONTINUATION)); mifContinuationType cont;
cont.mifBlockUnion = $4;
$$ = extractMifBody(buildMifStatement($3, cont, ELSE_CONTINUATION));
} }
| MELSEIF _ mIfHead mElseIf | 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 _ ']' array: variable '[' _ expression _ ']'
{ {
$$ = buildExpressionTerm(ARRAY_EXPR, $1, $4); $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4, NULL);
} }
| array '[' _ expression _ ']' | array '[' _ expression _ ']'
{ {
$$ = buildExpressionTerm(ARRAY_EXPR, $1, $4); $$ = buildExpressionTerm(ARRAY_EXPR, $1, $4, NULL);
} }
; ;
variable: Identifier variable: Identifier
{ {
$$ = buildExpressionTerm(IDENTIFIER_EXPR, lookupOrEnterSymbol($1, $$ = buildExpressionTerm(IDENTIFIER_EXPR, lookupOrEnterSymbol($1,
unknownSymbolTag)); unknownSymbolTag), NULL, NULL);
} }
; ;
@ -968,47 +1002,47 @@ expression: lvalue
} }
| functionCall | functionCall
{ {
$$ = buildExpressionTerm(FUNCTION_CALL_EXPR, $1); $$ = buildExpressionTerm(FUNCTION_CALL_EXPR, $1, NULL, NULL);
} }
| Number | Number
{ {
$$ = buildExpressionTerm(NUMBER_EXPR, $1); $$ = buildExpressionTerm(NUMBER_EXPR, $1, NULL, NULL);
} }
| ConditionCode | ConditionCode
{ {
$$ = buildExpressionTerm(CONDITION_CODE_EXPR, $1); $$ = buildExpressionTerm(CONDITION_CODE_EXPR, $1, NULL, NULL);
} }
| HERE | HERE
{ {
$$ = buildExpressionTerm(HERE_EXPR); $$ = buildExpressionTerm(HERE_EXPR, NULL, NULL, NULL);
} }
| TextString | TextString
{ {
$$ = buildExpressionTerm(STRING_EXPR, $1); $$ = buildExpressionTerm(STRING_EXPR, $1, NULL, NULL);
} }
| '(' _ expression _ ')' | '(' _ expression _ ')'
{ {
$$ = buildExpressionTerm(SUBEXPRESSION_EXPR, $3); $$ = buildExpressionTerm(SUBEXPRESSION_EXPR, $3, NULL, NULL);
} }
| SUB _ expression %prec UNARY_MINUS | SUB _ expression %prec UNARY_MINUS
{ {
$$ = buildExpressionTerm(UNOP_EXPR, UNARY_MINUS, $3); $$ = buildExpressionTerm(UNOP_EXPR, UNARY_MINUS, $3, NULL);
} }
| LOGICAL_NOT _ expression | LOGICAL_NOT _ expression
{ {
$$ = buildExpressionTerm(UNOP_EXPR, LOGICAL_NOT, $3); $$ = buildExpressionTerm(UNOP_EXPR, LOGICAL_NOT, $3, NULL);
} }
| BITWISE_NOT _ expression | BITWISE_NOT _ expression
{ {
$$ = buildExpressionTerm(UNOP_EXPR, BITWISE_NOT, $3); $$ = buildExpressionTerm(UNOP_EXPR, BITWISE_NOT, $3, NULL);
} }
| DIV _ expression %prec LO_BYTE | DIV _ expression %prec LO_BYTE
{ {
$$ = buildExpressionTerm(UNOP_EXPR, LO_BYTE, $3); $$ = buildExpressionTerm(UNOP_EXPR, LO_BYTE, $3, NULL);
} }
| HI_BYTE _ expression | HI_BYTE _ expression
{ {
$$ = buildExpressionTerm(UNOP_EXPR, HI_BYTE, $3); $$ = buildExpressionTerm(UNOP_EXPR, HI_BYTE, $3, NULL);
} }
| expression MUL _ expression | expression MUL _ expression
{ {
@ -1052,7 +1086,7 @@ expression: lvalue
} }
| expression GREATER_THAN_OR_EQUAL_TO _ expression | 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 | expression EQUAL_TO _ expression
{ {
@ -1097,19 +1131,19 @@ expression: lvalue
} }
| lvalue INCREMENT | lvalue INCREMENT
{ {
$$ = buildExpressionTerm(POSTOP_EXPR, INCREMENT, $1); $$ = buildExpressionTerm(POSTOP_EXPR, INCREMENT, $1, NULL);
} }
| lvalue DECREMENT | lvalue DECREMENT
{ {
$$ = buildExpressionTerm(POSTOP_EXPR, DECREMENT, $1); $$ = buildExpressionTerm(POSTOP_EXPR, DECREMENT, $1, NULL);
} }
| INCREMENT _ lvalue | INCREMENT _ lvalue
{ {
$$ = buildExpressionTerm(PREOP_EXPR, INCREMENT, $3); $$ = buildExpressionTerm(PREOP_EXPR, INCREMENT, $3, NULL);
} }
| DECREMENT _ lvalue | DECREMENT _ lvalue
{ {
$$ = buildExpressionTerm(PREOP_EXPR, DECREMENT, $3); $$ = buildExpressionTerm(PREOP_EXPR, DECREMENT, $3, NULL);
} }
; ;

25
main.c
View File

@ -29,33 +29,40 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "initialize.h"
#include "semanticMisc.h"
#include "y.tab.h"
main(argc, argv) #include <unistd.h>
int argc;
char *argv[]; int
main(int argc, char **argv)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
char end = get_end(); char end = get_end();
#else #else
extern char end; extern char end;
#endif #endif
char *sbrk();
fflush(stdout); fflush(stdout);
initializeStuff(argc, argv); initializeStuff(argc, argv);
yyparse(); yyparse();
finishUp(); 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) if (emitPrint)
printf("storage high water mark 0x%x == %d\n", sbrk(0) - &end, printf("storage high water mark 0x%x == %d\n", (void *)sbrk(0) - (void *)(&end),
sbrk(0) - &end); (void *)sbrk(0) - (void *)(&end));
if (errorFlag) if (errorFlag)
chokePukeAndDie(); chokePukeAndDie();
else return 0;
exit(0);
} }
void void
printVersion() printVersion(void)
{ {
printf("Macross %s version 4.20.\n", TARGET_CPU_STRING); printf("Macross %s version 4.20.\n", TARGET_CPU_STRING);
} }

View File

@ -80,7 +80,7 @@ union overhead {
*/ */
#define NBUCKETS 30 #define NBUCKETS 30
static union overhead *nextf[NBUCKETS]; static union overhead *nextf[NBUCKETS];
extern char *sbrk(); extern char *sbrk(int);
#ifdef MSTATS #ifdef MSTATS
/* /*
@ -109,8 +109,7 @@ static void morecore(int);
static int findbucket(union overhead *, int); static int findbucket(union overhead *, int);
char * char *
malloc(nbytes) malloc(register unsigned int nbytes)
register unsigned nbytes;
{ {
register union overhead *p; register union overhead *p;
register int bucket = 0; register int bucket = 0;
@ -160,8 +159,7 @@ malloc(nbytes)
* Allocate more memory to the indicated bucket. * Allocate more memory to the indicated bucket.
*/ */
static void static void
morecore(bucket) morecore(register int bucket)
register bucket;
{ {
register union overhead *op; register union overhead *op;
register int rnu; /* 2^rnu bytes will be requested */ register int rnu; /* 2^rnu bytes will be requested */
@ -209,8 +207,7 @@ morecore(bucket)
} }
void void
free(cp) free(char *cp)
char *cp;
{ {
register int size; register int size;
register union overhead *op; register union overhead *op;
@ -252,9 +249,7 @@ free(cp)
int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */ int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */
char * char *
realloc(cp, nbytes) realloc(char *cp, unsigned int nbytes)
char *cp;
unsigned nbytes;
{ {
register u_int onb; register u_int onb;
union overhead *op; union overhead *op;
@ -304,9 +299,7 @@ realloc(cp, nbytes)
* Return bucket number, or -1 if not found. * Return bucket number, or -1 if not found.
*/ */
static static
findbucket(freep, srchlen) findbucket(union overhead *freep, int srchlen)
union overhead *freep;
int srchlen;
{ {
register union overhead *p; register union overhead *p;
register int i, j; register int i, j;

116
object.c
View File

@ -29,25 +29,24 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 <string.h>
static int symbolTableSize; static int symbolTableSize;
static int symbolTableStringSize; static int symbolTableStringSize;
bool encodingFunction; bool encodingFunction;
void 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) if (debug || emitPrint)
printCodeBuffers(); printCodeBuffers();
outputPartition(); outputPartition();
@ -70,22 +69,20 @@ outputObjectFile()
} }
void void
outputWord(aWord) outputWord(int aWord)
int aWord;
{ {
putc(aWord & 0xFF, objectFileOutput); putc(aWord & 0xFF, objectFileOutput);
putc((aWord >> 8) & 0xFF, objectFileOutput); putc((aWord >> 8) & 0xFF, objectFileOutput);
} }
void void
outputPartition() outputPartition(void)
{ {
outputWord(0xFFFF); outputWord(0xFFFF);
} }
void void
outputBigword(bigword) outputBigword(long unsigned int bigword)
unsigned long bigword;
{ {
int i; int i;
@ -96,15 +93,13 @@ outputBigword(bigword)
} }
void void
outputByte(aByte) outputByte(byte aByte)
byte aByte;
{ {
putc(aByte, objectFileOutput); putc(aByte, objectFileOutput);
} }
void void
outputString(string) outputString(stringType *string)
stringType *string;
{ {
do { do {
putc(*string, objectFileOutput); putc(*string, objectFileOutput);
@ -112,8 +107,7 @@ outputString(string)
} }
void void
outputStartAddress(startAddress) outputStartAddress(addressType startAddress)
addressType startAddress;
{ {
outputWord(startAddress); outputWord(startAddress);
if (produceLinkableObject) { if (produceLinkableObject) {
@ -126,15 +120,12 @@ outputStartAddress(startAddress)
} }
void void
outputRelocatableCode() outputRelocatableCode(void)
{ {
int i; int i;
addressType codeStartAddress; addressType codeStartAddress;
addressType codeEndAddress; addressType codeEndAddress;
void outputPseudoSegment();
void outputBreak();
if (haveUserStartAddress && !fixupStartAddress && startAddress-> if (haveUserStartAddress && !fixupStartAddress && startAddress->
kindOfValue == RELOCATABLE_VALUE) kindOfValue == RELOCATABLE_VALUE)
outputStartAddress(startAddress->value); outputStartAddress(startAddress->value);
@ -159,8 +150,7 @@ outputRelocatableCode()
} }
void void
outputBreak(codeBreak) outputBreak(codeBreakType *codeBreak)
codeBreakType *codeBreak;
{ {
switch (codeBreak->kindOfBreak) { switch (codeBreak->kindOfBreak) {
case BREAK_BREAK: case BREAK_BREAK:
@ -183,13 +173,12 @@ outputBreak(codeBreak)
} }
void void
outputAbsoluteCode() outputAbsoluteCode(void)
{ {
int i; int i;
int startSegment; int startSegment;
int endSegment; int endSegment;
int nextSegment; int nextSegment;
void outputOneCodeBuffer();
if (haveUserStartAddress && !fixupStartAddress && startAddress-> if (haveUserStartAddress && !fixupStartAddress && startAddress->
kindOfValue==ABSOLUTE_VALUE) kindOfValue==ABSOLUTE_VALUE)
@ -221,8 +210,7 @@ outputAbsoluteCode()
} }
void void
outputOneCodeBuffer(segment) outputOneCodeBuffer(codeSegmentType *segment)
codeSegmentType *segment;
{ {
int i; int i;
@ -236,9 +224,7 @@ outputOneCodeBuffer(segment)
} }
void void
outputPseudoSegment(codeStartAddress, codeEndAddress) outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress)
addressType codeStartAddress;
addressType codeEndAddress;
{ {
int startSegment; int startSegment;
int endSegment; int endSegment;
@ -250,9 +236,6 @@ outputPseudoSegment(codeStartAddress, codeEndAddress)
int segment; int segment;
codeSegmentType *segmentPtr; codeSegmentType *segmentPtr;
void outputWord();
void outputByte();
outputWord(codeStartAddress); outputWord(codeStartAddress);
outputWord(codeEndAddress); outputWord(codeEndAddress);
startSegment = bufferNumber(codeStartAddress); startSegment = bufferNumber(codeStartAddress);
@ -271,8 +254,7 @@ outputPseudoSegment(codeStartAddress, codeEndAddress)
} }
bool bool
isObjectSymbol(symbol) isObjectSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
return(symbol != NULL && symbol->context->value != NULL && return(symbol != NULL && symbol->context->value != NULL &&
symbol->context->value->kindOfValue != FUNCTION_VALUE && symbol->context->value->kindOfValue != FUNCTION_VALUE &&
@ -287,7 +269,7 @@ isObjectSymbol(symbol)
} }
void void
enumerateAndCountSymbols() enumerateAndCountSymbols(void)
{ {
int i; int i;
symbolTableEntryType *symb; symbolTableEntryType *symb;
@ -303,7 +285,7 @@ enumerateAndCountSymbols()
} }
int int
enumerateAndCountReferences() enumerateAndCountReferences(void)
{ {
int result; int result;
int codeMode; int codeMode;
@ -321,8 +303,7 @@ enumerateAndCountReferences()
} }
void void
outputReference(reference) outputReference(expressionReferenceType *reference)
expressionReferenceType *reference;
{ {
byte funnyByte; byte funnyByte;
bigWord funnyWord; bigWord funnyWord;
@ -344,7 +325,7 @@ outputReference(reference)
static int referenceCount; static int referenceCount;
void void
outputReferenceInfo() outputReferenceInfo(void)
{ {
expressionReferenceListType *theReferences; expressionReferenceListType *theReferences;
int codeMode; int codeMode;
@ -361,12 +342,10 @@ outputReferenceInfo()
} }
void void
outputOneSymbol(symbol) outputOneSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
byte symbolClass; byte symbolClass;
valueType *symbolValue; valueType *symbolValue;
valueType *evaluateIdentifier();
if (symbol->context->usage == DEFINE_SYMBOL) if (symbol->context->usage == DEFINE_SYMBOL)
symbolValue = evaluateIdentifier(symbol, FALSE, NO_FIXUP_OK); symbolValue = evaluateIdentifier(symbol, FALSE, NO_FIXUP_OK);
@ -388,7 +367,7 @@ outputOneSymbol(symbol)
} }
void void
outputSymbolTableInfo() outputSymbolTableInfo(void)
{ {
int i; int i;
symbolTableEntryType *symb; symbolTableEntryType *symb;
@ -402,16 +381,13 @@ outputSymbolTableInfo()
} }
int int
symbolCompare(symbol1, symbol2) symbolCompare(symbolTableEntryType **symbol1, symbolTableEntryType **symbol2)
symbolTableEntryType **symbol1;
symbolTableEntryType **symbol2;
{ {
return(strcmplc((*symbol1)->symbolName, (*symbol2)->symbolName)); return(strcmplc((*symbol1)->symbolName, (*symbol2)->symbolName));
} }
bool bool
shouldDumpSymbol(symbol) shouldDumpSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
return(symbolTableDumpOn == 2 return(symbolTableDumpOn == 2
|| (symbol->context->usage != BUILT_IN_FUNCTION_SYMBOL || (symbol->context->usage != BUILT_IN_FUNCTION_SYMBOL
@ -426,7 +402,7 @@ shouldDumpSymbol(symbol)
} }
void void
dumpSymbolTable() dumpSymbolTable(void)
{ {
int i; int i;
symbolTableEntryType *symb; symbolTableEntryType *symb;
@ -435,9 +411,6 @@ dumpSymbolTable()
int symbolPtr; int symbolPtr;
valueType *value; valueType *value;
valueType *evaluateIdentifier();
void printValueTersely();
numberOfSymbols = 0; numberOfSymbols = 0;
for (i=0; i<HASH_TABLE_SIZE; i++) for (i=0; i<HASH_TABLE_SIZE; i++)
for (symb=symbolTable[i]; symb!=NULL; symb=symb->nextSymbol) { for (symb=symbolTable[i]; symb!=NULL; symb=symb->nextSymbol) {
@ -503,16 +476,14 @@ dumpSymbolTable()
} }
bool bool
hackableSymbol(symbol) hackableSymbol(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
return(symbol->context->usage == DEFINE_SYMBOL || symbol->context-> return(symbol->context->usage == DEFINE_SYMBOL || symbol->context->
usage == LABEL_SYMBOL); usage == LABEL_SYMBOL);
} }
void void
printValueTersely(value) printValueTersely(valueType *value)
valueType *value;
{ {
static char *valueKindTable[NUM_OF_VALUE_KINDS] = { static char *valueKindTable[NUM_OF_VALUE_KINDS] = {
"ABS", "ABS",
@ -540,7 +511,7 @@ printValueTersely(value)
} }
void void
outputReservations() outputReservations(void)
{ {
while (reservationList != NULL) { while (reservationList != NULL) {
outputWord(reservationList->startAddress); outputWord(reservationList->startAddress);
@ -550,7 +521,7 @@ outputReservations()
} }
void void
outputExpressionBuffer() outputExpressionBuffer(void)
{ {
int i; int i;
@ -562,14 +533,10 @@ outputExpressionBuffer()
} }
void void
outputOneExpression(expression) outputOneExpression(expressionType *expression)
expressionType *expression;
{ {
expressionType *newExpression; expressionType *newExpression;
expressionType *generateFixupExpression();
bool encodeExpression();
expressionBufferSize = 0; expressionBufferSize = 0;
if (expression == NULL) { if (expression == NULL) {
encodeRelocatableNumber(0); encodeRelocatableNumber(0);
@ -583,7 +550,7 @@ outputOneExpression(expression)
} }
void void
outputExpressions() outputExpressions(void)
{ {
int codeMode; int codeMode;
expressionReferenceListType *theReferences; expressionReferenceListType *theReferences;
@ -602,12 +569,9 @@ outputExpressions()
} }
void void
outputOneFunction(function) outputOneFunction(functionDefinitionType *function)
functionDefinitionType *function;
{ {
argumentDefinitionListType *argumentList; argumentDefinitionListType *argumentList;
bool encodeBlock();
int countArguments();
outputByte((byte)countArguments(function)); outputByte((byte)countArguments(function));
argumentList = function->arguments; argumentList = function->arguments;
@ -621,7 +585,7 @@ outputOneFunction(function)
} }
void void
outputFunctions() outputFunctions(void)
{ {
outputBigword(externalFunctionCount); outputBigword(externalFunctionCount);
encodingFunction = TRUE; encodingFunction = TRUE;

37
object.h Normal file
View File

@ -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

View File

@ -57,10 +57,6 @@ typedef selectionListType ySelectedOperandBodyType;
typedef selectionListType preSelectedOperandBodyType; typedef selectionListType preSelectedOperandBodyType;
#define BlockOperandBodyType anyOldThing /* kludge */
/* doing above right confuses compiler as it is a forward reference inside
yon union: */
typedef union { typedef union {
expressionOperandBodyType *expressionUnion; expressionOperandBodyType *expressionUnion;
immediateOperandBodyType *immediateUnion; immediateOperandBodyType *immediateUnion;
@ -76,5 +72,5 @@ typedef union {
ySelectedOperandBodyType *ySelectedUnion; ySelectedOperandBodyType *ySelectedUnion;
preSelectedOperandBodyType *preSelectedUnion; preSelectedOperandBodyType *preSelectedUnion;
stringOperandBodyType *stringUnion; stringOperandBodyType *stringUnion;
BlockOperandBodyType *blockUnion; blockOperandBodyType *blockUnion;
} operandBodyType; } operandBodyType;

View File

@ -69,14 +69,10 @@ typedef nullType uspRegisterOperandBodyType;
typedef nullType controlRegisterOperandBodyType; typedef nullType controlRegisterOperandBodyType;
#define BlockOperandBodyType anyOldThing /* kludge */
/* doing above right confuses compiler as it is a forward reference inside
yon union: */
typedef union { typedef union {
expressionOperandBodyType *expressionUnion; expressionOperandBodyType *expressionUnion;
stringOperandBodyType *stringUnion; stringOperandBodyType *stringUnion;
BlockOperandBodyType *blockUnion; blockOperandBodyType *blockUnion;
dRegisterOperandBodyType *dRegisterUnion; dRegisterOperandBodyType *dRegisterUnion;
aRegisterOperandBodyType *aRegisterUnion; aRegisterOperandBodyType *aRegisterUnion;
aRegisterIndirectOperandBodyType *aRegisterIndirectUnion; aRegisterIndirectOperandBodyType *aRegisterIndirectUnion;

21
operandStuff.h Normal file
View File

@ -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

View File

@ -30,13 +30,20 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 */ /* corresponds to routines in buildStuff2.c */
operandType * operandType *
buildOperand(kindOfOperand, arg) buildOperand(operandKindType kindOfOperand, anyOldThing *arg)
operandKindType kindOfOperand;
anyOldThing *arg;
{ {
operandType *result; operandType *result;
@ -116,7 +123,7 @@ buildOperand(kindOfOperand, arg)
break; break;
case BLOCK_OPND: case BLOCK_OPND:
result->theOperand.blockUnion = (BlockOperandBodyType *) arg; result->theOperand.blockUnion = (blockOperandBodyType *) arg;
break; break;
default: default:
@ -129,14 +136,10 @@ buildOperand(kindOfOperand, arg)
/* corresponds to routines in fixups.c */ /* corresponds to routines in fixups.c */
operandListType * operandListType *
duplicateOperandForFixup(operand, isSpecialFunctionOperand) duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand)
operandListType *operand;
bool isSpecialFunctionOperand;
{ {
operandListType *result; operandListType *result;
expressionType *duplicateExpressionForFixup();
result = typeAlloc(operandListType); result = typeAlloc(operandListType);
result->kindOfOperand = operand->kindOfOperand; result->kindOfOperand = operand->kindOfOperand;
result->nextOperand = NULL; result->nextOperand = NULL;
@ -151,14 +154,14 @@ duplicateOperandForFixup(operand, isSpecialFunctionOperand)
case X_INDEXED_OPND: case X_INDEXED_OPND:
case Y_INDEXED_OPND: case Y_INDEXED_OPND:
result->theOperand.expressionUnion = result->theOperand.expressionUnion =
duplicateExpressionForFixup(operand->theOperand, duplicateExpressionForFixup(operand->theOperand.expressionUnion,
FALSE, isSpecialFunctionOperand); FALSE, isSpecialFunctionOperand);
break; break;
case X_SELECTED_OPND: case X_SELECTED_OPND:
case Y_SELECTED_OPND: case Y_SELECTED_OPND:
case PRE_SELECTED_X_OPND: case PRE_SELECTED_X_OPND:
result->theOperand.expressionUnion = result->theOperand.expressionUnion =
duplicateExpressionForFixup(operand->theOperand, duplicateExpressionForFixup(operand->theOperand.xSelectedUnion,
FALSE, isSpecialFunctionOperand); FALSE, isSpecialFunctionOperand);
break; break;
case A_REGISTER_OPND: case A_REGISTER_OPND:
@ -182,8 +185,7 @@ duplicateOperandForFixup(operand, isSpecialFunctionOperand)
#define nullFree(thing) if (thing == NULL) return; #define nullFree(thing) if (thing == NULL) return;
void void
freeOperand(operand) freeOperand(operandType *operand)
operandType *operand;
{ {
nullFree(operand); nullFree(operand);
switch (operand->kindOfOperand) { switch (operand->kindOfOperand) {
@ -195,7 +197,7 @@ freeOperand(operand)
case PRE_INDEXED_X_OPND: case PRE_INDEXED_X_OPND:
case X_INDEXED_OPND: case X_INDEXED_OPND:
case Y_INDEXED_OPND: case Y_INDEXED_OPND:
freeExpression(operand->theOperand); freeExpression(operand->theOperand.expressionUnion);
break; break;
case A_REGISTER_OPND: case A_REGISTER_OPND:
@ -206,15 +208,15 @@ freeOperand(operand)
case X_SELECTED_OPND: case X_SELECTED_OPND:
case Y_SELECTED_OPND: case Y_SELECTED_OPND:
case PRE_SELECTED_X_OPND: case PRE_SELECTED_X_OPND:
freeSelectionList(operand->theOperand); freeSelectionList(operand->theOperand.xSelectedUnion);
break; break;
case STRING_OPND: case STRING_OPND:
freeString(operand->theOperand); freeString(operand->theOperand.stringUnion);
break; break;
case BLOCK_OPND: case BLOCK_OPND:
freeBlock(operand->theOperand); freeBlock(operand->theOperand.blockUnion);
break; break;
default: default:
@ -229,8 +231,7 @@ freeOperand(operand)
/* corresponds to routines in listing.c */ /* corresponds to routines in listing.c */
void void
expandOperand(addressMode) expandOperand(operandKindType addressMode, char *buffer)
operandKindType addressMode;
{ {
switch (addressMode) { switch (addressMode) {
case IMMEDIATE_OPND: moreText("#"); break; case IMMEDIATE_OPND: moreText("#"); break;
@ -247,7 +248,7 @@ expandOperand(addressMode)
case PRE_SELECTED_X_OPND: moreText("@x"); break; case PRE_SELECTED_X_OPND: moreText("@x"); break;
default: break; default: break;
} }
expandExpression(NULL); expandExpression(NULL, NULL);
if (addressMode == POST_INDEXED_Y_OPND || if (addressMode == POST_INDEXED_Y_OPND ||
addressMode == PRE_INDEXED_X_OPND || addressMode == PRE_INDEXED_X_OPND ||
addressMode == X_INDEXED_OPND || addressMode == X_INDEXED_OPND ||
@ -278,17 +279,12 @@ expandOperand(addressMode)
#define expansionOn() expandMacros=saveExpansion; #define expansionOn() expandMacros=saveExpansion;
valueType * valueType *
evaluateOperand(operand) evaluateOperand(operandType *operand)
operandType *operand;
{ {
valueType *result; valueType *result;
bool saveExpansion; bool saveExpansion;
expressionType *expression; expressionType *expression;
valueType *evaluateExpression();
valueType *evaluateSelectionList();
valueType *newValue();
nullEvaluate(operand); nullEvaluate(operand);
if (operand->kindOfOperand != EXPRESSION_OPND) if (operand->kindOfOperand != EXPRESSION_OPND)
newFixupAddressMode = operand->kindOfOperand; newFixupAddressMode = operand->kindOfOperand;
@ -301,7 +297,7 @@ evaluateOperand(operand)
case PRE_INDEXED_X_OPND: case PRE_INDEXED_X_OPND:
case X_INDEXED_OPND: case X_INDEXED_OPND:
case Y_INDEXED_OPND: case Y_INDEXED_OPND:
result = evaluateExpression(operand->theOperand, result = evaluateExpression(operand->theOperand.expressionUnion,
performingFixups ? NO_FIXUP : OPERAND_FIXUP); performingFixups ? NO_FIXUP : OPERAND_FIXUP);
if (operand->kindOfOperand != EXPRESSION_OPND) { if (operand->kindOfOperand != EXPRESSION_OPND) {
if (result->addressMode != EXPRESSION_OPND) { if (result->addressMode != EXPRESSION_OPND) {
@ -323,7 +319,7 @@ evaluateOperand(operand)
case X_SELECTED_OPND: case X_SELECTED_OPND:
case Y_SELECTED_OPND: case Y_SELECTED_OPND:
case PRE_SELECTED_X_OPND: case PRE_SELECTED_X_OPND:
result = evaluateSelectionList(operand->theOperand); result = evaluateSelectionList(operand->theOperand.xSelectedUnion);
if (result->addressMode != EXPRESSION_OPND) { if (result->addressMode != EXPRESSION_OPND) {
error(BAD_ADDRESS_MODE_ERROR); error(BAD_ADDRESS_MODE_ERROR);
result->kindOfValue = FAIL; result->kindOfValue = FAIL;
@ -333,7 +329,7 @@ evaluateOperand(operand)
break; break;
case STRING_OPND: case STRING_OPND:
result = newValue(STRING_VALUE, operand->theOperand, result = newValue(STRING_VALUE, operand->theOperand.stringUnion,
STRING_OPND); STRING_OPND);
break; break;
@ -341,7 +337,7 @@ evaluateOperand(operand)
if (standaloneExpansionFlag) if (standaloneExpansionFlag)
forceExpansion(); forceExpansion();
sideEffectFlag = TRUE; sideEffectFlag = TRUE;
assembleBlock(operand->theOperand); assembleBlock(operand->theOperand.blockUnion);
expansionOn(); expansionOn();
result = newValue(FAIL, 0, BLOCK_OPND); result = newValue(FAIL, 0, BLOCK_OPND);
break; break;
@ -357,8 +353,7 @@ evaluateOperand(operand)
/* from parserMisc.c */ /* from parserMisc.c */
conditionType conditionType
invertConditionCode(conditionCode) invertConditionCode(conditionType conditionCode)
conditionType conditionCode;
{ {
#define cc (int)conditionCode #define cc (int)conditionCode
@ -375,8 +370,7 @@ invertConditionCode(conditionCode)
/* from semanticMisc.c */ /* from semanticMisc.c */
bool bool
shouldParenthesize(operand) shouldParenthesize(operandType *operand)
operandType *operand;
{ {
expressionTermKindType kind; expressionTermKindType kind;

View File

@ -59,7 +59,7 @@ buildOperand(kindOfOperand, arg1, arg2, arg3, arg4)
break; break;
case BLOCK_OPND: case BLOCK_OPND:
result->theOperand.blockUnion = (BlockOperandBodyType *) arg1; result->theOperand.blockUnion = (blockOperandBodyType *) arg1;
break; break;
case D_REGISTER_OPND: case D_REGISTER_OPND:

View File

@ -32,114 +32,115 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "y.tab.h" #include "y.tab.h"
#include "buildStuff.h"
#include "fixups.h"
#include "initialize.h"
#include "errorStuff.h"
#include "parserMisc.h"
#include <stdarg.h>
#include <string.h>
statementType * statementType *
addLabelToStatement(labelList, statement) addLabelToStatement(labelListType *labelList, statementType *statement)
labelListType *labelList;
statementType *statement;
{ {
statementType *newStatement();
if (statement == NULL) if (statement == NULL)
statement = newStatement(NULL_STATEMENT, NULL); statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL });
statement->labels = labelList; statement->labels = labelList;
return(statement); return(statement);
} }
/* TODO: This should be a varargs function. In 1984 it probably wasn't
* standardized, but here in Glorious Future Year 1989 the vprintf
* function does almost exactly what we want. */
void void
botch(message, arg1, arg2, arg3) botch(char *message, ...)
char *message;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
{ {
va_list ap;
printf("Macross horrible terrible internal botch: "); printf("Macross horrible terrible internal botch: ");
printf(message, arg1, arg2, arg3); va_start(ap, message);
vprintf(message, ap);
va_end(ap);
chokePukeAndDie(); chokePukeAndDie();
} }
void void
checkDefineAssignmentOperator(assignmentOperator) checkDefineAssignmentOperator(assignmentKindType assignmentOperator)
assignmentKindType assignmentOperator;
{ {
if (assignmentOperator != ASSIGN_ASSIGN) if (assignmentOperator != ASSIGN_ASSIGN)
puntOnError(DEFINE_ASSIGNMENT_WRONG_ERROR); puntOnError(DEFINE_ASSIGNMENT_WRONG_ERROR);
} }
statementType * statementType *
convertDefineToMdefine(defineStatement) convertDefineToMdefine(statementType *defineStatement)
statementType *defineStatement;
{ {
if (defineStatement->kindOfStatement != DEFINE_STATEMENT) if (defineStatement->kindOfStatement != DEFINE_STATEMENT)
botch("convertDefineToMdefine got statement kind: %d\n", botch("convertDefineToMdefine got statement kind: %d\n",
defineStatement->kindOfStatement); defineStatement->kindOfStatement, 0, 0);
defineStatement->kindOfStatement = MDEFINE_STATEMENT; defineStatement->kindOfStatement = MDEFINE_STATEMENT;
return(defineStatement); return(defineStatement);
} }
ifStatementBodyType * ifStatementBodyType *
extractIfBody(ifStatement) extractIfBody(statementType *ifStatement)
statementType *ifStatement;
{ {
ifStatementBodyType *result; ifStatementBodyType *result;
result = ifStatement->statementBody.ifUnion; result = ifStatement->statementBody.ifUnion;
if (ifStatement->labels != NULL) 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) 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 else
qfree(ifStatement); qfree(ifStatement);
return(result); return(result);
} }
mifStatementBodyType * mifStatementBodyType *
extractMifBody(mifStatement) extractMifBody(statementType *mifStatement)
statementType *mifStatement;
{ {
mifStatementBodyType *result; mifStatementBodyType *result;
result = mifStatement->statementBody.mifUnion; result = mifStatement->statementBody.mifUnion;
if (mifStatement->labels != NULL) 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) 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 else
qfree(mifStatement); qfree(mifStatement);
return(result); return(result);
} }
stringType * stringType *
extractString(textExpression) extractString(operandType *textExpression)
operandType *textExpression;
{ {
stringType *result; stringType *result;
if (textExpression->kindOfOperand != STRING_OPND) if (textExpression->kindOfOperand != STRING_OPND)
botch("extract string got handed an opnd kind: %d\n", botch("extract string got handed an opnd kind: %d\n",
textExpression->kindOfOperand); textExpression->kindOfOperand, 0, 0);
result = textExpression->theOperand.stringUnion; result = textExpression->theOperand.stringUnion;
qfree(textExpression); qfree(textExpression);
return(result); return(result);
} }
void void
popMacroOrFunctionNestingDepth() popMacroOrFunctionNestingDepth(void)
{ {
if (--macroOrFunctionNestingDepth == 0) if (--macroOrFunctionNestingDepth == 0)
unknownSymbolTag = UNKNOWN_SYMBOL; unknownSymbolTag = UNKNOWN_SYMBOL;
} }
void void
pushMacroOrFunctionNestingDepth() pushMacroOrFunctionNestingDepth(void)
{ {
macroOrFunctionNestingDepth++; macroOrFunctionNestingDepth++;
unknownSymbolTag = NESTED_UNKNOWN_SYMBOL; unknownSymbolTag = NESTED_UNKNOWN_SYMBOL;
} }
char * char *
saveString(s) saveString(char *s)
char *s;
{ {
char *result; char *result;

17
parserMisc.h Normal file
View File

@ -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

View File

@ -32,6 +32,21 @@
#include "macrossGlobals.h" #include "macrossGlobals.h"
#include "y.tab.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 <string.h>
#define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;} #define expansionOff() {saveExpansion=expandMacros; expandMacros=FALSE;}
#define expansionOn() expandMacros=saveExpansion; #define expansionOn() expandMacros=saveExpansion;
@ -40,20 +55,17 @@
*/ */
bool bool
absoluteValue(address) absoluteValue(valueType *address)
valueType *address;
{ {
return(address->kindOfValue == ABSOLUTE_VALUE); return(address->kindOfValue == ABSOLUTE_VALUE);
} }
void void
addAttributeToSymbol(symbol, attribute) addAttributeToSymbol(symbolTableEntryType *symbol, symbolAttributesType attribute)
symbolTableEntryType *symbol;
symbolAttributesType attribute;
{ {
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getBaseContext(); symbolInContextType *getBaseContext(symbolTableEntryType *identifier);
context = getBaseContext(symbol); context = getBaseContext(symbol);
if (context != NULL) if (context != NULL)
@ -61,8 +73,7 @@ addAttributeToSymbol(symbol, attribute)
} }
addressType addressType
addressValue(value) addressValue(valueType *value)
valueType *value;
{ {
if (value->kindOfValue==STRING_VALUE || if (value->kindOfValue==STRING_VALUE ||
value->kindOfValue==CONDITION_VALUE || value->kindOfValue==CONDITION_VALUE ||
@ -73,9 +84,7 @@ addressValue(value)
} }
valueKindType valueKindType
addValueKind(leftOperand, rightOperand) addValueKind(valueType *leftOperand, valueType *rightOperand)
valueType *leftOperand;
valueType *rightOperand;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -206,20 +215,17 @@ addValueKind(leftOperand, rightOperand)
} }
bool bool
alreadyDefined(context) alreadyDefined(symbolInContextType *context)
symbolInContextType *context;
{ {
return((context->attributes & DEFINED_VARIABLE_ATT) != 0); return((context->attributes & DEFINED_VARIABLE_ATT) != 0);
} }
bool bool
booleanTest(expression) booleanTest(expressionType *expression)
expressionType *expression;
{ {
bool result; bool result;
valueType *expressionResult; valueType *expressionResult;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
expansionOff(); expansionOff();
expressionResult = evaluateExpression(expression, NO_FIXUP); expressionResult = evaluateExpression(expression, NO_FIXUP);
@ -238,8 +244,7 @@ booleanTest(expression)
} }
int int
countArguments(function) countArguments(functionDefinitionType *function)
functionDefinitionType *function;
{ {
int result; int result;
argumentDefinitionListType *arguments; argumentDefinitionListType *arguments;
@ -254,8 +259,7 @@ countArguments(function)
} }
int int
countParameters(parameterList) countParameters(operandListType *parameterList)
operandListType *parameterList;
{ {
int result; int result;
@ -268,9 +272,7 @@ countParameters(parameterList)
} }
arrayType * arrayType *
allocArray(size, contentsPtr) allocArray(int size, valueType ***contentsPtr)
int size;
valueType ***contentsPtr;
{ {
arrayType *result; arrayType *result;
int i; int i;
@ -285,9 +287,7 @@ allocArray(size, contentsPtr)
} }
valueType * valueType *
createArray(dimension, initializers) createArray(expressionType *dimension, expressionListType *initializers)
expressionType *dimension;
expressionListType *initializers;
{ {
int initCount; int initCount;
valueType *arraySizeValue; valueType *arraySizeValue;
@ -296,8 +296,6 @@ createArray(dimension, initializers)
arrayType *result; arrayType *result;
int i; int i;
valueType *newValue();
initCount = expressionListLength(initializers); initCount = expressionListLength(initializers);
if ((int)dimension == -1) { if ((int)dimension == -1) {
arraySize = initCount; arraySize = initCount;
@ -323,8 +321,7 @@ createArray(dimension, initializers)
} }
bool bool
decrementable(value) decrementable(valueType *value)
valueType *value;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -354,8 +351,7 @@ decrementable(value)
} }
int int
expressionListLength(expressionList) expressionListLength(expressionListType *expressionList)
expressionListType *expressionList;
{ {
int result; int result;
@ -368,11 +364,9 @@ expressionListLength(expressionList)
} }
int int
fieldValue(symbol) fieldValue(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
valueType *value; valueType *value;
valueType *evaluateIdentifier();
value = evaluateIdentifier(symbol, FALSE, NO_FIXUP); value = evaluateIdentifier(symbol, FALSE, NO_FIXUP);
if (value->kindOfValue != FIELD_VALUE) { if (value->kindOfValue != FIELD_VALUE) {
@ -384,8 +378,7 @@ fieldValue(symbol)
} }
bool bool
incrementable(value) incrementable(valueType *value)
valueType *value;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -415,8 +408,7 @@ incrementable(value)
} }
int int
intValue(value) intValue(valueType *value)
valueType *value;
{ {
if (value->kindOfValue != ABSOLUTE_VALUE) { if (value->kindOfValue != ABSOLUTE_VALUE) {
error(VALUE_IS_NOT_AN_INT_ERROR); error(VALUE_IS_NOT_AN_INT_ERROR);
@ -427,8 +419,7 @@ intValue(value)
} }
bool bool
isAssignable(context) isAssignable(symbolInContextType *context)
symbolInContextType *context;
{ {
return( context->usage==ARGUMENT_SYMBOL || return( context->usage==ARGUMENT_SYMBOL ||
context->usage==VARIABLE_SYMBOL || context->usage==VARIABLE_SYMBOL ||
@ -436,15 +427,13 @@ isAssignable(context)
} }
bool bool
isBuiltInFunction(context) isBuiltInFunction(symbolInContextType *context)
symbolInContextType *context;
{ {
return(context!=NULL && context->usage==BUILT_IN_FUNCTION_SYMBOL); return(context!=NULL && context->usage==BUILT_IN_FUNCTION_SYMBOL);
} }
bool bool
isDefinable(context) isDefinable(symbolInContextType *context)
symbolInContextType *context;
{ {
return( context->usage==DEFINE_SYMBOL || return( context->usage==DEFINE_SYMBOL ||
context->usage==DEAD_SYMBOL || context->usage==DEAD_SYMBOL ||
@ -453,21 +442,17 @@ isDefinable(context)
} }
bool bool
isExternal(symbol) isExternal(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getBaseContext();
context = getBaseContext(symbol); context = getBaseContext(symbol);
return (context!=NULL && (context->attributes & GLOBAL_ATT)!=0 && return (context!=NULL && (context->attributes & GLOBAL_ATT)!=0 &&
context->usage != DEAD_SYMBOL); context->usage != DEAD_SYMBOL);
} }
bool bool
isFailure(value) isFailure(valueType *value)
valueType *value;
{ {
if (value == NULL) if (value == NULL)
return(FALSE); return(FALSE);
@ -476,15 +461,13 @@ isFailure(value)
} }
bool bool
isFunction(context) isFunction(symbolInContextType *context)
symbolInContextType *context;
{ {
return(context!=NULL && context->usage==FUNCTION_SYMBOL); return(context!=NULL && context->usage==FUNCTION_SYMBOL);
} }
bool bool
isLastStatementInBlock(statement) isLastStatementInBlock(statementType *statement)
statementType *statement;
{ {
statement = statement->nextStatement; statement = statement->nextStatement;
while (statement != NULL) { while (statement != NULL) {
@ -517,8 +500,7 @@ isLastStatementInBlock(statement)
} }
bool bool
isLogicalOp(op) isLogicalOp(int op)
int op;
{ {
return (op==EQUAL_TO || op==GREATER_THAN || op== return (op==EQUAL_TO || op==GREATER_THAN || op==
GREATER_THAN_OR_EQUAL_TO || op==LESS_THAN || op== GREATER_THAN_OR_EQUAL_TO || op==LESS_THAN || op==
@ -527,8 +509,7 @@ isLogicalOp(op)
} }
bool bool
isPotentialVariable(context) isPotentialVariable(symbolInContextType *context)
symbolInContextType *context;
{ {
return( context->usage == VARIABLE_SYMBOL || return( context->usage == VARIABLE_SYMBOL ||
context->usage == DEAD_SYMBOL || context->usage == DEAD_SYMBOL ||
@ -536,33 +517,26 @@ isPotentialVariable(context)
} }
bool bool
isUndefined(value) isUndefined(valueType *value)
valueType *value;
{ {
return(value==NULL || value->kindOfValue==UNDEFINED_VALUE); return(value==NULL || value->kindOfValue==UNDEFINED_VALUE);
} }
bool bool
isUsable(value) isUsable(valueType *value)
valueType *value;
{ {
return(value!=NULL && value->kindOfValue!=UNDEFINED_VALUE && return(value!=NULL && value->kindOfValue!=UNDEFINED_VALUE &&
value->kindOfValue!=FAIL); value->kindOfValue!=FAIL);
} }
bool bool
logicalXOR(int1, int2) logicalXOR(int int1, int int2)
int int1;
int int2;
{ {
return((int1 && !int2) || (int2 && !int1)); return((int1 && !int2) || (int2 && !int1));
} }
valueType * valueType *
newValue(kindOfValue, value, addressMode) newValue(valueKindType kindOfValue, int value, operandKindType addressMode)
valueKindType kindOfValue;
int value;
operandKindType addressMode;
{ {
valueType *result; valueType *result;
@ -574,9 +548,7 @@ newValue(kindOfValue, value, addressMode)
} }
valueKindType valueKindType
opValueKind(leftOperand, rightOperand) opValueKind(valueType *leftOperand, valueType *rightOperand)
valueType *leftOperand;
valueType *rightOperand;
{ {
if (leftOperand->kindOfValue==ABSOLUTE_VALUE && rightOperand-> if (leftOperand->kindOfValue==ABSOLUTE_VALUE && rightOperand->
kindOfValue==ABSOLUTE_VALUE) kindOfValue==ABSOLUTE_VALUE)
@ -603,17 +575,14 @@ opValueKind(leftOperand, rightOperand)
} }
bool bool
relocatableValue(address) relocatableValue(valueType *address)
valueType *address;
{ {
return( address->kindOfValue==DATA_VALUE || return( address->kindOfValue==DATA_VALUE ||
address->kindOfValue==RELOCATABLE_VALUE ); address->kindOfValue==RELOCATABLE_VALUE );
} }
valueKindType valueKindType
selectValueKind(leftOperand, rightOperand) selectValueKind(valueType *leftOperand, valueType *rightOperand)
valueType *leftOperand;
valueType *rightOperand;
{ {
if (rightOperand->kindOfValue!=FIELD_VALUE || if (rightOperand->kindOfValue!=FIELD_VALUE ||
(leftOperand->kindOfValue!=ABSOLUTE_VALUE && (leftOperand->kindOfValue!=ABSOLUTE_VALUE &&
@ -625,9 +594,7 @@ selectValueKind(leftOperand, rightOperand)
} }
valueKindType valueKindType
subValueKind(leftOperand, rightOperand) subValueKind(valueType *leftOperand, valueType *rightOperand)
valueType *leftOperand;
valueType *rightOperand;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'valueKindType'. */ enumerated type 'valueKindType'. */
@ -758,25 +725,20 @@ subValueKind(leftOperand, rightOperand)
} }
int int
swab(i) swabInt(int i)
int i;
{ {
return(((i & 0xFF) << 8) | ((i & 0xFF00) >> 8)); return(((i & 0xFF) << 8) | ((i & 0xFF00) >> 8));
} }
valueType * valueType *
swabValue(value) swabValue(valueType *value)
valueType *value;
{ {
valueType *newValue(); return(newValue(value->kindOfValue, swabInt(value->value), value->
return(newValue(value->kindOfValue, swab(value->value), value->
addressMode)); addressMode));
} }
valueKindType valueKindType
unopValueKind(operand) unopValueKind(valueType *operand)
valueType *operand;
{ {
return(operand->kindOfValue==ABSOLUTE_VALUE || operand->kindOfValue== return(operand->kindOfValue==ABSOLUTE_VALUE || operand->kindOfValue==
UNDEFINED_VALUE || operand->kindOfValue==RELOCATABLE_VALUE ? UNDEFINED_VALUE || operand->kindOfValue==RELOCATABLE_VALUE ?
@ -784,15 +746,10 @@ unopValueKind(operand)
} }
void void
valueField(symbol, value) valueField(symbolTableEntryType *symbol, valueType *value)
symbolTableEntryType *symbol;
valueType *value;
{ {
symbolInContextType *workingContext; symbolInContextType *workingContext;
symbolInContextType *getWorkingContext();
symbolTableEntryType *effectiveSymbol();
symbol = effectiveSymbol(symbol, &workingContext); symbol = effectiveSymbol(symbol, &workingContext);
expand(moreLabel("%s:", symbol->symbolName)); expand(moreLabel("%s:", symbol->symbolName));
if (workingContext->usage == DEAD_SYMBOL) if (workingContext->usage == DEAD_SYMBOL)
@ -811,16 +768,10 @@ valueField(symbol, value)
} }
void void
valueLabel(symbol, value) valueLabel(symbolTableEntryType *symbol, valueType *value)
symbolTableEntryType *symbol;
valueType *value;
{ {
symbolInContextType *workingContext; symbolInContextType *workingContext;
symbolTableEntryType *generateLocalLabel();
symbolInContextType *getBaseContext();
symbolTableEntryType *effectiveSymbol();
symbol = effectiveSymbol(symbol, &workingContext); symbol = effectiveSymbol(symbol, &workingContext);
expand(moreLabel("%s:", symbol->symbolName)); expand(moreLabel("%s:", symbol->symbolName));
if (workingContext->usage == DEAD_SYMBOL) if (workingContext->usage == DEAD_SYMBOL)
@ -860,17 +811,10 @@ valueLabel(symbol, value)
*/ */
void void
createFixup(expression, location, kindOfFixup, codeMode, whichFixup) createFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup, codeBufferKindType codeMode, int whichFixup)
expressionType *expression;
addressType location;
fixupKindType kindOfFixup;
codeBufferKindType codeMode;
int whichFixup;
{ {
fixupListType *newFixup; fixupListType *newFixup;
expressionType *generateFixupExpression();
if (debug || emitPrint) if (debug || emitPrint)
printCreateFixup(expression, location, kindOfFixup); printCreateFixup(expression, location, kindOfFixup);
newFixup = typeAlloc(fixupListType); newFixup = typeAlloc(fixupListType);
@ -898,11 +842,8 @@ createFixup(expression, location, kindOfFixup, codeMode, whichFixup)
} }
void void
finishUp() finishUp(void)
{ {
void performFixups();
void performStartAddressFixup();
if (listingOn) if (listingOn)
terminateListingFiles(); terminateListingFiles();
performFixups(fixupList); performFixups(fixupList);
@ -932,7 +873,7 @@ isReferenceToRemember(reference)
} }
*/ */
void void
noteAnonymousReference() noteAnonymousReference(void)
{ {
expressionReferenceListType *newReference; expressionReferenceListType *newReference;
@ -954,11 +895,7 @@ noteAnonymousReference()
} }
void void
noteReference(expression, kindOfFixup, location, codeMode) noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode)
expressionType *expression;
fixupKindType kindOfFixup;
addressType location;
codeBufferKindType codeMode;
{ {
expressionReferenceListType *newReference; expressionReferenceListType *newReference;
@ -1006,10 +943,8 @@ noteReference(expression, kindOfFixup, location, codeMode)
} }
void void
performFixups(fixups) performFixups(fixupListType *fixups)
fixupListType *fixups;
{ {
valueType *evaluateExpression();
valueType *valueToPoke; valueType *valueToPoke;
performingFixups = TRUE; performingFixups = TRUE;
@ -1069,12 +1004,10 @@ performFixups(fixups)
} }
void void
performStartAddressFixup() performStartAddressFixup(void)
{ {
expressionType *startAddressExpression; expressionType *startAddressExpression;
expressionType *generateFixupExpression();
startAddressExpression = (expressionType *)startAddress; startAddressExpression = (expressionType *)startAddress;
startAddress = evaluateExpression(startAddressExpression,NO_FIXUP_OK); startAddress = evaluateExpression(startAddressExpression,NO_FIXUP_OK);
if (startAddress->kindOfValue == UNDEFINED_VALUE && if (startAddress->kindOfValue == UNDEFINED_VALUE &&
@ -1091,9 +1024,7 @@ performStartAddressFixup()
} }
void void
putFixupsHere(kindOfFixupsToPut, whichFixup) putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup)
fixupKindType kindOfFixupsToPut;
int whichFixup;
{ {
int location; int location;
@ -1184,8 +1115,7 @@ putReferencesHere(kindOfReferencesToPut, whichReference)
*/ */
void void
addNewLocalVariable(symbol) addNewLocalVariable(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
identifierListType *newLocalVariable; identifierListType *newLocalVariable;
@ -1196,17 +1126,13 @@ addNewLocalVariable(symbol)
} }
symbolTableEntryType * symbolTableEntryType *
effectiveSymbol(symbol, assignmentTargetContext) effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext)
symbolTableEntryType *symbol;
symbolInContextType **assignmentTargetContext;
{ {
symbolInContextType *context; symbolInContextType *context;
operandType *operand; operandType *operand;
expressionType *expression; expressionType *expression;
environmentType *saveEnvironment; environmentType *saveEnvironment;
symbolInContextType *getWorkingContext();
context = getWorkingContext(symbol); context = getWorkingContext(symbol);
saveEnvironment = currentEnvironment; saveEnvironment = currentEnvironment;
while (context != NULL && context->usage == ARGUMENT_SYMBOL && while (context != NULL && context->usage == ARGUMENT_SYMBOL &&
@ -1233,18 +1159,13 @@ effectiveSymbol(symbol, assignmentTargetContext)
} }
symbolTableEntryType * symbolTableEntryType *
generateLocalLabel(symbol) generateLocalLabel(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
stringType *localLabelString();
symbolTableEntryType *lookupOrEnterSymbol();
return(lookupOrEnterSymbol(localLabelString(symbol), LABEL_SYMBOL)); return(lookupOrEnterSymbol(localLabelString(symbol), LABEL_SYMBOL));
} }
symbolInContextType * symbolInContextType *
getBaseContext(identifier) getBaseContext(symbolTableEntryType *identifier)
symbolTableEntryType *identifier;
{ {
symbolInContextType *result; symbolInContextType *result;
@ -1256,8 +1177,7 @@ getBaseContext(identifier)
} }
symbolInContextType * symbolInContextType *
getWorkingContext(identifier) getWorkingContext(symbolTableEntryType *identifier)
symbolTableEntryType *identifier;
{ {
symbolInContextType *result; symbolInContextType *result;
@ -1271,14 +1191,11 @@ getWorkingContext(identifier)
} }
stringType * stringType *
localLabelString(symbol) localLabelString(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
#define TEMP_SYMBOL_SIZE_LIMIT 200 #define TEMP_SYMBOL_SIZE_LIMIT 200
char nameUnderConstruction[TEMP_SYMBOL_SIZE_LIMIT]; char nameUnderConstruction[TEMP_SYMBOL_SIZE_LIMIT];
stringType *saveString();
sprintf(nameUnderConstruction, "_%d_", localLabelTagValue(symbol)); sprintf(nameUnderConstruction, "_%d_", localLabelTagValue(symbol));
strncat(nameUnderConstruction, &(symbName(symbol)[1]), strncat(nameUnderConstruction, &(symbName(symbol)[1]),
TEMP_SYMBOL_SIZE_LIMIT); TEMP_SYMBOL_SIZE_LIMIT);
@ -1286,14 +1203,10 @@ localLabelString(symbol)
} }
int int
localLabelTagValue(symbol) localLabelTagValue(symbolTableEntryType *symbol)
symbolTableEntryType *symbol;
{ {
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
void addNewLocalVariable();
context = getWorkingContext(symbol); context = getWorkingContext(symbol);
if (context == NULL) if (context == NULL)
botch("local label doesn't have symbol context\n"); botch("local label doesn't have symbol context\n");
@ -1308,12 +1221,9 @@ localLabelTagValue(symbol)
} }
void void
addBreak(kind, data) addBreak(codeBreakKindType kind, int data)
codeBreakKindType kind;
int data;
{ {
codeBreakType *newBreak; codeBreakType *newBreak;
codeBreakType *buildCodeBreak();
newBreak = buildCodeBreak(kind, currentLocationCounter.value, data); newBreak = buildCodeBreak(kind, currentLocationCounter.value, data);
if (codeBreakList == NULL) { if (codeBreakList == NULL) {
@ -1325,12 +1235,8 @@ addBreak(kind, data)
} }
void void
reserveAbsolute(startAddress, blockSize) reserveAbsolute(addressType startAddress, int blockSize)
addressType startAddress;
int blockSize;
{ {
reservationListType *buildReservation();
if (reservationList != NULL && reservationList->startAddress + if (reservationList != NULL && reservationList->startAddress +
reservationList->blockSize == startAddress) reservationList->blockSize == startAddress)
reservationList->blockSize += blockSize; reservationList->blockSize += blockSize;
@ -1340,8 +1246,7 @@ reserveAbsolute(startAddress, blockSize)
} }
bool bool
listableStatement(kind) listableStatement(statementKindType kind)
statementKindType kind;
{ {
return( kind == ALIGN_STATEMENT || kind == BLOCK_STATEMENT || return( kind == ALIGN_STATEMENT || kind == BLOCK_STATEMENT ||
kind == BYTE_STATEMENT || kind == CONSTRAIN_STATEMENT || kind == BYTE_STATEMENT || kind == CONSTRAIN_STATEMENT ||

66
semanticMisc.h Normal file
View File

@ -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

View File

@ -1,17 +1,17 @@
.SUFFIXES: .o .c .h .run .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\ instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o\
write.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\ 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 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: .c.o:
cc $(CFLAGS) -c -g $*.c cc $(CFLAGS) -c $*.c
.c.run: .c.run:
cc $(CFLAGS) -o $* $*.c cc $(CFLAGS) -o $* $*.c
@ -19,30 +19,6 @@ CFLAGS=-m32 # slinky is not 64 bit clean
slinky: $(OBJECTS) slinky: $(OBJECTS)
cc $(CFLAGS) -g -o 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 builtins.o: builtins.c slinkyGlobals.h slinkyTypes.h slinkyExpressions.h
debugPrint.o: debugPrint.c slinkyGlobals.h slinkyTypes.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 write.o: write.c slinkyGlobals.h slinkyTypes.h
cleanup: clean:
/bin/rm -f *.o slinky /bin/rm -f *.o slinky
love: love:

View File

@ -30,14 +30,17 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "slinkyExpressions.h" #include "slinkyExpressions.h"
#include <strings.h> #include "builtins.h"
#include "errorStuff.h"
#include "expr.h"
#include "link.h"
#include "relocate.h"
#include <string.h>
#define getSymbol() ((symbolType *)getNumber()) #define getSymbol() ((symbolType *)getNumber())
void void
tooFewArgs(argCount, name) tooFewArgs(int argCount, stringType *name)
int argCount;
stringType *name;
{ {
error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, name); error(TOO_FEW_ARGUMENTS_TO_BIF_ERROR, name);
while (argCount-- > 0) while (argCount-- > 0)
@ -45,9 +48,7 @@ tooFewArgs(argCount, name)
} }
void void
tooManyArgs(argCount, name) tooManyArgs(int argCount, stringType *name)
int argCount;
stringType *name;
{ {
error(TOO_MANY_ARGUMENTS_TO_BIF_ERROR, name); error(TOO_MANY_ARGUMENTS_TO_BIF_ERROR, name);
while (argCount-- > 0) while (argCount-- > 0)
@ -84,8 +85,7 @@ static char atasciiTable[] = { /* 0xFFs will become 0x00s on output */
/* Convert a string to ATASCII */ /* Convert a string to ATASCII */
stringType * stringType *
atasciiBIF(argCount) atasciiBIF(int argCount)
int argCount;
{ {
stringType *string; stringType *string;
stringType *newString; stringType *newString;
@ -108,8 +108,7 @@ atasciiBIF(argCount)
/* Convert a string to ATASCII while setting high-order color bits */ /* Convert a string to ATASCII while setting high-order color bits */
stringType * stringType *
atasciiColorBIF(argCount) atasciiColorBIF(int argCount)
int argCount;
{ {
stringType *string; stringType *string;
stringType *newString; stringType *newString;
@ -144,8 +143,7 @@ atasciiColorBIF(argCount)
/* Check if an operand is absolute (as opposed to relocatable) */ /* Check if an operand is absolute (as opposed to relocatable) */
bool bool
isAbsoluteValueBIF(argCount) isAbsoluteValueBIF(int argCount)
int argCount;
{ {
if (argCount > 1) if (argCount > 1)
tooManyArgs(argCount, "isAbsoluteValue"); tooManyArgs(argCount, "isAbsoluteValue");
@ -154,8 +152,7 @@ isAbsoluteValueBIF(argCount)
/* Check if operand is a condition code */ /* Check if operand is a condition code */
bool bool
isConditionCodeBIF(argCount) isConditionCodeBIF(int argCount)
int argCount;
{ {
bool result; bool result;
@ -172,8 +169,7 @@ isConditionCodeBIF(argCount)
/* Check if a symbol is defined */ /* Check if a symbol is defined */
bool bool
isDefinedBIF(argCount) isDefinedBIF(int argCount)
int argCount;
{ {
symbolType *symbol; symbolType *symbol;
@ -194,8 +190,7 @@ isDefinedBIF(argCount)
/* Check if a symbol is externally visible */ /* Check if a symbol is externally visible */
bool bool
isExternalBIF(argCount) isExternalBIF(int argCount)
int argCount;
{ {
symbolType *symbol; symbolType *symbol;
@ -216,8 +211,7 @@ isExternalBIF(argCount)
/* Return the Nth character of a string (as an integer) */ /* Return the Nth character of a string (as an integer) */
int int
nthCharBIF(argCount) nthCharBIF(int argCount)
int argCount;
{ {
stringType *string; stringType *string;
int position; int position;
@ -240,8 +234,7 @@ nthCharBIF(argCount)
/* Pass stuff through to stdio's 'printf' function */ /* Pass stuff through to stdio's 'printf' function */
int int
printfBIF(argCount) printfBIF(int argCount)
int argCount;
{ {
stringType *formatString; stringType *formatString;
int argument[20]; int argument[20];
@ -269,8 +262,7 @@ printfBIF(argCount)
/* Concatenate two strings */ /* Concatenate two strings */
stringType * stringType *
strcatBIF(argCount) strcatBIF(int argCount)
int argCount;
{ {
stringType *string1; stringType *string1;
stringType *string2; stringType *string2;
@ -294,8 +286,7 @@ strcatBIF(argCount)
/* Compare two strings */ /* Compare two strings */
int int
strcmpBIF(argCount) strcmpBIF(int argCount)
int argCount;
{ {
stringType *string1; stringType *string1;
stringType *string2; stringType *string2;
@ -314,9 +305,7 @@ strcmpBIF(argCount)
/* Compare two strings in a case-independent fashion */ /* Compare two strings in a case-independent fashion */
int int
strcmplcBIF(argCount) strcmplcBIF(int argCount)
int argCount;
{ {
stringType *string1; stringType *string1;
stringType *string2; stringType *string2;
@ -335,8 +324,7 @@ strcmplcBIF(argCount)
/* Return the length of a string */ /* Return the length of a string */
int int
strlenBIF(argCount) strlenBIF(int argCount)
int argCount;
{ {
if (argCount < 1) if (argCount < 1)
return(0); return(0);
@ -349,8 +337,7 @@ strlenBIF(argCount)
/* Return a substring of a string */ /* Return a substring of a string */
char * char *
substrBIF(argCount) substrBIF(int argCount)
int argCount;
{ {
stringType *string; stringType *string;
int start; int start;
@ -404,12 +391,10 @@ substrBIF(argCount)
/* Turn a string into a symbol and return its value */ /* Turn a string into a symbol and return its value */
addressType addressType
symbolLookupBIF(argCount) symbolLookupBIF(int argCount)
int argCount;
{ {
symbolType *symbol; symbolType *symbol;
stringType *symbolName; stringType *symbolName;
symbolType *lookupGlobalSymbol();
if (argCount < 1) { if (argCount < 1) {
tooFewArgs(argCount, "symbolLookup"); tooFewArgs(argCount, "symbolLookup");
@ -429,8 +414,7 @@ symbolLookupBIF(argCount)
/* Turn a symbol into a string */ /* Turn a symbol into a string */
stringType * stringType *
symbolNameBIF(argCount) symbolNameBIF(int argCount)
int argCount;
{ {
symbolType *symbol; symbolType *symbol;

24
slinky/builtins.h Normal file
View File

@ -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

View File

@ -31,7 +31,7 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "debugPrint.h"
static char *modeStrings[2] = { static char *modeStrings[2] = {
"abs", "abs",
@ -64,18 +64,14 @@ static char *symbolStrings[6] = {
}; };
void void
printCode(startAddress, endAddress, mode) printCode(int startAddress, int endAddress, int mode)
int startAddress;
int endAddress;
int mode;
{ {
printf(" Code: 0x%04x:0x%04x %s\n", startAddress, endAddress, printf(" Code: 0x%04x:0x%04x %s\n", startAddress, endAddress,
modeStrings[mode]); modeStrings[mode]);
} }
void void
printReference(reference) printReference(expressionReferenceType *reference)
expressionReferenceType *reference;
{ {
printf(" Ref : 0x%04x (%s %s %s %s) expression #%d\n", reference-> printf(" Ref : 0x%04x (%s %s %s %s) expression #%d\n", reference->
referenceAddress, modeStrings[reference->referenceMode], referenceAddress, modeStrings[reference->referenceMode],
@ -85,8 +81,7 @@ printReference(reference)
} }
void void
printReferenceFixup(reference) printReferenceFixup(expressionReferenceType *reference)
expressionReferenceType *reference;
{ {
printf(" Ref : 0x%04x (%s %s %s %s) expression=0x%x\n", printf(" Ref : 0x%04x (%s %s %s %s) expression=0x%x\n",
reference->referenceAddress, modeStrings[reference-> reference->referenceAddress, modeStrings[reference->
@ -97,9 +92,7 @@ printReferenceFixup(reference)
} }
void void
printSymbol(symbolTag, symbol) printSymbol(int symbolTag, symbolType *symbol)
int symbolTag;
symbolType *symbol;
{ {
printf(" Symb: %3d %s 0x%04x \"%s\"\n", symbolTag, symbolStrings[ printf(" Symb: %3d %s 0x%04x \"%s\"\n", symbolTag, symbolStrings[
symbol->symbolClass], symbol->symbolValue, symbol->symbolClass], symbol->symbolValue,
@ -107,15 +100,14 @@ printSymbol(symbolTag, symbol)
} }
void void
printLoadMapSymbol(symbol) printLoadMapSymbol(symbolType *symbol)
symbolType *symbol;
{ {
fprintf(mapFileOutput, "%-20s 0x%04x %s ", symbol->symbolName, fprintf(mapFileOutput, "%-20s 0x%04x %s ", symbol->symbolName,
symbol->symbolValue, symbolStrings[symbol->symbolClass]); symbol->symbolValue, symbolStrings[symbol->symbolClass]);
} }
void void
printGlobalSymbols() printGlobalSymbols(void)
{ {
int symbolCount; int symbolCount;
@ -128,9 +120,7 @@ printGlobalSymbols()
} }
void void
printExpression(expression, length) printExpression(expressionPCType expression, int length)
expressionPCType expression;
int length;
{ {
int line; int line;
int i; int i;

14
slinky/debugPrint.h Normal file
View File

@ -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

View File

@ -29,16 +29,12 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "errorStuff.h"
void #include <stdarg.h>
error(theError, arg1, arg2, arg3, arg4, arg5, arg6)
errorType theError; static void
anyOldThing *arg1; verror(errorType theError, va_list ap)
anyOldThing *arg2;
anyOldThing *arg3;
anyOldThing *arg4;
anyOldThing *arg5;
anyOldThing *arg6;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'errorType'. */ enumerated type 'errorType'. */
@ -79,8 +75,16 @@ error(theError, arg1, arg2, arg3, arg4, arg5, arg6)
}; };
printf("\"%s\": ", currentFileName); printf("\"%s\": ", currentFileName);
printf(errorMessageStrings[(int)theError], arg1, arg2, arg3, arg4, vprintf(errorMessageStrings[(int)theError], ap);
arg5, arg6);
printf("\n"); printf("\n");
errorFlag = TRUE; errorFlag = TRUE;
} }
void
error(errorType theError, ...)
{
va_list ap;
va_start(ap, theError);
verror(theError, ap);
va_end(ap);
}

8
slinky/errorStuff.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef ERROR_STUFF_H_
#define ERROR_STUFF_H_
#include "slinkyTypes.h"
void error(errorType theError, ...);
#endif

View File

@ -30,6 +30,9 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "slinkyExpressions.h" #include "slinkyExpressions.h"
#include "expr.h"
#include "errorStuff.h"
#include "initialize.h"
#include "y.tab.h" #include "y.tab.h"
#define overSymbol() (pc+=sizeof(symbolType *)) #define overSymbol() (pc+=sizeof(symbolType *))
@ -41,17 +44,11 @@
#define nextByte(byt) (byt = *pc++) #define nextByte(byt) (byt = *pc++)
#define intOp(byt) (byt+256) #define intOp(byt) (byt+256)
addressType evaluateExpression();
void skipArray();
void skipClause();
void skipString();
void skipExpression();
static bool hitFreturn = FALSE; static bool hitFreturn = FALSE;
static addressType functionResult; static addressType functionResult;
int int
getNumber() getNumber(void)
{ {
register int result; register int result;
register int i; register int i;
@ -64,7 +61,7 @@ getNumber()
} }
addressType addressType
evaluateArray() evaluateArray(void)
{ {
error(ARRAY_TERM_IN_OBJECT_ERROR); error(ARRAY_TERM_IN_OBJECT_ERROR);
skipArray(); skipArray();
@ -72,7 +69,7 @@ evaluateArray()
} }
addressType addressType
evaluateAssert() evaluateAssert(void)
{ {
if (!evaluateExpression()) if (!evaluateExpression())
error(ASSERT_FAILED_ERROR, pc); error(ASSERT_FAILED_ERROR, pc);
@ -80,7 +77,7 @@ evaluateAssert()
} }
addressType addressType
evaluateBinop() evaluateBinop(void)
{ {
int op; int op;
symbolType *leftSymbol; symbolType *leftSymbol;
@ -159,7 +156,7 @@ evaluateBinop()
} }
addressType addressType
evaluateBlock() evaluateBlock(void)
{ {
while (*pc != END_TAG) { while (*pc != END_TAG) {
evaluateExpression(); evaluateExpression();
@ -172,7 +169,7 @@ evaluateBlock()
} }
addressType addressType
evaluateConditionCode() evaluateConditionCode(void)
{ {
overByte(); overByte();
error(CONDITION_CODE_EXPRESSION_ENCOUNTERED_ERROR); error(CONDITION_CODE_EXPRESSION_ENCOUNTERED_ERROR);
@ -180,9 +177,7 @@ evaluateConditionCode()
} }
void void
pushSymbol(symbol, value) pushSymbol(symbolType *symbol, addressType value)
symbolType *symbol;
addressType value;
{ {
bindingListType *newBinding; bindingListType *newBinding;
@ -197,9 +192,7 @@ pushSymbol(symbol, value)
} }
void void
bindFunctionArguments(theFunction, argCount) bindFunctionArguments(functionType *theFunction, int argCount)
functionType *theFunction;
int argCount;
{ {
argumentListType *argList; argumentListType *argList;
@ -223,7 +216,7 @@ bindFunctionArguments(theFunction, argCount)
} }
void void
undoBindings() undoBindings(void)
{ {
bindingListType *deadBinding; bindingListType *deadBinding;
@ -239,7 +232,7 @@ undoBindings()
} }
addressType addressType
evaluateFreturn() evaluateFreturn(void)
{ {
hitFreturn = TRUE; hitFreturn = TRUE;
functionResult = evaluateExpression(); functionResult = evaluateExpression();
@ -247,7 +240,7 @@ evaluateFreturn()
} }
addressType addressType
evaluateBuiltinFunctionCall() evaluateBuiltinFunctionCall(void)
{ {
int theFunction; int theFunction;
int argCount; int argCount;
@ -262,7 +255,7 @@ evaluateBuiltinFunctionCall()
} }
addressType addressType
evaluateFunctionCall() evaluateFunctionCall(void)
{ {
expressionPCType savePoint; expressionPCType savePoint;
functionType *theFunction; functionType *theFunction;
@ -288,13 +281,13 @@ evaluateFunctionCall()
} }
addressType addressType
evaluateHere() evaluateHere(void)
{ {
return(here); return(here);
} }
addressType addressType
evaluateMdefine() evaluateMdefine(void)
{ {
symbolType *symbol; symbolType *symbol;
@ -303,7 +296,7 @@ evaluateMdefine()
} }
addressType addressType
evaluateMdoUntil() evaluateMdoUntil(void)
{ {
expressionPCType testPoint; expressionPCType testPoint;
expressionPCType endPoint; expressionPCType endPoint;
@ -320,7 +313,7 @@ evaluateMdoUntil()
} }
addressType addressType
evaluateMdoWhile() evaluateMdoWhile(void)
{ {
expressionPCType testPoint; expressionPCType testPoint;
expressionPCType endPoint; expressionPCType endPoint;
@ -337,7 +330,7 @@ evaluateMdoWhile()
} }
addressType addressType
evaluateMfor() evaluateMfor(void)
{ {
expressionPCType testPoint; expressionPCType testPoint;
expressionPCType incrPoint; expressionPCType incrPoint;
@ -367,7 +360,7 @@ evaluateMfor()
} }
addressType addressType
evaluateMif() evaluateMif(void)
{ {
if (evaluateExpression()) { if (evaluateExpression()) {
evaluateExpression(); evaluateExpression();
@ -380,8 +373,7 @@ evaluateMif()
} }
bool bool
evaluateClause(pattern) evaluateClause(addressType pattern)
addressType pattern;
{ {
bool match; bool match;
@ -399,7 +391,7 @@ evaluateClause(pattern)
} }
addressType addressType
evaluateMswitch() evaluateMswitch(void)
{ {
addressType pattern; addressType pattern;
@ -414,7 +406,7 @@ evaluateMswitch()
} }
addressType addressType
evaluateMwhile() evaluateMwhile(void)
{ {
expressionPCType testPoint; expressionPCType testPoint;
expressionPCType endPoint; expressionPCType endPoint;
@ -433,7 +425,7 @@ evaluateMwhile()
} }
addressType addressType
evaluateMvariable() evaluateMvariable(void)
{ {
symbolType *symbol; symbolType *symbol;
@ -442,7 +434,7 @@ evaluateMvariable()
} }
addressType addressType
evaluateNumber() evaluateNumber(void)
{ {
addressType result; addressType result;
int i; int i;
@ -455,20 +447,20 @@ evaluateNumber()
} }
addressType addressType
evaluateRelocatableNumber() evaluateRelocatableNumber(void)
{ {
return(evaluateNumber() + relocationOffset); return(evaluateNumber() + relocationOffset);
} }
addressType addressType
evaluatePerform() evaluatePerform(void)
{ {
evaluateExpression(); evaluateExpression();
return(0); return(0);
} }
addressType addressType
evaluatePostop() evaluatePostop(void)
{ {
int op; int op;
symbolType *target; symbolType *target;
@ -485,7 +477,7 @@ evaluatePostop()
} }
addressType addressType
evaluatePreop() evaluatePreop(void)
{ {
int op; int op;
symbolType *target; symbolType *target;
@ -502,7 +494,7 @@ evaluatePreop()
} }
addressType addressType
evaluateString() evaluateString(void)
{ {
addressType result; addressType result;
@ -513,7 +505,7 @@ evaluateString()
} }
addressType addressType
evaluateSymbol() evaluateSymbol(void)
{ {
symbolType *target; symbolType *target;
@ -522,7 +514,7 @@ evaluateSymbol()
} }
addressType addressType
evaluateUnop() evaluateUnop(void)
{ {
int op; int op;
addressType arg; addressType arg;
@ -548,7 +540,7 @@ evaluateUnop()
} }
addressType addressType
evaluateExpression() evaluateExpression(void)
{ {
if (pc == NULL) if (pc == NULL)
return(0); return(0);
@ -650,21 +642,21 @@ evaluateExpression()
} }
void void
skipArray() skipArray(void)
{ {
overSymbol(); overSymbol();
skipExpression(); skipExpression();
} }
void void
skipAssert() skipAssert(void)
{ {
skipExpression(); skipExpression();
skipString(); skipString();
} }
void void
skipBinop() skipBinop(void)
{ {
overByte(); overByte();
skipExpression(); skipExpression();
@ -672,7 +664,7 @@ skipBinop()
} }
void void
skipBlock() skipBlock(void)
{ {
while (*pc != END_TAG) while (*pc != END_TAG)
skipExpression(); skipExpression();
@ -680,7 +672,7 @@ skipBlock()
} }
void void
skipFunctionCall() skipFunctionCall(void)
{ {
int argCount; int argCount;
@ -691,28 +683,28 @@ skipFunctionCall()
} }
void void
skipMdefine() skipMdefine(void)
{ {
overSymbol(); overSymbol();
skipExpression(); skipExpression();
} }
void void
skipMdoUntil() skipMdoUntil(void)
{ {
skipExpression(); skipExpression();
skipExpression(); skipExpression();
} }
void void
skipMdoWhile() skipMdoWhile(void)
{ {
skipExpression(); skipExpression();
skipExpression(); skipExpression();
} }
void void
skipMfor() skipMfor(void)
{ {
skipExpression(); skipExpression();
skipExpression(); skipExpression();
@ -721,7 +713,7 @@ skipMfor()
} }
void void
skipMif() skipMif(void)
{ {
skipExpression(); skipExpression();
skipExpression(); skipExpression();
@ -729,7 +721,7 @@ skipMif()
} }
void void
skipClause() skipClause(void)
{ {
while (*pc != BLOCK_TAG) while (*pc != BLOCK_TAG)
skipExpression; skipExpression;
@ -737,7 +729,7 @@ skipClause()
} }
void void
skipMswitch() skipMswitch(void)
{ {
skipExpression(); skipExpression();
while (*pc != END_TAG) while (*pc != END_TAG)
@ -746,49 +738,49 @@ skipMswitch()
} }
void void
skipMvariable() skipMvariable(void)
{ {
overSymbol(); overSymbol();
skipExpression(); skipExpression();
} }
void void
skipMwhile() skipMwhile(void)
{ {
skipExpression(); skipExpression();
skipExpression(); skipExpression();
} }
void void
skipPostop() skipPostop(void)
{ {
overByte(); overByte();
skipExpression(); skipExpression();
} }
void void
skipPreop() skipPreop(void)
{ {
overByte(); overByte();
skipExpression(); skipExpression();
} }
void void
skipString() skipString(void)
{ {
while (*pc++ != '\0') while (*pc++ != '\0')
; ;
} }
void void
skipUnop() skipUnop(void)
{ {
overByte(); overByte();
skipExpression(); skipExpression();
} }
void void
skipExpression() skipExpression(void)
{ {
if (pc == NULL) if (pc == NULL)
return; return;

57
slinky/expr.h Normal file
View File

@ -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

63
slinky/globals.c Normal file
View File

@ -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];

View File

@ -29,20 +29,24 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "initialize.h"
#include "errorStuff.h"
#include "main.h"
#include <string.h>
#include <unistd.h>
static char *outputFileName; static char *outputFileName;
void void
chokePukeAndDie() chokePukeAndDie(void)
{ {
unlink(outputFileName); unlink(outputFileName);
exit(1); exit(1);
} }
void void
initializeStuff(argc, argv) initializeStuff(int argc, char **argv)
int argc;
char *argv[];
{ {
int i; int i;
int j; int j;
@ -52,9 +56,6 @@ initializeStuff(argc, argv)
int mapFilesFound; int mapFilesFound;
char *mapFileName; char *mapFileName;
void queueInputFile();
void queueLoadAddress();
currentFileName = "<command line>"; currentFileName = "<command line>";
errorFlag = FALSE; errorFlag = FALSE;
packFlag = FALSE; packFlag = FALSE;
@ -174,8 +175,7 @@ initializeStuff(argc, argv)
void void
queueInputFile(name) queueInputFile(char *name)
char *name;
{ {
objectFileListType *newObjectFile; objectFileListType *newObjectFile;
@ -194,8 +194,7 @@ queueInputFile(name)
} }
void void
queueLoadAddress(addressString) queueLoadAddress(char *addressString)
char *addressString;
{ {
int loadAddress; int loadAddress;
objectFileListType *newObjectFile; objectFileListType *newObjectFile;

11
slinky/initialize.h Normal file
View File

@ -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

View File

@ -31,6 +31,9 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "slinkyExpressions.h" #include "slinkyExpressions.h"
#include "errorStuff.h"
#include "expr.h"
#include "instantiate.h"
#include "y.tab.h" #include "y.tab.h"
#define overFunction() (pc+=sizeof(functionType *)) #define overFunction() (pc+=sizeof(functionType *))
@ -38,13 +41,8 @@
#define overByte() pc++ #define overByte() pc++
#define nextByte(byt) (byt = *pc++) #define nextByte(byt) (byt = *pc++)
void putSymbolPointersIntoArray();
void putSymbolPointersIntoClause();
void putSymbolPointersIntoExpression();
void void
putNumber(number) putNumber(int number)
int number;
{ {
int i; int i;
for (i=0; i<sizeof(int); ++i) { for (i=0; i<sizeof(int); ++i) {
@ -54,7 +52,7 @@ putNumber(number)
} }
void void
instantiateSymbol() instantiateSymbol(void)
{ {
int index; int index;
@ -64,7 +62,7 @@ instantiateSymbol()
} }
void void
instantiateFunction() instantiateFunction(void)
{ {
int index; int index;
@ -74,21 +72,21 @@ instantiateFunction()
} }
void void
putSymbolPointersIntoArray() putSymbolPointersIntoArray(void)
{ {
instantiateSymbol(); instantiateSymbol();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoAssert() putSymbolPointersIntoAssert(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
skipString(); skipString();
} }
void void
putSymbolPointersIntoBinop() putSymbolPointersIntoBinop(void)
{ {
overByte(); overByte();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
@ -96,7 +94,7 @@ putSymbolPointersIntoBinop()
} }
void void
putSymbolPointersIntoBlock() putSymbolPointersIntoBlock(void)
{ {
while (*pc != END_TAG) while (*pc != END_TAG)
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
@ -104,7 +102,7 @@ putSymbolPointersIntoBlock()
} }
void void
putSymbolPointersIntoBuiltinFunctionCall() putSymbolPointersIntoBuiltinFunctionCall(void)
{ {
int argCount; int argCount;
@ -115,7 +113,7 @@ putSymbolPointersIntoBuiltinFunctionCall()
} }
void void
putSymbolPointersIntoFunctionCall() putSymbolPointersIntoFunctionCall(void)
{ {
int argCount; int argCount;
@ -126,28 +124,28 @@ putSymbolPointersIntoFunctionCall()
} }
void void
putSymbolPointersIntoMdefine() putSymbolPointersIntoMdefine(void)
{ {
instantiateSymbol(); instantiateSymbol();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoMdoUntil() putSymbolPointersIntoMdoUntil(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoMdoWhile() putSymbolPointersIntoMdoWhile(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoMfor() putSymbolPointersIntoMfor(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
@ -156,7 +154,7 @@ putSymbolPointersIntoMfor()
} }
void void
putSymbolPointersIntoMif() putSymbolPointersIntoMif(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
@ -164,7 +162,7 @@ putSymbolPointersIntoMif()
} }
void void
putSymbolPointersIntoClause() putSymbolPointersIntoClause(void)
{ {
while (*pc != BLOCK_TAG) while (*pc != BLOCK_TAG)
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
@ -172,7 +170,7 @@ putSymbolPointersIntoClause()
} }
void void
putSymbolPointersIntoMswitch() putSymbolPointersIntoMswitch(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
while (*pc != END_TAG) while (*pc != END_TAG)
@ -181,42 +179,42 @@ putSymbolPointersIntoMswitch()
} }
void void
putSymbolPointersIntoMvariable() putSymbolPointersIntoMvariable(void)
{ {
instantiateSymbol(); instantiateSymbol();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoMwhile() putSymbolPointersIntoMwhile(void)
{ {
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoPostop() putSymbolPointersIntoPostop(void)
{ {
overByte(); overByte();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoPreop() putSymbolPointersIntoPreop(void)
{ {
overByte(); overByte();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoUnop() putSymbolPointersIntoUnop(void)
{ {
overByte(); overByte();
putSymbolPointersIntoExpression(); putSymbolPointersIntoExpression();
} }
void void
putSymbolPointersIntoExpression() putSymbolPointersIntoExpression(void)
{ {
if (pc == NULL) if (pc == NULL)
return; return;

29
slinky/instantiate.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef INSTANTIATE_H_
#define INSTANTIATE_H_
#include "slinkyTypes.h"
void putNumber(int number);
void instantiateSymbol(void);
void instantiateFunction(void);
void putSymbolPointersIntoArray(void);
void putSymbolPointersIntoAssert(void);
void putSymbolPointersIntoBinop(void);
void putSymbolPointersIntoBlock(void);
void putSymbolPointersIntoBuiltinFunctionCall(void);
void putSymbolPointersIntoFunctionCall(void);
void putSymbolPointersIntoMdefine(void);
void putSymbolPointersIntoMdoUntil(void);
void putSymbolPointersIntoMdoWhile(void);
void putSymbolPointersIntoMfor(void);
void putSymbolPointersIntoMif(void);
void putSymbolPointersIntoClause(void);
void putSymbolPointersIntoMswitch(void);
void putSymbolPointersIntoMvariable(void);
void putSymbolPointersIntoMwhile(void);
void putSymbolPointersIntoPostop(void);
void putSymbolPointersIntoPreop(void);
void putSymbolPointersIntoUnop(void);
void putSymbolPointersIntoExpression(void);
#endif

View File

@ -29,6 +29,15 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "link.h"
#include "debugPrint.h"
#include "errorStuff.h"
#include "instantiate.h"
#include "poke.h"
#include "read.h"
#include "relocate.h"
#include "write.h"
/*#define readWord(f,fn) ((getc(f) & 0xFF) | ((getc(f) & 0xFF)<<8))*/ /*#define readWord(f,fn) ((getc(f) & 0xFF) | ((getc(f) & 0xFF)<<8))*/
/* /*
@ -94,15 +103,13 @@
*/ */
bool bool
internalizeOneObjectFile(objectFile) internalizeOneObjectFile(objectFileListType *objectFile)
objectFileListType *objectFile;
{ {
FILE *objectFildes; FILE *objectFildes;
int magic; int magic;
int mode; int mode;
addressType startAddress; addressType startAddress;
addressType endAddress; addressType endAddress;
bool compareSymbolValues();
currentFileName = objectFile->name; currentFileName = objectFile->name;
if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { if ((objectFildes = fopen(objectFile->name, "r")) == NULL) {
@ -152,9 +159,7 @@ internalizeOneObjectFile(objectFile)
#define toLowerCase(c) (('A'<=(c)&&(c)<='Z')?((c)-'A'+'a'):(c)); #define toLowerCase(c) (('A'<=(c)&&(c)<='Z')?((c)-'A'+'a'):(c));
bool bool
strcmplc(s1, s2) strcmplc(char *s1, char *s2)
char *s1;
char *s2;
{ {
register char c1; register char c1;
register char c2; register char c2;
@ -176,9 +181,7 @@ strcmplc(s1, s2)
} }
bool bool
compareSymbols(symbol1, symbol2) compareSymbols(symbolType **symbol1, symbolType **symbol2)
symbolType **symbol1;
symbolType **symbol2;
{ {
bool result; bool result;
@ -193,8 +196,7 @@ compareSymbols(symbol1, symbol2)
} }
void void
buildGlobalSymbolTable(inputFileList) buildGlobalSymbolTable(objectFileListType *inputFileList)
objectFileListType *inputFileList;
{ {
int symbolCount; int symbolCount;
symbolType **symbol; symbolType **symbol;
@ -226,7 +228,7 @@ buildGlobalSymbolTable(inputFileList)
} }
bool bool
readem() readem(void)
{ {
objectFileListType *inputFileList; objectFileListType *inputFileList;
@ -246,8 +248,7 @@ readem()
} }
codeSegmentHeaderType * codeSegmentHeaderType *
locateConflictingSegment(codeSegment) locateConflictingSegment(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
segmentListType *segmentPtr; segmentListType *segmentPtr;
int segmentListOffset; int segmentListOffset;
@ -283,9 +284,7 @@ locateConflictingSegment(codeSegment)
} }
void void
reserveSegment(start, end) reserveSegment(addressType start, addressType end)
addressType start;
addressType end;
{ {
freeSegmentEntryType *freeSegmentPtr; freeSegmentEntryType *freeSegmentPtr;
freeSegmentEntryType *previousSegmentPtr; freeSegmentEntryType *previousSegmentPtr;
@ -338,8 +337,7 @@ reserveSegment(start, end)
} }
codeSegmentHeaderType * codeSegmentHeaderType *
allocateAbsolute(codeSegment) allocateAbsolute(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
freeSegmentEntryType *freeSegmentPtr; freeSegmentEntryType *freeSegmentPtr;
freeSegmentEntryType *previousSegmentPtr; freeSegmentEntryType *previousSegmentPtr;
@ -389,7 +387,7 @@ allocateAbsolute(codeSegment)
} }
void void
reserveReservations() reserveReservations(void)
{ {
while (reservationList != NULL) { while (reservationList != NULL) {
reserveSegment(reservationList->startAddress, reserveSegment(reservationList->startAddress,
@ -400,8 +398,7 @@ reserveReservations()
} }
void void
installSegment(codeSegment) installSegment(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
segmentListType *previousSegment; segmentListType *previousSegment;
segmentListType *installSegmentList; segmentListType *installSegmentList;
@ -436,8 +433,7 @@ installSegment(codeSegment)
} }
void void
installAbsoluteCodeSegment(codeSegment) installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
codeSegmentHeaderType *conflictingSegment; codeSegmentHeaderType *conflictingSegment;
@ -452,7 +448,7 @@ installAbsoluteCodeSegment(codeSegment)
} }
void void
linkem() linkem(void)
{ {
if (!readem()) if (!readem())
return; return;

19
slinky/link.h Normal file
View File

@ -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

View File

@ -29,21 +29,22 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "main.h"
#include "initialize.h"
#include "link.h"
main(argc, argv) int
int argc; main(int argc, char **argv)
char *argv[];
{ {
initializeStuff(argc, argv); initializeStuff(argc, argv);
linkem(); linkem();
if (errorFlag) if (errorFlag)
chokePukeAndDie(); chokePukeAndDie();
else return 0;
exit(0);
} }
void void
printVersion() printVersion(void)
{ {
printf("Slinky version 1.16.\n"); printf("Slinky version 1.16.\n");
} }

8
slinky/main.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef MAIN_H_
#define MAIN_H_
#include "slinkyTypes.h"
void printVersion(void);
#endif

View File

@ -30,16 +30,12 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "map.h"
typedef struct { #include "debugPrint.h"
symbolType *symbol; #include "link.h"
stringType *fileName;
} loadMapTableEntryType;
int int
compareLoadMapEntries(entry1, entry2) compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2)
loadMapTableEntryType *entry1;
loadMapTableEntryType *entry2;
{ {
int result; int result;
@ -55,7 +51,7 @@ compareLoadMapEntries(entry1, entry2)
} }
void void
outputLoadMap() outputLoadMap(void)
{ {
loadMapTableEntryType *loadMapTable; loadMapTableEntryType *loadMapTable;
loadMapTableEntryType *loadMapPtr; loadMapTableEntryType *loadMapPtr;

14
slinky/map.h Normal file
View File

@ -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

View File

@ -31,33 +31,31 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "poke.h"
#include "debugPrint.h"
#include "errorStuff.h"
#include "expr.h"
bool bool
isWordSized(value) isWordSized(int value)
int value;
{ {
return (-32768<=value && value<=65535); return (-32768<=value && value<=65535);
} }
bool bool
isByteSized(value) isByteSized(int value)
int value;
{ {
return (-128<=value && value<=255); return (-128<=value && value<=255);
} }
bool bool
isByteOffset(value) isByteOffset(int value)
int value;
{ {
return (-128<=value && value<=127); return (-128<=value && value<=127);
} }
int int
computeRelativeValue(valueToPoke, codeSegment, offset) computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset)
int valueToPoke;
codeSegmentHeaderType *codeSegment;
int offset;
{ {
int fromLocation; int fromLocation;
int result; int result;
@ -77,10 +75,7 @@ computeRelativeValue(valueToPoke, codeSegment, offset)
} }
int int
getBaseValue(codeBuffer, offset, referenceKind) getBaseValue(byte *codeBuffer, int offset, int referenceKind)
byte codeBuffer[];
int offset;
int referenceKind;
{ {
int result; int result;
@ -101,12 +96,7 @@ getBaseValue(codeBuffer, offset, referenceKind)
} }
void void
pokeValue(value, codeBuffer, offset, referenceKind, trueAddress) pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress)
int value;
byte codeBuffer[];
int offset;
int referenceKind;
int trueAddress;
{ {
switch (referenceKind) { switch (referenceKind) {
case REF_BYTE: case REF_BYTE:
@ -150,9 +140,7 @@ pokeValue(value, codeBuffer, offset, referenceKind, trueAddress)
} }
void void
fixupReference(reference, codeSegment) fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment)
expressionReferenceType *reference;
codeSegmentHeaderType *codeSegment;
{ {
int offset; int offset;
addressType baseValue; addressType baseValue;
@ -182,7 +170,7 @@ fixupReference(reference, codeSegment)
} }
void void
pokem() pokem(void)
{ {
objectFileListType *inputFileList; objectFileListType *inputFileList;
codeSegmentHeaderType *codeSegment; codeSegmentHeaderType *codeSegment;

15
slinky/poke.h Normal file
View File

@ -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

View File

@ -31,14 +31,18 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.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 isAbsolute(symbol) (((symbol)->symbolClass & SYMBOL_ABSOLUTE) != 0)
#define isRelocatable(symbol) (((symbol)->symbolClass &SYMBOL_RELOCATABLE)!=0) #define isRelocatable(symbol) (((symbol)->symbolClass &SYMBOL_RELOCATABLE)!=0)
void void
fileCheck(fildes, fileName) fileCheck(FILE *fildes, char *fileName)
FILE *fildes;
char *fileName;
{ {
if (feof(fildes)) { if (feof(fildes)) {
error(PREMATURE_EOF_ERROR, fileName); error(PREMATURE_EOF_ERROR, fileName);
@ -51,9 +55,7 @@ fileCheck(fildes, fileName)
} }
wordType wordType
readWord(file, fileName) readWord(FILE *file, char *fileName)
FILE *file;
char *fileName;
{ {
wordType result; wordType result;
register char loByte; register char loByte;
@ -67,9 +69,7 @@ readWord(file, fileName)
} }
byte byte
readByte(file, fileName) readByte(FILE *file, char *fileName)
FILE *file;
char *fileName;
{ {
int result; int result;
@ -80,9 +80,7 @@ readByte(file, fileName)
} }
bigWord bigWord
readBigword(file, fileName) readBigword(FILE *file, char *fileName)
FILE *file;
char *fileName;
{ {
register bigWord result; register bigWord result;
@ -95,9 +93,7 @@ readBigword(file, fileName)
} }
bigWord bigWord
read3ByteWord(file, fileName) read3ByteWord(FILE *file, char *fileName)
FILE *file;
char *fileName;
{ {
register bigWord result; register bigWord result;
@ -109,10 +105,7 @@ read3ByteWord(file, fileName)
} }
int int
readString(buffer, fildes, fileName) readString(char *buffer, FILE *fildes, char *fileName)
char *buffer;
FILE *fildes;
char *fileName;
{ {
register char c; register char c;
register char *scratchBuffer; register char *scratchBuffer;
@ -126,11 +119,7 @@ readString(buffer, fildes, fileName)
} }
void void
readChunk(buffer, numberOfBytes, fildes, fileName) readChunk(byte *buffer, int numberOfBytes, FILE *fildes, char *fileName)
byte *buffer;
int numberOfBytes;
FILE *fildes;
char *fileName;
{ {
do { do {
*buffer++ = getc(fildes); *buffer++ = getc(fildes);
@ -139,12 +128,7 @@ readChunk(buffer, numberOfBytes, fildes, fileName)
} }
void void
readCode(startAddress, endAddress, mode, objectFile, objectFildes) readCode(addressType startAddress, addressType endAddress, int mode, objectFileListType *objectFile, FILE *objectFildes)
addressType startAddress;
addressType endAddress;
int mode;
objectFileListType *objectFile;
FILE *objectFildes;
{ {
int size; int size;
byte *codeBuffer; byte *codeBuffer;
@ -193,9 +177,7 @@ readCode(startAddress, endAddress, mode, objectFile, objectFildes)
} }
bool bool
compareReferences(reference1, reference2) compareReferences(expressionReferenceType *reference1, expressionReferenceType *reference2)
expressionReferenceType *reference1;
expressionReferenceType *reference2;
{ {
if (reference1->referenceMode == MODE_ABSOLUTE && reference2-> if (reference1->referenceMode == MODE_ABSOLUTE && reference2->
referenceMode == MODE_RELOCATABLE) referenceMode == MODE_RELOCATABLE)
@ -212,19 +194,14 @@ compareReferences(reference1, reference2)
} }
void void
sortReferences(theReferences, numberOfReferences) sortReferences(expressionReferenceType *theReferences, int numberOfReferences)
expressionReferenceType *theReferences;
int numberOfReferences;
{ {
qsort(theReferences, numberOfReferences, qsort(theReferences, numberOfReferences,
sizeof(expressionReferenceType), compareReferences); sizeof(expressionReferenceType), compareReferences);
} }
void void
readReference(reference, fildes, fileName) readReference(expressionReferenceType *reference, FILE *fildes, char *fileName)
expressionReferenceType *reference;
FILE *fildes;
char *fileName;
{ {
register byte funnyByte; register byte funnyByte;
@ -241,9 +218,7 @@ readReference(reference, fildes, fileName)
} }
void void
readReferences(objectFile, objectFildes) readReferences(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
int count; int count;
int readCount; int readCount;
@ -292,9 +267,7 @@ readReferences(objectFile, objectFildes)
} }
bool bool
compareSymbolValues(symbol1, symbol2) compareSymbolValues(symbolType **symbol1, symbolType **symbol2)
symbolType **symbol1;
symbolType **symbol2;
{ {
if ((isAbsolute(*symbol1) && !isAbsolute(*symbol2)) || if ((isAbsolute(*symbol1) && !isAbsolute(*symbol2)) ||
(isRelocatable(*symbol1) && !isRelocatable(*symbol2) (isRelocatable(*symbol1) && !isRelocatable(*symbol2)
@ -315,9 +288,7 @@ compareSymbolValues(symbol1, symbol2)
} }
void void
readSymbols(objectFile, objectFildes) readSymbols(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
symbolType *symbolTable; symbolType *symbolTable;
symbolType **symbolTableIndir; symbolType **symbolTableIndir;
@ -359,9 +330,7 @@ readSymbols(objectFile, objectFildes)
} }
expressionPCType expressionPCType
readOneExpression(objectFile, objectFildes) readOneExpression(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
char *fileName; char *fileName;
int expressionSize; int expressionSize;
@ -386,9 +355,7 @@ readOneExpression(objectFile, objectFildes)
} }
void void
readExpressions(objectFile, objectFildes) readExpressions(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
expressionPCType *expressions; expressionPCType *expressions;
int expressionCount; int expressionCount;
@ -420,9 +387,7 @@ readExpressions(objectFile, objectFildes)
} }
argumentListType * argumentListType *
readArgumentList(objectFile, objectFildes) readArgumentList(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
int argumentCount; int argumentCount;
char *fileName; char *fileName;
@ -447,9 +412,7 @@ readArgumentList(objectFile, objectFildes)
} }
void void
readFunctions(objectFile, objectFildes) readFunctions(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
functionType *functions; functionType *functions;
int functionCount; int functionCount;
@ -483,8 +446,7 @@ readFunctions(objectFile, objectFildes)
} }
void void
instantiateExpressionAndSymbolPointers(objectFile) instantiateExpressionAndSymbolPointers(objectFileListType *objectFile)
objectFileListType *objectFile;
{ {
symbolType **symbolTable; symbolType **symbolTable;
expressionPCType *expressions; expressionPCType *expressions;
@ -515,12 +477,9 @@ instantiateExpressionAndSymbolPointers(objectFile)
} }
void void
readReservations(objectFile, objectFildes) readReservations(objectFileListType *objectFile, FILE *objectFildes)
objectFileListType *objectFile;
FILE *objectFildes;
{ {
addressType startAddress; addressType startAddress;
reservationListType *buildReservation();
if (debug) if (debug)
printf(" reservations\n"); printf(" reservations\n");
@ -532,10 +491,7 @@ readReservations(objectFile, objectFildes)
} }
reservationListType * reservationListType *
buildReservation(startAddress, blockSize, nextReservation) buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation)
addressType startAddress;
int blockSize;
reservationListType *nextReservation;
{ {
reservationListType *result; reservationListType *result;

28
slinky/read.h Normal file
View File

@ -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

View File

@ -30,11 +30,16 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.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) #define isUndefined(symbol) (((symbol)->symbolClass & ~SYMBOL_EXTERNAL) == 0)
void void
removeZeroPageFromFreeList() removeZeroPageFromFreeList(void)
{ {
while (freeSegmentList->segmentEndAddress <= 0x100) while (freeSegmentList->segmentEndAddress <= 0x100)
freeSegmentList = freeSegmentList->nextFreeSegment; freeSegmentList = freeSegmentList->nextFreeSegment;
@ -43,9 +48,7 @@ removeZeroPageFromFreeList()
} }
addressType addressType
align(address, alignment) align(addressType address, int alignment)
addressType address;
int alignment;
{ {
if (alignment == 0) if (alignment == 0)
return(address); return(address);
@ -54,10 +57,7 @@ align(address, alignment)
} }
addressType addressType
constrain(address, size, constraint) constrain(addressType address, int size, addressType constraint)
addressType address;
int size;
addressType constraint;
{ {
if (constraint == 0) if (constraint == 0)
return(address); return(address);
@ -67,8 +67,7 @@ constrain(address, size, constraint)
return(address); return(address);
} }
void void
moveRelocationBase(newBase) moveRelocationBase(addressType newBase)
addressType newBase;
{ {
freeSegmentEntryType *freePtr; freeSegmentEntryType *freePtr;
freeSegmentEntryType *newFreePtr; freeSegmentEntryType *newFreePtr;
@ -90,8 +89,7 @@ moveRelocationBase(newBase)
} }
addressType addressType
allocateRelocatable(codeSegment) allocateRelocatable(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
freeSegmentEntryType *freePtr; freeSegmentEntryType *freePtr;
freeSegmentEntryType *previousPtr; freeSegmentEntryType *previousPtr;
@ -146,9 +144,7 @@ allocateRelocatable(codeSegment)
} }
void void
relocateOneCodeSegment(codeSegment, targetLocation) relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation)
codeSegmentHeaderType *codeSegment;
addressType targetLocation;
{ {
int relocationOffset; int relocationOffset;
@ -170,7 +166,7 @@ relocateOneCodeSegment(codeSegment, targetLocation)
} }
void void
relocatem() relocatem(void)
{ {
objectFileListType *inputFileList; objectFileListType *inputFileList;
addressType targetLocation; addressType targetLocation;
@ -205,9 +201,7 @@ relocatem()
} }
codeSegmentHeaderType * codeSegmentHeaderType *
matchModes(symbol, codeSegment) matchModes(symbolType *symbol, codeSegmentHeaderType *codeSegment)
symbolType *symbol;
codeSegmentHeaderType *codeSegment;
{ {
while (codeSegment!=NULL && ((codeSegment->segmentMode==MODE_ABSOLUTE while (codeSegment!=NULL && ((codeSegment->segmentMode==MODE_ABSOLUTE
&& !(symbol->symbolClass & SYMBOL_ABSOLUTE)) || && !(symbol->symbolClass & SYMBOL_ABSOLUTE)) ||
@ -219,9 +213,7 @@ matchModes(symbol, codeSegment)
} }
bool bool
matchedModes(symbol, codeSegment) matchedModes(symbolType *symbol, codeSegmentHeaderType *codeSegment)
symbolType *symbol;
codeSegmentHeaderType *codeSegment;
{ {
return(((symbol->symbolClass & SYMBOL_ABSOLUTE) && codeSegment-> return(((symbol->symbolClass & SYMBOL_ABSOLUTE) && codeSegment->
segmentMode == MODE_ABSOLUTE) || ((symbol->symbolClass & segmentMode == MODE_ABSOLUTE) || ((symbol->symbolClass &
@ -230,9 +222,7 @@ matchedModes(symbol, codeSegment)
} }
codeSegmentHeaderType * codeSegmentHeaderType *
synchronizeCodeSegment(symbol, codeSegment) synchronizeCodeSegment(symbolType *symbol, codeSegmentHeaderType *codeSegment)
symbolType *symbol;
codeSegmentHeaderType *codeSegment;
{ {
codeSegment = matchModes(symbol, codeSegment); codeSegment = matchModes(symbol, codeSegment);
while (codeSegment != NULL && codeSegment->nextSegment != NULL && while (codeSegment != NULL && codeSegment->nextSegment != NULL &&
@ -245,15 +235,12 @@ synchronizeCodeSegment(symbol, codeSegment)
} }
void void
handleGlobalSymbol(symbol) handleGlobalSymbol(symbolType *symbol)
symbolType *symbol;
{ {
} }
void void
valueSymbol(symbol, codeSegment) valueSymbol(symbolType *symbol, codeSegmentHeaderType *codeSegment)
symbolType *symbol;
codeSegmentHeaderType *codeSegment;
{ {
if (symbol->symbolClass & SYMBOL_ABSOLUTE) { if (symbol->symbolClass & SYMBOL_ABSOLUTE) {
return; return;
@ -265,8 +252,7 @@ valueSymbol(symbol, codeSegment)
} }
symbolType * symbolType *
lookupGlobalSymbol(symbolName) lookupGlobalSymbol(char *symbolName)
char *symbolName;
{ {
int guess; int guess;
int top; int top;
@ -295,8 +281,7 @@ lookupGlobalSymbol(symbolName)
} }
void void
valueUndefinedSymbol(symbol) valueUndefinedSymbol(symbolType *symbol)
symbolType *symbol;
{ {
symbolType *globalSymbol; symbolType *globalSymbol;
@ -309,7 +294,7 @@ valueUndefinedSymbol(symbol)
} }
void void
valuem() valuem(void)
{ {
objectFileListType *inputFileList; objectFileListType *inputFileList;
codeSegmentHeaderType *codeSegmentPtr; codeSegmentHeaderType *codeSegmentPtr;

22
slinky/relocate.h Normal file
View File

@ -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

View File

@ -27,43 +27,43 @@
9-March-1985 9-March-1985
*/ */
bool debug; /* TRUE iff we should print debug diagnostics */ extern bool debug; /* TRUE iff we should print debug diagnostics */
bool errorFlag; /* TRUE iff an error occured during linking */ extern bool errorFlag; /* TRUE iff an error occured during linking */
bool verbose; extern bool verbose;
bool packFlag; extern bool packFlag;
#define DEFAULT_LOAD_FILE_NAME "s.out" #define DEFAULT_LOAD_FILE_NAME "s.out"
FILE *loadFileOutput; /* where to put the results */ extern FILE *loadFileOutput; /* where to put the results */
FILE *mapFileOutput; extern FILE *mapFileOutput;
objectFileListType *objectFileList; extern objectFileListType *objectFileList;
objectFileListType *endOfObjectFileList; extern objectFileListType *endOfObjectFileList;
char *currentFileName; extern char *currentFileName;
freeSegmentEntryType *freeSegmentList; extern freeSegmentEntryType *freeSegmentList;
freeSegmentEntryType *effectiveFreeSegmentList; extern freeSegmentEntryType *effectiveFreeSegmentList;
addressType relocationOffset; extern addressType relocationOffset;
addressType entryPointAddress; extern addressType entryPointAddress;
int entryPointMode; extern int entryPointMode;
expressionPCType entryPointExpression; extern expressionPCType entryPointExpression;
bool produceLoadMap; extern bool produceLoadMap;
bool leaveOffLoadFiles; extern bool leaveOffLoadFiles;
bool haveEntryPoint; extern bool haveEntryPoint;
bool haveExpressionEntryPoint; extern bool haveExpressionEntryPoint;
bool readExpressionEntryPoint; extern bool readExpressionEntryPoint;
symbolType **globalSymbolTable; extern symbolType **globalSymbolTable;
int globalSymbolCount; extern int globalSymbolCount;
symbolType **currentSymbolTable; extern symbolType **currentSymbolTable;
functionType *currentFunctionTable; extern functionType *currentFunctionTable;
reservationListType *reservationList; extern reservationListType *reservationList;
int totalSymbolCount; extern int totalSymbolCount;
expressionPCType pc; extern expressionPCType pc;
addressType here; extern addressType here;
bindingListType *localBindings; extern bindingListType *localBindings;
#define CODE_REGIONS_IN_ADDRESS_SPACE 256 #define CODE_REGIONS_IN_ADDRESS_SPACE 256
#define CODE_REGION_SIZE 0x100 #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) #define regionOf(addr) (addr / CODE_REGION_SIZE)
struct { extern struct {
stringType *functionName; stringType *functionName;
addressType (*functionEntry)(); addressType (*functionEntry)();
} builtInFunctionTable[]; } builtInFunctionTable[];

View File

@ -28,23 +28,7 @@
*/ */
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "builtins.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();
/* Used to initialize symbols representing built-in functions */ /* Used to initialize symbols representing built-in functions */
struct { struct {

7
slinky/slinkyTables.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef SLINKY_TABLES_H_
#define SLINKY_TABLES_H_
#include "slinkyTypes.h"
#endif

View File

@ -26,7 +26,10 @@
8-March-1985 8-March-1985
*/ */
#ifndef SLINKY_TYPES_H_
#define SLINKY_TYPES_H_
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
typedef unsigned char byte; typedef unsigned char byte;
@ -187,3 +190,5 @@ typedef enum {
#define typeAlloc(type) (type *)malloc(sizeof(type)) #define typeAlloc(type) (type *)malloc(sizeof(type))
#define typeAllocBlock(type, size) (type *)malloc(sizeof(type) * (size)) #define typeAllocBlock(type, size) (type *)malloc(sizeof(type) * (size))
#endif

View File

@ -30,13 +30,14 @@
#include "slinkyTypes.h" #include "slinkyTypes.h"
#include "slinkyGlobals.h" #include "slinkyGlobals.h"
#include "write.h"
#define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\ #define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\
putc((aWord >> 8) & 0xFF, loadFileOutput) putc((aWord >> 8) & 0xFF, loadFileOutput)
#define writeByte(aByte) putc(aByte & 0xFF, loadFileOutput) #define writeByte(aByte) putc(aByte & 0xFF, loadFileOutput)
void void
writeEntryPoint() writeEntryPoint(void)
{ {
writeWord(entryPointAddress); writeWord(entryPointAddress);
writeWord(entryPointAddress); writeWord(entryPointAddress);
@ -44,8 +45,7 @@ writeEntryPoint()
} }
void void
writeCodeSegment(codeSegment) writeCodeSegment(codeSegmentHeaderType *codeSegment)
codeSegmentHeaderType *codeSegment;
{ {
int length; int length;
int i; int i;
@ -59,7 +59,7 @@ writeCodeSegment(codeSegment)
} }
void void
writem() writem(void)
{ {
int regionNumber; int regionNumber;
codeSegmentHeaderType *lastSegment; codeSegmentHeaderType *lastSegment;

10
slinky/write.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef WRITE_H_
#define WRITE_H_
#include "slinkyTypes.h"
void writeEntryPoint(void);
void writeCodeSegment(codeSegmentHeaderType *codeSegment);
void writem(void);
#endif

View File

@ -30,6 +30,23 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 */ operandType *dbOperand; /* safe temps for dbx hacking */
expressionType *dbExpression; expressionType *dbExpression;
@ -49,31 +66,21 @@ bool nullStatementFlag = FALSE;
#define expansionOn() expandMacros=saveExpansion; #define expansionOn() expandMacros=saveExpansion;
void void
assembleBlock(block) assembleBlock(blockType *block)
blockType *block;
{ {
simpleFixupListType *assembleStatement();
nullAssemble(block); nullAssemble(block);
assembleStatement(block, FALSE, NULL); assembleStatement(block, FALSE, NULL);
} }
simpleFixupListType * simpleFixupListType *
assembleBlockInsideIf(block, ongoingFixupList) assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList)
blockType *block;
simpleFixupListType *ongoingFixupList;
{ {
simpleFixupListType *assembleStatement();
nullAssembleNULL(block); nullAssembleNULL(block);
return(assembleStatement(block, TRUE, ongoingFixupList)); return(assembleStatement(block, TRUE, ongoingFixupList));
} }
bool bool
operandCheck(opcode, numberOfOperands, evaluatedOperands) operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands)
opcodeTableEntryType *opcode;
int numberOfOperands;
valueType *evaluatedOperands[];
{ {
int i; int i;
@ -89,18 +96,13 @@ operandCheck(opcode, numberOfOperands, evaluatedOperands)
} }
void void
assembleMachineInstruction(opcode, operands) assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands)
opcodeTableEntryType *opcode;
operandListType *operands;
{ {
int i; int i;
int op; int op;
valueType *evaluatedOperands[MAX_NUMBER_OF_OPERANDS]; valueType *evaluatedOperands[MAX_NUMBER_OF_OPERANDS];
valueType *value; valueType *value;
valueType *evaluateOperand();
addressType addressValue();
nullAssemble(opcode); nullAssemble(opcode);
expand(moreText("%s\t", opcode->mnemonic)); expand(moreText("%s\t", opcode->mnemonic));
for (op=1; operands!=NULL && op<=opcode->maxNumberOfOperands; for (op=1; operands!=NULL && op<=opcode->maxNumberOfOperands;
@ -141,9 +143,7 @@ assembleMachineInstruction(opcode, operands)
} }
void void
assembleMacro(macroInstruction, operands) assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands)
macroTableEntryType *macroInstruction;
operandListType *operands;
{ {
int numberBound; int numberBound;
identifierListType *savedLocalVariableList; identifierListType *savedLocalVariableList;
@ -187,15 +187,11 @@ assembleMacro(macroInstruction, operands)
} }
void void
assembleAlignStatement(alignStatement) assembleAlignStatement(alignStatementBodyType *alignStatement)
alignStatementBodyType *alignStatement;
{ {
int alignment; int alignment;
bool saveExpansion; bool saveExpansion;
int intValue();
valueType *evaluateExpression();
nullAssemble(alignStatement); nullAssemble(alignStatement);
expansionOff(); expansionOff();
alignment = intValue(evaluateExpression(alignStatement, NO_FIXUP)); alignment = intValue(evaluateExpression(alignStatement, NO_FIXUP));
@ -222,15 +218,12 @@ assembleAlignStatement(alignStatement)
} }
void void
assembleAssertStatement(assertStatement) assembleAssertStatement(assertStatementBodyType *assertStatement)
assertStatementBodyType *assertStatement;
{ {
valueType *test; valueType *test;
valueType *message; valueType *message;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
expansionOff(); expansionOff();
test = evaluateExpression(assertStatement->condition, NO_FIXUP); test = evaluateExpression(assertStatement->condition, NO_FIXUP);
expansionOn(); expansionOn();
@ -255,15 +248,11 @@ assembleAssertStatement(assertStatement)
} }
void void
assembleBlockStatement(blockStatement) assembleBlockStatement(blockStatementBodyType *blockStatement)
blockStatementBodyType *blockStatement;
{ {
valueType *blockIncrement; valueType *blockIncrement;
int blockSize; int blockSize;
valueType *evaluateExpression();
int intValue();
blockSize = 0; blockSize = 0;
nullAssemble(blockStatement); nullAssemble(blockStatement);
expand(moreText("block\t")); expand(moreText("block\t"));
@ -272,7 +261,7 @@ assembleBlockStatement(blockStatement)
theExpression, NO_FIXUP); theExpression, NO_FIXUP);
blockSize += intValue(blockIncrement); blockSize += intValue(blockIncrement);
blockStatement = blockStatement->nextExpression; blockStatement = blockStatement->nextExpression;
expand((expandExpression(NULL), blockStatement!=NULL ? expand((expandExpression(NULL, NULL), blockStatement!=NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
qfree(blockIncrement); qfree(blockIncrement);
} }
@ -295,13 +284,10 @@ assembleBlockStatement(blockStatement)
} }
void void
assembleByteStatement(byteStatement) assembleByteStatement(byteStatementBodyType *byteStatement)
byteStatementBodyType *byteStatement;
{ {
valueType *byteValue; valueType *byteValue;
valueType *evaluateExpression();
nullAssemble(byteStatement); nullAssemble(byteStatement);
expand(moreText("byte\t")); expand(moreText("byte\t"));
while (byteStatement != NULL) { while (byteStatement != NULL) {
@ -315,15 +301,14 @@ assembleByteStatement(byteStatement)
} }
qfree(byteValue); qfree(byteValue);
byteStatement = byteStatement->nextExpression; byteStatement = byteStatement->nextExpression;
expand((expandExpression(NULL), byteStatement != NULL ? expand((expandExpression(NULL, NULL), byteStatement != NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
} }
expand(endLine()); expand(endLine());
} }
void void
assembleConstrainStatement(constrainStatement) assembleConstrainStatement(constrainStatementBodyType *constrainStatement)
constrainStatementBodyType *constrainStatement;
{ {
valueType *constraintValue; valueType *constraintValue;
int constraint; int constraint;
@ -331,8 +316,6 @@ assembleConstrainStatement(constrainStatement)
addressType endAddress; addressType endAddress;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
expansionOff(); expansionOff();
constraintValue = evaluateExpression(constrainStatement->constraint, constraintValue = evaluateExpression(constrainStatement->constraint,
NO_FIXUP); NO_FIXUP);
@ -368,21 +351,17 @@ assembleConstrainStatement(constrainStatement)
} }
void void
assembleDbyteStatement(dbyteStatement) assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement)
dbyteStatementBodyType *dbyteStatement;
{ {
valueType *wordValue; valueType *wordValue;
valueType *evaluateExpression();
valueType *swabValue();
nullAssemble(dbyteStatement); nullAssemble(dbyteStatement);
expand(moreText("dbyte\t")); expand(moreText("dbyte\t"));
while (dbyteStatement != NULL) { while (dbyteStatement != NULL) {
wordValue = swabValue(evaluateExpression(dbyteStatement-> wordValue = swabValue(evaluateExpression(dbyteStatement->
theExpression, DBYTE_FIXUP)); theExpression, DBYTE_FIXUP));
dbyteStatement = dbyteStatement->nextExpression; dbyteStatement = dbyteStatement->nextExpression;
expand((expandExpression(NULL), dbyteStatement != NULL ? expand((expandExpression(NULL, NULL), dbyteStatement != NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
putFixupsHere(DBYTE_FIXUP, 0); putFixupsHere(DBYTE_FIXUP, 0);
emitWordValue(wordValue); emitWordValue(wordValue);
@ -392,17 +371,12 @@ assembleDbyteStatement(dbyteStatement)
} }
void void
assembleDefineStatement(defineStatement) assembleDefineStatement(defineStatementBodyType *defineStatement)
defineStatementBodyType *defineStatement;
{ {
symbolTableEntryType *symbolToDefine; symbolTableEntryType *symbolToDefine;
symbolInContextType *contextToDefine; symbolInContextType *contextToDefine;
bool saveExpansion; bool saveExpansion;
valueType *evaluateDefineExpression();
valueType *newValue();
symbolTableEntryType *effectiveSymbol();
nullAssemble(defineStatement); nullAssemble(defineStatement);
symbolToDefine = effectiveSymbol(defineStatement->theSymbol, symbolToDefine = effectiveSymbol(defineStatement->theSymbol,
&contextToDefine); &contextToDefine);
@ -422,7 +396,7 @@ assembleDefineStatement(defineStatement)
evaluateDefineExpression( evaluateDefineExpression(
defineStatement->theValue); defineStatement->theValue);
contextToDefine->usage = DEFINE_SYMBOL; contextToDefine->usage = DEFINE_SYMBOL;
expand(expandExpression(NULL)); expand(expandExpression(NULL, NULL));
} else } else
contextToDefine->value = newValue(FAIL, 0, contextToDefine->value = newValue(FAIL, 0,
EXPRESSION_OPND); EXPRESSION_OPND);
@ -437,13 +411,10 @@ assembleDefineStatement(defineStatement)
} }
void void
assembleDoUntilStatement(doUntilStatement) assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement)
doUntilStatementBodyType *doUntilStatement;
{ {
valueType topOfLoop; valueType topOfLoop;
simpleFixupListType *emitJump();
nullAssemble(doUntilStatement); nullAssemble(doUntilStatement);
topOfLoop = currentLocationCounter; topOfLoop = currentLocationCounter;
if (doUntilStatement->doUntilCondition == NEVER_COND) if (doUntilStatement->doUntilCondition == NEVER_COND)
@ -464,13 +435,10 @@ assembleDoUntilStatement(doUntilStatement)
} }
void void
assembleDoWhileStatement(doWhileStatement) assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement)
doWhileStatementBodyType *doWhileStatement;
{ {
valueType topOfLoop; valueType topOfLoop;
simpleFixupListType *emitJump();
nullAssemble(doWhileStatement); nullAssemble(doWhileStatement);
topOfLoop = currentLocationCounter; topOfLoop = currentLocationCounter;
if (doWhileStatement->doWhileCondition == ALWAYS_COND) if (doWhileStatement->doWhileCondition == ALWAYS_COND)
@ -491,15 +459,11 @@ assembleDoWhileStatement(doWhileStatement)
} }
void void
assembleExternStatement(externStatement) assembleExternStatement(externStatementBodyType *externStatement)
externStatementBodyType *externStatement;
{ {
symbolInContextType *context; symbolInContextType *context;
symbolTableEntryType *theSymbol; symbolTableEntryType *theSymbol;
symbolInContextType *getBaseContext();
symbolTableEntryType *effectiveSymbol();
expand(moreText("extern\t")); expand(moreText("extern\t"));
while (externStatement != NULL) { while (externStatement != NULL) {
theSymbol = effectiveSymbol(externStatement->theSymbol, theSymbol = effectiveSymbol(externStatement->theSymbol,
@ -523,8 +487,7 @@ assembleExternStatement(externStatement)
} }
void void
assembleFreturnStatement(freturnStatement) assembleFreturnStatement(freturnStatementBodyType *freturnStatement)
freturnStatementBodyType *freturnStatement;
{ {
freturnExit = TRUE; freturnExit = TRUE;
resultOfLastFunctionCall = evaluateExpression(freturnStatement, resultOfLastFunctionCall = evaluateExpression(freturnStatement,
@ -532,17 +495,12 @@ assembleFreturnStatement(freturnStatement)
} }
void void
assembleFunctionStatement(functionStatement) assembleFunctionStatement(functionStatementBodyType *functionStatement)
functionStatementBodyType *functionStatement;
{ {
symbolTableEntryType *newFunctionSymbol; symbolTableEntryType *newFunctionSymbol;
functionDefinitionType *newFunction; functionDefinitionType *newFunction;
symbolInContextType *context; symbolInContextType *context;
symbolTableEntryType *lookupOrEnterSymbol();
valueType *newValue();
symbolInContextType *getBaseContext();
nullAssemble(functionStatement); nullAssemble(functionStatement);
if (currentEnvironment != &globalEnvironment) { if (currentEnvironment != &globalEnvironment) {
error(FUNCTION_DEFINITION_INSIDE_FUNCTION_ERROR); error(FUNCTION_DEFINITION_INSIDE_FUNCTION_ERROR);
@ -576,8 +534,7 @@ assembleFunctionStatement(functionStatement)
} }
void void
assembleGroupStatement(groupStatement) assembleGroupStatement(blockType *groupStatement)
blockType *groupStatement;
{ {
expand((startLineMarked(), tabIndent(), moreText("{"), endLine(), expand((startLineMarked(), tabIndent(), moreText("{"), endLine(),
tabCount++)); tabCount++));
@ -587,17 +544,11 @@ assembleGroupStatement(groupStatement)
} }
simpleFixupListType * simpleFixupListType *
assembleIfStatement(ifStatement, terminalIf, ongoingFixupList) assembleIfStatement(ifStatementBodyType *ifStatement, bool terminalIf, simpleFixupListType *ongoingFixupList)
ifStatementBodyType *ifStatement;
bool terminalIf;
simpleFixupListType *ongoingFixupList;
{ {
valueType fixupLocation1[COMPOUND_BRANCH_MAX]; valueType fixupLocation1[COMPOUND_BRANCH_MAX];
simpleFixupListType *fixupLocation2; simpleFixupListType *fixupLocation2;
simpleFixupListType *emitJump();
void assembleIfStatementOldStyle();
if (backwardsCompatibleIfFlag) { if (backwardsCompatibleIfFlag) {
assembleIfStatementOldStyle(ifStatement); assembleIfStatementOldStyle(ifStatement);
return(NULL); return(NULL);
@ -643,14 +594,11 @@ assembleIfStatement(ifStatement, terminalIf, ongoingFixupList)
} }
void void
assembleIfStatementOldStyle(ifStatement) assembleIfStatementOldStyle(ifStatementBodyType *ifStatement)
ifStatementBodyType *ifStatement;
{ {
valueType fixupLocation1[COMPOUND_BRANCH_MAX]; valueType fixupLocation1[COMPOUND_BRANCH_MAX];
simpleFixupListType *fixupLocation2; simpleFixupListType *fixupLocation2;
simpleFixupListType *emitJump();
nullAssemble(ifStatement); nullAssemble(ifStatement);
if (ifStatement->ifCondition != ALWAYS_COND) { if (ifStatement->ifCondition != ALWAYS_COND) {
emitRelativeBranch(invertConditionCode(ifStatement-> emitRelativeBranch(invertConditionCode(ifStatement->
@ -678,14 +626,11 @@ assembleIfStatementOldStyle(ifStatement)
} }
void void
assembleIncludeStatement(includeStatement) assembleIncludeStatement(includeStatementBodyType *includeStatement)
includeStatementBodyType *includeStatement;
{ {
stringType *fileName; stringType *fileName;
valueType *possibleFileName; valueType *possibleFileName;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
stringType *saveString();
expansionOff(); expansionOff();
possibleFileName = evaluateExpression(includeStatement, NO_FIXUP); possibleFileName = evaluateExpression(includeStatement, NO_FIXUP);
@ -701,9 +646,7 @@ assembleIncludeStatement(includeStatement)
} }
void void
assembleInstructionStatement(instructionStatement, cumulativeLineNumber) assembleInstructionStatement(instructionStatementBodyType *instructionStatement, int cumulativeLineNumber)
instructionStatementBodyType *instructionStatement;
int cumulativeLineNumber;
{ {
nullAssemble(instructionStatement); nullAssemble(instructionStatement);
switch(instructionStatement->kindOfInstruction) { switch(instructionStatement->kindOfInstruction) {
@ -727,26 +670,23 @@ assembleInstructionStatement(instructionStatement, cumulativeLineNumber)
default: default:
botch("bad instruction type=%d\n", instructionStatement-> botch("bad instruction type=%d\n", instructionStatement->
kindOfInstruction); kindOfInstruction, 0, 0);
break; break;
} }
} }
void void
assembleLongStatement(longStatement) assembleLongStatement(longStatementBodyType *longStatement)
longStatementBodyType *longStatement;
{ {
valueType *longValue; valueType *longValue;
valueType *evaluateExpression();
nullAssemble(longStatement); nullAssemble(longStatement);
expand(moreText("long\t")); expand(moreText("long\t"));
while (longStatement != NULL) { while (longStatement != NULL) {
longValue = evaluateExpression(longStatement->theExpression, longValue = evaluateExpression(longStatement->theExpression,
LONG_FIXUP); LONG_FIXUP);
longStatement = longStatement->nextExpression; longStatement = longStatement->nextExpression;
expand((expandExpression(NULL), longStatement != NULL ? expand((expandExpression(NULL, NULL), longStatement != NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
putFixupsHere(LONG_FIXUP, 0); putFixupsHere(LONG_FIXUP, 0);
emitLongValue(longValue); emitLongValue(longValue);
@ -756,13 +696,10 @@ assembleLongStatement(longStatement)
} }
void void
assembleMacroStatement(macroStatement) assembleMacroStatement(macroStatementBodyType *macroStatement)
macroStatementBodyType *macroStatement;
{ {
macroTableEntryType *newMacro; macroTableEntryType *newMacro;
macroTableEntryType *installMacro();
nullAssemble(macroStatement); nullAssemble(macroStatement);
if (currentEnvironment != &globalEnvironment) { if (currentEnvironment != &globalEnvironment) {
error(MACRO_DEFINITION_INSIDE_MACRO_ERROR); error(MACRO_DEFINITION_INSIDE_MACRO_ERROR);
@ -781,11 +718,9 @@ assembleMacroStatement(macroStatement)
} }
void void
assembleMdefineStatement(mdefineStatement) assembleMdefineStatement(defineStatementBodyType *mdefineStatement)
defineStatementBodyType *mdefineStatement;
{ {
bool saveExpansion; bool saveExpansion;
valueType *evaluateDefineExpression();
nullAssemble(mdefineStatement); nullAssemble(mdefineStatement);
expansionOff(); expansionOff();
@ -796,8 +731,7 @@ assembleMdefineStatement(mdefineStatement)
} }
void void
assembleMdoUntilStatement(mdoUntilStatement) assembleMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement)
mdoUntilStatementBodyType *mdoUntilStatement;
{ {
bool saveListingOn; bool saveListingOn;
@ -811,8 +745,7 @@ assembleMdoUntilStatement(mdoUntilStatement)
} }
void void
assembleMdoWhileStatement(mdoWhileStatement) assembleMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement)
mdoWhileStatementBodyType *mdoWhileStatement;
{ {
bool saveListingOn; bool saveListingOn;
@ -826,8 +759,7 @@ assembleMdoWhileStatement(mdoWhileStatement)
} }
void void
assembleMforStatement(mforStatement) assembleMforStatement(mforStatementBodyType *mforStatement)
mforStatementBodyType *mforStatement;
{ {
bool saveListingOn; bool saveListingOn;
bool saveExpansion; bool saveExpansion;
@ -848,9 +780,7 @@ assembleMforStatement(mforStatement)
} }
void void
assembleMifStatement(mifStatement, cumulativeLineNumber) assembleMifStatement(mifStatementBodyType *mifStatement, int cumulativeLineNumber)
mifStatementBodyType *mifStatement;
int cumulativeLineNumber;
{ {
while (mifStatement != NULL) { while (mifStatement != NULL) {
if (mifStatement->mifCondition == NULL) { if (mifStatement->mifCondition == NULL) {
@ -869,8 +799,7 @@ assembleMifStatement(mifStatement, cumulativeLineNumber)
} }
void void
assembleMswitchStatement(mswitchStatement) assembleMswitchStatement(mswitchStatementBodyType *mswitchStatement)
mswitchStatementBodyType *mswitchStatement;
{ {
valueType *switchValue; valueType *switchValue;
caseListType *caseList; caseListType *caseList;
@ -879,7 +808,6 @@ assembleMswitchStatement(mswitchStatement)
expressionListType *tagExpressionList; expressionListType *tagExpressionList;
valueType *tagValue; valueType *tagValue;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
expansionOff(); expansionOff();
switchValue = evaluateExpression(mswitchStatement->switchExpression, switchValue = evaluateExpression(mswitchStatement->switchExpression,
@ -932,16 +860,12 @@ assembleMswitchStatement(mswitchStatement)
} }
void void
assembleMvariableStatement(mvariableStatement) assembleMvariableStatement(mvariableStatementBodyType *mvariableStatement)
mvariableStatementBodyType *mvariableStatement;
{ {
identifierListType *newLocalVariable; identifierListType *newLocalVariable;
int initCount; int initCount;
bool saveExpansion; bool saveExpansion;
valueType *createArray();
int expressionListLength();
nullAssemble(mvariableStatement); nullAssemble(mvariableStatement);
expansionOff(); expansionOff();
if (mvariableStatement->theDimension == NULL) { if (mvariableStatement->theDimension == NULL) {
@ -970,8 +894,7 @@ assembleMvariableStatement(mvariableStatement)
} }
void void
assembleMwhileStatement(mwhileStatement) assembleMwhileStatement(mwhileStatementBodyType *mwhileStatement)
mwhileStatementBodyType *mwhileStatement;
{ {
bool saveListingOn; bool saveListingOn;
@ -985,12 +908,10 @@ assembleMwhileStatement(mwhileStatement)
} }
void void
assembleOrgStatement(orgStatement) assembleOrgStatement(orgStatementBodyType *orgStatement)
orgStatementBodyType *orgStatement;
{ {
valueType *orgAddress; valueType *orgAddress;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
nullAssemble(orgStatement); nullAssemble(orgStatement);
targetOffset = 0; targetOffset = 0;
@ -1015,11 +936,8 @@ assembleOrgStatement(orgStatement)
} }
void void
assemblePerformStatement(performStatement) assemblePerformStatement(performStatementBodyType *performStatement)
performStatementBodyType *performStatement;
{ {
void evaluateExpressionStandalone();
nullAssemble(performStatement); nullAssemble(performStatement);
sideEffectFlag = FALSE; sideEffectFlag = FALSE;
evaluateExpressionStandalone(performStatement); evaluateExpressionStandalone(performStatement);
@ -1028,8 +946,7 @@ assemblePerformStatement(performStatement)
} }
void void
assembleRelStatement(relStatement) assembleRelStatement(relStatementBodyType *relStatement)
relStatementBodyType *relStatement;
{ {
targetOffset = 0; targetOffset = 0;
if (!relocatableValue(&currentLocationCounter)) { if (!relocatableValue(&currentLocationCounter)) {
@ -1042,13 +959,8 @@ assembleRelStatement(relStatement)
} }
void void
assembleStartStatement(startStatement) assembleStartStatement(startStatementBodyType *startStatement)
startStatementBodyType *startStatement;
{ {
valueType *evaluateExpression();
addressType addressValue();
expressionType *generateFixupExpression();
nullAssemble(startStatement); nullAssemble(startStatement);
expand(moreText("start\t")); expand(moreText("start\t"));
if (haveUserStartAddress) { if (haveUserStartAddress) {
@ -1066,7 +978,7 @@ assembleStartStatement(startStatement)
expand((moreText("*fail*"), endLine())); expand((moreText("*fail*"), endLine()));
error(BAD_START_ADDRESS_ERROR); error(BAD_START_ADDRESS_ERROR);
} else { } else {
expand((expandExpression(NULL), endLine())); expand((expandExpression(NULL, NULL), endLine()));
haveUserStartAddress = TRUE; haveUserStartAddress = TRUE;
fixupStartAddress = FALSE; fixupStartAddress = FALSE;
} }
@ -1074,13 +986,10 @@ assembleStartStatement(startStatement)
} }
void void
assembleStringStatement(stringStatement) assembleStringStatement(stringStatementBodyType *stringStatement)
stringStatementBodyType *stringStatement;
{ {
valueType *byteValue; valueType *byteValue;
valueType *evaluateExpression();
nullAssemble(stringStatement); nullAssemble(stringStatement);
expand(moreText("string\t")); expand(moreText("string\t"));
while (stringStatement != NULL) { while (stringStatement != NULL) {
@ -1095,15 +1004,14 @@ assembleStringStatement(stringStatement)
} }
qfree(byteValue); qfree(byteValue);
stringStatement = stringStatement->nextExpression; stringStatement = stringStatement->nextExpression;
expand((expandExpression(NULL), stringStatement != NULL ? expand((expandExpression(NULL, NULL), stringStatement != NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
} }
expand(endLine()); expand(endLine());
} }
void void
assembleStructStatement(structStatement) assembleStructStatement(structStatementBodyType *structStatement)
structStatementBodyType *structStatement;
{ {
nullAssemble(structStatement); nullAssemble(structStatement);
if (structStatement->structBody == NULL) if (structStatement->structBody == NULL)
@ -1113,12 +1021,10 @@ assembleStructStatement(structStatement)
} }
void void
assembleTargetStatement(targetStatement) assembleTargetStatement(targetStatementBodyType *targetStatement)
targetStatementBodyType *targetStatement;
{ {
valueType *targetAddress; valueType *targetAddress;
bool saveExpansion; bool saveExpansion;
valueType *evaluateExpression();
nullAssemble(targetStatement); nullAssemble(targetStatement);
targetOffset = 0; targetOffset = 0;
@ -1138,11 +1044,8 @@ assembleTargetStatement(targetStatement)
} }
void void
assembleUndefineStatement(undefineStatement) assembleUndefineStatement(undefineStatementBodyType *undefineStatement)
undefineStatementBodyType *undefineStatement;
{ {
symbolTableEntryType *effectiveSymbol();
expand(moreText("undefine\t")); expand(moreText("undefine\t"));
while (undefineStatement != NULL) { while (undefineStatement != NULL) {
expand(moreText("%s", symbName(undefineStatement->theSymbol))); expand(moreText("%s", symbName(undefineStatement->theSymbol)));
@ -1155,17 +1058,12 @@ assembleUndefineStatement(undefineStatement)
} }
void void
assembleVariableStatement(variableStatement) assembleVariableStatement(variableStatementBodyType *variableStatement)
variableStatementBodyType *variableStatement;
{ {
symbolTableEntryType *newVariable; symbolTableEntryType *newVariable;
symbolInContextType *contextForVariable; symbolInContextType *contextForVariable;
int initCount; int initCount;
symbolTableEntryType *effectiveSymbol();
valueType *createArray();
int expressionListLength();
nullAssemble(variableStatement); nullAssemble(variableStatement);
newVariable = effectiveSymbol(variableStatement->theSymbol, newVariable = effectiveSymbol(variableStatement->theSymbol,
&contextForVariable); &contextForVariable);
@ -1184,7 +1082,7 @@ assembleVariableStatement(variableStatement)
theValue)) == 1) { theValue)) == 1) {
contextForVariable->value = evaluateExpression( contextForVariable->value = evaluateExpression(
variableStatement->theValue->theExpression, NO_FIXUP); variableStatement->theValue->theExpression, NO_FIXUP);
expand(expandExpression(NULL)); expand(expandExpression(NULL, NULL));
} else { } else {
if (initCount > 1) if (initCount > 1)
error(TOO_MANY_VARIABLE_INITIALIZERS_ERROR); error(TOO_MANY_VARIABLE_INITIALIZERS_ERROR);
@ -1206,8 +1104,7 @@ assembleVariableStatement(variableStatement)
} }
void void
assembleWhileStatement(whileStatement) assembleWhileStatement(whileStatementBodyType *whileStatement)
whileStatementBodyType *whileStatement;
{ {
valueType topOfLoop; valueType topOfLoop;
valueType fixupLocation[COMPOUND_BRANCH_MAX]; valueType fixupLocation[COMPOUND_BRANCH_MAX];
@ -1238,20 +1135,17 @@ assembleWhileStatement(whileStatement)
} }
void void
assembleWordStatement(wordStatement) assembleWordStatement(wordStatementBodyType *wordStatement)
wordStatementBodyType *wordStatement;
{ {
valueType *word; valueType *word;
valueType *evaluateExpression();
nullAssemble(wordStatement); nullAssemble(wordStatement);
expand(moreText("word\t")); expand(moreText("word\t"));
while (wordStatement != NULL) { while (wordStatement != NULL) {
word = evaluateExpression(wordStatement->theExpression, word = evaluateExpression(wordStatement->theExpression,
WORD_FIXUP); WORD_FIXUP);
wordStatement = wordStatement->nextExpression; wordStatement = wordStatement->nextExpression;
expand((expandExpression(NULL), wordStatement != NULL ? expand((expandExpression(NULL, NULL), wordStatement != NULL ?
moreText(", ") : 0)); moreText(", ") : 0));
putFixupsHere(WORD_FIXUP, 0); putFixupsHere(WORD_FIXUP, 0);
emitWordValue(word); emitWordValue(word);
@ -1261,13 +1155,7 @@ assembleWordStatement(wordStatement)
} }
bool bool
assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf, assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList)
ifFixupList)
statementKindType kind;
statementBodyType body;
int cumulativeLineNumber;
bool worryAboutIf;
simpleFixupListType **ifFixupList;
{ {
bool result; bool result;
@ -1468,7 +1356,7 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf,
break; break;
default: default:
botch("assembleStatementBody doesn't know kind %d\n", kind); botch("assembleStatementBody doesn't know kind %d\n", kind, 0, 0);
break; break;
} }
/* return(result);*/ /* return(result);*/
@ -1476,11 +1364,8 @@ assembleStatementBody(kind, body, cumulativeLineNumber, worryAboutIf,
} }
void void
assembleLabelList(labelList) assembleLabelList(labelListType *labelList)
labelListType *labelList;
{ {
valueType *newValue();
while (labelList != NULL) { while (labelList != NULL) {
if (structNestingDepth == 0) if (structNestingDepth == 0)
valueLabel(labelList->theLabel, valueLabel(labelList->theLabel,
@ -1495,10 +1380,7 @@ assembleLabelList(labelList)
} }
simpleFixupListType * simpleFixupListType *
assembleStatement(statement, insideIf, ongoingFixupList) assembleStatement(statementType *statement, bool insideIf, simpleFixupListType *ongoingFixupList)
statementType *statement;
bool insideIf;
simpleFixupListType *ongoingFixupList;
{ {
char *saveFileName; char *saveFileName;
int saveLineNumber; int saveLineNumber;
@ -1522,9 +1404,10 @@ assembleStatement(statement, insideIf, ongoingFixupList)
statement->statementBody, statement-> statement->statementBody, statement->
cumulativeLineNumber, insideIf && cumulativeLineNumber, insideIf &&
isLastStatementInBlock(statement), &result)) { isLastStatementInBlock(statement), &result)) {
statementType *next = statement->nextStatement;
if (freeFlag && statementEvaluationDepth == 1) if (freeFlag && statementEvaluationDepth == 1)
freeStatement(statement); freeStatement(statement);
statement = statement->nextStatement; statement = next;
} else { } else {
if (freeFlag && statementEvaluationDepth == 1) if (freeFlag && statementEvaluationDepth == 1)
freeStatement(statement); freeStatement(statement);
@ -1543,8 +1426,7 @@ assembleStatement(statement, insideIf, ongoingFixupList)
} }
void void
eatStatement(statement) eatStatement(statementType *statement)
statementType *statement;
{ {
if (debug) { if (debug) {
printf("assembling:\n"); printf("assembling:\n");

54
statementSemantics.h Normal file
View File

@ -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

View File

@ -29,11 +29,16 @@
#include "macrossTypes.h" #include "macrossTypes.h"
#include "macrossGlobals.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 void
putStructFixups(base, fixups) putStructFixups(int base, fixupListType *fixups)
int base;
fixupListType *fixups;
{ {
fixupListType *newFixup; fixupListType *newFixup;
@ -54,9 +59,7 @@ putStructFixups(base, fixups)
} }
void void
putStructReferences(base, references) putStructReferences(int base, expressionReferenceListType *references)
int base;
expressionReferenceListType *references;
{ {
expressionReferenceListType *newReference; expressionReferenceListType *newReference;
int currentMode; int currentMode;
@ -80,15 +83,12 @@ putStructReferences(base, references)
} }
void void
instantiateStruct(structStatement) instantiateStruct(structStatementBodyType *structStatement)
structStatementBodyType *structStatement;
{ {
int i; int i;
int base; int base;
symbolInContextType *context; symbolInContextType *context;
symbolInContextType *getWorkingContext();
#define structInstance ((structInstanceType *) context->value->value) #define structInstance ((structInstanceType *) context->value->value)
context = getWorkingContext(structStatement->structName); context = getWorkingContext(structStatement->structName);
@ -112,8 +112,7 @@ instantiateStruct(structStatement)
} }
structInstanceType * structInstanceType *
assembleStructDefinitionBody(structBody) assembleStructDefinitionBody(structBodyType *structBody)
structBodyType *structBody;
{ {
int i; int i;
simpleFixupListType *dummy; simpleFixupListType *dummy;
@ -128,7 +127,7 @@ assembleStructDefinitionBody(structBody)
expand(listableStatement(structBody->kindOfStatement) ? expand(listableStatement(structBody->kindOfStatement) ?
(expandLabel(), tabIndent()) : 0); (expandLabel(), tabIndent()) : 0);
assembleStatementBody(structBody->kindOfStatement, assembleStatementBody(structBody->kindOfStatement,
structBody->statementBody, FALSE, &dummy); structBody->statementBody, 0 /* random guess */, FALSE, &dummy);
if (currentFieldOffset > MAXIMUM_ALLOWED_STRUCT_SIZE) { if (currentFieldOffset > MAXIMUM_ALLOWED_STRUCT_SIZE) {
error(STRUCT_TOO_BIG_ERROR); error(STRUCT_TOO_BIG_ERROR);
return(NULL); return(NULL);
@ -144,14 +143,11 @@ assembleStructDefinitionBody(structBody)
} }
void void
assembleStructDefinition(structStatement) assembleStructDefinition(structStatementBodyType *structStatement)
structStatementBodyType *structStatement;
{ {
symbolTableEntryType *name; symbolTableEntryType *name;
symbolInContextType *context; symbolInContextType *context;
symbolTableEntryType *effectiveSymbol();
name = effectiveSymbol(structStatement->structName, &context); name = effectiveSymbol(structStatement->structName, &context);
if (context == NULL) if (context == NULL)
botch("struct definition doesn't have working context\n"); botch("struct definition doesn't have working context\n");

12
structSemantics.h Normal file
View File

@ -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

9
tokenStrings.h Normal file
View File

@ -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

View File

@ -34,8 +34,7 @@
/* conditionString similarly deals with condition codes */ /* conditionString similarly deals with condition codes */
char * char *
conditionString(condition) conditionString(conditionType condition)
conditionType condition;
{ {
/* This table MUST be maintained congruently with the definition of the /* This table MUST be maintained congruently with the definition of the
enumerated type 'conditionType' */ enumerated type 'conditionType' */
@ -67,8 +66,7 @@ conditionString(condition)
/* tokenString similarly deals with parser tokens */ /* tokenString similarly deals with parser tokens */
char * char *
tokenString(token) tokenString(int token)
int token;
{ {
/* This table MUST be maintained congruently with the token definitions in /* This table MUST be maintained congruently with the token definitions in
the file 'y.tab.h' as output by yacc. */ the file 'y.tab.h' as output by yacc. */