Changeset 299

Show
Ignore:
Timestamp:
04/22/08 19:43:11 (9 months ago)
Author:
h3r3tic
Message:

memory usage reductions

Files:

Legend:

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

    r298 r299  
    238238                    } else { 
    239239                        char[] ext = sym.isExternal ? "external" : "local"; 
    240                         bool isWeak = sym.type == SymbolType.Weak; 
    241                         throw new DDLException("cannot resolve symbol: [{0:X}] {1} {2} {3}" ~ (isWeak ? " the symbol is weak" : "") ~ \n,cast(uint)sym.address, sym.getTypeName(), ext, sym.name); 
     240                        throw new DDLException("cannot resolve symbol: [{0:X}] {1} {2}"\n, cast(uint)sym.address, sym.getTypeName(), ext, sym.name); 
    242241                    } 
    243242                } 
     
    287286                } 
    288287                 
    289                 auto otherSym = otherMod.getSymbol(sym.name); 
     288                auto otherSym = lib.getSymbol(sym.name);//otherMod.getSymbol(sym.name); 
    290289                 
    291290                //if (SymbolType.Unresolved != otherSym.type) { 
  • trunk/ddl/PathLibrary.d

    r287 r299  
    235235   }    
    236236    
    237    public override ExportSymbolPtr getSymbol(char[] name){ 
     237   /+public override ExportSymbolPtr getSymbol(char[] name){ 
    238238      DynamicModule mod = this.getModuleForSymbol(name); 
    239239      if(mod) return mod.getSymbol(name); 
    240240      return null; 
    241    } 
     241   }+/ 
    242242          
    243243   public override DynamicModule[] getModules(){ 
     
    257257   public override char[][char[]] getAttributes(){ 
    258258      return this.attributes; 
     259   } 
     260 
     261   public override ExportSymbolPtr getSymbol(char[] name){ 
     262      if(name.length > 2 && name[0..2] == "_D"){ 
     263         for (char[] namespace = parseNamespace(name); namespace !is null; namespace = getParentNamespace(namespace)) { 
     264            // try a namespace lookup first 
     265            DynamicLibrary* xrefLib = namespace in namespaceXref; 
     266            if(xrefLib){ 
     267                return (*xrefLib).getSymbol(name); 
     268            }                     
     269              
     270            // dig through the root libs    
     271            foreach(DynamicLibrary lib; getRootLibraries()){ 
     272               ExportSymbolPtr sym = lib.getSymbol(name); 
     273               namespaceXref[namespace] = lib; 
     274               if (sym !is &ExportSymbol.NONE) return sym; 
     275            } 
     276                         
     277            foreach (xlat; namespaceTranslators) { 
     278                char[] path = FilePath.join(this.root.toString(), xlat(namespace.dup)); 
     279                if(isFullyLoaded){ 
     280                    //don't bother with path matching because we're already loaded 
     281                    foreach(libPath,lib; pathXref){ 
     282                        if(libPath == path){ 
     283                           ExportSymbolPtr sym = lib.getSymbol(name); 
     284                           namespaceXref[namespace] = lib; 
     285                           if (sym !is &ExportSymbol.NONE) return sym; 
     286                        } 
     287                    } 
     288                } 
     289                else{ 
     290                   // look for a path match 
     291                   if(path != ""){ 
     292                       auto test = new FilePath(path); 
     293                      if (test.exists && !test.isFolder){ 
     294                         DynamicLibrary lib = loaderRegistry.load(path); 
     295                         if(lib) { 
     296                            cachedLibraries ~= lib; 
     297                            namespaceXref[namespace] = lib; 
     298                            return lib.getSymbol(name); 
     299                         } 
     300                      } 
     301                       
     302                      //find first loadable library file that matches <root-path><path>/* and contains 'name' 
     303                      ExportSymbolPtr sym; 
     304                      (new FilePath(path)).toList(delegate bool(FilePath path_, bool isDirectory){ 
     305                         DynamicLibrary lib = loaderRegistry.load(path_.toString); 
     306                         if (lib) { 
     307                            cachedLibraries ~= lib; 
     308                            namespaceXref[namespace] = lib; 
     309                            sym = lib.getSymbol(name); 
     310                            return 0; 
     311                         } 
     312                         return 1; 
     313                      }); 
     314                      return sym; 
     315                   } 
     316               } 
     317            } 
     318         } 
     319      } 
     320      // match a non-D symbol 
     321      else{ 
     322         // dig through the root libs 
     323            foreach(DynamicLibrary lib; getRootLibraries()){ 
     324               auto sym = lib.getSymbol(name); 
     325               if (sym !is &ExportSymbol.NONE) return sym; 
     326            }  
     327      } 
     328      //failed to find the module 
     329      debug debugLog("PathLibrary.getSymbol - failed to find: {0}",name); 
     330      return null; 
    259331   } 
    260332 
     
    331403   } 
    332404 
     405 
    333406   // expects resource in file-path format 
    334407   public override ubyte[] getResource(char[] name){ 
  • trunk/ddl/omf/OMFBinary.d

    r297 r299  
    567567     
    568568    // use the repeat count repeat rawData  
    569     ubyte[] tempData; 
     569     
     570    // BUG? This code didn't do anything meaningful - h3 
     571    /+ubyte[] tempData; 
    570572    for(uint i=0; i<repeatCount; i++){ 
    571573        tempData ~= result; 
    572     } 
     574    }+/ 
     575     
    573576    // use rawData to store the result of the repeat 
    574577    return result; 
     
    941944            thisRecord.parse(mainReader); 
    942945                         
    943             OMFReader reader = thisRecord.getOMFReader(); 
     946            scope OMFReader reader = thisRecord.getOMFReader(); 
    944947             
    945948            debug debugLog("record: {0:X} ({1:X}) data: {2} {3} length: {4}",thisRecord.recordType,thisRecord.type,thisRecord.data,recordNameLookup[thisRecord.recordType], thisRecord.length); 
  • trunk/ddl/omf/OMFLibrary.d

    r292 r299  
    4040class OMFLibrary : DynamicLibrary{ 
    4141    DynamicModule[] modules; 
    42     DynamicModule[char[]] crossReference; // modules by symbol name 
    43     ExportSymbolPtr[char[]] dictionary; // symbols by symbol name 
     42     
     43    struct SymInfo { 
     44        DynamicModule       mod; 
     45        ExportSymbolPtr sym; 
     46    } 
     47    SymInfo[char[]] crossReference; 
     48     
    4449    Attributes attributes; 
    4550 
     
    7075     
    7176    public ExportSymbolPtr getSymbol(char[] name){ 
    72         ExportSymbolPtr* sym = name in dictionary
    73         if(sym) return *sym; 
     77        auto sym = name in crossReference
     78        if (sym) return sym.sym; 
    7479        else return &ExportSymbol.NONE; 
    7580    } 
     
    8186    public DynamicModule getModuleForSymbol(char[] name){ 
    8287        debug debugLog("[OMF] looking for {0} in {1}",name,attributes["omf.filename"]); 
    83         DynamicModule* mod = name in crossReference; 
     88        auto mod = name in crossReference; 
    8489        debug debugLog("[OMF] Result: {0:X}",mod); 
    85         if(mod) return *mod; 
     90        if (mod) return mod.mod; 
    8691        return null; 
    8792    } 
     
    96101        for(uint i=0; i<symbols.length; i++){ 
    97102            ExportSymbolPtr exp = &(symbols[i]); 
    98             if(exp.name in crossReference){ 
     103            if (auto found = exp.name in crossReference){ 
    99104                switch(exp.type){ 
    100105                case SymbolType.Weak: // replace extern only 
    101                     if(dictionary[exp.name].type == SymbolType.Unresolved){ 
    102                         crossReference[exp.name] = mod; 
    103                         dictionary[exp.name] = exp; 
     106                    if (found.sym.type == SymbolType.Unresolved){ 
     107                        found.mod = mod; 
     108                        found.sym = exp; 
    104109                    } 
    105110                    break; 
    106111                case SymbolType.Strong: // always overwrite 
    107                     crossReference[exp.name] = mod; 
    108                     dictionary[exp.name] = exp; 
     112                    crossReference[exp.name] = SymInfo(mod, exp); 
     113                    /+crossReference[exp.name] = mod; 
     114                    dictionary[exp.name] = exp;+/ 
    109115                    break; 
    110116                default: 
     
    113119            } 
    114120            else{ 
    115                 crossReference[exp.name] = mod; 
    116                 dictionary[exp.name] = exp; 
     121                /+crossReference[exp.name] = mod; 
     122                dictionary[exp.name] = exp;+/ 
     123                crossReference[exp.name] = SymInfo(mod, exp); 
    117124            } 
    118125        } 
  • trunk/ddl/omf/OMFModule.d

    r292 r299  
    3636 
    3737private import Text = tango.text.Util; 
    38 import tango.stdc.stdio; 
     38//import tango.stdc.stdio; 
    3939 
    4040version(Windows){ 
     
    6565    SegmentImage[] segmentImages; 
    6666    ExportSymbol[] symbols; 
    67     ExportSymbolPtr[char[]] symbolXref; 
    6867    char[] moduleName; 
    6968    bool resolved; 
     
    8887     
    8988    public ExportSymbol* getSymbol(char[] name){ 
    90         if(name in symbolXref) return symbolXref[name]; 
    91         else return &ExportSymbol.NONE; 
     89        /+if(name in symbolXref) return symbolXref[name]; 
     90        else return &ExportSymbol.NONE;+/ 
     91        foreach (ref sym; symbols) { 
     92            if (sym.name == name) { 
     93                return &sym; 
     94            } 
     95        } 
     96         
     97        return &ExportSymbol.NONE; 
    9298    } 
    9399     
     
    189195         
    190196    protected void loadBinary(DDLReader reader){ 
     197        ExportSymbolPtr[char[]] symbolXref; 
     198 
    191199        debug{} else{ 
    192200            OMFBinary binary;