ton-assembly
Version:
TON assembler and disassembler
66 lines • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMappingInfo = exports.fromParserLoc = exports.Loc = void 0;
const Loc = (file, line, otherLines) => ({
file,
line,
otherLines,
});
exports.Loc = Loc;
const fromParserLoc = (loc) => ({
file: loc.file,
line: loc.line,
otherLines: [],
});
exports.fromParserLoc = fromParserLoc;
const processMapping = (mapping, cells) => {
const previousData = cells[mapping.cell];
if (previousData !== undefined) {
// If we already have this cell in the mapping, we need to merge its
// instructions with the existing ones.
// This can happen if we have multiple instructions pointing to the same cell.
for (const [index, instr] of mapping.instructions.entries()) {
const line = instr.instr.loc?.line;
const instructionInfo = previousData.instructions.at(index);
if (line !== undefined && instructionInfo !== undefined) {
instructionInfo.loc?.otherLines.push(line);
}
}
return;
}
const instructions = mapping.instructions.map(({ instr: { $: name, loc }, offset, debugSection }) => ({
name,
loc: loc ? (0, exports.fromParserLoc)(loc) : undefined,
offset,
debugSection,
}));
cells[mapping.cell] = { instructions };
};
const buildCellsMapping = (mapping, cells) => {
const dictionaryInfos = [...mapping.dictionaryInfo];
processMapping(mapping, cells);
for (const subMapping of mapping.subMappings) {
processMapping(subMapping, cells);
for (const it of subMapping.subMappings) {
dictionaryInfos.push(...buildCellsMapping(it, cells));
}
}
return dictionaryInfos;
};
/**
* Creates a mapping of all cells to their instructions.
*/
const createMappingInfo = (m) => {
const cells = {};
const dictionaryInfos = buildCellsMapping(m, cells);
return {
dictionaryCells: dictionaryInfos.map(it => ({
cell: it.builder.asCell().hash().toString("hex"),
offset: it.offset,
dataCell: it.childCell.hash().toString("hex"),
})),
cells: cells,
};
};
exports.createMappingInfo = createMappingInfo;
//# sourceMappingURL=mapping.js.map