diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/mono/pass/union-exist2 | 1 | ||||
| -rw-r--r-- | test/mono/union-exist2.sail | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/test/mono/pass/union-exist2 b/test/mono/pass/union-exist2 new file mode 100644 index 00000000..9852a125 --- /dev/null +++ b/test/mono/pass/union-exist2 @@ -0,0 +1 @@ +union-exist2.sail -auto_mono diff --git a/test/mono/union-exist2.sail b/test/mono/union-exist2.sail new file mode 100644 index 00000000..aede3c0d --- /dev/null +++ b/test/mono/union-exist2.sail @@ -0,0 +1,31 @@ +default Order dec +$include <prelude.sail> + +union myunion = { + MyConstr : {'n 'm 'o, 'n in {8,16} & 'o in {8,16} & 'n <= 'm & 'm <= 'o. (int('n),bits('n),int('o),bits('o),int('m))} +} + +val make : bits(2) -> myunion + +function make(v) = + let (n,v,m) : {'n 'm, 'n in {8,16} & 'm in {8,16} & 'n <= 'm. (int('n),bits('n),int('m))} = match v { + 0b00 => ( 8, 0x12, 8), + 0b01 => (16,0x1234,16), + 0b10 => ( 8, 0x56,16), + 0b11 => (16,0x5678,16) + } in + let w = sail_zero_extend(0x5,m) in + MyConstr(n,v,m,w,m) + +val use : myunion -> bits(32) + +function use(MyConstr(n,v,_,_,_)) = sail_zero_extend(v,32) + +val run : unit -> unit effect {escape} + +function run () = { + assert(use(make(0b00)) == 0x00000012); + assert(use(make(0b01)) == 0x00001234); + assert(use(make(0b10)) == 0x00000056); + assert(use(make(0b11)) == 0x00005678); +} |
