2001-06-06 22:29:01 +02:00
|
|
|
//===- Parser.cpp - Main dispatch module for the Parser library -------------===
|
2003-10-20 21:43:21 +02: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 22:29:01 +02:00
|
|
|
//
|
|
|
|
// This library implements the functionality defined in llvm/assembly/parser.h
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
|
|
|
#include "ParserInternals.h"
|
2003-10-23 20:00:34 +02:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Analysis/Verifier.h"
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-09-23 01:50:25 +02:00
|
|
|
// The useful interface defined by this file... Parse an ASCII file, and return
|
2001-06-06 22:29:01 +02:00
|
|
|
// the internal representation in a nice slice'n'dice'able representation.
|
|
|
|
//
|
2003-10-23 20:00:34 +02:00
|
|
|
Module *ParseAssemblyFile(const std::string &Filename) {
|
2001-06-06 22:29:01 +02:00
|
|
|
FILE *F = stdin;
|
|
|
|
|
2002-02-20 19:06:43 +01:00
|
|
|
if (Filename != "-") {
|
2001-07-22 20:36:00 +02:00
|
|
|
F = fopen(Filename.c_str(), "r");
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2002-02-20 19:06:43 +01:00
|
|
|
if (F == 0)
|
|
|
|
throw ParseException(Filename, "Could not open file '" + Filename + "'");
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
|
|
|
|
2002-02-20 19:06:43 +01: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 22:29:01 +02:00
|
|
|
|
|
|
|
if (F != stdin)
|
|
|
|
fclose(F);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
// ParseException Class
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
|
|
|
|
2003-10-23 20:00:34 +02:00
|
|
|
ParseException::ParseException(const std::string &filename,
|
|
|
|
const std::string &message,
|
2001-07-22 20:36:00 +02:00
|
|
|
int lineNo, int colNo)
|
|
|
|
: Filename(filename), Message(message) {
|
2001-06-06 22:29:01 +02:00
|
|
|
LineNo = lineNo; ColumnNo = colNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseException::ParseException(const ParseException &E)
|
2001-07-22 20:36:00 +02:00
|
|
|
: Filename(E.Filename), Message(E.Message) {
|
2001-06-06 22:29:01 +02:00
|
|
|
LineNo = E.LineNo;
|
|
|
|
ColumnNo = E.ColumnNo;
|
|
|
|
}
|
|
|
|
|
2003-10-23 20:00:34 +02:00
|
|
|
// Includes info from options
|
|
|
|
const std::string ParseException::getMessage() const {
|
|
|
|
std::string Result;
|
2001-06-06 22:29:01 +02:00
|
|
|
char Buffer[10];
|
|
|
|
|
2001-07-22 20:36:00 +02:00
|
|
|
if (Filename == "-")
|
2001-06-06 22:29:01 +02:00
|
|
|
Result += "<stdin>";
|
|
|
|
else
|
2001-07-22 20:36:00 +02:00
|
|
|
Result += Filename;
|
2001-06-06 22:29:01 +02:00
|
|
|
|
|
|
|
if (LineNo != -1) {
|
|
|
|
sprintf(Buffer, "%d", LineNo);
|
2003-10-23 20:00:34 +02:00
|
|
|
Result += std::string(":") + Buffer;
|
2001-06-06 22:29:01 +02:00
|
|
|
if (ColumnNo != -1) {
|
|
|
|
sprintf(Buffer, "%d", ColumnNo);
|
2003-10-23 20:00:34 +02:00
|
|
|
Result += std::string(",") + Buffer;
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result + ": " + Message;
|
|
|
|
}
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
} // End llvm namespace
|