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/tests/one_layer/acceptance/sample/mkopir.c # 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 / tests / one_layer / acceptance / sample / mkopir.c` 62 lines ยท 2563 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 /* 18 * mkopir.c -- writes the OmegaProgram IR bytes of the PUBLIC SAMPLE corpus cases (not the sealed 19 * corpus). Built from the repo's own program API so the bytes are what omega_program_ir_decode reads: 20 * mkopir [ ]... op: add sub mul and or 21 * Prints "program_id=". Uses omega_program_build_unary_op for the first step, appends the 22 * rest, sets the declared width, recomputes the id (omega_program_compute_id), then 23 * omega_program_ir_encode. 24 */ 25 #include 26 #include 27 #include 28 29 #include "omega_program.h" 30 #include "omega_program_ir.h" 31 32 static int opc(const char *s) 33 { 34 return !strcmp(s, "add") ? OP_ADD : !strcmp(s, "sub") ? OP_SUB : !strcmp(s, "mul") ? OP_MUL 35 : !strcmp(s, "and") ? OP_AND : !strcmp(s, "or") ? OP_OR : -1; 36 } 37 38 int main(int argc, char **argv) 39 { 40 if (argc < 5 || (argc - 3) % 2) { fprintf(stderr, "usage: mkopir out width op imm [op imm]...\n"); return 2; } 41 static OmegaProgram p; 42 int op = opc(argv[3]); 43 if (op < 0 || omega_program_build_unary_op(&p, "sample", (OpCode)op, strtoull(argv[4], NULL, 0))) return 1; 44 for (int i = 5; i + 1 < argc; i += 2) { 45 if ((op = opc(argv[i])) < 0 || p.body.step_count >= OMEGA_PROGRAM_MAX_STEPS) return 1; 46 p.body.steps[p.body.step_count].op = (uint8_t)op; 47 p.body.steps[p.body.step_count++].imm = strtoull(argv[i + 1], NULL, 0); 48 } 49 uint16_t w = (uint16_t)atoi(argv[2]); 50 p.contract.input_width = p.contract.output_width = w; 51 if (omega_program_compute_id(&p)) return 1; 52 uint8_t *b = NULL; 53 size_t n = 0; 54 if (omega_program_ir_encode(&p, &b, &n)) return 1; 55 FILE *f = fopen(argv[1], "wb"); 56 if (!f || fwrite(b, 1, n, f) != n || fclose(f)) return 1; 57 printf("program_id="); 58 for (int i = 0; i < 32; i++) printf("%02x", p.program_id.bytes[i]); 59 printf("\n"); 60 free(b); 61 return 0; 62 }