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"
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
39 std::unique_ptr<Module> parseAssemblyFile(StringRef Filename,
42 SlotMapping *Slots = nullptr);
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
55 std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
58 SlotMapping *Slots = nullptr);
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
66 std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
68 SlotMapping *Slots = nullptr);
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.
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
80 /// \return true on error.
81 bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
82 SlotMapping *Slots = nullptr);
84 /// Parse a type and a constant value in the given string.
86 /// The constant value can be any LLVM constant, including a constant
89 /// \param Slots The optional slot mapping that will restore the parsing state
91 /// \return null on error.
92 Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
93 const SlotMapping *Slots = nullptr);
95 /// Parse a type in the given string.
97 /// \param Slots The optional slot mapping that will restore the parsing state
99 /// \return null on error.
100 Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
101 const SlotMapping *Slots = nullptr);
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.
107 /// \param Slots The optional slot mapping that will restore the parsing state
109 /// \return null on error.
110 Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
111 const Module &M, const SlotMapping *Slots = nullptr);
113 } // End llvm namespace