translator structure lexer parser expression binaryexpression unaryexpression declaration function...
TRANSCRIPT
![Page 1: Translator Structure Lexer Parser Expression BinaryExpression UnaryExpression Declaration Function Statement IfStatement.... AST Structure Cw Code TranslationUnit](https://reader036.vdocuments.site/reader036/viewer/2022082612/5697bf721a28abf838c7ec41/html5/thumbnails/1.jpg)
Translator Structure
LexerParser
ExpressionBinaryExpressionUnaryExpression
DeclarationFunction
StatementIfStatement
....
AST StructureCw Code
TranslationUnit
VarDeclara-tion
FunctionDefini-tion
Identifier VariableDeclara-tion
Compound-Statement
....
Output: AST
Driver
Cw Translation Pass
Other passesin the future
Load IntrinsicsStore Intrinsics
BinaryOperator Intrinsics....
Intrinsic Emitter
Intrinsics inCanonical
Format
Input
Uses
Translated ASTFinal Out-
put
![Page 2: Translator Structure Lexer Parser Expression BinaryExpression UnaryExpression Declaration Function Statement IfStatement.... AST Structure Cw Code TranslationUnit](https://reader036.vdocuments.site/reader036/viewer/2022082612/5697bf721a28abf838c7ec41/html5/thumbnails/2.jpg)
Translation example(Actual Translation)
{ vector int a[100][8], b[100], c[100][8]; c[:][:] = a[:][:] + b[:];}
{ int a[100][8], b[100], c[100][8]; vec4x32 **p_vec_a = (vec4x32**)a; vec4x32 *p_vec_b = (vec4x32*)b; vec4x32 **p_vec_c = (vec4x32**)c; for( cw_i0 = 0; cw_i0 < 100; cw_i0++){ for( cw_i1 = 0; cw_i1 < 8/4; cw_i1++){ vec4x32 vec_a; vec4x32 vec_b; vec_a = vec4x32Load(p_vec_a[cw_i0] + cw_i1); vec_b = vec4x32Load(p_vec_b + cw_i1); vec_a = vec4x32Add(vec_a, vec_b); vec4x32Store(p_vec_c[cw_i0] + cw_i1, vec_a); } }}
![Page 3: Translator Structure Lexer Parser Expression BinaryExpression UnaryExpression Declaration Function Statement IfStatement.... AST Structure Cw Code TranslationUnit](https://reader036.vdocuments.site/reader036/viewer/2022082612/5697bf721a28abf838c7ec41/html5/thumbnails/3.jpg)
• Collect vector symbols– a, b, c
• Find Assignment Expressions that involve vector symbols– exp = exp
• Check LHS if it is Array-Access expression– Identifier[exp][exp] ...
• Check types of LHS and RHS to know declared array size, dimension– RHS traverses sub-expressions until it reaches Identifier– Identifier lookup symbol table to find out declared types
• Traverse up ancestor ASTNodes until it finds the SymbolTable containing matching symbol• compute dimension and type
• Translate RHS– Translate Sub-expressions first
• Translation of sub-expression returns vector identifier presented in the innermost for-loop (vec_a, vec_b..)
– Translating ArrayAccess • Declare pointer variable for base of array-access• Add pointer specifier as many as num-dimension of declared symbol• Create for-loop nested as many as num-dimensions of declared symbol• Put LOAD intrinsic in the innermost loop
• Translate Assignment Expression– put store intrinsics at the end of innermost for-loop body, which is created during RHS
translation
{ vector int a[100][8], b[100], c[100][8]; c[:][:] = a[:][:] + b[:];}
Simplified Step