diff --git a/src/cst/expression.rs b/src/cst/expression.rs index 10b8708..083144b 100644 --- a/src/cst/expression.rs +++ b/src/cst/expression.rs @@ -58,14 +58,14 @@ impl Expression { Tag::REFERENCE, Tag::LOCAL_ROOT, Tag::UNQUALIFIED_ID, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], ]; let json_symbol_identifier: Vec<_> = json_symbol_identifier_path - .iter() - .flat_map(|x|Tools::match_tags(vec![json], x.to_vec())) - .collect(); + .iter() + .flat_map(|x| Tools::match_tags(vec![json], x.to_vec())) + .collect(); assert_eq!(json_symbol_identifier.len(), 1); let json_scalar = Tools::match_tags( @@ -137,9 +137,7 @@ impl Expression { None => builder.ins().prb(symbol_value), Some(s) => builder.ins().ld(s), } - } - else if context.symbol.contains_key(&symbol) - { + } else if context.symbol.contains_key(&symbol) { let symbol_info = &context.symbol[&symbol]; assert_eq!(symbol_info.kind, SymbolKind::Param); builder.ins().const_int(symbol_info.value.clone()) @@ -197,6 +195,11 @@ impl Expression { let value = builder.ins().sub(opd_l, opd_r); Some(value) } + Some(Tag::MUL) => { + warn!("FIXME: signed multiplication not supported"); + let value = builder.ins().umul(opd_l, opd_r); + Some(value) + } Some(Tag::BITWISE_AND) => { let value = builder.ins().and(opd_l, opd_r); Some(value) @@ -235,6 +238,10 @@ impl Expression { let value = builder.ins().eq(opd_l, opd_r); Some(value) } + Some(Tag::NOT_EQUAL) => { + let value = builder.ins().neq(opd_l, opd_r); + Some(value) + } Some(Tag::LESS_THAN_OR_EQUAL_TO) => { let value = builder.ins().sle(opd_l, opd_r); Some(value) @@ -243,6 +250,14 @@ impl Expression { let value = builder.ins().sge(opd_l, opd_r); Some(value) } + Some(Tag::LESS_THAN) => { + let value = builder.ins().slt(opd_l, opd_r); + Some(value) + } + Some(Tag::GREATER_THAN) => { + let value = builder.ins().sgt(opd_l, opd_r); + Some(value) + } Some(tag) => { error!("FIXME: case '{}' missing", tag); None diff --git a/src/cst/net_variable_assignment.rs b/src/cst/net_variable_assignment.rs index 1b801a5..7fb7f15 100644 --- a/src/cst/net_variable_assignment.rs +++ b/src/cst/net_variable_assignment.rs @@ -52,14 +52,14 @@ impl NetVariableAssignment { Tag::REFERENCE, Tag::LOCAL_ROOT, Tag::UNQUALIFIED_ID, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], - ]; - + ]; + let json_symbol_identifier: Vec<_> = lpvalue_paths - .iter() - .flat_map(|x|Tools::match_tags(vec![&json_children[0]], x.to_vec())) - .collect(); + .iter() + .flat_map(|x| Tools::match_tags(vec![&json_children[0]], x.to_vec())) + .collect(); // let json_symbol_identifier = Tools::match_tags( // vec![&json_children[0]], // vec![ @@ -117,16 +117,15 @@ impl NetVariableAssignment { builder.append_to(bb_head); let delta_time = builder.ins().const_time(TimeValue::new(num::zero(), 1, 0)); - if let Some(opt) = opt_expr { + if let Some(opt) = opt_expr { if unit_ctx.raw_name_to_value.contains_key(lvalue_name) { - let inst = builder.ins().drv( - unit_ctx.raw_name_to_value[lvalue_name], - opt, - delta_time, - ); - context.syntax_table.insert_inst(builder.unit(), inst, json); - } - } + let inst = + builder + .ins() + .drv(unit_ctx.raw_name_to_value[lvalue_name], opt, delta_time); + context.syntax_table.insert_inst(builder.unit(), inst, json); + } + } //context.syntax_table.insert_inst(builder.unit(), inst, json); if unit_ctx.raw_name_to_shadow.contains_key(lvalue_name) { warn!("TODO: double check"); diff --git a/src/cst/symbol_declaration.rs b/src/cst/symbol_declaration.rs index 0b99037..231cbc2 100644 --- a/src/cst/symbol_declaration.rs +++ b/src/cst/symbol_declaration.rs @@ -9,8 +9,8 @@ use std::collections::HashMap; #[allow(unused_imports)] use log::{debug, error, info, trace, warn}; -pub struct SymbolDeclaration { -//#[derive(Copy, Clone)] +pub struct SymbolDeclaration { + //#[derive(Copy, Clone)] } impl<'a> SymbolDeclaration { @@ -95,25 +95,25 @@ impl<'a> SymbolDeclaration { Tag::IDENTIFIER_LIST, Tag::IDENTIFIER_UNPACKED_DIMENSIONS, Tag::UNQUALIFIED_ID, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], vec![ Tag::MODULE_PORT_DECLARATION, Tag::IDENTIFIER_LIST, Tag::IDENTIFIER_UNPACKED_DIMENSIONS, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], vec![ Tag::MODULE_PORT_DECLARATION, Tag::IDENTIFIER_UNPACKED_DIMENSIONS_LIST, Tag::IDENTIFIER_UNPACKED_DIMENSIONS, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], vec![ Tag::MODULE_PORT_DECLARATION, Tag::PORT_IDENTIFIER_LIST, Tag::PORT_IDENTIFIER, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ], ]; @@ -155,28 +155,27 @@ impl<'a> SymbolDeclaration { fn gen_port_info_2005(json_io_ports: &mut Vec<&'a JsonValue>) -> Vec<(String, SymbolInfo<'a>)> { let name_path = [ vec![ - Tag::PORT_DECLARATION, - Tag::UNQUALIFIED_ID, - Tag::SYMBOL_IDENTIFIER, - ], + Tag::PORT_DECLARATION, + Tag::UNQUALIFIED_ID, + Tag::SYMBOL_IDENTIFIER, + ], vec![ - Tag::PORT, - Tag::PORT_REFERENCE, - Tag::UNQUALIFIED_ID, - Tag::SYMBOL_IDENTIFIER, - ], - vec![ - Tag::PORT_DECLARATION, - Tag::UNQUALIFIED_ID, - Tag::ESCAPEDIDENTIFIER, - ], + Tag::PORT, + Tag::PORT_REFERENCE, + Tag::UNQUALIFIED_ID, + Tag::SYMBOL_IDENTIFIER, + ], vec![ - Tag::PORT, - Tag::PORT_REFERENCE, - Tag::UNQUALIFIED_ID, - Tag::ESCAPEDIDENTIFIER, - ], - + Tag::PORT_DECLARATION, + Tag::UNQUALIFIED_ID, + Tag::ESCAPED_IDENTIFIER, + ], + vec![ + Tag::PORT, + Tag::PORT_REFERENCE, + Tag::UNQUALIFIED_ID, + Tag::ESCAPED_IDENTIFIER, + ], ]; let dim_path = [ @@ -191,21 +190,14 @@ impl<'a> SymbolDeclaration { ]; let io_paths = [ - vec![ - Tag::PORT_DECLARATION_LIST, - Tag::PORT_DECLARATION, - ], - vec![ - Tag::PORT_DECLARATION_LIST, - Tag::PORT, - ], + vec![Tag::PORT_DECLARATION_LIST, Tag::PORT_DECLARATION], + vec![Tag::PORT_DECLARATION_LIST, Tag::PORT], ]; let json_io_declarations: Vec<_> = io_paths - .iter() - .flat_map(|x|Tools::match_tags(json_io_ports.to_vec(), x.to_vec())) - .collect(); - + .iter() + .flat_map(|x| Tools::match_tags(json_io_ports.to_vec(), x.to_vec())) + .collect(); json_io_declarations .iter() @@ -218,11 +210,21 @@ impl<'a> SymbolDeclaration { Some(Tag::PORT_REFERENCE) => { let mut kindkind = SymbolKind::Inout; let mut i = 0; - while i < (json_io_declarations.len()-1) { - if ((&json_io_declarations[i+1])["children"][0]["tag"].as_str() == Some(Tag::PORT_REFERENCE)) && ((&json_io_declarations[i])["children"][0]["tag"].as_str() == Some(Tag::INPUT) || (&json_io_declarations[i])["children"][0]["tag"].as_str() == Some(Tag::OUTPUT)) { - if (&json_io_declarations[i])["children"][0]["tag"].as_str() == Some(Tag::INPUT) { - kindkind = SymbolKind::Input; - } else if (&json_io_declarations[i])["children"][0]["tag"].as_str() == Some(Tag::OUTPUT) { + while i < (json_io_declarations.len() - 1) { + if ((&json_io_declarations[i + 1])["children"][0]["tag"].as_str() + == Some(Tag::PORT_REFERENCE)) + && ((&json_io_declarations[i])["children"][0]["tag"].as_str() + == Some(Tag::INPUT) + || (&json_io_declarations[i])["children"][0]["tag"].as_str() + == Some(Tag::OUTPUT)) + { + if (&json_io_declarations[i])["children"][0]["tag"].as_str() + == Some(Tag::INPUT) + { + kindkind = SymbolKind::Input; + } else if (&json_io_declarations[i])["children"][0]["tag"].as_str() + == Some(Tag::OUTPUT) + { kindkind = SymbolKind::Output; } } @@ -234,9 +236,9 @@ impl<'a> SymbolDeclaration { }; let width = Self::gen_var_width(json_port, dim_path.to_vec()); let json_port_names: Vec<_> = name_path - .iter() - .flat_map(|x|Tools::match_tags(vec![json_port], x.to_vec())) - .collect(); + .iter() + .flat_map(|x| Tools::match_tags(vec![json_port], x.to_vec())) + .collect(); assert!(json_port_names.len() > 0); json_port_names @@ -353,7 +355,7 @@ impl<'a> SymbolDeclaration { Tag::NET_DECLARATION, Tag::NET_VARIABLE_DECLARATION_ASSIGN, Tag::NET_VARIABLE, - Tag::ESCAPEDIDENTIFIER, + Tag::ESCAPED_IDENTIFIER, ]; let dim_path = [ @@ -397,24 +399,24 @@ impl<'a> SymbolDeclaration { let width = Self::gen_var_width(json, dim_path.to_vec()); if json_names.len() != 0 { - for json_name in json_names { - if json_name.len() != 0 { - let name = &json_name["text"].to_string(); - let symbol = SymbolInfo::new(kind, IntValue::zero(width), json_name); - if !context.symbol.contains_key(name) { - context.symbol.insert(name.clone(), symbol); - } else { - info!("{} '{}' has been declared", kind, name); + for json_name in json_names { + if json_name.len() != 0 { + let name = &json_name["text"].to_string(); + let symbol = SymbolInfo::new(kind, IntValue::zero(width), json_name); + if !context.symbol.contains_key(name) { + context.symbol.insert(name.clone(), symbol); + } else { + info!("{} '{}' has been declared", kind, name); + } + } } } - } - } } } fn gen_var_width(json: &JsonValue, dim_path: Vec<&str>) -> usize { let json_dims = Tools::match_tags(vec![json], dim_path); - assert!(json_dims.len() == 0 || json_dims.len() == 1 ||json_dims.len() == 2); + assert!(json_dims.len() == 0 || json_dims.len() == 1 || json_dims.len() == 2); match json_dims.len() { 2 => { diff --git a/src/cst/tags.rs b/src/cst/tags.rs index cc63636..2af7294 100644 --- a/src/cst/tags.rs +++ b/src/cst/tags.rs @@ -117,6 +117,7 @@ impl Tag { pub const ADD: &'static str = "+"; pub const SUB: &'static str = "-"; + pub const MUL: &'static str = "*"; pub const BITWISE_AND: &'static str = "&"; pub const BITWISE_OR: &'static str = "|"; pub const BITWISE_XOR: &'static str = "^"; @@ -125,17 +126,19 @@ impl Tag { pub const LOGICAL_AND: &'static str = "&&"; pub const LOGICAL_OR: &'static str = "||"; pub const EQUAL: &'static str = "=="; + pub const NOT_EQUAL: &'static str = "!="; pub const LESS_THAN_OR_EQUAL_TO: &'static str = "<="; pub const GREATER_THAN_OR_EQUAL_TO: &'static str = ">="; + pub const LESS_THAN: &'static str = "<"; + pub const GREATER_THAN: &'static str = ">"; pub const LOGICAL_NOT: &'static str = "!"; pub const BITWISE_NOT: &'static str = "~"; pub const XOR_REDUCE: &'static str = "^"; pub const BRACEGROUP: &'static str = "kBraceGroup"; - pub const ESCAPEDIDENTIFIER: &'static str = "EscapedIdentifier"; + pub const ESCAPED_IDENTIFIER: &'static str = "EscapedIdentifier"; pub const GATEINSTANTIAN: &'static str = "kGateInstantiation"; pub const PRIMITIVE_GATE_LIST: &'static str = "kPrimitiveGateInstanceList"; pub const PRIMITIVE_GATE: &'static str = "kPrimitiveGateInstance"; - }