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
40 //===------------------------------------------------------------------------===
41 // ParseException Class
42 //===------------------------------------------------------------------------===
45 ParseException::ParseException(const string &filename, const string &message,
46 int lineNo, int colNo)
47 : Filename(filename), Message(message) {
48 LineNo = lineNo; ColumnNo = colNo;
51 ParseException::ParseException(const ParseException &E)
52 : Filename(E.Filename), Message(E.Message) {
54 ColumnNo = E.ColumnNo;
57 const string ParseException::getMessage() const { // Includes info from options
67 sprintf(Buffer, "%d", LineNo);
68 Result += string(":") + Buffer;
70 sprintf(Buffer, "%d", ColumnNo);
71 Result += string(",") + Buffer;
75 return Result + ": " + Message;