Skip to content

Commit

Permalink
First pass ts conversion for lib/mapfiles (#4386)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Dec 6, 2022
1 parent e7b1051 commit 81ed9f2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 247 deletions.
100 changes: 32 additions & 68 deletions lib/mapfiles/map-file-delphi.js → lib/mapfiles/map-file-delphi.ts
Expand Up @@ -25,23 +25,13 @@
import {MapFileReader} from './map-file';

export class MapFileReaderDelphi extends MapFileReader {
/**
* constructor
*
* @param {string} mapFilename
*/
constructor(mapFilename) {
super(mapFilename);

this.regexDelphiCodeSegmentOffset = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)h\s*(\.[$a-z]*)\s*([a-z]*)$/i;
this.regexDelphiCodeSegment = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)\s*c=code\s*s=.text\s*g=.*m=([\w.]*)\s.*/i;
this.regexDelphiICodeSegment =
/^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)\s*c=icode\s*s=.itext\s*g=.*m=([\w.]*)\s.*/i;
this.regexDelphiNames = /^\s([\da-f]*):([\da-f]*)\s*([\w$.<>@{}]*)$/i;
this.regexDelphiLineNumbersStart = /line numbers for (.*)\(.*\) segment \.text/i;
this.regexDelphiLineNumber = /^(\d*)\s([\da-f]*):([\da-f]*)/i;
this.regexDelphiLineNumbersStartIText = /line numbers for (.*)\(.*\) segment \.itext/i;
}
regexDelphiCodeSegmentOffset = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)h\s*(\.[$a-z]*)\s*([a-z]*)$/i;
regexDelphiCodeSegment = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)\s*c=code\s*s=.text\s*g=.*m=([\w.]*)\s.*/i;
regexDelphiICodeSegment = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)\s*c=icode\s*s=.itext\s*g=.*m=([\w.]*)\s.*/i;
regexDelphiNames = /^\s([\da-f]*):([\da-f]*)\s*([\w$.<>@{}]*)$/i;
regexDelphiLineNumbersStart = /line numbers for (.*)\(.*\) segment \.text/i;
regexDelphiLineNumber = /^(\d*)\s([\da-f]*):([\da-f]*)/i;
regexDelphiLineNumbersStartIText = /line numbers for (.*)\(.*\) segment \.itext/i;

/**
* Tries to match the given line to code segment information
Expand All @@ -50,12 +40,8 @@ export class MapFileReaderDelphi extends MapFileReader {
* 2. code segment delphi map
* 3. icode segment delphi map
* 4. code segment vs map
*
* @param {string} line
*/
tryReadingCodeSegmentInfo(line) {
let codesegmentObject = false;

override tryReadingCodeSegmentInfo(line: string) {
let matches = line.match(this.regexDelphiCodeSegmentOffset);
if (matches && !matches[4].includes('$') && parseInt(matches[2], 16) >= this.preferredLoadAddress) {
const addressWithOffset = parseInt(matches[2], 16);
Expand All @@ -68,83 +54,61 @@ export class MapFileReaderDelphi extends MapFileReader {
} else {
matches = line.match(this.regexDelphiCodeSegment);
if (matches) {
codesegmentObject = this.addressToObject(matches[1], matches[2]);
codesegmentObject.id = this.segments.length + 1;
codesegmentObject.segmentLength = parseInt(matches[3], 16);
codesegmentObject.unitName = matches[4];

if (codesegmentObject.unitName === 'prog') {
codesegmentObject.unitName = 'prog.dpr';
} else {
codesegmentObject.unitName = codesegmentObject.unitName + '.pas';
}

this.segments.push(codesegmentObject);
this.segments.push({
...this.addressToObject(matches[1], matches[2]),
id: this.segments.length + 1,
segmentLength: parseInt(matches[3], 16),
unitName: matches[4] === 'prog' ? 'prog.dpr' : matches[4] + '.pas',
});
} else {
matches = line.match(this.regexDelphiICodeSegment);
if (matches) {
codesegmentObject = this.addressToObject(matches[1], matches[2]);
codesegmentObject.id = this.isegments.length + 1;
codesegmentObject.segmentLength = parseInt(matches[3], 16);
codesegmentObject.unitName = matches[4];

if (codesegmentObject.unitName === 'prog') {
codesegmentObject.unitName = 'prog.dpr';
} else {
codesegmentObject.unitName = codesegmentObject.unitName + '.pas';
}

this.isegments.push(codesegmentObject);
this.isegments.push({
...this.addressToObject(matches[1], matches[2]),
id: this.isegments.length + 1,
segmentLength: parseInt(matches[3], 16),
unitName: matches[4] === 'prog' ? 'prog.dpr' : matches[4] + '.pas',
});
}
}
}
}

/**
* Try to match information about the address where a symbol is
*
* @param {string} line
*/
tryReadingNamedAddress(line) {
let symbolObject = false;

override tryReadingNamedAddress(line: string) {
const matches = line.match(this.regexDelphiNames);
if (matches) {
if (!this.getSymbolInfoByName(matches[3])) {
symbolObject = this.addressToObject(matches[1], matches[2]);
symbolObject.displayName = matches[3];

this.namedAddresses.push(symbolObject);
this.namedAddresses.push({
...this.addressToObject(matches[1], matches[2]),
displayName: matches[3],
segmentLength: 0,
});
}
}
}

/**
*
* @param {string} line
*/
isStartOfLineNumbers(line) {
override isStartOfLineNumbers(line: string) {
const matches = line.match(this.regexDelphiLineNumbersStart);
return !!matches;
}

/**
* Retreives line number references from supplied Map line
*
* @param {string} line
* @returns {boolean}
*/
tryReadingLineNumbers(line) {
override tryReadingLineNumbers(line: string) {
let hasLineNumbers = false;

const references = line.split(' '); // 4 spaces
for (const reference of references) {
const matches = reference.match(this.regexDelphiLineNumber);
if (matches) {
const lineObject = this.addressToObject(matches[2], matches[3]);
lineObject.lineNumber = parseInt(matches[1], 10);

this.lineNumbers.push(lineObject);
this.lineNumbers.push({
...this.addressToObject(matches[2], matches[3]),
lineNumber: parseInt(matches[1], 10),
});

hasLineNumbers = true;
}
Expand Down
48 changes: 14 additions & 34 deletions lib/mapfiles/map-file-vs.js → lib/mapfiles/map-file-vs.ts
Expand Up @@ -25,24 +25,11 @@
import {MapFileReader} from './map-file';

export class MapFileReaderVS extends MapFileReader {
/**
* constructor
*
* @param {string} mapFilename
*/
constructor(mapFilename) {
super(mapFilename);
regexVsNames = /^\s([\da-f]*):([\da-f]*)\s*([\w$.?@]*)\s*([\da-f]*)(\sf\si\s*|\sf\s*|\s*)([\w.:<>-]*)$/i;
regexVSLoadAddress = /\spreferred load address is ([\da-f]*)/i;
regexVsCodeSegment = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)h\s*\.text\$mn\s*code.*/i;

this.regexVsNames = /^\s([\da-f]*):([\da-f]*)\s*([\w$.?@]*)\s*([\da-f]*)(\sf\si\s*|\sf\s*|\s*)([\w.:<>-]*)$/i;
this.regexVSLoadAddress = /\spreferred load address is ([\da-f]*)/i;
this.regexVsCodeSegment = /^\s([\da-f]*):([\da-f]*)\s*([\da-f]*)h\s*\.text\$mn\s*code.*/i;
}

/**
*
* @param {string} line
*/
tryReadingPreferredAddress(line) {
override tryReadingPreferredAddress(line: string) {
const matches = line.match(this.regexVSLoadAddress);
if (matches) {
this.preferredLoadAddress = parseInt(matches[1], 16);
Expand All @@ -56,42 +43,35 @@ export class MapFileReaderVS extends MapFileReader {
* 2. code segment delphi map
* 3. icode segment delphi map
* 4. code segment vs map
*
* @param {string} line
*/
tryReadingCodeSegmentInfo(line) {
let codesegmentObject = false;

override tryReadingCodeSegmentInfo(line: string) {
const matches = line.match(this.regexVsCodeSegment);
if (matches) {
codesegmentObject = this.addressToObject(matches[1], matches[2]);
codesegmentObject.id = this.segments.length + 1;
codesegmentObject.segmentLength = parseInt(matches[3], 16);
codesegmentObject.unitName = false;

this.segments.push(codesegmentObject);
this.segments.push({
...this.addressToObject(matches[1], matches[2]),
id: this.segments.length + 1,
segmentLength: parseInt(matches[3], 16),
unitName: false,
});
}
}

/**
* Try to match information about the address where a symbol is
*
* @param {string} line
*/
tryReadingNamedAddress(line) {
let symbolObject = false;

override tryReadingNamedAddress(line: string) {
const matches = line.match(this.regexVsNames);
if (matches && matches.length >= 7 && matches[4] !== '') {
const addressWithOffset = parseInt(matches[4], 16);
symbolObject = {
const symbolObject = {
segment: matches[1],
addressWithoutOffset: parseInt(matches[2], 16),
addressInt: addressWithOffset,
address: addressWithOffset.toString(16),
displayName: matches[3],
unitName: matches[6],
isStaticSymbol: false,
segmentLength: 0,
};
this.namedAddresses.push(symbolObject);

Expand Down

0 comments on commit 81ed9f2

Please sign in to comment.