blob: a6b6f7f344bc54bb8be47d72738a1138ba42586c [file] [log] [blame]
Daniel Dunbare75d8342009-03-16 06:56:51 +00001//===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Daniel Dunbare75d8342009-03-16 06:56:51 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +00009#ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
10#define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
Daniel Dunbare75d8342009-03-16 06:56:51 +000011
Justin Lebard98cea82016-01-11 23:15:21 +000012#include "clang/Driver/Action.h"
Daniel Dunbar04c4c2c2009-03-18 07:06:02 +000013#include "clang/Driver/Types.h"
Reid Kleckner898229a2013-06-14 17:17:23 +000014#include "llvm/Option/Arg.h"
Daniel Dunbare75d8342009-03-16 06:56:51 +000015#include <cassert>
Daniel Dunbarb39cc522009-03-17 22:47:06 +000016#include <string>
Daniel Dunbare75d8342009-03-16 06:56:51 +000017
18namespace clang {
19namespace driver {
Daniel Dunbare75d8342009-03-16 06:56:51 +000020
21/// InputInfo - Wrapper for information about an input source.
22class InputInfo {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000023 // 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 Dunbare75d8342009-03-16 06:56:51 +000036 union {
37 const char *Filename;
Reid Kleckner724c21c2013-06-17 13:59:19 +000038 const llvm::opt::Arg *InputArg;
Daniel Dunbare75d8342009-03-16 06:56:51 +000039 } Data;
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000040 Class Kind;
Justin Lebard98cea82016-01-11 23:15:21 +000041 const Action* Act;
Daniel Dunbare75d8342009-03-16 06:56:51 +000042 types::ID Type;
43 const char *BaseInput;
44
Justin Lebard98cea82016-01-11 23:15:21 +000045 static types::ID GetActionType(const Action *A) {
46 return A != nullptr ? A->getType() : types::TY_Nothing;
Daniel Dunbarb39cc522009-03-17 22:47:06 +000047 }
Justin Lebard98cea82016-01-11 23:15:21 +000048
49public:
50 InputInfo() : InputInfo(nullptr, nullptr) {}
51 InputInfo(const Action *A, const char *_BaseInput)
52 : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
53
54 InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
55 : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000056 Data.Filename = _Filename;
Daniel Dunbare75d8342009-03-16 06:56:51 +000057 }
Justin Lebard98cea82016-01-11 23:15:21 +000058 InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
59 : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
60 Data.Filename = _Filename;
61 }
62
63 InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
Reid Kleckner724c21c2013-06-17 13:59:19 +000064 const char *_BaseInput)
Justin Lebard98cea82016-01-11 23:15:21 +000065 : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
66 Data.InputArg = _InputArg;
67 }
68 InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
69 const char *_BaseInput)
70 : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000071 Data.InputArg = _InputArg;
72 }
Daniel Dunbare75d8342009-03-16 06:56:51 +000073
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000074 bool isNothing() const { return Kind == Nothing; }
75 bool isFilename() const { return Kind == Filename; }
76 bool isInputArg() const { return Kind == InputArg; }
Daniel Dunbare75d8342009-03-16 06:56:51 +000077 types::ID getType() const { return Type; }
78 const char *getBaseInput() const { return BaseInput; }
Justin Lebard98cea82016-01-11 23:15:21 +000079 /// The action for which this InputInfo was created. May be null.
80 const Action *getAction() const { return Act; }
81 void setAction(const Action *A) { Act = A; }
Daniel Dunbare75d8342009-03-16 06:56:51 +000082
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000083 const char *getFilename() const {
84 assert(isFilename() && "Invalid accessor.");
Daniel Dunbare75d8342009-03-16 06:56:51 +000085 return Data.Filename;
86 }
Reid Kleckner724c21c2013-06-17 13:59:19 +000087 const llvm::opt::Arg &getInputArg() const {
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000088 assert(isInputArg() && "Invalid accessor.");
89 return *Data.InputArg;
90 }
Daniel Dunbarb39cc522009-03-17 22:47:06 +000091
92 /// getAsString - Return a string name for this input, for
93 /// debugging.
94 std::string getAsString() const {
Daniel Dunbarb440f562010-08-02 02:38:21 +000095 if (isFilename())
Daniel Dunbar5cdf3e02009-03-19 07:29:38 +000096 return std::string("\"") + getFilename() + '"';
97 else if (isInputArg())
98 return "(input arg)";
Daniel Dunbarb39cc522009-03-17 22:47:06 +000099 else
100 return "(nothing)";
101 }
Daniel Dunbare75d8342009-03-16 06:56:51 +0000102};
103
104} // end namespace driver
105} // end namespace clang
106
107#endif