Compiler
Download
1 / 37

B84506024 Tien-Hsin Lee - PowerPoint PPT Presentation


  • 71 Views
  • Uploaded on

Compiler Term Project. B84506024 Tien-Hsin Lee. Features:. Expression: ‘+’, ‘-’, ‘*’, ‘/’, ‘%’, ‘<‘, ‘>’, ‘? :’ ‘+=‘, ‘++i’, ….. Basic type expression: integer, float, double, char Multiarray expression: A[i+3][j*4]+B[5] Nested structures expression: R.a.aa + S.b.bb

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' B84506024 Tien-Hsin Lee' - octavius-soto


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Compiler Term Project

  • B84506024 Tien-Hsin Lee


Features:

  • Expression: ‘+’, ‘-’, ‘*’, ‘/’, ‘%’, ‘<‘, ‘>’, ‘? :’

  • ‘+=‘, ‘++i’, …..

  • Basic type expression: integer, float, double, char

  • Multiarray expression: A[i+3][j*4]+B[5]

  • Nested structures expression: R.a.aa + S.b.bb

  • Function expression: i = f1*3 + f2

  • Function calls: double f1(int a, float b)

  • Control statements: for, while, do, if-else-then

  • Recursive function calls


Term project presentation
Term Project Presentation

  • 報告流程

    • Scanner & Parser

    • Symbol Table

    • Semantic Record Data Structure

    • Declaration

    • Expression

    • Control Flow


Scanner
Scanner

  • Input: scan.l Output: lexyy.c

    flex

  • What’s up in scan.l?

    • Token: yytext

    • check_type( ): return identifier or type_name

    • count( ): return line and column of a token

    • SlideCompile( ): the main function


Parser
Parser

  • Input: gram.y Output: gram_tab.h&

    yacc gram_tab.cpp

  • Declaration

  • Expression

  • Control Statement

  • I/O Statement


Symbol table
SYMBOL TABLE

  • Each function has its own symbol table

  • Global symbol table is visible everywhere



Symbol table2
Symbol Table

  • Push a symtab_class pointer into sym_stack while entering a function scope.


Semantic data structure
Semantic Data Structure

  • Semantic Record

    • Record kind

      • ID, TYPEREF, ID_LIST, DATAOBJECT, TOKENOBJECT, USERTYPE, PARAM_LIST, RECORDDEF, CONSTOPTION, ERRORREC

    • Semantic data


Dataobject in semantic record
DataObject in Semantic Record

  • OBJECTVALUE:

    Literal values including int,float..basic types

  • OBJECTNAME:

    Declared non-pointer variables

  • OBJECTARRAY:

    Declared array

  • OBJECTRECORD:

    Declared record


Dataobject more
DataObject …(more)

  • OBJECTTEMP:

    The most common type of DataObject that is carried in the semantic record. Whenever an expression is evaluated, it becomes an OBJECTTEMP. The code generated will be carried as well.


More about objecttemp
More about OBJECTTEMP...

  • How to become an OBJECTTEMP?

  • Why OBJECTTEMP needs to bring code?

    Due to the bottom up parsing design and different combination of binary operation.

  • When is the right time to generate code into the output file?


Expression
Expression

  • Unary_Operation:

    • +, -, ~, !, ++, --

  • TypeCast_Operation:

  • Arithmetic_Operation

    • *, /, %, +, -

  • Shift_Operation

    • >>, <<


Expression more
Expression…(more)

  • Relational_Operation:

    • <, >, <=, >=, !=, ==

  • Bitwise_Operation:

    • &, ^, |

  • Logic_Operation:

    • &&, ||

      ps. According to precedence rule


Expression1
Expression

  • Semantic Routines ( Call by Parser)

  • Process literal

    • TRUE ,FALSE, INTEGER, REAL

  • Process Operator

    • Type :Token ,Record operator

  • Eval_operator

    • Unary: not Binary : relation , +,-,*,/


Expression2
Expression

  • Sematic_Record

    • Record-Kind

      Error ,ID ,Array , Range,DataObject,Token(op)

      If_Stmt Do_For Do_While

      BlockFormat CyclicFormat

    • Semantic-data

    • Next : point to another Semantic _Record


Expression3
Expression

  • It must be DataObject .op. DataObject

    or .op. DataOject

  • DataObject has four types

    • ObjectName

    • ObjectValue

    • ObjecTemp

    • ObjectArray


Expression4
Expression

  • Case 1: ObjectValue .op. ObjectValue

    “ +-*/ ”=>Compute it directive and turn value

  • Case 2: ObjectArray operation

    • NotTemplate

      A(I1,I2,...In)=>A[I1][I2]....[In]

    • Template

      A(I1,I2,...In)=>hpf_read_A(I1,I2,..In,temp[J])


Expression5
Expression

  • Other Case:

    • ObjectName,ObjectTemp,ObjectValue

    • Use it Directively

    • Return temp[index]

  • Error Detect

    • simple process


Next presentation
Next Presentation

  • 報告流程

    • Scanner & Parser

    • Semantic Data Structure

    • Symbol Table

    • Expression

    • Control

    • Assignment

    • HPF





If statement
IF statement

IF expr THEN

IF expr THEN

IF expr THEN

ENDIF

ENDIF

ENDIF


Assignment

Left Hand Side

Variable

Array Element

Vector Operand

Right Hand Side

Value

Variable

Temp Variable

Array Element

Vector Operand

Assignment


Vector operand assignment
Vector Operand Assignment

V_C(1:5:2) = V_D(1:5:2)

for(index[0]=1,index[1]=3;index[0]<=5;index[0]+=2,index[1]++)

int_temp[index[1]] = V_D[index[0]];

for(index[0]=1,index[1]=3;index[0]<=5;index[0]+=2,index[1]++)

V_C[index[0]] = int_temp[index[1]];


Hpf directive

HPF Directive

TEMPLATE

PROCESSOR

ALIGN

DISTRIBUTE

Initialization & Close


Template
TEMPLATE

  • flag: IsTemplate , in attribute record

  • Setting IsTemplate flag in ALIGN & DISTRIBUTE

  • for Testing whether HPF_READ/WRITE

  • Connect type_descriptor to Semantic Record (id_type)


Processors
PROCESSORS

!HPF$ PROCESSORS P(3,5)

int hpf_P[3][5]

called in-main:void hpf_create_processor_P()

Using for loop.........

{hpf_create_processor(&hpf_P[][],X) ;}

X:P(x)(y) --> using for to do ()()


Align 1 2
ALIGN(1/2)

!HPF$ ALIGN A(I,J,K) WITH T(I,11*J-9)

  • Using In HPF_READ/WRITE

  • Need to calculate address of A on T

  • being called in hpf_read_A/hpf_write_A for actual distributed elements of A.


Align 2 2
ALIGN(2/2)

  • For each ALIGN, we generate a function calculating address.

  • Index_ArrayName(int dim, int_index_list)

    • dim : which dimension to compute

    • index_list : array index to convert

    • function_Name():set subFuncName;

    • gen_index_func():generate function header

    • gen_case():produce each dimension case.


Distribute 1 4
DISTRIBUTE(1/4)

!HPFS DISTRIBUTE T(BLOCK,CYCLIC(4)) ONTO P

  • Generate 3 functions for each distributed_array

    • hpf_declare_ArrayName

    • hpf_read_ArrayName

    • hpf_write_ArrayName

  • Handle distribute-data methods in dimension.

    • In Semantic Record :

      • BLOCK(X) : BLOCKFORMAT , block_value;

      • CYCLIC(Y) : CYCLICFORMAT, cyclic_value;


Distribute 2 4 hpf declare a
DISTRIBUTE(2/4) -- hpf_declare_A

  • Allocate memory space for array in each processor.

  • char* hpf_A[][];

  • Using multi-for-loop to declare array, according to Processor Number. hpf_declare(hpf_P[][],size,&hpf_A[][])


Distribute 3 4 hpf read write a
DISTRIBUTE(3/4) -- hpf_(read/write)_A

void hpf_(read/write)_A(int_index_list, int *data)

  • Call Index_Function to calculate ALIGN address.

  • Compute offset in each processor according to BLOCK and CYCLIC structure.

  • Call hpf_(read/write) of pvm


Distribute 4 4 generated codes
DISTRIBUTE(4/4) -- Generated Codes

A(1,2,3) = B(3,2,1)

hpf_read_B(3,2,1,&int_temp[2]);

hpf_write_A(1,2,3,int_temp[2]);


Initialization close
Initialization & Close

  • HPF_Initialization

    • Create Processor

    • Declare Array

  • HPF_Close

    • hpf_end(&hpf_P[][], ... );

    • pvm_exit();


Demo ....................

HPF Generated Code

&

Running on PVM


ad