示例#1
0
def parseInterface(filename):
    result = proto.ComponentInterface()
    if filename == '-':
        result.ParseFromString(sys.stdin.read())
    else:
        result.ParseFromString(open(filename, 'rb').read())
    return result
示例#2
0
def p_action_if(p):
    """
    action : IF '(' VAR REL LIT ')' THEN '{' action '}' ELSE '{' action '}'
    """
    p[0] = proto.ActionTree(type=proto.CASE)
    p[0].case.var = p[3]
    assert p[4] == '=='
    case = p[0].case
    case.test.type = proto.I
    case.test.int.value = hex(p[5])[2:]
    case.test.int.bits = 32
    case._then.CopyFrom(p[9])
    case._else.CopyFrom(p[13])
示例#3
0
def p_action_event(p):
    """
    action : SIGNAL ID '(' args ')' ';' action 
    action : SIGNAL ID '(' args ')'
    """
    p[0] = proto.ActionTree(type=proto.EVENT)
    evt = p[0].event
    evt.handler = p[2]
    evt.args.extend(p[4])
    if len(p) == 8:
        evt.then.CopyFrom(p[7])
    else:
        evt.exit = True
示例#4
0
def readInterfaceFromText(f):
    ptrn_rest = r'(?:\s*,\s*(.*))?'
    ptrn_call = re.compile(r'([^(]+)\(([^)]*)\)\s*(?::\s*([0-9]+))?')
    ptrn_int = re.compile(r'i([0-9]+)\s+([0-9]+)' + ptrn_rest)
    ptrn_str = re.compile(r'^"((?:[^"\\]|(?:\\"))+)"' + ptrn_rest)
    ptrn_unknown = re.compile(r'^\?' + ptrn_rest)

    result = proto.ComponentInterface()

    for line in [x.strip() for x in f.readlines()]:
        if len(line) == 0:
            continue
        if line.startswith('#'):
            continue
        mtch = ptrn_call.match(line)
        if mtch:
            v = result.calls.add(name=mtch.group(1))
            if mtch.group(3):
                v.count = int(mtch.group(3))
            args = mtch.group(2).strip()
            while args and not args == '':
                args = args.strip()
                m = ptrn_unknown.match(args)
                if m:
                    args.add(type=proto.U)
                    args = m.group(1)
                else:
                    m = ptrn_int.match(args)
                    if m:
                        a = v.args.add(type=proto.I)
                        a.int.value = hex(int(m.group(2)))[2:]
                        a.int.bits = int(m.group(1))
                        args = m.group(3)
                    else:
                        m = ptrn_str.match(args)
                        if m:
                            a = v.args.add(type=proto.S)
                            a.str.data = m.group(1)
                            args = m.group(2)
                        else:
                            assert False
        else:
            print "skipping line '%s'" % line
    return result
示例#5
0
def mainInterface():
    main = proto.ComponentInterface()
    c = main.calls.add(name='main', count=1)
    c.args.add(type=proto.U)
    c.args.add(type=proto.U)
    main.references.extend('main')

    atexit = main.calls.add(name='atexit', count=1)
    atexit.args.add(type=proto.U)
    main.references.extend('atexit')

    inittls = main.calls.add(name='_init_tls', count=1)
    main.references.extend('_init_tls')

    exitr = main.calls.add(name='exit', count=1)
    exitr.args.add(type=proto.U)
    main.references.extend('exit')

    return main
示例#6
0
def emptyInterface():
    return proto.ComponentInterface()
示例#7
0
 def make(self):
     return proto.ComponentInterface()
示例#8
0
 def make(self):
     return proto.ComponentInterfaceTransform()
示例#9
0
def parse(s):
    return parseInto(proto.EnforceInterface(), s)
示例#10
0
def p_action_fail(p):
    "action : FAIL"
    p[0] = proto.ActionTree(type=proto.FAIL)
示例#11
0
def p_action_forward(p):
    "action : FORWARD"
    p[0] = proto.ActionTree(type=proto.FORWARD)