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
174
175
176
177
178
use super::ParamValue;
use super::{BinType, FlowCondition, FlowID, GroupType, PatternGroupType};
use crate::generator::ast::Meta;
use crate::testers::SupportedTester;
use crate::{Result, FLOW};

/// Start a sub-flow, the returned reference should be retained and passed to end_block
pub fn start_sub_flow(name: &str, meta: Option<Meta>) -> Result<usize> {
    let n = node!(PGMSubFlow, name.to_owned(); meta);
    FLOW.push_and_open(n)
}

pub fn end_block(ref_id: usize) -> Result<()> {
    FLOW.close(ref_id)
}

/// Defines a new test in the AST, returning its ID.
/// A test must be initially defined before attributes can be set on it. It won't actually
/// appear in the test flow until it is added to if via add_test()
pub fn define_test(
    name: &str,
    tester: &SupportedTester,
    lib_name: &str,
    template_name: &str,
    meta: Option<Meta>,
) -> Result<usize> {
    let id = crate::STATUS.generate_unique_id();
    let n = node!(PGMDefTest, id, name.to_owned(), tester.to_owned(), lib_name.to_owned(), template_name.to_owned(); meta);
    FLOW.push(n)?;
    Ok(id)
}

/// Defines a new test invocation in the AST, returning its ID.
/// A test invoration must be initially defined before attributes can be set on it. It won't actually
/// appear in the test flow until it is added to if via add_test()
pub fn define_test_invocation(
    name: &str,
    tester: &SupportedTester,
    meta: Option<Meta>,
) -> Result<usize> {
    let id = crate::STATUS.generate_unique_id();
    let n = node!(PGMDefTestInv, id, name.to_owned(), tester.to_owned(); meta);
    FLOW.push(n)?;
    Ok(id)
}

/// Set an attribute of either a test or a test invocation
pub fn set_test_attr(id: usize, name: &str, value: ParamValue, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMSetAttr, id, name.to_owned(), value; meta);
    FLOW.push(n)?;
    Ok(())
}

pub fn assign_test_to_invocation(
    invocation_id: usize,
    test_id: usize,
    meta: Option<Meta>,
) -> Result<()> {
    let n = node!(PGMAssignTestToInv, invocation_id, test_id; meta);
    FLOW.push(n)?;
    Ok(())
}

/// Execute the given test (or invocation) from the current flow
pub fn execute_test(id: usize, flow_id: FlowID, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMTest, id, flow_id; meta);
    FLOW.push(n)
}

/// Execute the given test (or invocation) from the current flow, where the test is a string that
/// will be rendered verbatim to the flow - no linkage to an actual test object will be checked or
/// inserted by Origen
pub fn execute_test_str(name: String, flow_id: FlowID, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMTestStr, name, flow_id; meta);
    FLOW.push(n)
}

/// Cz the given test (or invocation) from the current flow
pub fn execute_cz_test(
    id: usize,
    cz_setup: String,
    flow_id: FlowID,
    meta: Option<Meta>,
) -> Result<()> {
    let n = node!(PGMCz, id, cz_setup, flow_id; meta);
    FLOW.push(n)
}

pub fn define_pattern_group(
    name: String,
    tester: SupportedTester,
    kind: Option<PatternGroupType>,
    meta: Option<Meta>,
) -> Result<usize> {
    let id = crate::STATUS.generate_unique_id();
    let n = node!(PGMPatternGroup, id, name, tester, kind; meta);
    FLOW.push(n)?;
    Ok(id)
}

pub fn push_pattern_to_group(
    id: usize,
    path: String,
    start_label: Option<String>,
    meta: Option<Meta>,
) -> Result<()> {
    let n = node!(PGMPushPattern, id, path, start_label; meta);
    FLOW.push(n)
}

/// Renders the given string directly to the test flow
pub fn render(text: String, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMRender, text; meta);
    FLOW.push(n)
}

pub fn log(text: String, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMLog, text; meta);
    FLOW.push(n)
}

/// [IGXL only] Set the given wait flags on the given test instance
pub fn set_wait_flags(ti_id: usize, flags: Vec<String>, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMIGXLSetWaitFlags, ti_id, flags; meta);
    FLOW.push(n)
}

/// Used to model flow groups, IG-XL test instance groups, etc.
pub fn start_group(
    name: String,
    tester: Option<SupportedTester>,
    kind: GroupType,
    flow_id: Option<FlowID>,
    meta: Option<Meta>,
) -> Result<usize> {
    if kind == GroupType::Flow && flow_id.is_none() {
        return error!("A flow_id must be supplied when starting a flow group");
    }
    let n = node!(PGMGroup, name, tester, kind, flow_id; meta);
    FLOW.push_and_open(n)
}

pub fn start_condition(condition: FlowCondition, meta: Option<Meta>) -> Result<usize> {
    let n = node!(PGMCondition, condition; meta);
    FLOW.push_and_open(n)
}

pub fn define_bin(
    number: usize,
    is_soft: bool,
    kind: BinType,
    description: Option<String>,
    priority: Option<usize>,
    meta: Option<Meta>,
) -> Result<()> {
    let n = node!(PGMDefBin, number, is_soft, kind, description, priority; meta);
    FLOW.push(n)
}

/// Bin out the DUT
pub fn bin(hard: usize, soft: Option<usize>, kind: BinType, meta: Option<Meta>) -> Result<()> {
    let n = node!(PGMBin, hard, soft, kind; meta);
    FLOW.push(n)
}

/// Start an on-failed block (events to run if the given test or group failed), the returned
/// reference should be retained and passed to end_block
pub fn start_on_failed(flow_id: FlowID, meta: Option<Meta>) -> Result<usize> {
    let n = node!(PGMOnFailed, flow_id; meta);
    FLOW.push_and_open(n)
}

/// Start an on-passed block (events to run if the given test or group passed), the returned
/// reference should be retained and passed to end_block
pub fn start_on_passed(flow_id: FlowID, meta: Option<Meta>) -> Result<usize> {
    let n = node!(PGMOnPassed, flow_id; meta);
    FLOW.push_and_open(n)
}