Skip to content

Commit be8fe97

Browse files
authored
Fix lineinfo from wat2wasm (#91)
* Fix lineinfo from wat2wasm * Adjust compiler test for new compiler options * Revert ad hoc fix for #91 (e3f4c02)
1 parent 873ba26 commit be8fe97

File tree

3 files changed

+3
-52
lines changed

3 files changed

+3
-52
lines changed

src/CompilerBridges/WASMCompilerBridge.ts

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,8 @@ function extractLineInfo(lineString: string): LineInfo {
4242
return parseUtils.jsonParse(lineString);
4343
}
4444

45-
function extractSectionAddressCorrections(lines: string[]): Map<number, number> {
46-
const corrections: Map<number, number> = new Map();
47-
const sections: string[] =
48-
['Type', 'Import', 'Function', 'Table', 'Memory', 'Global', 'Export', 'Elem', 'Code']
49-
.map(kind => {
50-
return `; section "${kind}" (`;
51-
});
52-
let candidates: number[] = [];
53-
let inSection = false;
54-
let sectionStartIdx = -1;
55-
for (let i = 0; i < lines.length; i++) {
56-
const line = lines[i];
57-
const foundSection = sections.find(s => {
58-
return line.startsWith(s);
59-
});
60-
61-
if (foundSection) {
62-
inSection = true;
63-
sectionStartIdx = i + 1;
64-
}
65-
66-
if (inSection && i >= sectionStartIdx) {
67-
candidates.push(i);
68-
if (line.includes('; FIXUP section size')) {
69-
const hexaAddr = line.match(/: ([a-zA-Z0-9]+)/)?.[1];
70-
if (hexaAddr) {
71-
assert(hexaAddr.length % 2 === 0, 'hexa address is not even');
72-
const amountBytes = hexaAddr.length / 2;
73-
candidates.forEach(lineNr => {
74-
corrections.set(lineNr, amountBytes - 1);
75-
});
76-
}
77-
inSection = false;
78-
sectionStartIdx = -1;
79-
candidates = [];
80-
}
81-
}
82-
}
83-
return corrections;
84-
}
85-
8645
function createLineInfoPairs(lines: string[]): LineInfoPairs[] { // TODO update
8746

88-
const corrections = extractSectionAddressCorrections(lines);
8947
let result = [];
9048
let lastLineInfo = undefined;
9149
for (let i = 0; i < lines.length; i++) {
@@ -97,13 +55,6 @@ function createLineInfoPairs(lines: string[]): LineInfoPairs[] { // TODO update
9755
}
9856
try {
9957
let addr = parseUtils.extractAddressInformation(line);
100-
if (corrections.has(i)) {
101-
const offset = corrections.get(i)!;
102-
const newAddr = Number(`0x${addr}`) + offset;
103-
const tmpAddr = newAddr.toString(16);
104-
// add padding
105-
addr = `${'0'.repeat(addr.length - tmpAddr.length)}${tmpAddr}`;
106-
}
10758
const li = {
10859
line: lastLineInfo!.line,
10960
column: lastLineInfo!.column,
@@ -270,7 +221,7 @@ export class WASMCompilerBridge implements CompileBridge {
270221
}
271222

272223
private compileToWasmCommand(): string {
273-
return `${this.wabt}/wat2wasm --debug-names -v -o ${this.tmpdir}/upload.wasm ` + this.wasmFilePath;
224+
return `${this.wabt}/wat2wasm --no-canonicalize-leb128s --disable-bulk-memory --debug-names -v -o ${this.tmpdir}/upload.wasm ` + this.wasmFilePath;
274225
}
275226

276227
private getNameDumpCommand(): string {

src/State/SourceMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ export function getLineNumberForAddress(sourceMap: SourceMap, address: number, i
3434
}
3535
});
3636
return line;
37-
}
37+
}

src/test/suite/compilertest.ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('WASM Compiler Bridge Test Suite', () => {
2929
let compilerBridge = new WASMCompilerBridge(`${wasmDirectoryPath}/fac_ok.wast`, tmpdir, wabtSDK);
3030
const result = (await compilerBridge.compile()).sourceMap;
3131
expect(result.lineInfoPairs).to.have.lengthOf.above(0);
32-
expect(result.lineInfoPairs[0].lineAddress).to.equal('000002e');
32+
expect(result.lineInfoPairs[0].lineAddress).to.equal('0000042');
3333
expect(result.lineInfoPairs[0].lineInfo.line).to.equal(13);
3434
});
3535

0 commit comments

Comments
 (0)