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 { |
| 20 | class PipedJob; |
| 21 | |
| 22 | /// InputInfo - Wrapper for information about an input source. |
| 23 | class InputInfo { |
Daniel Dunbar | 115a792 | 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 | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 37 | union { |
| 38 | const char *Filename; |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 39 | const Arg *InputArg; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 40 | PipedJob *Pipe; |
| 41 | } Data; |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 42 | Class Kind; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 43 | types::ID Type; |
| 44 | const char *BaseInput; |
| 45 | |
| 46 | public: |
| 47 | InputInfo() {} |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 48 | InputInfo(types::ID _Type, const char *_BaseInput) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 49 | : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 50 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 51 | InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) |
| 52 | : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { |
| 53 | Data.Filename = _Filename; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 54 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 55 | InputInfo(const Arg *_InputArg, types::ID _Type, const char *_BaseInput) |
| 56 | : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { |
| 57 | Data.InputArg = _InputArg; |
| 58 | } |
| 59 | InputInfo(PipedJob *_Pipe, types::ID _Type, const char *_BaseInput) |
| 60 | : Kind(Pipe), Type(_Type), BaseInput(_BaseInput) { |
| 61 | Data.Pipe = _Pipe; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 64 | bool isNothing() const { return Kind == Nothing; } |
| 65 | bool isFilename() const { return Kind == Filename; } |
| 66 | bool isInputArg() const { return Kind == InputArg; } |
| 67 | bool isPipe() const { return Kind == Pipe; } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 68 | types::ID getType() const { return Type; } |
| 69 | const char *getBaseInput() const { return BaseInput; } |
| 70 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 71 | const char *getFilename() const { |
| 72 | assert(isFilename() && "Invalid accessor."); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 73 | return Data.Filename; |
| 74 | } |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 75 | const Arg &getInputArg() const { |
| 76 | assert(isInputArg() && "Invalid accessor."); |
| 77 | return *Data.InputArg; |
| 78 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 79 | PipedJob &getPipe() const { |
| 80 | assert(isPipe() && "Invalid accessor."); |
| 81 | return *Data.Pipe; |
| 82 | } |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 83 | |
| 84 | /// getAsString - Return a string name for this input, for |
| 85 | /// debugging. |
| 86 | std::string getAsString() const { |
| 87 | if (isPipe()) |
| 88 | return "(pipe)"; |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 89 | else if (isFilename()) |
| 90 | return std::string("\"") + getFilename() + '"'; |
| 91 | else if (isInputArg()) |
| 92 | return "(input arg)"; |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 93 | else |
| 94 | return "(nothing)"; |
| 95 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // end namespace driver |
| 99 | } // end namespace clang |
| 100 | |
| 101 | #endif |