llvm.org GIT mirror llvm / 8e7254c
Reapply 50867: A small refactoring (extract method) + some comment fixes. Fixed the build breakage, sorry for that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50895 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
2 changed file(s) with 70 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
1414 list properties = l;
1515 }
1616
17 // Special Tool instance - graph root.
17 // Special Tool instance - the root node of the compilation graph.
1818
1919 def root : Tool<[]>;
2020
4646
4747 // Possible edge properties
4848
49 // 'Atomic' properties.
4950 def switch_on;
5051 def parameter_equals;
5152 def element_in_list;
162162 std::string Help;
163163 unsigned Flags;
164164
165 // We need t provide a default constructor since
166 // StringMap can only store DefaultConstructible objects
165 // We need to provide a default constructor because
166 // StringMap can only store DefaultConstructible objects.
167167 GlobalOptionDescription() : OptionDescription(), Flags(0)
168168 {}
169169
221221 };
222222
223223
224 // Tool-local option description
225
226 // Properties without arguments are implemented as flags
224 // Tool-local option description.
225
226 // Properties without arguments are implemented as flags.
227227 namespace ToolOptionDescriptionFlags {
228228 enum ToolOptionDescriptionFlags { StopCompilation = 0x1,
229229 Forward = 0x2, UnpackValues = 0x4};
313313
314314
315315 /// CollectProperties - Function object for iterating over a list of
316 /// tool property records
316 /// tool property records.
317317 class CollectProperties {
318318 private:
319319
568568
569569
570570 /// CollectToolProperties - Gather information from the parsed
571 /// TableGen data (basically a wrapper for CollectProperties).
571 /// TableGen data (basically a wrapper for the CollectProperties
572 /// function object).
572573 void CollectToolProperties (RecordVector::const_iterator B,
573574 RecordVector::const_iterator E,
574575 ToolPropertiesList& TPList,
588589 }
589590 }
590591
591 /// EmitOptionPropertyHandlingCode - Used by EmitGenerateActionMethod.
592 /// EmitForwardOptionPropertyHandlingCode - Helper function used to
593 /// implement EmitOptionPropertyHandlingCode(). Emits code for
594 /// handling the (forward) option property.
595 void EmitForwardOptionPropertyHandlingCode (const ToolOptionDescription& D,
596 std::ostream& O) {
597 switch (D.Type) {
598 case OptionType::Switch:
599 O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n";
600 break;
601 case OptionType::Parameter:
602 O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n";
603 O << Indent3 << "vec.push_back(" << D.GenVariableName() << ");\n";
604 break;
605 case OptionType::Prefix:
606 O << Indent3 << "vec.push_back(\"-" << D.Name << "\" + "
607 << D.GenVariableName() << ");\n";
608 break;
609 case OptionType::PrefixList:
610 O << Indent3 << "for (" << D.GenTypeDeclaration()
611 << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
612 << Indent3 << "E = " << D.GenVariableName() << ".end(); B != E; ++B)\n"
613 << Indent4 << "vec.push_back(\"-" << D.Name << "\" + "
614 << "*B);\n";
615 break;
616 case OptionType::ParameterList:
617 O << Indent3 << "for (" << D.GenTypeDeclaration()
618 << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
619 << Indent3 << "E = " << D.GenVariableName()
620 << ".end() ; B != E; ++B) {\n"
621 << Indent4 << "vec.push_back(\"-" << D.Name << "\");\n"
622 << Indent4 << "vec.push_back(*B);\n"
623 << Indent3 << "}\n";
624 break;
625 }
626 }
627
628 /// EmitOptionPropertyHandlingCode - Helper function used by
629 /// EmitGenerateActionMethod(). Emits code that handles option
630 /// properties.
592631 void EmitOptionPropertyHandlingCode (const ToolProperties& P,
593632 const ToolOptionDescription& D,
594633 std::ostream& O)
595634 {
596 // if clause
635 // Start of the if-clause.
597636 O << Indent2 << "if (";
598637 if (D.Type == OptionType::Switch)
599638 O << D.GenVariableName();
602641
603642 O <<") {\n";
604643
605 // Handle option properties that take an argument
644 // Handle option properties that take an argument.
606645 for (OptionPropertyList::const_iterator B = D.Props.begin(),
607646 E = D.Props.end(); B!=E; ++B) {
608647 const OptionProperty& val = *B;
621660 // Handle flags
622661
623662 // (forward) property
624 if (D.isForward()) {
625 switch (D.Type) {
626 case OptionType::Switch:
627 O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n";
628 break;
629 case OptionType::Parameter:
630 O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n";
631 O << Indent3 << "vec.push_back(" << D.GenVariableName() << ");\n";
632 break;
633 case OptionType::Prefix:
634 O << Indent3 << "vec.push_back(\"-" << D.Name << "\" + "
635 << D.GenVariableName() << ");\n";
636 break;
637 case OptionType::PrefixList:
638 O << Indent3 << "for (" << D.GenTypeDeclaration()
639 << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
640 << Indent3 << "E = " << D.GenVariableName() << ".end(); B != E; ++B)\n"
641 << Indent4 << "vec.push_back(\"-" << D.Name << "\" + "
642 << "*B);\n";
643 break;
644 case OptionType::ParameterList:
645 O << Indent3 << "for (" << D.GenTypeDeclaration()
646 << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
647 << Indent3 << "E = " << D.GenVariableName()
648 << ".end() ; B != E; ++B) {\n"
649 << Indent4 << "vec.push_back(\"-" << D.Name << "\");\n"
650 << Indent4 << "vec.push_back(*B);\n"
651 << Indent3 << "}\n";
652 break;
653 }
654 }
663 if (D.isForward())
664 EmitForwardOptionPropertyHandlingCode(D, O);
655665
656666 // (unpack_values) property
657667 if (D.isUnpackValues()) {
672682 }
673683 }
674684
675 // close if clause
685 // End of the if-clause.
676686 O << Indent2 << "}\n";
677687 }
678688
679 // EmitGenerateActionMethod - Emit one of two versions of
680 // GenerateAction method.
681 void EmitGenerateActionMethod (const ToolProperties& P, int V, std::ostream& O)
689 // EmitGenerateActionMethod - Emit one of two versions of the
690 // Tool::GenerateAction() method.
691 void EmitGenerateActionMethod (const ToolProperties& P, bool V, std::ostream& O)
682692 {
683 assert(V==1 || V==2);
684 if (V==1)
693 if (V)
685694 O << Indent1 << "Action GenerateAction(const PathVector& inFiles,\n";
686695 else
687696 O << Indent1 << "Action GenerateAction(const sys::Path& inFile,\n";
700709 const std::string& cmd = *I;
701710 O << Indent2;
702711 if (cmd == "$INFILE") {
703 if (V==1)
712 if (V)
704713 O << "for (PathVector::const_iterator B = inFiles.begin()"
705714 << ", E = inFiles.end();\n"
706715 << Indent2 << "B != E; ++B)\n"
716725 }
717726 }
718727
719 // For every understood option, emit handling code
728 // For every understood option, emit handling code.
720729 for (ToolOptionDescriptions::const_iterator B = P.OptDescs.begin(),
721730 E = P.OptDescs.end(); B != E; ++B) {
722731 const ToolOptionDescription& val = B->second;
723732 EmitOptionPropertyHandlingCode(P, val, O);
724733 }
725734
726 // Handle Sink property
735 // Handle the Sink property.
727736 if (P.isSink()) {
728737 O << Indent2 << "if (!" << SinkOptionName << ".empty()) {\n"
729738 << Indent3 << "vec.insert(vec.end(), "
735744 << Indent1 << "}\n\n";
736745 }
737746
738 /// EmitGenerateActionMethods - Emit two GenerateAction methods for a given
739 /// Tool class.
747 /// EmitGenerateActionMethods - Emit two GenerateAction() methods for
748 /// a given Tool class.
740749 void EmitGenerateActionMethods (const ToolProperties& P, std::ostream& O) {
741750
742751 if (!P.isJoin())
747756 << " is not a Join tool!\");\n"
748757 << Indent1 << "}\n\n";
749758 else
750 EmitGenerateActionMethod(P, 1, O);
751
752 EmitGenerateActionMethod(P, 2, O);
753 }
754
755 /// EmitIsLastMethod - Emit IsLast() method for a given Tool class
759 EmitGenerateActionMethod(P, true, O);
760
761 EmitGenerateActionMethod(P, false, O);
762 }
763
764 /// EmitIsLastMethod - Emit the IsLast() method for a given Tool
765 /// class.
756766 void EmitIsLastMethod (const ToolProperties& P, std::ostream& O) {
757767 O << Indent1 << "bool IsLast() const {\n"
758768 << Indent2 << "bool last = false;\n";