Inliner pass header file was moved.
[llvm-complete.git] / lib / AsmParser / Parser.cpp
blobb7921f830581706149353ed292b47605fdf78699
1 //===- Parser.cpp - Main dispatch module for the Parser library -------------===
2 //
3 // The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This library implements the functionality defined in llvm/assembly/parser.h
12 //===------------------------------------------------------------------------===
14 #include "ParserInternals.h"
15 #include "llvm/Module.h"
16 using namespace llvm;
19 ParseError* TheParseError = 0; /// FIXME: Not threading friendly
21 Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError* Err) {
22 FILE *F = stdin;
24 if (Filename != "-") {
25 F = fopen(Filename.c_str(), "r");
27 if (F == 0) {
28 if (Err)
29 Err->setError(Filename,"Could not open file '" + Filename + "'");
30 return 0;
34 TheParseError = Err;
35 Module *Result = RunVMAsmParser(Filename, F);
37 if (F != stdin)
38 fclose(F);
40 return Result;
43 Module *llvm::ParseAssemblyString(
44 const char * AsmString, Module * M, ParseError* Err)
46 TheParseError = Err;
47 return RunVMAsmParser(AsmString, M);
51 //===------------------------------------------------------------------------===
52 // ParseError Class
53 //===------------------------------------------------------------------------===
56 void ParseError::setError(const std::string &filename,
57 const std::string &message,
58 int lineNo, int colNo)
60 Filename = filename;
61 Message = message;
62 LineNo = lineNo;
63 colNo = colNo;
66 ParseError::ParseError(const ParseError &E)
67 : Filename(E.Filename), Message(E.Message) {
68 LineNo = E.LineNo;
69 ColumnNo = E.ColumnNo;
72 // Includes info from options
73 const std::string ParseError::getMessage() const {
74 std::string Result;
75 char Buffer[10];
77 if (Filename == "-")
78 Result += "<stdin>";
79 else
80 Result += Filename;
82 if (LineNo != -1) {
83 sprintf(Buffer, "%d", LineNo);
84 Result += std::string(":") + Buffer;
85 if (ColumnNo != -1) {
86 sprintf(Buffer, "%d", ColumnNo);
87 Result += std::string(",") + Buffer;
91 return Result + ": " + Message;