return val.getValue();
}
+bool InitPtrToBool(const Init* ptr) {
+ bool ret = false;
+ const DefInit& val = dynamic_cast<const DefInit&>(*ptr);
+ const std::string& str = val.getAsString();
+
+ if (str == "true") {
+ ret = true;
+ }
+ else if (str == "false") {
+ ret = false;
+ }
+ else {
+ throw "Incorrect boolean value: '" + str +
+ "': must be either 'true' or 'false'";
+ }
+
+ return ret;
+}
+
const std::string& InitPtrToString(const Init* ptr) {
const StringInit& val = dynamic_cast<const StringInit&>(*ptr);
return val.getValue();
/// CheckBooleanConstant - Check that the provided value is a boolean constant.
void CheckBooleanConstant(const Init* I) {
- const DefInit& val = dynamic_cast<const DefInit&>(*I);
- const std::string& str = val.getAsString();
-
- if (str != "true" && str != "false") {
- throw "Incorrect boolean value: '" + str +
- "': must be either 'true' or 'false'";
- }
+ InitPtrToBool(I);
}
// CheckNumberOfArguments - Ensure that the number of args in d is
CheckNumberOfArguments(d, 2);
+ // Alias option store the aliased option name in the 'Help' field and do not
+ // have any properties.
if (OD.isAlias()) {
- // Aliases store the aliased option name in the 'Help' field.
OD.Help = InitPtrToString(d.getArg(1));
}
else {
processOptionProperties(d, OD);
}
+ // Switch options are ZeroOrMore by default.
+ if (OD.isSwitch()) {
+ if (!(OD.isOptional() || OD.isOneOrMore() || OD.isRequired()))
+ OD.setZeroOrMore();
+ }
+
OptDescs_.InsertDescription(OD);
}
}
void onJoin (const DagInit& d) {
- CheckNumberOfArguments(d, 0);
- toolDesc_.setJoin();
+ bool isReallyJoin = false;
+
+ if (d.getNumArgs() == 0) {
+ isReallyJoin = true;
+ }
+ else {
+ Init* I = d.getArg(0);
+ isReallyJoin = InitPtrToBool(I);
+ }
+
+ // Is this *really* a join tool? We allow (join false) for generating two
+ // tool descriptions from a single generic one.
+ // TOFIX: come up with a cleaner solution.
+ if (isReallyJoin) {
+ toolDesc_.setJoin();
+ }
}
void onOutLanguage (const DagInit& d) {
FilterNotInGraph(Data.Edges, Data.ToolDescs);
// Typecheck the compilation graph.
+ // TODO: use a genuine graph representation instead of a vector and check for
+ // multiple edges.
TypecheckGraph(Data.Edges, Data.ToolDescs);
// Check that there are no options without side effects (specified
CheckForSuperfluousOptions(Data.Edges, Data.ToolDescs, Data.OptDescs);
}
-void EmitDriverCode(const DriverData& Data, raw_ostream& O) {
+void EmitDriverCode(const DriverData& Data,
+ raw_ostream& O, RecordKeeper &Records) {
// Emit file header.
EmitIncludes(O);
CheckDriverData(Data);
this->EmitSourceFileHeader("llvmc-based driver: auto-generated code", O);
- EmitDriverCode(Data, O);
+ EmitDriverCode(Data, O, Records);
} catch (std::exception& Error) {
throw Error.what() + std::string(" - usually this means a syntax error.");