Ejemplo n.º 1
0
def analyze(s):
    name = traceback.extract_stack()[-2][2]
    ast = Parser().parse(s, lexer=Lexer())
    table, blocks, functions = il_gen.generate(ast, debug=True)
    dot('ast.%s'%name, ast.dotty(), str(ast))
    dot('blks.%s'%name, functions['f2'].entry.dotty())
    cf.analyze(table, blocks, functions, debug=True)
    dot('cf.%s'%name, functions['f2'].tree.dotty())
    return functions
Ejemplo n.º 2
0
def run(s):
    #out = cStringIO.StringIO()
    try:
        code = x86_gen.generate(*il_gen.generate(Parser().parse(s, lexer=Lexer()), debug=True))
        print code
        gas = subprocess.Popen(['as', '--32', '-o', 'exe.o'], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
        print gas.communicate(code)
        ld = subprocess.Popen(['ld', '-o', 'exe', '-melf_i386', '-dynamic-linker', conf.dynlinker,
             conf.libc32, 'exe.o'], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
        print ld.communicate()
        exe = subprocess.Popen(['./exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        ret, err = exe.communicate()
        print '>', (ret, err)
    except Exception, e:
        print e
        traceback.print_exc(file=sys.stdout)
        ret = 'fail'
        err = e
Ejemplo n.º 3
0
        code = self.emit(x.pushl, i.a)
        code += [x.pushl("$printf_msg"), x.call("printf"), x.addl(x.cint(8), x.esp)]
        return code


if __name__ == "__main__":

    code = generate(
        *il_gen.generate(
            Parser().parse(
                """
                _add = func(a, b) {
                    reflect = func(x) {
                        print x
                        y = x + 5
                        return y - 5
                    }
                    return reflect(a) + reflect(b)
                }
                add = func(f, a, b) {
                    return f(a, b)
                }
                print add(_add, 18, 37)
            """,
                lexer=Lexer(),
            )
        )
    )
    # print code
    vm.run(code)
Ejemplo n.º 4
0
def run(s):
    out = cStringIO.StringIO()
    vm.run(vm_gen.generate(*il_gen.generate(Parser().parse(s, lexer=Lexer()))), out)
    r = out.getvalue()
    del out
    return r