1 //===- Parser.cpp - Main dispatch module for the Parser library -------------===
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This library implements the functionality defined in llvm/assembly/parser.h
12 //===------------------------------------------------------------------------===
14 #include "llvm/Analysis/Verifier.h"
15 #include "llvm/Module.h"
16 #include "ParserInternals.h"
19 // The useful interface defined by this file... Parse an ASCII file, and return
20 // the internal representation in a nice slice'n'dice'able representation.
22 Module *ParseAssemblyFile(const string &Filename) { // throw (ParseException)
25 if (Filename != "-") {
26 F = fopen(Filename.c_str(), "r");
29 throw ParseException(Filename, "Could not open file '" + Filename + "'");
34 Result = RunVMAsmParser(Filename, F);
36 if (F != stdin) fclose(F); // Make sure to close file descriptor if an
37 throw; // exception is thrown
47 //===------------------------------------------------------------------------===
48 // ParseException Class
49 //===------------------------------------------------------------------------===
52 ParseException::ParseException(const string &filename, const string &message,
53 int lineNo, int colNo)
54 : Filename(filename), Message(message) {
55 LineNo = lineNo; ColumnNo = colNo;
58 ParseException::ParseException(const ParseException &E)
59 : Filename(E.Filename), Message(E.Message) {
61 ColumnNo = E.ColumnNo;
64 const string ParseException::getMessage() const { // Includes info from options
74 sprintf(Buffer, "%d", LineNo);
75 Result += string(":") + Buffer;
77 sprintf(Buffer, "%d", ColumnNo);
78 Result += string(",") + Buffer;
82 return Result + ": " + Message;