<commit_before>// Copyright (C) 2015 <NAME>, <NAME>
// License: BSD 2-Clause (see LICENSE for details)

package TurboRav

import Chisel._

import Array._
import java.math.BigInteger;
import scala.sys.process._;

class Rom(elf_path: String) extends Module {
  val io = new Bundle {
    val pc    = UInt(INPUT, Config.xlen)
    val instr = UInt(OUTPUT, Config.xlen)
  }

  // The pc addresses individual bytes, but the ROM stores 4-byte
  // words and assumes that all addresses are word-aligned. To go from
  // a byte-addressable address to a word addressable address we
  // right-shift twice.
  val word_addr = io.pc >> UInt(2)

  // Create ROM
  val rom_array = parseRomContents(elf_path)
  val rom = Vec(rom_array)

  // Read from rom
  io.instr := rom(word_addr)

  private def parseRomContents(elf_path: String): Array[UInt] = {
    val elf_path_bin = s"$elf_path.bin"
    Seq(
      "riscv64-unknown-elf-objcopy",
      "-O",
      "binary",
      elf_path,
      elf_path_bin
    ).!<commit_msg>Minor refactor in rom.scala<commit_after>// Copyright (C) 2015 <NAME>, <NAME>
// License: BSD 2-Clause (see LICENSE for details)

package TurboRav

import Chisel._

import Array._
import java.math.BigInteger;
import scala.sys.process._;

class Rom(elf_path: String) extends Module {
  val io = new Bundle {
    val pc    = UInt(INPUT, Config.xlen)
    val instr = UInt(OUTPUT, Config.xlen)
  }

  // Create ROM
  val rom_array = parseRomContents(elf_path)
  val rom = Vec(rom_array)

  // The pc addresses individual bytes, but the ROM stores 4-byte
  // words and assumes that all addresses are word-aligned. To go from
  // a byte-addressable address to a word addressable address we
  // right-shift twice.
  val word_addr = io.pc >> UInt(2)

  // Read from rom
  io.instr := rom(word_addr)

  private def parseRomContents(elf_path: String): Array[UInt] = {
    val elf_path_bin = s"$elf_path.bin"
    Seq(
      "riscv64-unknown-elf-objcopy",
      "-O",
      "binary",
      elf_path,
      elf_path_bin
    ).!
{'fraction_non_alphanumeric': 0.1103960396039604, 'fraction_numerical': 0.00891089108910891, 'mean_word_length': 2.9861932938856017, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6785780', 'n_tokens_mistral': 705, 'n_tokens_neox': 675, 'n_words': 209}