Home | History | Annotate | Line # | Download | only in Driver
      1  1.1  joerg //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
      2  1.1  joerg //
      3  1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4  1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      5  1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6  1.1  joerg //
      7  1.1  joerg //===----------------------------------------------------------------------===//
      8  1.1  joerg 
      9  1.1  joerg #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
     10  1.1  joerg #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
     11  1.1  joerg 
     12  1.1  joerg #include "clang/Driver/Action.h"
     13  1.1  joerg #include "clang/Driver/Types.h"
     14  1.1  joerg #include "llvm/Option/Arg.h"
     15  1.1  joerg #include <cassert>
     16  1.1  joerg #include <string>
     17  1.1  joerg 
     18  1.1  joerg namespace clang {
     19  1.1  joerg namespace driver {
     20  1.1  joerg 
     21  1.1  joerg /// InputInfo - Wrapper for information about an input source.
     22  1.1  joerg class InputInfo {
     23  1.1  joerg   // FIXME: The distinction between filenames and inputarg here is
     24  1.1  joerg   // gross; we should probably drop the idea of a "linker
     25  1.1  joerg   // input". Doing so means tweaking pipelining to still create link
     26  1.1  joerg   // steps when it sees linker inputs (but not treat them as
     27  1.1  joerg   // arguments), and making sure that arguments get rendered
     28  1.1  joerg   // correctly.
     29  1.1  joerg   enum Class {
     30  1.1  joerg     Nothing,
     31  1.1  joerg     Filename,
     32  1.1  joerg     InputArg,
     33  1.1  joerg     Pipe
     34  1.1  joerg   };
     35  1.1  joerg 
     36  1.1  joerg   union {
     37  1.1  joerg     const char *Filename;
     38  1.1  joerg     const llvm::opt::Arg *InputArg;
     39  1.1  joerg   } Data;
     40  1.1  joerg   Class Kind;
     41  1.1  joerg   const Action* Act;
     42  1.1  joerg   types::ID Type;
     43  1.1  joerg   const char *BaseInput;
     44  1.1  joerg 
     45  1.1  joerg   static types::ID GetActionType(const Action *A) {
     46  1.1  joerg     return A != nullptr ? A->getType() : types::TY_Nothing;
     47  1.1  joerg   }
     48  1.1  joerg 
     49  1.1  joerg public:
     50  1.1  joerg   InputInfo() : InputInfo(nullptr, nullptr) {}
     51  1.1  joerg   InputInfo(const Action *A, const char *_BaseInput)
     52  1.1  joerg       : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
     53  1.1  joerg 
     54  1.1  joerg   InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
     55  1.1  joerg       : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
     56  1.1  joerg     Data.Filename = _Filename;
     57  1.1  joerg   }
     58  1.1  joerg   InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
     59  1.1  joerg       : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
     60  1.1  joerg     Data.Filename = _Filename;
     61  1.1  joerg   }
     62  1.1  joerg 
     63  1.1  joerg   InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
     64  1.1  joerg             const char *_BaseInput)
     65  1.1  joerg       : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
     66  1.1  joerg     Data.InputArg = _InputArg;
     67  1.1  joerg   }
     68  1.1  joerg   InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
     69  1.1  joerg             const char *_BaseInput)
     70  1.1  joerg       : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
     71  1.1  joerg     Data.InputArg = _InputArg;
     72  1.1  joerg   }
     73  1.1  joerg 
     74  1.1  joerg   bool isNothing() const { return Kind == Nothing; }
     75  1.1  joerg   bool isFilename() const { return Kind == Filename; }
     76  1.1  joerg   bool isInputArg() const { return Kind == InputArg; }
     77  1.1  joerg   types::ID getType() const { return Type; }
     78  1.1  joerg   const char *getBaseInput() const { return BaseInput; }
     79  1.1  joerg   /// The action for which this InputInfo was created.  May be null.
     80  1.1  joerg   const Action *getAction() const { return Act; }
     81  1.1  joerg   void setAction(const Action *A) { Act = A; }
     82  1.1  joerg 
     83  1.1  joerg   const char *getFilename() const {
     84  1.1  joerg     assert(isFilename() && "Invalid accessor.");
     85  1.1  joerg     return Data.Filename;
     86  1.1  joerg   }
     87  1.1  joerg   const llvm::opt::Arg &getInputArg() const {
     88  1.1  joerg     assert(isInputArg() && "Invalid accessor.");
     89  1.1  joerg     return *Data.InputArg;
     90  1.1  joerg   }
     91  1.1  joerg 
     92  1.1  joerg   /// getAsString - Return a string name for this input, for
     93  1.1  joerg   /// debugging.
     94  1.1  joerg   std::string getAsString() const {
     95  1.1  joerg     if (isFilename())
     96  1.1  joerg       return std::string("\"") + getFilename() + '"';
     97  1.1  joerg     else if (isInputArg())
     98  1.1  joerg       return "(input arg)";
     99  1.1  joerg     else
    100  1.1  joerg       return "(nothing)";
    101  1.1  joerg   }
    102  1.1  joerg };
    103  1.1  joerg 
    104  1.1  joerg } // end namespace driver
    105  1.1  joerg } // end namespace clang
    106  1.1  joerg 
    107  1.1  joerg #endif
    108