kuroko/modules/dis.krk
2022-07-15 08:06:34 +09:00

29 lines
762 B
Python

'''
@brief Called when 'dis' is run as the main module (-m dis)
'''
# Get the real dis
import dis
def disrec(code, seen):
let next = [code]
while next:
let co = next[0]
next = next[1:]
dis.dis(co)
for inst,size,operand in dis.examine(co):
if isinstance(operand,codeobject) and operand not in seen and operand not in next:
next.append(operand)
if next:
print()
if __name__ == '__main__':
import kuroko
if (len(kuroko.argv) < 2):
print("Usage: kuroko -m dis FILE")
return 1
import fileio
for file in kuroko.argv[1:]:
with fileio.open(file,'r') as f:
let result = dis.build(f.read(), file)
disrec(result,set())