Changeset 121
- Timestamp:
- 08/21/05 12:54:43 (3 years ago)
- Files:
-
- trunk/ddl/RecordCursor.d (modified) (2 diffs)
- trunk/ddl/ddl.d (modified) (2 diffs)
- trunk/ddl/omfloader.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/RecordCursor.d
r119 r121 52 52 } 53 53 54 public void setPosition(uint value){ 55 position = value; 56 } 57 54 58 public bit hasMore(){ 55 59 return position < data.length; … … 59 63 ubyte result = data[position]; 60 64 position++; 65 return result; 66 } 67 68 public ubyte[] getBytes(uint size){ 69 ubyte[] result = data[position..position+size]; 70 position += size; 61 71 return result; 62 72 } trunk/ddl/ddl.d
r119 r121 1 1 /* 2 2 Copyright (c) 2005 Eric Anderton 3 Original (non-DSP version) - Copyright (c) 2004 Kris Bell, Scott Sanders4 3 5 4 Permission is hereby granted, free of charge, to any person … … 34 33 35 34 interface DynamicModule{ 36 char[][] getRequiredModuleNames(); 35 char[][] getDependencies(); 36 void resolveDependency(char[] name,void* address); 37 37 ExportSymbol[] getExports(); 38 void resolveImports(DynamicLibraryLoader loader);38 ExportSymbol getExport(char[] name); 39 39 } 40 40 41 41 interface DynamicLibrary{ 42 42 ExportSymbol[] getExports(); 43 ExportSymbol getSymbol(char[] name); 43 44 DynamicModule[] getModules(); 44 45 void resolveImports(DynamicLibraryLoader loader);46 void init();47 45 } 48 46 trunk/ddl/omfloader.d
r120 r121 42 42 private import RecordCursor; 43 43 private import OMFException; 44 44 45 45 46 struct Segment{ … … 403 404 } 404 405 } 405 406 // add raw data to a segment407 protected void parseLogicalEnumeratedData(RecordCursor cursor){ 406 407 408 protected void parseLogicalEnumeratedData(RecordCursor cursor){ 408 409 uint segmentIndex = cursor.getIndex(); 409 410 uint offsetAddress = cursor.getVWord(); 410 411 411 //read raw data and overlay segment data with these bytes412 412 ubyte[] rawData = cursor.getRemainder(); 413 this.segments[segmentIndex].data[offsetAddress.. rawData.length] = rawData;413 this.segments[segmentIndex].data[offsetAddress..offsetAddress+rawData.length] = rawData; 414 414 415 415 this.enumData.segmentIndex = segmentIndex; 416 416 this.enumData.offset = offsetAddress; 417 417 418 debug writefln("enum data: segmentIndex %d | offset %d | length %d",segmentIndex,offsetAddress,rawData.length); 419 } 418 debug writefln("enum data: segmentIndex %d | offset %d | length %d",segmentIndex,offsetAddress,rawData.length); 419 } 420 421 // add raw data to a segment 422 protected void parseLogicalIteratedData(RecordCursor cursor){ 423 uint segmentIndex = cursor.getIndex(); 424 uint offsetAddress = cursor.getVWord(); 425 ubyte[] rawData; 426 427 debug writefln("LIDATA: %s seg %d offset %d",cursor.getData(),segmentIndex,offsetAddress); 428 429 // define recursive parser 430 ubyte[] parseBlock(){ 431 uint repeatCount = cursor.getVWord(); 432 uint blockCount = cursor.getWord(); 433 ubyte[] result; 434 435 //debug writefln("parseblock: repeat %d block count %d",repeatCount,blockCount); 436 437 //build raw data using a repeated block 438 if(blockCount == 0){ 439 ubyte count = cursor.getByte(); 440 441 ubyte[] data = cursor.getBytes(count); 442 443 for(uint i=0; i<repeatCount; i++){ 444 result ~= data; 445 } 446 } 447 // recursion 448 else{ 449 uint startPosition = cursor.getPosition(); 450 for(uint i=0; i<blockCount; i++){ 451 cursor.setPosition(startPosition); // reset cursor so recursion works correctly 452 result = parseBlock(); 453 } 454 } 455 456 // use the repeat count repeat rawData 457 ubyte[] tempData; 458 for(uint i=0; i<repeatCount; i++){ 459 tempData ~= result; 460 } 461 // use rawData to store the result of the repeat 462 return result; 463 } 464 465 // multiple data blocks 466 while(cursor.hasMore()){ 467 rawData ~= parseBlock(); 468 } 469 470 debug writefln("rawData: %d %s",rawData.length,rawData); 471 472 this.segments[segmentIndex].data[offsetAddress..offsetAddress+rawData.length] = rawData; 473 474 this.enumData.segmentIndex = segmentIndex; 475 this.enumData.offset = offsetAddress; 476 477 debug writefln("iterated data: segmentIndex %d | offset %d | length %d",segmentIndex,offsetAddress,rawData.length); 478 } 479 420 480 421 481 protected void parseExternalNames(RecordCursor cursor){ … … 532 592 case 0x9C: parseFixupData(cursor); break; 533 593 case 0xA0: parseLogicalEnumeratedData(cursor); break; 594 case 0xA2: parseLogicalIteratedData(cursor); break; 534 595 case 0xBC: parseExternalNames(cursor); break; 535 596 case 0xC2: parseCommonData(cursor); break; … … 613 674 resolveInternals(); 614 675 615 676 /+ 616 677 debug{ 617 678 // read in foobar.x and display its value … … 655 716 writef("]\n"); 656 717 657 writefln("add: %d",add(42,69)); 658 659 } 718 writefln("add: %d",add(42,69)); 719 }+/ 660 720 } 661 721 }
