Changeset 91

Show
Ignore:
Timestamp:
12/21/05 13:20:34 (3 years ago)
Author:
pragma
Message:

Updated misc classes and utils

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/Utils.d

    r86 r91  
    3131    private import std.string; 
    3232    private import std.file; 
    33          
     33     
     34    alias writefln debugLog; 
     35     
    3436    struct DDLFile{ 
    3537        ubyte[] buffer; 
     
    172174        char[] result; 
    173175        uint pos; 
     176        uint next; 
    174177        for(pos=position; pos<data.length; pos++){ 
    175             if(data[pos] == '\r' || data[pos] == '\n'){ 
    176                 for(pos=pos; pos<data.length && (data[pos] == '\n' || data[pos] == '\r'); pos++){} 
     178            if(data[pos] == '\n'){ 
     179                next=pos+2; 
    177180                break; 
    178181            } 
    179         } 
     182            if(data[pos] == '\r'){ 
     183                next=pos+2; 
     184                if(pos+1 < data.length && data[pos] == '\n'){ 
     185                    next++; 
     186                } 
     187                break; 
     188            } 
     189        } 
     190        //if(data[pos] != '\n')  
    180191        result = cast(char[])data[position..pos]; 
    181         position = pos
     192        position = next
    182193        return result;       
    183194    } 
     
    203214    protected void allocSpace(uint amount){ 
    204215        if(position+amount > data.length){ 
    205             data ~= new ubyte[AllocSize]; 
     216            data ~= new ubyte[AllocSize < amount ? amount : AllocSize]; 
    206217        } 
    207218    } 
     
    242253    } 
    243254     
     255    public void writeText(char[] value){ 
     256        write(cast(ubyte[])value); 
     257    } 
     258     
    244259    public uint getPosition(){ 
    245260        return position; 
  • trunk/ddl/insitu/InSituMapBinary.d

    r85 r91  
    4242        parseSegmentDefinitions(cursor); 
    4343        parsePublicsByName(cursor);  
    44         // throw away the publics by address    
     44        // throw away the publics by address 
    4545    } 
    4646     
     
    7272            char[] line = cursor.readLine(); 
    7373            if(line.length == 0) break; 
    74              
     74                        
    7575            // throw away the address (first nine chars)  
    7676            if(line[14..21] == "  Imp  ") continue; // throw this away! We want the '__imp__' version instead. 
     
    112112            sym.address = cast(void*)rva; 
    113113            sym.name = symbol; 
    114              
     114                        
    115115            allSymbols[sym.name] = sym; 
    116116             
  • trunk/utils/bless.d

    r85 r91  
    3333 
    3434private import utils.ddlinfo_bn; 
    35 private import ddl.all; 
    3635private import utils.ArgParser; 
    3736 
  • trunk/utils/insitu.d

    r31 r91  
    2727module utils.insitu; 
    2828 
    29 // DDL bless utility 
     29// DDL insitu utility 
    3030 
    3131private import ddl.all; 
    3232private import ddl.insitu.all; 
    3333 
     34private import utils.ddlinfo_bn; 
    3435private import utils.ArgParser; 
    35  
    36 private import std.string; 
    37 private import std.stdio; 
    38 private import std.stream; 
    39 private import std.file; 
    40 private import std.zlib; 
    4136 
    4237 
    4338char[] helpText =  
    44 "InSitu - Optimized in situ module generator - V1.0 
     39"InSitu - Optimized in situ module generator - V1.1 %d 
    4540Copyright (C) 2005 Eric Anderton 
    4641Documentation: http://www.dsource.org/projects/ddl 
     
    5045 
    5146Usage:  
    52   insitu <map file> 
    53   insitu <map file> <output file> 
     47  insitu <map file>  { -switch } 
     48  insitu <map file>  { -switch } 
     49   
     50  -o    Specify output file 
     51  -c    Compression level for data (1-9) 
    5452   
    5553  When the output file is not specified, a file in the 
    56   form of <filename>.situ will be used instead. 
     54  form of <filename>.situ will be used by instead.  
     55   
     56  Map files are expected to be the same format as provided 
     57  by DMD. 
    5758"; 
    5859 
     60//  -d  Create a .d file with a SituLibrary class instead 
     61//With the -d switch, <filename>_InSitu.d will be used instead. 
     62   
     63 
    5964int main(char[][] args){ 
     65    DefaultRegistry registry = new DefaultRegistry(); 
     66     
    6067    if(args.length == 1 || args.length > 3){ 
    61         writefln("%s",helpText); 
     68        Stdout.println(helpText,auto_build_number); 
     69        Stdout.println("Supported Object Types:"); 
     70        foreach(char[] ext; registry.getSupportedTypes){ 
     71            Stdout.print("%s ",ext); 
     72        } 
     73        Stdout.println(""); 
    6274        return 0; 
    6375    } 
    6476             
    6577    // get the filename 
    66     char[] inputFilename = args[1]; 
    67     int split = inputFilename.irfind("."); 
    68      
    69     char[] originalShortName = inputFilename; 
    70     char[] originalExtension; 
    71      
    72     if(split >= 0){ 
    73         originalExtension = inputFilename[split+1..$]; 
    74         originalShortName = inputFilename[0..($-originalExtension.length)-1]; 
    75     } 
     78    DDLFile inputFile; 
     79    inputFile.create(args[1]); 
    7680     
    7781    // determine the output file 
    78     char[] outputFilename; 
    79      
    80     if(args.length == 2){ 
    81         outputFilename = originalShortName ~ ".situ"; 
    82     }    
    83     else if(args.length == 3){ 
    84         outputFilename = args[2]; 
    85     } 
     82    char[] outputFilename = inputFile.getName; 
     83    //bit dOutput = false; 
     84    bit filenameOverride = false; 
    8685     
    8786    //TODO: determine the compression level 
     
    9089    // get dash prefixed args 
    9190    ArgParser parser = new ArgParser("-"); 
     91     
     92    parser.bind("o",delegate uint(char[] value){ 
     93        filenameOverride = true; 
     94        outputFilename = value; 
     95        return value.length; 
     96    });      
    9297         
    9398    parser.bind("c",delegate uint(char[] value){ 
     
    99104        return 1; 
    100105    }); 
     106             
     107    //parser.bind("d",delegate void(){ 
     108    //  dOutput = true; 
     109    //}); 
    101110     
    102     parser.parse(args[2..$]);   
     111    parser.parse(args[2..$]); 
    103112     
    104113    // load the .map file and get what we need 
    105     File inputFile = new File(inputFilename); 
     114    //TODO: load via registry instead, and use DynamicLibrary 
     115    inputFile.load(); 
    106116    InSituMapBinary inputBinary = new InSituMapBinary(); 
    107117    inputBinary.load(inputFile); 
    108     inputFile.close(); 
    109118     
    110     debug writefln("%d exports total",inputBinary.getAllSymbols().values.length); 
    111     debug writefln("first export: %s",inputBinary.getAllSymbols().values[0].name); 
     119    debugLog("%d bytes loaded",inputFile.buffer.length); 
    112120     
    113     // commit the data to the lib-style binary 
    114     File outputFile = new File(outputFilename,FileMode.OutNew); 
    115     InSituLibBinary outputBinary = new InSituLibBinary(); 
    116     outputBinary.setAllSymbols(inputBinary.getAllSymbols()); 
    117     outputBinary.save(outputFile,compressionLevel); 
    118     outputFile.close(); 
    119      
     121    debugLog("%d exports total",inputBinary.getAllSymbols().values.length); 
     122 
     123    DDLFile outputFile; 
     124    outputFile.create(outputFilename);   
     125         
     126    //if(!dOutput){ 
     127        if(!filenameOverride) outputFile.filename ~= ".situ"; 
     128        // commit the data to the lib-style binary 
     129        InSituLibBinary outputBinary = new InSituLibBinary(); 
     130        outputBinary.setAllSymbols(inputBinary.getAllSymbols()); 
     131        outputBinary.save(outputFile,compressionLevel); 
     132    /*} 
     133    else{ 
     134        // create .d sourcecode to use instead 
     135        WriteCursor cursor = new WriteCursor(); 
     136         
     137        char[] symbolExterns = ""; 
     138        char[] symbolPointers = ""; 
     139         
     140        // create buffers 
     141        foreach(ExportSymbol exp; inputBinary.getAllSymbols()){ 
     142            //NOTE: hack off the first char ('_') to get the correct symbol 
     143            char[] name = exp.name[1..$]; 
     144            symbolExterns ~= "\tvoid " ~ name ~ "();\n"; 
     145            symbolPointers ~= "\t\t{&" ~ name ~ ",\"" ~ exp.name ~ "\"},\n"; 
     146        } 
     147 
     148        char[] dText = 
     149"//Auto-generated by the DDL In-Situ tool 
     150module " ~ outputFile.filename ~ "_InSitu; 
     151import ddl.insitu.InSituStubLibrary; 
     152extern(C){ 
     153" ~ symbolExterns ~ " 
     154
     155const ExportSymbol[char[]] symbols=[ 
     156" ~ symbolPointers ~ " 
     157    ]; 
     158class InSituLibrary : InSituStubLibrary{ 
     159    public this(){ 
     160        super(symbols); 
     161    } 
     162}"; 
     163        cursor.writeText(dText); 
     164        if(!filenameOverride) outputFile.filename ~= "_InSitu.d"; 
     165        outputFile.save(cursor.getData()); 
     166    }*/ 
    120167    return 0; 
    121168}