Esempio n. 1
0
def p_postfix_expression_2(p):
    '''postfix_expression : postfix_expression '[' expression ']' '''
    p[0] = {}
    if 'const' in p[3]:
        index = p[3]['val']
        l1 = ''
    else:
        tmp_var, tmp = cg.load(p[3]['id'], "postfix_expression")
        var_id = m.new_reg()
        m.symbols.add(var_id, 'i64')
        l1 = "{0} = sext {1} {2} to {3}".format(m.symbols.var(var_id), m.symbols.type(tmp_var), m.symbols.var(tmp_var), m.symbols.primary_type(var_id))
        l1 = tmp + cg.indent(l1)
        index = m.symbols.var(var_id)

    p[0]['id'], l2 = cg.getelementptr(p[1]['id'], index)
    p[0]['code'] = p[1]['code'] + l1 + l2
Esempio n. 2
0
def p_primary_expression_7(p):
    '''primary_expression : MAP '(' postfix_expression ',' postfix_expression ')' '''
    if m.symbols.is_function(p[3]['id']):
        type1 = m.symbols.args(p[3]['id'])[0]
        type2 = m.symbols.primary_type(p[3]['id'], src=True)
        if type1 not in [m._type_int, m._type_float] or type2 not in [m._type_int, m._type_float]:
            m.error('map type unsuported {0}, {1}'.format(type1, type2))
    else:
        m.error('map first argument must be a function, or a function pointer')

    if m.symbols.is_function(p[3]['id']) and not m.symbols.modifiers(p[3]['id']) :
        var, tmp = cg.cast(p[3], m._type_ptr+'*')
        func = m.new_reg()
        m.symbols.add(func, m._type_ptr, '**')
        tmp1 = "{0} = alloca {1}".format(m.symbols.var(func), m.symbols.dereference(func))
        tmp2 = "store {0} {1}, {2} {3}".format(m.symbols.type(var),
            m.symbols.var(var), m.symbols.type(func), m.symbols.var(func))
        funcl = tmp + cg.indent(tmp1) + cg.indent(tmp2)
    else :
        func = p[3]['id']
        funcl =''

    if m.symbols.is_array(p[5]['id']) :
        tab, tabl = cg.getelementptr(p[5]['id'], 0, 'argument_expression_list')
    else:
        tab = p[5]['id']
        tabl = ''

    p[0] = {}
    p[0]['id'] = m.new_reg()
    size = cg.length(p[5])
    if 'const' in size:
        tab_size = size['const']
    else:
        tab_size = "{0} {1}".format(m.symbols.type(size['id']), m.symbols.var(size['id']))


    m.symbols.add(p[0]['id'], type2, '*')
    l = "{0} = call {2}* (i8**, {1}*, i32)* @..{1}.{2}.map({3} {4}, {5} {6}, {7})".format(
        m.symbols.var(p[0]['id']), type1, type2, m.symbols.type(func), m.symbols.var(func),
        m.symbols.type(tab), m.symbols.var(tab), tab_size)

    m.symbols.set_allocated(p[0]['id'], m.last_alloc())
    p[0]['code'] = funcl + tabl + size['code'] + cg.indent(l)
Esempio n. 3
0
def p_argument_expression_list_2(p):
    '''argument_expression_list : argument_expression_list ',' expression'''
    p[0] = {}
    if 'const' in p[3]:
        var = p[3]['const']
        l = ''
    elif m.symbols.is_constant(p[3]['id']) :
        var = "{0}* getelementptr inbounds ({1} {2}, i32 0, i32 0)".format(m.symbols.primary_type(p[3]['id']), m.symbols.type(p[3]['id']), m.symbols.var(p[3]['id']))
        l = ''
    elif m.symbols.is_array(p[3]['id']) :
        new, l = cg.getelementptr(p[3]['id'], 0, 'argument_expression_list')
        var = "{0} {1}".format(m.symbols.type(new), m.symbols.var(new))
    elif not m.symbols.is_pointer(p[3]['id']) :
        var = "{0} {1}".format(m.symbols.type(p[3]['id']), m.symbols.var(p[3]['id']))
        l = ''
    else:
        var, l = cg.load(p[3]['id'], "argument_expression_list")
        var = "{0} {1}".format(m.symbols.type(var), m.symbols.var(var))

    p[0]['alloc'] = p[3]['code'] + p[1]['alloc'] + l
    p[0]['code'] = "{0}, {1}".format(p[1]['code'], var)
Esempio n. 4
0
def p_argument_expression_list_1(p):
    '''argument_expression_list : barg expression earg'''
    p[0] = {}
    p[0] = p[2]
    if 'const' in p[2]:
        var = p[2]['const']
        l = ''
    elif m.symbols.is_constant(p[2]['id']) :
        var = "{0}* getelementptr inbounds ({1} {2}, i32 0, i32 0)".format(m.symbols.primary_type(p[2]['id']), m.symbols.type(p[2]['id']), m.symbols.var(p[2]['id']))
        l = ''
    elif m.symbols.is_array(p[2]['id']) :
        var, l = cg.getelementptr(p[2]['id'], 0, 'argument_expression_list')
        p[0]['id'] = var
        var = "{0} {1}".format(m.symbols.type(p[2]['id']), m.symbols.var(p[2]['id']))
    elif not m.symbols.is_pointer(p[2]['id']) :
        var = "{0} {1}".format(m.symbols.type(p[2]['id']), m.symbols.var(p[2]['id']))
        l = ''
    else:
        var, l = cg.load(p[2]['id'], "argument_expression_list")
        p[0]['id'] = var
        var = "{0} {1}".format(m.symbols.type(var), m.symbols.var(var))

    p[0]['alloc'] = p[2]['code'] + l
    p[0]['code'] = var