drh / lcc

The lcc retargetable ANSI C compiler

Home Page:https://drh.github.io/lcc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Targeting the CP1610 CPU for Intellivision possible?

zezba9000 opened this issue · comments

Hey we're having a discussion over at Atariage about the possibility of getting a C compiler to target the "CP1610" CPU. Ref: http://atariage.com/forums/topic/286670-sdcc-pic16-c-compiler/?p=4192163

Its a 16 bit CPU where sizeof(char) = sizeof(int) = sizeof(void*) = 1.
Is re-targeting for this CPU possible and if so are there any good docs or reference for what parts need to be changed in LCC to make this happen?

So everything is really 16-bits? ... run ops c=2 s=2 i=2 l=2 h=2 f=2 d=2 x=2 p=2 to generate the proper %term statements for the lburg file and update the sizes in the IR record appropriately. If LCC can't deal with non-8 bit chars, you could leave it as 8-bit and modify the lexer to essentially #define char int.

Yep everything is addressed and stored as 16 bits.
Is the only file that needs to be looked at "lex.c" for this modification you're suggesting?
In short change the "int gettok(void)" method to change any findings of "char" to "int" tokens?

Or can I just change "token.h" at line:
FROM: xx(CHAR, 3, 0, 0, 0, CHAR, "char")
TO: xx(INT, 3, 0, 0, 0, CHAR, "char")

You can run rcc -target=symbolic -charmetric=2,2,2 -longmetric=2,2,2 -ptrmetric=2,2,2 to get a sense for what happens if you just give them that size. (rcc is the compiler that runs after the preprocessor and generates assembly language.) string literals get a little screwed up -- they're packed but then padded with extra 0s at the end instead of inline. Try playing with that and see what happens.

Sadly i don't think LCC is really suitable for this, LCC is quite "happy" to put things temporarily into memory in the symbolic dumps at least and this would probably hurt performance quite badly on slower CPU's (maybe i missed checking optimized builds?). Might be worth checking out SDCC (small device C compiler that has many backends) or the old PCC compiler to see if they are easy to adapt. As long as you don't need C++ there is quite a few options and while LCC is attractively designed this tendency for temporaries would not fly with those old CPU's. (If you want good performance with games that i suspect is the target?)