LLVM  4.0.0
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 struct SlotMapping;
25 class SMDiagnostic;
26 class Type;
27 
28 /// This function is the main interface to the LLVM Assembly Parser. It parses
29 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
30 /// Module (intermediate representation) with the corresponding features. Note
31 /// that this does not verify that the generated Module is valid, so you should
32 /// run the verifier after parsing the file to check that it is okay.
33 /// \brief Parse LLVM Assembly from a file
34 /// \param Filename The name of the file to parse
35 /// \param Error Error result info.
36 /// \param Context Context in which to allocate globals info.
37 /// \param Slots The optional slot mapping that will be initialized during
38 /// parsing.
39 std::unique_ptr<Module> parseAssemblyFile(StringRef Filename,
40  SMDiagnostic &Error,
41  LLVMContext &Context,
42  SlotMapping *Slots = nullptr);
43 
44 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
45 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
46 /// Module (intermediate representation) with the corresponding features. Note
47 /// that this does not verify that the generated Module is valid, so you should
48 /// run the verifier after parsing the file to check that it is okay.
49 /// \brief Parse LLVM Assembly from a string
50 /// \param AsmString The string containing assembly
51 /// \param Error Error result info.
52 /// \param Context Context in which to allocate globals info.
53 /// \param Slots The optional slot mapping that will be initialized during
54 /// parsing.
55 std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
56  SMDiagnostic &Error,
57  LLVMContext &Context,
58  SlotMapping *Slots = nullptr);
59 
60 /// parseAssemblyFile and parseAssemblyString are wrappers around this function.
61 /// \brief Parse LLVM Assembly from a MemoryBuffer.
62 /// \param F The MemoryBuffer containing assembly
63 /// \param Err Error result info.
64 /// \param Slots The optional slot mapping that will be initialized during
65 /// parsing.
66 std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
67  LLVMContext &Context,
68  SlotMapping *Slots = nullptr);
69 
70 /// This function is the low-level interface to the LLVM Assembly Parser.
71 /// This is kept as an independent function instead of being inlined into
72 /// parseAssembly for the convenience of interactive users that want to add
73 /// recently parsed bits to an existing module.
74 ///
75 /// \param F The MemoryBuffer containing assembly
76 /// \param M The module to add data to.
77 /// \param Err Error result info.
78 /// \param Slots The optional slot mapping that will be initialized during
79 /// parsing.
80 /// \return true on error.
81 bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
82  SlotMapping *Slots = nullptr);
83 
84 /// Parse a type and a constant value in the given string.
85 ///
86 /// The constant value can be any LLVM constant, including a constant
87 /// expression.
88 ///
89 /// \param Slots The optional slot mapping that will restore the parsing state
90 /// of the module.
91 /// \return null on error.
92 Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
93  const SlotMapping *Slots = nullptr);
94 
95 /// Parse a type in the given string.
96 ///
97 /// \param Slots The optional slot mapping that will restore the parsing state
98 /// of the module.
99 /// \return null on error.
100 Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
101  const SlotMapping *Slots = nullptr);
102 
103 /// Parse a string \p Asm that starts with a type.
104 /// \p Read[out] gives the number of characters that have been read to parse
105 /// the type in \p Asm.
106 ///
107 /// \param Slots The optional slot mapping that will restore the parsing state
108 /// of the module.
109 /// \return null on error.
110 Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
111  const Module &M, const SlotMapping *Slots = nullptr);
112 
113 } // End llvm namespace
114 
115 #endif
LLVMContext & Context
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:70
#define F(x, y, z)
Definition: MD5.cpp:51
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:34
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:98
bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err, SlotMapping *Slots=nullptr)
This function is the low-level interface to the LLVM Assembly Parser.
Definition: Parser.cpp:25
std::unique_ptr< Module > parseAssemblyFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, SlotMapping *Slots=nullptr)
This function is the main interface to the LLVM Assembly Parser.
Definition: Parser.cpp:47
std::unique_ptr< Module > parseAssemblyString(StringRef AsmString, SMDiagnostic &Error, LLVMContext &Context, SlotMapping *Slots=nullptr)
The function is a secondary interface to the LLVM Assembly Parser.
Definition: Parser.cpp:62
Type * parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type in the given string.
Definition: Parser.cpp:82