Skip to content

Commit 83aeb39

Browse files
committed
[BatchMode] Add CommandOutput::addOutputs and hasSameAdditionalOutputTypes.
1 parent 6132f18 commit 83aeb39

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

include/swift/Driver/Job.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ class CommandOutput {
147147
/// with the provided \p Input pair of Base and Primary inputs.
148148
void addPrimaryOutput(CommandInputPair Input, StringRef PrimaryOutputFile);
149149

150+
/// Return true iff the set of additional output types in \c this is
151+
/// identical to the set of additional output types in \p other.
152+
bool hasSameAdditionalOutputTypes(CommandOutput const &other) const;
153+
154+
/// Copy all the input pairs from \p other to \c this. Assumes (and asserts)
155+
/// that \p other shares output file map and PrimaryOutputType with \c this
156+
/// already, as well as AdditionalOutputTypes if \c this has any.
157+
void addOutputs(CommandOutput const &other);
158+
150159
/// Assuming (and asserting) that there is only one input pair, return the
151160
/// primary output file associated with it. Note that the returned StringRef
152161
/// may be invalidated by subsequent mutations to the \c CommandOutput.

lib/Driver/Job.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@ void CommandOutput::ensureEntry(StringRef PrimaryInputFile,
5252
}
5353
}
5454

55+
bool CommandOutput::hasSameAdditionalOutputTypes(
56+
CommandOutput const &other) const {
57+
bool sameAdditionalOutputTypes = true;
58+
types::forAllTypes([&](types::ID Type) {
59+
bool a = AdditionalOutputTypes.count(Type) == 0;
60+
bool b = other.AdditionalOutputTypes.count(Type) == 0;
61+
if (a != b)
62+
sameAdditionalOutputTypes = false;
63+
});
64+
return sameAdditionalOutputTypes;
65+
}
66+
67+
void CommandOutput::addOutputs(CommandOutput const &other) {
68+
assert(PrimaryOutputType == other.PrimaryOutputType);
69+
assert(&DerivedOutputMap == &other.DerivedOutputMap);
70+
Inputs.append(other.Inputs.begin(),
71+
other.Inputs.end());
72+
// Should only be called with an empty AdditionalOutputTypes
73+
// or one populated with the same types as other.
74+
if (AdditionalOutputTypes.empty()) {
75+
AdditionalOutputTypes = other.AdditionalOutputTypes;
76+
} else {
77+
assert(hasSameAdditionalOutputTypes(other));
78+
}
79+
}
80+
5581
CommandOutput::CommandOutput(types::ID PrimaryOutputType,
5682
OutputFileMap &Derived)
5783
: PrimaryOutputType(PrimaryOutputType), DerivedOutputMap(Derived) {}

0 commit comments

Comments
 (0)