phasm/phasm/__main__.py
Johan B.W. de Vries d97be81828 Optimise: Remove unused functions
By default, we add a lot of build in functions that may
never get called.

This commit adds a simple reachability graph algorithm
to remove functions that can't be called from outside.

Also, unmarks a lot of functions as being exported. It
was the default to export - now it's the default to not
export.

Also, some general cleanup to the wasm statement calls.
2025-05-25 16:39:25 +02:00

34 lines
724 B
Python

"""
Functions for using this module from CLI
"""
import sys
from .compiler import phasm_compile
from .optimise.removeunusedfuncs import removeunusedfuncs
from .parser import phasm_parse
from .type3.entry import phasm_type3
def main(source: str, sink: str) -> int:
"""
Main method
"""
with open(source, 'r') as fil:
code_py = fil.read()
our_module = phasm_parse(code_py)
phasm_type3(our_module, verbose=False)
wasm_module = phasm_compile(our_module)
removeunusedfuncs(wasm_module)
code_wat = wasm_module.to_wat()
with open(sink, 'w') as fil:
fil.write(code_wat)
return 0
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:])) # pylint: disable=E1120