Changeset 118
- Timestamp:
- 08/16/05 22:04:52 (3 years ago)
- Files:
-
- trunk/ddl/omfloader.d (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/omfloader.d
r117 r118 107 107 class ExternRecord{ 108 108 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 } 111 119 112 120 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 } 114 127 } 115 128 … … 126 139 127 140 public this(){ 141 name = ""; 128 142 baseGroup = GroupRecord.Null; 129 143 baseSegment = SegmentRecord.Null; … … 198 212 +/ 199 213 class OMFLoader{ 214 char[] memoryModel; 215 char[] libraryName; 216 char[] debugInfo; 200 217 char[] filename; 201 218 char[][] headerNames; … … 218 235 char[] output = "OMF File - " ~ filename ~ "\n"; 219 236 237 output ~= "Memory Model: " ~ memoryModel ~ "\n"; 238 output ~= "Library Name: " ~ libraryName ~ "\n"; 239 output ~= "Debug Info: " ~ debugInfo ~ "\n"; 240 220 241 output ~= "Header Names\n"; 221 foreach(char[] name; headerNames){ 242 foreach(uint idx,char[] name; headerNames){ 243 if(idx == 0) continue; 222 244 output ~= "\t" ~ name ~ "\n"; 223 245 } … … 229 251 +/ 230 252 output ~= "Segments\n"; 231 foreach(SegmentRecord obj; segments){ 253 foreach(uint idx,SegmentRecord obj; segments){ 254 if(idx == 0) continue; 232 255 output ~= "\t" ~ obj.toString() ~ "\n"; 233 256 } … … 239 262 +/ 240 263 output ~= "Public Symbols\n"; 241 foreach(PublicRecord obj; publics){ 264 foreach(uint idx,PublicRecord obj; publics){ 265 if(idx == 0) continue; 242 266 output ~= "\t" ~ obj.toString() ~ "\n"; 243 267 } … … 245 269 output ~= "Externs\n"; 246 270 foreach(uint idx,ExternRecord obj; externs){ 271 if(idx == 0) continue; 247 272 output ~= "\t" ~ obj.toString() ~ "\n"; 248 273 } 249 274 250 275 output ~= "Common Data\n"; 251 foreach(CommonDataRecord obj; commonData){ 276 foreach(uint idx,CommonDataRecord obj; commonData){ 277 if(idx == 0) continue; 252 278 output ~= "\t" ~ obj.toString() ~ "\n"; 253 279 } 254 280 255 281 output ~= "Enum Data\n"; 256 foreach(EnumDataRecord obj; enumData){ 282 foreach(uint idx,EnumDataRecord obj; enumData){ 283 if(idx == 0) continue; 257 284 output ~= "\t" ~ obj.toString() ~ "\n"; 258 285 } 259 286 260 287 output ~= "Fixups\n"; 261 foreach(FixupRecord obj; fixups){ 288 foreach(uint idx,FixupRecord obj; fixups){ 289 if(idx == 0) continue; 262 290 output ~= "\t" ~ obj.toString() ~ "\n"; 263 291 } … … 269 297 +/ 270 298 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"; 273 302 } 274 303 … … 308 337 switch(commentClass){ 309 338 case 0x9D: // memory model 310 debug writefln("Memory Model: %s",comment);339 this.memoryModel = comment; 311 340 break; 312 341 case 0x9F: // external library name (dependency) 313 debug writefln("External Library Name: %s",comment);342 this.libraryName = comment; 314 343 break; 315 344 … … 321 350 case 0x01: // IMPDEF 322 351 debug writefln("IMPDEF"); 352 323 353 break; 324 354 case 0x02: // EXPDEF … … 380 410 case 0xA1: // Debug Info Type 381 411 // 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..$]); 383 413 break; 384 414 … … 392 422 uint consumed = cursor.parseIndex(cast(ubyte[])comment,externIndex); 393 423 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 400 425 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 */ 402 435 break; 403 436 … … 436 469 437 470 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 } 443 477 } 444 478 … … 664 698 665 699 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; 667 701 668 702 default: … … 704 738 while(cursor.hasMore()){ 705 739 ExternRecord external = new ExternRecord(); 706 707 740 external.name = this.names[cursor.getIndex()]; 708 external.typeIndex = cursor.getIndex(); 709 741 cursor.getIndex(); // throw away the type index 710 742 this.externs ~= external; 711 debug writefln("[[extern name parsed]]");712 743 } 713 744 } … … 784 815 cursor = new WordRecordCursor(block,type); 785 816 } 786 817 787 818 //NOTE: there are *many* record types not supported in here, as they are not used in DMD .obj files 788 819 //NOTE: the specification is organized by the type number, simply search it on xxH. … … 826 857 OMFLoader loader = new OMFLoader(); 827 858 loader.load(args[1]); 828 writefln("Debug output: \n%s",loader.toString());859 writefln("Debug output:\n\n%s",loader.toString()); 829 860 /+ 830 861 debug{
