switch to sigspec type

This commit is contained in:
NotAFile 2022-01-16 20:13:04 +01:00
parent a6b8429ed0
commit 42349a6273
3 changed files with 31 additions and 9 deletions

View File

@ -109,7 +109,7 @@ fn lower_assignment(
) -> Result<(), CompileError> { ) -> Result<(), CompileError> {
let target_id = make_pubid(assignment.lhs); let target_id = make_pubid(assignment.lhs);
let return_wire = lower_expression(ctx, module, &assignment.expr)?; let return_wire = lower_expression(ctx, module, &assignment.expr)?;
module.add_connection(target_id, return_wire); module.add_connection(&target_id, &return_wire);
Ok(()) Ok(())
} }

View File

@ -46,6 +46,28 @@ pub trait RtlilWrite {
fn write_rtlil(&self, writer: &mut ILWriter); fn write_rtlil(&self, writer: &mut ILWriter);
} }
#[derive(Debug)]
pub enum SigSpec {
Const(i32, u32),
Wire(String),
}
impl SigSpec {
pub fn wire(id: &str) -> Self {
Self::Wire(id.to_owned())
}
}
impl std::fmt::Display for SigSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SigSpec::Const(val, width) => write!(f, "{}'{}", width, val)?,
SigSpec::Wire(id) => write!(f, "{}", id)?,
};
Ok(())
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Wire { pub struct Wire {
/// rtlil ID /// rtlil ID
@ -98,7 +120,7 @@ pub struct Module {
name: String, name: String,
wires: Vec<Wire>, wires: Vec<Wire>,
cells: Vec<Cell>, cells: Vec<Cell>,
connections: Vec<(String, String)>, connections: Vec<(SigSpec, SigSpec)>,
gen_id: i32, gen_id: i32,
} }
@ -117,8 +139,8 @@ impl Module {
self.wires.push(wire) self.wires.push(wire)
} }
pub fn add_connection(&mut self, target: String, source: String) { pub fn add_connection(&mut self, target: &str, source: &str) {
self.connections.push((target, source)) self.connections.push((SigSpec::wire(target), SigSpec::wire(source)))
} }
pub fn add_cell(&mut self, cell: Cell) { pub fn add_cell(&mut self, cell: Cell) {
@ -151,7 +173,7 @@ pub struct Cell {
id: String, id: String,
celltype: String, celltype: String,
parameters: Vec<(String, String)>, parameters: Vec<(String, String)>,
connections: Vec<(String, String)>, connections: Vec<(SigSpec, SigSpec)>,
} }
impl Cell { impl Cell {
@ -169,7 +191,7 @@ impl Cell {
} }
pub fn add_connection(&mut self, from: &str, to: &str) { pub fn add_connection(&mut self, from: &str, to: &str) {
self.connections.push((from.into(), to.into())) self.connections.push((SigSpec::wire(from), SigSpec::wire(to)))
} }
} }

View File

@ -1,4 +1,4 @@
use crate::rtlil::RtlilWrite; use crate::rtlil::{RtlilWrite, SigSpec};
pub struct Process { pub struct Process {
id: String, id: String,
@ -7,7 +7,7 @@ pub struct Process {
} }
pub struct CaseRule { pub struct CaseRule {
assign: Vec<(String, String)>, assign: Vec<(SigSpec, SigSpec)>,
switches: Vec<SwitchRule>, switches: Vec<SwitchRule>,
} }
@ -18,7 +18,7 @@ pub struct SwitchRule {
pub struct SyncRule { pub struct SyncRule {
cond: SyncCond, cond: SyncCond,
assign: Vec<(String, String)>, assign: Vec<(SigSpec, SigSpec)>,
} }
pub enum SyncCond { pub enum SyncCond {