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