LLVM API Documentation
00001 //===-- llvm/Assembly/Parser.h - Parser for VM assembly files ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // These classes are implemented by the lib/AsmParser library. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ASSEMBLY_PARSER_H 00015 #define LLVM_ASSEMBLY_PARSER_H 00016 00017 #include <string> 00018 00019 namespace llvm { 00020 00021 class Module; 00022 class ParseError; 00023 class raw_ostream; 00024 00025 /// This function is the main interface to the LLVM Assembly Parser. It parses 00026 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a 00027 /// Module (intermediate representation) with the corresponding features. Note 00028 /// that this does not verify that the generated Module is valid, so you should 00029 /// run the verifier after parsing the file to check that it is okay. 00030 /// @brief Parse LLVM Assembly from a file 00031 Module *ParseAssemblyFile( 00032 const std::string &Filename, ///< The name of the file to parse 00033 ParseError &Error ///< If not null, an object to return errors in. 00034 ); 00035 00036 /// The function is a secondary interface to the LLVM Assembly Parser. It parses 00037 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a 00038 /// Module (intermediate representation) with the corresponding features. Note 00039 /// that this does not verify that the generated Module is valid, so you should 00040 /// run the verifier after parsing the file to check that it is okay. 00041 /// @brief Parse LLVM Assembly from a string 00042 Module *ParseAssemblyString( 00043 const char *AsmString, ///< The string containing assembly 00044 Module *M, ///< A module to add the assembly too. 00045 ParseError &Error ///< If not null, an object to return errors in. 00046 ); 00047 00048 //===------------------------------------------------------------------------=== 00049 // Helper Classes 00050 //===------------------------------------------------------------------------=== 00051 00052 /// An instance of this class can be passed to ParseAssemblyFile or 00053 /// ParseAssemblyString functions in order to capture error information from 00054 /// the parser. It provides a standard way to print out the error message 00055 /// including the file name and line number where the error occurred. 00056 /// @brief An LLVM Assembly Parsing Error Object 00057 class ParseError { 00058 public: 00059 ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {} 00060 ParseError(const ParseError &E); 00061 00062 void setFilename(const std::string &F) { Filename = F; } 00063 00064 inline const std::string &getRawMessage() const { // Just the raw message. 00065 return Message; 00066 } 00067 00068 inline const std::string &getFilename() const { 00069 return Filename; 00070 } 00071 00072 void setError(const std::string &message, int lineNo = -1, int ColNo = -1, 00073 const std::string &FileContents = "") { 00074 Message = message; 00075 LineNo = lineNo; ColumnNo = ColNo; 00076 LineContents = FileContents; 00077 } 00078 00079 // getErrorLocation - Return the line and column number of the error in the 00080 // input source file. The source filename can be derived from the 00081 // ParserOptions in effect. If positional information is not applicable, 00082 // these will return a value of -1. 00083 // 00084 inline void getErrorLocation(int &Line, int &Column) const { 00085 Line = LineNo; Column = ColumnNo; 00086 } 00087 00088 void PrintError(const char *ProgName, raw_ostream &S); 00089 00090 private : 00091 std::string Filename; 00092 std::string Message; 00093 int LineNo, ColumnNo; // -1 if not relevant 00094 std::string LineContents; 00095 00096 void operator=(const ParseError &E); // DO NOT IMPLEMENT 00097 }; 00098 00099 } // End llvm namespace 00100 00101 #endif