2016-01-14 15:23:33 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-05-04 05:20:34 +00:00
|
|
|
/*
|
|
|
|
parserMisc.c -- Miscellaneous parser support routines for the Macross
|
|
|
|
assembler.
|
|
|
|
|
|
|
|
Chip Morningstar -- Lucasfilm Ltd.
|
|
|
|
|
|
|
|
3-November-1984
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "macrossTypes.h"
|
|
|
|
#include "macrossGlobals.h"
|
|
|
|
#include "y.tab.h"
|
2016-01-24 05:50:12 +00:00
|
|
|
#include "buildStuff.h"
|
|
|
|
#include "fixups.h"
|
|
|
|
#include "initialize.h"
|
|
|
|
#include "errorStuff.h"
|
2016-01-23 11:51:29 +00:00
|
|
|
#include "parserMisc.h"
|
2014-05-04 05:20:34 +00:00
|
|
|
|
2016-01-23 16:35:49 +00:00
|
|
|
#include <stdarg.h>
|
2016-01-23 14:53:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-01-24 05:50:12 +00:00
|
|
|
statementType *
|
2016-01-23 18:18:42 +00:00
|
|
|
addLabelToStatement(labelListType *labelList, statementType *statement)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (statement == NULL)
|
2016-01-23 17:47:57 +00:00
|
|
|
statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL });
|
2014-05-04 05:20:34 +00:00
|
|
|
statement->labels = labelList;
|
|
|
|
return(statement);
|
|
|
|
}
|
|
|
|
|
2016-01-23 11:51:29 +00:00
|
|
|
/* 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. */
|
|
|
|
|
2014-05-04 05:20:34 +00:00
|
|
|
void
|
2016-01-23 16:35:49 +00:00
|
|
|
botch(char *message, ...)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
2016-01-23 16:35:49 +00:00
|
|
|
va_list ap;
|
2014-05-04 05:20:34 +00:00
|
|
|
printf("Macross horrible terrible internal botch: ");
|
2016-01-23 16:35:49 +00:00
|
|
|
va_start(ap, message);
|
|
|
|
vprintf(message, ap);
|
|
|
|
va_end(ap);
|
2014-05-04 05:20:34 +00:00
|
|
|
chokePukeAndDie();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
checkDefineAssignmentOperator(assignmentKindType assignmentOperator)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (assignmentOperator != ASSIGN_ASSIGN)
|
|
|
|
puntOnError(DEFINE_ASSIGNMENT_WRONG_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
statementType *
|
2016-01-23 18:18:42 +00:00
|
|
|
convertDefineToMdefine(statementType *defineStatement)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (defineStatement->kindOfStatement != DEFINE_STATEMENT)
|
|
|
|
botch("convertDefineToMdefine got statement kind: %d\n",
|
2016-01-23 11:51:29 +00:00
|
|
|
defineStatement->kindOfStatement, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
defineStatement->kindOfStatement = MDEFINE_STATEMENT;
|
|
|
|
return(defineStatement);
|
|
|
|
}
|
|
|
|
|
|
|
|
ifStatementBodyType *
|
2016-01-23 18:18:42 +00:00
|
|
|
extractIfBody(statementType *ifStatement)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
ifStatementBodyType *result;
|
|
|
|
|
|
|
|
result = ifStatement->statementBody.ifUnion;
|
|
|
|
if (ifStatement->labels != NULL)
|
2016-01-23 11:51:29 +00:00
|
|
|
botch("extract if body with non-null labels\n", 0, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
else if (ifStatement->nextStatement != NULL)
|
2016-01-23 11:51:29 +00:00
|
|
|
botch("extract if body with non-null next\n", 0, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
else
|
|
|
|
qfree(ifStatement);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
mifStatementBodyType *
|
2016-01-23 18:18:42 +00:00
|
|
|
extractMifBody(statementType *mifStatement)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
mifStatementBodyType *result;
|
|
|
|
|
|
|
|
result = mifStatement->statementBody.mifUnion;
|
|
|
|
if (mifStatement->labels != NULL)
|
2016-01-23 11:51:29 +00:00
|
|
|
botch("extract mif body with non-null labels\n", 0, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
else if (mifStatement->nextStatement != NULL)
|
2016-01-23 11:51:29 +00:00
|
|
|
botch("extract mif body with non-null next\n", 0, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
else
|
|
|
|
qfree(mifStatement);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
stringType *
|
2016-01-23 18:18:42 +00:00
|
|
|
extractString(operandType *textExpression)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
stringType *result;
|
|
|
|
|
|
|
|
if (textExpression->kindOfOperand != STRING_OPND)
|
|
|
|
botch("extract string got handed an opnd kind: %d\n",
|
2016-01-23 11:51:29 +00:00
|
|
|
textExpression->kindOfOperand, 0, 0);
|
2014-05-04 05:20:34 +00:00
|
|
|
result = textExpression->theOperand.stringUnion;
|
|
|
|
qfree(textExpression);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
popMacroOrFunctionNestingDepth(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (--macroOrFunctionNestingDepth == 0)
|
|
|
|
unknownSymbolTag = UNKNOWN_SYMBOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
pushMacroOrFunctionNestingDepth(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
macroOrFunctionNestingDepth++;
|
|
|
|
unknownSymbolTag = NESTED_UNKNOWN_SYMBOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2016-01-23 18:18:42 +00:00
|
|
|
saveString(char *s)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
result = (char *)malloc(strlen(s)+1);
|
|
|
|
strcpy(result, s);
|
|
|
|
return(result);
|
|
|
|
}
|