| 1 | This folder contains JSON representations of the files. The format is |
| 2 | a bit ad-hoc; here is a partial description: |
| 3 | |
| 4 | The types of the fields: |
| 5 | |
| 6 | Let `string` be the standard string type, let `[t]` stand for an array |
| 7 | whose elements have type `t`, let `t | u` denote the union of types |
| 8 | `t` and `u`. String literals will be used as singleton types |
| 9 | containing only themselves, and we will use braces (`{` and `}`) for |
| 10 | standard JSON objects/dictionaries. |
| 11 | |
| 12 | Let us define the following types: |
| 13 | |
| 14 | - `datatype`, which is either the literal `"(auto)"`, a string |
| 15 | matching the regex `/(u|i)\d+/`, standing for an unsigned (u) or |
| 16 | signed (i) integer of a given number of bits, or a string matching |
| 17 | the regex `/(u|i)\d+\[\d+\]/`, standing for an array of the given |
| 18 | length of the given integer type |
| 19 | |
| 20 | - `varname`, either the literal `"_"` (for unused variables) or a |
| 21 | string matching `/x\d+/` |
| 22 | |
| 23 | - `name`, which is either `varname`, a string matching |
| 24 | `/(arg|out)\d+\[\d+\]/` for input/output arrays, the literal `&` |
| 25 | followed by a `varname` (for references), or the literal `*` |
| 26 | followed by a `varname` for dereferences. These last two are very |
| 27 | rare, and we make an effort to avoid them in code generation. |
| 28 | |
| 29 | - `operation`, a string which is one of `=`, `dereference`, `>>`, |
| 30 | `<<`, `&` (infix bitwise and), `|` (infix bitwise or), `~` (bitwise |
| 31 | negation), `!` (boolean negation), `+`, `*`, `-`, `mulx`, |
| 32 | `addcarryx`, `subborrowx`, `cmovznz`, or `static_cast` |
| 33 | |
| 34 | - `number`, a string which is either a decimal numeral or a |
| 35 | hexadecimal numeral |
| 36 | |
| 37 | - `bound`, either `null` or a `number` or a list of `bound`s |
| 38 | |
| 39 | - `parameters`, a JSON object with `string` keys and `string | number` values |
| 40 | |
| 41 | Let us define one more type. The recursive type of expressions |
| 42 | (corresponding to lines of code or expressions) `expr` has the format: |
| 43 | |
| 44 | ```json |
| 45 | { |
| 46 | "datatype" : datatype, |
| 47 | "name" : [name], |
| 48 | "operation" : operation, |
| 49 | "parameters": parameters |
| 50 | "arguments" : [ name | expr | number ] |
| 51 | } |
| 52 | ``` |
| 53 | |
| 54 | When `parameters` is empty, the entire `"parameters": { parameters }` |
| 55 | key-value pair will be omitted. |
| 56 | |
| 57 | It describes a line of code or an expression: |
| 58 | |
| 59 | - whose output type is specified by `"datatype"` (`"(auto)"` means |
| 60 | that the type should be inferred automatically, and is generally |
| 61 | used only in assignment statements), |
| 62 | |
| 63 | - whose output(s) are stored in the variables in `"name"` (an empty |
| 64 | list means that the value is used immediately in the enclosing |
| 65 | expression), |
| 66 | |
| 67 | - whose kind of function / operation is given by the `"operation"` |
| 68 | field, |
| 69 | |
| 70 | - whose compile-time constant parameters are given by the |
| 71 | `"parameters"` field (currently only relevant for `mulx`, |
| 72 | `addcarryx`, and `subborrowx`, all of which have a single parameter |
| 73 | `"size"` which is an integer bitwidth denoting the carry location), |
| 74 | and |
| 75 | |
| 76 | - whose arguments are the in the arguments field, which may be either |
| 77 | subexpressions or variable names |
| 78 | |
| 79 | The format of top-level functions is: |
| 80 | |
| 81 | ```json |
| 82 | { |
| 83 | "operation": string, |
| 84 | "arguments": [{"datatype": datatype, "name": varname, "lbound": bound, "ubound": bound}], |
| 85 | "returns": [{"datatype": datatype, "name": varname, "lbound": bound, "ubound": bound}], |
| 86 | "body": [expr] |
| 87 | } |
| 88 | ``` |
| 89 | |
| 90 | Note that here `"operation"` is just the name of the function, and may |
| 91 | be something like `fiat_25519_carry_mul`. |
| 92 | |
| 93 | The fields `"lbound"` and `"ubound"` stand for "lower bound" and |
| 94 | "upper bound" respectively. The bounds are assumptions about the |
| 95 | arguments, and guarantees about the returns. If the `"datatype"` is |
| 96 | an integer, the bounds will either be `null` or a string with a |
| 97 | hexadecimal number. If the `"datatype"` is a list of integers, the |
| 98 | bounds will either be `null` or a list of the appropriate length |
| 99 | containing either `null` or strings with hexadecimal encodings of |
| 100 | numbers. Bounds of `null` should never appear, and indicate that |
| 101 | bounds were either not given, unknown, or that the bounds analysis |
| 102 | pass failed. |
| 103 | |
| 104 | Note that errors in the pretty-printing process may be encoded with |
| 105 | `#error ...`; these can be detected by running the code through a JSON |
| 106 | validator, as the resulting code will not be valid JSON. |
| 107 | |
| 108 | |
| 109 | ----------------------- |
| 110 | |
| 111 | |
| 112 | Here a few examples: |
| 113 | |
| 114 | `uint64_t x1 = (arg1[1]);` corresponds to a JSON-Object such as: |
| 115 | ```json |
| 116 | { |
| 117 | "datatype": "u64", |
| 118 | "name": ["x1"], |
| 119 | "operation": "=", |
| 120 | "arguments": ["arg1[1]"] |
| 121 | } |
| 122 | ``` |
| 123 | |
| 124 | |
| 125 | ```c |
| 126 | fiat_p256_mulx_u64(&x5, &x6, x4, (arg1[3])); |
| 127 | ``` |
| 128 | would correspond to: |
| 129 | ```json |
| 130 | { |
| 131 | "datatype": "(auto)", |
| 132 | "name": ["x5", "x6"], |
| 133 | "operation": "mulx", |
| 134 | "parameters": {"size": 64}, |
| 135 | "arguments": ["x4", "arg1[3]"] |
| 136 | } |
| 137 | ``` |
| 138 | from the combination `"mulx"` and `"size": 64` we can infer, which elements from |
| 139 | the name-property is high/low limb. |
| 140 | |
| 141 | ```c |
| 142 | fiat_p256_subborrowx_u64(&x180, &x181, x179, x171, UINT64_C(0xffffffff00000001)); |
| 143 | ``` |
| 144 | would correspond to |
| 145 | ```json |
| 146 | { |
| 147 | "datatype": "(auto)", |
| 148 | "name": ["x180", "x181"], |
| 149 | "operation": "subborrowx", |
| 150 | "parameters": {"size": 64}, |
| 151 | "arguments": ["x179", "x171", "0xffffffff00000001"] |
| 152 | } |
| 153 | ``` |
| 154 | also, we can infer from `subborrowx` which arguments have which meaning |
| 155 | and which variable in `"name"` contains the carry out. |
| 156 | |
| 157 | ```c |
| 158 | fiat_p256_addcarryx_u51(&x180, &x181, x179, x171, UINT64_C(0xffffffff00000001)); |
| 159 | ``` |
| 160 | would correspond to |
| 161 | ```json |
| 162 | { |
| 163 | "datatype": "(auto)", |
| 164 | "name": ["x180", "x181"], |
| 165 | "operation": "addcarryx", |
| 166 | "parameters": {"size": 51}, |
| 167 | "arguments": ["x179", "x171", "0xffffffff00000001"] |
| 168 | } |
| 169 | ``` |
| 170 | |
| 171 | ```c |
| 172 | uint64_t x173 = ((uint64_t)x172 + x153); |
| 173 | ``` |
| 174 | ```json |
| 175 | { |
| 176 | "datatype": "u64", |
| 177 | "name": ["x173"], |
| 178 | "operation": "+", |
| 179 | "arguments": ["x172", "x153"] |
| 180 | } |
| 181 | ``` |
| 182 | |
| 183 | ```c |
| 184 | fiat_p256_cmovznz_u64(&x184, x183, x174, x165); |
| 185 | ``` |
| 186 | ```json |
| 187 | { |
| 188 | "datatype": "u64", |
| 189 | "name": ["x184"], |
| 190 | "operation": "cmovznz", |
| 191 | "arguments": ["x183", "x174", "x165"] |
| 192 | } |
| 193 | ``` |
| 194 | `cmovznz` means semantically `names[0] = arguments[0] == 0 ? arguments[1] : |
| 195 | arguments[2]`, or replaced: `x184 <- x183 == 0 ? x174 : x165`; |
| 196 | |
| 197 | |
| 198 | ```c |
| 199 | fiat_25519_uint128 x14 = ((fiat_25519_uint128)(arg1[2]) * (arg1[1])); |
| 200 | ``` |
| 201 | ```json |
| 202 | { |
| 203 | "datatype": "u128", |
| 204 | "name": ["x14"], |
| 205 | "operation": "*", |
| 206 | "arguments": ["arg1[2]", "arg1[1]"] |
| 207 | } |
| 208 | ``` |
| 209 | |
| 210 | ```c |
| 211 | uint64_t x45 = (x44 >> 51); |
| 212 | ``` |
| 213 | ```json |
| 214 | { |
| 215 | "datatype": "u64", |
| 216 | "name": ["x45"], |
| 217 | "operation": ">>", |
| 218 | "arguments": ["x44", "51"] |
| 219 | } |
| 220 | ``` |
| 221 | Note that, at least currently, `arguments[1]` will always be an immediate |
| 222 | value |
| 223 | |
| 224 | ```c |
| 225 | fiat_25519_uint1 x48 = (fiat_25519_uint1)(x47 >> 51); |
| 226 | ``` |
| 227 | ```json |
| 228 | { |
| 229 | "datatype": "u1", |
| 230 | "name": ["x48"], |
| 231 | "operation": ">>", |
| 232 | "arguments": ["x47", "51"] |
| 233 | } |
| 234 | ``` |
| 235 | |
| 236 | ```c |
| 237 | uint64_t x105 = (x92 + (x83 + (x75 + (x68 + (x62 + (x57 + (x53 + (x50 + (x48 + x1))))))))); |
| 238 | ``` |
| 239 | ```json |
| 240 | { |
| 241 | "datatype": "u64", |
| 242 | "name": ["x105"], |
| 243 | "operation": "+", |
| 244 | "arguments": [ |
| 245 | "x92" |
| 246 | , |
| 247 | { |
| 248 | "datatype": "u64", |
| 249 | "name": [], |
| 250 | "operation": "+", |
| 251 | "arguments": [ |
| 252 | "x83" |
| 253 | , |
| 254 | { |
| 255 | "datatype": "u64", |
| 256 | "name": [], |
| 257 | "operation": "+", |
| 258 | "arguments": [ |
| 259 | "x75" |
| 260 | , |
| 261 | { |
| 262 | "datatype": "u64", |
| 263 | "name": [], |
| 264 | "operation": "+", |
| 265 | "arguments": [ |
| 266 | "x68" |
| 267 | , |
| 268 | { |
| 269 | "datatype": "u64", |
| 270 | "name": [], |
| 271 | "operation": "+", |
| 272 | "arguments": [ |
| 273 | "x62" |
| 274 | , |
| 275 | { |
| 276 | "datatype": "u64", |
| 277 | "name": [], |
| 278 | "operation": "+", |
| 279 | "arguments": [ |
| 280 | "x57" |
| 281 | , |
| 282 | { |
| 283 | "datatype": "u64", |
| 284 | "name": [], |
| 285 | "operation": "+", |
| 286 | "arguments": [ |
| 287 | "x53" |
| 288 | , |
| 289 | { |
| 290 | "datatype": "u64", |
| 291 | "name": [], |
| 292 | "operation": "+", |
| 293 | "arguments": [ |
| 294 | "x50" |
| 295 | , |
| 296 | { |
| 297 | "datatype": "u64", |
| 298 | "name": [], |
| 299 | "operation": "+", |
| 300 | "arguments": [ |
| 301 | "x48" |
| 302 | , |
| 303 | "x1" |
| 304 | ] |
| 305 | } |
| 306 | ] |
| 307 | } |
| 308 | ] |
| 309 | } |
| 310 | ] |
| 311 | } |
| 312 | ] |
| 313 | } |
| 314 | ] |
| 315 | } |
| 316 | ] |
| 317 | } |
| 318 | ] |
| 319 | } |
| 320 | ] |
| 321 | } |
| 322 | ``` |