Skip to content

Commit

Permalink
Implement macro_defs handling during STIL parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaj committed Jan 17, 2025
1 parent 79675ad commit 385a1df
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 4 deletions.
6 changes: 6 additions & 0 deletions rust/origen_metal/src/stil/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pub enum STIL {
SignalGroupsRef(String),
MacroDefs(String),
Procedures(String),
ProceduresBlock(Option<String>),
ProceduresDef(String),
MacroDefsBlock(Option<String>),
MacroDef(String),
Shift,
WfcData(String),
ScanStructuresRef(String),
Start(String),
Stop(String),
Expand Down
53 changes: 52 additions & 1 deletion rust/origen_metal/src/stil/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,56 @@ pub fn to_ast(mut pair: Pair<Rule>, source_file: Option<&str>) -> Result<AST<STI
}
ast.push(node!(STIL::EventList, vals))
}
Rule::procedures_block => {
let mut p = pair.into_inner();
let n;
if let Some(nxt) = p.peek() {
n = match nxt.as_rule() {
Rule::name => node!(STIL::ProceduresBlock, Some(unquote(p.next().unwrap().as_str()))),
_ => node!(STIL::ProceduresBlock, None),
};
} else {
n = node!(STIL::ProceduresBlock, None);
}
ids.push(ast.push_and_open(n));
pairs.push(p);
}
Rule::procedures_def => {
let mut p = pair.into_inner();
ids.push(
ast.push_and_open(node!(STIL::ProceduresDef, unquote(p.next().unwrap().as_str()))),
);
pairs.push(p);
}
Rule::macrodefs_block => {
let mut p = pair.into_inner();
let n;
if let Some(nxt) = p.peek() {
n = match nxt.as_rule() {
Rule::name => node!(STIL::MacroDefsBlock, Some(unquote(p.next().unwrap().as_str()))),
_ => node!(STIL::MacroDefsBlock, None),
};
} else {
n = node!(STIL::MacroDefsBlock, None);
}
ids.push(ast.push_and_open(n));
pairs.push(p);
}
Rule::macro_def => {
let mut p = pair.into_inner();
ids.push(
ast.push_and_open(node!(STIL::MacroDef, unquote(p.next().unwrap().as_str()))),
);
pairs.push(p);
}
Rule::procedure_or_macro_item => {
ids.push(0);
pairs.push(pair.into_inner());
}
Rule::shift_pat_stmt => {
ids.push(ast.push_and_open(node!(STIL::Shift)));
pairs.push(pair.into_inner());
}
Rule::spec_block => {
let mut p = pair.into_inner();
let n;
Expand Down Expand Up @@ -886,6 +936,7 @@ pub fn to_ast(mut pair: Pair<Rule>, source_file: Option<&str>) -> Result<AST<STI
})
}
Rule::data_string => ast.push(node!(STIL::Data, pair.as_str().to_string())),
Rule::wfc_data_string => ast.push(node!(STIL::WfcData, pair.as_str().to_string())),
Rule::vec_data => {
ids.push(0);
pairs.push(pair.into_inner());
Expand All @@ -910,7 +961,7 @@ pub fn to_ast(mut pair: Pair<Rule>, source_file: Option<&str>) -> Result<AST<STI
Rule::macro_statement => {
let mut p = pair.into_inner();
ids.push(
ast.push_and_open(node!(STIL::Macro, p.next().unwrap().as_str().to_string())),
ast.push_and_open(node!(STIL::Macro, unquote(p.next().unwrap().as_str()))),
);
pairs.push(p);
}
Expand Down
19 changes: 16 additions & 3 deletions rust/origen_metal/src/stil/stil.pest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ stil_source = { SOI ~ stil_source_items+ ~ EOI }
stil_source_items = _{
stil_version | header_block | env_block | signals_block | signal_groups_block |
timing_block | pattern_exec_block | pattern_burst_block | spec_block | selector_block |
scan_structures_block | pattern_block | include | dcapfilter_block | dcapsetup_block
scan_structures_block | pattern_block | include | dcapfilter_block | dcapsetup_block |
macrodefs_block
}

stil_version = { "STIL" ~ integer ~ "." ~ integer ~ (ext_block | EOS) }
Expand Down Expand Up @@ -223,7 +224,7 @@ inherit_waveform = { "InheritWaveform" ~ name ~ EOS }
wfc_definition = { wfc_list ~ "{" ~ inherit_waveform_wfc* ~ event* ~ "}" }
tagged_wfc_definition = { tag ~ wfc_list ~ "{" ~ inherit_waveform_wfc* ~ event* ~ "}" }
wfc_list = @{ wfc_char+ }
wfc_char = { ASCII_ALPHANUMERIC }
wfc_char = { ASCII_ALPHANUMERIC | "#" | "%" }
inherit_waveform_wfc = { "InheritWaveform" ~ name_wfc ~ EOS }
name_wfc = { ((name_segment ~ ".")+ ~ wfc_list) | wfc_list }
event = { label? ~ time_expr? ~ event_list? ~ EOS }
Expand Down Expand Up @@ -281,12 +282,13 @@ vector = { "V" ~ "ector"? ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}" }
vector_with_comment = ${ "V" ~ "ector"? ~ (space | N)* ~ "{" ~ ((space | N)* ~ (cyclized_data | non_cyclized_data))* ~ (space | N)* ~ "}" ~ vector_comment }
vector_comment = @{ space* ~ "//" ~ (!N ~ ANY)* ~ N }
cyclized_data = { (sigref_expr ~ "=" ~ vec_data+ ~ EOS) | (sigref_expr ~ "{" ~ (vec_data ~ EOS)+ ~ "}") }
vec_data = { repeat | waveform_format | hex_format | dec_format | data_string }
vec_data = { repeat | waveform_format | hex_format | dec_format | data_string | wfc_data_string }
repeat = @{ "\\r" ~ integer }
waveform_format = { "\\w" }
hex_format = @{ "\\h " | ("\\h" ~ data_string) }
dec_format = @{ "\\d " | ("\\d" ~ data_string) }
data_string = { ASCII_ALPHANUMERIC+ }
wfc_data_string = { wfc_char+ }
non_cyclized_data = { (time_value ~ sigref_expr ~ "=" ~ event_list ~ EOS) |
(time_value ~ "{" ~ (sigref_expr ~ "=" ~ event_list ~ EOS)+ ~ "}") }
time_value = @{ "@" ~ integer }
Expand Down Expand Up @@ -318,6 +320,17 @@ stop_statement = { "Stop" ~ EOS }

scan_chain_statement = { "ScanChain" ~ name ~ EOS }

//############################################################################
//# 24. Procedures and MacroDefs blocks
//############################################################################

procedures_block = { "Procedures" ~ name? ~ "{" ~ (procedures_def | include)* ~ "}" }
procedures_def = { name ~ "{" ~ procedure_or_macro_item* ~"}" }
macrodefs_block = { "MacroDefs" ~ name? ~ "{" ~ (macro_def | include)* ~ "}" }
macro_def = { name ~ "{" ~ procedure_or_macro_item* ~"}" }
procedure_or_macro_item = { shift_pat_stmt | pattern_statement }
shift_pat_stmt = { "Shift" ~ "{" ~ (label? ~ pattern_statement)* ~ "}" }

//############################################################################
//# Identifiers
//############################################################################
Expand Down
1 change: 1 addition & 0 deletions test_apps/python_app/vendor/stil/example4.stil
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Header {
Include "file_that_contains_signals.extension";
Include "file_that_contains_signal_groups.extension";
Include "file_that_contains_wavetable.extension";
Include "file_that_contains_macrodefs.extension";

PatternBurst "test_pattern_example_BURST" {
PatList { "test_pattern_example"; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
STIL 1.0;

MacroDefs {
"Scan_Macro_TEST0" {
WaveformTable WaveTable_Standard;
Shift {
Vector {
ScanData= #;
}
}
}
"Scan_Macro_TEST1" {
WaveformTable WaveTable_Standard;
Shift {
Vector {
ScanData= #;
}
}
}
"Scan_Macro_TEST2" {
WaveformTable WaveTable_Standard;
V { ScanData1= 010101; ScanData2= 010101;}
V { ScanData1= 101010; }
V { ScanData2= 101010; }
}
"Scan_Macro_TEST2" {
WaveformTable WaveTable_Standard;
Condition { ScanData1= HLHLHL; }
V { ScanData1= 010101; }
}
}

0 comments on commit 385a1df

Please sign in to comment.