add a #include to improve portability to windows, as requested by
[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
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.
34 );
35
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.
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   void setFilename(const std::string &F) { Filename = F; }
63   
64   inline const std::string &getRawMessage() const {   // Just the raw message.
65     return Message;
66   }
67
68   inline const std::string &getFilename() const {
69     return Filename;
70   }
71
72   void setError(const std::string &message, int lineNo = -1, int ColNo = -1,
73                 const std::string &FileContents = "") {
74     Message = message;
75     LineNo = lineNo; ColumnNo = ColNo;
76     LineContents = FileContents;
77   }
78
79   // getErrorLocation - Return the line and column number of the error in the
80   // input source file.  The source filename can be derived from the
81   // ParserOptions in effect.  If positional information is not applicable,
82   // these will return a value of -1.
83   //
84   inline void getErrorLocation(int &Line, int &Column) const {
85     Line = LineNo; Column = ColumnNo;
86   }
87   
88   void PrintError(const char *ProgName, raw_ostream &S);
89
90 private :
91   std::string Filename;
92   std::string Message;
93   int LineNo, ColumnNo;                               // -1 if not relevant
94   std::string LineContents;
95
96   void operator=(const ParseError &E); // DO NOT IMPLEMENT
97 };
98
99 } // End llvm namespace
100
101 #endif