From cf03da0ce913267c4971534e8792297e06535a4e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 11 Aug 2004 02:22:39 +0000 Subject: [PATCH] Start parsing more information from the Operand information git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15644 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/CodeGenInstruction.h | 30 ++++++++++++++++++++++++----- utils/TableGen/CodeGenTarget.cpp | 13 ++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/utils/TableGen/CodeGenInstruction.h b/utils/TableGen/CodeGenInstruction.h index 5269cc76e2b..85be70e650f 100644 --- a/utils/TableGen/CodeGenInstruction.h +++ b/utils/TableGen/CodeGenInstruction.h @@ -31,15 +31,35 @@ namespace llvm { /// instruction. std::string AsmString; - /// OperandInfo - For each operand declared in the OperandList of the - /// instruction, keep track of its record (which specifies the class of the - /// operand), its type, and the name given to the operand, if any. + /// OperandInfo - The information we keep track of for each operand in the + /// operand list for a tablegen instruction. struct OperandInfo { + /// Rec - The definition this operand is declared as. Record *Rec; + + /// Ty - The MachineValueType of the operand. + /// MVT::ValueType Ty; + + /// Name - If this operand was assigned a symbolic name, this is it, + /// otherwise, it's empty. std::string Name; - OperandInfo(Record *R, MVT::ValueType T, const std::string &N) - : Rec(R), Ty(T), Name(N) {} + + /// PrinterMethodName - The method used to print operands of this type in + /// the asmprinter. + std::string PrinterMethodName; + + /// MIOperandNo - Currently (this is meant to be phased out), some logical + /// operands correspond to multiple MachineInstr operands. In the X86 + /// target for example, one address operand is represented as 4 + /// MachineOperands. Because of this, the operand number in the + /// OperandList may not match the MachineInstr operand num. Until it + /// does, this contains the MI operand index of this operand. + unsigned MIOperandNo; + + OperandInfo(Record *R, MVT::ValueType T, const std::string &N, + const std::string &PMN, unsigned MION) + : Rec(R), Ty(T), Name(N), PrinterMethodName(PMN), MIOperandNo(MION) {} }; /// OperandList - The list of declared operands, along with their declared diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index 9004104315e..e7ca8570280 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -132,19 +132,26 @@ CodeGenInstruction::CodeGenInstruction(Record *R) : TheDef(R) { try { DagInit *DI = R->getValueAsDag("OperandList"); + unsigned MIOperandNo = 0; for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) if (DefInit *Arg = dynamic_cast(DI->getArg(i))) { Record *Rec = Arg->getDef(); MVT::ValueType Ty; + std::string PrintMethod = "printOperand"; + unsigned NumOps = 1; if (Rec->isSubClassOf("RegisterClass")) Ty = getValueType(Rec->getValueAsDef("RegType")); - else if (Rec->isSubClassOf("Operand")) + else if (Rec->isSubClassOf("Operand")) { Ty = getValueType(Rec->getValueAsDef("Type")); - else + PrintMethod = Rec->getValueAsString("PrintMethod"); + NumOps = Rec->getValueAsInt("NumMIOperands"); + } else throw "Unknown operand class '" + Rec->getName() + "' in instruction '" + R->getName() + "' instruction!"; - OperandList.push_back(OperandInfo(Rec, Ty, DI->getArgName(i))); + OperandList.push_back(OperandInfo(Rec, Ty, DI->getArgName(i), + PrintMethod, MIOperandNo)); + MIOperandNo += NumOps; } else { throw "Illegal operand for the '" + R->getName() + "' instruction!"; }