14
14
#define SWIFT_FRONTEND_FRONTENDOPTIONS_H
15
15
16
16
#include " swift/AST/Module.h"
17
+ #include " swift/Frontend/FrontendInputs.h"
17
18
#include " swift/Frontend/InputFile.h"
18
19
#include " llvm/ADT/Hashing.h"
19
20
@@ -26,142 +27,6 @@ namespace llvm {
26
27
27
28
namespace swift {
28
29
29
- // / Information about all the inputs to the frontend.
30
- class FrontendInputs {
31
- friend class ArgsToFrontendInputsConverter ;
32
-
33
- std::vector<InputFile> AllFiles;
34
- typedef llvm::StringMap<unsigned > InputFileMap;
35
- InputFileMap PrimaryInputs;
36
-
37
- public:
38
- FrontendInputs () = default ;
39
-
40
- FrontendInputs (const FrontendInputs &other) {
41
- for (InputFile input : other.getAllFiles ())
42
- addInput (input);
43
- }
44
-
45
- FrontendInputs &operator =(const FrontendInputs &other) {
46
- clearInputs ();
47
- for (InputFile input : other.getAllFiles ())
48
- addInput (input);
49
- return *this ;
50
- }
51
-
52
- // Readers:
53
-
54
- ArrayRef<InputFile> getAllFiles () const { return AllFiles; }
55
-
56
- std::vector<std::string> getInputFilenames () const {
57
- std::vector<std::string> filenames;
58
- for (auto &input : getAllFiles ()) {
59
- filenames.push_back (input.file ());
60
- }
61
- return filenames;
62
- }
63
-
64
- unsigned inputCount () const { return getAllFiles ().size (); }
65
-
66
- bool hasInputs () const { return !AllFiles.empty (); }
67
-
68
- bool hasSingleInput () const { return inputCount () == 1 ; }
69
-
70
- StringRef getFilenameOfFirstInput () const {
71
- assert (hasInputs ());
72
- const InputFile &inp = getAllFiles ()[0 ];
73
- StringRef f = inp.file ();
74
- assert (!f.empty ());
75
- return f;
76
- }
77
-
78
- bool isReadingFromStdin () const {
79
- return hasSingleInput () && getFilenameOfFirstInput () == " -" ;
80
- }
81
-
82
- // If we have exactly one input filename, and its extension is "bc" or "ll",
83
- // treat the input as LLVM_IR.
84
- bool shouldTreatAsLLVM () const ;
85
-
86
- // Primary input readers
87
-
88
- private:
89
- void assertMustNotBeMoreThanOnePrimaryInput () const {
90
- assert (primaryInputCount () < 2 &&
91
- " have not implemented >1 primary input yet" );
92
- }
93
- bool areAllNonPrimariesSIB () const ;
94
-
95
- public:
96
- unsigned primaryInputCount () const { return PrimaryInputs.size (); }
97
-
98
- // Primary count readers:
99
-
100
- bool hasUniquePrimaryInput () const { return primaryInputCount () == 1 ; }
101
-
102
- bool hasPrimaryInputs () const { return primaryInputCount () > 0 ; }
103
-
104
- bool isWholeModule () const { return !hasPrimaryInputs (); }
105
-
106
- // Count-dependend readers:
107
-
108
- // / Return the unique primary input, if one exists.
109
- const InputFile *getUniquePrimaryInput () const {
110
- assertMustNotBeMoreThanOnePrimaryInput ();
111
- const auto b = PrimaryInputs.begin ();
112
- return b == PrimaryInputs.end () ? nullptr : &AllFiles[b->second ];
113
- }
114
-
115
- const InputFile &getRequiredUniquePrimaryInput () const {
116
- if (const auto *input = getUniquePrimaryInput ())
117
- return *input;
118
- llvm_unreachable (" No primary when one is required" );
119
- }
120
-
121
- // / Return the name of the unique primary input, or an empty StrinRef if there
122
- // / isn't one.
123
- StringRef getNameOfUniquePrimaryInputFile () const {
124
- const auto *input = getUniquePrimaryInput ();
125
- return input == nullptr ? StringRef () : input->file ();
126
- }
127
-
128
- bool isFilePrimary (StringRef file) {
129
- auto iterator = PrimaryInputs.find (file);
130
- return iterator != PrimaryInputs.end () &&
131
- AllFiles[iterator->second ].isPrimary ();
132
- }
133
-
134
- unsigned numberOfPrimaryInputsEndingWith (const char *extension) const ;
135
-
136
- // Multi-facet readers
137
-
138
- bool shouldTreatAsSIL () const ;
139
-
140
- // / Return true for error
141
- bool verifyInputs (DiagnosticEngine &diags, bool treatAsSIL,
142
- bool isREPLRequested, bool isNoneRequested) const ;
143
-
144
- // Writers
145
-
146
- void addInputFile (StringRef file, llvm::MemoryBuffer *buffer = nullptr ) {
147
- addInput (InputFile (file, false , buffer));
148
- }
149
- void addPrimaryInputFile (StringRef file,
150
- llvm::MemoryBuffer *buffer = nullptr ) {
151
- addInput (InputFile (file, true , buffer));
152
- }
153
-
154
- void addInput (const InputFile &input) {
155
- if (!input.file ().empty () && input.isPrimary ())
156
- PrimaryInputs.insert (std::make_pair (input.file (), AllFiles.size ()));
157
- AllFiles.push_back (input);
158
- }
159
-
160
- void clearInputs () {
161
- AllFiles.clear ();
162
- PrimaryInputs.clear ();
163
- }
164
- };
165
30
166
31
// / Options for controlling the behavior of the frontend.
167
32
class FrontendOptions {
@@ -454,8 +319,6 @@ class FrontendOptions {
454
319
}
455
320
456
321
private:
457
- static const char *suffixForPrincipalOutputFileForAction (ActionType);
458
-
459
322
bool hasUnusedDependenciesFilePath () const ;
460
323
static bool canActionEmitDependencies (ActionType);
461
324
bool hasUnusedObjCHeaderOutputPath () const ;
@@ -467,9 +330,11 @@ class FrontendOptions {
467
330
bool hasUnusedModuleDocOutputPath () const ;
468
331
static bool canActionEmitModuleDoc (ActionType);
469
332
333
+ public:
470
334
static bool doesActionProduceOutput (ActionType);
471
335
static bool doesActionProduceTextualOutput (ActionType);
472
336
static bool needsProperModuleName (ActionType);
337
+ static const char *suffixForPrincipalOutputFileForAction (ActionType);
473
338
};
474
339
475
340
}
0 commit comments