AsmParser: Save and restore the parsing state for types using SlotMapping.
[oota-llvm.git] / include / llvm / AsmParser / Parser.h
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
17 #include "llvm/Support/MemoryBuffer.h"
18
19 namespace llvm {
20
21 class Constant;
22 class LLVMContext;
23 class Module;
24 struct SlotMapping;
25 class SMDiagnostic;
26
27 /// This function is the main interface to the LLVM Assembly Parser. It parses
28 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
29 /// Module (intermediate representation) with the corresponding features. Note
30 /// that this does not verify that the generated Module is valid, so you should
31 /// run the verifier after parsing the file to check that it is okay.
32 /// \brief Parse LLVM Assembly from a file
33 /// \param Filename The name of the file to parse
34 /// \param Error Error result info.
35 /// \param Context Context in which to allocate globals info.
36 /// \param Slots The optional slot mapping that will be initialized during
37 ///              parsing.
38 std::unique_ptr<Module> parseAssemblyFile(StringRef Filename,
39                                           SMDiagnostic &Error,
40                                           LLVMContext &Context,
41                                           SlotMapping *Slots = nullptr);
42
43 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
44 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
45 /// Module (intermediate representation) with the corresponding features. Note
46 /// that this does not verify that the generated Module is valid, so you should
47 /// run the verifier after parsing the file to check that it is okay.
48 /// \brief Parse LLVM Assembly from a string
49 /// \param AsmString The string containing assembly
50 /// \param Error Error result info.
51 /// \param Context Context in which to allocate globals info.
52 /// \param Slots The optional slot mapping that will be initialized during
53 ///              parsing.
54 std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
55                                             SMDiagnostic &Error,
56                                             LLVMContext &Context,
57                                             SlotMapping *Slots = nullptr);
58
59 /// parseAssemblyFile and parseAssemblyString are wrappers around this function.
60 /// \brief Parse LLVM Assembly from a MemoryBuffer.
61 /// \param F The MemoryBuffer containing assembly
62 /// \param Err Error result info.
63 /// \param Slots The optional slot mapping that will be initialized during
64 ///              parsing.
65 std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
66                                       LLVMContext &Context,
67                                       SlotMapping *Slots = nullptr);
68
69 /// This function is the low-level interface to the LLVM Assembly Parser.
70 /// This is kept as an independent function instead of being inlined into
71 /// parseAssembly for the convenience of interactive users that want to add
72 /// recently parsed bits to an existing module.
73 ///
74 /// \param F The MemoryBuffer containing assembly
75 /// \param M The module to add data to.
76 /// \param Err Error result info.
77 /// \param Slots The optional slot mapping that will be initialized during
78 ///              parsing.
79 /// \return true on error.
80 bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
81                        SlotMapping *Slots = nullptr);
82
83 /// Parse a type and a constant value in the given string.
84 ///
85 /// The constant value can be any LLVM constant, including a constant
86 /// expression.
87 ///
88 /// \param Slots The optional slot mapping that will restore the parsing state
89 /// of the module.
90 /// \return null on error.
91 Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
92                              const SlotMapping *Slots = nullptr);
93
94 } // End llvm namespace
95
96 #endif