Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- llvm/Assembly/Parser.h - Parser for VM assembly files ---*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 84e66db | 2007-12-29 19:59:42 +0000 | [diff] [blame^] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // These classes are implemented by the lib/AsmParser library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_ASSEMBLY_PARSER_H |
| 15 | #define LLVM_ASSEMBLY_PARSER_H |
| 16 | |
| 17 | #include <string> |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | class Module; |
| 22 | class ParseError; |
| 23 | |
| 24 | |
| 25 | /// This function is the main interface to the LLVM Assembly Parse. It parses |
| 26 | /// an ascii file that (presumably) contains LLVM Assembly code. It returns a |
| 27 | /// Module (intermediate representation) with the corresponding features. Note |
| 28 | /// that this does not verify that the generated Module is valid, so you should |
| 29 | /// run the verifier after parsing the file to check that it is okay. |
| 30 | /// @brief Parse LLVM Assembly from a file |
| 31 | Module *ParseAssemblyFile( |
| 32 | const std::string &Filename, ///< The name of the file to parse |
| 33 | ParseError* Error = 0 ///< If not null, an object to return errors in. |
| 34 | ); |
| 35 | |
| 36 | /// The function is a secondary interface to the LLVM Assembly Parse. It parses |
| 37 | /// an ascii string that (presumably) contains LLVM Assembly code. It returns a |
| 38 | /// Module (intermediate representation) with the corresponding features. Note |
| 39 | /// that this does not verify that the generated Module is valid, so you should |
| 40 | /// run the verifier after parsing the file to check that it is okay. |
| 41 | /// @brief Parse LLVM Assembly from a string |
| 42 | Module *ParseAssemblyString( |
| 43 | const char * AsmString, ///< The string containing assembly |
| 44 | Module * M, ///< A module to add the assembly too. |
| 45 | ParseError* Error = 0 ///< If not null, an object to return errors in. |
| 46 | ); |
| 47 | |
| 48 | //===------------------------------------------------------------------------=== |
| 49 | // Helper Classes |
| 50 | //===------------------------------------------------------------------------=== |
| 51 | |
| 52 | /// An instance of this class can be passed to ParseAssemblyFile or |
| 53 | /// ParseAssemblyString functions in order to capture error information from |
| 54 | /// the parser. It provides a standard way to print out the error message |
| 55 | /// including the file name and line number where the error occurred. |
| 56 | /// @brief An LLVM Assembly Parsing Error Object |
| 57 | class ParseError { |
| 58 | public: |
| 59 | ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {} |
| 60 | ParseError(const ParseError &E); |
| 61 | |
| 62 | // getMessage - Return the message passed in at construction time plus extra |
| 63 | // information extracted from the options used to parse with... |
| 64 | // |
| 65 | const std::string getMessage() const; |
| 66 | |
| 67 | inline const std::string &getRawMessage() const { // Just the raw message... |
| 68 | return Message; |
| 69 | } |
| 70 | |
| 71 | inline const std::string &getFilename() const { |
| 72 | return Filename; |
| 73 | } |
| 74 | |
| 75 | void setError(const std::string &filename, const std::string &message, |
| 76 | int LineNo = -1, int ColNo = -1); |
| 77 | |
| 78 | // getErrorLocation - Return the line and column number of the error in the |
| 79 | // input source file. The source filename can be derived from the |
| 80 | // ParserOptions in effect. If positional information is not applicable, |
| 81 | // these will return a value of -1. |
| 82 | // |
| 83 | inline const void getErrorLocation(int &Line, int &Column) const { |
| 84 | Line = LineNo; Column = ColumnNo; |
| 85 | } |
| 86 | |
| 87 | private : |
| 88 | std::string Filename; |
| 89 | std::string Message; |
| 90 | int LineNo, ColumnNo; // -1 if not relevant |
| 91 | |
| 92 | ParseError &operator=(const ParseError &E); // objects by reference |
| 93 | }; |
| 94 | |
| 95 | } // End llvm namespace |
| 96 | |
| 97 | #endif |