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
26 /// This function is the main interface to the LLVM Assembly Parser. It parses
27 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
28 /// Module (intermediate representation) with the corresponding features. Note
29 /// that this does not verify that the generated Module is valid, so you should
30 /// run the verifier after parsing the file to check that it is okay.
31 /// @brief Parse LLVM Assembly from a file
32 Module *ParseAssemblyFile(
33 const std::string &Filename, ///< The name of the file to parse
34 ParseError &Error, ///< If not null, an object to return errors in.
35 const LLVMContext& Context ///< Context in which to allocate globals info.
38 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
39 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
40 /// Module (intermediate representation) with the corresponding features. Note
41 /// that this does not verify that the generated Module is valid, so you should
42 /// run the verifier after parsing the file to check that it is okay.
43 /// @brief Parse LLVM Assembly from a string
44 Module *ParseAssemblyString(
45 const char *AsmString, ///< The string containing assembly
46 Module *M, ///< A module to add the assembly too.
47 ParseError &Error, ///< If not null, an object to return errors in.
48 const LLVMContext& Context
51 //===------------------------------------------------------------------------===
53 //===------------------------------------------------------------------------===
55 /// An instance of this class can be passed to ParseAssemblyFile or
56 /// ParseAssemblyString functions in order to capture error information from
57 /// the parser. It provides a standard way to print out the error message
58 /// including the file name and line number where the error occurred.
59 /// @brief An LLVM Assembly Parsing Error Object
62 ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {}
63 ParseError(const ParseError &E);
65 void setFilename(const std::string &F) { Filename = F; }
67 inline const std::string &getRawMessage() const { // Just the raw message.
71 inline const std::string &getFilename() const {
75 void setError(const std::string &message, int lineNo = -1, int ColNo = -1,
76 const std::string &FileContents = "") {
78 LineNo = lineNo; ColumnNo = ColNo;
79 LineContents = FileContents;
82 // getErrorLocation - Return the line and column number of the error in the
83 // input source file. The source filename can be derived from the
84 // ParserOptions in effect. If positional information is not applicable,
85 // these will return a value of -1.
87 inline void getErrorLocation(int &Line, int &Column) const {
88 Line = LineNo; Column = ColumnNo;
91 void PrintError(const char *ProgName, raw_ostream &S);
96 int LineNo, ColumnNo; // -1 if not relevant
97 std::string LineContents;
99 void operator=(const ParseError &E); // DO NOT IMPLEMENT
102 } // End llvm namespace