#!/usr/bin/env python

import sys

from os.path import basename

from code.callgraph import CallGraph
from code.util import fileToModule

def main(args):
    if len(args) > 1:

        module = fileToModule(args[1])

        if module is None:
            return 0

        gname = basename(args[1]).replace('.', '_')

        callgraph = CallGraph.fromModule(gname, module, False) # True means we skip system calls

        print(callgraph)
        #print(callgraph.toDotString())

        return 0

    else:
        print("Usage: {0} <llvm bitcode or ir>\n".format(args[0]))
        return 1



if __name__ == '__main__':
    sys.exit(main(sys.argv))
