Changeset 150
- Timestamp:
- 02/23/06 12:50:12 (3 years ago)
- Files:
-
- branches/larsivi-elf/ddl/insitu/InSituBinary.d (modified) (1 diff)
- branches/larsivi-elf/ddl/insitu/InSituLibBinary.d (modified) (2 diffs)
- branches/larsivi-elf/ddl/insitu/InSituLoader.d (modified) (3 diffs)
- branches/larsivi-elf/ddl/insitu/InSituMapBinary.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/larsivi-elf/ddl/insitu/InSituBinary.d
r85 r150 26 26 27 27 private import ddl.ExportSymbol; 28 private import ddl. Utils;28 private import ddl.FileBuffer; 29 29 30 30 interface InSituBinary{ 31 public void load( DDLFilefile);31 public void load(FileBuffer file); 32 32 public ExportSymbol[char[]] getAllSymbols(); 33 33 } branches/larsivi-elf/ddl/insitu/InSituLibBinary.d
r92 r150 27 27 private import std.zlib; 28 28 29 private import ddl.Utils; 29 private import ddl.FileBuffer; 30 private import ddl.DDLReader; 31 private import ddl.DDLWriter; 30 32 private import ddl.ExportSymbol; 31 33 private import ddl.insitu.InSituBinary; 34 35 private import mango.io.GrowBuffer; 32 36 33 37 class InSituLibBinary : InSituBinary{ … … 50 54 } 51 55 52 public void load( DDLFilefile){53 ReadCursor cursor = new ReadCursor(file);56 public void load(FileBuffer file){ 57 ubyte[] magic; 54 58 uint fileVersion; 55 uint symbolCount; 59 uint symbolCount; 60 void[] binaryData; 61 DDLReader reader = new DDLReader(file); 56 62 57 63 // read the magic 58 char[] magic = cast(char[])cursor.getBytes(8);59 assert(magic == magicString);64 reader.get(magic,8); 65 reader.get(fileVersion); 60 66 61 // read the version 62 fileVersion = cursor.getDWord(); 67 assert(magic == cast(ubyte[])magicString); 63 68 assert(fileVersion == InSituVersion); 64 69 65 70 // read symbol count 66 symbolCount = cursor.getDWord();71 reader.get(symbolCount); 67 72 68 73 // read compressed data area 69 ubyte[] binaryData = cursor.getCurrentData();70 cursor = new ReadCursor(cast(ubyte[])uncompress(binaryData));74 reader.getAll(binaryData); 75 reader = new DDLReader(uncompress(binaryData)); 71 76 72 77 // read symbols 73 78 for(uint i=0; i<symbolCount; i++){ 79 uint address; 74 80 ExportSymbol sym; 75 81 76 sym.address = cast(void*)cursor.getDWord(); 77 sym.name = cursor.getString(); 78 82 reader.get(address); 83 reader.get(sym.name); 84 85 sym.address = cast(void*)address; 86 79 87 allSymbols[sym.name] = sym; 80 88 } 81 89 } 82 90 83 public void save( DDLFilefile,ubyte compressionLevel){84 WriteCursor cursor = new WriteCursor();91 public void save(FileBuffer file,ubyte compressionLevel){ 92 DDLWriter zipWriter = new DDLWriter(new GrowBuffer()); 85 93 assert(compressionLevel <= 9); 86 94 87 95 // write everything to the buffer 88 96 foreach(ExportSymbol sym; allSymbols.values){ 89 cursor.write(cast(uint)sym.address);90 cursor.write(sym.name);91 } 97 zipWriter.put(cast(uint)sym.address); 98 zipWriter.put(sym.name); 99 } 92 100 93 101 // compress the data 94 ubyte[] binaryData = cast(ubyte[])compress( cursor.getData,compressionLevel);102 ubyte[] binaryData = cast(ubyte[])compress(zipWriter.getBuffer.toString,compressionLevel); 95 103 96 104 // write the actual file 97 cursor = new WriteCursor(); 98 cursor.write(cast(ubyte[])magicString); 99 cursor.write(InSituVersion); 100 cursor.write(allSymbols.length); 101 cursor.write(binaryData); 102 103 file.save(cursor); 105 DDLWriter writer = new DDLWriter(file); 106 writer.put(cast(ubyte[])magicString); 107 writer.put(InSituVersion); 108 writer.put(allSymbols.length); 109 writer.put(binaryData); 104 110 } 105 111 } branches/larsivi-elf/ddl/insitu/InSituLoader.d
r85 r150 31 31 private import ddl.DynamicLibraryLoader; 32 32 private import ddl.LoaderRegistry; 33 private import ddl. Utils;33 private import ddl.FileBuffer; 34 34 35 35 private import ddl.insitu.InSituMapBinary; … … 49 49 } 50 50 51 public bit canLoadLibrary( DDLFilefile){52 return file.buffer[0..8] == cast(ubyte[])"DDLSITU!";51 public bit canLoadLibrary(FileBuffer file){ 52 return (cast(char[])file.get(8,false)) == "DDLSITU!"; 53 53 } 54 54 55 public DynamicLibrary load(LoaderRegistry registry, DDLFilefile){55 public DynamicLibrary load(LoaderRegistry registry,FileBuffer file){ 56 56 InSituLibBinary binary = new InSituLibBinary(); 57 57 binary.load(file); … … 72 72 } 73 73 74 public bit canLoadLibrary( DDLFilefile){75 return file.buffer[0..8] == cast(ubyte[])"\r\n Start";74 public bit canLoadLibrary(FileBuffer file){ 75 return (cast(char[])file.get(8,false)) == "\r\n Start"; 76 76 } 77 77 78 public DynamicLibrary load(LoaderRegistry registry, DDLFilefile){78 public DynamicLibrary load(LoaderRegistry registry,FileBuffer file){ 79 79 InSituMapBinary binary = new InSituMapBinary(); 80 80 binary.load(file); branches/larsivi-elf/ddl/insitu/InSituMapBinary.d
r91 r150 26 26 27 27 private import ddl.ExportSymbol; 28 private import ddl. Utils;28 private import ddl.FileBuffer; 29 29 private import ddl.insitu.InSituBinary; 30 31 private import mango.io.TextReader; 32 private import mango.text.LineIterator; 33 30 34 31 35 /* Binary 'file' for DMD map files */ … … 38 42 } 39 43 40 public void load( DDLFilefile){41 ReadCursor cursor = new ReadCursor(file);42 parseSegmentDefinitions( cursor);43 parsePublicsByName( cursor);44 public void load(FileBuffer file){ 45 TextReader reader = new TextReader(new LineIterator(file)); 46 parseSegmentDefinitions(reader); 47 parsePublicsByName(reader); 44 48 // throw away the publics by address 45 49 } … … 53 57 } 54 58 55 protected void parseSegmentDefinitions(ReadCursor cursor){ 56 cursor.readLine(); // throw away the first line (blank) 57 cursor.readLine(); // throw away the second line (header) 59 protected void parseSegmentDefinitions(TextReader reader){ 60 char[] line; 61 reader.get(line); // throw away the first line (blank) 62 reader.get(line); // throw away the second line (header) 58 63 59 64 // read until there's a blank line 60 65 while(true){ 61 char[] line = cursor.readLine();66 reader.get(line); 62 67 if(line.length == 0) break; 63 68 } 64 69 } 65 70 66 protected void parsePublicsByName(ReadCursor cursor){ 67 cursor.readLine(); // throw away the first line (header) 68 cursor.readLine(); // throw away the second line (blank) 71 protected void parsePublicsByName(TextReader reader){ 72 char[] line; 73 reader.get(line); // throw away the first line (header) 74 reader.get(line); // throw away the second line (blank) 69 75 70 76 // read until there's a blank line 71 77 while(true){ 72 char[] line = cursor.readLine();78 reader.get(line); 73 79 if(line.length == 0) break; 74 80 75 81 // throw away the address (first nine chars) 76 82 if(line[14..21] == " Imp ") continue; // throw this away! We want the '__imp__' version instead. … … 81 87 uint pos = 0; 82 88 while(line[pos] != ' ') pos++; 83 char[] symbol = line[0..pos] ;89 char[] symbol = line[0..pos].dup; // get a copy 84 90 85 91 // parse whitespace (variable length)
