Changeset 85

Show
Ignore:
Timestamp:
12/17/05 17:08:57 (3 years ago)
Author:
pragma
Message:

Dirty Commit (still testing latest refactoring stage and improving utils)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/buildutils.bat

    r66 r85  
    11@echo off 
    22 
     3echo UTILS:Building 
    34build -full utils\ddlinfo.d 
    45build -full utils\bless.d 
     
    910copy insitu.map utils 
    1011 
    11 zip ../downloads/ddl.utils.1.0.bin.zip utils/*.exe 
     12echo UTILS:Packaging Win32 Binaries 
     13rm ../downloads/ddl.beta.utils.1.0.win32.bin.zip 
     14zip ../downloads/ddl.beta.utils.1.0.win32.bin.zip utils/*.exe 
     15 
     16echo UTILS:Packaging Source 
     17rm ../downloads/ddl.beta.utils.1.0.src.zip 
     18zip ../downloads/ddl.beta.utils.1.0.src.zip utils/*.d 
  • trunk/clean.bat

    r66 r85  
     1@echo off  
     2 
     3echo CLEAN:cleaning files 
    14del /s ddl\*.obj 
    25del /s ddl\*.html 
  • trunk/ddl/DynamicLibrary.d

    r66 r85  
    4141    public ExportSymbol getExport(char[] name); 
    4242    public DynamicModule[] getModules(); 
     43    public char[] getType(); 
     44    public char[][char[]] getAttributes(); 
    4345     
    4446    public void* getExportAddress(char[] name){ 
  • trunk/ddl/DynamicLibraryLoader.d

    r66 r85  
    3333 
    3434private import ddl.DynamicLibrary; 
    35 private import std.stream; 
    36 private import std.string; 
    37  
    38 interface DynamicLibraryLoader{ 
    39     public DynamicLibrary loadFromFile(char[] filename); 
    40     public DynamicLibrary loadFromStream(Stream stream); 
    41 
    42  
    43 package static DynamicLibraryLoader[char[]] loaders; 
     35private import ddl.LoaderRegistry; 
     36private import ddl.Utils; 
    4437 
    4538/** 
    46     Loads a DDL supported binary from a file. 
     39    Base class for all dynamic library loaders. 
     40*/ 
     41abstract class DynamicLibraryLoader{ 
     42    /** 
     43        Returns: the type for this library. 
     44    */ 
     45    public char[] getLibraryType(); 
    4746     
    48     Params: 
    49         filename = The filename of the binary file to load. 
    50 */ 
    51 DynamicLibrary loadDDL(char[] filename){ 
    52     uint split = filename.irfind("."); 
    53     if(split == -1) return null; 
     47    /**  
     48        Returns: the preferred file extension for this library. 
     49    */ 
     50    public char[] getFileExtension(); 
    5451     
    55     char[] extension = filename[split+1..$]; 
     52    /** 
     53        Returns: true if the file can be loaded by this loader, false if it cannot. 
     54    */ 
     55    public bit canLoadLibrary(DDLFile file); 
    5656     
    57     return loadDDL(filename,extension); 
     57    /** 
     58        Loads a binary file. 
     59     
     60        Returns: the library stored in the provided file. 
     61        Params: 
     62            file = the file that contains the binary library data. 
     63    */ 
     64    public DynamicLibrary load(LoaderRegistry registry,DDLFile file); 
    5865} 
    59  
    60 /** 
    61     Loads a DDL supported binary from a file. 
    62      
    63     Params: 
    64         filename = The filename of the binary file to load. 
    65         extension = The true extension/type of the binary file. 
    66 */ 
    67 DynamicLibrary loadDDL(char[] filename,char[] extension){    
    68     if(!(extension in loaders)) return null; 
    69      
    70     DynamicLibraryLoader loader = loaders[extension]; 
    71      
    72     return loader.loadFromFile(filename); 
    73 } 
    74  
    75 /** 
    76     Returns a list of extensions currently supported.    
    77 */ 
    78 char[][] getDDLSupportedExtensions(){ 
    79     return loaders.keys; 
    80 } 
  • trunk/ddl/Linker.d

    r66 r85  
    3030module ddl.Linker; 
    3131 
    32 //private import ddl.CachedLoader
     32private import ddl.Utils
    3333private import ddl.ExportSymbol; 
    3434private import ddl.DynamicLibrary; 
    3535private import ddl.DynamicModule; 
    3636private import ddl.Demangle; 
    37  
    38 debug private import std.stdio; 
    39  
    40 private import std.moduleinit; // used for ModuleInfo 
     37private import ddl.LoaderRegistry; 
     38 
     39private import std.moduleinit; // used for ModuleInfo type 
    4140 
    4241/** 
     
    7170    General-Purpose runtime linker for DDL. 
    7271*/ 
    73 class Linker{    
     72class Linker{ 
     73    protected LoaderRegistry registry; 
    7474    /**  
    7575        Library list for libraries used for linking. 
     
    9292     
    9393    /**  
    94         Default constructor. 
    95     */ 
    96     public this(){ 
    97         // do nothing 
    98     } 
    99      
    100     /** 
    101         Adds a library to the linker to be used during link operations. 
    102     */ 
    103     void add(DynamicLibrary lib){ 
    104         debug foreach(DynamicModule mod; lib.getModules){ 
    105             writefln("add: %s",mod.getName); 
    106         } 
    107         libraries ~= lib; 
     94        The linker uses an LoaderRegistry to handle internal library dependencies 
     95        automatically, such that the developer can more easily automate linking behavior. 
     96             
     97        Params: 
     98            registry = the LoaderRegistry to use when loading binaries. 
     99    */ 
     100    public this(LoaderRegistry registry){ 
     101        this.registry = registry; 
     102    } 
     103     
     104    /** 
     105        Returns: the current registry 
     106    */ 
     107    public LoaderRegistry getRegistry(){ 
     108        return this.registry; 
    108109    } 
    109110     
     
    174175            nextDep: 
    175176            debug if(sym == ExportSymbol.init){ 
    176                 writefln("cannot find %s",dep); 
     177                debugLog("[Linker.link]: cannot find %s",dep); 
    177178            } 
    178179        } 
     
    217218        } 
    218219    } 
     220     
     221     
     222    /** 
     223        Registers a library with the linker to be used during link operations. 
     224    */ 
     225    void register(DynamicLibrary lib){ 
     226        debug foreach(DynamicModule mod; lib.getModules){ 
     227            debugLog("[Linker.register]: %s",mod.getName); 
     228        } 
     229        libraries ~= lib; 
     230    } 
     231     
     232    /**  
     233        Loads a DDL library and registers it with this linker. 
     234         
     235        Returns: the DynamicLibrary that corresponds to filename 
     236        Params: 
     237            filename = the file name of the library to load 
     238    */ 
     239    public DynamicLibrary loadAndRegister(char[] filename){ 
     240        DynamicLibrary result = registry.load(filename); 
     241        register(result); 
     242        return result; 
     243    } 
     244     
     245    /**  
     246        Loads a DDL library and links it against all registered libraries. 
     247         
     248        Returns: the DynamicLibrary that corresponds to filename 
     249        Params: 
     250            filename = the file name of the library to load 
     251    */ 
     252    public DynamicLibrary loadAndLink(char[] filename){ 
     253        DynamicLibrary result = registry.load(filename); 
     254        link(result); 
     255        return result; 
     256    } 
     257     
     258    /**  
     259        Loads a DDL library, links it against all registered libraries, and registers it. 
     260         
     261        Returns: the DynamicLibrary that corresponds to filename 
     262        Params: 
     263            filename = the file name of the library to load 
     264    */ 
     265    public DynamicLibrary loadLinkAndRegister(char[] filename){ 
     266        DynamicLibrary result = registry.load(filename); 
     267        link(result); 
     268        register(result); 
     269        return result; 
     270    }    
    219271} 
  • trunk/ddl/all.d

    r66 r85  
    2525module ddl.all; 
    2626 
    27 // low level support 
     27import ddl.DynamicLibrary; 
     28import ddl.DefaultRegistry; 
     29import ddl.DynamicLibraryLoader; 
     30import ddl.DynamicModule; 
    2831import ddl.ExportSymbol; 
    29 import ddl.DynamicModule; 
    30 import ddl.DynamicLibrary; 
    31 import ddl.DynamicLibraryLoader; 
    3232import ddl.Demangle; 
    33 import ddl.bootstrap; 
    3433import ddl.Linker; 
     34import ddl.LoaderRegistry; 
     35import ddl.Mangle; 
     36import ddl.Utils; 
     37 
  • trunk/ddl/coff/COFFImage.d

    r55 r85  
    44//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    55 
    6 private import ddl.all; 
     6private import ddl.ExportSymbol; 
     7private import ddl.Utils; 
     8 
    79private import ddl.coff.COFF; 
    810private import ddl.coff.COFFBinary; 
    911private import ddl.coff.COFFObject; 
    10 //private import ddl.coff.codeview; 
    11 //private import ddl.coff.petools; 
    12 //private import ddl.coff.symbols; 
    13  
    14  
    15 //private import windows.win32; 
    16 //private import windows.winnt; 
     12 
    1713private import std.string; 
    1814private import std.stdio; 
     
    141137            uint debug_dir = RVA2Offset( datadir.Debug.RVA ); 
    142138            uint dircnt = datadir.Debug.Size / COFFImageDebugDirectory.sizeof; 
    143 //          debug writefln( "Found %d debug director%s at file position 0x%X\n",dircnt,dircnt==1?"y":"ies",debug_dir); 
     139//          debugLog( "Found %d debug director%s at file position 0x%X\n",dircnt,dircnt==1?"y":"ies",debug_dir); 
    144140 
    145141            // read debug directory 
  • trunk/ddl/coff/COFFLibrary.d

    r56 r85  
    44 
    55//import ddl.coff.coff; 
    6 import ddl.coff.COFFBinary; 
    7 import ddl.coff.COFFModule; 
    8 import ddl.coff.COFFWrite; 
    9  
    10 private import ddl.all; 
     6private import ddl.coff.cursor; 
     7private import ddl.coff.COFFBinary; 
     8private import ddl.coff.COFFModule; 
     9private import ddl.coff.COFFWrite; 
     10 
     11private import ddl.ExportSymbol; 
     12private import ddl.DynamicLibrary; 
     13private import ddl.DynamicModule; 
     14private import ddl.Utils; 
    1115 
    1216private import std.string; 
     
    4549        loadFromStream(stream); 
    4650    } 
    47  
     51     
     52    public this(DataCursor cur){ 
     53        loadFromCursor(cur); 
     54    } 
     55     
     56    public char[] getType(){ 
     57        return("COFF"); 
     58    } 
     59         
     60    public char[][char[]] getAttributes(){ 
     61        return (char[][char[]]).init; //TODO: support this 
     62    }        
     63     
    4864    public ExportSymbol[] getExports() 
    4965    { 
     
    8096 
    8197        // print debug output 
    82         debug writefln( "File: ", filename ); 
    83         debug writefln( "File type: COFF LIBRARY\n" ); 
     98        debug debugLog( "File: ", filename ); 
     99        debug debugLog( "File type: COFF LIBRARY\n" ); 
    84100 
    85101        // open & parse the file 
     
    87103        loadFromStream( libFile ); 
    88104        libFile.close(); 
     105    } 
     106     
     107    void loadFromCursor(DataCursor cur){ 
     108        //TODO: 
    89109    } 
    90110 
     
    112132        while( !file.eof() ) 
    113133        { 
    114 //          debug writefln( "reading library member header %d - %d bytes left", i, file.available ); 
     134//          debug debugLog( "reading library member header %d - %d bytes left", i, file.available ); 
    115135 
    116136            // each member header starts on the first even address after the end of the previous archive member 
    117137            if( ( nAddress & 1 ) == 1 ) 
    118138            { 
    119 //              debug writefln( "* padding data address" ); 
     139//              debug debugLog( "* padding data address" ); 
    120140                byte bTemp; 
    121141                file.read( bTemp ); 
     
    168188                // link member #1 - skip 
    169189                assert( itemName == "/" ); 
    170                 debug writefln( "\nLIB MEMBER #1 - 1st Linker Member - obsolete" ); 
     190                debug debugLog( "\nLIB MEMBER #1 - 1st Linker Member - obsolete" ); 
    171191                // next member 
    172192                i++; 
     
    179199                assert( itemName == "/" ); 
    180200 
    181                 debug writefln( "\nLIB MEMBER #2 - 2nd Linker Member - symbols table" ); 
     201                debug debugLog( "\nLIB MEMBER #2 - 2nd Linker Member - symbols table" ); 
    182202 
    183203                // load linker symbol 
     
    187207                uint numModules = (*cast(uint*)dataPtr); 
    188208                uint[] moduleOffsets; 
    189                 debug writefln( "\t\tNumber of members: ", numModules ); 
     209                debug debugLog( "\t\tNumber of members: ", numModules ); 
    190210 
    191211                // increment data 
     
    198218                    foreach( int index, uint offset; moduleOffsets ) 
    199219                    { 
    200 //                      writefln( "\t\t\t%d - 0x%08x", index, offset ); 
     220//                      debugLog( "\t\t\t%d - 0x%08x", index, offset ); 
    201221                    } 
    202222                } 
     
    208228                // get number of symbols 
    209229                numSymbols = (*cast(uint*)dataPtr); 
    210                 debug writefln( "\t\tNumber of symbols: ", numSymbols ); 
     230                debug debugLog( "\t\tNumber of symbols: ", numSymbols ); 
    211231 
    212232                // increment data 
     
    220240                    { 
    221241                        assert( offset <= numModules ); 
    222 //                      writefln( "\t\t\t%d - archive %d", index, offset ); 
     242//                      debugLog( "\t\t\t%d - archive %d", index, offset ); 
    223243                    } 
    224244                } 
     
    232252                    char[] symbolName = std.string.toString( dataPtr ); 
    233253                    dataPtr += symbolName.length + 1; 
    234 //                  writefln( "\t\t\t%d - ", symbolIndex, symbolName ); 
     254//                  debugLog( "\t\t\t%d - ", symbolIndex, symbolName ); 
    235255 
    236256                    // place symbol into table 
     
    246266            if( (i == 2) && (itemName == "//") ) 
    247267            { 
    248                 debug writefln( "\nLIB MEMBER #3 - 3rd Linker Member - longnames table" ); 
     268                debug debugLog( "\nLIB MEMBER #3 - 3rd Linker Member - longnames table" ); 
    249269 
    250270                // longnames list 
     
    278298                writef( "\nLIB MEMBER #", std.conv.toString(i+1) ); 
    279299                if( importObj ) 
    280                     writefln( " - COFF IMPORT OBJECT\n" ); 
     300                    debugLog( " - COFF IMPORT OBJECT\n" ); 
    281301                else 
    282                     writefln( " - COFF OBJECT\n" ); 
    283                 writefln( "\tname ",  itemName ); 
    284                 writefln( "\tdate ",  strDate ); 
    285                 writefln( "\tuser ",  itemUser ); 
    286                 writefln( "\tgroup ",     itemGroup ); 
    287                 writefln( "\tmode ",  itemMode ); 
    288                 writefln( "\tsize ",  itemSize ); 
     302                    debugLog( " - COFF OBJECT\n" ); 
     303                debugLog( "\tname ",  itemName ); 
     304                debugLog( "\tdate ",  strDate ); 
     305                debugLog( "\tuser ",  itemUser ); 
     306                debugLog( "\tgroup ",     itemGroup ); 
     307                debugLog( "\tmode ",  itemMode ); 
     308                debugLog( "\tsize ",  itemSize ); 
    289309            } 
    290310 
     
    375395        } 
    376396 
    377         debug writefln( "COFF library parsing complete" ); 
     397        debug debugLog( "COFF library parsing complete" ); 
    378398 
    379399        //skip the dictionary (redundant) 
  • trunk/ddl/coff/COFFLoader.d

    r58 r85  
    44import ddl.coff.COFFModule; 
    55import ddl.coff.COFFLibrary; 
     6import ddl.coff.cursor; 
    67 
    7 private import ddl.all; 
    8 private import std.stream; 
     8private import ddl.ExportSymbol; 
     9private import ddl.DynamicLibrary; 
     10private import ddl.DynamicLibraryLoader; 
     11private import ddl.LoaderRegistry; 
     12private import ddl.Utils; 
    913 
    10 class COFFLoader : DynamicLibraryLoader 
    11 
    12     public DynamicLibrary loadFromFile(char[] filename) 
    13     { 
    14         return new COFFLibrary(filename); 
     14class COFFLibLoader : DynamicLibraryLoader{ 
     15    public static char[] typeName = "COFFLIB"; 
     16    public static char[] fileExtension = "lib"; 
     17     
     18    public char[] getLibraryType(){ 
     19        return(typeName); 
    1520    } 
    16  
    17     public DynamicLibrary loadFromStream(Stream stream) 
    18     { 
    19         return new COFFLibrary(stream); 
     21     
     22    public char[] getFileExtension(){ 
     23        return(fileExtension); 
     24    }    
     25         
     26    public bit canLoadLibrary(DDLFile file){ 
     27        return file.buffer[0..8] == cast(ubyte[])"!<arch>\n"; 
     28    } 
     29     
     30    public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 
     31        DataCursor cur; 
     32        cur.data = cast(char[])file.buffer; 
     33        cur.position = 0; 
     34         
     35        return new COFFLibrary(cur); 
    2036    } 
    2137} 
    2238 
    23  
    24 class COFFObjLoader : DynamicLibraryLoader 
    25 
    26     public bit canLoad(char[] filename) 
    27    
    28         return (filename.length >= 4) && (filename[$-4..$] == ".obj"); 
     39class COFFObjLoader : DynamicLibraryLoader{ 
     40    public static char[] typeName = "COFFOBJ"; 
     41    public static char[] fileExtension = "obj"; 
     42     
     43    public char[] getLibraryType()
     44        return(typeName); 
    2945    } 
    30  
    31     public DynamicLibrary loadFromStream(Stream stream) 
    32     { 
     46     
     47    public char[] getFileExtension(){ 
     48        return(fileExtension); 
     49    }    
     50         
     51    public bit canLoadLibrary(DDLFile file){ 
     52        return file.buffer[0] == 0x4c && file.buffer[1] == 0x01; 
     53    } 
     54     
     55    public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 
    3356        COFFLibrary lib = new COFFLibrary(); 
    3457 
    3558        // load object format 
    36         COFFModule mod = new COFFModule(stream); 
     59        DataCursor cur; 
     60        cur.data = cast(char[])file.buffer; 
     61        cur.position = 0; 
     62         
     63        COFFModule mod = new COFFModule(cur,file.filename); 
    3764        lib.addModule(mod); 
    38  
    39         return lib; 
    40     } 
    41  
    42     public DynamicLibrary loadFromFile(char[] filename) 
    43     { 
    44         assert(filename.length >= 4); 
    45  
    46         COFFLibrary lib = new COFFLibrary(); 
    47  
    48         // load object format 
    49         COFFModule mod = new COFFModule(filename); 
    50         lib.addModule(mod); 
    51  
    5265        return lib; 
    5366    } 
    5467} 
     68 
     69class COFFPELoader : DynamicLibraryLoader{ 
     70    public static char[] typeName = "COFFDLL"; 
     71    public static char[] fileExtension = "dll"; //TODO: what about .exe? 
     72     
     73    public char[] getLibraryType(){ 
     74        return(typeName); 
     75    } 
     76     
     77    public char[] getFileExtension(){ 
     78        return(fileExtension); 
     79    }    
     80         
     81    public bit canLoadLibrary(DDLFile file){ 
     82        return file.buffer[0] == 'M' && file.buffer[1] == 'Z'; 
     83    } 
     84     
     85    public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 
     86        throw new Exception("COFF/PE files are not supported"); 
     87        return null; 
     88    } 
     89} 
  • trunk/ddl/coff/COFFModule.d

    r57 r85  
    33module ddl.coff.COFFModule; 
    44 
    5 import ddl.all; 
    6 import ddl.coff.COFF; 
    7 import ddl.coff.COFFBinary; 
    8 import ddl.coff.COFFObject; 
    9 import ddl.coff.cursor; 
     5private import ddl.ExportSymbol; 
     6private import ddl.DynamicModule; 
     7private import ddl.Utils; 
     8 
     9private import ddl.coff.COFF; 
     10private import ddl.coff.COFFBinary; 
     11private import ddl.coff.COFFObject; 
     12private import ddl.coff.cursor; 
     13 
    1014 
    1115private import std.string; 
  • trunk/ddl/coff/COFFObject.d

    r58 r85  
    33// COFF Object class (.obj file) 
    44 
    5 import ddl.all; 
    6  
    7 import ddl.coff.COFF; 
    8 import ddl.coff.COFFBinary
    9 //import ddl.coff.coffwrite
     5private import ddl.ExportSymbol; 
     6private import ddl.Utils; 
     7 
     8private import ddl.coff.COFF
     9private import ddl.coff.COFFBinary
    1010 
    1111private import std.string; 
     
    115115        this.name       = getBaseName( filename ).dup; 
    116116 
    117         debug writefln( "COFFObject - load from file: %s (%s)", this.filename, this.name ); 
     117        writefln( "COFFObject - load from file: %s (%s)", this.filename, this.name ); 
    118118 
    119119        loadFromStream( new File(filename, FileMode.In) ); 
     
    239239                    case IMAGE_REL_I386_DIR32:      // The targets 32-bit virtual address. 
    240240                        fix.isSegmentRelative   = false;    // is this a segment relative fixup (true=add address of segment, false=use actual address) 
    241                         debug writefln( "fixup type: target" ); 
     241                        writefln( "fixup type: target" ); 
    242242                        break; 
    243243                    case IMAGE_REL_I386_REL32:      // The 32-bit relative displacement to the target. This supports the x86 relative branch and call instructions. 
    244244                        fix.isSegmentRelative   = true;     // is this a segment relative fixup (true=add address of segment, false=use actual address) 
    245                         debug writefln( "fixup type: 32-bit relative" ); 
     245                        writefln( "fixup type: 32-bit relative" ); 
    246246                        break; 
    247247//                  case IMAGE_REL_I386_DIR32NB:    // The targets 32-bit relative virtual address. 
    248 //                      debug writefln( "fixup type: relative target" ); 
     248//                      writefln( "fixup type: relative target" ); 
    249249//                      break; 
    250250//                  case IMAGE_REL_I386_SECTION:    // The 16-bit-section index of the section containing the target. This is used to support debugging information. 
    251 //                      debug writefln( "fixup type: section index" ); 
     251//                      writefln( "fixup type: section index" ); 
    252252//                      break; 
    253253//                  case IMAGE_REL_I386_SECREL:     // The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage. 
    254 //                      debug writefln( "fixup type: 32-bit offset" ); 
     254//                      writefln( "fixup type: 32-bit offset" ); 
    255255//                      break; 
    256256                    default: 
     
    336336    protected void resolveFixups(Fixup[] fixupSet) 
    337337    { 
    338         debug writefln("resolve fixups (%d)", fixupSet.length ); 
     338        writefln("resolve fixups (%d)", fixupSet.length ); 
    339339        for(uint fixIdx=0; fixIdx<fixupSet.length; fixIdx++) 
    340340        { 
     
    350350                if( !target.isResolved ) 
    351351                { 
    352                     debug writefln(" - symbol unresolved" ); 
     352                    writefln(" - symbol unresolved" ); 
    353353                    // cannot fix this up yet, so save it for later 
    354354                    unresolvedFixups ~= *fix; 
     
    358358                // set address value 
    359359                fixupValue = cast(uint)target.address; 
    360                 debug writefln( "fixup: %s @ 0x08%x",target.name, fixupValue ); 
     360                writefln( "fixup: %s @ 0x08%x",target.name, fixupValue ); 
    361361            } 
    362362            else 
     
    368368                if( !sym.isResolved ) 
    369369                { 
    370                     debug writefln(" - symbol unresolved" ); 
     370                    writefln(" - symbol unresolved" ); 
    371371                    // cannot fix this up yet, so save it for later 
    372372                    unresolvedFixups ~= *fix; 
     
    377377//              fixupValue = cast(uint)(seg.data.ptr); 
    378378                fixupValue = cast(uint)sym.address; 
    379                 debug writefln("fixup: %s @ 0x08%x", sym.name, fixupValue); 
     379                writefln("fixup: %s @ 0x08%x", sym.name, fixupValue); 
    380380            } 
    381381 
     
    387387                // self relative fixup 
    388388                uint value = fixupValue - cast(uint)dest - 4; // relative fixup, offset by width of field 
    389                 debug writefln("[self relative] %d dest %0.8X (at %0.8X) to %0.8X",fix.destSectionIndex,*dest,dest,value^0xffffffff); 
     389                writefln("[self relative] %d dest %0.8X (at %0.8X) to %0.8X",fix.destSectionIndex,*dest,dest,value^0xffffffff); 
    390390                *dest = value; 
    391391            } 
    392392            else 
    393393            { 
    394                 debug writefln("[segment] %d dest %0.8X to %0.8X",fix.destSectionIndex,*dest,fixupValue); 
     394                writefln("[segment] %d dest %0.8X to %0.8X",fix.destSectionIndex,*dest,fixupValue); 
    395395                *dest += fixupValue; 
    396396            } 
     
    969969            if( (linkerDirectives.length = cast(ubyte) sect.data[0]) != 0 ) 
    970970                memcpy( linkerDirectives.ptr, &sect.data[1], linkerDirectives.length ); 
    971             debug writefln( "\t\tlinker directives: %s", linkerDirectives ); 
     971            writefln( "\t\tlinker directives: %s", linkerDirectives ); 
    972972        } 
    973973 
  • trunk/ddl/coff/COFFWrite.d

    r55 r85  
    22// utils for writing out PE-COFF data structures 
    33 
     4private import ddl.Utils; 
     5 
     6private import ddl.coff.COFF; 
     7private import ddl.coff.COFFBinary; 
    48private import ddl.coff.COFFObject;         // .obj 
    59private import ddl.coff.COFFLibrary;        // .lib 
  • trunk/ddl/ddl/DDLBinary.d

    <
    r68 r85  
    2828module ddl.ddl.DDLBinary; 
    2929 
    30 private import std.stream; 
    31 private import std.string; 
    32  
    33 debug private import std.stdio; 
     30private import ddl.Utils; 
    3431 
    3532/** 
    36     Exibits two different behaviors depending on which constructor is used. 
    37      
    38     - this(char[] binaryFilename)  
    39       Reads in the header only and skips the binary loading.   
    40       Call getBinaryStream to explicitly load the binary data from the file 
    41        
    42     - this(Stream) 
    43       Reads in the entire file from the stream, including the contained binary 
     33    Provides support for loading and saving DDL files. 
    4434*/ 
    4535class DDLBinary{ 
    46     protected static const uint DDLVersion = 0x00010000; 
     36    protected static const uint MagicBytes = ('D'<<24)|('D'<<16)|('L'<<8)|('!'); 
     37    protected static const uint DDLVersion = 0x00010001; 
    4738    protected static const uint BufferSize = 4096; 
    4839     
    49     public char[] filename; 
    50     public char[] binaryExtension
     40    public char[] binaryType; 
     41    public char[] processorArch
    5142    public char[][] definedNamespaces; 
    5243    public char[][] importedModules; 
     44    public char[][char[]] attributes; 
    5345    public ubyte[] binaryData; 
     46     
    5447     
    5548    public this(){ 
     
    5851     
    5952    /** 
    60         Loads just the file header, a call to getBinaryStream() does the rest. 
    61     */ 
    62     public this(char[] binaryFilename){ 
    63         this.filename = binaryFilename; 
    64         File binaryFile = new File(filename); 
    65         loadHeader(binaryFile);      
    66         binaryFile.close(); 
     53        Loads the entire file, and buffers the attached binary file 
     54    */   
     55    public this(ubyte[] data){ 
     56        ReadCursor cursor = new ReadCursor(data); 
     57        loadHeader(cursor); 
     58        binaryData ~= cursor.getCurrentData(); 
    6759    } 
    6860     
    69     /** 
    70         Loads the entire file 
    71     */ 
    72     public this(Stream binaryFile){ 
    73         loadHeader(binaryFile); 
    74          
    75         // get the entire trailing binary file 
    76         ubyte[] buffer = new ubyte[BufferSize]; 
    77          
    78         while(!binaryFile.eof()){ 
    79             uint amount = binaryFile.read(buffer); 
    80             binaryData ~= buffer[0..amount]; 
    81         } 
    82     } 
    83      
    84     protected uint readVersion(Stream binaryFile){ 
    85         uint ver; 
    86         binaryFile.read(ver); 
    87         if(ver != DDLVersion){ 
    88             throw new Exception(std.string.format("DDL library is the wrong version: %d.%d",(ver>>16),(ver&0x000F))); 
     61    protected void loadHeader(ReadCursor cursor){ 
     62        uint magic = cursor.getDWord(); 
     63        if(magic != MagicBytes){ 
     64            throw new Exception("File is not a DDL library"); 
    8965        } 
    9066         
    91         return ver; 
    92     } 
    93      
    94     protected void loadHeader(Stream binaryFile){ 
    95         readVersion(binaryFile); 
    96      
    97         uint binaryStart; 
    98         binaryFile.read(binaryStart); // dummy read, never used 
    99          
    100         binaryFile.read(binaryExtension); 
     67        uint ver = cursor.getDWord(); 
     68        if(ver != DDLVersion){ 
     69            throw new Exception("DDL library is the wrong version"); 
     70        } 
     71             
     72        uint binaryStart = cursor.getDWord(); 
     73        binaryType = cursor.getString(); 
     74        processorArch = cursor.getString(); 
    10175         
    10276        uint count; 
    103         char[] str; 
    10477         
    105         binaryFile.read(count); 
     78        count = cursor.getDWord();