Changeset 118

Show
Ignore:
Timestamp:
08/16/05 22:04:52 (3 years ago)
Author:
pragma
Message:

tweaks. Better output.

Files:

Legend:

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

    r117 r118  
    107107class ExternRecord{ 
    108108    public char[] name; 
    109     public uint typeIndex; 
    110     public ExternRecord defaultExtern; // non-null if the extern is weak 
     109    public bit isWeak; 
     110    public ExternRecord weakExtern; // non-null if the extern is weak 
     111    public ExternRecord defaultExtern;  
     112     
     113    public this(){ 
     114        isWeak = false; 
     115        name = ""; 
     116        weakExtern = ExternRecord.Null; 
     117        defaultExtern = ExternRecord.Null; 
     118    } 
    111119     
    112120    public char[] toString(){ 
    113         return std.string.format("extern %s [%d]",name,typeIndex);   
     121        if(isWeak){ 
     122            return std.string.format("weak extern %s default: %s",weakExtern.name,defaultExtern.name); 
     123        } 
     124        else{ 
     125            return std.string.format("extern %s",name);  
     126        } 
    114127    } 
    115128     
     
    126139     
    127140    public this(){ 
     141        name = ""; 
    128142        baseGroup = GroupRecord.Null; 
    129143        baseSegment = SegmentRecord.Null; 
     
    198212+/ 
    199213class OMFLoader{ 
     214    char[] memoryModel; 
     215    char[] libraryName; 
     216    char[] debugInfo; 
    200217    char[] filename; 
    201218    char[][] headerNames; 
     
    218235        char[] output = "OMF File - " ~ filename ~ "\n"; 
    219236         
     237        output ~= "Memory Model: " ~ memoryModel ~ "\n"; 
     238        output ~= "Library Name: " ~ libraryName ~ "\n"; 
     239        output ~= "Debug Info: " ~ debugInfo ~ "\n"; 
     240         
    220241        output ~= "Header Names\n"; 
    221         foreach(char[] name; headerNames){ 
     242        foreach(uint idx,char[] name; headerNames){ 
     243            if(idx == 0) continue; 
    222244            output ~= "\t" ~ name ~ "\n"; 
    223245        } 
     
    229251        +/ 
    230252        output ~= "Segments\n"; 
    231         foreach(SegmentRecord obj; segments){ 
     253        foreach(uint idx,SegmentRecord obj; segments){ 
     254            if(idx == 0) continue; 
    232255            output ~= "\t" ~ obj.toString() ~ "\n"; 
    233256        }        
     
    239262+/ 
    240263        output ~= "Public Symbols\n"; 
    241         foreach(PublicRecord obj; publics){ 
     264        foreach(uint idx,PublicRecord obj; publics){ 
     265            if(idx == 0) continue; 
    242266            output ~= "\t" ~ obj.toString() ~ "\n"; 
    243267        }                
     
    245269        output ~= "Externs\n"; 
    246270        foreach(uint idx,ExternRecord obj; externs){ 
     271            if(idx == 0) continue; 
    247272            output ~= "\t" ~ obj.toString() ~ "\n"; 
    248273        }    
    249274         
    250275        output ~= "Common Data\n"; 
    251         foreach(CommonDataRecord obj; commonData){ 
     276        foreach(uint idx,CommonDataRecord obj; commonData){ 
     277            if(idx == 0) continue; 
    252278            output ~= "\t" ~ obj.toString() ~ "\n"; 
    253279        }            
    254280 
    255281        output ~= "Enum Data\n"; 
    256         foreach(EnumDataRecord obj; enumData){ 
     282        foreach(uint idx,EnumDataRecord obj; enumData){ 
     283            if(idx == 0) continue; 
    257284            output ~= "\t" ~ obj.toString() ~ "\n"; 
    258285        } 
    259286         
    260287        output ~= "Fixups\n"; 
    261         foreach(FixupRecord obj; fixups){ 
     288        foreach(uint idx,FixupRecord obj; fixups){ 
     289            if(idx == 0) continue; 
    262290            output ~= "\t" ~ obj.toString() ~ "\n"; 
    263291        } 
     
    269297+/       
    270298        output ~= "Dependencies\n"; 
    271         foreach(uint index; dependencies){ 
    272             output ~= "\t" ~ this.externs[index].toString() ~ "\n"; 
     299        foreach(uint idx; dependencies){ 
     300            if(idx == 0) continue; 
     301            output ~= "\t" ~ this.externs[idx].toString() ~ "\n"; 
    273302        }        
    274303         
     
    308337        switch(commentClass){ 
    309338        case 0x9D: // memory model 
    310             debug writefln("Memory Model: %s",comment)
     339            this.memoryModel = comment
    311340            break;   
    312341        case 0x9F: // external library name (dependency) 
    313             debug writefln("External Library Name: %s",comment)
     342            this.libraryName = comment
    314343            break; 
    315344             
     
    321350            case 0x01: // IMPDEF 
    322351                debug writefln("IMPDEF"); 
     352                 
    323353                break; 
    324354            case 0x02: // EXPDEF 
     
    380410        case 0xA1: // Debug Info Type 
    381411            // 0:byte | version:byte char1 char2 
    382             debug writefln("Debug Info: %s",comment); 
     412            this.debugInfo ~= std.string.format("%d %s",cast(ubyte)(comment[0]),comment[1..$]); 
    383413            break; 
    384414                     
     
    392422            uint consumed = cursor.parseIndex(cast(ubyte[])comment,externIndex);  
    393423            cursor.parseIndex(cast(ubyte[])comment[consumed..$],defaultIndex); // thrown out 
    394                          
    395             debug writefln("[[weakextern parsed]]"); 
    396             //NOTE: this is due to a bug in the DMC backend (spec states that the index is fine as-is) 
    397             externIndex--; 
    398              
    399             // dependencies are *forward* referenced, so we'll resolve them later 
     424 
    400425            this.dependencies ~= externIndex; 
    401          
     426             
     427        /*BUG: do not insert this data into the actual externs listing 
     428            ExternRecord ext = new ExternRecord(); 
     429            ext.weakExtern = this.externs[externIndex]; 
     430            ext.defaultExtern = this.externs[defaultIndex]; 
     431            ext.isWeak = true; 
     432         
     433            this.externs ~= ext; 
     434        */ 
    402435            break; 
    403436             
     
    436469     
    437470    protected void parseExternName(RecordCursor cursor){ 
    438         ExternRecord external = new ExternRecord(); 
    439         external.name = cursor.getLString(); 
    440         external.typeIndex = cursor.getIndex(); 
    441         this.externs ~= external; 
    442         debug writefln("[[single extern name parsed]]"); 
     471        while(cursor.hasMore()){ 
     472            ExternRecord external = new ExternRecord(); 
     473            external.name = cursor.getLString(); 
     474            cursor.getIndex(); // throw away type index 
     475            this.externs ~= external; 
     476        } 
    443477    } 
    444478 
     
    664698 
    665699                    case 2: targetDisplacement = 0; 
    666                     case 6: output ~= std.string.format("displacement: %d extern %d of %d",targetDisplacement,targetDatum,this.externs.length); break; 
     700                    case 6: output ~= std.string.format("displacement: %d extern %s",targetDisplacement,this.externs[targetDatum].name); break; 
    667701 
    668702                    default: 
     
    704738        while(cursor.hasMore()){ 
    705739            ExternRecord external = new ExternRecord(); 
    706              
    707740            external.name = this.names[cursor.getIndex()]; 
    708             external.typeIndex = cursor.getIndex(); 
    709                                      
     741            cursor.getIndex(); // throw away the type index 
    710742            this.externs ~= external; 
    711             debug writefln("[[extern name parsed]]"); 
    712743        } 
    713744    } 
     
    784815                cursor = new WordRecordCursor(block,type); 
    785816            } 
    786          
     817                    
    787818            //NOTE: there are *many* record types not supported in here, as they are not used in DMD .obj files 
    788819            //NOTE: the specification is organized by the type number, simply search it on xxH. 
     
    826857    OMFLoader loader = new OMFLoader(); 
    827858    loader.load(args[1]); 
    828     writefln("Debug output: \n %s",loader.toString()); 
     859    writefln("Debug output:\n\n%s",loader.toString()); 
    829860    /+ 
    830861    debug{