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

Post on 16-Nov-2014

899 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Low Level Virtual Machine C# Compiler Senior Project Proposal Presentation

TRANSCRIPT

Prabir Shrestha (4915302)Myo Min Zin (4845411)

Napaporn Wuthongcharernkun (4846824)

Senior Project Proposal

2

Objective Motivation Scope The Framework Gantt Chart Questions and Answers

3

A Naive Compiler

4

Back-end

Front-end

5

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

6

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

– Open source

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.

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

9

Keywords- Categories Operators and Special Characters Source Language Features

10

Types

Conditionals

Loops

bool char float int string class struct enum object

if else

for while do

11

Single Inheritance

Encapsulation

Overloading Operators

Method Overloading / Method Overriding

base

private protected public

operator

override virtual

12

Indexing & Properties(Accessor/ Mutator)

Modifiers

Type Casting

static sealed

get set value

explicit implicit

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

14

Operators & Special characters supported

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

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

a[x] + <= = *

x++ - >= += /

++x ! == -= &&

15

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

16

Overall Process Scanner Parser Semantic Analyzer Code Generator Assembling and Linking

17

18

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.

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

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.

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.

23

Synchronization Example

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

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

24

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

26

27

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

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

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

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

31

Example

i = 100 * 20 * 3 i = 6000

Constant Folding

Simplifies constant expressions at compile time

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

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

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

35

36

User Phases

37

38

top related