Esempio n. 1
0
def test_func_simple():
    # -------------------- flowgraph building --------------------
    #     def f(x):
    #         return x+1
    x = Variable("x")
    x.concretetype = Signed
    result = Variable("result")
    result.concretetype = Signed
    one = Constant(1)
    one.concretetype = Signed
    op = SpaceOperation("int_add", [x, one], result)
    block = Block([x])
    graph = FunctionGraph("f", block)
    block.operations.append(op)
    block.closeblock(Link([result], graph.returnblock))
    graph.getreturnvar().concretetype = Signed
    # --------------------         end        --------------------

    F = FuncType([Signed], Signed)
    f = functionptr(F, "f", graph=graph)
    db = LowLevelDatabase()
    db.get(f)
    db.complete()
    dump_on_stdout(db)

    S = GcStruct('testing', ('fptr', Ptr(F)))
    s = malloc(S)
    s.fptr = f
    db = LowLevelDatabase()
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 2
0
def test_func_simple():
    # -------------------- flowgraph building --------------------
    #     def f(x):
    #         return x+1
    x = Variable("x")
    x.concretetype = Signed
    result = Variable("result")
    result.concretetype = Signed
    one = Constant(1)
    one.concretetype = Signed
    op = SpaceOperation("int_add", [x, one], result)
    block = Block([x])
    graph = FunctionGraph("f", block)
    block.operations.append(op)
    block.closeblock(Link([result], graph.returnblock))
    graph.getreturnvar().concretetype = Signed
    # --------------------         end        --------------------

    F = FuncType([Signed], Signed)
    f = functionptr(F, "f", graph=graph)
    db = LowLevelDatabase()
    db.get(f)
    db.complete()
    dump_on_stdout(db)

    S = GcStruct('testing', ('fptr', Ptr(F)))
    s = malloc(S)
    s.fptr = f
    db = LowLevelDatabase()
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 3
0
def test_array_of_char():
    A = GcArray(Char)
    a = malloc(A, 11)
    for i, c in zip(range(11), 'hello world'):
        a[i] = c
    db = LowLevelDatabase()
    db.get(a)
    db.complete()
    dump_on_stdout(db)
Esempio n. 4
0
def test_array_of_char():
    A = GcArray(Char)
    a = malloc(A, 11)
    for i, c in zip(range(11), 'hello world'):
        a[i] = c
    db = LowLevelDatabase()
    db.get(a)
    db.complete()
    dump_on_stdout(db)
Esempio n. 5
0
def test_recursive_struct():
    S = GcForwardReference()
    S.become(GcStruct('testing', ('p', Ptr(S))))
    p = malloc(S)
    p.p = p
    db = LowLevelDatabase()
    db.get(p)
    db.complete()
    dump_on_stdout(db)
Esempio n. 6
0
def test_recursive_struct():
    S = GcForwardReference()
    S.become(GcStruct('testing', ('p', Ptr(S))))
    p = malloc(S)
    p.p = p
    db = LowLevelDatabase()
    db.get(p)
    db.complete()
    dump_on_stdout(db)
Esempio n. 7
0
    def build_database(self):
        translator = self.translator

        gcpolicyclass = self.get_gcpolicyclass()

        if self.config.translation.gcrootfinder == "asmgcc":
            if not self.standalone:
                raise NotImplementedError("--gcrootfinder=asmgcc requires standalone")

        exctransformer = translator.getexceptiontransformer()
        db = LowLevelDatabase(translator, standalone=self.standalone,
                              gcpolicyclass=gcpolicyclass,
                              gchooks=self.gchooks,
                              exctransformer=exctransformer,
                              thread_enabled=self.config.translation.thread,
                              sandbox=self.config.translation.sandbox,
                              split_gc_address_space=
                                 self.config.translation.split_gc_address_space,
                              reverse_debugger=
                                 self.config.translation.reverse_debugger)
        self.db = db

        # give the gc a chance to register interest in the start-up functions it
        # need (we call this for its side-effects of db.get())
        list(db.gcpolicy.gc_startup_code())

        # build entrypoint and eventually other things to expose
        pf = self.getentrypointptr()
        if isinstance(pf, list):
            for one_pf in pf:
                db.get(one_pf)
            self.c_entrypoint_name = None
        else:
            pfname = db.get(pf)

            for func, _ in self.secondary_entrypoints:
                bk = translator.annotator.bookkeeper
                db.get(getfunctionptr(bk.getdesc(func).getuniquegraph()))

            self.c_entrypoint_name = pfname

        if self.config.translation.reverse_debugger:
            from rpython.translator.revdb import gencsupp
            gencsupp.prepare_database(db)

        for obj in exports.EXPORTS_obj2name.keys():
            db.getcontainernode(obj)
        exports.clear()

        for ll_func in db.translator._call_at_startup:
            db.get(ll_func)

        db.complete()

        self.collect_compilation_info(db)
        return db
Esempio n. 8
0
def test_inlined_struct():
    db = LowLevelDatabase()
    pfx = db.namespace.global_prefix + 'g_'
    S = GcStruct('test', ('x', Struct('subtest', ('y', Signed))))
    s = malloc(S)
    s.x.y = 42
    assert db.get(s).startswith('(&' + pfx)
    assert db.containernodes.keys() == [s._obj]
    db.complete()
    assert len(db.structdefnodes) == 2
    assert S in db.structdefnodes
    assert S.x in db.structdefnodes
Esempio n. 9
0
def test_inlined_struct():
    db = LowLevelDatabase()
    pfx = db.namespace.global_prefix + 'g_'
    S = GcStruct('test', ('x', Struct('subtest', ('y', Signed))))
    s = malloc(S)
    s.x.y = 42
    assert db.get(s).startswith('(&'+pfx)
    assert db.containernodes.keys() == [s._obj]
    db.complete()
    assert len(db.structdefnodes) == 2
    assert S in db.structdefnodes
    assert S.x in db.structdefnodes
Esempio n. 10
0
def test_codegen_2():
    db = LowLevelDatabase()
    A = GcArray(('x', Signed))
    S = GcStruct('test', ('aptr', Ptr(A)))
    a = malloc(A, 3)
    a[0].x = 100
    a[1].x = 101
    a[2].x = 102
    s = malloc(S)
    s.aptr = a
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 11
0
def test_codegen():
    db = LowLevelDatabase()
    U = Struct('inlined', ('z', Signed))
    T = Struct('subtest', ('y', Signed))
    S = Struct('test', ('x', Ptr(T)), ('u', U), ('p', Ptr(U)))
    s = malloc(S, immortal=True)
    s.x = malloc(T, immortal=True)
    s.x.y = 42
    s.u.z = -100
    s.p = s.u
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 12
0
def test_malloc():
    S = GcStruct('testing', ('x', Signed), ('y', Signed))
    def ll_f(x):
        p = malloc(S)
        p.x = x
        p.y = x+1
        return p.x * p.y
    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Esempio n. 13
0
def test_function_call():
    def g(x, y):
        return x-y
    def f(x):
        return g(1, x)
    t, graph = makegraph(f, [int])

    F = FuncType([Signed], Signed)
    f = functionptr(F, "f", graph=graph)
    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(f)
    db.complete()
    dump_on_stdout(db)
Esempio n. 14
0
def test_codegen_2():
    db = LowLevelDatabase()
    A = GcArray(('x', Signed))
    S = GcStruct('test', ('aptr', Ptr(A)))
    a = malloc(A, 3)
    a[0].x = 100
    a[1].x = 101
    a[2].x = 102
    s = malloc(S)
    s.aptr = a
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 15
0
def test_codegen():
    db = LowLevelDatabase()
    U = Struct('inlined', ('z', Signed))
    T = Struct('subtest', ('y', Signed))
    S = Struct('test', ('x', Ptr(T)), ('u', U), ('p', Ptr(U)))
    s = malloc(S, immortal=True)
    s.x = malloc(T, immortal=True)
    s.x.y = 42
    s.u.z = -100
    s.p = s.u
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 16
0
def test_function_call():
    def g(x, y):
        return x - y

    def f(x):
        return g(1, x)

    t, graph = makegraph(f, [int])

    F = FuncType([Signed], Signed)
    f = functionptr(F, "f", graph=graph)
    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(f)
    db.complete()
    dump_on_stdout(db)
Esempio n. 17
0
def test_malloc():
    S = GcStruct('testing', ('x', Signed), ('y', Signed))

    def ll_f(x):
        p = malloc(S)
        p.x = x
        p.y = x + 1
        return p.x * p.y

    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Esempio n. 18
0
def test_codegen_3():
    db = LowLevelDatabase()
    A = Struct('varsizedstuff', ('x', Signed), ('y', Array(('i', Signed))))
    S = Struct('test', ('aptr', Ptr(A)), ('anitem', Ptr(A.y.OF)),
               ('anarray', Ptr(A.y)))
    a = malloc(A, 3, immortal=True)
    a.x = 99
    a.y[0].i = 100
    a.y[1].i = 101
    a.y[2].i = 102
    s = malloc(S, immortal=True)
    s.aptr = a
    s.anitem = a.y[1]
    s.anarray = a.y
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 19
0
def test_codegen_3():
    db = LowLevelDatabase()
    A = Struct('varsizedstuff', ('x', Signed), ('y', Array(('i', Signed))))
    S = Struct('test', ('aptr', Ptr(A)),
                       ('anitem', Ptr(A.y.OF)),
                       ('anarray', Ptr(A.y)))
    a = malloc(A, 3, immortal=True)
    a.x = 99
    a.y[0].i = 100
    a.y[1].i = 101
    a.y[2].i = 102
    s = malloc(S, immortal=True)
    s.aptr = a
    s.anitem =  a.y[1]
    s.anarray = a.y
    db.get(s)
    db.complete()
    dump_on_stdout(db)
Esempio n. 20
0
    def build_database(self):
        translator = self.translator

        gcpolicyclass = self.get_gcpolicyclass()

        if self.config.translation.gcrootfinder == "asmgcc":
            if not self.standalone:
                raise NotImplementedError("--gcrootfinder=asmgcc requires standalone")

        exctransformer = translator.getexceptiontransformer()
        db = LowLevelDatabase(translator, standalone=self.standalone,
                              gcpolicyclass=gcpolicyclass,
                              exctransformer=exctransformer,
                              thread_enabled=self.config.translation.thread,
                              sandbox=self.config.translation.sandbox)
        self.db = db

        # give the gc a chance to register interest in the start-up functions it
        # need (we call this for its side-effects of db.get())
        list(db.gcpolicy.gc_startup_code())

        # build entrypoint and eventually other things to expose
        pf = self.getentrypointptr()
        if isinstance(pf, list):
            for one_pf in pf:
                db.get(one_pf)
            self.c_entrypoint_name = None
        else:
            pfname = db.get(pf)

            for func, _ in self.secondary_entrypoints:
                bk = translator.annotator.bookkeeper
                db.get(getfunctionptr(bk.getdesc(func).getuniquegraph()))

            self.c_entrypoint_name = pfname

        for obj in exports.EXPORTS_obj2name.keys():
            db.getcontainernode(obj)
        exports.clear()
        db.complete()

        self.collect_compilation_info(db)
        return db
Esempio n. 21
0
def test_multiple_malloc():
    S1 = GcStruct('testing1', ('x', Signed), ('y', Signed))
    S = GcStruct('testing', ('ptr1', Ptr(S1)),
                            ('ptr2', Ptr(S1)),
                            ('z', Signed))
    def ll_f(x):
        ptr1 = malloc(S1)
        ptr1.x = x
        ptr2 = malloc(S1)
        ptr2.x = x+1
        s = malloc(S)
        s.ptr1 = ptr1
        s.ptr2 = ptr2
        return s.ptr1.x * s.ptr2.x
    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Esempio n. 22
0
def test_multiple_malloc():
    S1 = GcStruct('testing1', ('x', Signed), ('y', Signed))
    S = GcStruct('testing', ('ptr1', Ptr(S1)), ('ptr2', Ptr(S1)),
                 ('z', Signed))

    def ll_f(x):
        ptr1 = malloc(S1)
        ptr1.x = x
        ptr2 = malloc(S1)
        ptr2.x = x + 1
        s = malloc(S)
        s.ptr1 = ptr1
        s.ptr2 = ptr2
        return s.ptr1.x * s.ptr2.x

    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t, exctransformer=t.getexceptiontransformer())
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)