众力资讯网

这个任务很有意思,就像观察远古海洋中核糖核酸分子的诞生。> 从零实现一个能自举的

这个任务很有意思,就像观察远古海洋中核糖核酸分子的诞生。

> 从零实现一个能自举的 C 子集编译器。> 1. 不要求符合 C99 等标准,能自举即可。> 2. 涉及的软硬件平台为 Windows、x64。> 3. 先实现支持十六进制字节输出、标签定义及地址和相对偏移解析的最小装配器。其程序须直接输出为十六进制机器码的文本。可调用 Python 将十六进制文本转为二进制,但不得用 Python 参与功能实现。> 4. 后续允许编写源码、增加中间工具,但所有后续二进制产物只能由此前构建的自制工具生成。> 5. 外部工具仅可用于文本编辑、命令执行、测试和检查,不得用于生成或修改编译产物。> 6. 最终编译器须用其支持的 C 子集编写,连续编译自身两次,验证产物一致并通过功能测试。交付完整源码、种子十六进制文本及可复现构建步骤。

```cmdC:\tmp>build.cmd[1/6] Decode the handwritten hex seed[2/6] Build the template expander using the seed[3/6] Build the handwritten bootstrap compiler[4/6] Compile the C compiler source[5/6] Compile itself twice[6/6] Run functional, rejection, and artifact checksPASS: seed reproduces itself; c0 == c1 == c2 byte for byte (EXE and compiler output).PASS: forward/backward relative references, absolute address, zero fill, macros, quoted bytes, invalid hex and macro rejection.PASS: c0 runs hello, 75 feature assertions, text/binary echo, exit code, and string escapes.PASS: c1 runs hello, 75 feature assertions, text/binary echo, exit code, and string escapes.PASS: c2 runs hello, 75 feature assertions, text/binary echo, exit code, and string escapes.PASS: 17 invalid-source cases rejected by each of c0, c1, c2.PASS: cc.cmd handles an output filename containing spaces.PASS: final artifact is a Windows x64 PE32+ console executable.seed.exe 2048 bytes SHA256 5cc5ce6c07b04c77faa6957a550d3eb596ec66850fafe84fab1707fabaf72747expand.exe 4196411 bytes SHA256 4f16f57ffc61e9e7f29c8a7b38aa6e1206ee16fce39a9853d6eade2f4eb6e794bootstrap.exe 4810476 bytes SHA256 41086b9c68e203750488eba8f4b4d83a895e4ea61a18481110863428ff8707cdc0.exe 4831705 bytes SHA256 7b27091e0c6556670123f949a9c3282a9fd1d709009b5752769de3b8c8534b37c1.exe 4831705 bytes SHA256 7b27091e0c6556670123f949a9c3282a9fd1d709009b5752769de3b8c8534b37c2.exe 4831705 bytes SHA256 7b27091e0c6556670123f949a9c3282a9fd1d709009b5752769de3b8c8534b37ALL CHECKS PASSEDSUCCESS: build\c2.exe is the self-hosted compiler.```