Monday, April 11, 2011

Python tprint output

SKETCH now supports generating Python files from tprint output. This is useful for localizing synthesis; for example, extracting a read-write sequence from a concrete scan network, so that one can then synthesize a function for mapping the indices. For a simple example, consider the following sketch, that multiplies [1 .. 4] by a constant value.



pragma options "-n -y outPyFile";

printfcn void main() {
    for (int x = 0; x < 4; x++) {
        int v = ?? * x;
        tprint("factor", v, "src", x);
        if (x % 3 == 0) {
            tprint("sync", 0);
        }
    }
}

This generates the following Python code (currently printed to stdout until the skdev shell alias is cleaned up),

class Message(object):
    def __init__(self, value, **kwargs):
        self.value = value
        [setattr(self, k, v) for k, v in kwargs.items()]
    def __repr__(self):
        return "%s%s" %(self.__class__.__name__, self.__dict__)
    __str__ = __repr__
class Factor(Message): pass
class Sync(Message): pass
isfactor = lambda a: isinstance(a, Factor)
issync = lambda a: isinstance(a, Sync)

main_messages = [
    Factor(0, src=0),
    Sync(0),
    Factor(8, src=1),
    Factor(16, src=2),
    Factor(24, src=3),
    Sync(0) ]

Hope the Blog posting and email works! This should show up at http://research-internal.gatoatigrado.com/.


cheers,
Nicholas — https://ntung.com — CS major @ UC Berkeley

No comments:

Post a Comment