Daniel Dunbar | f353c8c | 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 | |
| 10 | #ifndef CLANG_LIB_DRIVER_INPUTINFO_H_ |
| 11 | #define CLANG_LIB_DRIVER_INPUTINFO_H_ |
| 12 | |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Types.h" |
| 14 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 15 | #include <cassert> |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 16 | #include <string> |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 17 | |
| 18 | namespace clang { |
| 19 | namespace driver { |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 20 | |
| 21 | /// InputInfo - Wrapper for information about an input source. |
| 22 | class InputInfo { |
Daniel Dunbar | 115a792 | 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 | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 36 | union { |
| 37 | const char *Filename; |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 38 | const Arg *InputArg; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 39 | } Data; |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 40 | Class Kind; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 41 | types::ID Type; |
| 42 | const char *BaseInput; |
| 43 | |
| 44 | public: |
| 45 | InputInfo() {} |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 46 | InputInfo(types::ID _Type, const char *_BaseInput) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 47 | : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 48 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 49 | InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) |
| 50 | : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { |
| 51 | Data.Filename = _Filename; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 52 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 53 | InputInfo(const Arg *_InputArg, types::ID _Type, const char *_BaseInput) |
| 54 | : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { |
| 55 | Data.InputArg = _InputArg; |
| 56 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 57 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 58 | bool isNothing() const { return Kind == Nothing; } |
| 59 | bool isFilename() const { return Kind == Filename; } |
| 60 | bool isInputArg() const { return Kind == InputArg; } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 61 | types::ID getType() const { return Type; } |
| 62 | const char *getBaseInput() const { return BaseInput; } |
| 63 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 64 | const char *getFilename() const { |
| 65 | assert(isFilename() && "Invalid accessor."); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 66 | return Data.Filename; |
| 67 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 68 | const Arg &getInputArg() const { |
| 69 | assert(isInputArg() && "Invalid accessor."); |
| 70 | return *Data.InputArg; |
| 71 | } |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 72 | |
| 73 | /// getAsString - Return a string name for this input, for |
| 74 | /// debugging. |
| 75 | std::string getAsString() const { |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 76 | if (isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 77 | return std::string("\"") + getFilename() + '"'; |
| 78 | else if (isInputArg()) |
| 79 | return "(input arg)"; |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 80 | else |
| 81 | return "(nothing)"; |
| 82 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // end namespace driver |
| 86 | } // end namespace clang |
| 87 | |
| 88 | #endif |