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 / tests / one_layer / acceptance / sample / mkoscir.c
| 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 | /* |
| 18 | * mkoscir.c -- writes the OSC binary IR bytes (spec/one-layer-format.md) of a PUBLIC SAMPLE OSC text |
| 19 | * program, for the v2 selftest (HARNESS_INTERFACE_V2.md kind oscir). Not the sealed corpus. |
| 20 | * mkoscir <in.osc> <out.oscir> |
| 21 | * osc_compile, then osc_ir_encode: the canonical bytes osc_ir_decode admits. |
| 22 | */ |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include "osc_front.h" |
| 28 | #include "osc_ir.h" |
| 29 | |
| 30 | int main(int argc, char **argv) |
| 31 | { |
| 32 | if (argc != 3) { fprintf(stderr, "usage: mkoscir in.osc out.oscir\n"); return 2; } |
| 33 | FILE *f = fopen(argv[1], "rb"); |
| 34 | if (!f) return 1; |
| 35 | static char src[1 << 20]; |
| 36 | size_t n = fread(src, 1, sizeof src, f); |
| 37 | fclose(f); |
| 38 | OscUnit *u = calloc(1, sizeof *u); |
| 39 | static uint8_t buf[OSC_IR_ENCODED_MAX]; |
| 40 | size_t len = 0; |
| 41 | OscDiag d; |
| 42 | memset(&d, 0, sizeof d); |
| 43 | if (!u || osc_compile(src, n, u, &d, NULL) || osc_ir_encode(u, buf, sizeof buf, &len)) { fprintf(stderr, "mkoscir: refused\n"); return 1; } |
| 44 | if (!(f = fopen(argv[2], "wb")) || fwrite(buf, 1, len, f) != len || fclose(f)) return 1; |
| 45 | free(u); |
| 46 | return 0; |
| 47 | } |