1 //===-- Parser.h - Parser for LLVM IR text assembly files -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes are implemented by the lib/AsmParser library.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ASMPARSER_PARSER_H
15 #define LLVM_ASMPARSER_PARSER_H
17 #include "llvm/Support/MemoryBuffer.h"
24 class ModuleSummaryIndex;
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 Error 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
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 = "");
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 Error 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
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,
67 SlotMapping *Slots = nullptr,
68 bool UpgradeDebugInfo = true,
69 StringRef DataLayoutString = "");
71 /// Holds the Module and ModuleSummaryIndex returned by the interfaces
73 struct ParsedModuleAndIndex {
74 std::unique_ptr<Module> Mod;
75 std::unique_ptr<ModuleSummaryIndex> Index;
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 Error 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
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.
95 parseAssemblyFileWithIndex(StringRef Filename, SMDiagnostic &Err,
96 LLVMContext &Context, SlotMapping *Slots = nullptr,
97 bool UpgradeDebugInfo = true,
98 StringRef DataLayoutString = "");
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 Error Error result info.
108 std::unique_ptr<ModuleSummaryIndex>
109 parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err);
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
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,
122 LLVMContext &Context,
123 SlotMapping *Slots = nullptr,
124 bool UpgradeDebugInfo = true,
125 StringRef DataLayoutString = "");
127 /// Parse LLVM Assembly including the summary index from a MemoryBuffer.
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
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.
138 /// parseAssemblyFileWithIndex is a wrapper around this function.
139 ParsedModuleAndIndex parseAssemblyWithIndex(MemoryBufferRef F,
141 LLVMContext &Context,
142 SlotMapping *Slots = nullptr,
143 bool UpgradeDebugInfo = true,
144 StringRef DataLayoutString = "");
146 /// Parse LLVM Assembly for summary index from a MemoryBuffer.
148 /// \param F The MemoryBuffer containing assembly with summary
149 /// \param Err Error result info.
151 /// parseSummaryIndexAssemblyFile is a wrapper around this function.
152 std::unique_ptr<ModuleSummaryIndex>
153 parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err);
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.
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
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.
171 bool parseAssemblyInto(MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index,
172 SMDiagnostic &Err, SlotMapping *Slots = nullptr,
173 bool UpgradeDebugInfo = true,
174 StringRef DataLayoutString = "");
176 /// Parse a type and a constant value in the given string.
178 /// The constant value can be any LLVM constant, including a constant
181 /// \param Slots The optional slot mapping that will restore the parsing state
183 /// \return null on error.
184 Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
185 const SlotMapping *Slots = nullptr);
187 /// Parse a type in the given string.
189 /// \param Slots The optional slot mapping that will restore the parsing state
191 /// \return null on error.
192 Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
193 const SlotMapping *Slots = nullptr);
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.
199 /// \param Slots The optional slot mapping that will restore the parsing state
201 /// \return null on error.
202 Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
203 const Module &M, const SlotMapping *Slots = nullptr);
205 } // End llvm namespace