-CodeGenInstruction::CodeGenInstruction(Record *R, const std::string &AsmStr)
- : TheDef(R), AsmString(AsmStr) {
- Name = R->getValueAsString("Name");
- Namespace = R->getValueAsString("Namespace");
-
- isReturn = R->getValueAsBit("isReturn");
- isBranch = R->getValueAsBit("isBranch");
- isIndirectBranch = R->getValueAsBit("isIndirectBranch");
- isBarrier = R->getValueAsBit("isBarrier");
- isCall = R->getValueAsBit("isCall");
- isLoad = R->getValueAsBit("isLoad");
- isStore = R->getValueAsBit("isStore");
- isImplicitDef= R->getValueAsBit("isImplicitDef");
- bool isTwoAddress = R->getValueAsBit("isTwoAddress");
- isPredicable = R->getValueAsBit("isPredicable");
- isConvertibleToThreeAddress = R->getValueAsBit("isConvertibleToThreeAddress");
- isCommutable = R->getValueAsBit("isCommutable");
- isTerminator = R->getValueAsBit("isTerminator");
- isReMaterializable = R->getValueAsBit("isReMaterializable");
- hasDelaySlot = R->getValueAsBit("hasDelaySlot");
- usesCustomDAGSchedInserter = R->getValueAsBit("usesCustomDAGSchedInserter");
- hasCtrlDep = R->getValueAsBit("hasCtrlDep");
- isNotDuplicable = R->getValueAsBit("isNotDuplicable");
- mayHaveSideEffects = R->getValueAsBit("mayHaveSideEffects");
- neverHasSideEffects = R->getValueAsBit("neverHasSideEffects");
- hasOptionalDef = false;
- hasVariableNumberOfOperands = false;
-
- if (mayHaveSideEffects && neverHasSideEffects)
- throw R->getName() +
- ": cannot have both 'mayHaveSideEffects' and 'neverHasSideEffects' set!";
-
- DagInit *DI;
- try {
- DI = R->getValueAsDag("OutOperandList");
- } catch (...) {
- // Error getting operand list, just ignore it (sparcv9).
- AsmString.clear();
- OperandList.clear();
- return;
- }
- NumDefs = DI->getNumArgs();
-
- DagInit *IDI;
- try {
- IDI = R->getValueAsDag("InOperandList");
- } catch (...) {
- // Error getting operand list, just ignore it (sparcv9).
- AsmString.clear();
- OperandList.clear();
- return;
- }
- DI = (DagInit*)(new BinOpInit(BinOpInit::CONCAT, DI, IDI))->Fold();
-
- unsigned MIOperandNo = 0;
- std::set<std::string> OperandNames;
- for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) {
- DefInit *Arg = dynamic_cast<DefInit*>(DI->getArg(i));
- if (!Arg)
- throw "Illegal operand for the '" + R->getName() + "' instruction!";
-
- Record *Rec = Arg->getDef();
- std::string PrintMethod = "printOperand";
- unsigned NumOps = 1;
- DagInit *MIOpInfo = 0;
- if (Rec->isSubClassOf("Operand")) {
- PrintMethod = Rec->getValueAsString("PrintMethod");
- MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
-
- // Verify that MIOpInfo has an 'ops' root value.
- if (!dynamic_cast<DefInit*>(MIOpInfo->getOperator()) ||
- dynamic_cast<DefInit*>(MIOpInfo->getOperator())
- ->getDef()->getName() != "ops")
- throw "Bad value for MIOperandInfo in operand '" + Rec->getName() +
- "'\n";
-
- // If we have MIOpInfo, then we have #operands equal to number of entries
- // in MIOperandInfo.
- if (unsigned NumArgs = MIOpInfo->getNumArgs())
- NumOps = NumArgs;
-
- if (Rec->isSubClassOf("PredicateOperand"))
- isPredicable = true;
- else if (Rec->isSubClassOf("OptionalDefOperand"))
- hasOptionalDef = true;
- } else if (Rec->getName() == "variable_ops") {
- hasVariableNumberOfOperands = true;
- continue;
- } else if (!Rec->isSubClassOf("RegisterClass") &&
- Rec->getName() != "ptr_rc")
- throw "Unknown operand class '" + Rec->getName() +
- "' in instruction '" + R->getName() + "' instruction!";
-
- // Check that the operand has a name and that it's unique.
- if (DI->getArgName(i).empty())
- throw "In instruction '" + R->getName() + "', operand #" + utostr(i) +
- " has no name!";
- if (!OperandNames.insert(DI->getArgName(i)).second)
- throw "In instruction '" + R->getName() + "', operand #" + utostr(i) +
- " has the same name as a previous operand!";
-
- OperandList.push_back(OperandInfo(Rec, DI->getArgName(i), PrintMethod,
- MIOperandNo, NumOps, MIOpInfo));
- MIOperandNo += NumOps;
- }