blob: 285a7c022a24a95951c175936494d145c034b60a [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- 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
17#include "llvm/Support/MemoryBuffer.h"
18
19namespace llvm {
20
21class Constant;
22class LLVMContext;
23class Module;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010024class ModuleSummaryIndex;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025struct SlotMapping;
26class SMDiagnostic;
27class Type;
28
Andrew Scullcdfcccc2018-10-05 20:58:37 +010029/// This function is a main interface to the LLVM Assembly Parser. It parses
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030/// 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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010034/// Parse LLVM Assembly from a file
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010035/// \param Filename The name of the file to parse
Andrew Scullcdfcccc2018-10-05 20:58:37 +010036/// \param Err Error result info.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037/// \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.
44std::unique_ptr<Module>
Andrew Scullcdfcccc2018-10-05 20:58:37 +010045parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046 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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010054/// Parse LLVM Assembly from a string
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010055/// \param AsmString The string containing assembly
Andrew Scullcdfcccc2018-10-05 20:58:37 +010056/// \param Err Error result info.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010057/// \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.
64std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
Andrew Scullcdfcccc2018-10-05 20:58:37 +010065 SMDiagnostic &Err,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010066 LLVMContext &Context,
67 SlotMapping *Slots = nullptr,
68 bool UpgradeDebugInfo = true,
69 StringRef DataLayoutString = "");
70
Andrew Scullcdfcccc2018-10-05 20:58:37 +010071/// Holds the Module and ModuleSummaryIndex returned by the interfaces
72/// that parse both.
73struct ParsedModuleAndIndex {
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.
94ParsedModuleAndIndex
95parseAssemblyFileWithIndex(StringRef Filename, SMDiagnostic &Err,
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.
108std::unique_ptr<ModuleSummaryIndex>
109parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err);
110
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100111/// parseAssemblyFile and parseAssemblyString are wrappers around this function.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100112/// Parse LLVM Assembly from a MemoryBuffer.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100113/// \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.
121std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
122 LLVMContext &Context,
123 SlotMapping *Slots = nullptr,
124 bool UpgradeDebugInfo = true,
125 StringRef DataLayoutString = "");
126
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100127/// 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.
139ParsedModuleAndIndex parseAssemblyWithIndex(MemoryBufferRef F,
140 SMDiagnostic &Err,
141 LLVMContext &Context,
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.
152std::unique_ptr<ModuleSummaryIndex>
153parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err);
154
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100155/// 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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100162/// \param Index The index to add data to.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100163/// \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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100171bool parseAssemblyInto(MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index,
172 SMDiagnostic &Err, SlotMapping *Slots = nullptr,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100173 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.
184Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
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.
192Type *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.
202Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
203 const Module &M, const SlotMapping *Slots = nullptr);
204
205} // End llvm namespace
206
207#endif