2001-06-06 20:29:01 +00:00
|
|
|
//===- Parser.cpp - Main dispatch module for the Parser library -------------===
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This library implements the functionality defined in llvm/assembly/parser.h
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
|
|
|
#include "ParserInternals.h"
|
2003-10-23 18:00:34 +00:00
|
|
|
#include "llvm/Module.h"
|
2004-07-13 08:42:12 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-09-22 23:50:25 +00:00
|
|
|
// The useful interface defined by this file... Parse an ASCII file, and return
|
2001-06-06 20:29:01 +00:00
|
|
|
// the internal representation in a nice slice'n'dice'able representation.
|
|
|
|
//
|
2004-07-13 08:42:12 +00:00
|
|
|
Module *llvm::ParseAssemblyFile(const std::string &Filename) {
|
2001-06-06 20:29:01 +00:00
|
|
|
FILE *F = stdin;
|
|
|
|
|
2002-02-20 18:06:43 +00:00
|
|
|
if (Filename != "-") {
|
2001-07-22 18:36:00 +00:00
|
|
|
F = fopen(Filename.c_str(), "r");
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-02-20 18:06:43 +00:00
|
|
|
if (F == 0)
|
|
|
|
throw ParseException(Filename, "Could not open file '" + Filename + "'");
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 18:06:43 +00:00
|
|
|
Module *Result;
|
|
|
|
try {
|
|
|
|
Result = RunVMAsmParser(Filename, F);
|
|
|
|
} catch (...) {
|
|
|
|
if (F != stdin) fclose(F); // Make sure to close file descriptor if an
|
|
|
|
throw; // exception is thrown
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
if (F != stdin)
|
|
|
|
fclose(F);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
// ParseException Class
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
|
|
|
|
2003-10-23 18:00:34 +00:00
|
|
|
ParseException::ParseException(const std::string &filename,
|
|
|
|
const std::string &message,
|
2001-07-22 18:36:00 +00:00
|
|
|
int lineNo, int colNo)
|
|
|
|
: Filename(filename), Message(message) {
|
2001-06-06 20:29:01 +00:00
|
|
|
LineNo = lineNo; ColumnNo = colNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseException::ParseException(const ParseException &E)
|
2001-07-22 18:36:00 +00:00
|
|
|
: Filename(E.Filename), Message(E.Message) {
|
2001-06-06 20:29:01 +00:00
|
|
|
LineNo = E.LineNo;
|
|
|
|
ColumnNo = E.ColumnNo;
|
|
|
|
}
|
|
|
|
|
2003-10-23 18:00:34 +00:00
|
|
|
// Includes info from options
|
|
|
|
const std::string ParseException::getMessage() const {
|
|
|
|
std::string Result;
|
2001-06-06 20:29:01 +00:00
|
|
|
char Buffer[10];
|
|
|
|
|
2001-07-22 18:36:00 +00:00
|
|
|
if (Filename == "-")
|
2001-06-06 20:29:01 +00:00
|
|
|
Result += "<stdin>";
|
|
|
|
else
|
2001-07-22 18:36:00 +00:00
|
|
|
Result += Filename;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
if (LineNo != -1) {
|
|
|
|
sprintf(Buffer, "%d", LineNo);
|
2003-10-23 18:00:34 +00:00
|
|
|
Result += std::string(":") + Buffer;
|
2001-06-06 20:29:01 +00:00
|
|
|
if (ColumnNo != -1) {
|
|
|
|
sprintf(Buffer, "%d", ColumnNo);
|
2003-10-23 18:00:34 +00:00
|
|
|
Result += std::string(",") + Buffer;
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result + ": " + Message;
|
|
|
|
}
|