abstract syntax description language(asdl ) in lcc

22
Abstract Syntax Description Language(ASDL) In LCC By: Bagher Salami Advanced Computer Architecture -Department of Computer Engineering-Ferdowsi University Of Mashhad February 2012

Upload: tyrell

Post on 20-Jan-2016

64 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 2: Abstract Syntax Description  Language(ASDL ) In LCC

• 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

Page 3: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 4: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 5: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 6: Abstract Syntax Description  Language(ASDL ) In LCC

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)

Page 7: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 8: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 9: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 10: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 11: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 12: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 13: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 14: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 15: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 16: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 17: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 18: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 19: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 20: Abstract Syntax Description  Language(ASDL ) In LCC

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

Page 21: Abstract Syntax Description  Language(ASDL ) In LCC

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.

Page 22: Abstract Syntax Description  Language(ASDL ) In LCC

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