Subject: [1401_software] Small-C cross compiler for the 1401
From: Luca Severini < lucaseverini @mac . com >
Date: Fri, Mar 13, 2015 1:07 am
On this dropbox link https://www.dropbox.com/s/0vma85fpmt2197s/compiler.zip?dl=0 you can download the version 1.0 (beta) of the Small-C compiler for the IBM 1401.
It is written in Java using JavaCC, the well-known parser and lexical analyzer generator, and run as a command line program. Java version 1.6 or later is required. It runs on Mac, Windows and Linux (or, in theory wherever there is a compatible java VM available).
The compiler accepts a Small-C c file and outputs a complete autocoder .s file ready to be assembled with ROPE or autocoder.
Internally there is a preprocessor doing its typical work than passing a temp file to the real compiler.
Once unzipped the folder you can see inside it a java executable, a readMe and three folders.
The snippets folder contains some 1401 autocoder code the compiler include to the output to perform certain operations.
The nonstdlib folder contains few header files mostly for io and string operations. Something close to the standard C library files. They are still incomplete. There is just a simple printf able to print %c, %d and %s arguments and little more.
The c_files folder contains some C files we have used for testing and as examples.
The README.TXT file is the standard java readMe file explaining how to execute a java program plus the syntax to compile one of the examples:
java -jar Small-C.jar -v -h nonstdlib -D IBM1401 c_files/test.c
If the compilation is successful a test.s file will be written in the same folder containing the C file.
There is no inline help yet nor a manual of some sort so here is the list of the arguments other than the path to the C file which must be the last one.
-v / -v1 / -v2 : generates a more verbose output
-h path : uses the path to look for include files
-o file : outputs the assembly code to that file
-k : doesn't delete the temporary preprocessed C file, generated by the preprocessor, which is passed to the compiler
-X : prints some more messages to stdout (not very useful)
-D definition / -D definition=value : sets the definition (definition and value can be any alphanumeric string).
Regarding the definitions, STACK, CODE and DATA define the memory location where the stack, the code and the data (variables and constants) is placed.
By default they are STACk=400, DATA=2000, CODE=3000.
My class-mate Matt and I, are still working to improve it on many aspects. We already have a long list of things to fix, improve and add... ;-)
This compiler was my idea for the final project of the CS153 "Compiler Design" class last fall semester at SJSU. The class is taught by prof. Ron Mak who many of you already know as the original designer and developer of ROPE IDE.
I want to remember that I worked on this compiler together with two teammates, Matt and Sean. Matt who, like me, is still a SJSU student, is working with me in this semester. Sean just graduated last December and is now working full-time at InsideMaps.
As those of you who know Autocoder assembly can see, the generated code is still far from perfect and some choices we decided are sub-optimal because of the short and tight time we had to complete it toward the end of the semester.
Some problems has been already fixed in the first month after we completed the very first version but it still uses the stack way too much wasting some precious memory space. Reporting of syntax error is almost completely absent. If you don't see the output file that probably means something was wrong in the source.
The switch statement and some other bitwise operations aren't implemented yet.
Small-C (http://en.wikipedia.org/wiki/Small-C) is a subset of C developed to let the microcomputers of the late 70' and 80' compile C programs in their little memory so few things are missing from standard ansi C. And some more are missing because we didn't have enough time to implement them. But we will!
I'm pretty sure there are many other problems too and I hope some of you will find them and let us know.
Any note or comment on how to fix and improve things are very welcome of course.
I apologize in advance for my English... ;-)
return to main page