5ac6ec20fa14b6d941d17a98cd0025b15f22a7d5
[oota-llvm.git] / include / llvm / Assembly / Parser.h
1 //===-- llvm/assembly/Parser.h - Parser for VM assembly files ----*- C++ -*--=//
2 //
3 //  These classes are implemented by the lib/AssemblyParser library.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_ASSEMBLY_PARSER_H
8 #define LLVM_ASSEMBLY_PARSER_H
9
10 #include <string>
11
12 class Module;
13 class ToolCommandLine;
14 class ParseException;
15
16
17 // The useful interface defined by this file... Parse an ascii file, and return
18 // the internal representation in a nice slice'n'dice'able representation.
19 //
20 Module *ParseAssemblyFile(const ToolCommandLine &Opts) throw (ParseException);
21
22 //===------------------------------------------------------------------------===
23 //                              Helper Classes
24 //===------------------------------------------------------------------------===
25
26 // ParseException - For when an exceptional event is generated by the parser.
27 // This class lets you print out the exception message
28 //
29 class ParseException {
30 public:
31   ParseException(const ToolCommandLine &Opts, const string &message, 
32                  int LineNo = -1, int ColNo = -1);
33
34   ParseException(const ParseException &E);
35
36   // getMessage - Return the message passed in at construction time plus extra 
37   // information extracted from the options used to parse with...
38   //
39   const string getMessage() const;
40
41   inline const string getRawMessage() const {    // Just the raw message...
42     return Message;
43   }
44
45   inline const ToolCommandLine &getOptions() const {
46     return Opts;                           // Get the options obj used to parse.
47   }
48
49   // getErrorLocation - Return the line and column number of the error in the
50   // input source file.  The source filename can be derived from the 
51   // ParserOptions in effect.  If positional information is not applicable, 
52   // these will return a value of -1.
53   //
54   inline const void getErrorLocation(int &Line, int &Column) const {
55     Line = LineNo; Column = ColumnNo;
56   }
57
58 private :
59   const ToolCommandLine &Opts;
60   string Message;
61   int LineNo, ColumnNo;                               // -1 if not relevant
62
63   ParseException &operator=(const ParseException &E); // objects by reference
64 };
65
66 #endif