예제 #1
0
    def convertToASTs(self, tile_level, loop_info_table, node=None):
        '''To generate a sequence of ASTs that correspond to this sequence of "simple" loops'''

        if node == None:
            node = self.loops

        if isinstance(node, tuple):
            iname, subnodes = node
            tsize_name, titer_name, st_exp = loop_info_table[iname]
            id = ast.IdentExp(iname)
            lb = ast.IdentExp(titer_name)
            tmp = ast.BinOpExp(ast.IdentExp(tsize_name),
                               ast.ParenthExp(st_exp), ast.BinOpExp.SUB)
            ub = ast.BinOpExp(lb, ast.ParenthExp(tmp), ast.BinOpExp.ADD)
            st = st_exp
            lbody = ast.CompStmt(
                self.convertToASTs(tile_level, loop_info_table, subnodes))
            return self.ast_util.createForLoop(id, lb, ub, st, lbody)

        elif isinstance(node, list):
            return [
                self.convertToASTs(tile_level, loop_info_table, n)
                for n in node
            ]

        else:
            return node
예제 #2
0
    def createForLoop(self, index_id, lbound_exp, ubound_exp, stride_exp,
                      loop_body):
        '''
        Generate a for-loop statement based on the given loop structure information:
          for (index_id = lbound_exp; index_id <= ubound_exp; index_id = index_id + stride_exp)
            loop_body
        '''

        init_exp = None
        test_exp = None
        iter_exp = None
        if lbound_exp:
            init_exp = ast.BinOpExp(index_id.replicate(),
                                    lbound_exp.replicate(),
                                    ast.BinOpExp.EQ_ASGN)
        if ubound_exp:
            test_exp = ast.BinOpExp(index_id.replicate(),
                                    ubound_exp.replicate(), ast.BinOpExp.LE)
        if stride_exp:
            while isinstance(stride_exp, ast.ParenthExp):
                stride_exp = stride_exp.exp
            it = ast.BinOpExp(index_id.replicate(), stride_exp.replicate(),
                              ast.BinOpExp.ADD)
            iter_exp = ast.BinOpExp(index_id.replicate(), it,
                                    ast.BinOpExp.EQ_ASGN)
        if not isinstance(loop_body, ast.CompStmt):
            loop_body = ast.CompStmt([loop_body])
        return ast.ForStmt(init_exp, test_exp, iter_exp, loop_body.replicate())
예제 #3
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_additive_expression_2(p):
    'additive_expression : additive_expression additive_operator multiplicative_expression'
    if (p[2] == '+'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD, getLineNumber(p.lineno(1)))
    elif (p[2] == '-'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB, getLineNumber(p.lineno(1)))
    else:
        err('orio.module.ortildriver.code_parser internal error: unknown additive operator' )
예제 #4
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_equality_expression_2(p):
    'equality_expression : equality_expression equality_operator relational_expression'
    if p[2] == '==':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ, getLineNumber(p.lineno(1)))
    elif p[2] == '!=':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.NE, getLineNumber(p.lineno(1)))
    else:
        err('orio.module.ortildriver.code_parser internal error: unknown equality operator')
예제 #5
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_additive_expression_2(p):
    "additive_expression : additive_expression additive_operator multiplicative_expression"
    if p[2] == "+":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD)
    elif p[2] == "-":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB)
    else:
        err("orio.module.tilic.code_parser internal error: unknown additive operator")
예제 #6
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_equality_expression_2(p):
    "equality_expression : equality_expression equality_operator relational_expression"
    if p[2] == "==":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ)
    elif p[2] == "!=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.NE)
    else:
        err("orio.module.tilic.code_parser internal error: unknown equality operator")
예제 #7
0
def p_additive_expression_2(p):
    'additive_expression : additive_expression additive_operator multiplicative_expression'
    if (p[2] == '+'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '-'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB, line_no=str(p.lineno(1) + __start_line_no - 1))
    else:
        err('orio.module.loop.parser internal error: unknown additive operator' )
예제 #8
0
def p_equality_expression_2(p):
    'equality_expression : equality_expression equality_operator relational_expression'
    if p[2] == '==':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif p[2] == '!=':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.NE, line_no=str(p.lineno(1) + __start_line_no - 1))
    else:
        err('orio.module.loop.parser internal error: unknown equality operator')
예제 #9
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_additive_expression_2(p):
    'additive_expression : additive_expression additive_operator multiplicative_expression'
    if (p[2] == '+'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD)
    elif (p[2] == '-'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB)
    else:
        err('orio.module.tilic.code_parser internal error: unknown additive operator' )
예제 #10
0
def p_equality_expression_2(p):
    'equality_expression : equality_expression equality_operator relational_expression'
    if p[2] == '==':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ, p.lineno(1) + __start_line_no - 1)
    elif p[2] == '!=':
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.NE, p.lineno(1) + __start_line_no - 1)
    else:
        print 'internal error: unknown equality operator'
        sys.exit(1)
예제 #11
0
def p_additive_expression_2(p):
    'additive_expression : additive_expression additive_operator multiplicative_expression'
    if (p[2] == '+'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '-'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB, p.lineno(1) + __start_line_no - 1)
    else:
        print 'internal error: unknown additive operator' 
        sys.exit(1)
예제 #12
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_multiplicative_expression_2(p):
    'multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression'
    if (p[2] == '*'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL, getLineNumber(p.lineno(1)))
    elif (p[2] == '/'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV, getLineNumber(p.lineno(1)))
    elif (p[2] == '%'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD, getLineNumber(p.lineno(1)))
    else:
        err('orio.module.ortildriver.code_parser internal error: unknown multiplicative operator')
예제 #13
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_multiplicative_expression_2(p):
    'multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression'
    if (p[2] == '*'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL)
    elif (p[2] == '/'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV)
    elif (p[2] == '%'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD)
    else:
        err('orio.module.tilic.code_parser internal error: unknown multiplicative operator')
예제 #14
0
def p_multiplicative_expression_2(p):
    'multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression'
    if (p[2] == '*'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '/'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '%'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD, line_no=str(p.lineno(1) + __start_line_no - 1))
    else:
        err('orio.module.loop.parser internal error: unknown multiplicative operator')
예제 #15
0
def p_additive_expression_2(p):
    "additive_expression : additive_expression additive_operator multiplicative_expression"
    if p[2] == "+":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD,
                            getLineNumber(p.lineno(1)))
    elif p[2] == "-":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB,
                            getLineNumber(p.lineno(1)))
    else:
        err("orio.module.ortil.code_parser internal error:OrTil: unknown additive operator"
            )
예제 #16
0
def p_equality_expression_2(p):
    "equality_expression : equality_expression equality_operator relational_expression"
    if p[2] == "==":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ,
                            getLineNumber(p.lineno(1)))
    elif p[2] == "!=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.NE,
                            getLineNumber(p.lineno(1)))
    else:
        err("orio.module.ortil.code_parser internal error:OrTil: unknown equality operator"
            )
예제 #17
0
def p_multiplicative_expression_2(p):
    'multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression'
    if (p[2] == '*'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '/'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '%'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD, p.lineno(1) + __start_line_no - 1)
    else:
        print 'internal error: unknown multiplicative operator'
        sys.exit(1)
예제 #18
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_relational_expression_2(p):
    'relational_expression : relational_expression relational_operator additive_expression'
    if (p[2] == '<'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT, getLineNumber(p.lineno(1)))
    elif (p[2] == '>'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT, getLineNumber(p.lineno(1)))
    elif (p[2] == '<='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE, getLineNumber(p.lineno(1)))
    elif (p[2] == '>='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE, getLineNumber(p.lineno(1)))
    else:
        err('orio.module.ortildriver.code_parser internal error: unknown relational operator')
예제 #19
0
파일: code_parser.py 프로젝트: zhjp0/Orio
def p_relational_expression_2(p):
    'relational_expression : relational_expression relational_operator additive_expression'
    if (p[2] == '<'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT)
    elif (p[2] == '>'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT)
    elif (p[2] == '<='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE)
    elif (p[2] == '>='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE)
    else:
        err('orio.module.tilic.code_parser internal error: unknown relational operator')
예제 #20
0
def p_relational_expression_2(p):
    'relational_expression : relational_expression relational_operator additive_expression'
    if (p[2] == '<'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '>'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '<='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE, line_no=str(p.lineno(1) + __start_line_no - 1))
    elif (p[2] == '>='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE, line_no=str(p.lineno(1) + __start_line_no - 1))
    else:
        err('orio.module.loop.parser internal error: unknown relational operator')
예제 #21
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_multiplicative_expression_2(p):
    "multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression"
    if p[2] == "*":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL)
    elif p[2] == "/":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV)
    elif p[2] == "%":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD)
    else:
        err(
            "orio.module.tilic.code_parser internal error: unknown multiplicative operator"
        )
예제 #22
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_relational_expression_2(p):
    "relational_expression : relational_expression relational_operator additive_expression"
    if p[2] == "<":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT)
    elif p[2] == ">":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT)
    elif p[2] == "<=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE)
    elif p[2] == ">=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE)
    else:
        err("orio.module.tilic.code_parser internal error: unknown relational operator")
예제 #23
0
def p_relational_expression_2(p):
    'relational_expression : relational_expression relational_operator additive_expression'
    if (p[2] == '<'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '>'):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '<='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE, p.lineno(1) + __start_line_no - 1)
    elif (p[2] == '>='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE, p.lineno(1) + __start_line_no - 1)
    else:
        print 'internal error: unknown relational operator'
        sys.exit(1)
예제 #24
0
def p_multiplicative_expression_2(p):
    "multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression"
    if p[2] == "*":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL,
                            getLineNumber(p.lineno(1)))
    elif p[2] == "/":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV,
                            getLineNumber(p.lineno(1)))
    elif p[2] == "%":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD,
                            getLineNumber(p.lineno(1)))
    else:
        err("orio.module.ortil.code_parser internal error:OrTil: unknown multiplicative operator"
            )
예제 #25
0
    def __getIntraTileLoop(self, iter_name, tsize_name, lb_exp, st_exp, lbody):
        '''
        Generate an intra-tile loop:
          for (i=lb; i<=lb+(Ti-st); i+=st)
             lbody
        '''

        id = ast.IdentExp(iter_name)
        lb = lb_exp
        tmp = ast.BinOpExp(ast.IdentExp(tsize_name), ast.ParenthExp(st_exp),
                           ast.BinOpExp.SUB)
        ub = ast.BinOpExp(lb_exp, ast.ParenthExp(tmp), ast.BinOpExp.ADD)
        st = st_exp
        return self.ast_util.createForLoop(id, lb, ub, st, lbody)
예제 #26
0
파일: transformation.py 프로젝트: phrb/Orio
    def __getInterTileLoop(self, iter_name, tsize_name, lb_exp, ub_exp, st_exp,
                           lbody):
        """
        Generate an inter-tile loop:
          for (i=lb; i<=ub-(Ti-st); i+=Ti)
             lbody
        """

        id = ast.IdentExp(iter_name)
        lb = lb_exp
        tmp = ast.BinOpExp(ast.IdentExp(tsize_name), ast.ParenthExp(st_exp),
                           ast.BinOpExp.SUB)
        ub = ast.BinOpExp(ub_exp, ast.ParenthExp(tmp), ast.BinOpExp.SUB)
        st = ast.IdentExp(tsize_name)
        return self.ast_util.createForLoop(id, lb, ub, st, lbody)
예제 #27
0
def p_multiplicative_expression_2(p):
    "multiplicative_expression : multiplicative_expression multiplicative_operator unary_expression"
    if p[2] == "*":
        p[0] = ast.BinOpExp(
            p[1], p[3], ast.BinOpExp.MUL, line_no=str(p.lineno(1) + __start_line_no - 1)
        )
    elif p[2] == "/":
        p[0] = ast.BinOpExp(
            p[1], p[3], ast.BinOpExp.DIV, line_no=str(p.lineno(1) + __start_line_no - 1)
        )
    elif p[2] == "%":
        p[0] = ast.BinOpExp(
            p[1], p[3], ast.BinOpExp.MOD, line_no=str(p.lineno(1) + __start_line_no - 1)
        )
    else:
        err("orio.module.loop.parser internal error: unknown multiplicative operator")
예제 #28
0
def p_relational_expression_2(p):
    "relational_expression : relational_expression relational_operator additive_expression"
    if p[2] == "<":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LT,
                            getLineNumber(p.lineno(1)))
    elif p[2] == ">":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GT,
                            getLineNumber(p.lineno(1)))
    elif p[2] == "<=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.LE,
                            getLineNumber(p.lineno(1)))
    elif p[2] == ">=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.GE,
                            getLineNumber(p.lineno(1)))
    else:
        err("orio.module.ortil.code_parser internal error:OrTil: unknown relational operator"
            )
예제 #29
0
def p_assignment_expression_2(p):
    "assignment_expression : unary_expression assignment_operator assignment_expression"
    if p[2] == "=":
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ_ASGN,
                            getLineNumber(p.lineno(1)))
    elif p[2] in ("*=", "/=", "%=", "+=", "-="):
        lhs = p[1].replicate()
        rhs = None
        if p[2] == "*=":
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL,
                               getLineNumber(p.lineno(1)))
        elif p[2] == "/=":
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV,
                               getLineNumber(p.lineno(1)))
        elif p[2] == "%=":
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD,
                               getLineNumber(p.lineno(1)))
        elif p[2] == "+=":
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD,
                               getLineNumber(p.lineno(1)))
        elif p[2] == "-=":
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB,
                               getLineNumber(p.lineno(1)))
        else:
            err("orio.module.ortil.code_parser internal error:OrTil: unknown assignment operator"
                )
        p[0] = ast.BinOpExp(lhs, rhs, ast.BinOpExp.EQ_ASGN,
                            getLineNumber(p.lineno(1)))
    else:
        err("orio.module.ortil.code_parser internal error:OrTil: unknown assignment operator"
            )
예제 #30
0
def p_assignment_expression_2(p):
    'assignment_expression : unary_expression assignment_operator assignment_expression'
    if (p[2] == '='):
        p[0] = ast.BinOpExp(p[1], p[3], ast.BinOpExp.EQ_ASGN,
                            p.lineno(1) + __start_line_no - 1)
    elif p[2] in ('*=', '/=', '%=', '+=', '-='):
        lhs = p[1].replicate()
        rhs = None
        if (p[2] == '*='):
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MUL, p.lineno(1) + __start_line_no - 1)
        elif (p[2] == '/='):
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.DIV, p.lineno(1) + __start_line_no - 1)
        elif (p[2] == '%='):
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.MOD, p.lineno(1) + __start_line_no - 1)
        elif (p[2] == '+='):
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.ADD, p.lineno(1) + __start_line_no - 1)
        elif (p[2] == '-='):
            rhs = ast.BinOpExp(p[1], p[3], ast.BinOpExp.SUB, p.lineno(1) + __start_line_no - 1)
        else:
            print 'internal error: missing case for assignment operator'
            sys.exit(1)
        p[0] = ast.BinOpExp(lhs, rhs, ast.BinOpExp.EQ_ASGN, p.lineno(1) + __start_line_no - 1)
    else:
        print 'internal error: unknown assignment operator'
        sys.exit(1)