hn.today

Making portable my unportable transputer C compiler

nanochess.org4 points0 comments
Screenshot of Making portable my unportable transputer C compiler

A found floppy contained a 1998 C compiler for the transputer that had been ported to DJGPP/G++ but would not compile on a modern 64-bit Mac M1 because the original code relied on 32-bit assumptions: pointers and integers were used interchangeably, FILE was treated as int, there were no function prototypes, and Small-C heritage stored structures and types in a byte pool with 32-bit words. The goal was to change as little as possible so the compiler would build on a 64-bit host while still being able to compile itself for the transputer using only features implemented by the compiler. Key portability problems included saving 32-bit pointers in integer arrays, hard-coded offsets for symbol table entries, and expression nodes that mixed pointer and integer uses.

The porting approach replaced fragile integer arrays with proper structs (including FILE fields and K&R-style prototypes), rewrote include-state handling to store pointers in a struct array, and converted many int-based type and node representations to typed structs or indices. The author incrementally fixed dozens of pointer/int errors (reporting reductions from dozens to 25, then 8, then 5, and finally zero), added small node fields instead of complex unions, and adjusted symbol tables to a struct-based layout. After resolving runtime issues (undefined NULL and use of fputs/stdout), the compiler assembled and produced a smaller, working cc2 executable; emitted assembler matched previous output and the compiler successfully ran in the transputer operating system.

Read on nanochess.org0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.