llvm.org GIT mirror llvm / 581936a
Implemented switch_on edge property. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50729 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
2 changed file(s) with 55 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3737 def opt : Tool<
3838 [(in_language "llvm-bitcode"),
3939 (out_language "llvm-bitcode"),
40 (switch_option "opt", (help "Enable opt")),
4041 (output_suffix "bc"),
4142 (cmd_line "opt $INFILE -o $OUTFILE")
4243 ]>;
5656 StringInit& val = dynamic_cast(*ptr);
5757 return val.getValue();
5858 }
59
60 // Ensure that the number of args in d is <= min_arguments,
61 // throw exception otherwise
62 void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
63 if (d->getNumArgs() < min_arguments)
64 throw "Property " + d->getOperator()->getAsString()
65 + " has too few arguments!";
66 }
67
5968
6069 //===----------------------------------------------------------------------===//
6170 /// Back-end specific code
185194 container_type Descriptions;
186195 // Should the emitter generate a "cl::sink" option?
187196 bool HasSink;
197
198 const GlobalOptionDescription& FindOption(const std::string& OptName) const {
199 const_iterator I = Descriptions.find(OptName);
200 if (I != Descriptions.end())
201 return I->second;
202 else
203 throw OptName + ": no such option!";
204 }
188205
189206 // Support for STL-style iteration
190207 const_iterator begin() const { return Descriptions.begin(); }
357374 // Just forwards to the corresponding property handler.
358375 void operator() (Init* i) {
359376 DagInit& d = dynamic_cast(*i);
360 std::string property_name = d.getOperator()->getAsString();
377 const std::string& property_name = d.getOperator()->getAsString();
361378 PropertyHandlerMap::iterator method
362379 = propertyHandlers_.find(property_name);
363380
467484 toolProps_.OptDescs[name].Name = name;
468485 processOptionProperties(d, o);
469486 insertDescription(o);
470 }
471
472 // Ensure that the number of args in d is <= min_arguments,
473 // throw exception otherwise
474 void checkNumberOfArguments (DagInit* d, unsigned min_arguments) {
475 if (d->getNumArgs() < min_arguments)
476 throw "Property " + d->getOperator()->getAsString()
477 + " has too few arguments!";
478487 }
479488
480489 // Insert new GlobalOptionDescription into GlobalOptionDescriptions list
896905 }
897906
898907 // Emit Edge* classes that represent edges in the graph.
899 // TOFIX: add edge properties.
900908 void EmitEdgeClasses (Record* CompilationGraph,
901909 const GlobalOptionDescriptions& OptDescs,
902910 std::ostream& O) {
913921 O << "class Edge" << i << ": public Edge {\n"
914922 << "public:\n"
915923 << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
916 << "\") {}\n";
917
918 O << Indent1 << "bool isEnabled() const { return true; }\n";
919
920 O << Indent1 << "bool isDefault() const { return false; }\n";
921
922 O << "};\n\n";
924 << "\") {}\n\n"
925 << Indent1 << "bool isEnabled() const {\n";
926
927 for (unsigned i = 0; i < Props->size(); ++i) {
928 const DagInit& Prop = dynamic_cast(*Props->getElement(i));
929 const std::string& PropName = Prop.getOperator()->getAsString();
930
931 if (PropName == "switch_on") {
932 checkNumberOfArguments(&Prop, 1);
933 const std::string& OptName = InitPtrToString(Prop.getArg(0));
934 const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
935 if (OptDesc.Type != OptionType::Switch)
936 throw OptName + ": incorrect option type!";
937 O << Indent2 << "if (" << OptDesc.GenVariableName() << ")\n"
938 << Indent3 << "return true;\n";
939 }
940 else if (PropName == "parameter_equals") {
941 checkNumberOfArguments(&Prop, 2);
942 throw PropName + ": not implemented!";
943 }
944 else if (PropName == "element_in_list") {
945 checkNumberOfArguments(&Prop, 2);
946 throw PropName + ": not implemented!";
947 }
948 else if (PropName == "or") {
949 throw PropName + ": not implemented!";
950 }
951 else {
952 throw "No such edge property: " + PropName;
953 }
954 }
955
956 O << Indent2 << "return false;\n"
957 << Indent1 << "};\n\n"
958 << Indent1 << "bool isDefault() const { return false; }\n"
959 << "};\n\n";
923960 }
924961 }
925962