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"
19 ParseError
* TheParseError
= 0; /// FIXME: Not threading friendly
21 Module
*llvm::ParseAssemblyFile(const std::string
&Filename
, ParseError
* Err
) {
24 if (Filename
!= "-") {
25 F
= fopen(Filename
.c_str(), "r");
29 Err
->setError(Filename
,"Could not open file '" + Filename
+ "'");
35 Module
*Result
= RunVMAsmParser(Filename
, F
);
43 Module
*llvm::ParseAssemblyString(
44 const char * AsmString
, Module
* M
, ParseError
* Err
)
47 return RunVMAsmParser(AsmString
, M
);
51 //===------------------------------------------------------------------------===
53 //===------------------------------------------------------------------------===
56 void ParseError::setError(const std::string
&filename
,
57 const std::string
&message
,
58 int lineNo
, int colNo
)
66 ParseError::ParseError(const ParseError
&E
)
67 : Filename(E
.Filename
), Message(E
.Message
) {
69 ColumnNo
= E
.ColumnNo
;
72 // Includes info from options
73 const std::string
ParseError::getMessage() const {
83 sprintf(Buffer
, "%d", LineNo
);
84 Result
+= std::string(":") + Buffer
;
86 sprintf(Buffer
, "%d", ColumnNo
);
87 Result
+= std::string(",") + Buffer
;
91 return Result
+ ": " + Message
;