8{
9 if (argc < 2) {
10 fprintf(stderr,
11 "Usage:\n"
12 " %s /path/to/config.json [--emit out.c] [--emit-lib] # parse config, dump + codegen\n"
13 " %s --ir /path/to/ir.json [--emit out.c] [--emit-lib] # parse IR JSON, dump + codegen\n"
14 "\n"
15 "Options:\n"
16 " --emit out.c Write generated C code to file\n"
17 " --emit-lib Generate shared library API (no main)\n"
18 " Without --emit-lib: generates standalone executable with main()\n",
19 argv[0], argv[0]);
20 return 1;
21 }
22
25
26 const char *emit_path = NULL;
28
29 for (int i = 1; i < argc; ++i) {
30 if (strcmp(argv[i], "--emit") == 0 && i + 1 < argc) {
31 emit_path = argv[++i];
32 } else if (strcmp(argv[i], "--emit-lib") == 0) {
34 }
35 }
36
37 if (strcmp(argv[1], "--ir") == 0) {
38 if (argc < 3) {
39 fprintf(stderr, "Missing IR JSON path after --ir\n");
40 return 1;
41 }
42 const char *ir_path = argv[2];
44 fprintf(stderr, "Failed to parse IR JSON: %s\n", ir_path);
45 return 1;
46 }
48 fprintf(stderr, "Failed to build backward IR from IR JSON\n");
50 return 1;
51 }
52 } else {
53 const char *config_path = argv[1];
56 fprintf(stderr, "Failed to parse config.json: %s\n", config_path);
57 return 1;
58 }
59
61 fprintf(stderr, "Failed to build decoder IR\n");
62 return 1;
63 }
64
66 fprintf(stderr, "Failed to build backward IR\n");
68 return 1;
69 }
70 }
71
72 printf("=== Forward IR ===\n");
74 printf("\n=== Backward IR (skeleton) ===\n");
76
77 printf("\n=== Generated C Skeleton ===\n");
79
80 if (emit_path) {
81 const char *mode_str = (emit_mode ==
CK_EMIT_LIBRARY) ?
"library" :
"standalone";
83 fprintf(stderr, "\n[ck_ir_demo] %s runtime written to %s\n", mode_str, emit_path);
84 } else {
85 fprintf(stderr, "\n[ck_ir_demo] failed to write %s runtime to %s\n", mode_str, emit_path);
86 }
87 }
88
89
90 if (strcmp(argv[1], "--ir") != 0) {
92 fprintf(stderr, "\n[ck_ir_demo] JSON IR written to build/ir.json\n");
93 } else {
94 fprintf(stderr, "\n[ck_ir_demo] Failed to write JSON IR to build/ir.json\n");
95 }
96 }
97
100 return 0;
101}
int ck_codegen_emit_runtime(const CKIRGraph *forward, const char *path, CKEmitMode mode)
void ck_codegen_c_skeleton(const CKIRGraph *forward, const CKIRGraph *backward, FILE *out)
int ck_build_decoder_ir(const CKModelConfig *cfg, CKIRGraph *graph)
int ck_ir_serialize_json(const CKIRGraph *graph, const char *path)
int ck_build_decoder_backward_ir(const CKIRGraph *forward, CKIRGraph *backward)
void ck_ir_dump(const CKIRGraph *graph, FILE *out)
int ck_model_config_from_hf_json(const char *path, CKModelConfig *cfg)
int ck_ir_parse_json(const char *path, CKIRGraph *graph)
void ck_ir_free(CKIRGraph *graph)