Crate cmtir

Crate cmtir 

Source
Expand description

cmtir is the central intermediate representation (IR) for Cement (cmt2) languages and compiler tools.

Key features:

  • Rule-based syntax and semantics
  • Natural parse-print support
  • Def-use support for operations
  • Compatibility with FIRRTL

§Design

cmtir is implemented based on kir, which provides a consistent pattern of parse-print support for all IR components.

src/ir defines different components of cmtir:

  • ir::op: operations.
  • ir::instance: instance declaration and usage.
  • ir::literal: literals.
  • ir::rule: rules.
  • ir::structure: module and circuit.
  • ir::error: span and error messages.

All structs in cmtir have the consistent pattern of SExpr derive, which is a macro that provides parse-print support (see kir::SExpr).

For operations, cmtir derives OpIO trait (also defined in kir), which provides def-use support: taking/updating def/use values of operations. For most operations, the OpIO trait is derived automatically when #[opio(xxx)] is specified on the struct fields.

§External Module

cmtir accepts FIRRTL code as external modules. This is useful for reusing existing modules from the FIRRTL (or Chisel, Chipyard) ecosystem. Also, since FIRRTL supports blackbox SV modules, cmtir is also compatible with SV legacy code indirectly.

The question is, how cmtir treat RTL external modules in the rule-based semantics? cmtir provides syntax to declare external rules for external modules, each of which specifies the real hardware behavior of the corresponding rule, like setting up some signals. cmtir also provides syntax to bind cmtir module ports and RTL ports in external modules.

Re-exports§

pub use anyhow;
pub use json;
pub use common::*;
pub use utils::*;
pub use ir::*;
pub use to_fir::*;

Modules§

common
fir
FIRRTL.
flatindex
fsmgen
cmtir’s operation creation support for FSMGEN (generating FSMs from procedural descriptions)primitives, including seq, par, branch, for, …
ir
cmtir’s IR components.
to_fir
utils

Macros§

flat_combine
flat_combine_deref
flat_combine_len
flat_combine_mut
new_key_type
texpr

Structs§

AttrView
Parser
Printer
SlotMap
Slot map, storage with stable unique keys.
Value
ValueId
ValuePrinter
ValueResolver

Enums§

Token
Type
ValueName

Traits§

Ctx
IRDump
IdFor
KeyIter
OpIO
Parse
ParsePrint
Print
PrintableId

Functions§

ir_dump
ir_dump_with

Type Aliases§

ValueMap

Derive Macros§

OpIO
ParsePrint
SExpr