1 //===-- llvm/Assembly/Parser.h - Parser for VM 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_ASSEMBLY_PARSER_H
15 #define LLVM_ASSEMBLY_PARSER_H
25 /// This function is the main interface to the LLVM Assembly Parser. 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 ///< If not null, an object to return errors in.
36 /// The function is a secondary interface to the LLVM Assembly Parser. 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 ///< If not null, an object to return errors in.
48 //===------------------------------------------------------------------------===
50 //===------------------------------------------------------------------------===
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
59 ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {}
60 ParseError(const ParseError &E);
62 void setFilename(const std::string &F) { Filename = F; }
64 // getMessage - Return the message passed in at construction time plus extra
65 // information extracted from the options used to parse with...
67 const std::string getMessage() const;
69 inline const std::string &getRawMessage() const { // Just the raw message...
73 inline const std::string &getFilename() const {
77 void setError(const std::string &message, int lineNo = -1, int ColNo = -1,
78 const std::string &FileContents = "") {
80 LineNo = lineNo; ColumnNo = ColNo;
81 LineContents = FileContents;
84 // getErrorLocation - Return the line and column number of the error in the
85 // input source file. The source filename can be derived from the
86 // ParserOptions in effect. If positional information is not applicable,
87 // these will return a value of -1.
89 inline void getErrorLocation(int &Line, int &Column) const {
90 Line = LineNo; Column = ColumnNo;
93 void PrintError(const char *ProgName, raw_ostream &S);
98 int LineNo, ColumnNo; // -1 if not relevant
99 std::string LineContents;
101 void operator=(const ParseError &E); // DO NOT IMPLEMENT
104 } // End llvm namespace