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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
pub mod api;
pub mod igxl;
pub mod simulator;
pub mod smt;
mod supported_testers;
pub mod vector_based;

use crate::core::tester::{Interceptor, TesterAPI, TesterID};
use crate::generator::ast::{Attrs, Node};
use crate::generator::processor::{Processor, Return};
use crate::{dut, Result};
use std::path::PathBuf;
pub use supported_testers::SupportedTester;

pub fn instantiate_tester(g: &SupportedTester) -> Result<Box<dyn TesterAPI + std::marker::Send>> {
    match g {
        SupportedTester::DUMMYRENDERER => Ok(Box::new(DummyRenderer::default())),
        SupportedTester::DUMMYRENDERERWITHINTERCEPTORS => {
            Ok(Box::new(DummyRendererWithInterceptors::default()))
        }
        SupportedTester::V93KSMT7 => Ok(Box::new(smt::V93K_SMT7::default())),
        SupportedTester::SIMULATOR => Ok(Box::new(simulator::Renderer::default())),
        SupportedTester::ULTRAFLEX => Ok(Box::new(igxl::UltraFlex::default())),
        SupportedTester::J750 => Ok(Box::new(igxl::j750::J750::default())),
        SupportedTester::CUSTOM(_) => {
            error!("Custom testers are not instantiated by this function")
        }
        _ => error!("The tester driver for {}, is not implemented yet", g),
    }
}

#[derive(Debug, Clone)]
pub struct DummyRenderer {
    count: usize,
    current_timeset_id: Option<usize>,
}

impl Default for DummyRenderer {
    fn default() -> Self {
        Self {
            count: 0,
            current_timeset_id: Option::None,
        }
    }
}

impl DummyRenderer {}
impl Interceptor for DummyRenderer {}

impl TesterID for DummyRenderer {
    fn id(&self) -> SupportedTester {
        SupportedTester::DUMMYRENDERER
    }
}

impl TesterAPI for DummyRenderer {
    fn render_pattern(&mut self, ast: &Node) -> crate::Result<Vec<PathBuf>> {
        ast.process(self)?;
        Ok(vec![])
    }
}

impl Processor for DummyRenderer {
    fn on_node(&mut self, node: &Node) -> crate::Result<Return> {
        match &node.attrs {
            Attrs::Test(_name) => {
                // Not counting the top node as a node. Only comments and cycles.
                println!("Printing StubAST to console...");
                Ok(Return::ProcessChildren)
            }
            Attrs::Comment(_level, msg) => {
                println!(
                    "  ::DummyRenderer Node {}: Comment - Content: {}",
                    self.count, msg
                );
                self.count += 1;
                Ok(Return::Unmodified)
            }
            Attrs::Cycle(repeat, _compressable) => {
                let dut = dut();
                let t = &dut.timesets[self.current_timeset_id.unwrap()];
                println!(
                    "  ::DummyRenderer Node {}: Vector - Repeat: {}, Timeset: '{}'",
                    self.count, repeat, t.name
                );
                self.count += 1;
                Ok(Return::Unmodified)
            }
            Attrs::SetTimeset(timeset_id) => {
                self.current_timeset_id = Some(*timeset_id);
                Ok(Return::Unmodified)
            }
            _ => Ok(Return::ProcessChildren),
        }
    }
}

#[derive(Debug, Clone)]
pub struct DummyRendererWithInterceptors {
    count: usize,
    current_timeset_id: Option<usize>,
}

impl DummyRendererWithInterceptors {}

impl TesterID for DummyRendererWithInterceptors {
    fn id(&self) -> SupportedTester {
        SupportedTester::DUMMYRENDERERWITHINTERCEPTORS
    }
}

impl TesterAPI for DummyRendererWithInterceptors {
    fn render_pattern(&mut self, ast: &Node) -> crate::Result<Vec<PathBuf>> {
        ast.process(self)?;
        Ok(vec![])
    }
}

impl Default for DummyRendererWithInterceptors {
    fn default() -> Self {
        Self {
            count: 0,
            current_timeset_id: Option::None,
        }
    }
}

impl Interceptor for DummyRendererWithInterceptors {
    fn cycle(&mut self, _repeat: u32, _compressable: bool, _node: &Node) -> Result<()> {
        println!("Vector intercepted by DummyRendererWithInterceptors!");
        Ok(())
    }

    fn cc(&mut self, _level: u8, _msg: &str, _node: &Node) -> Result<()> {
        println!("Comment intercepted by DummyRendererWithInterceptors!");
        Ok(())
    }
}

impl Processor for DummyRendererWithInterceptors {
    fn on_node(&mut self, node: &Node) -> crate::Result<Return> {
        match &node.attrs {
            Attrs::Test(_name) => {
                // Not counting the top node as a node. Only comments and cycles.
                println!("Printing StubAST to console...");
                Ok(Return::ProcessChildren)
            }
            Attrs::Comment(_level, msg) => {
                println!(
                    "  ::DummyRendererWithInterceptors Node {}: Comment - Content: {}",
                    self.count, msg
                );
                self.count += 1;
                Ok(Return::Unmodified)
            }
            Attrs::Cycle(repeat, _compressable) => {
                let dut = dut();
                let t = &dut.timesets[self.current_timeset_id.unwrap()];
                println!(
                    "  ::DummyRendererWithInterceptors Node {}: Vector - Repeat: {}, Timeset: '{}'",
                    self.count, repeat, t.name
                );
                self.count += 1;
                Ok(Return::Unmodified)
            }
            Attrs::SetTimeset(timeset_id) => {
                self.current_timeset_id = Some(*timeset_id);
                Ok(Return::Unmodified)
            }
            _ => Ok(Return::ProcessChildren),
        }
    }
}