Exemplo n.º 1
0
    def visit_Constant(self,const):
        if const.type == 'int':
            #XXX
            t = types.Int()
            reg = ir.I32()
            const = ir.ConstantI32(const.value)
            op = ir.LoadConstant(reg,const)
            v = ValTracker(False,t,reg)
            self.curBasicBlock.append(op)
            return v
        elif const.type == 'string':
            t = types.Char()
            reg = ir.Pointer()
            v = ValTracker(False,types.Pointer(t),reg)
            rawdata = cstrings.parseCString(const.value)
            label = self.module.addReadOnlyData(rawdata)
            op = ir.LoadGlobalAddr(reg,GlobalSym(label,v.type.clone()))
            self.curBasicBlock.append(op)
            return v
        elif const.type == 'char':
            t = types.Char()
            v = ValTracker(False,t,None)
            v.createVirtualReg()
            const = ir.ConstantI8(cstrings.parseCChar(const.value))
            op = ir.LoadConstant(v.reg,const)
            self.curBasicBlock.append(op)
            return v
 
        else:
            raise Exception('unimplemented constant load : %s' % const.coord)
Exemplo n.º 2
0
def test_stringparse():

    tests = [
        (r"", "\x00"),
        (r'"\n"', "\n\x00"),
        (r'"\r"', "\r\x00"),
        (r'"\x03"', "\x03\x00"),
        (r'"\\\r\n\""', '\\\r\n"\x00'),
        (r'"hello..."', "hello...\x00"),
    ]
    for s, parsed in tests:
        assert cstrings.parseCString(s) == parsed