From 5765dba5ce9f493f063a7caf1106e7db9b6693b6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 22 Jan 2005 17:40:38 +0000 Subject: Minor refactoring, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19753 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/AsmWriterEmitter.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'utils/TableGen/AsmWriterEmitter.cpp') diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index d44515fe2e..e9d33869c6 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -53,8 +53,9 @@ namespace { struct AsmWriterInst { std::vector Operands; + const CodeGenInstruction *CGI; - void ParseAsmString(const CodeGenInstruction &CGI, unsigned Variant); + AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant); void EmitCode(std::ostream &OS) const { for (unsigned i = 0, e = Operands.size(); i != e; ++i) Operands[i].EmitCode(OS); @@ -84,8 +85,8 @@ void AsmWriterOperand::EmitCode(std::ostream &OS) const { /// ParseAsmString - Parse the specified Instruction's AsmString into this /// AsmWriterInst. /// -void AsmWriterInst::ParseAsmString(const CodeGenInstruction &CGI, - unsigned Variant) { +AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) { + this->CGI = &CGI; bool inVariant = false; // True if we are inside a {.|.|.} region. const std::string &AsmString = CGI.AsmString; @@ -152,10 +153,11 @@ void AsmWriterInst::ParseAsmString(const CodeGenInstruction &CGI, throw "Stray '$' in '" + CGI.Name + "' asm string, maybe you want $$?"; unsigned OpNo = CGI.getOperandNamed(VarName); + CodeGenInstruction::OperandInfo OpInfo = CGI.OperandList[OpNo]; // If this is a two-address instruction and we are not accessing the // 0th operand, remove an operand. - unsigned MIOp = CGI.OperandList[OpNo].MIOperandNo; + unsigned MIOp = OpInfo.MIOperandNo; if (CGI.isTwoAddress && MIOp != 0) { if (MIOp == 1) throw "Should refer to operand #0 instead of #1 for two-address" @@ -163,8 +165,8 @@ void AsmWriterInst::ParseAsmString(const CodeGenInstruction &CGI, --MIOp; } - Operands.push_back(AsmWriterOperand(CGI.OperandList[OpNo].PrinterMethodName, - MIOp, CGI.OperandList[OpNo].Ty)); + Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, + MIOp, OpInfo.Ty)); LastEmitted = VarEnd; } } @@ -193,17 +195,20 @@ void AsmWriterEmitter::run(std::ostream &O) { std::string Namespace = Target.inst_begin()->second.Namespace; + std::vector Instructions; + for (CodeGenTarget::inst_iterator I = Target.inst_begin(), E = Target.inst_end(); I != E; ++I) - if (!I->second.AsmString.empty()) { - O << " case " << Namespace << "::" << I->first << ": "; - - AsmWriterInst AWI; - AWI.ParseAsmString(I->second, Variant); - AWI.EmitCode(O); - O << " break;\n"; - } - + if (!I->second.AsmString.empty()) + Instructions.push_back(AsmWriterInst(I->second, Variant)); + + for (unsigned i = 0, e = Instructions.size(); i != e; ++i) { + O << " case " << Namespace << "::" + << Instructions[i].CGI->Name << ": "; + Instructions[i].EmitCode(O); + O << " break;\n"; + } + O << " }\n" " return true;\n" "}\n"; -- cgit v1.2.3