1f4a2713aSLionel Sambuc //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc 10*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H 11*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc #include "clang/Driver/Types.h" 14f4a2713aSLionel Sambuc #include "llvm/Option/Arg.h" 15f4a2713aSLionel Sambuc #include <cassert> 16f4a2713aSLionel Sambuc #include <string> 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc namespace clang { 19f4a2713aSLionel Sambuc namespace driver { 20f4a2713aSLionel Sambuc 21f4a2713aSLionel Sambuc /// InputInfo - Wrapper for information about an input source. 22f4a2713aSLionel Sambuc class InputInfo { 23f4a2713aSLionel Sambuc // FIXME: The distinction between filenames and inputarg here is 24f4a2713aSLionel Sambuc // gross; we should probably drop the idea of a "linker 25f4a2713aSLionel Sambuc // input". Doing so means tweaking pipelining to still create link 26f4a2713aSLionel Sambuc // steps when it sees linker inputs (but not treat them as 27f4a2713aSLionel Sambuc // arguments), and making sure that arguments get rendered 28f4a2713aSLionel Sambuc // correctly. 29f4a2713aSLionel Sambuc enum Class { 30f4a2713aSLionel Sambuc Nothing, 31f4a2713aSLionel Sambuc Filename, 32f4a2713aSLionel Sambuc InputArg, 33f4a2713aSLionel Sambuc Pipe 34f4a2713aSLionel Sambuc }; 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc union { 37f4a2713aSLionel Sambuc const char *Filename; 38f4a2713aSLionel Sambuc const llvm::opt::Arg *InputArg; 39f4a2713aSLionel Sambuc } Data; 40f4a2713aSLionel Sambuc Class Kind; 41f4a2713aSLionel Sambuc types::ID Type; 42f4a2713aSLionel Sambuc const char *BaseInput; 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc public: InputInfo()45f4a2713aSLionel Sambuc InputInfo() {} InputInfo(types::ID _Type,const char * _BaseInput)46f4a2713aSLionel Sambuc InputInfo(types::ID _Type, const char *_BaseInput) 47f4a2713aSLionel Sambuc : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { 48f4a2713aSLionel Sambuc } InputInfo(const char * _Filename,types::ID _Type,const char * _BaseInput)49f4a2713aSLionel Sambuc InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) 50f4a2713aSLionel Sambuc : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { 51f4a2713aSLionel Sambuc Data.Filename = _Filename; 52f4a2713aSLionel Sambuc } InputInfo(const llvm::opt::Arg * _InputArg,types::ID _Type,const char * _BaseInput)53f4a2713aSLionel Sambuc InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, 54f4a2713aSLionel Sambuc const char *_BaseInput) 55f4a2713aSLionel Sambuc : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { 56f4a2713aSLionel Sambuc Data.InputArg = _InputArg; 57f4a2713aSLionel Sambuc } 58f4a2713aSLionel Sambuc isNothing()59f4a2713aSLionel Sambuc bool isNothing() const { return Kind == Nothing; } isFilename()60f4a2713aSLionel Sambuc bool isFilename() const { return Kind == Filename; } isInputArg()61f4a2713aSLionel Sambuc bool isInputArg() const { return Kind == InputArg; } getType()62f4a2713aSLionel Sambuc types::ID getType() const { return Type; } getBaseInput()63f4a2713aSLionel Sambuc const char *getBaseInput() const { return BaseInput; } 64f4a2713aSLionel Sambuc getFilename()65f4a2713aSLionel Sambuc const char *getFilename() const { 66f4a2713aSLionel Sambuc assert(isFilename() && "Invalid accessor."); 67f4a2713aSLionel Sambuc return Data.Filename; 68f4a2713aSLionel Sambuc } getInputArg()69f4a2713aSLionel Sambuc const llvm::opt::Arg &getInputArg() const { 70f4a2713aSLionel Sambuc assert(isInputArg() && "Invalid accessor."); 71f4a2713aSLionel Sambuc return *Data.InputArg; 72f4a2713aSLionel Sambuc } 73f4a2713aSLionel Sambuc 74f4a2713aSLionel Sambuc /// getAsString - Return a string name for this input, for 75f4a2713aSLionel Sambuc /// debugging. getAsString()76f4a2713aSLionel Sambuc std::string getAsString() const { 77f4a2713aSLionel Sambuc if (isFilename()) 78f4a2713aSLionel Sambuc return std::string("\"") + getFilename() + '"'; 79f4a2713aSLionel Sambuc else if (isInputArg()) 80f4a2713aSLionel Sambuc return "(input arg)"; 81f4a2713aSLionel Sambuc else 82f4a2713aSLionel Sambuc return "(nothing)"; 83f4a2713aSLionel Sambuc } 84f4a2713aSLionel Sambuc }; 85f4a2713aSLionel Sambuc 86f4a2713aSLionel Sambuc } // end namespace driver 87f4a2713aSLionel Sambuc } // end namespace clang 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc #endif 90