#!/usr/bin/env python3 ############################################################################# # trace2trace # # Converts a simulation trace file to the epiphany trace format # # Simulators supported: ovpsim, spike # ############################################################################# import re import sys #Input Arguments with open(sys.argv[1], 'r') as f: file_content = f.read() fileout=open(sys.argv[2],"w") #Reading input file into buffer list=file_content.split('\'riscvOVPsim/cpu\'') #ABI dictionary regs={ "zero":"r0", "ra":"r1", "sp":"r2", "gp":"r3", "tp":"r4", "t0":"r5", "t1":"r6", "t2":"r7", "s0":"r8", "s1":"r9", "a0":"r10", "a1":"r11", "a2":"r12", "a3":"r13", "a4":"r14", "a5":"r15", "a6":"r16", "a7":"r17", "s2":"r18", "s3":"r19", "s4":"r20", "s5":"r21", "s6":"r22", "s7":"r23", "s8":"r24", "s9":"r25", "s10":"r26", "s11":"r27", "t3":"r28", "t4":"r29", "t5":"r30", "t6":"r31", "mtvec":"mtvec", "pmpaddr0":"pmpaddr0", "pmpcfg0":"pmpcfg0", "mstatus":"mstatus", "mepc":"mepc", "mcause":"mcause", } #Format Trace for i in list: instr=i.replace('\n',' ') #replace all newlines in middle of strings instr=instr.replace('Info','') #remove info instr=re.sub('\(SIGNATURE_DUMP.*','',instr) #remove crud from end of file if(re.search('^\,',instr)) : #filter out more crud fields=instr.split() #split into fields pc=re.sub('\(.*','',fields[1]) pc=re.sub('0x','',pc) #removing hex prefix opcode=fields[2] name=fields[3].rjust(8) if(re.search('\-\>',instr)) : #print("XXX" + instr) reg=fields[-4] reg=regs[reg] val=fields[-1] if(re.search('^r',reg)) : update=reg + "=" + val.zfill(16); #don't update csrs for now else : update="" fileout.write("TRACE: cpu_0.trace PC=" + pc + " I=" + name + " F=-------- " + update + "\n") fileout.close()