You're famous now: https://hackaday.com/2019/04/26/the-no- ... -compiler/
Rudimentary vCPU support for the lcc C compiler
Forum rules
Be nice. No drama.
Be nice. No drama.
Re: Rudimentary vCPU support for the lcc C compiler
I've just merged Pat's branch into the Gigatron repo, with preservation of its git history. Hopefully I didn't goof up because I forgot how I did it last time. (For future reference, I used instructions from here.)
We "promoted" it directly to Utils/lcc/, even though it's still very much work in progress. It helps collaboration to have it in a place where we want it to end up eventually. Besides, there's little expectation that these changes will ever find their way back upstream into the original lcc code base...
Libs/ will be a place for libraries. Makefiles and README's etcetera still need attention.
Expect things to break once in a while
We "promoted" it directly to Utils/lcc/, even though it's still very much work in progress. It helps collaboration to have it in a place where we want it to end up eventually. Besides, there's little expectation that these changes will ever find their way back upstream into the original lcc code base...
Libs/ will be a place for libraries. Makefiles and README's etcetera still need attention.
Expect things to break once in a while
Re: Rudimentary vCPU support for the lcc C compiler
With one command from the root directory of the gigatron-rom repository we can build lcc:
All of lcc is now in a the directory Utils/lcc/build/. The compiler has many subprograms and files, with lcc itself being the driver for it all. We can simply keep everything there.
Next compile the test program. The Gigatron backend requires Python 3.6 or up to be installed on the system.
Now we have a program that we can send to a Gigatron with Utils/sendFile.py (Python 2...!), or load into an emulator.
[Edit: updated paths for changes made afterwards]
Code: Select all
$ make lcc
mkdir -p Utils/lcc/build
cd Utils/lcc && env HOSTFILE=etc/gt1h.c make all
cc -g -c -Isrc -o build/main.o src/main.c
cc -g -c -Isrc -o build/alloc.o src/alloc.c
cc -g -c -Isrc -o build/bind.o src/bind.c
cc -g -c -Isrc -o build/dag.o src/dag.c
[
...lots of output and compiler warnings snipped...
]
cp rt.py build/rt.py
cp asm.py build/asm.py
$
Next compile the test program. The Gigatron backend requires Python 3.6 or up to be installed on the system.
Code: Select all
$ make Libs/Example.gt1
Utils/lcc/build/lcc -ILibs -c Libs/sys/ClearScreen.c -o Libs/sys/ClearScreen.o
Utils/lcc/build/lcc -ILibs -c Libs/sys/Newline.c -o Libs/sys/Newline.o
Utils/lcc/build/lcc -ILibs -c Libs/sys/Random.c -o Libs/sys/Random.o
Utils/lcc/build/lcc -ILibs -c Libs/stdio/putchar.c -o Libs/stdio/putchar.o
Utils/lcc/build/lcc -ILibs -c Libs/stdio/puts.c -o Libs/stdio/puts.o
Utils/lcc/build/lcc -ILibs -c Libs/Example.c -o Libs/Example.o
Utils/lcc/build/lcc -ILibs Libs/sys/ClearScreen.o Libs/sys/Newline.o Libs/sys/Random.o Libs/stdio/putchar.o Libs/stdio/puts.o Libs/Example.o -o Libs/Example.gt1
$ ls -l Libs/Example.gt1
-rw-r----- 1 marcelk staff 743 Apr 29 22:59 Libs/Example.gt1
$
[Edit: updated paths for changes made afterwards]
Re: Rudimentary vCPU support for the lcc C compiler
Our new C library now has rudimentary versions for sprintf() and printf(). From the GitHub commit message:
Output works as expected:
Libs/Example.c uses these functions to write a welcome message to the screen and format some numbers before turning itself into a TV Typewriter. Many of the flags and format specifiers are working already. For example:libc: printf/sprintf family
- Example.c: demonstrate sprintf and printf for %d, %u, %s and %c
- lcc: change argument order to support va_arg() (issue #62)
- lcc: caller of variadic function pops the "extra" arguments
- lcc: fix bug in swapping comparison operands (issue #63)
- stdarg: va_start, va_arg, v_end (and va_sarg, see comments issue #62)
- ctype: isdigit
- stdio: fprintf, fputc, fputs, printf, putchar, puts, snprint, vfprintf, vprintf, vsnprintf, vsprintf
- Makefile: fix mixup between LCC and native compiler
Code: Select all
ClearScreen();
// Demo printf and varargs
printf("%d %d %u\n", 1972, -327, UINT_MAX);
printf("%07d %07d %07u\n", 1972, -327, UINT_MAX);
printf("%+7d %+7d %+7u\n", 1972, -327, UINT_MAX);
printf("%+07d %+07d %+07u\n", 1972, -327, UINT_MAX);
puts("Ready");
- Attachments
-
- Example.gt1
- Compiler Example.c
- (3.61 KiB) Downloaded 362 times
-
- Example.c
- Using printf/sprintf
- (2.21 KiB) Downloaded 388 times
Re: Rudimentary vCPU support for the lcc C compiler
Some updates since last week:
This holds for all operators implemented with helper functions: <<, >>, *, / and %.
- Signed and unsigned division and remainder are working(*). Signed / and % follow the C99 rules for negative operands (ANSI C was less demanding in this area)
- stdout is now a true FILE object, with a tiny one-line buffer. fflush() works
- The size argument for vsnprintf() works, and with that, we have snprintf() obeying it as well
- The assembler can do offset calculations. This enables the whole assortment of constant expression initialisers
- Some bugs solved regarding code generation for page hopping
- The linker gives an error message when a function remains undefined, instead of a Python stack dump
Code: Select all
a * (b / c); // won't work yet.
Re: Rudimentary vCPU support for the lcc C compiler
Hi all, my first post here. Thank you for doing this. It is fascinating!
This also works on Ubuntu desktop and even Ubuntu on Windows 10 (Linux shell). First I tried to clone the repository on Windows, but gcc threw many strange errors. After that, cloned it right on the Linux shell, installed bison (sudo apt install bison) and it worked. Not sure what else needs to be installed, because I already had Python et al installed there.marcelk wrote: ↑29 Apr 2019, 21:15 With one command from the root directory of the gigatron-rom repository we can build lcc:All of lcc is now in a the directory Utils/lcc/build/. The compiler has many subprograms and files, with lcc itself being the driver for it all. We can simply keep everything there.Code: Select all
$ make lcc mkdir -p Utils/lcc/build cd Utils/lcc && env HOSTFILE=etc/gt1h.c make all cc -g -c -Isrc -o build/main.o src/main.c cc -g -c -Isrc -o build/alloc.o src/alloc.c cc -g -c -Isrc -o build/bind.o src/bind.c cc -g -c -Isrc -o build/dag.o src/dag.c [ ...lots of output and compiler warnings snipped... ] cp rt.py build/rt.py cp asm.py build/asm.py $
Next compile the test program. The Gigatron backend requires Python 3.6 or up to be installed on the system.
Now we have a program that we can send to a Gigatron with Utils/sendFile.py (Python 2...!), or load into an emulator.Code: Select all
$ make Libs/Example.gt1 Utils/lcc/build/lcc -ILibs -c Libs/sys/ClearScreen.c -o Libs/sys/ClearScreen.o Utils/lcc/build/lcc -ILibs -c Libs/sys/Newline.c -o Libs/sys/Newline.o Utils/lcc/build/lcc -ILibs -c Libs/sys/Random.c -o Libs/sys/Random.o Utils/lcc/build/lcc -ILibs -c Libs/stdio/putchar.c -o Libs/stdio/putchar.o Utils/lcc/build/lcc -ILibs -c Libs/stdio/puts.c -o Libs/stdio/puts.o Utils/lcc/build/lcc -ILibs -c Libs/Example.c -o Libs/Example.o Utils/lcc/build/lcc -ILibs Libs/sys/ClearScreen.o Libs/sys/Newline.o Libs/sys/Random.o Libs/stdio/putchar.o Libs/stdio/puts.o Libs/Example.o -o Libs/Example.gt1 $ ls -l Libs/Example.gt1 -rw-r----- 1 marcelk staff 743 Apr 29 22:59 Libs/Example.gt1 $
[Edit: updated paths for changes made afterwards]
Re: Rudimentary vCPU support for the lcc C compiler
When TTL programmers get bored spending too much time on terminal applications. This interactive 3D demo is a single page C program and should run ok on ROM versions all the way back to ROMv1.
Video link: https://youtu.be/KxZI28kUBgQ
Screen shot:
Video link: https://youtu.be/KxZI28kUBgQ
Screen shot:
- Attachments
-
- Horizon.gt1
- (5.51 KiB) Downloaded 316 times