}
-static bool ReadArchiveBuffer(unsigned char *Buffer, unsigned Length,
+static bool ReadArchiveBuffer(const std::string &Filename,
+ unsigned char *Buffer, unsigned Length,
std::vector<Module*> &Objects,
std::string *ErrorStr) {
if (Length < 8 || memcmp(Buffer, "!<arch>\n", 8))
return true;
break;
case UserObject: {
- Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size, ErrorStr);
+ Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size,
+ Filename+":somefile", ErrorStr);
if (!M) return true;
Objects.push_back(M);
break;
return Error(ErrorStr, "Error mmapping file!");
// Parse the archive files we mmap'ped in
- bool Result = ReadArchiveBuffer(Buffer, Length, Objects, ErrorStr);
+ bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
munmap((char*)Buffer, Length);
CurFilename = Filename;
llvmAsmlineno = 1; // Reset the current line number...
- CurModule.CurrentModule = new Module(); // Allocate a new module to read
+ // Allocate a new module to read
+ CurModule.CurrentModule = new Module(Filename);
yyparse(); // Parse the file.
Module *Result = ParserResult;
llvmAsmin = stdin; // F is about to go away, don't use it anymore...
}
-static bool ReadArchiveBuffer(unsigned char *Buffer, unsigned Length,
+static bool ReadArchiveBuffer(const std::string &Filename,
+ unsigned char *Buffer, unsigned Length,
std::vector<Module*> &Objects,
std::string *ErrorStr) {
if (Length < 8 || memcmp(Buffer, "!<arch>\n", 8))
return true;
break;
case UserObject: {
- Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size, ErrorStr);
+ Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size,
+ Filename+":somefile", ErrorStr);
if (!M) return true;
Objects.push_back(M);
break;
return Error(ErrorStr, "Error mmapping file!");
// Parse the archive files we mmap'ped in
- bool Result = ReadArchiveBuffer(Buffer, Length, Objects, ErrorStr);
+ bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
munmap((char*)Buffer, Length);
}
-static bool ReadArchiveBuffer(unsigned char *Buffer, unsigned Length,
+static bool ReadArchiveBuffer(const std::string &Filename,
+ unsigned char *Buffer, unsigned Length,
std::vector<Module*> &Objects,
std::string *ErrorStr) {
if (Length < 8 || memcmp(Buffer, "!<arch>\n", 8))
return true;
break;
case UserObject: {
- Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size, ErrorStr);
+ Module *M = ParseBytecodeBuffer(Buffer+sizeof(ar_hdr), Size,
+ Filename+":somefile", ErrorStr);
if (!M) return true;
Objects.push_back(M);
break;
return Error(ErrorStr, "Error mmapping file!");
// Parse the archive files we mmap'ped in
- bool Result = ReadArchiveBuffer(Buffer, Length, Objects, ErrorStr);
+ bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
munmap((char*)Buffer, Length);
return 0;
}
-Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf) {
+Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf,
+ const std::string &ModuleID) {
unsigned Sig;
// Read and check signature...
if (read(Buf, EndBuf, Sig) ||
Sig != ('l' | ('l' << 8) | ('v' << 16) | 'm' << 24))
return ::Error(&Error, "Invalid bytecode signature!");
- TheModule = new Module();
+ TheModule = new Module(ModuleID);
if (ParseModule(Buf, EndBuf)) {
delete TheModule;
TheModule = 0;
Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
- std::string *ErrorStr) {
+ const std::string &ModuleID, std::string *ErrorStr){
BytecodeParser Parser;
unsigned char *PtrToDelete = 0;
if ((intptr_t)Buffer & 3) { // If the buffer is not 4 byte aligned...
Buffer = PtrToDelete+Offset;
}
- Module *R = Parser.ParseBytecode(Buffer, Buffer+Length);
+ Module *R = Parser.ParseBytecode(Buffer, Buffer+Length, ModuleID);
if (ErrorStr) *ErrorStr = Parser.getError();
delete [] PtrToDelete; // Delete alignment buffer if neccesary
return Error(ErrorStr, "Error mmapping file!");
// Parse the bytecode we mmapped in
- Result = ParseBytecodeBuffer(Buffer, Length, ErrorStr);
+ Result = ParseBytecodeBuffer(Buffer, Length, Filename, ErrorStr);
// Unmmap the bytecode...
munmap((char*)Buffer, Length);
unsigned char *Buf = &FileData[0];
#endif
- Result = ParseBytecodeBuffer(Buf, FileData.size(), ErrorStr);
+ Result = ParseBytecodeBuffer(Buf, FileData.size(), "<stdin>", ErrorStr);
#if ALIGN_PTRS
munmap((char*)Buf, FileData.size()); // Free mmap'd data area
freeTable(ModuleValues);
}
- Module *ParseBytecode(const uchar *Buf, const uchar *EndBuf);
+ Module *ParseBytecode(const uchar *Buf, const uchar *EndBuf,
+ const std::string &ModuleID);
std::string getError() const { return Error; }