Skip to main content

Move Function Call Graph (FCG) extraction tool using tree-sitter (supports Aptos Move and Sui Move)

Project description

move-fcg-tool

Build Status Python License

Move Function Call Graph (FCG) extraction tool using tree-sitter - Universal support for Aptos Move and Sui Move

✨ Features

  • Universal Move Support: Parses both Aptos Move and Sui Move
  • Complete Syntax Coverage: Modules, structs, functions, generics, abilities
  • Advanced Features: Phantom types, entry functions, shared objects, dynamic fields
  • Function Call Graph (FCG): Extract function definitions and call relationships
  • Cross-Platform: Windows, Linux, macOS (Intel & Apple Silicon)
  • Python Bindings: Easy integration with Python projects
  • Type Stubs: Full type hints support

📦 Installation

From PyPI (when published)

pip install move-fcg-tool

From Wheel (local)

# Windows
pip install move_fcg_tool-0.1.0-cp312-cp312-win_amd64.whl

# Linux
pip install move_fcg_tool-0.1.0-cp310-cp310-linux_x86_64.whl

# macOS
pip install move_fcg_tool-0.1.0-cp314-cp314-macosx_15_0_x86_64.whl

🚀 Quick Start

import tree_sitter
from tree_sitter_move import language

# Create parser
parser = tree_sitter.Parser(tree_sitter.Language(language()))

# Parse Move code
code = b'''
module 0x1::example {
    struct Counter has key {
        value: u64
    }

    public fun increment(counter: &mut Counter) {
        counter.value = counter.value + 1;
    }
}
'''

tree = parser.parse(code)
print(tree.root_node.sexp())

📚 Supported Move Variants

Aptos Move

module 0x1::coin {
    use std::signer;

    struct Coin has key {
        balance: u64
    }

    public fun mint(account: &signer, value: u64) {
        move_to(account, Coin { balance: value });
    }

    public fun get_balance(addr: address): u64 acquires Coin {
        borrow_global<Coin>(addr).balance
    }
}

Aptos-specific features:

  • Global storage operators: move_to, borrow_global, borrow_global_mut, exists
  • acquires keyword
  • signer type for authentication

Sui Move

module 0x2::coin {
    use sui::object::{Self, UID};
    use sui::transfer;
    use sui::tx_context::{Self, TxContext};

    struct Coin<phantom T> has key, store {
        id: UID,
        balance: u64
    }

    public entry fun mint<T>(value: u64, ctx: &mut TxContext) {
        let coin = Coin {
            id: object::new(ctx),
            balance: value
        };
        transfer::transfer(coin, tx_context::sender(ctx));
    }

    public fun merge<T>(coin1: &mut Coin<T>, coin2: Coin<T>) {
        let Coin { id, balance } = coin2;
        object::delete(id);
        coin1.balance = coin1.balance + balance;
    }
}

Sui-specific features:

  • Object model with UID
  • phantom type parameters
  • entry functions
  • transfer::transfer, transfer::share_object
  • TxContext for transaction context

🔧 Building from Source

Windows

Requirements:

  • Python 3.8+
  • MinGW-w64 or MSVC
# Using MinGW
python setup.py build_ext --inplace --compiler=mingw32
python setup.py bdist_wheel

# Using MSVC
python setup.py build_ext --inplace
python setup.py bdist_wheel

Linux / WSL

Requirements:

  • Python 3.8+
  • GCC
chmod +x build_linux.sh
./build_linux.sh

Or manually:

sudo apt-get install -y build-essential python3-dev
python3 setup.py build_ext --inplace
python3 setup.py bdist_wheel

macOS

Requirements:

  • Python 3.8+
  • Xcode Command Line Tools
chmod +x build_macos.sh
./build_macos.sh

Or manually:

xcode-select --install
python3 setup.py build_ext --inplace
python3 setup.py bdist_wheel

详细说明: 请参考 BUILD_MACOS.md

🧪 Testing

# Test Sui Move advanced features
python test_sui_advanced.py

# Expected output:
# ✅ PASS: Shared Objects
# ✅ PASS: Entry Functions
# ✅ PASS: Phantom Types
# ✅ PASS: Witness Pattern
# ✅ PASS: Dynamic Fields
# 总计: 5/5 通过

📖 Grammar Source

This package is based on the Move grammar from aptos-move-analyzer, which provides comprehensive support for the Move language syntax.

Why it works for both Aptos and Sui:

  • Aptos Move and Sui Move share the same core syntax
  • Differences are primarily in semantics (libraries, object model)
  • The tree-sitter grammar parses syntax, not semantics

📄 License

Apache-2.0

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📞 Support

If you encounter any issues:

  1. Check the BUILD_MACOS.md for platform-specific guidance
  2. Run the test suite: python test_sui_advanced.py
  3. Open an issue with your error logs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

move_fcg_tool-0.1.0-cp314-cp314-macosx_15_0_x86_64.whl (146.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ x86-64

move_fcg_tool-0.1.0-cp312-cp312-win_amd64.whl (170.6 kB view details)

Uploaded CPython 3.12Windows x86-64

move_fcg_tool-0.1.0-cp310-cp310-manylinux_2_17_x86_64.whl (97.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file move_fcg_tool-0.1.0-cp314-cp314-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for move_fcg_tool-0.1.0-cp314-cp314-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d2a28de8ff541b8f5339c7dea5208dc85366b482c50c4f2aad2a1b4b1ee82937
MD5 9855b3a67d1a510c8158d108db39c81e
BLAKE2b-256 ce101b4730abc53b7e63d47bd8626348c26a540247d41d2272a508d7fa68786a

See more details on using hashes here.

File details

Details for the file move_fcg_tool-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for move_fcg_tool-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7163fd8815f069cbb481ad33d9a7a22a44cf4f9aac29e18cc85ed093dd287498
MD5 25869982a87d296f807bb5f2c44484f7
BLAKE2b-256 b5a55e1eda15a91e7e41d2ec9b93194358ca3be03107d92123f200a7119f2eaa

See more details on using hashes here.

File details

Details for the file move_fcg_tool-0.1.0-cp310-cp310-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for move_fcg_tool-0.1.0-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 db547d24081bfa9eff23de509c1ec61bd00f041c9b0e830bae9c209bf48d3414
MD5 9ba09a51e0d848e17f2aea582a7b01e4
BLAKE2b-256 d9ff8d5d827e602058eb5b4c03f50a554c21edef76dbc6963c517a24b37d2ee9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page