LLVM  8.0.1
Parser.h
Go to the documentation of this file.
1 //===-- Parser.h - Parser for LLVM IR text assembly files -------*- 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 // These classes are implemented by the lib/AsmParser library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ASMPARSER_PARSER_H
15 #define LLVM_ASMPARSER_PARSER_H
16 
18 
19 namespace llvm {
20 
21 class Constant;
22 class LLVMContext;
23 class Module;
24 class ModuleSummaryIndex;
25 struct SlotMapping;
26 class SMDiagnostic;
27 class Type;
28 
29 /// This function is a main interface to the LLVM Assembly Parser. It parses
30 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
31 /// Module (intermediate representation) with the corresponding features. Note
32 /// that this does not verify that the generated Module is valid, so you should
33 /// run the verifier after parsing the file to check that it is okay.
34 /// Parse LLVM Assembly from a file
35 /// \param Filename The name of the file to parse
36 /// \param Err Error result info.
37 /// \param Context Context in which to allocate globals info.
38 /// \param Slots The optional slot mapping that will be initialized during
39 /// parsing.
40 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
41 /// This option should only be set to false by llvm-as
42 /// for use inside the LLVM testuite!
43 /// \param DataLayoutString Override datalayout in the llvm assembly.
44 std::unique_ptr<Module>
45 parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
46  SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true,
47  StringRef DataLayoutString = "");
48 
49 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
50 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
51 /// Module (intermediate representation) with the corresponding features. Note
52 /// that this does not verify that the generated Module is valid, so you should
53 /// run the verifier after parsing the file to check that it is okay.
54 /// Parse LLVM Assembly from a string
55 /// \param AsmString The string containing assembly
56 /// \param Err Error result info.
57 /// \param Context Context in which to allocate globals info.
58 /// \param Slots The optional slot mapping that will be initialized during
59 /// parsing.
60 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
61 /// This option should only be set to false by llvm-as
62 /// for use inside the LLVM testuite!
63 /// \param DataLayoutString Override datalayout in the llvm assembly.
64 std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
65  SMDiagnostic &Err,
66  LLVMContext &Context,
67  SlotMapping *Slots = nullptr,
68  bool UpgradeDebugInfo = true,
69  StringRef DataLayoutString = "");
70 
71 /// Holds the Module and ModuleSummaryIndex returned by the interfaces
72 /// that parse both.
74  std::unique_ptr<Module> Mod;
75  std::unique_ptr<ModuleSummaryIndex> Index;
76 };
77 
78 /// This function is a main interface to the LLVM Assembly Parser. It parses
79 /// an ASCII file that (presumably) contains LLVM Assembly code, including
80 /// a module summary. It returns a Module (intermediate representation) and
81 /// a ModuleSummaryIndex with the corresponding features. Note that this does
82 /// not verify that the generated Module or Index are valid, so you should
83 /// run the verifier after parsing the file to check that they are okay.
84 /// Parse LLVM Assembly from a file
85 /// \param Filename The name of the file to parse
86 /// \param Err Error result info.
87 /// \param Context Context in which to allocate globals info.
88 /// \param Slots The optional slot mapping that will be initialized during
89 /// parsing.
90 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
91 /// This option should only be set to false by llvm-as
92 /// for use inside the LLVM testuite!
93 /// \param DataLayoutString Override datalayout in the llvm assembly.
96  LLVMContext &Context, SlotMapping *Slots = nullptr,
97  bool UpgradeDebugInfo = true,
98  StringRef DataLayoutString = "");
99 
100 /// This function is a main interface to the LLVM Assembly Parser. It parses
101 /// an ASCII file that (presumably) contains LLVM Assembly code for a module
102 /// summary. It returns a a ModuleSummaryIndex with the corresponding features.
103 /// Note that this does not verify that the generated Index is valid, so you
104 /// should run the verifier after parsing the file to check that it is okay.
105 /// Parse LLVM Assembly Index from a file
106 /// \param Filename The name of the file to parse
107 /// \param Err Error result info.
108 std::unique_ptr<ModuleSummaryIndex>
110 
111 /// parseAssemblyFile and parseAssemblyString are wrappers around this function.
112 /// Parse LLVM Assembly from a MemoryBuffer.
113 /// \param F The MemoryBuffer containing assembly
114 /// \param Err Error result info.
115 /// \param Slots The optional slot mapping that will be initialized during
116 /// parsing.
117 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
118 /// This option should only be set to false by llvm-as
119 /// for use inside the LLVM testuite!
120 /// \param DataLayoutString Override datalayout in the llvm assembly.
121 std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
123  SlotMapping *Slots = nullptr,
124  bool UpgradeDebugInfo = true,
125  StringRef DataLayoutString = "");
126 
127 /// Parse LLVM Assembly including the summary index from a MemoryBuffer.
128 ///
129 /// \param F The MemoryBuffer containing assembly with summary
130 /// \param Err Error result info.
131 /// \param Slots The optional slot mapping that will be initialized during
132 /// parsing.
133 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
134 /// This option should only be set to false by llvm-as
135 /// for use inside the LLVM testuite!
136 /// \param DataLayoutString Override datalayout in the llvm assembly.
137 ///
138 /// parseAssemblyFileWithIndex is a wrapper around this function.
140  SMDiagnostic &Err,
142  SlotMapping *Slots = nullptr,
143  bool UpgradeDebugInfo = true,
144  StringRef DataLayoutString = "");
145 
146 /// Parse LLVM Assembly for summary index from a MemoryBuffer.
147 ///
148 /// \param F The MemoryBuffer containing assembly with summary
149 /// \param Err Error result info.
150 ///
151 /// parseSummaryIndexAssemblyFile is a wrapper around this function.
152 std::unique_ptr<ModuleSummaryIndex>
154 
155 /// This function is the low-level interface to the LLVM Assembly Parser.
156 /// This is kept as an independent function instead of being inlined into
157 /// parseAssembly for the convenience of interactive users that want to add
158 /// recently parsed bits to an existing module.
159 ///
160 /// \param F The MemoryBuffer containing assembly
161 /// \param M The module to add data to.
162 /// \param Index The index to add data to.
163 /// \param Err Error result info.
164 /// \param Slots The optional slot mapping that will be initialized during
165 /// parsing.
166 /// \return true on error.
167 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
168 /// This option should only be set to false by llvm-as
169 /// for use inside the LLVM testuite!
170 /// \param DataLayoutString Override datalayout in the llvm assembly.
172  SMDiagnostic &Err, SlotMapping *Slots = nullptr,
173  bool UpgradeDebugInfo = true,
174  StringRef DataLayoutString = "");
175 
176 /// Parse a type and a constant value in the given string.
177 ///
178 /// The constant value can be any LLVM constant, including a constant
179 /// expression.
180 ///
181 /// \param Slots The optional slot mapping that will restore the parsing state
182 /// of the module.
183 /// \return null on error.
185  const SlotMapping *Slots = nullptr);
186 
187 /// Parse a type in the given string.
188 ///
189 /// \param Slots The optional slot mapping that will restore the parsing state
190 /// of the module.
191 /// \return null on error.
192 Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
193  const SlotMapping *Slots = nullptr);
194 
195 /// Parse a string \p Asm that starts with a type.
196 /// \p Read[out] gives the number of characters that have been read to parse
197 /// the type in \p Asm.
198 ///
199 /// \param Slots The optional slot mapping that will restore the parsing state
200 /// of the module.
201 /// \return null on error.
202 Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
203  const Module &M, const SlotMapping *Slots = nullptr);
204 
205 } // End llvm namespace
206 
207 #endif
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
Definition: Parser.cpp:148
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
F(f)
std::unique_ptr< Module > parseAssemblyString(StringRef AsmString, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
The function is a secondary interface to the LLVM Assembly Parser.
Definition: Parser.cpp:103
std::unique_ptr< ModuleSummaryIndex > parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err)
This function is a main interface to the LLVM Assembly Parser.
Definition: Parser.cpp:136
std::unique_ptr< Module > Mod
Definition: Parser.h:74
Type * parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a string Asm that starts with a type.
Definition: Parser.cpp:176
Class to hold module path string table and global value map, and encapsulate methods for operating on...
std::unique_ptr< ModuleSummaryIndex > parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err)
Parse LLVM Assembly for summary index from a MemoryBuffer.
Definition: Parser.cpp:125
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:42
bool parseAssemblyInto(MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index, SMDiagnostic &Err, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
This function is the low-level interface to the LLVM Assembly Parser.
Definition: Parser.cpp:26
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
std::unique_ptr< Module > parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
This function is a main interface to the LLVM Assembly Parser.
Definition: Parser.cpp:56
This is an important base class in LLVM.
Definition: Constant.h:42
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
ParsedModuleAndIndex parseAssemblyWithIndex(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
Parse LLVM Assembly including the summary index from a MemoryBuffer.
Definition: Parser.cpp:71
ParsedModuleAndIndex parseAssemblyFileWithIndex(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
This function is a main interface to the LLVM Assembly Parser.
Definition: Parser.cpp:86
std::unique_ptr< ModuleSummaryIndex > Index
Definition: Parser.h:75
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:33
Holds the Module and ModuleSummaryIndex returned by the interfaces that parse both.
Definition: Parser.h:73
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Type * parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type in the given string.
Definition: Parser.cpp:160
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260