1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15[$default byte_order: "LittleEndian"] 16[(cpp) namespace: "emboss::test"] 17 18 19struct BasicConditional: 20 0 [+1] UInt x 21 if x == 0: 22 1 [+1] UInt xc 23 24 25struct NegativeConditional: 26 0 [+1] UInt x 27 if x != 0: 28 1 [+1] UInt xc 29 30 31struct ConditionalAndUnconditionalOverlappingFinalField: 32 0 [+1] UInt x 33 if x == 0: 34 1 [+1] UInt xc 35 36 1 [+1] UInt z 37 38 39struct ConditionalBasicConditionalFieldFirst: 40 if x == 0: 41 0 [+1] UInt xc 42 43 1 [+1] UInt x 44 45 46struct ConditionalAndDynamicLocation: 47 0 [+1] UInt x 48 2 [+1] UInt y 49 if x == 0: 50 y [+1] UInt xc 51 52 53struct ConditionUsesMinInt: 54 0 [+1] Int x 55 if x - 0x7fff_ffff_ffff_ff80 == -0x8000_0000_0000_0000: 56 1 [+1] UInt xc 57 58 59struct NestedConditional: 60 0 [+1] UInt x 61 if x == 0: 62 1 [+1] UInt xc 63 64 if xc == 0: 65 2 [+1] UInt xcc 66 67 68struct CorrectNestedConditional: 69 0 [+1] UInt x 70 if x == 0: 71 1 [+1] UInt xc 72 73 if x == 0 && xc == 0: 74 2 [+1] UInt xcc 75 76 77struct AlwaysFalseCondition: 78 0 [+1] UInt x 79 if false: 80 1 [+1] UInt xc 81 82 83struct OnlyAlwaysFalseCondition: 84 if false: 85 0 [+1] UInt xc 86 87 88struct EmptyStruct: 89 -- Empty structure. 90 91 92struct AlwaysFalseConditionDynamicSize: 93 0 [+1] UInt x 94 x [+1] UInt y 95 if false: 96 1 [+1] UInt xc 97 98 99struct ConditionDoesNotContributeToSize: 100 0 [+1] UInt x 101 if x == 0: 102 1 [+1] UInt xc 103 2 [+1] UInt y 104 105 106enum OnOff: 107 OFF = 0 108 ON = 1 109 110 111struct EnumCondition: 112 0 [+1] OnOff x 113 if x == OnOff.ON: 114 1 [+1] UInt xc 115 if x > OnOff.OFF: 116 1 [+1] UInt xc2 117 118 119struct NegativeEnumCondition: 120 0 [+1] OnOff x 121 if x != OnOff.ON: 122 1 [+1] UInt xc 123 124 125struct LessThanCondition: 126 0 [+1] UInt x 127 if x < 5: 128 1 [+1] UInt xc 129 130 131struct LessThanOrEqualCondition: 132 0 [+1] UInt x 133 if x <= 5: 134 1 [+1] UInt xc 135 136 137struct GreaterThanOrEqualCondition: 138 0 [+1] UInt x 139 if x >= 5: 140 1 [+1] UInt xc 141 142 143struct GreaterThanCondition: 144 0 [+1] UInt x 145 if x > 5: 146 1 [+1] UInt xc 147 148 149struct RangeCondition: 150 0 [+1] UInt x 151 1 [+1] UInt y 152 if 5 < x <= y < 10: 153 2 [+1] UInt xc 154 155 156struct ReverseRangeCondition: 157 0 [+1] UInt x 158 1 [+1] UInt y 159 if 10 > y >= x > 5: 160 2 [+1] UInt xc 161 162 163struct AndCondition: 164 0 [+1] UInt x 165 1 [+1] UInt y 166 if x == 5 && y == 5: 167 2 [+1] UInt xc 168 169 170struct OrCondition: 171 0 [+1] UInt x 172 1 [+1] UInt y 173 if x == 5 || y == 5: 174 2 [+1] UInt xc 175 176 177struct ChoiceCondition: 178 0 [+1] enum field: 179 USE_X = 1 180 USE_Y = 2 181 182 1 [+1] UInt x 183 2 [+1] UInt y 184 if (field == Field.USE_X ? x : y) == 5: 185 3 [+1] UInt xyc 186 187 188struct ContainsBits: 189 0 [+1] bits: 190 7 [+1] UInt has_top 191 0 [+1] UInt has_bottom 192 193 194struct ContainsContainsBits: 195 0 [+1] ContainsBits condition 196 # TODO(bolms): allow Flags to be used as booleans in conditions. 197 if condition.has_top == 1: 198 1 [+1] UInt top 199 200 201struct ConditionalInline: 202 0 [+1] UInt payload_id 203 204 if payload_id == 0: 205 1 [+3] struct type_0: 206 0 [+1] UInt a 207 1 [+1] UInt b 208 2 [+1] UInt c 209 210 if payload_id == 1: 211 1 [+3] struct type_1: 212 0 [+1] UInt a 213 1 [+1] UInt b 214 2 [+1] UInt c 215 216 217struct ConditionalAnonymous: 218 0 [+1] UInt x 219 if x > 10: 220 1 [+1] bits: 221 0 [+1] UInt low 222 if low == 1: 223 3 [+2] UInt mid 224 7 [+1] UInt high 225 226 227struct ConditionalOnFlag: 228 0 [+1] bits: 229 0 [+1] Flag enabled 230 if enabled: 231 1 [+1] UInt value 232