abstract syntax description language(asdl ) in lcc
DESCRIPTION
Abstract Syntax Description Language(ASDL ) In LCC. By: Bagher Salami. Outline. Compiler background Retargetable compilers Little C compiler (lcc) Compiler Importance What is ASDL? The lcc Code-Generation Interface Dividing lcc Evaluation Conclusions. Assem- bler. OBJ. Linker. - PowerPoint PPT PresentationTRANSCRIPT
Abstract Syntax Description Language(ASDL) In LCC
By:Bagher Salami
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
• Compiler background• Retargetable compilers• Little C compiler (lcc)• Compiler Importance• What is ASDL?• The lcc Code-Generation Interface• Dividing lcc• Evaluation• Conclusions
Outline
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
2
Compiler background
Frontend IROptimi-zations
IR Backend ASM
ASMAssem-bler
OBJ Linker EXE
Compiler phases
• Compiler is a quite complex software package
• Compilers must be particularly reliable
• Design requires separation into multiple phases
• Compiler followed by Assembler, Linker
LIBS
Csrc
3
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Retargetable compilers
source code
ASM code
CompilerCompiler
source code
ASM code
CompilerCompiler
processormodel
“Classical” compiler Retargetable compiler
4
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Little C compiler (lcc)
• “Lightweight” public-domain C compiler (Princeton Univ.)
• ANSI C frontend, few built-in optimizations
• Generate compilers are very fast
• Mainly for RISC and CISC targets
• Small amount of source code
• Excellent documentation
5
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Compiler Importance
High-quality compilers are essential for researches such as: •computer architecture
are required to run benchmarks for evaluating new ideas in architecture
•programming languages and environmentscompilers for new languages need optimizers, code
generators
6
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
So we need to enhance the compiler performance (enhance lcc performance)So we need to enhance the compiler performance (enhance lcc performance)
ASDL• ASDL is a language for specifying the tree data structures
in compiler IR.• The ASDL generator reads an ASDL specification and
generates code to construct, read, and write instances of the trees specified.
• Using ASDL permits a compiler to be decomposed into semi-independent components.
7
Parser
Lexer
Toke
ns
ASTSemanticAnalysis
AS
T
Translate IR OPT1
....
IR
IR OPTn
IR
CodeGen
AST IR
GlueGenerator
GlueDescription
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
ASDL
This experience is valuable for two reasons:
1.lcc is perhaps the simplest C compiler available and thus provides a `basis' test case for ASDL.
2.lcc wasn't designed to be decomposed into reusable program components, so doing so suggests how difficult it is to retrfiot ASDL into existing compilers.
8
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
ASDLAdvantage of using ASDL:partition a compiler into several independent programs
A front end reads source code and builds an IR (pickle) using the asdlGen. Subsequent phases read and write pickles as necessary.
pickles are independent of both language and host platform. Thus, compiler phases can be written in whatever ASDL-supported language best suits. 9
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
ASDLASDL is such a simple language that examples suffice to explain nearly all of its features.
The following ASDL specification describes an IR for a language of arithmetic expressions, assignment statements, and print statements.
10
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
ASDLGiven an ASDL specification, asdlGen emits an interface (IR.h) and an implementation (IR.c).The snippets from the interface (IR.h) that writes asdlGen.
11
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
ASDL
The implementation, (IR.c), contains thedefinitions for the functions declared in IR.h. For example, the constructor IR_SEQ is
12
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
The lcc Code-Generation Interface
Communication between lcc's target-independent front end and its target-dependent back ends is specified by a small code-generation interface.
This interface consists of:• a few shared data structures• 33-operator tree IR that represents executable code• 18 procedures that manipulate and modify shared data structures
The shared data structures include:• tree nodes• symbol-table entries• types
13
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
The lcc Code-Generation Interface
The 33 tree IR operators
14
Each of these generic operators can be specialized by appending an operand type suffix and a size in bytes. The 6 type suffixes are:F floatI integerU unsignedP pointerB `block' (aggregate)V void
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
The lcc Code-Generation Interface
The purpose of the 18 code-generation procedures.
15
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Dividing lcclcc is a monolithic compiler: back ends can make calls to functions provided by the front end, and the front end reads data structures written by the back ends.
16
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Dividing lcc• lcc is small, it omits some components, most notably a
global optimizer.
• One way to add more functionality is to split lcc into a separate front end and back ends so that an optimizer can be run between these programs.
• This design would also make it easier to use lcc in research projects.
17
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Dividing lcc• Splitting lcc into two separate programs requires either
massive revisions.
• ASDL facilitates dividing lcc into separate programs with no change to the code-generation interface. So, the existing back ends can be used unmodified.
18
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
Evaluation
19
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
conclusions• Revising lcc to use ASDL was provide an improved
platform for compiler-related research using lcc.
• It is now possible to insert additional passes into the compilation pipeline without modifying or even understanding the front and back ends.
• The obvious first candidate is a global optimization pass
20
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
References
21
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2
[1] D. R. Hanson. Early experience with ASDL in lcc. Software -Practice and Experience, 29(5):417–435, 1999.
[2] P. Ienne and R. Leupers, editors. Customizable EmbeddedProcessors. Morgan Kauffman, 2006.
Thank You !Thank You !
22
Ad
van
ced
Co
mp
ute
r A
rch
itect
ure
-D
ep
art
me
nt
of
Co
mp
ute
r E
ng
ine
erin
g-F
erd
ow
si U
niv
ers
ity O
f M
ash
ha
dF
eb
rua
ry 2
01
2