Princeton CS ![]() ![]() ![]() |
The lcc 4.1 distribution includes the files necessary to emit ASDL, as described in:
D. R. Hanson, Early Experience with ASDL in lcc, SoftwarePractice and Experience 29 (5), 417-435, 4/25/99.
(120 KB).
Slides of the talk at the National Compiler Infrastructure Tutorial, PLDI'98, 6/19/98.(71KB).
Rebuilding lcc 4.1 to include ASDL support on UNIX platforms involves the following steps.
ASDL_HOME
to the root of your ASDL
installation directory.src/inits.c
:void init(int argc, char *argv[]) { {extern void input_init(int, char *[]); input_init(argc, argv);} {extern void main_init(int, char *[]); main_init(argc, argv);} {extern void prof_init(int, char *[]); prof_init(argc, argv);} {extern void trace_init(int, char *[]); trace_init(argc, argv);} {extern void type_init(int, char *[]); type_init(argc, argv);} {extern void x86linux_init(int, char *[]); x86linux_init(argc, argv);} {extern void asdl_init(int, char *[]); asdl_init(argc, argv);} }
custom.mk
, creating one if necessary.EXTRALIBS=-L$(ASDL_HOME)/lib/asdlGen -lasdl -lcii EXTRAOBJS=$(BUILDDIR)/asdl$O $(BUILDDIR)/rcc$O all:: $(BUILDDIR)/pass2$E $(BUILDDIR)/2html$E
These lines augment the rules in the makefile
so that it generates $(BUILDDIR)/rcc.h
and $(BUILDDIR)/rcc.c
from the ASDL grammar for lcc pickles in src/rcc.asdl
,
compiles these generated files, and compiles src/asdl.c
(the ASDL "back end"), src/pass2.c
(reads pickles, emits assembly language), and src/2html.c
(reads pickles, emits HTML).
% make CUSTOM=custom.mk all
This step builds a new rcc
(the compiler proper), pass2
, and 2html
.
pass2
to /usr/local/bin
, or a plant a symbolic link to it
as suggested in Installation on UNIX.
You can also copy to link to 2html
, which reads ASDL pickles and emits HTML.Once you've installed the compiler, you can generate ASDL pickles by giving the -Wf-asdl
and -S
options, e.g.,
% lcc -Wf-asdl -S -o wf1.pickle tst/wf1.c
As shown, use the -o
option to specify the file name for the pickle; if
you omit this option, the pickle lands in, for example, wf1.s
.
pass2 reads a pickle and emits assembly language, as usual, e.g.,
% pass2 wf1.pickle wf1.s % lcc wf1.s
These commands generate assembly code from wf1.pickle
, and assemble and
link it into a.out
. The assembly code generated by pass2
is often identical to that generated by lcc directly. When there are differences, they are
usually due to differences in compiler-generated label numbers.
Rebuilding lcc 4.1 on Windows NT/95/98 to support ASDL involves the analogous steps.
The Windows makefile, makefile.nt
, doesn't
support includes, so you'll have to edit the file to add the EXTRALIBS
and EXTRAOBJS
definitions and the additional prerequisites for the all
target.