blob: 4eedd22a62dacf1dcdefbdfa7d93d53722658536 [file] [log] [blame]
Daniel Dunbarf353c8c2009-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
10#ifndef CLANG_LIB_DRIVER_INPUTINFO_H_
11#define CLANG_LIB_DRIVER_INPUTINFO_H_
12
Daniel Dunbar871adcf2009-03-18 07:06:02 +000013#include "clang/Driver/Types.h"
Reid Klecknerb1e25a12013-06-14 17:17:23 +000014#include "llvm/Option/Arg.h"
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000015#include <cassert>
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000016#include <string>
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000017
18namespace clang {
19namespace driver {
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000020
21/// InputInfo - Wrapper for information about an input source.
22class InputInfo {
Daniel Dunbar115a7922009-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 Dunbarf353c8c2009-03-16 06:56:51 +000036 union {
37 const char *Filename;
Reid Klecknerdd0b3c42013-06-17 13:59:19 +000038 const llvm::opt::Arg *InputArg;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000039 } Data;
Daniel Dunbar115a7922009-03-19 07:29:38 +000040 Class Kind;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000041 types::ID Type;
42 const char *BaseInput;
43
44public:
45 InputInfo() {}
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000046 InputInfo(types::ID _Type, const char *_BaseInput)
Daniel Dunbar115a7922009-03-19 07:29:38 +000047 : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) {
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000048 }
Daniel Dunbar115a7922009-03-19 07:29:38 +000049 InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput)
50 : Kind(Filename), Type(_Type), BaseInput(_BaseInput) {
51 Data.Filename = _Filename;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000052 }
Reid Klecknerdd0b3c42013-06-17 13:59:19 +000053 InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type,
54 const char *_BaseInput)
55 : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) {
Daniel Dunbar115a7922009-03-19 07:29:38 +000056 Data.InputArg = _InputArg;
57 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000058
Daniel Dunbar115a7922009-03-19 07:29:38 +000059 bool isNothing() const { return Kind == Nothing; }
60 bool isFilename() const { return Kind == Filename; }
61 bool isInputArg() const { return Kind == InputArg; }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000062 types::ID getType() const { return Type; }
63 const char *getBaseInput() const { return BaseInput; }
64
Daniel Dunbar115a7922009-03-19 07:29:38 +000065 const char *getFilename() const {
66 assert(isFilename() && "Invalid accessor.");
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000067 return Data.Filename;
68 }
Reid Klecknerdd0b3c42013-06-17 13:59:19 +000069 const llvm::opt::Arg &getInputArg() const {
Daniel Dunbar115a7922009-03-19 07:29:38 +000070 assert(isInputArg() && "Invalid accessor.");
71 return *Data.InputArg;
72 }
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000073
74 /// getAsString - Return a string name for this input, for
75 /// debugging.
76 std::string getAsString() const {
Daniel Dunbar7c1e4652010-08-02 02:38:21 +000077 if (isFilename())
Daniel Dunbar115a7922009-03-19 07:29:38 +000078 return std::string("\"") + getFilename() + '"';
79 else if (isInputArg())
80 return "(input arg)";
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000081 else
82 return "(nothing)";
83 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000084};
85
86} // end namespace driver
87} // end namespace clang
88
89#endif