Skip to content

Commit

Permalink
Merge pull request #209 from Origen-SDK/stil_updates
Browse files Browse the repository at this point in the history
STIL - ignore include statements, in-line loop comments
  • Loading branch information
rlaj authored Oct 7, 2024
2 parents 4f8ae75 + 4cadf35 commit f0951a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions rust/origen_metal/src/stil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pub fn from_file(path: &Path) -> OrigenResult<Node<STIL>> {
Ok(ast)
}

pub fn from_file_ignore_includes(path: &Path) -> OrigenResult<Node<STIL>> {
let ast = parser::parse_file(path)?;
Ok(ast)
}

/// Parse the given STIL file, using the given load path to resolve any include statements
/// that are encountered.
/// Include files can optionally be renamed using the `rename` argument, which
Expand Down
8 changes: 7 additions & 1 deletion rust/origen_metal/src/stil/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,20 @@ pub fn to_ast(mut pair: Pair<Rule>, source_file: Option<&str>) -> Result<AST<STI
);
pairs.push(p);
}
Rule::loop_statement => {
Rule::loop_statement | Rule::loop_statement_with_comment => {
let mut p = pair.into_inner();
ids.push(ast.push_and_open(node!(
STIL::Loop,
p.next().unwrap().as_str().parse().unwrap()
)));
pairs.push(p);
}
Rule::loop_comment => {
let cmt = pair.as_str().to_string();
let cmt = cmt.trim();
let cmt = cmt.replace("\n", "");
ast.push(node!(STIL::Comment, cmt))
}
Rule::match_loop => {
let mut p = pair.into_inner();
let timeout = p.next().unwrap();
Expand Down
6 changes: 4 additions & 2 deletions rust/origen_metal/src/stil/stil.pest
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ scan_inversion_val = { ("0" | "1") }
pattern_block = { "Pattern" ~ name ~ "{" ~ (label? ~ time_unit)? ~ pattern_statement* ~ "}" }
label = { (string | name) ~ ":" }
time_unit = { "TimeUnit" ~ time_expr ~ EOS }
pattern_statement = { label | vector_with_comment | vector | waveform_statement | condition | call | macro_statement | loop_statement |
match_loop | goto | breakpoint | iddq | stop_statement | scan_chain_statement | annotation }
pattern_statement = !{ label | vector_with_comment | vector | waveform_statement | condition | call | macro_statement |loop_statement_with_comment |
loop_statement | match_loop | goto | breakpoint | iddq | stop_statement | scan_chain_statement | annotation }

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 }
Expand All @@ -302,6 +302,8 @@ call = { ("Call" ~ name ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}") | ("
macro_statement = { ("Macro" ~ name ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}") | ("Macro" ~ name ~ EOS) }

loop_statement = { "Loop" ~ integer ~ "{" ~ pattern_statement* ~ "}" }
loop_statement_with_comment = ${ "Loop" ~ (space | N)* ~ integer ~ (space | N)* ~ "{" ~ ((space | N)* ~ pattern_statement)* ~ (space | N)* ~ "}" ~ loop_comment }
loop_comment = @{ space* ~ "//" ~ (!N ~ ANY)* ~ N }

match_loop = { "MatchLoop" ~ (integer | infinite) ~ "{" ~ pattern_statement+ ~ "}" }
infinite = { "Infinite" }
Expand Down

0 comments on commit f0951a5

Please sign in to comment.