All files / utils/constants TOOLCHAIN_REQUIREMENTS.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248                                            51x                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
import type IToolchainRequirement from "../../types/IToolchainRequirement";
import type TRequirementKey from "../../types/TRequirementKey";
 
/**
 * Issue #1143: The single source of truth for what generated output costs.
 *
 * Every construct the code generator emits whose acceptance depends on the
 * toolchain has an entry here, and the emitting code records that entry's key
 * at the moment it produces the text. The transpile-time report, the per-file
 * banner, docs/compatibility.md, the MISRA guideline rows and any compile-time
 * guard are all projections of this table -- none of them re-derives the
 * answer, so none of them can contradict what was emitted.
 *
 * Requirements are CONDITIONAL. A file that uses no critical section pays no
 * CMSIS cost; a file that does not index bits of a float pays no C11 cost. The
 * flat claim "generated code is standard C99" was false in both directions: it
 * overstated what plain files need and understated what these files need.
 *
 * Note there is currently no compiler-version floor anywhere in this table.
 * The only one that ever existed came from the unreachable
 * __builtin_*_overflow calls removed in #1143.
 */
const TOOLCHAIN_REQUIREMENTS: Record<TRequirementKey, IToolchainRequirement> = {
  "baseline-c": {
    key: "baseline-c",
    modes: ["c"],
    feature: "baseline",
    standard: "C99",
    compiler: null,
    extensions: [],
    platformLib: null,
    condition: null,
    reason: "<stdint.h> fixed-width types, // comments, mixed declarations",
    incurredBy: "any C-Next file transpiled to C",
    probe: null,
    adr: "ADR-044",
    misra: ["1.1"],
  },
 
  "baseline-cpp": {
    key: "baseline-cpp",
    modes: ["cpp"],
    feature: "baseline",
    standard: "C++11",
    compiler: null,
    extensions: [],
    platformLib: null,
    condition: null,
    reason: "nullptr, static_cast, reinterpret_cast",
    incurredBy: "any C-Next file transpiled with --cpp",
    probe: null,
    adr: "ADR-010",
    misra: ["1.1"],
  },
 
  "float-assert-c11": {
    key: "float-assert-c11",
    modes: ["c"],
    feature: "float bit indexing",
    standard: "C11",
    compiler: null,
    extensions: [],
    platformLib: null,
    condition: null,
    reason: "_Static_assert",
    incurredBy: "reading or writing a bit range of an f32 or f64",
    probe: /_Static_assert\(sizeof\((?:float|double)\)/,
    adr: "ADR-007",
    misra: ["1.1"],
  },
 
  "float-assert-cpp11": {
    key: "float-assert-cpp11",
    modes: ["cpp"],
    feature: "float bit indexing",
    standard: "C++11",
    compiler: null,
    extensions: [],
    platformLib: null,
    condition: null,
    reason: "static_assert",
    incurredBy: "reading or writing a bit range of an f32 or f64 with --cpp",
    probe: /static_assert\(sizeof\((?:float|double)\)/,
    adr: "ADR-007",
    misra: [],
  },
 
  "critical-arm-gnu": {
    key: "critical-arm-gnu",
    modes: ["c", "cpp"],
    // #1146: a critical block and an atomic read-modify-write both mask
    feature: "interrupt masking",
    standard: "C99",
    compiler: null,
    extensions: ["GNU inline assembly", "__attribute__((always_inline))"],
    platformLib: "ARMv7-M core",
    condition: "defined(__arm__) || defined(__ARM_ARCH)",
    reason:
      '__asm volatile ("MRS %0, primask"), __attribute__((always_inline))',
    // #1146: an atomic read-modify-write masks through the same wrappers
    incurredBy:
      "a critical block, or an atomic read-modify-write on a target without LDREX/STREX",
    probe: /MRS %0, primask/,
    adr: "ADR-050",
    misra: ["1.2", "Dir 4.3", "20.8", "20.9", "20.14"],
  },
 
  "critical-arduino": {
    key: "critical-arduino",
    modes: ["c", "cpp"],
    // #1146: a critical block and an atomic read-modify-write both mask
    feature: "interrupt masking",
    standard: "C99",
    compiler: null,
    // The Arduino `#if` is nested INSIDE the ARM arm, so an ARM+Arduino target
    // compiles the PRIMASK helpers as well as noInterrupts(). It needs the ARM
    // arm's extensions too -- this is a refinement of that arm, not an
    // alternative to it, and declaring `[]` here understated it.
    extensions: ["GNU inline assembly", "__attribute__((always_inline))"],
    platformLib: "ARMv7-M core + Arduino core",
    condition: "defined(__arm__) && defined(ARDUINO)",
    reason: "noInterrupts()",
    // #1146: an atomic read-modify-write masks through the same wrappers
    incurredBy:
      "a critical block, or an atomic read-modify-write on a target without LDREX/STREX",
    probe: /noInterrupts\(\)/,
    adr: "ADR-050",
    misra: ["Dir 4.9", "20.8", "20.9", "20.14"],
  },
 
  "critical-avr-libc": {
    key: "critical-avr-libc",
    modes: ["c", "cpp"],
    // #1146: a critical block and an atomic read-modify-write both mask
    feature: "interrupt masking",
    standard: "C99",
    compiler: null,
    // Issue #1147: the arm includes <avr/io.h> and <avr/interrupt.h>, which
    // avr-libc provides.
    platformLib: "avr-libc",
    extensions: [],
    condition: "defined(__AVR__)",
    reason: "SREG, cli()",
    // #1146: an atomic read-modify-write masks through the same wrappers
    incurredBy:
      "a critical block, or an atomic read-modify-write on a target without LDREX/STREX",
    probe: /return SREG;/,
    adr: "ADR-050",
    misra: ["Dir 4.9", "20.8", "20.9", "20.14"],
  },
 
  "critical-cmsis-fallback": {
    key: "critical-cmsis-fallback",
    modes: ["c", "cpp"],
    // #1146: a critical block and an atomic read-modify-write both mask
    feature: "interrupt masking",
    standard: "C99",
    compiler: null,
    extensions: [],
    // Issue #1147: no <cmsis_gcc.h> is emitted on this arm either.
    platformLib: "CMSIS",
    condition: "neither ARM nor AVR",
    reason: "__disable_irq(), __get_PRIMASK(), __set_PRIMASK()",
    // #1146: an atomic read-modify-write masks through the same wrappers
    incurredBy:
      "a critical block, or an atomic read-modify-write on a target without LDREX/STREX",
    probe: /\{ __disable_irq\(\); \}/,
    adr: "ADR-050",
    misra: ["Dir 4.9", "20.8", "20.9", "20.14"],
  },
 
  "atomic-ldrex-cmsis": {
    key: "atomic-ldrex-cmsis",
    modes: ["c", "cpp"],
    feature: "atomic read-modify-write",
    standard: "C99",
    compiler: null,
    extensions: [],
    platformLib: "CMSIS + ARMv7-M",
    condition: null,
    reason: "__LDREXB/H/W, __STREXB/H/W",
    incurredBy:
      "compound assignment to an atomic variable on a target with LDREX/STREX",
    probe: /__(?:LDREX|STREX)[BHW]\b/,
    adr: "ADR-049",
    misra: ["Dir 4.9"],
  },
 
  "cpp-designated-initializer": {
    key: "cpp-designated-initializer",
    modes: ["cpp"],
    feature: "struct initializer",
    standard: "C++20",
    compiler: null,
    // Accepted by GCC and Clang before C++20 as an extension, which is how the
    // repo's own -std=c++14 harness compiles this output.
    extensions: ["designated initializers in C++"],
    platformLib: null,
    condition: null,
    reason: ".field = value inside a braced initializer",
    incurredBy: "initializing a struct in --cpp mode",
    // Anchored on the brace, not on `= {`: the key is recorded before
    // formatStructInitializer decides whether to wrap the braces in a cast, so
    // the same requirement also appears as `= (T){ .field = ... }`. Anchoring
    // on the assignment made the probe unable to match a form it is recorded
    // for -- a recorded requirement whose emission the probe cannot see, which
    // is the #1141 shape this registry exists to prevent.
    probe: /\{\s*\.[A-Za-z_]\w*\s*=/,
    adr: "ADR-035",
    misra: [],
  },
 
  "cpp-compound-literal": {
    key: "cpp-compound-literal",
    modes: ["cpp"],
    feature: "struct initializer",
    standard: "C++11",
    compiler: null,
    // Compound literals are not ISO C++ at any version.
    extensions: ["compound literals in C++"],
    platformLib: null,
    condition: null,
    reason: "(T){ ... } in C++",
    incurredBy: "a non-declaration struct literal in --cpp mode",
    probe: /=\s*\([A-Za-z_][\w:]*\)\{/,
    adr: "ADR-035",
    misra: ["1.2"],
  },
 
  "overflow-panic-hosted-libc": {
    key: "overflow-panic-hosted-libc",
    modes: ["c", "cpp"],
    feature: "overflow panic (--debug)",
    standard: "C99",
    compiler: null,
    extensions: [],
    platformLib: "hosted libc",
    condition: null,
    reason: "fprintf(stderr, ...), abort()",
    incurredBy: "transpiling with --debug and using a clamp type",
    probe: /fprintf\(stderr, "PANIC:/,
    adr: "ADR-044",
    misra: ["21.6", "21.8"],
  },
};
 
export default TOOLCHAIN_REQUIREMENTS;