1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::ast::VerilogLiteral;
use crate::atom::{Atom, AtomKind};
use crate::block::Block;
use crate::constraint::PinConstraint;
use crate::logic::Logic;
use crate::probe::Probe;
use crate::signal::get_signal_id;
use crate::synth::{Synth, VCDValue};
#[derive(Copy, Clone, Debug)]
pub struct Constant<T: Synth> {
val: T,
id: usize,
}
impl<T: Synth> Constant<T> {
pub fn new(val: T) -> Constant<T> {
Constant {
val,
id: get_signal_id(),
}
}
pub fn val(&self) -> T {
self.val
}
}
impl<T: Synth> Logic for Constant<T> {
fn update(&mut self) {}
fn connect(&mut self) {}
}
impl<T: Synth> Atom for Constant<T> {
fn bits(&self) -> usize {
T::BITS
}
fn connected(&self) -> bool {
true
}
fn changed(&self) -> bool {
false
}
fn kind(&self) -> AtomKind {
AtomKind::Constant
}
fn is_enum(&self) -> bool {
T::ENUM_TYPE
}
fn name(&self, ndx: usize) -> &'static str {
T::name(ndx)
}
fn type_name(&self) -> &'static str {
T::TYPE_NAME
}
fn vcd(&self) -> VCDValue {
self.val.vcd()
}
fn verilog(&self) -> VerilogLiteral {
self.val.verilog()
}
fn id(&self) -> usize {
self.id
}
fn constraints(&self) -> Vec<PinConstraint> {
vec![]
}
}
impl<T: Synth> Block for Constant<T> {
fn connect_all(&mut self) {}
fn update_all(&mut self) {}
fn has_changed(&self) -> bool {
false
}
fn accept(&self, name: &str, probe: &mut dyn Probe) {
probe.visit_atom(name, self);
}
}