diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-02 07:01:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-02 07:01:27 +0000 |
commit | df98617b23315e427cc4fad8ccfdd50d68bec2f9 (patch) | |
tree | 7ff121d47bf96432f608d5059916d6b7062e6d36 /include/llvm/Assembly | |
parent | ccb6976a69a6e146db049fff8e6338e31c91b6f8 (diff) | |
download | external_llvm-df98617b23315e427cc4fad8ccfdd50d68bec2f9.zip external_llvm-df98617b23315e427cc4fad8ccfdd50d68bec2f9.tar.gz external_llvm-df98617b23315e427cc4fad8ccfdd50d68bec2f9.tar.bz2 |
Reimplement the old and horrible bison parser for .ll files with a nice
and clean recursive descent parser.
This change has a couple of ramifications:
1. The parser code is about 400 lines shorter (in what we maintain, not
including what is autogenerated).
2. The code should be significantly faster than the old code because we
don't have to work around bison's poor handling of datatypes with
ctors/dtors. This also makes the code much more resistant to memory
leaks.
3. We now get caret diagnostics from the .ll parser, woo.
4. The actual diagnostics emited from the parser are completely different
so a bunch of testcases had to be updated.
5. I now disallow "%ty = type opaque %ty = type i32". There was no good
reason to support this, it was just an accident of the old
implementation. I have no reason to think that anyone is actually using
this.
6. The syntax for sticking a global variable has changed to make it
unambiguous. I don't think anyone is depending on this since only clang
supports this and it is not solid yet, so I'm not worried about anything
breaking.
7. This gets rid of the last use of bison, and along with it the .cvs files.
I'll prune this from the makefiles as a subsequent commit.
There are a few minor cleanups that can be done after this commit (suggestions
welcome!) but this passes dejagnu testing and is ready for its time in the
limelight.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61558 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Assembly')
-rw-r--r-- | include/llvm/Assembly/Parser.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h index 904130d..17484ae 100644 --- a/include/llvm/Assembly/Parser.h +++ b/include/llvm/Assembly/Parser.h @@ -20,6 +20,7 @@ namespace llvm { class Module; class ParseError; +class raw_ostream; /// This function is the main interface to the LLVM Assembly Parser. It parses /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a @@ -29,7 +30,7 @@ class ParseError; /// @brief Parse LLVM Assembly from a file Module *ParseAssemblyFile( const std::string &Filename, ///< The name of the file to parse - ParseError* Error = 0 ///< If not null, an object to return errors in. + ParseError &Error ///< If not null, an object to return errors in. ); /// The function is a secondary interface to the LLVM Assembly Parser. It parses @@ -39,9 +40,9 @@ Module *ParseAssemblyFile( /// run the verifier after parsing the file to check that it is okay. /// @brief Parse LLVM Assembly from a string Module *ParseAssemblyString( - const char * AsmString, ///< The string containing assembly - Module * M, ///< A module to add the assembly too. - ParseError* Error = 0 ///< If not null, an object to return errors in. + const char *AsmString, ///< The string containing assembly + Module *M, ///< A module to add the assembly too. + ParseError &Error ///< If not null, an object to return errors in. ); //===------------------------------------------------------------------------=== @@ -58,6 +59,8 @@ public: ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {} ParseError(const ParseError &E); + void setFilename(const std::string &F) { Filename = F; } + // getMessage - Return the message passed in at construction time plus extra // information extracted from the options used to parse with... // @@ -71,8 +74,12 @@ public: return Filename; } - void setError(const std::string &filename, const std::string &message, - int LineNo = -1, int ColNo = -1); + void setError(const std::string &message, int lineNo = -1, int ColNo = -1, + const std::string &FileContents = "") { + Message = message; + LineNo = lineNo; ColumnNo = ColNo; + LineContents = FileContents; + } // getErrorLocation - Return the line and column number of the error in the // input source file. The source filename can be derived from the @@ -82,13 +89,16 @@ public: inline void getErrorLocation(int &Line, int &Column) const { Line = LineNo; Column = ColumnNo; } + + void PrintError(const char *ProgName, raw_ostream &S); private : std::string Filename; std::string Message; int LineNo, ColumnNo; // -1 if not relevant + std::string LineContents; - ParseError &operator=(const ParseError &E); // objects by reference + void operator=(const ParseError &E); // DO NOT IMPLEMENT }; } // End llvm namespace |