LLVM  6.0.0svn
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 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
40 /// This option should only be set to false by llvm-as
41 /// for use inside the LLVM testuite!
42 std::unique_ptr<Module>
43 parseAssemblyFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
44  SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true);
45 
46 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
47 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
48 /// Module (intermediate representation) with the corresponding features. Note
49 /// that this does not verify that the generated Module is valid, so you should
50 /// run the verifier after parsing the file to check that it is okay.
51 /// \brief Parse LLVM Assembly from a string
52 /// \param AsmString The string containing assembly
53 /// \param Error Error result info.
54 /// \param Context Context in which to allocate globals info.
55 /// \param Slots The optional slot mapping that will be initialized during
56 /// parsing.
57 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
58 /// This option should only be set to false by llvm-as
59 /// for use inside the LLVM testuite!
60 std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
61  SMDiagnostic &Error,
62  LLVMContext &Context,
63  SlotMapping *Slots = nullptr,
64  bool UpgradeDebugInfo = true);
65 
66 /// parseAssemblyFile and parseAssemblyString are wrappers around this function.
67 /// \brief Parse LLVM Assembly from a MemoryBuffer.
68 /// \param F The MemoryBuffer containing assembly
69 /// \param Err Error result info.
70 /// \param Slots The optional slot mapping that will be initialized during
71 /// parsing.
72 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
73 /// This option should only be set to false by llvm-as
74 /// for use inside the LLVM testuite!
75 std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
76  LLVMContext &Context,
77  SlotMapping *Slots = nullptr,
78  bool UpgradeDebugInfo = true);
79 
80 /// This function is the low-level interface to the LLVM Assembly Parser.
81 /// This is kept as an independent function instead of being inlined into
82 /// parseAssembly for the convenience of interactive users that want to add
83 /// recently parsed bits to an existing module.
84 ///
85 /// \param F The MemoryBuffer containing assembly
86 /// \param M The module to add data to.
87 /// \param Err Error result info.
88 /// \param Slots The optional slot mapping that will be initialized during
89 /// parsing.
90 /// \return true on error.
91 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
92 /// This option should only be set to false by llvm-as
93 /// for use inside the LLVM testuite!
94 bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
95  SlotMapping *Slots = nullptr,
96  bool UpgradeDebugInfo = true);
97 
98 /// Parse a type and a constant value in the given string.
99 ///
100 /// The constant value can be any LLVM constant, including a constant
101 /// expression.
102 ///
103 /// \param Slots The optional slot mapping that will restore the parsing state
104 /// of the module.
105 /// \return null on error.
106 Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
107  const SlotMapping *Slots = nullptr);
108 
109 /// Parse a type in the given string.
110 ///
111 /// \param Slots The optional slot mapping that will restore the parsing state
112 /// of the module.
113 /// \return null on error.
114 Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
115  const SlotMapping *Slots = nullptr);
116 
117 /// Parse a string \p Asm that starts with a type.
118 /// \p Read[out] gives the number of characters that have been read to parse
119 /// the type in \p Asm.
120 ///
121 /// \param Slots The optional slot mapping that will restore the parsing state
122 /// of the module.
123 /// \return null on error.
124 Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
125  const Module &M, const SlotMapping *Slots = nullptr);
126 
127 } // End llvm namespace
128 
129 #endif
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:35
bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true)
This function is the low-level interface to the LLVM Assembly Parser.
Definition: Parser.cpp:25
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
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:72
F(f)
std::unique_ptr< Module > parseAssemblyFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true)
This function is the main interface to the LLVM Assembly Parser.
Definition: Parser.cpp:46
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:100
std::unique_ptr< Module > parseAssemblyString(StringRef AsmString, SMDiagnostic &Error, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true)
The function is a secondary interface to the LLVM Assembly Parser.
Definition: Parser.cpp:63
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
Type * parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type in the given string.
Definition: Parser.cpp:84