#!/usr/local/bin/python

"""
pystrip file.pyc ...

  pystrip removes the SET_LINENO instructions from the compiled modules
specified on the command line. 

Author: Mike McDonald <mikemac@sgi.com>

History:
    Version: 1.0 April 8, 1997 - first released
"""

import sys, assem, ctransform

def strip_line_nums(f):
    """strip_line_nums(f) removes all of the SET_LINENO instructions from
    the function 'f'.
    """
    new_instructions = []
    code = assem.disassemble(f)
    for instr in code.instructions:
	label = instr[0]
	opname = instr[1]
	arg = instr[2]
	if opname != 'SET_LINENO':
	    new_instructions.append([label, opname, arg])
    code.instructions = new_instructions
    return code.assemble()

if __name__ == '__main__':
    if len(sys.argv) == 1:
	print 'usage: pystrip file.pyc ...'
	sys.exit(1)
    for arg in sys.argv[1:]:
	mod = ctransform.load_compiled_module(arg)
	new_mod = ctransform.transform_compiled_module(mod, strip_line_nums)
	new_mod.dump()
