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"
10 #include <stdio.h> // for sprintf
13 // The useful interface defined by this file... Parse an ascii file, and return
14 // the internal representation in a nice slice'n'dice'able representation.
16 Module *ParseAssemblyFile(const string &Filename) { // throw (ParseException)
20 F = fopen(Filename.c_str(), "r");
23 throw ParseException(Filename, string("Could not open file '") +
27 // TODO: If this throws an exception, F is not closed.
28 Module *Result = RunVMAsmParser(Filename, F);
33 if (Result) { // Check to see that it is valid...
34 if (verifyModule(Result)) {
36 throw ParseException(Filename, "Source file is not well formed LLVM!");
43 //===------------------------------------------------------------------------===
44 // ParseException Class
45 //===------------------------------------------------------------------------===
48 ParseException::ParseException(const string &filename, const string &message,
49 int lineNo, int colNo)
50 : Filename(filename), Message(message) {
51 LineNo = lineNo; ColumnNo = colNo;
54 ParseException::ParseException(const ParseException &E)
55 : Filename(E.Filename), Message(E.Message) {
57 ColumnNo = E.ColumnNo;
60 const string ParseException::getMessage() const { // Includes info from options
70 sprintf(Buffer, "%d", LineNo);
71 Result += string(":") + Buffer;
73 sprintf(Buffer, "%d", ColumnNo);
74 Result += string(",") + Buffer;
78 return Result + ": " + Message;