def _process_core_sim_log_fd(log_fd, csv_fd, full_trace=True): """Process core simulation log. Reads from log_fd, which should be a file object containing a trace from an core simulation. Writes in a standard CSV format to csv_fd, which should be a file object opened for writing. If full_trace is true, this dumps information about operands for, replacing absolute branch destinations with offsets relative to the current pc. """ instr_cnt = 0 trace_csv = RiscvInstructionTraceCsv(csv_fd) trace_csv.start_new_trace() trace_entry = None for line in log_fd: if re.search("ecall", line): instr_cnt += 1 # Extract instruction information m = ECALL_RE.search(line) if m: # Write the extracted instruction to a csvcol buffer file trace_entry = RiscvInstructionTraceEntry() trace_entry.instr_str = "ecall" trace_entry.pc = m.group("pc") trace_entry.binary = m.group("bin") trace_csv.write_trace_entry(trace_entry) break # Extract instruction information m = INSTR_RE.search(line) if m: instr_cnt += 1 # Write the extracted instruction to a csvcol buffer file trace_entry = RiscvInstructionTraceEntry() trace_entry.instr_str = m.group("instr") trace_entry.instr = m.group("instr").split()[0] trace_entry.pc = m.group("pc") trace_entry.binary = m.group("bin") if full_trace: # Convert the operands into ABI format for # the functional coverage flow operands = m.group("instr").split()[1] trace_entry.operand = operands process_operands(trace_entry) trace_entry.operand = convert_operands_to_abi( trace_entry.operand) process_trace(trace_entry) c = RD_RE.search(line) if c: trace_entry.gpr.append('{}:{}'.format( gpr_to_abi("x%0s" % c.group("rd")), c.group("rd_val"))) trace_csv.write_trace_entry(trace_entry) return instr_cnt
def _process_ibex_sim_log_fd(log_fd, csv_fd, full_trace=True): """Process ibex simulation log. Reads from log_fd, which should be a file object containing a trace from an Ibex simulation. Writes in a standard CSV format to csv_fd, which should be a file object opened for writing. If full_trace is true, this dumps information about operands for, replacing absolute branch destinations with offsets relative to the current pc. """ instr_cnt = 0 trace_csv = RiscvInstructionTraceCsv(csv_fd) trace_csv.start_new_trace() trace_entry = None for line in log_fd: if re.search("ecall", line): break # Extract instruction information m = INSTR_RE.search(line) if m is None: continue instr_cnt += 1 # Write the extracted instruction to a csvcol buffer file trace_entry = RiscvInstructionTraceEntry() trace_entry.instr_str = m.group("instr") trace_entry.instr = m.group("instr").split()[0] trace_entry.pc = m.group("pc") trace_entry.binary = m.group("bin") if full_trace: expand_trace_entry(trace_entry, m.group("instr").split()[1]) c = RD_RE.search(line) if c: abi_name = gpr_to_abi("x{}".format(c.group("rd"))) gpr_entry = "{}:{}".format(abi_name, c.group("rd_val")) trace_entry.gpr.append(gpr_entry) trace_csv.write_trace_entry(trace_entry) return instr_cnt