1193326Sed//===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed 10193326Sed#ifndef CLANG_LIB_DRIVER_INPUTINFO_H_ 11193326Sed#define CLANG_LIB_DRIVER_INPUTINFO_H_ 12193326Sed 13193326Sed#include "clang/Driver/Types.h" 14263508Sdim#include "llvm/Option/Arg.h" 15193326Sed#include <cassert> 16193326Sed#include <string> 17193326Sed 18193326Sednamespace clang { 19193326Sednamespace driver { 20193326Sed 21193326Sed/// InputInfo - Wrapper for information about an input source. 22193326Sedclass InputInfo { 23193326Sed // FIXME: The distinction between filenames and inputarg here is 24193326Sed // gross; we should probably drop the idea of a "linker 25193326Sed // input". Doing so means tweaking pipelining to still create link 26193326Sed // steps when it sees linker inputs (but not treat them as 27193326Sed // arguments), and making sure that arguments get rendered 28193326Sed // correctly. 29193326Sed enum Class { 30193326Sed Nothing, 31193326Sed Filename, 32193326Sed InputArg, 33193326Sed Pipe 34193326Sed }; 35193326Sed 36193326Sed union { 37193326Sed const char *Filename; 38263508Sdim const llvm::opt::Arg *InputArg; 39193326Sed } Data; 40193326Sed Class Kind; 41193326Sed types::ID Type; 42193326Sed const char *BaseInput; 43193326Sed 44193326Sedpublic: 45193326Sed InputInfo() {} 46193326Sed InputInfo(types::ID _Type, const char *_BaseInput) 47193326Sed : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { 48193326Sed } 49193326Sed InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) 50193326Sed : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { 51193326Sed Data.Filename = _Filename; 52193326Sed } 53263508Sdim InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, 54263508Sdim const char *_BaseInput) 55263508Sdim : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { 56193326Sed Data.InputArg = _InputArg; 57193326Sed } 58193326Sed 59193326Sed bool isNothing() const { return Kind == Nothing; } 60193326Sed bool isFilename() const { return Kind == Filename; } 61193326Sed bool isInputArg() const { return Kind == InputArg; } 62193326Sed types::ID getType() const { return Type; } 63193326Sed const char *getBaseInput() const { return BaseInput; } 64193326Sed 65193326Sed const char *getFilename() const { 66193326Sed assert(isFilename() && "Invalid accessor."); 67193326Sed return Data.Filename; 68193326Sed } 69263508Sdim const llvm::opt::Arg &getInputArg() const { 70193326Sed assert(isInputArg() && "Invalid accessor."); 71193326Sed return *Data.InputArg; 72193326Sed } 73193326Sed 74193326Sed /// getAsString - Return a string name for this input, for 75193326Sed /// debugging. 76193326Sed std::string getAsString() const { 77212904Sdim if (isFilename()) 78193326Sed return std::string("\"") + getFilename() + '"'; 79193326Sed else if (isInputArg()) 80193326Sed return "(input arg)"; 81193326Sed else 82193326Sed return "(nothing)"; 83193326Sed } 84193326Sed}; 85193326Sed 86193326Sed} // end namespace driver 87193326Sed} // end namespace clang 88193326Sed 89193326Sed#endif 90