1/* 2 * Some or all of this work - Copyright (c) 2006 - 2016, Intel Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * Neither the name of Intel Corporation nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* 30 * Data type conversion and manipulation 31 * 32 * Extract Portion of Buffer or String 33 */ 34 35Name(z039, 39) 36 37Name(s200, "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*") 38 39// Verifying 3-parameters, 1-result operator 40Method(m304, 6, Serialized) 41{ 42 Store(0, Local5) 43 Store(arg1, Local3) 44 45 While(Local3) { 46 47 // Operands 48 49 Multiply(Local5, 3, Local6) 50 Store(DeRefOf(Index(arg3, Local6)), Local0) 51 Increment(Local6) 52 Store(DeRefOf(Index(arg3, Local6)), Local1) 53 Increment(Local6) 54 Store(DeRefOf(Index(arg3, Local6)), Local4) 55 56 // Expected result 57 58 Store(DeRefOf(Index(arg4, Local5)), Local2) 59 60 switch (ToInteger (arg5)) { 61 case (0) { 62 Mid(Local0, Local1, Local4, Local7) 63 if (LNotEqual(Local7, Local2)) { 64 err(arg0, z039, 0, 0, 0, Local5, arg2) 65 } 66 } 67 case (1) { 68 Mid(s200, Local1, Local4, Local7) 69 if (LNotEqual(Local7, Local2)) { 70 err(arg0, z039, 1, 0, 0, Local5, arg2) 71 } 72 } 73 } 74 Increment(Local5) 75 Decrement(Local3) 76 } 77} 78 79// String 80Name(p362, Package() 81{ 82 // Length > 0 83 84 "0123456789a", 85 0, 6, // Index == 0, Index + Length < Size 86 "0123456789a", 87 3, 7, // Index < Size, Index + Length < Size 88 "0123456789a", 89 5, 6, // Index < Size, Index + Length == Size 90 "0123456789a", 91 0, 11, // Index == 0, Index + Length == Size 92 "0123456789a", 93 8, 8, // Index < Size, Index + Length > Size 94 "0123456789a", 95 11, 3, // Index == Size 96 "0123456789a", 97 14, 1, // Index > Size 98 "0123456789a", 99 0, 14, // Index == 0, Length > Size 100 101 // Length == 0 102 103 "0123456789a", 104 0, 0, // Index == 0 105 "0123456789a", 106 5, 0, // Index < Size 107 "0123456789a", 108 11, 0, // Index == Size 109 "0123456789a", 110 15, 0, // Index > Size 111 112 // Size == 0 113 "", 114 0, 1, 115 "", 116 300, 300, 117}) 118 119Name(p363, Package() 120{ 121 "012345", 122 "3456789", 123 "56789a", 124 "0123456789a", 125 "89a", 126 "", 127 "", 128 "0123456789a", 129 "", 130 "", 131 "", 132 "", 133 "", 134 "", 135}) 136 137// String, Size == 200, Length > 0 138Name(p364, Package() 139{ 140 0, 141 0, 125, // Index == 0, Index + Length < Size 142 0, 143 67, 67, // Index < Size, Index + Length < Size 144 0, 145 93, 107, // Index < Size, Index + Length == Size 146 0, 147 0, 200, // Index == 0, Index + Length == Size 148 0, 149 127, 100, // Index < Size, Index + Length > Size 150 0, 151 200, 3, // Index == Size 152 0, 153 214, 1, // Index > Size 154 0, 155 0, 201, // Index == 0, Length > Size 156}) 157 158Name(p365, Package() 159{ 160 "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>", 161 "defghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFG", 162 "~ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*", 163 "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*", 164 "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*", 165 "", 166 "", 167 "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*", 168}) 169 170// Buffer 171Name(p366, Package() 172{ 173 // Length > 0 174 175 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 176 0, 6, // Index == 0, Index + Length < Size 177 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 178 3, 7, // Index < Size, Index + Length < Size 179 Buffer(11) {0, 1, 2, 3, 4, 5, 0, 7, 8, 9, 0}, 180 3, 7, // Index < Size, Index + Length < Size 181 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 182 5, 6, // Index < Size, Index + Length == Size 183 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 184 0, 11, // Index == 0, Index + Length == Size 185 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 186 8, 8, // Index < Size, Index + Length > Size 187 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 188 0, 201, // Index == 0, Length > Size 189 190 // Length > 200 191 Buffer(211) { 192 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 193 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 194 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 195 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 196 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 197 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 198 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 199 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112, 200 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, 201 129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144, 202 145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160, 203 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176, 204 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, 205 193,194,195,196,197,198,199,200}, 206 2, 203, 207}) 208 209Name(p367, Package() 210{ 211 Buffer(6) {0, 1, 2, 3, 4, 5}, 212 Buffer(7) {3, 4, 5, 6, 7, 8, 9}, 213 Buffer(7) {3, 4, 5, 0, 7, 8, 9}, 214 Buffer(6) {5, 6, 7, 8, 9, 0}, 215 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 216 Buffer(3) {8, 9, 0}, 217 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 218 Buffer(203) { 219 3, 4, 5, 6, 7, 8, 9, 0, 0, 220 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 221 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 222 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 223 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 224 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 225 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 226 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112, 227 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, 228 129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144, 229 145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160, 230 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176, 231 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, 232 193,194}, 233}) 234 235// Buffer, Mid() results in Buffer(0){} 236Name(p368, Package() 237{ 238 // Length > 0 239 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 240 11, 3, // Index == Size 241 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 242 14, 1, // Index > Size 243 244 // Length == 0 245 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 246 0, 0, // Index == 0 247 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 0, 8, 9, 0}, 248 5, 0, // Index < Size 249 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 250 11, 0, // Index == Size 251 Buffer(11) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 252 15, 0, // Index > Size 253}) 254 255// Run-method 256Method(MID0,, Serialized) 257{ 258 Name(ts, "MID0") 259 260 Store("TEST: MID0, Extract Portion of Buffer or String", Debug) 261 262 // String 263 m304(ts, 14, "p362", p362, p363, 0) 264 265 // String, Size == 200, Length > 0 266 m304(ts, 8, "p364", p364, p365, 1) 267 268 // Buffer 269 m304(ts, 8, "p366", p366, p367, 0) 270 271 // Prepare Package of Buffer(0){} elements 272 Store(Package(6){}, Local5) 273 Store(0, Local1) 274 Store(0, Local0) 275 While(LLess(Local0, 6)) { 276 Store(Buffer(Local1) {}, Index(Local5, Local0)) 277 Increment(Local0) 278 } 279 280 // Buffer, Mid() results in Buffer(0){} 281 m304(ts, 6, "p366", p368, Local5, 0) 282 283 // Buffer, Mid(Buffer(0){}) 284 Mid(Buffer(Local1) {}, 0, 1, Local7) 285 if (LNotEqual(Local7, Buffer(Local1) {})) { 286 err(ts, z039, 2, 0, 0, 0, "Buffer(0)") 287 } 288 Mid(Buffer(Local1) {}, 300, 300, Local7) 289 if (LNotEqual(Local7, Buffer(Local1) {})) { 290 err(ts, z039, 3, 0, 0, 0, "Buffer(0)") 291 } 292} 293