diff options
author | Juan Antonio Cano <jacanosalado@gmail.com> | 2017-10-23 23:17:08 +0300 |
---|---|---|
committer | Morgan Brown <morganbr@users.noreply.github.com> | 2017-10-23 23:17:08 +0300 |
commit | 5aed5155ac93f3af8cb0532828ae1c700a47f8e8 (patch) | |
tree | 17681aa5c987e5f908133ea3f7b153e300c4d499 /tests | |
parent | a9c7630c8a6c04765856cc05636f90bcffead652 (diff) |
Emit switch in wasm (#4769)
* Implement switch opcode Fix #4519
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/Simple/HelloWasm/Program.cs | 85 |
1 files changed, 58 insertions, 27 deletions
diff --git a/tests/src/Simple/HelloWasm/Program.cs b/tests/src/Simple/HelloWasm/Program.cs index fc5e7ea2b..453a8555e 100644 --- a/tests/src/Simple/HelloWasm/Program.cs +++ b/tests/src/Simple/HelloWasm/Program.cs @@ -11,66 +11,74 @@ internal static class Program private static unsafe void Main(string[] args) { Add(1, 2); - + int tempInt = 0; (*(&tempInt)) = 9; - + + if(tempInt == 9) + { + PrintLine("Hello from C#!"); + } + TwoByteStr str = new TwoByteStr() { first = 1, second = 2 }; - TwoByteStr str2 = new TwoByteStr() { first = 3, second = 4 }; ; - *(&str) = str2; - str2 = *(&str); + TwoByteStr str2 = new TwoByteStr() { first = 3, second = 4 }; - if (tempInt == 9) + if (str2.second == 4) { - string s = "Hello from C#!"; - PrintString(s); + PrintLine("value type int field test: Ok."); } - + staticInt = 5; if (staticInt == 5) { - PrintString("\n"); - PrintString("static int field test: Ok."); - } - - if (str.second == 4) - { - PrintString("\n"); - PrintString("value type int field test: Ok."); + PrintLine("static int field test: Ok."); } var not = Not(0xFFFFFFFF) == 0x00000000; if (not) { - PrintString("\n"); - PrintString("not test: Ok."); + PrintLine("not test: Ok."); } var negInt = Neg(42) == -42; if (negInt) { - PrintString("\n"); - PrintString("negInt test: Ok."); + PrintLine("negInt test: Ok."); } var shiftLeft = ShiftLeft(1, 2) == 4; if (shiftLeft) { - PrintString("\n"); - PrintString("shiftLeft test: Ok."); + PrintLine("shiftLeft test: Ok."); } var shiftRight = ShiftRight(4, 2) == 1; if (shiftRight) { - PrintString("\n"); - PrintString("shiftRight test: Ok."); + PrintLine("shiftRight test: Ok."); } var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu; if (unsignedShift) { - PrintString("\n"); - PrintString("unsignedShift test: Ok."); + PrintLine("unsignedShift test: Ok."); + } + + var switchTest0 = SwitchOp(5, 5, 0); + if (switchTest0 == 10) + { + PrintLine("SwitchOp0 test: Ok."); + } + + var switchTest1 = SwitchOp(5, 5, 1); + if (switchTest1 == 25) + { + PrintLine("SwitchOp1 test: Ok."); + } + + var switchTestDefault = SwitchOp(5, 5, 20); + if (switchTestDefault == 0) + { + PrintLine("SwitchOpDefault test: Ok."); } } @@ -87,6 +95,12 @@ internal static class Program } } } + + private static void PrintLine(string s) + { + PrintString(s); + PrintString("\n"); + } private static int Add(int a, int b) { @@ -117,6 +131,23 @@ internal static class Program { return a >> b; } + + private static int SwitchOp(int a, int b, int mode) + { + switch(mode) + { + case 0: + return a + b; + case 1: + return a * b; + case 2: + return a / b; + case 3: + return a - b; + default: + return 0; + } + } [DllImport("*")] private static unsafe extern int printf(byte* str, byte* unused); |