Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps #41

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* text=auto eol=lf
funcfiftlib.js linguist-vendored
src/fift/funcfiftlib.js linguist-vendored
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default tseslint.config(
"unicorn/no-null": "off",
"unicorn/no-lonely-if": "off",
"unicorn/no-process-exit": "off",
"unicorn/prefer-module": "off",
},
},
)
24 changes: 24 additions & 0 deletions src/decompiler/source-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {readFileSync} from "node:fs"
import {compileFiftForSourceMap} from "../fift/compileFift"

export type ProcedureHash = string

export type SourceMap = Map<ProcedureHash, string>

/**
* Extracts a source map from a Fift assembly file that was generated by Tact/FunC/Tolk.
*
* This function:
* 1. Takes a path to the original `.fif` assembly file (with actual names)
* 2. Combines it with a modified version of `Asm.fif` that outputs function names and hashes
* 3. Runs Fift compilation to get the `HASH -> name` mapping from stdout
* 4. Returns a Map that can be used by `AssemblyWriter.write()` to restore original names
*
* @param path Path to the original `.fif` assembly file
* @returns Map of function hashes to their original names
*/
export async function obtainSourceMap(path: string): Promise<SourceMap> {
const content = readFileSync(path).toString()
const result = await compileFiftForSourceMap(content)
return result.sourceMap
}
Loading