1 //===- Parser.cpp - Main dispatch module for the Parser library -------------===
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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"
16 #include "llvm/Support/MemoryBuffer.h"
21 ParseError* TheParseError = 0; /// FIXME: Not threading friendly
23 Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError* Err) {
25 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
28 Err->setError(Filename, "Could not open input file '" + Filename + "'");
33 Module *Result = RunVMAsmParser(F);
38 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
41 MemoryBuffer *F = MemoryBuffer::getMemBuffer(AsmString,
42 AsmString+strlen(AsmString),
44 Module *Result = RunVMAsmParser(F);
50 //===------------------------------------------------------------------------===
52 //===------------------------------------------------------------------------===
55 void ParseError::setError(const std::string &filename,
56 const std::string &message,
57 int lineNo, int colNo) {
64 ParseError::ParseError(const ParseError &E)
65 : Filename(E.Filename), Message(E.Message) {
67 ColumnNo = E.ColumnNo;
70 // Includes info from options
71 const std::string ParseError::getMessage() const {
81 sprintf(Buffer, "%d", LineNo);
82 Result += std::string(":") + Buffer;
84 sprintf(Buffer, "%d", ColumnNo);
85 Result += std::string(",") + Buffer;
89 return Result + ": " + Message;