blob: 0c36e817c13530fe6ece52639def22f26405752b [file] [log] [blame]
Daniel Dunbare75d8342009-03-16 06:56:51 +00001//===--- 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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010#ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
11#define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
Daniel Dunbare75d8342009-03-16 06:56:51 +000012
Justin Lebard98cea82016-01-11 23:15:21 +000013#include "clang/Driver/Action.h"
Daniel Dunbar04c4c2c2009-03-18 07:06:02 +000014#include "clang/Driver/Types.h"
Reid Kleckner898229a2013-06-14 17:17:23 +000015#include "llvm/Option/Arg.h"
Daniel Dunbare75d8342009-03-16 06:56:51 +000016#include <cassert>
Daniel Dunbarb39cc522009-03-17 22:47:06 +000017#include <string>
Daniel Dunbare75d8342009-03-16 06:56:51 +000018
19namespace clang {
20namespace driver {
Daniel Dunbare75d8342009-03-16 06:56:51 +000021
22/// InputInfo - Wrapper for information about an input source.
23class InputInfo {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000024 // 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 Dunbare75d8342009-03-16 06:56:51 +000037 union {
38 const char *Filename;
Reid Kleckner724c21c2013-06-17 13:59:19 +000039 const llvm::opt::Arg *InputArg;
Daniel Dunbare75d8342009-03-16 06:56:51 +000040 } Data;
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000041 Class Kind;
Justin Lebard98cea82016-01-11 23:15:21 +000042 const Action* Act;
Daniel Dunbare75d8342009-03-16 06:56:51 +000043 types::ID Type;
44 const char *BaseInput;
45
Justin Lebard98cea82016-01-11 23:15:21 +000046 static types::ID GetActionType(const Action *A) {
47 return A != nullptr ? A->getType() : types::TY_Nothing;
Daniel Dunbarb39cc522009-03-17 22:47:06 +000048 }
Justin Lebard98cea82016-01-11 23:15:21 +000049
50public:
51 InputInfo() : InputInfo(nullptr, nullptr) {}
52 InputInfo(const Action *A, const char *_BaseInput)
53 : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
54
55 InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
56 : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000057 Data.Filename = _Filename;
Daniel Dunbare75d8342009-03-16 06:56:51 +000058 }
Justin Lebard98cea82016-01-11 23:15:21 +000059 InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
60 : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
61 Data.Filename = _Filename;
62 }
63
64 InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
Reid Kleckner724c21c2013-06-17 13:59:19 +000065 const char *_BaseInput)
Justin Lebard98cea82016-01-11 23:15:21 +000066 : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
67 Data.InputArg = _InputArg;
68 }
69 InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
70 const char *_BaseInput)
71 : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000072 Data.InputArg = _InputArg;
73 }
Daniel Dunbare75d8342009-03-16 06:56:51 +000074
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000075 bool isNothing() const { return Kind == Nothing; }
76 bool isFilename() const { return Kind == Filename; }
77 bool isInputArg() const { return Kind == InputArg; }
Daniel Dunbare75d8342009-03-16 06:56:51 +000078 types::ID getType() const { return Type; }
79 const char *getBaseInput() const { return BaseInput; }
Justin Lebard98cea82016-01-11 23:15:21 +000080 /// The action for which this InputInfo was created. May be null.
81 const Action *getAction() const { return Act; }
82 void setAction(const Action *A) { Act = A; }
Daniel Dunbare75d8342009-03-16 06:56:51 +000083
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000084 const char *getFilename() const {
85 assert(isFilename() && "Invalid accessor.");
Daniel Dunbare75d8342009-03-16 06:56:51 +000086 return Data.Filename;
87 }
Reid Kleckner724c21c2013-06-17 13:59:19 +000088 const llvm::opt::Arg &getInputArg() const {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000089 assert(isInputArg() && "Invalid accessor.");
90 return *Data.InputArg;
91 }
Daniel Dunbarb39cc522009-03-17 22:47:06 +000092
93 /// getAsString - Return a string name for this input, for
94 /// debugging.
95 std::string getAsString() const {
Daniel Dunbarb440f562010-08-02 02:38:21 +000096 if (isFilename())
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000097 return std::string("\"") + getFilename() + '"';
98 else if (isInputArg())
99 return "(input arg)";
Daniel Dunbarb39cc522009-03-17 22:47:06 +0000100 else
101 return "(nothing)";
102 }
Daniel Dunbare75d8342009-03-16 06:56:51 +0000103};
104
105} // end namespace driver
106} // end namespace clang
107
108#endif