switch to sigspec type

main
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> {
let target_id = make_pubid(assignment.lhs);
let return_wire = lower_expression(ctx, module, &assignment.expr)?;
module.add_connection(target_id, return_wire);
module.add_connection(&target_id, &return_wire);
Ok(())
}

View File

@ -46,6 +46,28 @@ pub trait RtlilWrite {
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)]
pub struct Wire {
/// rtlil ID
@ -98,7 +120,7 @@ pub struct Module {
name: String,
wires: Vec<Wire>,
cells: Vec<Cell>,
connections: Vec<(String, String)>,
connections: Vec<(SigSpec, SigSpec)>,
gen_id: i32,
}
@ -117,8 +139,8 @@ impl Module {
self.wires.push(wire)
}
pub fn add_connection(&mut self, target: String, source: String) {
self.connections.push((target, source))
pub fn add_connection(&mut self, target: &str, source: &str) {
self.connections.push((SigSpec::wire(target), SigSpec::wire(source)))
}
pub fn add_cell(&mut self, cell: Cell) {
@ -151,7 +173,7 @@ pub struct Cell {
id: String,
celltype: String,
parameters: Vec<(String, String)>,
connections: Vec<(String, String)>,
connections: Vec<(SigSpec, SigSpec)>,
}
impl Cell {
@ -169,7 +191,7 @@ impl Cell {
}
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 {
id: String,
@ -7,7 +7,7 @@ pub struct Process {
}
pub struct CaseRule {
assign: Vec<(String, String)>,
assign: Vec<(SigSpec, SigSpec)>,
switches: Vec<SwitchRule>,
}
@ -18,7 +18,7 @@ pub struct SwitchRule {
pub struct SyncRule {
cond: SyncCond,
assign: Vec<(String, String)>,
assign: Vec<(SigSpec, SigSpec)>,
}
pub enum SyncCond {