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
45 Module *llvm::ParseAssemblyString(const char * AsmString, Module * M) {
46 return RunVMAsmParser(AsmString, M);
50 //===------------------------------------------------------------------------===
51 // ParseException Class
52 //===------------------------------------------------------------------------===
55 ParseException::ParseException(const std::string &filename,
56 const std::string &message,
57 int lineNo, int colNo)
58 : Filename(filename), Message(message) {
59 LineNo = lineNo; ColumnNo = colNo;
62 ParseException::ParseException(const ParseException &E)
63 : Filename(E.Filename), Message(E.Message) {
65 ColumnNo = E.ColumnNo;
68 // Includes info from options
69 const std::string ParseException::getMessage() const {
79 sprintf(Buffer, "%d", LineNo);
80 Result += std::string(":") + Buffer;
82 sprintf(Buffer, "%d", ColumnNo);
83 Result += std::string(",") + Buffer;
87 return Result + ": " + Message;