Home | History | Annotate | Download | only in ExecutionEngine
      1 //===------ JITSymbolFlags.h - Flags for symbols in the JIT -----*- 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 // Symbol flags for symbols in the JIT (e.g. weak, exported).
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
     15 #define LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
     16 
     17 #include "llvm/IR/GlobalValue.h"
     18 #include "llvm/Object/SymbolicFile.h"
     19 
     20 namespace llvm {
     21 
     22 /// @brief Flags for symbols in the JIT.
     23 enum class JITSymbolFlags : char {
     24   None = 0,
     25   Weak = 1U << 0,
     26   Exported = 1U << 1
     27 };
     28 
     29 inline JITSymbolFlags operator|(JITSymbolFlags LHS, JITSymbolFlags RHS) {
     30   typedef std::underlying_type<JITSymbolFlags>::type UT;
     31   return static_cast<JITSymbolFlags>(
     32            static_cast<UT>(LHS) | static_cast<UT>(RHS));
     33 }
     34 
     35 inline JITSymbolFlags& operator |=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
     36   LHS = LHS | RHS;
     37   return LHS;
     38 }
     39 
     40 inline JITSymbolFlags operator&(JITSymbolFlags LHS, JITSymbolFlags RHS) {
     41   typedef std::underlying_type<JITSymbolFlags>::type UT;
     42   return static_cast<JITSymbolFlags>(
     43            static_cast<UT>(LHS) & static_cast<UT>(RHS));
     44 }
     45 
     46 inline JITSymbolFlags& operator &=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
     47   LHS = LHS & RHS;
     48   return LHS;
     49 }
     50 
     51 /// @brief Base class for symbols in the JIT.
     52 class JITSymbolBase {
     53 public:
     54   JITSymbolBase(JITSymbolFlags Flags) : Flags(Flags) {}
     55 
     56   JITSymbolFlags getFlags() const { return Flags; }
     57 
     58   bool isWeak() const {
     59     return (Flags & JITSymbolFlags::Weak) == JITSymbolFlags::Weak;
     60   }
     61 
     62   bool isExported() const {
     63     return (Flags & JITSymbolFlags::Exported) == JITSymbolFlags::Exported;
     64   }
     65 
     66   static JITSymbolFlags flagsFromGlobalValue(const GlobalValue &GV) {
     67     JITSymbolFlags Flags = JITSymbolFlags::None;
     68     if (GV.hasWeakLinkage())
     69       Flags |= JITSymbolFlags::Weak;
     70     if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
     71       Flags |= JITSymbolFlags::Exported;
     72     return Flags;
     73   }
     74 
     75   static JITSymbolFlags
     76   flagsFromObjectSymbol(const object::BasicSymbolRef &Symbol) {
     77     JITSymbolFlags Flags = JITSymbolFlags::None;
     78     if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak)
     79       Flags |= JITSymbolFlags::Weak;
     80     if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported)
     81       Flags |= JITSymbolFlags::Exported;
     82     return Flags;
     83   }
     84 
     85 private:
     86   JITSymbolFlags Flags;
     87 };
     88 
     89 } // end namespace llvm
     90 
     91 #endif
     92