HN 표시: LLVM-Z80 - AI로 완전한 LLVM 백엔드를 작성했습니다.

hackernews | | 📦 오픈소스
#ai #llvm #z80 #마이크로프로세서 #반도체 #하드웨어/반도체
원문 출처: hackernews · Genesis Park에서 요약 및 분석

요약

한 개발자가 ChatGPT와 같은 생성형 AI의 도움을 받아 1970년대 Z80 CPU를 위한 완전한 LLVM 백엔드를 직접 구현했다고 밝혔습니다. Z80은 현대적인 컴파일러 인프라가 부족한 8비트 아키텍처이기에, 이번 성과는 AI를 활용해 레거시 하드웨어를 위한 복잡한 시스템 소프트웨어를 개발할 수 있음을 보여줍니다. 해당 프로젝트는 난해한 어셈블리어 제약과 문서를 AI와 협력하여 해결한 사례로 주목받고 있습니다.

본문

Artwork by zlfn. Created with Aseprite. Lettering assisted by AI & fonts. LLVM-Z80 is a LLVM fork supporting the Zilog Z80 series of microprocessors. [Backend Code] | [Tests / Utilities] | [Wiki] | [FAQ] | [Prebuilt Binaries] | [AUTHORS] | [NOTICE] The llvm-z80 project is not officially affiliated with or endorsed by the LLVM Foundation or LLVM project. Our project is a fork of LLVM that provides a new backend/target; our project is based on LLVM, not a part of LLVM. Our use of LLVM or other related trademarks does not imply affiliation or endorsement. Generative AI played significant role in generating code for the development of LLVM-Z80, which is currently is an experimental stage. Although the project aims to produce highly optimized, production-grade code, it is not yet stable enough for use in professional production environments. If you require a Z80 C compiler for production purposes, please use SDCC Z80, binary-compatible CPUs, and the SM83 (GBZ80). Z80, Z180, eZ80, Z80N, R800, μPD780, LH0080, SM83 (GBZ80), AP (Analogue Pocket). †1 Physical Hardware Validation : TODO Emulation Tested : Z80, SM83 - Integer arithmetic for types up to 128-bit width. †2 - Half and single-precision floating-point arithmetic in full compliance with the IEEE 754 standard. †3†4 - SDCC __sdcccall(1) /__sdcccall(0) compatible calling convention - Dual toolchain support: - ELF path (default): integrated assembler + ld.lld linker (--target=z80 ) - SDCC path: sdasz80 assembler + sdldz80 linker ( --target=z80-unknown-none-sdcc ) - ELF path (default): integrated assembler + - Cross-linking with SDCC-compiled code via elf2rel / rel2elf converters - GlobalISel-based code generation pipeline with register bank selection and instruction selection - Standard LLVM optimizations including constant folding, dead code elimination, copy propagation, and global register allocation - C/C++ : Supported via Clang included in this repository (C++ is experimental and untested) - Rust : llvm-z80/rust-z80 - Others : Potential support for other LLVM-based languages (Zig, TinyGo, EmbeddedSwift) - CMake 3.20+ - Ninja (recommended) - SDCC toolchain ( sdasz80 ,sdldz80 ): required for the SDCC toolchain path and cross-build testing On Linux and MacOS: git clone https://github.com/llvm-z80/llvm-z80.git On Windows: git clone --config core.autocrlf=false https://github.com/llvm-z80/llvm-z80.git If you fail to use the --config flag as above, then verification tests will fail on Windows. cmake -C clang/cmake/caches/Z80.cmake -G Ninja -S llvm -B build ninja -C build # Build llc + clang + lld + Z80Runtime Uses the integrated assembler and ld.lld linker. Produces ELF binaries. # Compile C to ELF clang --target=z80 -O1 input.c -o output.elf # Convert to flat binary and execute llvm-objcopy -O binary output.elf output.bin z88dk-ticks -trace output.bin Uses sdasz80 assembler and sdldz80 linker. Produces Intel HEX (.ihx) files. Useful for cross-linking with SDCC-compiled code. For more information on SDCC integration, refer LLVM-Z80 wiki # Compile C to Intel HEX (via sdasz80 + sdldz80) clang --target=z80-unknown-none-sdcc -O1 input.c -o output.ihx # Execute with z88dk-ticks makebin output.ihx output.bin z88dk-ticks -trace output.bin # Compile to .rel object file only (for linking with SDCC code) clang --target=z80-unknown-none-sdcc -c -O1 input.c -o input.rel # ELF path clang --target=sm83 -O1 input.c -o output.elf llvm-objcopy -O binary output.elf output.bin z88dk-ticks -mgbz80 -trace output.bin # SDCC path clang --target=sm83-nintendo-none-sdcc -O1 input.c -o output.ihx makebin output.ihx output.bin z88dk-ticks -mgbz80 -trace output.bin # LLVM IR → assembly → object → link (ELF path) clang --target=z80 -O1 -S -emit-llvm input.c -o input.ll llc -mtriple=z80 -O1 input.ll -o input.s clang --target=z80 input.s -o output.elf # LLVM IR → assembly → object → link (SDCC path) clang --target=z80 -O1 -S -emit-llvm input.c -o input.ll llc -mtriple=z80 -O1 -z80-asm-format=sdasz80 input.ll -o input.s sdasz80 -g -o input.rel input.s sdldz80 -i output.ihx input.rel build/lib/z80/z80_rt.lib Runtime libraries are built at build/lib/z80/ and build/lib/sm83/ . LLVM-Z80 stands on the shoulders of the following projects. - LLVM : The LLVM Compiler Infrastructure, upstream of this project. - LLVM-MOS : Another attempt to create an LLVM backend for a classic CPU, LLVM-Z80 has adopted many optimization passes from LLVM-MOS. - ajokela/LLVM-Z80 : Experimental GlobalISel based Z80 backend, this backend was developed based on this fork. - LLVM-eZ80 / ez80-clang : The most mature LLVM backend for the eZ80. - gb-llvm : An LLVM backend for the Nintendo Game Boy (SM83), including actual game ROM examples. - Rust-GB : Compiling Rust for the Game Boy, The reason this project was born. Many Other Experimental LLVM-Z80 Backends - †1Planned optimizations for specific CPU cores (eZ80, Z180, Z80N, etc.) and upcoming support for derivative architectures (Rabbit 2000, TLCS-90). - †2Primary support for i

Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.

공유

관련 저널 읽기

전체 보기 →