diff options
| author | Mikhail Glushenkov <foldr@codedgers.com> | 2010-07-19 17:17:22 +0000 |
|---|---|---|
| committer | Mikhail Glushenkov <foldr@codedgers.com> | 2010-07-19 17:17:22 +0000 |
| commit | 1432699cb23962c97cc7063124d2dac42e23fc4a (patch) | |
| tree | d5b326f6af29cc9371704a199c802fef281b8203 /llvm/utils/TableGen | |
| parent | 4fc84a0dcdc8ea921adfdb0c648b26d80e2fea10 (diff) | |
| download | bcm5719-llvm-1432699cb23962c97cc7063124d2dac42e23fc4a.tar.gz bcm5719-llvm-1432699cb23962c97cc7063124d2dac42e23fc4a.zip | |
Remove code duplication.
llvm-svn: 108718
Diffstat (limited to 'llvm/utils/TableGen')
| -rw-r--r-- | llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp b/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp index 5392d5e1aa0..4a16930effe 100644 --- a/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -1853,6 +1853,24 @@ void EmitCmdLineVecFill(const Init* CmdLine, const std::string& ToolName, } +/// EmitForEachListElementCycleHeader - Emit common code for iterating through +/// all elements of a list. Helper function used by +/// EmitForwardOptionPropertyHandlingCode. +void EmitForEachListElementCycleHeader (const OptionDescription& D, + unsigned IndentLevel, + raw_ostream& O) { + unsigned IndentLevel1 = IndentLevel + Indent1; + + O.indent(IndentLevel) + << "for (" << D.GenTypeDeclaration() + << "::iterator B = " << D.GenVariableName() << ".begin(),\n"; + O.indent(IndentLevel) + << "E = " << D.GenVariableName() << ".end(); B != E;) {\n"; + O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName() + << ".getPosition(B - " << D.GenVariableName() + << ".begin());\n"; +} + /// EmitForwardOptionPropertyHandlingCode - Helper function used to /// implement EmitActionHandler. Emits code for /// handling the (forward) and (forward_as) option properties. @@ -1893,16 +1911,7 @@ void EmitForwardOptionPropertyHandlingCode (const OptionDescription& D, << D.GenVariableName() << "));\n"; break; case OptionType::PrefixList: - // TODO: remove duplication across PrefixList / ParameterList / SwitchList - // branches - O.indent(IndentLevel) - << "for (" << D.GenTypeDeclaration() - << "::iterator B = " << D.GenVariableName() << ".begin(),\n"; - O.indent(IndentLevel) - << "E = " << D.GenVariableName() << ".end(); B != E;) {\n"; - O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName() - << ".getPosition(B - " << D.GenVariableName() - << ".begin());\n"; + EmitForEachListElementCycleHeader(D, IndentLevel, O); O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, \"" << Name << "\" + " << "*B));\n"; O.indent(IndentLevel1) << "++B;\n"; @@ -1915,14 +1924,7 @@ void EmitForwardOptionPropertyHandlingCode (const OptionDescription& D, O.indent(IndentLevel) << "}\n"; break; case OptionType::ParameterList: - O.indent(IndentLevel) - << "for (" << D.GenTypeDeclaration() << "::iterator B = " - << D.GenVariableName() << ".begin(),\n"; - O.indent(IndentLevel) << "E = " << D.GenVariableName() - << ".end() ; B != E;) {\n"; - O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName() - << ".getPosition(B - " << D.GenVariableName() - << ".begin());\n"; + EmitForEachListElementCycleHeader(D, IndentLevel, O); O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, \"" << Name << "\"));\n"; @@ -1934,14 +1936,7 @@ void EmitForwardOptionPropertyHandlingCode (const OptionDescription& D, O.indent(IndentLevel) << "}\n"; break; case OptionType::SwitchList: - O.indent(IndentLevel) - << "for (" << D.GenTypeDeclaration() << "::iterator B = " - << D.GenVariableName() << ".begin(),\n"; - O.indent(IndentLevel) << "E = " << D.GenVariableName() - << ".end() ; B != E;) {\n"; - O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName() - << ".getPosition(B - " << D.GenVariableName() - << ".begin());\n"; + EmitForEachListElementCycleHeader(D, IndentLevel, O); O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, \"" << Name << "\"));\n"; O.indent(IndentLevel1) << "++B;\n"; |

