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[0], Filename.size(),
29 Err->setError(Filename, "Could not open input file '" + Filename + "'");
34 Module *Result = RunVMAsmParser(F);
39 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
42 MemoryBuffer *F = MemoryBuffer::getMemBuffer(AsmString,
43 AsmString+strlen(AsmString),
45 Module *Result = RunVMAsmParser(F);
51 //===------------------------------------------------------------------------===
53 //===------------------------------------------------------------------------===
56 void ParseError::setError(const std::string &filename,
57 const std::string &message,
58 int lineNo, int colNo) {
65 ParseError::ParseError(const ParseError &E)
66 : Filename(E.Filename), Message(E.Message) {
68 ColumnNo = E.ColumnNo;
71 // Includes info from options
72 const std::string ParseError::getMessage() const {
82 sprintf(Buffer, "%d", LineNo);
83 Result += std::string(":") + Buffer;
85 sprintf(Buffer, "%d", ColumnNo);
86 Result += std::string(",") + Buffer;
90 return Result + ": " + Message;