Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1 | //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// |
| 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H |
| 11 | #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 12 | |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 04c4c2c | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Types.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 15 | #include "llvm/Option/Arg.h" |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 16 | #include <cassert> |
Daniel Dunbar | b39cc52 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 17 | #include <string> |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 18 | |
| 19 | namespace clang { |
| 20 | namespace driver { |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 21 | |
| 22 | /// InputInfo - Wrapper for information about an input source. |
| 23 | class InputInfo { |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 24 | // FIXME: The distinction between filenames and inputarg here is |
| 25 | // gross; we should probably drop the idea of a "linker |
| 26 | // input". Doing so means tweaking pipelining to still create link |
| 27 | // steps when it sees linker inputs (but not treat them as |
| 28 | // arguments), and making sure that arguments get rendered |
| 29 | // correctly. |
| 30 | enum Class { |
| 31 | Nothing, |
| 32 | Filename, |
| 33 | InputArg, |
| 34 | Pipe |
| 35 | }; |
| 36 | |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 37 | union { |
| 38 | const char *Filename; |
Reid Kleckner | 724c21c | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 39 | const llvm::opt::Arg *InputArg; |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 40 | } Data; |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 41 | Class Kind; |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 42 | const Action* Act; |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 43 | types::ID Type; |
| 44 | const char *BaseInput; |
| 45 | |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 46 | static types::ID GetActionType(const Action *A) { |
| 47 | return A != nullptr ? A->getType() : types::TY_Nothing; |
Daniel Dunbar | b39cc52 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 48 | } |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 49 | |
| 50 | public: |
| 51 | InputInfo() : InputInfo(nullptr, nullptr) {} |
| 52 | InputInfo(const Action *A, const char *_BaseInput) |
| 53 | : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {} |
| 54 | |
| 55 | InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput) |
| 56 | : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) { |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 57 | Data.Filename = _Filename; |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 58 | } |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 59 | InputInfo(const Action *A, const char *_Filename, const char *_BaseInput) |
| 60 | : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) { |
| 61 | Data.Filename = _Filename; |
| 62 | } |
| 63 | |
| 64 | InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg, |
Reid Kleckner | 724c21c | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 65 | const char *_BaseInput) |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 66 | : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) { |
| 67 | Data.InputArg = _InputArg; |
| 68 | } |
| 69 | InputInfo(const Action *A, const llvm::opt::Arg *_InputArg, |
| 70 | const char *_BaseInput) |
| 71 | : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) { |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 72 | Data.InputArg = _InputArg; |
| 73 | } |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 74 | |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 75 | bool isNothing() const { return Kind == Nothing; } |
| 76 | bool isFilename() const { return Kind == Filename; } |
| 77 | bool isInputArg() const { return Kind == InputArg; } |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 78 | types::ID getType() const { return Type; } |
| 79 | const char *getBaseInput() const { return BaseInput; } |
Justin Lebar | d98cea8 | 2016-01-11 23:15:21 +0000 | [diff] [blame] | 80 | /// The action for which this InputInfo was created. May be null. |
| 81 | const Action *getAction() const { return Act; } |
| 82 | void setAction(const Action *A) { Act = A; } |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 83 | |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 84 | const char *getFilename() const { |
| 85 | assert(isFilename() && "Invalid accessor."); |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 86 | return Data.Filename; |
| 87 | } |
Reid Kleckner | 724c21c | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 88 | const llvm::opt::Arg &getInputArg() const { |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 89 | assert(isInputArg() && "Invalid accessor."); |
| 90 | return *Data.InputArg; |
| 91 | } |
Daniel Dunbar | b39cc52 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 92 | |
| 93 | /// getAsString - Return a string name for this input, for |
| 94 | /// debugging. |
| 95 | std::string getAsString() const { |
Daniel Dunbar | b440f56 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 96 | if (isFilename()) |
Daniel Dunbar | 5cdf3e0 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 97 | return std::string("\"") + getFilename() + '"'; |
| 98 | else if (isInputArg()) |
| 99 | return "(input arg)"; |
Daniel Dunbar | b39cc52 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 100 | else |
| 101 | return "(nothing)"; |
| 102 | } |
Daniel Dunbar | e75d834 | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // end namespace driver |
| 106 | } // end namespace clang |
| 107 | |
| 108 | #endif |