Skip to content

On Compiling Dinosaur Code (also Yay)

January 9, 2015

LCC dates from the 1980’s. It’s impressive that it is still useful today. It’s for sure the easiest way to get a full C compiler running for a new architecture.

I have sometimes thought it was funny that you had to compile apps from source on linux/unix rather than the windows/installer route but it does get you past a lot of architecture issues. The compiler/libraries/processor might change but your c code should still run.

There are limits, however. Compiling the lcc compiler itself, RCC went ok except for warnings that i was comfortable ignoring, like:

src/gen.c:376:22: warning: '&&' within '||' [-Wlogical-op-parentheses]
                if (p->x.equatable && requate(p) || moveself(p))
                    ~~~~~~~~~~~~~~~^~~~~~~~~~~~~ ~~
src/gen.c:376:22: note: place parentheses around the '&&' expression to silence
      this warning
                if (p->x.equatable && requate(p) || moveself(p))
                                   ^
                    (                           )

This is actually pretty useful and i could fix it or silence it maybe with -Wlogical-op-parentheses.

Compiling CPP generated more ominous warnings and some outright errors.

cpp/tokens.c:270:38: warning: format specifies type 'int' but the
      argument has type 'long' [-Wformat]
                fprintf(stderr, "(tp offset %d) ", tp-trp->bp);
                                            ~~     ^~~~~~~~~~
                                            %ld

is worrying because getting the format specifier wrong is generally very bad. maybe the default for ints is long?

void *
memmov2(void *dp, const void *sp, size_t n)

generated many many errors until i changed it to memmov2.

It did compile though, and seems to run fine except where it runs into dos style line endings. Interestingly it’s just cpp that objects, the compiler itself seems fine(so far). I may look at hacking cpp and lburg to ignore the dos carriage return characters instead of throwing an error.

As of Now, I have the preprocessor and compiler piped together and producing code that looks correct (so Yay)


Like a Rhinestone Compiler
; generated by lcc-xr18DH $Version: 5.0 - XR18DH $ on Fri Jan  9 11:58:24 2015

SP:	equ	2 ;stack pointer
memAddr: equ	14
retAddr: equ	6
retVal:	equ	15
regArg1: equ	12
regArg2: equ	13
	listing off
	include lcc1802ProloDH.inc
	listing on
_PIN4:
	db 0
_mysetqOn:		;framesize=2
	seq
L1:
	Cretn

_main:		;framesize=6
	reserve 4
	lbr L5
L4:
	Ccall _mysetqOn
	ldaD R12,500; reg:acon
	Ccall _delay
	Ccall _setqOff; CALLI2(ar)
	ldaD R12,500; reg:acon
	Ccall _delay
L5:
	lbr L4
L3:
	release 4
	Cretn

_delay:		;framesize=10
	pushr R6
	pushr R7
	reserve 4; save room for outgoing arguments
	cpy2 R7,R12; function(2054) 1
	ldaD R6,1; reg:acon
	lbr L11
L8:
	Ccall _oneMs; CALLI2(ar)
L9:
	incm R6,1
L11:
	jneU2 R6,R7,L8; NE
L7:
	release 4; release room for outgoing arguments
	popr R7
	popr R6
	Cretn

_olduinoincluder:		;framesize=2
	include olduino.inc
L12:
	Cretn

	include lcc1802EpiloDH.inc
	include IO1802.inc
Advertisements

From → LLVM

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: