1 //===- Parser.cpp - Main dispatch module for the Parser library -------------===
3 // This library implements the functionality defined in llvm/assembly/parser.h
5 //===------------------------------------------------------------------------===
7 #include "llvm/Analysis/Verifier.h"
8 #include "llvm/Module.h"
9 #include "ParserInternals.h"
12 // The useful interface defined by this file... Parse an ascii file, and return
13 // the internal representation in a nice slice'n'dice'able representation.
15 Module *ParseAssemblyFile(const string &Filename) { // throw (ParseException)
18 if (Filename != "-") {
19 F = fopen(Filename.c_str(), "r");
22 throw ParseException(Filename, "Could not open file '" + Filename + "'");
27 Result = RunVMAsmParser(Filename, F);
29 if (F != stdin) fclose(F); // Make sure to close file descriptor if an
30 throw; // exception is thrown
36 if (Result) { // Check to see that it is valid...
37 if (verifyModule(*Result)) {
39 throw ParseException(Filename, "Source file is not well formed LLVM!");
46 //===------------------------------------------------------------------------===
47 // ParseException Class
48 //===------------------------------------------------------------------------===
51 ParseException::ParseException(const string &filename, const string &message,
52 int lineNo, int colNo)
53 : Filename(filename), Message(message) {
54 LineNo = lineNo; ColumnNo = colNo;
57 ParseException::ParseException(const ParseException &E)
58 : Filename(E.Filename), Message(E.Message) {
60 ColumnNo = E.ColumnNo;
63 const string ParseException::getMessage() const { // Includes info from options
73 sprintf(Buffer, "%d", LineNo);
74 Result += string(":") + Buffer;
76 sprintf(Buffer, "%d", ColumnNo);
77 Result += string(",") + Buffer;
81 return Result + ": " + Message;