package mars.assembler;
import mars.*;
import mars.util.Binary;
import mars.mips.instructions.*;
import java.util.*;
/*
Copyright (c) 2003-2008, Pete Sanderson and Kenneth Vollmar
Developed by Pete Sanderson (psanderson@otterbein.edu)
and Kenneth Vollmar (kenvollmar@missouristate.edu)
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.
(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/
/**
* Provides utility method related to MIPS operand formats.
*
* @author Pete Sanderson
* @version August 2003
*/
public class OperandFormat {
private OperandFormat() {
}
/*
* Syntax test for correct match in both numbers and types of operands.
*
* @param candidateList List of tokens generated from programmer's MIPS statement.
* @param spec The (resumably best matched) MIPS instruction.
* @param errors ErrorList into which any error messages generated here will be added.
*
* @return Returns true if the programmer's statement matches the MIPS
* specification, else returns false.
*/
static boolean tokenOperandMatch(TokenList candidateList, Instruction inst, ErrorList errors) {
if (!numOperandsCheck(candidateList, inst, errors))
return false;
if (!operandTypeCheck(candidateList, inst, errors))
return false;
return true;
}
/*
* If candidate operator token matches more than one instruction mnemonic, then select
* first such Instruction that has an exact operand match. If none match,
* return the first Instruction and let client deal with operand mismatches.
*/
static Instruction bestOperandMatch(TokenList tokenList, ArrayList instrMatches) {
if (instrMatches == null)
return null;
if (instrMatches.size() == 1)
return (Instruction) instrMatches.get(0);
for (int i=0; i=DataTypes.MIN_HALF_VALUE && temp<=DataTypes.MAX_HALF_VALUE)
continue;
if (specType == TokenTypes.INTEGER_16U && candType == TokenTypes.INTEGER_16 &&
temp>=DataTypes.MIN_UHALF_VALUE && temp<=DataTypes.MAX_UHALF_VALUE)
continue;
}
if ((specType == TokenTypes.INTEGER_5 && candType == TokenTypes.INTEGER_16) ||
(specType == TokenTypes.INTEGER_5 && candType == TokenTypes.INTEGER_16U) ||
(specType == TokenTypes.INTEGER_5 && candType == TokenTypes.INTEGER_32) ||
(specType == TokenTypes.INTEGER_16 && candType == TokenTypes.INTEGER_16U) ||
(specType == TokenTypes.INTEGER_16U && candType == TokenTypes.INTEGER_16) ||
(specType == TokenTypes.INTEGER_16U && candType == TokenTypes.INTEGER_32) ||
(specType == TokenTypes.INTEGER_16 && candType == TokenTypes.INTEGER_32)) {
generateMessage(candToken, "operand is out of range", errors);
return false;
}
if (candType != specType) {
generateMessage(candToken, "operand is of incorrect type", errors);
return false;
}
}
/******** nice little debugging code to see which operand format
******** the operands for this source code instruction matched.
System.out.print("Candidate: ");
for (int i=1; i