<commit_before>package spatial.codegen.chiselgen

import spatial.SpatialConfig
import spatial.SpatialExp
import scala.collection.mutable.HashMap

trait ChiselGenDRAM extends ChiselGenSRAM {
  val IR: SpatialExp
  import IR._

  var dramMap = HashMap[String, (String, String)]() // Map for tracking defs of nodes and if they get redeffed anywhere, we map it to a suffix

  override def quote(s: Exp[_]): String = {
    if (SpatialConfig.enableNaming) {
      s match {
        case lhs: Sym[_] =>
          lhs match {
              case Def(e: DRAMNew[_]) => s"x${lhs.id}_dram"
            case _ =>
              super.quote(s)
          }
        case _ =>
          super.quote(s)
      }
    } else {
      super.quote(s)
    }
  } 

  override protected def remap(tp: Staged[_]): String = tp match {
    case tp: DRAMType[_] => src"Array[${tp.child}]"
    case _ => super.remap(tp)
  }

  override protected def emitNode(lhs: Sym[_], rhs: Op[_]): Unit = rhs match {
    case op@DRAMNew(dims) => 
      // Register first dram
      val length = dims.map{i => src"${i}"}.mkString("*")
      if (dramMap.size == 0)  {
        dramMap += (src"$lhs" -> ("0", length))
      } else if (!dramMap.contains(src"$lhs")) {
        val start = dramMap.values.map{ _._2 }.mkString{" + "}
        dramMap += (src"$lhs" -> (start, length))
      } else {
        log(s"dram $lhs used multiple times")
      }

    case GetDRAMAddress(dram) =>
      val id = argMapping(dram)
      emit(src"""val $lhs = io.argIns(io_numArgIns_reg + $id)""")

    case FringeDenseLoad(dram,cmdStream,dataStream) =><commit_msg>arg fix<commit_after>package spatial.codegen.chiselgen

import spatial.SpatialConfig
import spatial.SpatialExp
import scala.collection.mutable.HashMap

trait ChiselGenDRAM extends ChiselGenSRAM {
  val IR: SpatialExp
  import IR._

  var dramMap = HashMap[String, (String, String)]() // Map for tracking defs of nodes and if they get redeffed anywhere, we map it to a suffix

  override def quote(s: Exp[_]): String = {
    if (SpatialConfig.enableNaming) {
      s match {
        case lhs: Sym[_] =>
          lhs match {
              case Def(e: DRAMNew[_]) => s"x${lhs.id}_dram"
            case _ =>
              super.quote(s)
          }
        case _ =>
          super.quote(s)
      }
    } else {
      super.quote(s)
    }
  } 

  override protected def remap(tp: Staged[_]): String = tp match {
    case tp: DRAMType[_] => src"Array[${tp.child}]"
    case _ => super.remap(tp)
  }

  override protected def emitNode(lhs: Sym[_], rhs: Op[_]): Unit = rhs match {
    case op@DRAMNew(dims) => 
      // Register first dram
      val length = dims.map{i => src"${i}"}.mkString("*")
      if (dramMap.size == 0)  {
        dramMap += (src"$lhs" -> ("0", length))
      } else if (!dramMap.contains(src"$lhs")) {
        val start = dramMap.values.map{ _._2 }.mkString{" + "}
        dramMap += (src"$lhs" -> (start, length))
      } else {
        log(s"dram $lhs used multiple times")
      }

    case GetDRAMAddress(dram) =>
      val id = argMapping(dram)
      emit(src"""val $lhs = io.argIns($id)""")

    case FringeDenseLoad(dram,cmdStream,dataStream) =>
{'fraction_non_alphanumeric': 0.14474929044465468, 'fraction_numerical': 0.001892147587511826, 'mean_word_length': 2.4780701754385963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '2884459', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1088, 'n_words': 266}