Changeset 150

Show
Ignore:
Timestamp:
02/23/06 12:50:12 (3 years ago)
Author:
larsivi
Message:

Merging in pragmas refactorings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/larsivi-elf/ddl/insitu/InSituBinary.d

    r85 r150  
    2626 
    2727private import ddl.ExportSymbol; 
    28 private import ddl.Utils
     28private import ddl.FileBuffer
    2929 
    3030interface InSituBinary{ 
    31     public void load(DDLFile file); 
     31    public void load(FileBuffer file); 
    3232    public ExportSymbol[char[]] getAllSymbols(); 
    3333} 
  • branches/larsivi-elf/ddl/insitu/InSituLibBinary.d

    r92 r150  
    2727private import std.zlib; 
    2828 
    29 private import ddl.Utils; 
     29private import ddl.FileBuffer; 
     30private import ddl.DDLReader; 
     31private import ddl.DDLWriter; 
    3032private import ddl.ExportSymbol; 
    3133private import ddl.insitu.InSituBinary; 
     34 
     35private import mango.io.GrowBuffer; 
    3236 
    3337class InSituLibBinary : InSituBinary{ 
     
    5054    } 
    5155         
    52     public void load(DDLFile file){ 
    53         ReadCursor cursor = new ReadCursor(file)
     56    public void load(FileBuffer file){ 
     57        ubyte[] magic
    5458        uint fileVersion; 
    55         uint symbolCount;        
     59        uint symbolCount; 
     60        void[] binaryData; 
     61        DDLReader reader = new DDLReader(file);      
    5662                 
    5763        // read the magic 
    58         char[] magic = cast(char[])cursor.getBytes(8); 
    59         assert(magic == magicString); 
     64        reader.get(magic,8); 
     65        reader.get(fileVersion);        
    6066         
    61         // read the version 
    62         fileVersion = cursor.getDWord(); 
     67        assert(magic == cast(ubyte[])magicString); 
    6368        assert(fileVersion == InSituVersion); 
    6469                 
    6570        // read symbol count 
    66         symbolCount = cursor.getDWord(); 
     71        reader.get(symbolCount); 
    6772         
    6873        // 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)); 
    7176         
    7277        // read symbols 
    7378        for(uint i=0; i<symbolCount; i++){ 
     79            uint address; 
    7480            ExportSymbol sym; 
    7581             
    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                     
    7987            allSymbols[sym.name] = sym; 
    8088        } 
    8189    } 
    8290     
    83     public void save(DDLFile file,ubyte compressionLevel){ 
    84         WriteCursor cursor = new WriteCursor(); 
     91    public void save(FileBuffer file,ubyte compressionLevel){ 
     92        DDLWriter zipWriter = new DDLWriter(new GrowBuffer()); 
    8593        assert(compressionLevel <= 9); 
    8694 
    8795        // write everything to the buffer 
    8896        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        } 
    92100         
    93101        // compress the data 
    94         ubyte[] binaryData = cast(ubyte[])compress(cursor.getData,compressionLevel); 
     102        ubyte[] binaryData = cast(ubyte[])compress(zipWriter.getBuffer.toString,compressionLevel); 
    95103         
    96104        // 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); 
    104110    } 
    105111} 
  • branches/larsivi-elf/ddl/insitu/InSituLoader.d

    r85 r150  
    3131private import ddl.DynamicLibraryLoader; 
    3232private import ddl.LoaderRegistry; 
    33 private import ddl.Utils
     33private import ddl.FileBuffer
    3434 
    3535private import ddl.insitu.InSituMapBinary; 
     
    4949    } 
    5050         
    51     public bit canLoadLibrary(DDLFile file){ 
    52         return file.buffer[0..8] == cast(ubyte[])"DDLSITU!"; 
     51    public bit canLoadLibrary(FileBuffer file){ 
     52        return (cast(char[])file.get(8,false)) == "DDLSITU!"; 
    5353    } 
    5454     
    55     public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 
     55    public DynamicLibrary load(LoaderRegistry registry,FileBuffer file){ 
    5656        InSituLibBinary binary = new InSituLibBinary(); 
    5757        binary.load(file); 
     
    7272    }    
    7373         
    74     public bit canLoadLibrary(DDLFile file){ 
    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"; 
    7676    } 
    7777     
    78     public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 
     78    public DynamicLibrary load(LoaderRegistry registry,FileBuffer file){ 
    7979        InSituMapBinary binary = new InSituMapBinary(); 
    8080        binary.load(file); 
  • branches/larsivi-elf/ddl/insitu/InSituMapBinary.d

    r91 r150  
    2626 
    2727private import ddl.ExportSymbol; 
    28 private import ddl.Utils
     28private import ddl.FileBuffer
    2929private import ddl.insitu.InSituBinary; 
     30 
     31private import mango.io.TextReader; 
     32private import mango.text.LineIterator; 
     33 
    3034 
    3135/* Binary 'file' for DMD map files */ 
     
    3842    } 
    3943         
    40     public void load(DDLFile file){ 
    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);    
    4448        // throw away the publics by address 
    4549    } 
     
    5357    } 
    5458     
    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) 
    5863         
    5964        // read until there's a blank line 
    6065        while(true){ 
    61             char[] line = cursor.readLine(); 
     66            reader.get(line);  
    6267            if(line.length == 0) break; 
    6368        } 
    6469    } 
    6570     
    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) 
    6975                 
    7076        // read until there's a blank line 
    7177        while(true){ 
    72             char[] line = cursor.readLine(); 
     78            reader.get(line); 
    7379            if(line.length == 0) break; 
    74                          
     80                                    
    7581            // throw away the address (first nine chars)  
    7682            if(line[14..21] == "  Imp  ") continue; // throw this away! We want the '__imp__' version instead. 
     
    8187            uint pos = 0; 
    8288            while(line[pos] != ' ') pos++; 
    83             char[] symbol = line[0..pos]; 
     89            char[] symbol = line[0..pos].dup; // get a copy 
    8490             
    8591            // parse whitespace (variable length)