from picshell.engine.core.PicEngine import PicEngine
from picshell.engine.util.Format import Format
from picshell.engine.core.State import State
    
class EngineMonitor :
    def __init__(self):
        self.level = 0

    # inst is an instance of class Inst
    # inst.model is an instance of class InstModel
    def executeBefore (self,engine,inst):
        print Format.formatInstruction(inst, self.level, False)
    def executeAfter (self,engine,inst):
       if inst.model.mnemonic == "CALL"  :
            self.level += 1
       if inst.model.mnemonic == "RETURN" :
            self.level -= 1
#
# Code execution start here
#
print "Start"    
engine = PicEngine.newInstance("16f628a",".\\test_hex_files\\picshell_portb_demo_16f.hex")
engine.monitors = [EngineMonitor()] # 
engine.runTillAddress(engine.lastAddress)
print "End"