Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 1 | //===-- Artifact.h --------------------------------------------------------===// |
| 2 | // |
Than McIntosh | c84d402 | 2018-06-20 08:50:57 -0400 | [diff] [blame] | 3 | // Copyright 2018 The Go Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Defines the Artifact class (helper for driver functionality). |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef GOLLVM_DRIVER_ARTIFACT_H |
| 14 | #define GOLLVM_DRIVER_ARTIFACT_H |
| 15 | |
| 16 | #include "llvm/ADT/SmallVector.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace opt { |
| 20 | class Arg; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | namespace gollvm { |
| 25 | namespace driver { |
| 26 | |
| 27 | // An artifact is a file produced or consumed by some compilation step. |
| 28 | // Artifacts may correspond to user-specified files (command line arg |
| 29 | // for example) or temporary files created by some intermediate phase |
| 30 | // in the compilation. |
| 31 | |
| 32 | class Artifact { |
| 33 | public: |
| 34 | enum Type { |
| 35 | A_Argument, |
| 36 | A_TempFile, |
| 37 | A_Empty |
| 38 | }; |
| 39 | |
| 40 | // Empty artifact (unusable as is) |
| 41 | Artifact() : type_(A_Empty) { u.arg = nullptr; } |
| 42 | |
| 43 | // Construct an artifact from a command line arg. |
| 44 | explicit Artifact(llvm::opt::Arg *arg) |
| 45 | : type_(A_Argument) { u.arg = arg; } |
| 46 | |
| 47 | // Construct an artifact given a temp file path. |
| 48 | explicit Artifact(const char *tempfilepath) |
| 49 | : type_(A_TempFile) { u.file = tempfilepath; } |
| 50 | |
| 51 | // Type of input |
| 52 | Type type() const { return type_; } |
| 53 | |
| 54 | // File for input |
| 55 | const char *file() const; |
| 56 | |
Than McIntosh | 93bb72f | 2018-04-24 15:36:24 -0400 | [diff] [blame] | 57 | // Return input argument if type is A_Argument, null otherwise. |
| 58 | llvm::opt::Arg *arg(); |
| 59 | |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 60 | // Debugging |
| 61 | std::string toString(); |
| 62 | void dump(); |
| 63 | |
| 64 | private: |
| 65 | Type type_; |
| 66 | union { |
| 67 | llvm::opt::Arg *arg; |
| 68 | const char *file; |
| 69 | } u; |
| 70 | }; |
| 71 | |
| 72 | // A list of artifacts. |
| 73 | typedef llvm::SmallVector<Artifact *, 3> ArtifactList; |
| 74 | |
| 75 | } // end namespace driver |
| 76 | } // end namespace gollvm |
| 77 | |
| 78 | #endif // GOLLVM_DRIVER_ARTIFACT_H |