low level virtual machine c# compiler senior project proposal presentation (ppt)

38
Prabir Shrestha (4915302) Myo Min Zin (4845411) Napaporn Wuthongcharernkun (4846824) Senior Project Proposal

Upload: prabirshrestha

Post on 16-Nov-2014

898 views

Category:

Documents


3 download

DESCRIPTION

Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation

TRANSCRIPT

Page 1: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

Prabir Shrestha (4915302)Myo Min Zin (4845411)

Napaporn Wuthongcharernkun (4846824)

Senior Project Proposal

Page 2: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

2

Objective Motivation Scope The Framework Gantt Chart Questions and Answers

Page 3: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

3

A Naive Compiler

Page 4: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

4

Back-end

Front-end

Page 5: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

5

Evolution of Computer Programming Managed Code vs Unmanaged Code Bulky .NET Framework Operating Systems written in managed code

Page 6: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

6

Why Low Level Virtual Machine?– Source Language independent – Retargetable code generator– Supports various architectures• X86, PowerPC, ARM

– Open source

Page 7: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

7

It is not– a compiler,– a virtual machine alike JVM, .NET Framework

It is– A modular compiler infrastructure • a collection of (C++) libraries and tools to help in

building compilers, debuggers, program analyzers etc.

Page 8: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

8

Commonly referred to as LLVM Started as academic project at University of

Illinois on 2002. Current development mainly by Apple Inc. Projects related to LLVM– Clang: C/C++ front-end; aims to replace gcc– OpenGL engine in Mac OS X 10.5– used by Adobe Systems Inc., Nvidia, Sun

Microsystems Laboratories

Page 9: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

9

Keywords- Categories Operators and Special Characters Source Language Features

Page 10: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

10

Types

Conditionals

Loops

bool char float int string class struct enum object

if else

for while do

Page 11: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

11

Single Inheritance

Encapsulation

Overloading Operators

Method Overloading / Method Overriding

base

private protected public

operator

override virtual

Page 12: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

12

Indexing & Properties(Accessor/ Mutator)

Modifiers

Type Casting

static sealed

get set value

explicit implicit

Page 13: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

13

base

bool

break

char

class

const

continue

do

else

enum

explicit

extern

false

float

for

get

if

implicit

int

namespace

new

null

operator

object

public

override

private

protected

return

sealed

set

sizeof

static

string

struct

this

true

typeof

using

virtual

void

while

value

is

Page 14: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

14

Operators & Special characters supported

x.y x-- < != *= ||

f(x) --x > (T) x /=

a[x] + <= = *

x++ - >= += /

++x ! == -= &&

Page 15: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

15

Single class Inheritance Encapsulation Overloadable Operators Method Overloading/Overriding Properties (Accessors / Mutators)

Page 16: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

16

Overall Process Scanner Parser Semantic Analyzer Code Generator Assembling and Linking

Page 17: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

17

Page 18: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

18

Page 19: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

19

Tokenization Process- Identifying the tokens from the input stream.

Skip meaningless characters, white spaces, Lexical Analysis- Checking for Lexical Errors Using Coco/R tool the scanner and parser are

generated at the same time.

Page 20: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

20

Syntax Analysis is performed at this phase. Coco/R generates a recursive descent parser.– Top down parsing method – Procedural-like functions– Generally for each production rule, one procedure

is generated.

Accepts Grammar in LL(k) Form – LL(1) Conflict Resolvers may be needed

LL: Left to Right, Left most Derivation

Page 21: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

21

Parser Error-Recovery Techniques– Synchronization– Weak Symbols

Synchronization Technique– SYNC symbols are placed in the grammar, where

there’s unlikely to be errors.

– Upon error detection, parser skips input symbols until it finds one that is expected at a synchronization point.

Page 22: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

22

Weak Symbols- Placed in front of tokens that are prone to error, often misspelled or missing.

- When error is encountered, reports error and can jump to next synchronization point.

Page 23: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

23

Synchronization Example

Weak Symbols ExampleEnumBody = "{" EnumMember { WEAK "," EnumMember} "}".

TypeDecl= SYNC ( "class" ident [ClassBase] ClassBody [";"] | "struct" ident [Base] StructBody [";"] | "enum" ident [":" IntType] EnumBody [";"] ).

Page 24: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

24

Page 25: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

25

A phase that follows after the generation of parser

To check semantic error once the lexical and syntax errors have been checked

Examples:– type checks, scoping of variable, constant values

not being changed, no redefinitions of a classes, method and member variables

Page 26: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

26

Page 27: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

27

After AST and semantic analysis Generating LLVM Intermediate Representation (IR)

Page 28: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

28

Language and Target independent Designed to support multiple language

frontends Represents the key operations of ordinary

processors Avoids machine specific constraints– physical registers, pipelining

Page 29: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

29

Does not define runtime and OS system functions– these are defined by runtime libraries

IR is a typed Virtual Instruction Set– unbounded number of registers– operations are low level– checked for consistency

Page 30: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

30

Usually 3-address code%temp2 = add i32 %temp0, %temp1

Instructions are typed Instructions are polymorphic Usually Static Single Assignment (SSA) Form–new register for each result–uses phi (ɸ) functions–code generator tries to store these variables in same real registers

Page 31: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

31

Example

i = 100 * 20 * 3 i = 6000

Constant Folding

Simplifies constant expressions at compile time

Page 32: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

32

Exampleint x = 7int y = 14 – x

int x = 7int y = 14 - 7

int x = 14int y = 7

Constant Propagation Substituting the values of known constants in

expressions at compile time

Page 33: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

33

Examples

y = x / 8 y = x >> 3

y = x * 64 y = x << 6

y = x * 2 y = x + x

Strength Reduction Costly operation is replaced with equivalent but

less expensive operation

Page 34: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

34

Examples

x = y + 0 x = y

y = z * 1 y = z

Elimination of Useless Instruction Drop instructions that do not modify any memory

storage

Page 35: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

35

Page 36: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

36

User Phases

Page 37: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

37

Page 38: Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation (ppt)

38