Hold the LLVMContext by reference rather than by pointer.
[oota-llvm.git] / include / llvm / Assembly / Parser.h
1 //===-- llvm/Assembly/Parser.h - Parser for VM 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_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 class raw_ostream;
24 class LLVMContext;
25
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.
36 );
37
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
49 );
50
51 //===------------------------------------------------------------------------===
52 //                              Helper Classes
53 //===------------------------------------------------------------------------===
54
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
60 class ParseError {
61 public:
62   ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {}
63   ParseError(const ParseError &E);
64
65   void setFilename(const std::string &F) { Filename = F; }
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 &message, int lineNo = -1, int ColNo = -1,
76                 const std::string &FileContents = "") {
77     Message = message;
78     LineNo = lineNo; ColumnNo = ColNo;
79     LineContents = FileContents;
80   }
81
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.
86   //
87   inline void getErrorLocation(int &Line, int &Column) const {
88     Line = LineNo; Column = ColumnNo;
89   }
90   
91   void PrintError(const char *ProgName, raw_ostream &S);
92
93 private :
94   std::string Filename;
95   std::string Message;
96   int LineNo, ColumnNo;                               // -1 if not relevant
97   std::string LineContents;
98
99   void operator=(const ParseError &E); // DO NOT IMPLEMENT
100 };
101
102 } // End llvm namespace
103
104 #endif