llvm.org GIT mirror llvm / 4434ed4
Make the use of const with respect to LLVMContext sane. Hopefully this is the last time, for the moment, that I will need to make far-reaching changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74655 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 10 years ago
29 changed file(s) with 58 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
3636 const char *BrainF::testreg = "test";
3737
3838 Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf,
39 const LLVMContext& Context) {
39 LLVMContext& Context) {
4040 in = in1;
4141 memtotal = mem;
4242 comflag = cf;
4747 return module;
4848 }
4949
50 void BrainF::header(const LLVMContext& C) {
50 void BrainF::header(LLVMContext& C) {
5151 module = new Module("BrainF", C);
5252
5353 //Function prototypes
3939 /// On error, it calls abort.
4040 /// The caller must delete the returned module.
4141 Module *parse(std::istream *in1, int mem, CompileFlags cf,
42 const LLVMContext& C);
42 LLVMContext& C);
4343
4444 protected:
4545 /// The different symbols in the BrainF language
6565 static const char *testreg;
6666
6767 /// Put the brainf function preamble and other fixed pieces of code
68 void header(const LLVMContext& C);
68 void header(LLVMContext& C);
6969
7070 /// The main loop for parsing. It calls itself recursively
7171 /// to handle the depth of nesting of "[]".
3131 Module *ParseAssemblyFile(
3232 const std::string &Filename, ///< The name of the file to parse
3333 ParseError &Error, ///< If not null, an object to return errors in.
34 const LLVMContext& Context ///< Context in which to allocate globals info.
34 LLVMContext& Context ///< Context in which to allocate globals info.
3535 );
3636
3737 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
4444 const char *AsmString, ///< The string containing assembly
4545 Module *M, ///< A module to add the assembly too.
4646 ParseError &Error, ///< If not null, an object to return errors in.
47 const LLVMContext& Context
47 LLVMContext& Context
4848 );
4949
5050 //===------------------------------------------------------------------------===
279279 /// @brief Create an empty Archive.
280280 static Archive* CreateEmpty(
281281 const sys::Path& Filename,///< Name of the archive to (eventually) create.
282 const LLVMContext& C ///< Context to use for global information
282 LLVMContext& C ///< Context to use for global information
283283 );
284284
285285 /// Open an existing archive and load its contents in preparation for
290290 /// @brief Open and load an archive file
291291 static Archive* OpenAndLoad(
292292 const sys::Path& filePath, ///< The file path to open and load
293 const LLVMContext& C, ///< The context to use for global information
293 LLVMContext& C, ///< The context to use for global information
294294 std::string* ErrorMessage ///< An optional error string
295295 );
296296
312312 /// @brief Open an existing archive and load its symbols.
313313 static Archive* OpenAndLoadSymbols(
314314 const sys::Path& Filename, ///< Name of the archive file to open
315 const LLVMContext& C, ///< The context to use for global info
315 LLVMContext& C, ///< The context to use for global info
316316 std::string* ErrorMessage=0 ///< An optional error string
317317 );
318318
452452 protected:
453453 /// @brief Construct an Archive for \p filename and optionally map it
454454 /// into memory.
455 explicit Archive(const sys::Path& filename, const LLVMContext& C);
455 explicit Archive(const sys::Path& filename, LLVMContext& C);
456456
457457 /// @param data The symbol table data to be parsed
458458 /// @param len The length of the symbol table data
533533 unsigned firstFileOffset; ///< Offset to first normal file.
534534 ModuleMap modules; ///< The modules loaded via symbol lookup.
535535 ArchiveMember* foreignST; ///< This holds the foreign symbol table.
536 const LLVMContext& Context; ///< This holds global data.
536 LLVMContext& Context; ///< This holds global data.
537537 /// @}
538538 /// @name Hidden
539539 /// @{
3131 /// error, this returns null, *does not* take ownership of Buffer, and fills
3232 /// in *ErrMsg with an error description if ErrMsg is non-null.
3333 ModuleProvider *getBitcodeModuleProvider(MemoryBuffer *Buffer,
34 const LLVMContext& Context,
34 LLVMContext& Context,
3535 std::string *ErrMsg = 0);
3636
3737 /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
3838 /// If an error occurs, this returns null and fills in *ErrMsg if it is
3939 /// non-null. This method *never* takes ownership of Buffer.
40 Module *ParseBitcodeFile(MemoryBuffer *Buffer, const LLVMContext& Context,
40 Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
4141 std::string *ErrMsg = 0);
4242
4343 /// WriteBitcodeToFile - Write the specified module to the specified output
9595 /// the PATH for the specified program, loading it when found. If the
9696 /// specified program cannot be found, an exception is thrown to indicate
9797 /// the error.
98 void loadProgram(const std::string &Path, const LLVMContext& Context);
98 void loadProgram(const std::string &Path, LLVMContext& Context);
9999
100100 /// unloadProgram - If a program is running, kill it, then unload all traces
101101 /// of the current program. If no program is loaded, this method silently
197197 };
198198
199199 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
200 extern const LLVMContext& getGlobalContext();
200 extern LLVMContext& getGlobalContext();
201201
202202 }
203203
6666 Linker(
6767 const std::string& progname, ///< name of tool running linker
6868 const std::string& modulename, ///< name of linker's end-result module
69 const LLVMContext& C, ///< Context for global info
69 LLVMContext& C, ///< Context for global info
7070 unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
7171 );
7272
284284 /// @name Data
285285 /// @{
286286 private:
287 const LLVMContext& Context; ///< The context for global information
287 LLVMContext& Context; ///< The context for global information
288288 Module* Composite; ///< The composite module linked together
289289 std::vector LibPaths; ///< The library search paths
290290 unsigned Flags; ///< Flags to control optional behavior.
109109 /// @name Member Variables
110110 /// @{
111111 private:
112 const LLVMContext& Context; ///< The LLVMContext from which types and
112 LLVMContext& Context; ///< The LLVMContext from which types and
113113 ///< constants are allocated.
114114 GlobalListType GlobalList; ///< The Global Variables in the module
115115 FunctionListType FunctionList; ///< The Functions in the module
130130 public:
131131 /// The Module constructor. Note that there is no default constructor. You
132132 /// must provide a name for the module upon construction.
133 explicit Module(const std::string &ModuleID, const LLVMContext& C);
133 explicit Module(const std::string &ModuleID, LLVMContext& C);
134134 /// The module destructor. This will dropAllReferences.
135135 ~Module();
136136
161161
162162 /// Get the global data context.
163163 /// @returns LLVMContext - a container for LLVM's global information
164 const LLVMContext& getContext() const { return Context; }
164 LLVMContext& getContext() const { return Context; }
165165
166166 /// Get any module-scope inline assembly blocks.
167167 /// @returns a string containing the module-scope inline assembly blocks.
137137 // Archive constructor - this is the only constructor that gets used for the
138138 // Archive class. Everything else (default,copy) is deprecated. This just
139139 // initializes and maps the file into memory, if requested.
140 Archive::Archive(const sys::Path& filename, const LLVMContext& C)
140 Archive::Archive(const sys::Path& filename, LLVMContext& C)
141141 : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
142142 symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
143143 }
207207
208208 // Get just the externally visible defined symbols from the bitcode
209209 bool llvm::GetBitcodeSymbols(const sys::Path& fName,
210 const LLVMContext& Context,
210 LLVMContext& Context,
211211 std::vector& symbols,
212212 std::string* ErrMsg) {
213213 std::auto_ptr Buffer(
239239 ModuleProvider*
240240 llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
241241 const std::string& ModuleID,
242 const LLVMContext& Context,
242 LLVMContext& Context,
243243 std::vector& symbols,
244244 std::string* ErrMsg) {
245245 // Get the module provider
7272
7373 // Get just the externally visible defined symbols from the bitcode
7474 bool GetBitcodeSymbols(const sys::Path& fName,
75 const LLVMContext& Context,
75 LLVMContext& Context,
7676 std::vector& symbols,
7777 std::string* ErrMsg);
7878
7979 ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
8080 const std::string& ModuleID,
81 const LLVMContext& Context,
81 LLVMContext& Context,
8282 std::vector& symbols,
8383 std::string* ErrMsg);
8484 }
326326
327327 // Open and completely load the archive file.
328328 Archive*
329 Archive::OpenAndLoad(const sys::Path& file, const LLVMContext& C,
329 Archive::OpenAndLoad(const sys::Path& file, LLVMContext& C,
330330 std::string* ErrorMessage) {
331331 std::auto_ptr result ( new Archive(file, C));
332332 if (result->mapToMemory(ErrorMessage))
441441
442442 // Open the archive and load just the symbol tables
443443 Archive* Archive::OpenAndLoadSymbols(const sys::Path& file,
444 const LLVMContext& C,
444 LLVMContext& C,
445445 std::string* ErrorMessage) {
446446 std::auto_ptr result ( new Archive(file, C) );
447447 if (result->mapToMemory(ErrorMessage))
6363 }
6464
6565 // Create an empty archive.
66 Archive* Archive::CreateEmpty(const sys::Path& FilePath, const LLVMContext& C) {
66 Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext& C) {
6767 Archive* result = new Archive(FilePath, C);
6868 return result;
6969 }
2020 using namespace llvm;
2121
2222 Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err,
23 const LLVMContext& Context) {
23 LLVMContext& Context) {
2424 Err.setFilename(Filename);
2525
2626 std::string ErrorStr;
3838 }
3939
4040 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
41 ParseError &Err, const LLVMContext& Context) {
41 ParseError &Err, LLVMContext& Context) {
4242 Err.setFilename("");
4343
4444 OwningPtr
20892089 /// getBitcodeModuleProvider - lazy function-at-a-time loading from a file.
20902090 ///
20912091 ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
2092 const LLVMContext& Context,
2092 LLVMContext& Context,
20932093 std::string *ErrMsg) {
20942094 BitcodeReader *R = new BitcodeReader(Buffer, Context);
20952095 if (R->ParseBitcode()) {
21062106
21072107 /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
21082108 /// If an error occurs, return null and fill in *ErrMsg if non-null.
2109 Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, const LLVMContext& Context,
2109 Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
21102110 std::string *ErrMsg){
21112111 BitcodeReader *R;
21122112 R = static_cast(getBitcodeModuleProvider(Buffer, Context,
8585 };
8686
8787 class BitcodeReader : public ModuleProvider {
88 const LLVMContext& Context;
88 LLVMContext& Context;
8989 MemoryBuffer *Buffer;
9090 BitstreamReader StreamFile;
9191 BitstreamCursor Stream;
124124 /// stream) and what linkage the original function had.
125125 DenseMap > DeferredFunctionInfo;
126126 public:
127 explicit BitcodeReader(MemoryBuffer *buffer, const LLVMContext& C)
127 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C)
128128 : Context(C), Buffer(buffer), ErrorString(0) {
129129 HasReversedFunctionsWithBodies = false;
130130 }
4646
4747 static Module *
4848 getMaterializedModuleProvider(const std::string &Filename,
49 const LLVMContext& C) {
49 LLVMContext& C) {
5050 std::auto_ptr Buffer;
5151 Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
5252 if (Buffer.get())
5858 /// the PATH for the specified program, loading it when found. If the
5959 /// specified program cannot be found, an exception is thrown to indicate the
6060 /// error.
61 void Debugger::loadProgram(const std::string &Filename, const LLVMContext& C) {
61 void Debugger::loadProgram(const std::string &Filename, LLVMContext& C) {
6262 if ((Program = getMaterializedModuleProvider(Filename, C)) ||
6363 (Program = getMaterializedModuleProvider(Filename+".bc", C)))
6464 return; // Successfully loaded the program.
1919 using namespace llvm;
2020
2121 Linker::Linker(const std::string& progname, const std::string& modname,
22 const LLVMContext& C, unsigned flags):
22 LLVMContext& C, unsigned flags):
2323 Context(C),
2424 Composite(new Module(modname, C)),
2525 LibPaths(),
2121
2222 static ManagedStatic GlobalContext;
2323
24 const LLVMContext& llvm::getGlobalContext() {
24 LLVMContext& llvm::getGlobalContext() {
2525 return *GlobalContext;
2626 }
2727
5454 // Primitive Module methods.
5555 //
5656
57 Module::Module(const std::string &MID, const LLVMContext& C)
57 Module::Module(const std::string &MID, LLVMContext& C)
5858 : Context(C), ModuleID(MID), DataLayout("") {
5959 ValSymTab = new ValueSymbolTable();
6060 TypeSymTab = new TypeSymbolTable();
6464
6565 BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
6666 unsigned timeout, unsigned memlimit,
67 const LLVMContext& ctxt)
67 LLVMContext& ctxt)
6868 : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile),
6969 Program(0), Interpreter(0), SafeInterpreter(0), gcc(0),
7070 run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout),
7575 /// return it, or return null if not possible.
7676 ///
7777 Module *llvm::ParseInputFile(const std::string &Filename,
78 const LLVMContext& Ctxt) {
78 LLVMContext& Ctxt) {
7979 std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
8080 Module *Result = 0;
8181 if (Buffer.get())
4242 extern bool BugpointIsInterrupted;
4343
4444 class BugDriver {
45 const LLVMContext& Context;
45 LLVMContext& Context;
4646 const std::string ToolName; // Name of bugpoint
4747 std::string ReferenceOutputFile; // Name of `good' output file
4848 Module *Program; // The raw program, linked together
6161
6262 public:
6363 BugDriver(const char *toolname, bool as_child, bool find_bugs,
64 unsigned timeout, unsigned memlimit, const LLVMContext& ctxt);
64 unsigned timeout, unsigned memlimit, LLVMContext& ctxt);
6565
6666 const std::string &getToolName() const { return ToolName; }
6767
68 const LLVMContext& getContext() { return Context; }
68 LLVMContext& getContext() { return Context; }
6969
7070 // Set up methods... these methods are used to copy information about the
7171 // command line arguments into instance variables of BugDriver.
294294 /// return it, or return null if not possible.
295295 ///
296296 Module *ParseInputFile(const std::string &InputFilename,
297 const LLVMContext& ctxt);
297 LLVMContext& ctxt);
298298
299299
300300 /// getPassesString - Turn a list of passes into a string which indicates the
2121 /// CLIDebugger constructor - This initializes the debugger to its default
2222 /// state, and initializes the command table.
2323 ///
24 CLIDebugger::CLIDebugger(const LLVMContext& ctxt)
24 CLIDebugger::CLIDebugger(LLVMContext& ctxt)
2525 : Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0),
2626 Prompt("(llvm-db) "), ListSize(10) {
2727 // Initialize instance variables
2828 /// CLIDebugger - This class implements the command line interface for the
2929 /// LLVM debugger.
3030 class CLIDebugger {
31 const LLVMContext& Context;
31 LLVMContext& Context;
3232
3333 /// Dbg - The low-level LLVM debugger object that we use to do our dirty
3434 /// work.
8181 const SourceLanguage *CurrentLanguage;
8282
8383 public:
84 CLIDebugger(const LLVMContext& ctxt);
84 CLIDebugger(LLVMContext& ctxt);
8585
8686 /// getDebugger - Return the current LLVM debugger implementation being
8787 /// used.
4848 // searches the link path for the specified file to try to find it...
4949 //
5050 static inline std::auto_ptr LoadFile(const std::string &FN,
51 const LLVMContext& Context) {
51 LLVMContext& Context) {
5252 sys::Path Filename;
5353 if (!Filename.set(FN)) {
5454 cerr << "Invalid file name: '" << FN << "'\n";
6868 }
6969
7070
71 LTOCodeGenerator::LTOCodeGenerator(const LLVMContext& Context)
71 LTOCodeGenerator::LTOCodeGenerator(LLVMContext& Context)
7272 : _context(Context),
7373 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
7474 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
3030 public:
3131 static const char* getVersionString();
3232
33 LTOCodeGenerator(const llvm::LLVMContext& Context);
33 LTOCodeGenerator(llvm::LLVMContext& Context);
3434 ~LTOCodeGenerator();
3535
3636 bool addModule(class LTOModule*, std::string& errMsg);
5353
5454 typedef llvm::StringMap StringSet;
5555
56 const llvm::LLVMContext& _context;
56 llvm::LLVMContext& _context;
5757 llvm::Linker _linker;
5858 llvm::TargetMachine* _target;
5959 bool _emitDwarfDebugInfo;
8686 }
8787
8888 LTOModule* LTOModule::makeLTOModule(const char* path,
89 const LLVMContext& Context,
89 LLVMContext& Context,
9090 std::string& errMsg)
9191 {
9292 OwningPtr buffer(MemoryBuffer::getFile(path, &errMsg));
112112
113113
114114 LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
115 const LLVMContext& Context,
115 LLVMContext& Context,
116116 std::string& errMsg)
117117 {
118118 OwningPtr buffer(makeBuffer(mem, length));
141141 }
142142
143143 LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
144 const LLVMContext& Context,
144 LLVMContext& Context,
145145 std::string& errMsg)
146146 {
147147 // parse bitcode buffer
5151 const char* triplePrefix);
5252
5353 static LTOModule* makeLTOModule(const char* path,
54 const llvm::LLVMContext& Context,
54 llvm::LLVMContext& Context,
5555 std::string& errMsg);
5656 static LTOModule* makeLTOModule(const void* mem, size_t length,
57 const llvm::LLVMContext& Context,
57 llvm::LLVMContext& Context,
5858 std::string& errMsg);
5959
6060 const char* getTargetTriple();
9090 const char* triplePrefix);
9191
9292 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
93 const llvm::LLVMContext& Context,
93 llvm::LLVMContext& Context,
9494 std::string& errMsg);
9595 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
9696