Skip to content

Commit

Permalink
feat(cli): --disasm option to expose TVM disassembler
Browse files Browse the repository at this point in the history
via @tact-lang/opcode library
  • Loading branch information
anton-trunov committed Dec 26, 2024
1 parent 136665e commit 56937e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ jobs:
run: |
tact -e '(1 + 2 * (pow(3,4) - 2) << 1 & 0x54 | 33 >> 1) * 2 + 2'
- name: CLI Test | Check TVM disassembler flag
if: runner.os != 'Windows'
run: |
tact bin/test/success.tact
tact --disasm success_HelloWorld.code.boc
- name: Test compatibility with tact-template
run: |
git clone https://github.com/tact-lang/tact-template.git
Expand Down
21 changes: 18 additions & 3 deletions bin/tact.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */

const pkg = require("../package.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const main = require("../dist/node.js");
const meowModule = import("meow");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execFileSync } = require("child_process");
const { decompileAll } = require("@tact-lang/opcode");
const { readFileSync } = require("fs");

void meowModule.then(
/** @param meow {import('meow/build/index')} */
(meow) => {
const cli = meow.default(
`
Usage
$ tact [...flags] (--config CONFIG | FILE)
$ tact [...flags] (--config CONFIG | --disasm BOC-FILE | TACT-FILE)
Flags
-c, --config CONFIG Specify path to config file (tact.config.json)
Expand All @@ -22,6 +23,7 @@ void meowModule.then(
--with-decompilation Full compilation followed by decompilation of produced binary code
--func Output intermediate FunC code and exit
--check Perform syntax and type checking, then exit
--disasm BOC-FILE Disassemble a BoC (bag of cells) file and output TVM instructions to stdout
-e, --eval EXPRESSION Evaluate a Tact expression and exit
-v, --version Print Tact compiler version and exit
-h, --help Display this text and exit
Expand Down Expand Up @@ -62,6 +64,7 @@ void meowModule.then(
type: "string",
isMultiple: true,
},
disasm: { type: "string" },
quiet: { shortFlag: "q", type: "boolean", default: false },
withDecompilation: { type: "boolean", default: false },
func: { type: "boolean", default: false },
Expand Down Expand Up @@ -117,6 +120,18 @@ void meowModule.then(
}
}

if (cli.flags.disasm !== undefined) {
try {
const boc = readFileSync(cli.flags.disasm);
const disasmResult = decompileAll({ src: Buffer.from(boc) });
console.log(disasmResult);
process.exit(0);
} catch (error) {
console.error(error.message);
process.exit(30);
}
}

// Disallow specifying both config or Tact source file at the same time
if (cli.flags.config !== undefined && cli.input.length > 0) {
console.log(
Expand Down

0 comments on commit 56937e6

Please sign in to comment.