John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1 | //===-- arcmt-test.cpp - ARC Migration Tool testbed -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/ARCMigrate/ARCMT.h" |
| 11 | #include "clang/Frontend/ASTUnit.h" |
| 12 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 13 | #include "clang/Frontend/VerifyDiagnosticConsumer.h" |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/Utils.h" |
| 15 | #include "clang/Lex/Preprocessor.h" |
| 16 | #include "llvm/Support/MemoryBuffer.h" |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 17 | #include "llvm/Support/FileSystem.h" |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Signals.h" |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 19 | #include "llvm/Support/system_error.h" |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace clang; |
| 22 | using namespace arcmt; |
| 23 | |
| 24 | static llvm::cl::opt<bool> |
| 25 | CheckOnly("check-only", |
| 26 | llvm::cl::desc("Just check for issues that need to be handled manually")); |
| 27 | |
| 28 | //static llvm::cl::opt<bool> |
| 29 | //TestResultForARC("test-result", |
| 30 | //llvm::cl::desc("Test the result of transformations by parsing it in ARC mode")); |
| 31 | |
| 32 | static llvm::cl::opt<bool> |
| 33 | OutputTransformations("output-transformations", |
| 34 | llvm::cl::desc("Print the source transformations")); |
| 35 | |
| 36 | static llvm::cl::opt<bool> |
| 37 | VerifyDiags("verify",llvm::cl::desc("Verify emitted diagnostics and warnings")); |
| 38 | |
| 39 | static llvm::cl::opt<bool> |
| 40 | VerboseOpt("v", llvm::cl::desc("Enable verbose output")); |
| 41 | |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 42 | static llvm::cl::opt<bool> |
| 43 | VerifyTransformedFiles("verify-transformed-files", |
| 44 | llvm::cl::desc("Read pairs of file mappings (typically the output of " |
| 45 | "c-arcmt-test) and compare their contents with the filenames " |
| 46 | "provided in command-line")); |
| 47 | |
| 48 | static llvm::cl::opt<std::string> |
| 49 | RemappingsFile("remappings-file", |
| 50 | llvm::cl::desc("Pairs of file mappings (typically the output of " |
| 51 | "c-arcmt-test)")); |
| 52 | |
| 53 | static llvm::cl::list<std::string> |
| 54 | ResultFiles(llvm::cl::Positional, llvm::cl::desc("<filename>...")); |
| 55 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 56 | static llvm::cl::extrahelp extraHelp( |
| 57 | "\nusage with compiler args: arcmt-test [options] --args [compiler flags]\n"); |
| 58 | |
| 59 | // This function isn't referenced outside its translation unit, but it |
| 60 | // can't use the "static" keyword because its address is used for |
| 61 | // GetMainExecutable (since some platforms don't support taking the |
| 62 | // address of main, and some platforms can't implement GetMainExecutable |
| 63 | // without being given the address of a function in the main executable). |
| 64 | llvm::sys::Path GetExecutablePath(const char *Argv0) { |
| 65 | // This just needs to be some symbol in the binary; C++ doesn't |
| 66 | // allow taking the address of ::main however. |
| 67 | void *MainAddr = (void*) (intptr_t) GetExecutablePath; |
| 68 | return llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); |
| 69 | } |
| 70 | |
| 71 | static void printSourceLocation(SourceLocation loc, ASTContext &Ctx, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 72 | raw_ostream &OS); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 73 | static void printSourceRange(CharSourceRange range, ASTContext &Ctx, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 74 | raw_ostream &OS); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 75 | |
| 76 | namespace { |
| 77 | |
| 78 | class PrintTransforms : public MigrationProcess::RewriteListener { |
| 79 | ASTContext *Ctx; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 80 | raw_ostream &OS; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 81 | |
| 82 | public: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 83 | PrintTransforms(raw_ostream &OS) |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 84 | : Ctx(0), OS(OS) { } |
| 85 | |
| 86 | virtual void start(ASTContext &ctx) { Ctx = &ctx; } |
| 87 | virtual void finish() { Ctx = 0; } |
| 88 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 89 | virtual void insert(SourceLocation loc, StringRef text) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 90 | assert(Ctx); |
| 91 | OS << "Insert: "; |
| 92 | printSourceLocation(loc, *Ctx, OS); |
| 93 | OS << " \"" << text << "\"\n"; |
| 94 | } |
| 95 | |
| 96 | virtual void remove(CharSourceRange range) { |
| 97 | assert(Ctx); |
| 98 | OS << "Remove: "; |
| 99 | printSourceRange(range, *Ctx, OS); |
| 100 | OS << '\n'; |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | } // anonymous namespace |
| 105 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 106 | static bool checkForMigration(StringRef resourcesPath, |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 107 | ArrayRef<const char *> Args) { |
David Blaikie | 78ad0b9 | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 108 | DiagnosticConsumer *DiagClient = |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 109 | new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions()); |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 110 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 111 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 112 | new DiagnosticsEngine(DiagID, DiagClient)); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 113 | // Chain in -verify checker, if requested. |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 114 | VerifyDiagnosticConsumer *verifyDiag = 0; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 115 | if (VerifyDiags) { |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 116 | verifyDiag = new VerifyDiagnosticConsumer(*Diags); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 117 | Diags->setClient(verifyDiag); |
| 118 | } |
| 119 | |
Argyrios Kyrtzidis | eaed19e | 2011-06-16 00:53:46 +0000 | [diff] [blame] | 120 | CompilerInvocation CI; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 121 | if (!CompilerInvocation::CreateFromArgs(CI, Args.begin(), Args.end(), *Diags)) |
| 122 | return true; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 123 | |
Argyrios Kyrtzidis | eaed19e | 2011-06-16 00:53:46 +0000 | [diff] [blame] | 124 | if (CI.getFrontendOpts().Inputs.empty()) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 125 | llvm::errs() << "error: no input files\n"; |
| 126 | return true; |
| 127 | } |
| 128 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 129 | if (!CI.getLangOpts()->ObjC1) |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 130 | return false; |
| 131 | |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 132 | arcmt::checkForManualIssues(CI, CI.getFrontendOpts().Inputs[0], |
Argyrios Kyrtzidis | e665d69 | 2011-06-18 00:53:41 +0000 | [diff] [blame] | 133 | Diags->getClient()); |
| 134 | return Diags->getClient()->getNumErrors() > 0; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 137 | static void printResult(FileRemapper &remapper, raw_ostream &OS) { |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 138 | PreprocessorOptions PPOpts; |
| 139 | remapper.applyMappings(PPOpts); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 140 | // The changed files will be in memory buffers, print them. |
| 141 | for (unsigned i = 0, e = PPOpts.RemappedFileBuffers.size(); i != e; ++i) { |
| 142 | const llvm::MemoryBuffer *mem = PPOpts.RemappedFileBuffers[i].second; |
| 143 | OS << mem->getBuffer(); |
| 144 | } |
| 145 | } |
| 146 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 147 | static bool performTransformations(StringRef resourcesPath, |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 148 | ArrayRef<const char *> Args) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 149 | // Check first. |
| 150 | if (checkForMigration(resourcesPath, Args)) |
| 151 | return true; |
| 152 | |
David Blaikie | 78ad0b9 | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 153 | DiagnosticConsumer *DiagClient = |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 154 | new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions()); |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 155 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 156 | IntrusiveRefCntPtr<DiagnosticsEngine> TopDiags( |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 157 | new DiagnosticsEngine(DiagID, DiagClient)); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 158 | |
Argyrios Kyrtzidis | eaed19e | 2011-06-16 00:53:46 +0000 | [diff] [blame] | 159 | CompilerInvocation origCI; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 160 | if (!CompilerInvocation::CreateFromArgs(origCI, Args.begin(), Args.end(), |
| 161 | *TopDiags)) |
| 162 | return true; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 163 | |
Argyrios Kyrtzidis | eaed19e | 2011-06-16 00:53:46 +0000 | [diff] [blame] | 164 | if (origCI.getFrontendOpts().Inputs.empty()) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 165 | llvm::errs() << "error: no input files\n"; |
| 166 | return true; |
| 167 | } |
| 168 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 169 | if (!origCI.getLangOpts()->ObjC1) |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 170 | return false; |
| 171 | |
Argyrios Kyrtzidis | eaed19e | 2011-06-16 00:53:46 +0000 | [diff] [blame] | 172 | MigrationProcess migration(origCI, DiagClient); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 173 | |
Argyrios Kyrtzidis | e0ac745 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 174 | std::vector<TransformFn> |
Fariborz Jahanian | bbdfad5 | 2012-01-26 20:57:58 +0000 | [diff] [blame] | 175 | transforms = arcmt::getAllTransformations(origCI.getLangOpts()->getGC(), |
| 176 | origCI.getMigratorOpts().NoFinalizeRemoval); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 177 | assert(!transforms.empty()); |
| 178 | |
Dylan Noblesmith | 1e4c01b | 2012-02-13 12:32:21 +0000 | [diff] [blame] | 179 | OwningPtr<PrintTransforms> transformPrinter; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 180 | if (OutputTransformations) |
| 181 | transformPrinter.reset(new PrintTransforms(llvm::outs())); |
| 182 | |
| 183 | for (unsigned i=0, e = transforms.size(); i != e; ++i) { |
| 184 | bool err = migration.applyTransform(transforms[i], transformPrinter.get()); |
| 185 | if (err) return true; |
| 186 | |
| 187 | if (VerboseOpt) { |
| 188 | if (i == e-1) |
| 189 | llvm::errs() << "\n##### FINAL RESULT #####\n"; |
| 190 | else |
| 191 | llvm::errs() << "\n##### OUTPUT AFTER "<< i+1 <<". TRANSFORMATION #####\n"; |
| 192 | printResult(migration.getRemapper(), llvm::errs()); |
| 193 | llvm::errs() << "\n##########################\n\n"; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if (!OutputTransformations) |
| 198 | printResult(migration.getRemapper(), llvm::outs()); |
| 199 | |
| 200 | // FIXME: TestResultForARC |
| 201 | |
| 202 | return false; |
| 203 | } |
| 204 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 205 | static bool filesCompareEqual(StringRef fname1, StringRef fname2) { |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 206 | using namespace llvm; |
| 207 | |
| 208 | OwningPtr<MemoryBuffer> file1; |
| 209 | MemoryBuffer::getFile(fname1, file1); |
| 210 | if (!file1) |
| 211 | return false; |
| 212 | |
| 213 | OwningPtr<MemoryBuffer> file2; |
| 214 | MemoryBuffer::getFile(fname2, file2); |
| 215 | if (!file2) |
| 216 | return false; |
| 217 | |
| 218 | return file1->getBuffer() == file2->getBuffer(); |
| 219 | } |
| 220 | |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 221 | static bool verifyTransformedFiles(ArrayRef<std::string> resultFiles) { |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 222 | using namespace llvm; |
| 223 | |
| 224 | assert(!resultFiles.empty()); |
| 225 | |
| 226 | std::map<StringRef, StringRef> resultMap; |
| 227 | |
| 228 | for (ArrayRef<std::string>::iterator |
| 229 | I = resultFiles.begin(), E = resultFiles.end(); I != E; ++I) { |
| 230 | StringRef fname(*I); |
| 231 | if (!fname.endswith(".result")) { |
| 232 | errs() << "error: filename '" << fname |
| 233 | << "' does not have '.result' extension\n"; |
| 234 | return true; |
| 235 | } |
| 236 | resultMap[sys::path::stem(fname)] = fname; |
| 237 | } |
| 238 | |
| 239 | OwningPtr<MemoryBuffer> inputBuf; |
| 240 | if (RemappingsFile.empty()) |
| 241 | MemoryBuffer::getSTDIN(inputBuf); |
| 242 | else |
| 243 | MemoryBuffer::getFile(RemappingsFile, inputBuf); |
| 244 | if (!inputBuf) { |
| 245 | errs() << "error: could not read remappings input\n"; |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | SmallVector<StringRef, 8> strs; |
| 250 | inputBuf->getBuffer().split(strs, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 251 | |
| 252 | if (strs.empty()) { |
| 253 | errs() << "error: no files to verify from stdin\n"; |
| 254 | return true; |
| 255 | } |
| 256 | if (strs.size() % 2 != 0) { |
| 257 | errs() << "error: files to verify are not original/result pairs\n"; |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | for (unsigned i = 0, e = strs.size(); i != e; i += 2) { |
| 262 | StringRef inputOrigFname = strs[i]; |
| 263 | StringRef inputResultFname = strs[i+1]; |
| 264 | |
| 265 | std::map<StringRef, StringRef>::iterator It; |
| 266 | It = resultMap.find(sys::path::filename(inputOrigFname)); |
| 267 | if (It == resultMap.end()) { |
| 268 | errs() << "error: '" << inputOrigFname << "' is not in the list of " |
| 269 | << "transformed files to verify\n"; |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | bool exists = false; |
| 274 | sys::fs::exists(It->second, exists); |
| 275 | if (!exists) { |
| 276 | errs() << "error: '" << It->second << "' does not exist\n"; |
| 277 | return true; |
| 278 | } |
| 279 | sys::fs::exists(inputResultFname, exists); |
| 280 | if (!exists) { |
| 281 | errs() << "error: '" << inputResultFname << "' does not exist\n"; |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | if (!filesCompareEqual(It->second, inputResultFname)) { |
| 286 | errs() << "error: '" << It->second << "' is different than " |
| 287 | << "'" << inputResultFname << "'\n"; |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | resultMap.erase(It); |
| 292 | } |
| 293 | |
| 294 | if (!resultMap.empty()) { |
| 295 | for (std::map<StringRef, StringRef>::iterator |
| 296 | I = resultMap.begin(), E = resultMap.end(); I != E; ++I) |
| 297 | errs() << "error: '" << I->second << "' was not verified!\n"; |
| 298 | return true; |
| 299 | } |
| 300 | |
| 301 | return false; |
| 302 | } |
| 303 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 304 | //===----------------------------------------------------------------------===// |
| 305 | // Misc. functions. |
| 306 | //===----------------------------------------------------------------------===// |
| 307 | |
| 308 | static void printSourceLocation(SourceLocation loc, ASTContext &Ctx, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 309 | raw_ostream &OS) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 310 | SourceManager &SM = Ctx.getSourceManager(); |
| 311 | PresumedLoc PL = SM.getPresumedLoc(loc); |
| 312 | |
| 313 | OS << llvm::sys::path::filename(PL.getFilename()); |
| 314 | OS << ":" << PL.getLine() << ":" |
| 315 | << PL.getColumn(); |
| 316 | } |
| 317 | |
| 318 | static void printSourceRange(CharSourceRange range, ASTContext &Ctx, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 319 | raw_ostream &OS) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 320 | SourceManager &SM = Ctx.getSourceManager(); |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 321 | const LangOptions &langOpts = Ctx.getLangOpts(); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 322 | |
| 323 | PresumedLoc PL = SM.getPresumedLoc(range.getBegin()); |
| 324 | |
| 325 | OS << llvm::sys::path::filename(PL.getFilename()); |
| 326 | OS << " [" << PL.getLine() << ":" |
| 327 | << PL.getColumn(); |
| 328 | OS << " - "; |
| 329 | |
| 330 | SourceLocation end = range.getEnd(); |
| 331 | PL = SM.getPresumedLoc(end); |
| 332 | |
| 333 | unsigned endCol = PL.getColumn() - 1; |
| 334 | if (!range.isTokenRange()) |
| 335 | endCol += Lexer::MeasureTokenLength(end, SM, langOpts); |
| 336 | OS << PL.getLine() << ":" << endCol << "]"; |
| 337 | } |
| 338 | |
| 339 | //===----------------------------------------------------------------------===// |
| 340 | // Command line processing. |
| 341 | //===----------------------------------------------------------------------===// |
| 342 | |
| 343 | int main(int argc, const char **argv) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 344 | void *MainAddr = (void*) (intptr_t) GetExecutablePath; |
| 345 | llvm::sys::PrintStackTraceOnErrorSignal(); |
| 346 | |
| 347 | std::string |
| 348 | resourcesPath = CompilerInvocation::GetResourcesPath(argv[0], MainAddr); |
| 349 | |
| 350 | int optargc = 0; |
| 351 | for (; optargc != argc; ++optargc) { |
| 352 | if (StringRef(argv[optargc]) == "--args") |
| 353 | break; |
| 354 | } |
David Blaikie | 6bd17d2 | 2012-02-07 19:36:38 +0000 | [diff] [blame] | 355 | llvm::cl::ParseCommandLineOptions(optargc, argv, "arcmt-test"); |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 356 | |
| 357 | if (VerifyTransformedFiles) { |
| 358 | if (ResultFiles.empty()) { |
| 359 | llvm::cl::PrintHelpMessage(); |
| 360 | return 1; |
| 361 | } |
| 362 | return verifyTransformedFiles(ResultFiles); |
| 363 | } |
| 364 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 365 | if (optargc == argc) { |
| 366 | llvm::cl::PrintHelpMessage(); |
| 367 | return 1; |
| 368 | } |
| 369 | |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 370 | ArrayRef<const char*> Args(argv+optargc+1, argc-optargc-1); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 371 | |
| 372 | if (CheckOnly) |
| 373 | return checkForMigration(resourcesPath, Args); |
| 374 | |
| 375 | return performTransformations(resourcesPath, Args); |
| 376 | } |