30 likes | 218 Views
Translator Structure. Cw Code. AST Structure. Input. Expression BinaryExpression UnaryExpression Declaration Function Statement IfStatement . Lexer Parser. Uses. Intrinsics in Canonical Format. Output: AST. Driver. TranslationUnit. VarDeclaration. FunctionDefinition.
E N D
Translator Structure Cw Code AST Structure Input ExpressionBinaryExpressionUnaryExpression DeclarationFunction Statement IfStatement .... Lexer Parser Uses Intrinsics in CanonicalFormat Output: AST Driver TranslationUnit VarDeclaration FunctionDefinition Identifier VariableDeclaration Compound-Statement Load IntrinsicsStore IntrinsicsBinaryOperatorIntrinsics.... Intrinsic Emitter .... Cw Translation Pass Other passesin the future Final Output Translated AST
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); } } }
Simplified Step { vector int a[100][8], b[100], c[100][8]; c[:][:] = a[:][:] + b[:]; } • 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