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
omega-mv / src / omega_program_ir.h
| 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 | #ifndef OMEGA_PROGRAM_IR_H |
| 18 | #define OMEGA_PROGRAM_IR_H |
| 19 | |
| 20 | /* omega_program_ir: the canonical IR of an Omega program, the bytes behind the Verified Crumb |
| 21 | * field source_or_ir_digest when digest_kind is OMEGA_VC_DIGEST_IR (VC1 stage 6, SPEC 6 step 3). |
| 22 | * |
| 23 | * The program id (omega_program_compute_id) binds exactly: the body steps, the input and output |
| 24 | * types and widths, and the precondition and postcondition ids. The IR carries exactly those |
| 25 | * fields and nothing else (no name, cost or realization: they are metadata), so the id can be |
| 26 | * RECOMPUTED from the IR bytes alone. That recomputation is what lets the resolver check that a |
| 27 | * stored blob really is the program its semantic id names. |
| 28 | * |
| 29 | * Layout (all integers big-endian, no padding): |
| 30 | * "AIEN_OMEGA_PROGRAM_IR_V1" 24 bytes |
| 31 | * u8 input_type u16 input_width u8 output_type u16 output_width |
| 32 | * 32 precondition_id 32 postcondition_id |
| 33 | * u16 step_count (0..OMEGA_PROGRAM_MAX_STEPS) |
| 34 | * step_count x { u8 op, u64 imm } |
| 35 | * Decoding is exact: wrong tag, truncation, trailing bytes, too many steps, or an op or type the |
| 36 | * program id does not accept are refusals. */ |
| 37 | |
| 38 | #include <stddef.h> |
| 39 | #include <stdint.h> |
| 40 | |
| 41 | #include "omega_program.h" |
| 42 | |
| 43 | #define OMEGA_PROGRAM_IR_TAG "AIEN_OMEGA_PROGRAM_IR_V1" |
| 44 | #define OMEGA_PROGRAM_IR_TAG_LEN 24 |
| 45 | |
| 46 | /* Canonical IR of prog (malloc'd, caller frees). Refuses a program with no body. 0 or -1. */ |
| 47 | int omega_program_ir_encode(const OmegaProgram *prog, uint8_t **out, size_t *len); |
| 48 | |
| 49 | /* Decode the IR into *out (zeroed first, program_id recomputed with omega_program_compute_id). |
| 50 | * 0 or -1; on -1 *out holds nothing to free. */ |
| 51 | int omega_program_ir_decode(const uint8_t *bytes, size_t len, OmegaProgram *out); |
| 52 | |
| 53 | /* Recompute the program id from the IR alone. 0 with id set, or -1. */ |
| 54 | int omega_program_ir_recompute_id(const uint8_t *bytes, size_t len, uint8_t id[32]); |
| 55 | |
| 56 | #endif /* OMEGA_PROGRAM_IR_H */ |