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