Fix randomize call
This commit is contained in:
parent
d2397393c1
commit
32cbf3a804
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.3.6...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.3.6...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Fixed] randomize_call bug
|
||||||
|
|
||||||
## [v0.3.6](https://github.com/dalance/sv-parser/compare/v0.3.5...v0.3.6) - 2019-11-05
|
## [v0.3.6](https://github.com/dalance/sv-parser/compare/v0.3.5...v0.3.6) - 2019-11-05
|
||||||
|
|
||||||
## [v0.3.5](https://github.com/dalance/sv-parser/compare/v0.3.4...v0.3.5) - 2019-11-05
|
## [v0.3.5](https://github.com/dalance/sv-parser/compare/v0.3.4...v0.3.5) - 2019-11-05
|
||||||
|
@ -181,12 +181,12 @@ pub(crate) fn method_call_body_user(s: Span) -> IResult<Span, MethodCallBody> {
|
|||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn built_in_method_call(s: Span) -> IResult<Span, BuiltInMethodCall> {
|
pub(crate) fn built_in_method_call(s: Span) -> IResult<Span, BuiltInMethodCall> {
|
||||||
alt((
|
alt((
|
||||||
map(array_manipulation_call, |x| {
|
|
||||||
BuiltInMethodCall::ArrayManipulationCall(Box::new(x))
|
|
||||||
}),
|
|
||||||
map(randomize_call, |x| {
|
map(randomize_call, |x| {
|
||||||
BuiltInMethodCall::RandomizeCall(Box::new(x))
|
BuiltInMethodCall::RandomizeCall(Box::new(x))
|
||||||
}),
|
}),
|
||||||
|
map(array_manipulation_call, |x| {
|
||||||
|
BuiltInMethodCall::ArrayManipulationCall(Box::new(x))
|
||||||
|
}),
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9716,44 +9716,40 @@ mod spec {
|
|||||||
endclass"##,
|
endclass"##,
|
||||||
Ok((_, _))
|
Ok((_, _))
|
||||||
);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"task exercise_bus (MyBus bus);
|
||||||
// many1(module_item),
|
int res;
|
||||||
// r##"task exercise_bus (MyBus bus);
|
|
||||||
// int res;
|
|
||||||
|
|
||||||
// // EXAMPLE 1: restrict to low addresses
|
// EXAMPLE 1: restrict to low addresses
|
||||||
// res = bus.randomize() with {atype == low;};
|
res = bus.randomize() with {atype == low;};
|
||||||
|
|
||||||
// // EXAMPLE 2: restrict to address between 10 and 20
|
// EXAMPLE 2: restrict to address between 10 and 20
|
||||||
// res = bus.randomize() with {10 <= addr && addr <= 20;};
|
res = bus.randomize() with {10 <= addr && addr <= 20;};
|
||||||
|
|
||||||
// // EXAMPLE 3: restrict data values to powers-of-two
|
// EXAMPLE 3: restrict data values to powers-of-two
|
||||||
// res = bus.randomize() with {(data & (data - 1)) == 0;};
|
res = bus.randomize() with {(data & (data - 1)) == 0;};
|
||||||
// endtask"##,
|
endtask"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"task exercise_illegal(MyBus bus, int cycles);
|
||||||
// many1(module_item),
|
int res;
|
||||||
// r##"task exercise_illegal(MyBus bus, int cycles);
|
|
||||||
// int res;
|
|
||||||
|
|
||||||
// // Disable word alignment constraint.
|
// Disable word alignment constraint.
|
||||||
// bus.word_align.constraint_mode(0);
|
bus.word_align.constraint_mode(0);
|
||||||
|
|
||||||
// repeat (cycles) begin
|
repeat (cycles) begin
|
||||||
// // CASE 1: restrict to small addresses.
|
// CASE 1: restrict to small addresses.
|
||||||
// res = bus.randomize() with {addr[0] || addr[1];};
|
res = bus.randomize() with {addr[0] || addr[1];};
|
||||||
// end
|
end
|
||||||
|
|
||||||
// // Reenable word alignment constraint
|
// Reenable word alignment constraint
|
||||||
// bus.word_align.constraint_mode(1);
|
bus.word_align.constraint_mode(1);
|
||||||
// endtask"##,
|
endtask"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
test!(
|
test!(
|
||||||
many1(module_item),
|
many1(module_item),
|
||||||
r##"class XYPair;
|
r##"class XYPair;
|
||||||
@ -9976,59 +9972,55 @@ mod spec {
|
|||||||
endclass"##,
|
endclass"##,
|
||||||
Ok((_, _))
|
Ok((_, _))
|
||||||
);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class Packet;
|
||||||
// many1(module_item),
|
rand bit mode;
|
||||||
// r##"class Packet;
|
rand int length;
|
||||||
// rand bit mode;
|
constraint deflt {
|
||||||
// rand int length;
|
soft length inside {32,1024};
|
||||||
// constraint deflt {
|
soft mode -> length == 1024;
|
||||||
// soft length inside {32,1024};
|
// Note: soft mode -> {length == 1024;} is not legal syntax,
|
||||||
// soft mode -> length == 1024;
|
// as soft must be followed by an expression
|
||||||
// // Note: soft mode -> {length == 1024;} is not legal syntax,
|
}
|
||||||
// // as soft must be followed by an expression
|
endclass
|
||||||
// }
|
|
||||||
// endclass
|
|
||||||
|
|
||||||
// initial begin
|
initial begin
|
||||||
// Packet p = new();
|
Packet p = new();
|
||||||
// p.randomize() with { length == 1512;} // mode will randomize to 0
|
p.randomize() with { length == 1512;}; // mode will randomize to 0
|
||||||
// p.randomize() with { length == 1512; mode == 1;} // mode will randomize to 1
|
p.randomize() with { length == 1512; mode == 1;}; // mode will randomize to 1
|
||||||
// end"##,
|
end"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class B1;
|
||||||
// many1(module_item),
|
rand int x;
|
||||||
// r##"class B1;
|
constraint a { soft x > 10 ; soft x < 100 ; }
|
||||||
// rand int x;
|
endclass /* a1 */ /* a2 */
|
||||||
// constraint a { soft x > 10 ; soft x < 100 ; }
|
class D1 extends B1;
|
||||||
// endclass /* a1 */ /* a2 */
|
constraint b { soft x inside {[5:9]} ; }
|
||||||
// class D1 extends B1;
|
endclass /* b1 */
|
||||||
// constraint b { soft x inside {[5:9]} ; }
|
class B2;
|
||||||
// endclass /* b1 */
|
rand int y;
|
||||||
// class B2;
|
constraint c { soft y > 10 ; }
|
||||||
// rand int y;
|
endclass /* c1 */
|
||||||
// constraint c { soft y > 10 ; }
|
class D2 extends B2;
|
||||||
// endclass /* c1 */
|
constraint d { soft y inside {[5:9]} ; }
|
||||||
// class D2 extends B2;
|
constraint e ; /* d1 */
|
||||||
// constraint d { soft y inside {[5:9]} ; }
|
rand D1 p1;
|
||||||
// constraint e ; /* d1 */
|
rand B1 p2;
|
||||||
// rand D1 p1;
|
rand D1 p3;
|
||||||
// rand B1 p2;
|
constraint f { soft p1.x < p2.x ; }
|
||||||
// rand D1 p3;
|
endclass /* f1 */
|
||||||
// constraint f { soft p1.x < p2.x ; }
|
constraint D2::e { soft y > 100 ; }
|
||||||
// endclass /* f1 */
|
/* e1 */
|
||||||
// constraint D2::e { soft y > 100 ; }
|
D2 d = new();
|
||||||
// /* e1 */
|
initial begin
|
||||||
// D2 d = new();
|
d.randomize() with { soft y inside {10,20,30} ; soft y < p1.x ; };
|
||||||
// initial begin
|
end /* i1 */ /* i2 */"##,
|
||||||
// d.randomize() with { soft y inside {10,20,30} ; soft y < p1.x ; };
|
Ok((_, _))
|
||||||
// end /* i1 */ /* i2 */"##,
|
);
|
||||||
// Ok((_, _))
|
|
||||||
//);
|
|
||||||
test!(
|
test!(
|
||||||
many1(module_item),
|
many1(module_item),
|
||||||
r##"class A;
|
r##"class A;
|
||||||
@ -10080,66 +10072,58 @@ mod spec {
|
|||||||
endclass"##,
|
endclass"##,
|
||||||
Ok((_, _))
|
Ok((_, _))
|
||||||
);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class SimpleSum;
|
||||||
// many1(module_item),
|
rand bit [7:0] x, y, z;
|
||||||
// r##"class SimpleSum;
|
constraint c {z == x + y;}
|
||||||
// rand bit [7:0] x, y, z;
|
endclass
|
||||||
// constraint c {z == x + y;}
|
|
||||||
// endclass
|
|
||||||
|
|
||||||
// task InlineConstraintDemo(SimpleSum p);
|
task InlineConstraintDemo(SimpleSum p);
|
||||||
// int success;
|
int success;
|
||||||
// success = p.randomize() with {x < y;};
|
success = p.randomize() with {x < y;};
|
||||||
// endtask"##,
|
endtask"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class C1;
|
||||||
// many1(module_item),
|
rand integer x;
|
||||||
// r##"class C1;
|
endclass
|
||||||
// rand integer x;
|
|
||||||
// endclass
|
|
||||||
|
|
||||||
// class C2;
|
class C2;
|
||||||
// integer x;
|
integer x;
|
||||||
// integer y;
|
integer y;
|
||||||
|
|
||||||
// task doit(C1 f, integer x, integer z);
|
task doit(C1 f, integer x, integer z);
|
||||||
// int result;
|
int result;
|
||||||
// result = f.randomize() with {x < y + z;};
|
result = f.randomize() with {x < y + z;};
|
||||||
// endtask
|
endtask
|
||||||
// endclass"##,
|
endclass"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class C;
|
||||||
// many1(module_item),
|
rand integer x;
|
||||||
// r##"class C;
|
endclass
|
||||||
// rand integer x;
|
|
||||||
// endclass
|
|
||||||
|
|
||||||
// function int F(C obj, integer y);
|
function int F(C obj, integer y);
|
||||||
// F = obj.randomize() with (x) { x < y; };
|
F = obj.randomize() with (x) { x < y; };
|
||||||
// endfunction"##,
|
endfunction"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
// TODO
|
test!(
|
||||||
// randomize is not keyword
|
many1(module_item),
|
||||||
//test!(
|
r##"class C;
|
||||||
// many1(module_item),
|
rand integer x;
|
||||||
// r##"class C;
|
endclass
|
||||||
// rand integer x;
|
|
||||||
// endclass
|
|
||||||
|
|
||||||
// function int F(C obj, integer x);
|
function int F(C obj, integer x);
|
||||||
// F = obj.randomize() with { x < local::x; };
|
F = obj.randomize() with { x < local::x; };
|
||||||
// endfunction"##,
|
endfunction"##,
|
||||||
// Ok((_, _))
|
Ok((_, _))
|
||||||
//);
|
);
|
||||||
test!(
|
test!(
|
||||||
many1(module_item),
|
many1(module_item),
|
||||||
r##"class Packet;
|
r##"class Packet;
|
||||||
@ -15835,6 +15819,10 @@ mod spec {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debug() {
|
fn debug() {
|
||||||
test!(source_text, r##"module top (); endmodule"##, Ok((_, _)));
|
test!(
|
||||||
|
source_text,
|
||||||
|
r##"module top (); initial begin p.randomize() with { length == 1512;}; end endmodule"##,
|
||||||
|
Ok((_, _))
|
||||||
|
);
|
||||||
nom_tracable::cumulative_histogram();
|
nom_tracable::cumulative_histogram();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user