Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/checker2/c2_ir.h # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / checker2 / c2_ir.h` 135 lines ยท 4680 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* c2_ir: checker2's own decoder and acceptance rules for canonical OSC IR bytes. 18 * 19 * INDEPENDENCE. Written from the byte layout of the encoder (src/compiler/osc_ir.c, the 20 * canonical-encoding section only, lines 537-729 at `d58023e6`) and the meaning stated in 21 * docs/osc/OSC-1-DESIGN.md, OSC-2-DESIGN.md, OSC-3-DESIGN.md, OSC-EXT-BYTES-DESIGN.md and the 22 * comments of src/compiler/osc_ir.h. It includes no compiler header, links no compiler object and 23 * never read osc_check.* or osc_ir_validate. Every constant below is restated here, not imported. 24 * The rule list is in spec/one-layer-receipts.md section 9. 25 * 26 * Fails closed: anything not understood is a rejection with a stable rule name. */ 27 #ifndef C2_IR_H 28 #define C2_IR_H 29 30 #include 31 #include 32 33 /* limits restated from the OSC design (osc_ir.h comments) */ 34 #define C2_MAX_FUNCS 32 35 #define C2_MAX_PARAMS 6 36 #define C2_MAX_VREGS 480 37 #define C2_MAX_INSNS 4096 38 #define C2_MAX_BLOCKS 512 39 #define C2_MAX_ARRAY 64 40 #define C2_NAME_MAX 63 /* bytes, excluding the terminator the producer keeps */ 41 #define C2_CLAUSE_MAX 255 42 #define C2_MAX_STRUCTS 16 43 #define C2_MAX_FIELDS 16 44 #define C2_POOL_SLOTS 16 45 #define C2_TRAP_MAX 14 46 47 /* scalar codes on the wire */ 48 enum { S_VOID = 0, S_BOOL, S_U8, S_U16, S_U32, S_U64, S_I8, S_I16, S_I32, S_I64, S_REF, S_BYTES, S_CELLS, 49 S_LIMIT }; 50 enum { K_NONE = 0, K_OWN, K_SHARED, K_MUT }; 51 52 /* opcodes on the wire */ 53 enum { 54 C2_CONST = 1, C2_MOV, C2_BIN, C2_UN, C2_CMP, C2_CAST, C2_ALLOC, C2_RELEASE, C2_LOAD, C2_STORE, 55 C2_CALL, C2_TRAP, C2_BR, C2_CBR, C2_RET, C2_FLOAD, C2_FSTORE, C2_AOPEN, C2_AALLOC, C2_ADESTROY, 56 C2_POPEN, C2_PCLOSE, C2_HALLOC, C2_HGEN, C2_HFREE, C2_HLOAD, C2_HSTORE, C2_SLOAD, C2_SSTORE, 57 C2_OP_LIMIT 58 }; 59 enum { B_ADD = 1, B_SUB, B_MUL, B_DIV, B_REM, B_AND, B_OR, B_XOR, B_SHL, B_SHR, B_LIMIT }; 60 enum { U_NEG = 1, U_BNOT, U_LNOT, U_LIMIT }; 61 enum { CC_EQ = 1, CC_NE, CC_LT, CC_LE, CC_GT, CC_GE, CC_LIMIT }; 62 63 typedef struct { 64 uint8_t s, kind, elem, sid; 65 uint16_t len; 66 } C2Type; 67 68 typedef struct { 69 uint8_t op, sub, nargs; 70 int16_t dst, a, b, c; 71 int16_t args[C2_MAX_PARAMS]; 72 uint16_t t, f, callee; 73 uint64_t imm; 74 } C2Insn; 75 76 typedef struct { uint32_t first, count; } C2Block; 77 78 typedef struct { 79 char name[C2_NAME_MAX + 1]; 80 uint8_t nparams; 81 C2Type ret; 82 uint16_t nvregs, nblocks; 83 uint32_t ninsns; 84 C2Type *vt; /* nvregs */ 85 C2Block *blk; /* nblocks */ 86 C2Insn *in; /* ninsns */ 87 uint16_t req_len, ens_len; 88 char req[C2_CLAUSE_MAX + 1], ens[C2_CLAUSE_MAX + 1]; 89 } C2Func; 90 91 typedef struct { 92 char name[C2_NAME_MAX + 1]; 93 uint8_t s; 94 uint16_t alen, off; 95 } C2Field; 96 97 typedef struct { 98 char name[C2_NAME_MAX + 1]; 99 uint8_t nfields; 100 uint16_t ncells; 101 C2Field f[C2_MAX_FIELDS]; 102 } C2Struct; 103 104 typedef struct { 105 uint8_t version; 106 uint8_t nstructs; 107 C2Struct st[C2_MAX_STRUCTS]; 108 uint16_t nfuncs; 109 C2Func fn[C2_MAX_FUNCS]; 110 } C2Unit; 111 112 /* Verdict. rule is a stable name ("C2-..."), func / insn locate it (-1 when not applicable). */ 113 typedef struct { 114 int ok; 115 const char *rule; 116 int func, insn; 117 char detail[160]; 118 } C2Verdict; 119 120 /* Strict decode: exact byte layout, canonical version byte, limits, no trailing bytes. 121 * 0 ok, -1 rejected with v filled. Call c2_unit_free afterwards in both cases. */ 122 int c2_decode(const uint8_t *buf, size_t len, C2Unit *u, C2Verdict *v); 123 void c2_unit_free(C2Unit *u); 124 /* Acceptance rules over a decoded unit (types, operands, CFG, calls, definite assignment, 125 * handle disciplines, ownership). 0 accept, -1 reject. */ 126 int c2_check_unit(const C2Unit *u, C2Verdict *v); 127 /* decode + check. */ 128 int c2_check_bytes(const uint8_t *buf, size_t len, C2Verdict *v); 129 130 /* checker2's own canonical re-encoding (used by the tests to plant defects structurally and to 131 * prove decode is the exact inverse on accepted inputs). Returns the length, or 0 if cap is too 132 * small. */ 133 size_t c2_encode(const C2Unit *u, uint8_t *buf, size_t cap); 134 135 #endif /* C2_IR_H */