Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:26

0001 //===- Module.h -------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_SANDBOXIR_MODULE_H
0010 #define LLVM_SANDBOXIR_MODULE_H
0011 
0012 #include "llvm/ADT/STLExtras.h"
0013 #include "llvm/IR/Module.h"
0014 #include <string>
0015 
0016 namespace llvm {
0017 
0018 class DataLayout;
0019 
0020 namespace sandboxir {
0021 
0022 class Context;
0023 class Function;
0024 class GlobalVariable;
0025 class Type;
0026 class Constant;
0027 class GlobalAlias;
0028 class GlobalIFunc;
0029 
0030 /// In SandboxIR the Module is mainly used to access the list of global objects.
0031 class Module {
0032   llvm::Module &LLVMM;
0033   Context &Ctx;
0034 
0035   Module(llvm::Module &LLVMM, Context &Ctx) : LLVMM(LLVMM), Ctx(Ctx) {}
0036   friend class Context; // For constructor.
0037 
0038 public:
0039   Context &getContext() const { return Ctx; }
0040 
0041   Function *getFunction(StringRef Name) const;
0042 
0043   const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
0044 
0045   const std::string &getSourceFileName() const {
0046     return LLVMM.getSourceFileName();
0047   }
0048 
0049   /// Look up the specified global variable in the module symbol table. If it
0050   /// does not exist, return null. If AllowInternal is set to true, this
0051   /// function will return types that have InternalLinkage. By default, these
0052   /// types are not returned.
0053   GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
0054   GlobalVariable *getGlobalVariable(StringRef Name) const {
0055     return getGlobalVariable(Name, /*AllowInternal=*/false);
0056   }
0057   /// Return the global variable in the module with the specified name, of
0058   /// arbitrary type. This method returns null if a global with the specified
0059   /// name is not found.
0060   GlobalVariable *getNamedGlobal(StringRef Name) const {
0061     return getGlobalVariable(Name, true);
0062   }
0063 
0064   // TODO: missing getOrInsertGlobal().
0065 
0066   /// Return the global alias in the module with the specified name, of
0067   /// arbitrary type. This method returns null if a global with the specified
0068   /// name is not found.
0069   GlobalAlias *getNamedAlias(StringRef Name) const;
0070 
0071   /// Return the global ifunc in the module with the specified name, of
0072   /// arbitrary type. This method returns null if a global with the specified
0073   /// name is not found.
0074   GlobalIFunc *getNamedIFunc(StringRef Name) const;
0075 
0076   // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
0077   // insertGlobalVariable()
0078 
0079   // TODO: Missing global_begin(), global_end(), globals().
0080 
0081   // TODO: Missing many other functions.
0082 
0083 #ifndef NDEBUG
0084   void dumpOS(raw_ostream &OS) const;
0085   LLVM_DUMP_METHOD void dump() const;
0086 #endif // NDEBUG
0087 };
0088 
0089 } // namespace sandboxir
0090 } // namespace llvm
0091 
0092 #endif // LLVM_SANDBOXIR_MODULE_H