Skip to content

Commit 53e7531

Browse files
authored
Merge pull request #2286 from taichi-ishitani/restore
Restore
2 parents d1ef474 + a1c8257 commit 53e7531

File tree

5 files changed

+111
-6
lines changed

5 files changed

+111
-6
lines changed

crates/analyzer/src/conv/statement.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ impl Conv<&IdentifierStatement> for ir::StatementBlock {
277277
ir::Arguments::Null
278278
};
279279

280-
let symbol = symbol_table::resolve(value.expression_identifier.as_ref())
281-
.map_err(|_| ir_error!(token))?;
280+
let resolved_path =
281+
context.resolve_path(value.expression_identifier.as_ref().into());
282+
let symbol = symbol_table::resolve(&resolved_path).map_err(|_| ir_error!(token))?;
282283

283284
match &symbol.found.kind {
284285
SymbolKind::SystemFunction(_) => {

crates/analyzer/src/conv/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,8 @@ pub fn eval_function_call(
11061106
ir::Arguments::Null
11071107
};
11081108

1109-
let symbol = symbol_table::resolve(value.expression_identifier.as_ref())
1110-
.map_err(|_| ir_error!(token))?;
1109+
let resolved_path = context.resolve_path(value.expression_identifier.as_ref().into());
1110+
let symbol = symbol_table::resolve(&resolved_path).map_err(|_| ir_error!(token))?;
11111111

11121112
match &symbol.found.kind {
11131113
SymbolKind::SystemFunction(_) => {

crates/analyzer/src/ir/signature.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ impl Signature {
6666
}
6767
symbol.found
6868
}
69+
SymbolKind::ProtoFunction(_) => {
70+
let resolved = context.resolve_path(path.clone());
71+
let symbol = symbol_table::resolve(&resolved).ok()?;
72+
match &symbol.found.kind {
73+
SymbolKind::Function(_) => symbol.found,
74+
_ => return None,
75+
}
76+
}
6977
SymbolKind::ProtoAliasModule(x) => {
7078
let symbol = symbol_table::resolve(&x.target).ok()?;
7179
return Some(Signature::new(symbol.found.id));

crates/analyzer/src/ir/tests.rs

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ fn concat() {
18391839
o: output logic<16>,
18401840
o2: output logic<16>,
18411841
) {
1842-
assign o = {8'hff + 8'h1};
1842+
assign o = {8'hff + 8'h1};
18431843
assign o2 = {8'hf0, 8'hff + 8'h1};
18441844
}
18451845
"#;
@@ -1857,3 +1857,99 @@ fn concat() {
18571857
"#;
18581858
check_ir(code, exp);
18591859
}
1860+
1861+
#[test]
1862+
fn proto_function() {
1863+
let code = r#"
1864+
proto package Element {
1865+
type data;
1866+
function gt(a: input data, b: input data) -> logic;
1867+
}
1868+
package IntElement for Element {
1869+
type data = logic<8>;
1870+
function gt(a: input data, b: input data) -> logic {
1871+
return a >: b;
1872+
}
1873+
}
1874+
module ModuleA::<E: Element> (
1875+
a: input E::data,
1876+
b: input E::data,
1877+
r: output logic,
1878+
) {
1879+
always_comb {
1880+
r = E::gt(a, b);
1881+
}
1882+
}
1883+
module Top (
1884+
a: input logic<8>,
1885+
b: input logic<8>,
1886+
r: output logic,
1887+
) {
1888+
inst inner: ModuleA::<IntElement> (a, b, r);
1889+
}
1890+
"#;
1891+
let exp = r#"module ModuleA {
1892+
input var0(a): unknown = 1'hx;
1893+
input var1(b): unknown = 1'hx;
1894+
output var2(r): logic = 1'hx;
1895+
1896+
comb {
1897+
var2 = unknown;
1898+
}
1899+
}
1900+
module Top {
1901+
input var0(a): logic<8> = 8'hxx;
1902+
input var1(b): logic<8> = 8'hxx;
1903+
output var2(r): logic = 1'hx;
1904+
1905+
inst inner (
1906+
var0 <- var0;
1907+
var1 <- var1;
1908+
var2 -> var2;
1909+
) {
1910+
module ModuleA {
1911+
input var0(a): logic<8> = 8'hxx;
1912+
input var1(b): logic<8> = 8'hxx;
1913+
output var2(r): logic = 1'hx;
1914+
var var4(E.gt.return): logic = 1'hx;
1915+
input var5(E.gt.a): logic<8> = 8'hxx;
1916+
input var6(E.gt.b): logic<8> = 8'hxx;
1917+
func var3(E.gt) -> var4 {
1918+
var4 = (var5 >: var6);
1919+
}
1920+
1921+
comb {
1922+
var2 = var3(a: var0, b: var1);
1923+
}
1924+
}
1925+
}
1926+
}
1927+
"#;
1928+
check_ir(code, exp);
1929+
}
1930+
1931+
#[test]
1932+
fn binary_operation_with_large_width_variable() {
1933+
let code = r#"
1934+
module Top (
1935+
a: input logic<65>,
1936+
b: output logic ,
1937+
) {
1938+
always_comb {
1939+
b = a == '0;
1940+
}
1941+
}
1942+
"#;
1943+
1944+
let exp = r#"module Top {
1945+
input var0(a): logic<65> = 65'hxxxxxxxxxxxxxxxxx;
1946+
output var1(b): logic = 1'hx;
1947+
1948+
comb {
1949+
var1 = (var0 == '0);
1950+
}
1951+
}
1952+
"#;
1953+
1954+
check_ir(code, exp);
1955+
}

crates/analyzer/src/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl Value {
752752
}
753753

754754
pub fn expand(&self, width: usize, use_sign: bool) -> Cow<'_, Self> {
755-
if self.width() == 0 || self.width() >= width {
755+
if (self.width() == 0 && width <= 64) || self.width() >= width {
756756
Cow::Borrowed(self)
757757
} else if width > 64 {
758758
let ret = match self {

0 commit comments

Comments
 (0)