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 "llvm/Assembly/Parser.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/raw_ostream.h"
22 Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
23 Err.setFilename(Filename);
26 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
28 Err.setError("Could not open input file '" + Filename + "'");
32 Module *Result = LLParser(F, Err).Run();
37 // FIXME: M is ignored??
38 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
40 Err.setFilename("<string>");
42 MemoryBuffer *F = MemoryBuffer::getMemBuffer(AsmString,
43 AsmString+strlen(AsmString),
45 Module *Result = LLParser(F, Err).Run();
51 //===------------------------------------------------------------------------===
53 //===------------------------------------------------------------------------===
55 void ParseError::PrintError(const char *ProgName, raw_ostream &S) {
56 errs() << ProgName << ": ";
63 errs() << ':' << LineNo;
65 errs() << ':' << (ColumnNo+1);
68 errs() << ": " << Message << '\n';
70 if (LineNo != -1 && ColumnNo != -1) {
71 errs() << LineContents << '\n';
73 // Print out spaces/tabs before the caret.
74 for (unsigned i = 0; i != unsigned(ColumnNo); ++i)
75 errs() << (LineContents[i] == '\t' ? '\t' : ' ');