Giter Club home page Giter Club logo

hardware-notes's Introduction

Hardware-Notes

firrtl & Chisel-tester2 reading

Emitter.scala

-E smt2:
Seq(RunFirrtlTransformAnnotation(Dependency(SMTLibEmitter)), EmitCircuitAnnotation(SMTLibEmitter.getClass))

Firrtl.backends.experimental.smt.*

  • Btor2Serializer.scala: SMTEmitter调用,输入TransitionSystem
  • SMTExprSerializer.scala:SMTExpr调用,

BVExpr, line35,

override def toString: String = SMTExprSerializer.serialize(this)

ArrayExpr, line192,

override def toString: String = SMTExprSerializer.serialize(this)
  • SMTLibSerializer.scala: 输入TransitionSystem,转为SMT

SMTEmitter调用,

SMTTransitionSystemEncoder调用,line102,

private def id(s: String): String = SMTLibSerializer.escapeIdentifier(s)
  • SMTTransitionSystemEncoder.scala:
def encode(sys: TransitionSystem): Iterable[SMTCommand] = {...}
  • FirrtlToTransitionSystem.scala:
/** Contains code to convert a flat firrtl module into a functional transition system which
  * can then be exported as SMTLib or Btor2 file.
  */

输入之前需要进行firrtl module的inline,但是目前还没清楚具体再那一步完成了inline

// since this pass only runs on the main module, inlining needs to happen before
  override def optionalPrerequisites: Seq[TransformDependency] = Seq(Dependency[firrtl.passes.InlineInstances])

execute中会new一个ModuleToTransitionSystem类,调用其中的run方法

override protected def execute(state: CircuitState): CircuitState = {
 ...
 // convert the main module
   ...
      case m: ir.Module =>
        new ModuleToTransitionSystem(presetRegs = presetRegs, memInit = memInit, uninterpreted = uninterpreted).run(m)
    }
}

run方法

// first pass over the module to convert expressions; discover state and I/O
    m.foreachPort(onPort)
    m.foreachStmt(onStatement)

onPort中遍历IO类型,得到clocks和inputs,inputs中append的是BVSymbol类型

onStatement根据不同statement类型得到inputs, signals, states等

返回一个TransitionSystem

TransitionSystem(m.name, inputs.toList, states.values.toList, signals.toList, comments.toMap, header)
  • UninterpretedModuleAnnotation.scala:
/** ExtModules annotated as UninterpretedModule will be modelled as
  * UninterpretedFunction (SMTLib) or constant arrays (btor2).
  * This can be useful when trying to abstract over a function that the
  * SMT solver or model checker is struggling with.
  ...
  */

chekModule方法

/** checks to see whether the annotation module can actually be abstracted. Use *after* LowerTypes! */
  def checkModule(m: ir.DefModule, anno: UninterpretedModuleAnnotation): Unit = m match {
  ...
  }

Maltese.scala

  • bmc调用toTransitionSystem():
val sysInfo = toTransitionSystem(circuit, sysAnnos)
  • toTransitionSystem(circuit: ir.Circuit, annos: AnnotationSeq):
val res = firrtlPhase.transform(
  Seq(
    RunFirrtlTransformAnnotation(Dependency(SMTLibEmitter)),
    new CurrentFirrtlStateAnnotation(Forms.LowForm),
    FirrtlCircuitAnnotation(circuit)
  ) ++: logLevel ++: annos ++: LoweringAnnos ++: opts
)

class FirrtlPhase定义在firrtl.FirrtlStage中:

class FirrtlPhase
    extends PhaseManager(
      targets = Seq(
        Dependency[firrtl.stage.phases.Compiler],
        Dependency[firrtl.stage.phases.ConvertCompilerAnnotations]
      )
    )
  • firrtl.stage.phases.ConvertCompilerAnnotations.scala中定义class ConvertCompilerAnnotations, 其中有:
override def transform(annotations: AnnotationSeq): AnnotationSeq = {
 ...
 RunFirrtlTransformAnnotation(a.emitter)
}

val res = firrtlPhase.transform()可能调用的是这里的transform

  • 从toTransitionSystem()中依然没办法直观看出来如何进行firrtl到transition system的转换,但是在定义res之后有一行代码:
val sys = res.collectFirst { case TransitionSystemAnnotation(s) => s }.get

其中

case class TransitionSystemAnnotation(sys: TransitionSystem) 

定义在firrtl.backends.experimental.smt.FirrtlToTransitionSystem.scala中,根据注释,在FirrtlToTransitionSystem方法中进行转换:

/** Contains code to convert a flat firrtl module into a functional transition system which
  * can then be exported as SMTLib or Btor2 file.
  */
object FirrtlToTransitionSystem extends Transform with DependencyAPIMigration {
}

hardware-notes's People

Contributors

fengwz17 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.