2009-03-16 14:56:51 +08:00
|
|
|
//===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-03-16 14:56:51 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
|
|
|
|
#define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
|
2009-03-16 14:56:51 +08:00
|
|
|
|
2016-01-12 07:15:21 +08:00
|
|
|
#include "clang/Driver/Action.h"
|
2009-03-18 15:06:02 +08:00
|
|
|
#include "clang/Driver/Types.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
2009-03-16 14:56:51 +08:00
|
|
|
#include <cassert>
|
2009-03-18 06:47:06 +08:00
|
|
|
#include <string>
|
2009-03-16 14:56:51 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace driver {
|
|
|
|
|
|
|
|
/// InputInfo - Wrapper for information about an input source.
|
|
|
|
class InputInfo {
|
2009-03-19 15:29:38 +08:00
|
|
|
// FIXME: The distinction between filenames and inputarg here is
|
|
|
|
// gross; we should probably drop the idea of a "linker
|
|
|
|
// input". Doing so means tweaking pipelining to still create link
|
|
|
|
// steps when it sees linker inputs (but not treat them as
|
|
|
|
// arguments), and making sure that arguments get rendered
|
|
|
|
// correctly.
|
|
|
|
enum Class {
|
|
|
|
Nothing,
|
|
|
|
Filename,
|
|
|
|
InputArg,
|
|
|
|
Pipe
|
|
|
|
};
|
|
|
|
|
2009-03-16 14:56:51 +08:00
|
|
|
union {
|
|
|
|
const char *Filename;
|
2013-06-17 21:59:19 +08:00
|
|
|
const llvm::opt::Arg *InputArg;
|
2009-03-16 14:56:51 +08:00
|
|
|
} Data;
|
2009-03-19 15:29:38 +08:00
|
|
|
Class Kind;
|
2016-01-12 07:15:21 +08:00
|
|
|
const Action* Act;
|
2009-03-16 14:56:51 +08:00
|
|
|
types::ID Type;
|
|
|
|
const char *BaseInput;
|
|
|
|
|
2016-01-12 07:15:21 +08:00
|
|
|
static types::ID GetActionType(const Action *A) {
|
|
|
|
return A != nullptr ? A->getType() : types::TY_Nothing;
|
|
|
|
}
|
|
|
|
|
2009-03-16 14:56:51 +08:00
|
|
|
public:
|
2016-01-12 07:15:21 +08:00
|
|
|
InputInfo() : InputInfo(nullptr, nullptr) {}
|
|
|
|
InputInfo(const Action *A, const char *_BaseInput)
|
|
|
|
: Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
|
|
|
|
|
|
|
|
InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
|
|
|
|
: Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
|
|
|
|
Data.Filename = _Filename;
|
2009-03-19 15:29:38 +08:00
|
|
|
}
|
2016-01-12 07:15:21 +08:00
|
|
|
InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
|
|
|
|
: Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
|
2009-03-19 15:29:38 +08:00
|
|
|
Data.Filename = _Filename;
|
2009-03-18 06:47:06 +08:00
|
|
|
}
|
2016-01-12 07:15:21 +08:00
|
|
|
|
|
|
|
InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
|
|
|
|
const char *_BaseInput)
|
|
|
|
: Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
|
|
|
|
Data.InputArg = _InputArg;
|
|
|
|
}
|
|
|
|
InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
|
2013-06-17 21:59:19 +08:00
|
|
|
const char *_BaseInput)
|
2016-01-12 07:15:21 +08:00
|
|
|
: Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
|
2009-03-19 15:29:38 +08:00
|
|
|
Data.InputArg = _InputArg;
|
2009-03-16 14:56:51 +08:00
|
|
|
}
|
|
|
|
|
2009-03-19 15:29:38 +08:00
|
|
|
bool isNothing() const { return Kind == Nothing; }
|
|
|
|
bool isFilename() const { return Kind == Filename; }
|
|
|
|
bool isInputArg() const { return Kind == InputArg; }
|
2009-03-16 14:56:51 +08:00
|
|
|
types::ID getType() const { return Type; }
|
|
|
|
const char *getBaseInput() const { return BaseInput; }
|
2016-01-12 07:15:21 +08:00
|
|
|
/// The action for which this InputInfo was created. May be null.
|
|
|
|
const Action *getAction() const { return Act; }
|
|
|
|
void setAction(const Action *A) { Act = A; }
|
2009-03-16 14:56:51 +08:00
|
|
|
|
2009-03-19 15:29:38 +08:00
|
|
|
const char *getFilename() const {
|
|
|
|
assert(isFilename() && "Invalid accessor.");
|
2009-03-16 14:56:51 +08:00
|
|
|
return Data.Filename;
|
|
|
|
}
|
2013-06-17 21:59:19 +08:00
|
|
|
const llvm::opt::Arg &getInputArg() const {
|
2009-03-19 15:29:38 +08:00
|
|
|
assert(isInputArg() && "Invalid accessor.");
|
|
|
|
return *Data.InputArg;
|
|
|
|
}
|
2009-03-18 06:47:06 +08:00
|
|
|
|
|
|
|
/// getAsString - Return a string name for this input, for
|
|
|
|
/// debugging.
|
|
|
|
std::string getAsString() const {
|
2010-08-02 10:38:21 +08:00
|
|
|
if (isFilename())
|
2009-03-19 15:29:38 +08:00
|
|
|
return std::string("\"") + getFilename() + '"';
|
|
|
|
else if (isInputArg())
|
|
|
|
return "(input arg)";
|
2009-03-18 06:47:06 +08:00
|
|
|
else
|
|
|
|
return "(nothing)";
|
|
|
|
}
|
2009-03-16 14:56:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace driver
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|