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