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 "ParserInternals.h"
15 #include "llvm/Module.h"
18 // The useful interface defined by this file... Parse an ASCII file, and return
19 // the internal representation in a nice slice'n'dice'able representation.
21 Module *llvm::ParseAssemblyFile(const std::string &Filename) {
24 if (Filename != "-") {
25 F = fopen(Filename.c_str(), "r");
28 throw ParseException(Filename, "Could not open file '" + Filename + "'");
33 Result = RunVMAsmParser(Filename, F);
35 if (F != stdin) fclose(F); // Make sure to close file descriptor if an
36 throw; // exception is thrown
46 //===------------------------------------------------------------------------===
47 // ParseException Class
48 //===------------------------------------------------------------------------===
51 ParseException::ParseException(const std::string &filename,
52 const std::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 // Includes info from options
65 const std::string ParseException::getMessage() const {
75 sprintf(Buffer, "%d", LineNo);
76 Result += std::string(":") + Buffer;
78 sprintf(Buffer, "%d", ColumnNo);
79 Result += std::string(",") + Buffer;
83 return Result + ": " + Message;