|
6 | 6 | #include <stdlib.h> |
7 | 7 | #include <string.h> |
8 | 8 |
|
| 9 | +#include "../src/dsl_compile_internal.h" |
9 | 10 | #include "../src/dsl_jit_ir.h" |
10 | 11 | #include "../src/dsl_parser.h" |
11 | 12 | #include "minctest.h" |
@@ -437,6 +438,71 @@ static int test_parser_pragmas(void) { |
437 | 438 | return 0; |
438 | 439 | } |
439 | 440 |
|
| 441 | +static int test_env_jit_compiler_override(void) { |
| 442 | + printf("\n=== JIT IR Test 6b: env compiler override ===\n"); |
| 443 | + |
| 444 | + const char *src = |
| 445 | + "# me:compiler=tcc\n" |
| 446 | + "def kernel(x):\n" |
| 447 | + " return x\n"; |
| 448 | + me_dsl_error error; |
| 449 | + me_dsl_program *parsed = me_dsl_parse(src, &error); |
| 450 | + me_dsl_compiled_program *compiled = NULL; |
| 451 | + |
| 452 | + if (!parsed) { |
| 453 | + printf(" FAILED: parse error for env compiler override source\n"); |
| 454 | + return 1; |
| 455 | + } |
| 456 | + |
| 457 | + if (setenv("ME_DSL_JIT_COMPILER", "cc", 1) != 0) { |
| 458 | + printf(" FAILED: could not set ME_DSL_JIT_COMPILER=cc\n"); |
| 459 | + me_dsl_program_free(parsed); |
| 460 | + return 1; |
| 461 | + } |
| 462 | + compiled = dsl_compiled_program_alloc(parsed, src, 1, NULL, 0); |
| 463 | + if (!compiled) { |
| 464 | + printf(" FAILED: could not allocate compiled program for cc override\n"); |
| 465 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 466 | + me_dsl_program_free(parsed); |
| 467 | + return 1; |
| 468 | + } |
| 469 | + if (compiled->compiler != ME_DSL_COMPILER_CC) { |
| 470 | + printf(" FAILED: env compiler override did not force cc backend\n"); |
| 471 | + dsl_compiled_program_free(compiled); |
| 472 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 473 | + me_dsl_program_free(parsed); |
| 474 | + return 1; |
| 475 | + } |
| 476 | + dsl_compiled_program_free(compiled); |
| 477 | + |
| 478 | + if (setenv("ME_DSL_JIT_COMPILER", "tcc", 1) != 0) { |
| 479 | + printf(" FAILED: could not set ME_DSL_JIT_COMPILER=tcc\n"); |
| 480 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 481 | + me_dsl_program_free(parsed); |
| 482 | + return 1; |
| 483 | + } |
| 484 | + compiled = dsl_compiled_program_alloc(parsed, src, 1, NULL, 0); |
| 485 | + if (!compiled) { |
| 486 | + printf(" FAILED: could not allocate compiled program for tcc override\n"); |
| 487 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 488 | + me_dsl_program_free(parsed); |
| 489 | + return 1; |
| 490 | + } |
| 491 | + if (compiled->compiler != ME_DSL_COMPILER_LIBTCC) { |
| 492 | + printf(" FAILED: env compiler override did not force tcc backend\n"); |
| 493 | + dsl_compiled_program_free(compiled); |
| 494 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 495 | + me_dsl_program_free(parsed); |
| 496 | + return 1; |
| 497 | + } |
| 498 | + |
| 499 | + dsl_compiled_program_free(compiled); |
| 500 | + unsetenv("ME_DSL_JIT_COMPILER"); |
| 501 | + me_dsl_program_free(parsed); |
| 502 | + printf(" PASSED\n"); |
| 503 | + return 0; |
| 504 | +} |
| 505 | + |
440 | 506 | static int test_ir_fingerprint_includes_fp_mode(void) { |
441 | 507 | printf("\n=== JIT IR Test 6: fingerprint includes fp mode ===\n"); |
442 | 508 |
|
@@ -593,6 +659,7 @@ int main(void) { |
593 | 659 | fail |= test_ir_rejects_unsupported_statements(); |
594 | 660 | fail |= test_ir_fingerprint_is_deterministic(); |
595 | 661 | fail |= test_parser_pragmas(); |
| 662 | + fail |= test_env_jit_compiler_override(); |
596 | 663 | fail |= test_ir_fingerprint_includes_fp_mode(); |
597 | 664 | fail |= test_ir_accepts_while_loops(); |
598 | 665 | fail |= test_ir_accepts_reassignment_dtype_coercion(); |
|
0 commit comments