Changeset a35b458 in mainline for contrib/arch/hadlbppp.py


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/arch/hadlbppp.py

    r3061bc1 ra35b458  
    4141def usage(prname):
    4242        "Print usage syntax"
    43        
     43
    4444        print("%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname)
    4545        print()
     
    5353def tabs(cnt):
    5454        "Return given number of tabs"
    55        
     55
    5656        return ("\t" * cnt)
    5757
    5858def cond_append(tokens, token, trim):
    5959        "Conditionally append token to tokens with trim"
    60        
     60
    6161        if (trim):
    6262                token = token.strip(" \t")
    63        
     63
    6464        if (token != ""):
    6565                tokens.append(token)
    66        
     66
    6767        return tokens
    6868
    6969def split_tokens(string, delimiters, trim = False, separate = False):
    7070        "Split string to tokens by delimiters, keep the delimiters"
    71        
     71
    7272        tokens = []
    7373        last = 0
    7474        i = 0
    75        
     75
    7676        while (i < len(string)):
    7777                for delim in delimiters:
    7878                        if (len(delim) > 0):
    79                                
     79
    8080                                if (string[i:(i + len(delim))] == delim):
    8181                                        if (separate):
     
    8686                                                tokens = cond_append(tokens, string[last:i], trim)
    8787                                                last = i
    88                                        
     88
    8989                                        i += len(delim) - 1
    9090                                        break
    91                
     91
    9292                i += 1
    93        
     93
    9494        tokens = cond_append(tokens, string[last:len(string)], trim)
    95        
     95
    9696        return tokens
    9797
    9898def identifier(token):
    9999        "Check whether the token is an identifier"
    100        
     100
    101101        if (len(token) == 0):
    102102                return False
    103        
     103
    104104        for i, char in enumerate(token):
    105105                if (i == 0):
     
    109109                        if ((not char.isalnum()) and (char != "_")):
    110110                                return False
    111        
     111
    112112        return True
    113113
    114114def descriptor(token):
    115115        "Check whether the token is an interface descriptor"
    116        
     116
    117117        parts = token.split(":")
    118118        if (len(parts) != 2):
    119119                return False
    120        
     120
    121121        return (identifier(parts[0]) and identifier(parts[1]))
    122122
    123123def word(token):
    124124        "Check whether the token is a word"
    125        
     125
    126126        if (len(token) == 0):
    127127                return False
    128        
     128
    129129        for i, char in enumerate(token):
    130130                if ((not char.isalnum()) and (char != "_") and (char != ".")):
    131131                        return False
    132        
     132
    133133        return True
    134134
    135135def tentative_bp(name, tokens):
    136136        "Preprocess tentative statements in Behavior Protocol"
    137        
     137
    138138        result = []
    139139        i = 0
    140        
     140
    141141        while (i < len(tokens)):
    142142                if (tokens[i] == "tentative"):
     
    145145                                start = i
    146146                                level = 1
    147                                
     147
    148148                                while ((i < len(tokens)) and (level > 0)):
    149149                                        if (tokens[i] == "{"):
     
    151151                                        elif (tokens[i] == "}"):
    152152                                                level -= 1
    153                                        
     153
    154154                                        i += 1
    155                                
     155
    156156                                if (level == 0):
    157157                                        result.append("(")
     
    168168                else:
    169169                        result.append(tokens[i])
    170                
     170
    171171                i += 1
    172        
     172
    173173        return result
    174174
    175175def alternative_bp(name, tokens):
    176176        "Preprocess alternative statements in Behavior Protocol"
    177        
     177
    178178        result = []
    179179        i = 0
    180        
     180
    181181        while (i < len(tokens)):
    182182                if (tokens[i] == "alternative"):
     
    184184                                i += 2
    185185                                reps = []
    186                                
     186
    187187                                while ((i < len(tokens)) and (tokens[i] != ")")):
    188188                                        reps.append(tokens[i])
     
    191191                                        else:
    192192                                                i += 1
    193                                
     193
    194194                                if (len(reps) >= 2):
    195195                                        if ((i + 1 < len(tokens)) and (tokens[i + 1] == "{")):
    196196                                                i += 2
    197                                                
     197
    198198                                                start = i
    199199                                                level = 1
    200                                                
     200
    201201                                                while ((i < len(tokens)) and (level > 0)):
    202202                                                        if (tokens[i] == "{"):
     
    204204                                                        elif (tokens[i] == "}"):
    205205                                                                level -= 1
    206                                                        
     206
    207207                                                        i += 1
    208                                                
     208
    209209                                                if (level == 0):
    210210                                                        first = True
    211                                                        
     211
    212212                                                        for rep in reps[1:]:
    213213                                                                retokens = []
     
    218218                                                                        else:
    219219                                                                                retokens.append(token)
    220                                                                
     220
    221221                                                                if (first):
    222222                                                                        first = False
    223223                                                                else:
    224224                                                                        result.append("+")
    225                                                                
     225
    226226                                                                result.append("(")
    227227                                                                result.extend(alternative_bp(name, retokens))
    228228                                                                result.append(")")
    229                                                        
     229
    230230                                                        if (i < len(tokens)):
    231231                                                                result.append(tokens[i])
     
    240240                else:
    241241                        result.append(tokens[i])
    242                
     242
    243243                i += 1
    244        
     244
    245245        return result
    246246
    247247def split_bp(protocol):
    248248        "Convert Behavior Protocol to tokens"
    249        
     249
    250250        return split_tokens(protocol, ["\n", " ", "\t", "(", ")", "{", "}", "*", ";", "+", "||", "|", "!", "?"], True, True)
    251251
    252252def extend_bp(name, tokens, iface):
    253253        "Convert interface Behavior Protocol to generic protocol"
    254        
     254
    255255        result = []
    256256        i = 0
    257        
     257
    258258        while (i < len(tokens)):
    259259                result.append(tokens[i])
    260                
     260
    261261                if (tokens[i] == "?"):
    262262                        if (i + 1 < len(tokens)):
    263263                                i += 1
    264264                                parts = tokens[i].split(".")
    265                                
     265
    266266                                if (len(parts) == 1):
    267267                                        result.append("%s.%s" % (iface, tokens[i]))
     
    270270                        else:
    271271                                print("%s: Unexpected end of protocol" % name)
    272                
     272
    273273                i += 1
    274        
     274
    275275        return result
    276276
    277277def merge_bp(initialization, finalization, protocols):
    278278        "Merge several Behavior Protocols"
    279        
     279
    280280        indep = []
    281        
     281
    282282        if (len(protocols) > 1):
    283283                first = True
    284                
     284
    285285                for protocol in protocols:
    286286                        if (first):
     
    288288                        else:
    289289                                indep.append("|")
    290                        
     290
    291291                        indep.append("(")
    292292                        indep.extend(protocol)
     
    294294        elif (len(protocols) == 1):
    295295                indep = protocols[0]
    296        
     296
    297297        inited = []
    298        
     298
    299299        if (initialization != None):
    300300                if (len(indep) > 0):
     
    310310        else:
    311311                inited = indep
    312        
     312
    313313        finited = []
    314        
     314
    315315        if (finalization != None):
    316316                if (len(inited) > 0):
     
    326326        else:
    327327                finited = inited
    328        
     328
    329329        return finited
    330330
    331331def parse_bp(name, tokens, base_indent):
    332332        "Parse Behavior Protocol"
    333        
     333
    334334        tokens = tentative_bp(name, tokens)
    335335        tokens = alternative_bp(name, tokens)
    336        
     336
    337337        indent = base_indent
    338338        output = ""
    339        
     339
    340340        for token in tokens:
    341341                if (token == "\n"):
    342342                        continue
    343                
     343
    344344                if ((token == ";") or (token == "+") or (token == "||") or (token == "|")):
    345345                        output += " %s" % token
     
    350350                        if (indent < base_indent):
    351351                                print("%s: Too many parentheses" % name)
    352                        
     352
    353353                        indent -= 1
    354354                        output += "\n%s%s" % (tabs(indent), token)
     
    359359                        if (indent < base_indent):
    360360                                print("%s: Too many parentheses" % name)
    361                        
     361
    362362                        indent -= 1
    363363                        output += "\n%s%s" % (tabs(indent), token)
     
    368368                else:
    369369                        output += "%s" % token
    370        
     370
    371371        if (indent > base_indent):
    372372                print("%s: Missing parentheses" % name)
    373        
     373
    374374        output = output.strip()
    375375        if (output == ""):
    376376                return "NULL"
    377        
     377
    378378        return output
    379379
    380380def parse_ebp(component, name, tokens, base_indent):
    381381        "Parse Behavior Protocol and generate Extended Behavior Protocol output"
    382        
     382
    383383        return "component %s {\n\tbehavior {\n\t\t%s\n\t}\n}" % (component, parse_bp(name, tokens, base_indent + 2))
    384384
    385385def get_iface(name):
    386386        "Get interface by name"
    387        
     387
    388388        global iface_properties
    389        
     389
    390390        if (name in iface_properties):
    391391                return iface_properties[name]
    392        
     392
    393393        return None
    394394
    395395def inherited_protocols(iface):
    396396        "Get protocols inherited by an interface"
    397        
     397
    398398        result = []
    399        
     399
    400400        if ('extends' in iface):
    401401                supiface = get_iface(iface['extends'])
     
    406406                else:
    407407                        print("%s: Extends unknown interface '%s'" % (iface['name'], iface['extends']))
    408        
     408
    409409        return result
    410410
    411411def dump_frame(directed_binds, frame, outdir, var, archf):
    412412        "Dump Behavior Protocol of a given frame"
    413        
     413
    414414        global opt_bp
    415415        global opt_ebp
    416        
     416
    417417        if (opt_ebp):
    418418                fname = "%s.ebp" % frame['name']
    419419        else:
    420420                fname = "%s.bp" % frame['name']
    421        
     421
    422422        if (archf != None):
    423423                archf.write("instantiate %s from \"%s\"\n" % (var, fname))
    424        
     424
    425425        outname = os.path.join(outdir, fname)
    426        
     426
    427427        protocols = []
    428428        if ('protocol' in frame):
    429429                protocols.append(frame['protocol'])
    430        
     430
    431431        if ('initialization' in frame):
    432432                initialization = frame['initialization']
    433433        else:
    434434                initialization = None
    435        
     435
    436436        if ('finalization' in frame):
    437437                finalization = frame['finalization']
    438438        else:
    439439                finalization = None
    440        
     440
    441441        if ('provides' in frame):
    442442                for provides in frame['provides']:
     
    448448                                else:
    449449                                        cnt = 1
    450                                
     450
    451451                                if ('protocol' in iface):
    452452                                        proto = extend_bp(outname, iface['protocol'], iface['name'])
    453453                                        for _ in range(0, cnt):
    454454                                                protocols.append(proto)
    455                                
     455
    456456                                for protocol in inherited_protocols(iface):
    457457                                        proto = extend_bp(outname, protocol, iface['name'])
     
    460460                        else:
    461461                                print("%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface']))
    462        
     462
    463463        if (opt_bp):
    464464                outf = open(outname, "w")
    465465                outf.write(parse_bp(outname, merge_bp(initialization, finalization, protocols), 0))
    466466                outf.close()
    467        
     467
    468468        if (opt_ebp):
    469469                outf = open(outname, "w")
     
    473473def get_system_arch():
    474474        "Get system architecture"
    475        
     475
    476476        global arch_properties
    477        
     477
    478478        for arch, properties in arch_properties.items():
    479479                if ('system' in properties):
    480480                        return properties
    481        
     481
    482482        return None
    483483
    484484def get_arch(name):
    485485        "Get architecture by name"
    486        
     486
    487487        global arch_properties
    488        
     488
    489489        if (name in arch_properties):
    490490                return arch_properties[name]
    491        
     491
    492492        return None
    493493
    494494def get_frame(name):
    495495        "Get frame by name"
    496        
     496
    497497        global frame_properties
    498        
     498
    499499        if (name in frame_properties):
    500500                return frame_properties[name]
    501        
     501
    502502        return None
    503503
    504504def create_null_bp(fname, outdir, archf):
    505505        "Create null frame protocol"
    506        
     506
    507507        global opt_bp
    508508        global opt_ebp
    509        
     509
    510510        if (archf != None):
    511511                archf.write("frame \"%s\"\n" % fname)
    512        
     512
    513513        outname = os.path.join(outdir, fname)
    514        
     514
    515515        if (opt_bp):
    516516                outf = open(outname, "w")
    517517                outf.write("NULL")
    518518                outf.close()
    519        
     519
    520520        if (opt_ebp):
    521521                outf = open(outname, "w")
     
    525525def flatten_binds(binds, delegates, subsumes):
    526526        "Remove bindings which are replaced by delegation or subsumption"
    527        
     527
    528528        result = []
    529529        stable = True
    530        
     530
    531531        for bind in binds:
    532532                keep = True
    533                
     533
    534534                for delegate in delegates:
    535535                        if (bind['to'] == delegate['to']):
    536536                                keep = False
    537537                                result.append({'from': bind['from'], 'to': delegate['rep']})
    538                
     538
    539539                for subsume in subsumes:
    540540                        if (bind['from'] == subsume['from']):
    541541                                keep = False
    542542                                result.append({'from': subsume['rep'], 'to': bind['to']})
    543                
     543
    544544                if (keep):
    545545                        result.append(bind)
    546546                else:
    547547                        stable = False
    548        
     548
    549549        if (stable):
    550550                return result
     
    554554def direct_binds(binds):
    555555        "Convert bindings matrix to set of sources by destination"
    556        
     556
    557557        result = {}
    558        
     558
    559559        for bind in binds:
    560560                if (not bind['to'] in result):
    561561                        result[bind['to']] = set()
    562                
     562
    563563                result[bind['to']].add(bind['from'])
    564        
     564
    565565        return result
    566566
    567567def merge_arch(prefix, arch, outdir):
    568568        "Merge subarchitecture into architecture"
    569        
     569
    570570        insts = []
    571571        binds = []
    572572        delegates = []
    573573        subsumes = []
    574        
     574
    575575        if ('inst' in arch):
    576576                for inst in arch['inst']:
     
    588588                                else:
    589589                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    590        
     590
    591591        if ('bind' in arch):
    592592                for bind in arch['bind']:
    593593                        binds.append({'from': "%s_%s.%s" % (prefix, bind['from'][0], bind['from'][1]), 'to': "%s_%s.%s" % (prefix, bind['to'][0], bind['to'][1])})
    594        
     594
    595595        if ('delegate' in arch):
    596596                for delegate in arch['delegate']:
    597597                        delegates.append({'to': "%s.%s" % (prefix, delegate['from']), 'rep': "%s_%s.%s" % (prefix, delegate['to'][0], delegate['to'][1])})
    598        
     598
    599599        if ('subsume' in arch):
    600600                for subsume in arch['subsume']:
    601601                        subsumes.append({'from': "%s.%s" % (prefix, subsume['to']), 'rep': "%s_%s.%s" % (prefix, subsume['from'][0], subsume['from'][1])})
    602        
     602
    603603        return (insts, binds, delegates, subsumes)
    604604
    605605def dump_archbp(outdir):
    606606        "Dump system architecture Behavior Protocol"
    607        
     607
    608608        global opt_bp
    609609        global opt_ebp
    610        
     610
    611611        arch = get_system_arch()
    612        
     612
    613613        if (arch is None):
    614614                print("Unable to find system architecture")
    615615                return
    616        
     616
    617617        insts = []
    618618        binds = []
    619619        delegates = []
    620620        subsumes = []
    621        
     621
    622622        if ('inst' in arch):
    623623                for inst in arch['inst']:
     
    635635                                else:
    636636                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    637        
     637
    638638        if ('bind' in arch):
    639639                for bind in arch['bind']:
    640640                        binds.append({'from': "%s.%s" % (bind['from'][0], bind['from'][1]), 'to': "%s.%s" % (bind['to'][0], bind['to'][1])})
    641        
     641
    642642        if ('delegate' in arch):
    643643                for delegate in arch['delegate']:
    644644                        print("Unable to delegate interface in system architecture")
    645645                        break
    646        
     646
    647647        if ('subsume' in arch):
    648648                for subsume in arch['subsume']:
    649649                        print("Unable to subsume interface in system architecture")
    650650                        break
    651        
     651
    652652        directed_binds = direct_binds(flatten_binds(binds, delegates, subsumes))
    653        
     653
    654654        outname = os.path.join(outdir, "%s.archbp" % arch['name'])
    655655        if ((opt_bp) or (opt_ebp)):
     
    657657        else:
    658658                outf = None
    659        
     659
    660660        create_null_bp("null.bp", outdir, outf)
    661        
     661
    662662        for inst in insts:
    663663                dump_frame(directed_binds, inst['frame'], outdir, inst['var'], outf)
    664        
     664
    665665        for dst, src in directed_binds.items():
    666666                if (outf != None):
    667667                        outf.write("bind %s to %s\n" % (", ".join(src), dst))
    668        
     668
    669669        if (outf != None):
    670670                outf.close()
     
    672672def preproc_adl(raw, inarg):
    673673        "Preprocess %% statements in ADL"
    674        
     674
    675675        return raw.replace("%%", inarg)
    676676
    677677def parse_adl(base, root, inname, nested, indent):
    678678        "Parse Architecture Description Language"
    679        
     679
    680680        global output
    681681        global context
     
    686686        global initialization
    687687        global finalization
    688        
     688
    689689        global iface_properties
    690690        global frame_properties
    691691        global arch_properties
    692        
     692
    693693        global arg0
    694        
     694
    695695        if (nested):
    696696                parts = inname.split("%")
    697                
     697
    698698                if (len(parts) > 1):
    699699                        inarg = parts[1]
    700700                else:
    701701                        inarg = "%%"
    702                
     702
    703703                if (parts[0][0:1] == "/"):
    704704                        path = os.path.join(base, ".%s" % parts[0])
     
    707707                        path = os.path.join(root, parts[0])
    708708                        nested_root = root
    709                
     709
    710710                if (not os.path.isfile(path)):
    711711                        print("%s: Unable to include file %s" % (inname, path))
     
    715715                path = inname
    716716                nested_root = root
    717        
     717
    718718        inf = open(path, "r")
    719        
     719
    720720        raw = preproc_adl(inf.read(), inarg)
    721721        tokens = split_tokens(raw, ["\n", " ", "\t", "(", ")", "{", "}", "[", "]", "/*", "*/", "#", ";"], True, True)
    722        
     722
    723723        for token in tokens:
    724                
     724
    725725                # Includes
    726                
     726
    727727                if (INC in context):
    728728                        context.remove(INC)
     
    730730                        context.add(POST_INC)
    731731                        continue
    732                
     732
    733733                if (POST_INC in context):
    734734                        if (token != "]"):
    735735                                print("%s: Expected ]" % inname)
    736                        
     736
    737737                        context.remove(POST_INC)
    738738                        continue
    739                
     739
    740740                # Comments and newlines
    741                
     741
    742742                if (BLOCK_COMMENT in context):
    743743                        if (token == "*/"):
    744744                                context.remove(BLOCK_COMMENT)
    745                        
     745
    746746                        continue
    747                
     747
    748748                if (LINE_COMMENT in context):
    749749                        if (token == "\n"):
    750750                                context.remove(LINE_COMMENT)
    751                        
     751
    752752                        continue
    753                
     753
    754754                # Any context
    755                
     755
    756756                if (token == "/*"):
    757757                        context.add(BLOCK_COMMENT)
    758758                        continue
    759                
     759
    760760                if (token == "#"):
    761761                        context.add(LINE_COMMENT)
    762762                        continue
    763                
     763
    764764                if (token == "["):
    765765                        context.add(INC)
    766766                        continue
    767                
     767
    768768                if (token == "\n"):
    769769                        continue
    770                
     770
    771771                # "frame"
    772                
     772
    773773                if (FRAME in context):
    774774                        if (NULL in context):
     
    777777                                else:
    778778                                        output += "%s\n" % token
    779                                
     779
    780780                                context.remove(NULL)
    781781                                context.remove(FRAME)
    782782                                frame = None
    783783                                continue
    784                        
     784
    785785                        if (BODY in context):
    786786                                if (FINALIZATION in context):
     
    789789                                        elif (token == "}"):
    790790                                                indent -= 1
    791                                        
     791
    792792                                        if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
    793793                                                bp = split_bp(finalization)
    794794                                                finalization = None
    795                                                
     795
    796796                                                if (not frame in frame_properties):
    797797                                                        frame_properties[frame] = {}
    798                                                
     798
    799799                                                if ('finalization' in frame_properties[frame]):
    800800                                                        print("%s: Finalization protocol for frame '%s' already defined" % (inname, frame))
    801801                                                else:
    802802                                                        frame_properties[frame]['finalization'] = bp
    803                                                
     803
    804804                                                output += "\n%s" % tabs(2)
    805805                                                output += parse_bp(inname, bp, 2)
    806                                                
     806
    807807                                                context.remove(FINALIZATION)
    808808                                                if (indent == -1):
     
    817817                                                finalization += token
    818818                                                continue
    819                                
     819
    820820                                if (INITIALIZATION in context):
    821821                                        if (token == "{"):
     
    823823                                        elif (token == "}"):
    824824                                                indent -= 1
    825                                        
     825
    826826                                        if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
    827827                                                bp = split_bp(initialization)
    828828                                                initialization = None
    829                                                
     829
    830830                                                if (not frame in frame_properties):
    831831                                                        frame_properties[frame] = {}
    832                                                
     832
    833833                                                if ('initialization' in frame_properties[frame]):
    834834                                                        print("%s: Initialization protocol for frame '%s' already defined" % (inname, frame))
    835835                                                else:
    836836                                                        frame_properties[frame]['initialization'] = bp
    837                                                
     837
    838838                                                output += "\n%s" % tabs(2)
    839839                                                output += parse_bp(inname, bp, 2)
    840                                                
     840
    841841                                                context.remove(INITIALIZATION)
    842842                                                if (indent == -1):
     
    851851                                                initialization += token
    852852                                                continue
    853                                
     853
    854854                                if (PROTOCOL in context):
    855855                                        if (token == "{"):
     
    857857                                        elif (token == "}"):
    858858                                                indent -= 1
    859                                        
     859
    860860                                        if (((token[-1] == ":") and (indent == 0)) or (indent == -1)):
    861861                                                bp = split_bp(protocol)
    862862                                                protocol = None
    863                                                
     863
    864864                                                if (not frame in frame_properties):
    865865                                                        frame_properties[frame] = {}
    866                                                
     866
    867867                                                if ('protocol' in frame_properties[frame]):
    868868                                                        print("%s: Protocol for frame '%s' already defined" % (inname, frame))
    869869                                                else:
    870870                                                        frame_properties[frame]['protocol'] = bp
    871                                                
     871
    872872                                                output += "\n%s" % tabs(2)
    873873                                                output += parse_bp(inname, bp, 2)
    874                                                
     874
    875875                                                context.remove(PROTOCOL)
    876876                                                if (indent == -1):
     
    885885                                                protocol += token
    886886                                                continue
    887                                
     887
    888888                                if (REQUIRES in context):
    889889                                        if (FIN in context):
     
    892892                                                else:
    893893                                                        output += "%s" % token
    894                                                
     894
    895895                                                context.remove(FIN)
    896896                                                continue
    897                                        
     897
    898898                                        if (VAR in context):
    899899                                                if (not identifier(token)):
     
    902902                                                        if (not frame in frame_properties):
    903903                                                                frame_properties[frame] = {}
    904                                                        
     904
    905905                                                        if (not 'requires' in frame_properties[frame]):
    906906                                                                frame_properties[frame]['requires'] = []
    907                                                        
     907
    908908                                                        frame_properties[frame]['requires'].append({'iface': arg0, 'var': token})
    909909                                                        arg0 = None
    910                                                        
     910
    911911                                                        output += "%s" % token
    912                                                
     912
    913913                                                context.remove(VAR)
    914914                                                context.add(FIN)
    915915                                                continue
    916                                        
     916
    917917                                        if ((token == "}") or (token[-1] == ":")):
    918918                                                context.remove(REQUIRES)
     
    923923                                                        arg0 = token
    924924                                                        output += "\n%s%s " % (tabs(indent), token)
    925                                                
     925
    926926                                                context.add(VAR)
    927927                                                continue
    928                                
     928
    929929                                if (PROVIDES in context):
    930930                                        if (FIN in context):
     
    933933                                                else:
    934934                                                        output += "%s" % token
    935                                                
     935
    936936                                                context.remove(FIN)
    937937                                                continue
    938                                        
     938
    939939                                        if (VAR in context):
    940940                                                if (not identifier(token)):
     
    943943                                                        if (not frame in frame_properties):
    944944                                                                frame_properties[frame] = {}
    945                                                        
     945
    946946                                                        if (not 'provides' in frame_properties[frame]):
    947947                                                                frame_properties[frame]['provides'] = []
    948                                                        
     948
    949949                                                        frame_properties[frame]['provides'].append({'iface': arg0, 'var': token})
    950950                                                        arg0 = None
    951                                                        
     951
    952952                                                        output += "%s" % token
    953                                                
     953
    954954                                                context.remove(VAR)
    955955                                                context.add(FIN)
    956956                                                continue
    957                                        
     957
    958958                                        if ((token == "}") or (token[-1] == ":")):
    959959                                                context.remove(PROVIDES)
     
    964964                                                        arg0 = token
    965965                                                        output += "\n%s%s " % (tabs(indent), token)
    966                                                
     966
    967967                                                context.add(VAR)
    968968                                                continue
    969                                
     969
    970970                                if (token == "}"):
    971971                                        if (indent != 2):
     
    974974                                                indent = 0
    975975                                                output += "\n%s" % token
    976                                        
     976
    977977                                        context.remove(BODY)
    978978                                        context.add(NULL)
    979979                                        continue
    980                                
     980
    981981                                if (token == "provides:"):
    982982                                        output += "\n%s%s" % (tabs(indent - 1), token)
    983983                                        context.add(PROVIDES)
    984984                                        continue
    985                                
     985
    986986                                if (token == "requires:"):
    987987                                        output += "\n%s%s" % (tabs(indent - 1), token)
    988988                                        context.add(REQUIRES)
    989989                                        continue
    990                                
     990
    991991                                if (token == "initialization:"):
    992992                                        output += "\n%s%s" % (tabs(indent - 1), token)
     
    995995                                        initialization = ""
    996996                                        continue
    997                                
     997
    998998                                if (token == "finalization:"):
    999999                                        output += "\n%s%s" % (tabs(indent - 1), token)
     
    10021002                                        finalization = ""
    10031003                                        continue
    1004                                
     1004
    10051005                                if (token == "protocol:"):
    10061006                                        output += "\n%s%s" % (tabs(indent - 1), token)
     
    10091009                                        protocol = ""
    10101010                                        continue
    1011                                
     1011
    10121012                                print("%s: Unknown token '%s' in frame '%s'" % (inname, token, frame))
    10131013                                continue
    1014                        
     1014
    10151015                        if (HEAD in context):
    10161016                                if (token == "{"):
     
    10201020                                        context.add(BODY)
    10211021                                        continue
    1022                                
     1022
    10231023                                if (token == ";"):
    10241024                                        output += "%s\n" % token
     
    10261026                                        context.remove(FRAME)
    10271027                                        continue
    1028                                
     1028
    10291029                                print("%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame))
    1030                                
     1030
    10311031                                continue
    1032                        
     1032
    10331033                        if (not identifier(token)):
    10341034                                print("%s: Expected frame name" % inname)
     
    10361036                                frame = token
    10371037                                output += "%s " % token
    1038                                
     1038
    10391039                                if (not frame in frame_properties):
    10401040                                        frame_properties[frame] = {}
    1041                                
     1041
    10421042                                frame_properties[frame]['name'] = frame
    1043                        
     1043
    10441044                        context.add(HEAD)
    10451045                        continue
    1046                
     1046
    10471047                # "interface"
    1048                
     1048
    10491049                if (IFACE in context):
    10501050                        if (NULL in context):
     
    10531053                                else:
    10541054                                        output += "%s\n" % token
    1055                                
     1055
    10561056                                context.remove(NULL)
    10571057                                context.remove(IFACE)
    10581058                                interface = None
    10591059                                continue
    1060                        
     1060
    10611061                        if (BODY in context):
    10621062                                if (PROTOCOL in context):
     
    10651065                                        elif (token == "}"):
    10661066                                                indent -= 1
    1067                                        
     1067
    10681068                                        if (indent == -1):
    10691069                                                bp = split_bp(protocol)
    10701070                                                protocol = None
    1071                                                
     1071
    10721072                                                if (not interface in iface_properties):
    10731073                                                        iface_properties[interface] = {}
    1074                                                
     1074
    10751075                                                if ('protocol' in iface_properties[interface]):
    10761076                                                        print("%s: Protocol for interface '%s' already defined" % (inname, interface))
    10771077                                                else:
    10781078                                                        iface_properties[interface]['protocol'] = bp
    1079                                                
     1079
    10801080                                                output += "\n%s" % tabs(2)
    10811081                                                output += parse_bp(inname, bp, 2)
    10821082                                                output += "\n%s" % token
    10831083                                                indent = 0
    1084                                                
     1084
    10851085                                                context.remove(PROTOCOL)
    10861086                                                context.remove(BODY)
     
    10881088                                        else:
    10891089                                                protocol += token
    1090                                        
    1091                                         continue
    1092                                
     1090
     1091                                        continue
     1092
    10931093                                if (PROTOTYPE in context):
    10941094                                        if (FIN in context):
     
    10971097                                                else:
    10981098                                                        output += "%s" % token
    1099                                                
     1099
    11001100                                                context.remove(FIN)
    11011101                                                context.remove(PROTOTYPE)
    11021102                                                continue
    1103                                        
     1103
    11041104                                        if (PAR_RIGHT in context):
    11051105                                                if (token == ")"):
     
    11091109                                                else:
    11101110                                                        output += " %s" % token
    1111                                                
    1112                                                 continue
    1113                                        
     1111
     1112                                                continue
     1113
    11141114                                        if (SIGNATURE in context):
    11151115                                                output += "%s" % token
     
    11171117                                                        context.remove(SIGNATURE)
    11181118                                                        context.add(FIN)
    1119                                                
     1119
    11201120                                                context.remove(SIGNATURE)
    11211121                                                context.add(PAR_RIGHT)
    11221122                                                continue
    1123                                        
     1123
    11241124                                        if (PAR_LEFT in context):
    11251125                                                if (token != "("):
     
    11271127                                                else:
    11281128                                                        output += "%s" % token
    1129                                                
     1129
    11301130                                                context.remove(PAR_LEFT)
    11311131                                                context.add(SIGNATURE)
    11321132                                                continue
    1133                                        
     1133
    11341134                                        if (not identifier(token)):
    11351135                                                print("%s: Method identifier expected in interface '%s'" % (inname, interface))
    11361136                                        else:
    11371137                                                output += "%s" % token
    1138                                        
     1138
    11391139                                        context.add(PAR_LEFT)
    11401140                                        continue
    1141                                
     1141
    11421142                                if (token == "}"):
    11431143                                        if (indent != 2):
     
    11461146                                                indent = 0
    11471147                                                output += "\n%s" % token
    1148                                        
     1148
    11491149                                        context.remove(BODY)
    11501150                                        context.add(NULL)
    11511151                                        continue
    1152                                
     1152
    11531153                                if (token == "sysarg_t"):
    11541154                                        output += "\n%s%s " % (tabs(indent), token)
    11551155                                        context.add(PROTOTYPE)
    11561156                                        continue
    1157                                
     1157
    11581158                                if (token == "protocol:"):
    11591159                                        output += "\n%s%s" % (tabs(indent - 1), token)
     
    11621162                                        protocol = ""
    11631163                                        continue
    1164                                
     1164
    11651165                                print("%s: Unknown token '%s' in interface '%s'" % (inname, token, interface))
    11661166                                continue
    1167                        
     1167
    11681168                        if (HEAD in context):
    11691169                                if (PRE_BODY in context):
     
    11751175                                                context.add(BODY)
    11761176                                                continue
    1177                                        
     1177
    11781178                                        if (token == ";"):
    11791179                                                output += "%s\n" % token
     
    11821182                                                context.remove(IFACE)
    11831183                                                continue
    1184                                                
     1184
    11851185                                        print("%s: Expected '{' or ';' in interface head '%s'" % (inname, interface))
    11861186                                        continue
    1187                                
     1187
    11881188                                if (EXTENDS in context):
    11891189                                        if (not identifier(token)):
     
    11931193                                                if (not interface in iface_properties):
    11941194                                                        iface_properties[interface] = {}
    1195                                                
     1195
    11961196                                                iface_properties[interface]['extends'] = token
    1197                                        
     1197
    11981198                                        context.remove(EXTENDS)
    11991199                                        context.add(PRE_BODY)
    12001200                                        continue
    1201                                
     1201
    12021202                                if (token == "extends"):
    12031203                                        output += "%s " % token
    12041204                                        context.add(EXTENDS)
    12051205                                        continue
    1206                                        
     1206
    12071207                                if (token == "{"):
    12081208                                        output += "%s" % token
     
    12111211                                        context.add(BODY)
    12121212                                        continue
    1213                                
     1213
    12141214                                if (token == ";"):
    12151215                                        output += "%s\n" % token
     
    12171217                                        context.remove(IFACE)
    12181218                                        continue
    1219                                
     1219
    12201220                                print("%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface))
    12211221                                continue
    1222                        
     1222
    12231223                        if (not identifier(token)):
    12241224                                print("%s: Expected interface name" % inname)
     
    12261226                                interface = token
    12271227                                output += "%s " % token
    1228                                
     1228
    12291229                                if (not interface in iface_properties):
    12301230                                        iface_properties[interface] = {}
    1231                                
     1231
    12321232                                iface_properties[interface]['name'] = interface
    1233                        
     1233
    12341234                        context.add(HEAD)
    12351235                        continue
    1236                
     1236
    12371237                # "architecture"
    1238                
     1238
    12391239                if (ARCH in context):
    12401240                        if (NULL in context):
     
    12431243                                else:
    12441244                                        output += "%s\n" % token
    1245                                
     1245
    12461246                                context.remove(NULL)
    12471247                                context.remove(ARCH)
     
    12491249                                architecture = None
    12501250                                continue
    1251                        
     1251
    12521252                        if (BODY in context):
    12531253                                if (DELEGATE in context):
     
    12571257                                                else:
    12581258                                                        output += "%s" % token
    1259                                                
     1259
    12601260                                                context.remove(FIN)
    12611261                                                context.remove(DELEGATE)
    12621262                                                continue
    1263                                        
     1263
    12641264                                        if (VAR in context):
    12651265                                                if (not descriptor(token)):
     
    12681268                                                        if (not architecture in arch_properties):
    12691269                                                                arch_properties[architecture] = {}
    1270                                                        
     1270
    12711271                                                        if (not 'delegate' in arch_properties[architecture]):
    12721272                                                                arch_properties[architecture]['delegate'] = []
    1273                                                        
     1273
    12741274                                                        arch_properties[architecture]['delegate'].append({'from': arg0, 'to': token.split(":")})
    12751275                                                        arg0 = None
    1276                                                        
     1276
    12771277                                                        output += "%s" % token
    1278                                                
     1278
    12791279                                                context.add(FIN)
    12801280                                                context.remove(VAR)
    12811281                                                continue
    1282                                        
     1282
    12831283                                        if (TO in context):
    12841284                                                if (token != "to"):
     
    12861286                                                else:
    12871287                                                        output += "%s " % token
    1288                                                
     1288
    12891289                                                context.add(VAR)
    12901290                                                context.remove(TO)
    12911291                                                continue
    1292                                        
     1292
    12931293                                        if (not identifier(token)):
    12941294                                                print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
     
    12961296                                                output += "%s " % token
    12971297                                                arg0 = token
    1298                                        
     1298
    12991299                                        context.add(TO)
    13001300                                        continue
    1301                                
     1301
    13021302                                if (SUBSUME in context):
    13031303                                        if (FIN in context):
     
    13061306                                                else:
    13071307                                                        output += "%s" % token
    1308                                                
     1308
    13091309                                                context.remove(FIN)
    13101310                                                context.remove(SUBSUME)
    13111311                                                continue
    1312                                        
     1312
    13131313                                        if (VAR in context):
    13141314                                                if (not identifier(token)):
     
    13171317                                                        if (not architecture in arch_properties):
    13181318                                                                arch_properties[architecture] = {}
    1319                                                        
     1319
    13201320                                                        if (not 'subsume' in arch_properties[architecture]):
    13211321                                                                arch_properties[architecture]['subsume'] = []
    1322                                                        
     1322
    13231323                                                        arch_properties[architecture]['subsume'].append({'from': arg0.split(":"), 'to': token})
    13241324                                                        arg0 = None
    1325                                                        
     1325
    13261326                                                        output += "%s" % token
    1327                                                
     1327
    13281328                                                context.add(FIN)
    13291329                                                context.remove(VAR)
    13301330                                                continue
    1331                                        
     1331
    13321332                                        if (TO in context):
    13331333                                                if (token != "to"):
     
    13351335                                                else:
    13361336                                                        output += "%s " % token
    1337                                                
     1337
    13381338                                                context.add(VAR)
    13391339                                                context.remove(TO)
    13401340                                                continue
    1341                                        
     1341
    13421342                                        if (not descriptor(token)):
    13431343                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
     
    13451345                                                output += "%s " % token
    13461346                                                arg0 = token
    1347                                        
     1347
    13481348                                        context.add(TO)
    13491349                                        continue
    1350                                
     1350
    13511351                                if (BIND in context):
    13521352                                        if (FIN in context):
     
    13551355                                                else:
    13561356                                                        output += "%s" % token
    1357                                                
     1357
    13581358                                                context.remove(FIN)
    13591359                                                context.remove(BIND)
    13601360                                                continue
    1361                                        
     1361
    13621362                                        if (VAR in context):
    13631363                                                if (not descriptor(token)):
     
    13661366                                                        if (not architecture in arch_properties):
    13671367                                                                arch_properties[architecture] = {}
    1368                                                        
     1368
    13691369                                                        if (not 'bind' in arch_properties[architecture]):
    13701370                                                                arch_properties[architecture]['bind'] = []
    1371                                                        
     1371
    13721372                                                        arch_properties[architecture]['bind'].append({'from': arg0.split(":"), 'to': token.split(":")})
    13731373                                                        arg0 = None
    1374                                                        
     1374
    13751375                                                        output += "%s" % token
    1376                                                
     1376
    13771377                                                context.add(FIN)
    13781378                                                context.remove(VAR)
    13791379                                                continue
    1380                                        
     1380
    13811381                                        if (TO in context):
    13821382                                                if (token != "to"):
     
    13841384                                                else:
    13851385                                                        output += "%s " % token
    1386                                                
     1386
    13871387                                                context.add(VAR)
    13881388                                                context.remove(TO)
    13891389                                                continue
    1390                                        
     1390
    13911391                                        if (not descriptor(token)):
    13921392                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
     
    13941394                                                output += "%s " % token
    13951395                                                arg0 = token
    1396                                        
     1396
    13971397                                        context.add(TO)
    13981398                                        continue
    1399                                
     1399
    14001400                                if (INST in context):
    14011401                                        if (FIN in context):
     
    14041404                                                else:
    14051405                                                        output += "%s" % token
    1406                                                
     1406
    14071407                                                context.remove(FIN)
    14081408                                                context.remove(INST)
    14091409                                                continue
    1410                                        
     1410
    14111411                                        if (VAR in context):
    14121412                                                if (not identifier(token)):
     
    14151415                                                        if (not architecture in arch_properties):
    14161416                                                                arch_properties[architecture] = {}
    1417                                                        
     1417
    14181418                                                        if (not 'inst' in arch_properties[architecture]):
    14191419                                                                arch_properties[architecture]['inst'] = []
    1420                                                        
     1420
    14211421                                                        arch_properties[architecture]['inst'].append({'type': arg0, 'var': token})
    14221422                                                        arg0 = None
    1423                                                        
     1423
    14241424                                                        output += "%s" % token
    1425                                                
     1425
    14261426                                                context.add(FIN)
    14271427                                                context.remove(VAR)
    14281428                                                continue
    1429                                        
     1429
    14301430                                        if (not identifier(token)):
    14311431                                                print("%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture))
     
    14331433                                                output += "%s " % token
    14341434                                                arg0 = token
    1435                                        
     1435
    14361436                                        context.add(VAR)
    14371437                                        continue
    1438                                
     1438
    14391439                                if (token == "}"):
    14401440                                        if (indent != 1):
     
    14431443                                                indent -= 1
    14441444                                                output += "\n%s" % token
    1445                                        
     1445
    14461446                                        context.remove(BODY)
    14471447                                        context.add(NULL)
    14481448                                        continue
    1449                                
     1449
    14501450                                if (token == "inst"):
    14511451                                        output += "\n%s%s " % (tabs(indent), token)
    14521452                                        context.add(INST)
    14531453                                        continue
    1454                                
     1454
    14551455                                if (token == "bind"):
    14561456                                        output += "\n%s%s " % (tabs(indent), token)
    14571457                                        context.add(BIND)
    14581458                                        continue
    1459                                
     1459
    14601460                                if (token == "subsume"):
    14611461                                        output += "\n%s%s " % (tabs(indent), token)
    14621462                                        context.add(SUBSUME)
    14631463                                        continue
    1464                                
     1464
    14651465                                if (token == "delegate"):
    14661466                                        output += "\n%s%s " % (tabs(indent), token)
    14671467                                        context.add(DELEGATE)
    14681468                                        continue
    1469                                
     1469
    14701470                                print("%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture))
    14711471                                continue
    1472                        
     1472
    14731473                        if (HEAD in context):
    14741474                                if (token == "{"):
     
    14781478                                        context.add(BODY)
    14791479                                        continue
    1480                                
     1480
    14811481                                if (token == ";"):
    14821482                                        output += "%s\n" % token
     
    14851485                                        context.discard(SYSTEM)
    14861486                                        continue
    1487                                
     1487
    14881488                                if (not word(token)):
    14891489                                        print("%s: Expected word in architecture head '%s'" % (inname, architecture))
    14901490                                else:
    14911491                                        output += "%s " % token
    1492                                
     1492
    14931493                                continue
    1494                        
     1494
    14951495                        if (not identifier(token)):
    14961496                                print("%s: Expected architecture name" % inname)
     
    14981498                                architecture = token
    14991499                                output += "%s " % token
    1500                                
     1500
    15011501                                if (not architecture in arch_properties):
    15021502                                        arch_properties[architecture] = {}
    1503                                
     1503
    15041504                                arch_properties[architecture]['name'] = architecture
    1505                                
     1505
    15061506                                if (SYSTEM in context):
    15071507                                        arch_properties[architecture]['system'] = True
    1508                        
     1508
    15091509                        context.add(HEAD)
    15101510                        continue
    1511                
     1511
    15121512                # "system architecture"
    1513                
     1513
    15141514                if (SYSTEM in context):
    15151515                        if (token != "architecture"):
     
    15171517                        else:
    15181518                                output += "%s " % token
    1519                        
     1519
    15201520                        context.add(ARCH)
    15211521                        continue
    1522                
     1522
    15231523                if (token == "frame"):
    15241524                        output += "\n%s " % token
    15251525                        context.add(FRAME)
    15261526                        continue
    1527                
     1527
    15281528                if (token == "interface"):
    15291529                        output += "\n%s " % token
    15301530                        context.add(IFACE)
    15311531                        continue
    1532                
     1532
    15331533                if (token == "system"):
    15341534                        output += "\n%s " % token
    15351535                        context.add(SYSTEM)
    15361536                        continue
    1537                
     1537
    15381538                if (token == "architecture"):
    15391539                        output += "\n%s " % token
    15401540                        context.add(ARCH)
    15411541                        continue
    1542                
     1542
    15431543                print("%s: Unknown token '%s'" % (inname, token))
    1544        
     1544
    15451545        inf.close()
    15461546
    15471547def open_adl(base, root, inname, outdir, outname):
    15481548        "Open Architecture Description file"
    1549        
     1549
    15501550        global output
    15511551        global context
     
    15561556        global initialization
    15571557        global finalization
    1558        
     1558
    15591559        global arg0
    1560        
     1560
    15611561        global opt_adl
    1562        
     1562
    15631563        output = ""
    15641564        context = set()
     
    15701570        finalization = None
    15711571        arg0 = None
    1572        
     1572
    15731573        parse_adl(base, root, inname, False, 0)
    15741574        output = output.strip()
    1575        
     1575
    15761576        if ((output != "") and (opt_adl)):
    15771577                outf = open(outname, "w")
     
    15811581def recursion(base, root, output, level):
    15821582        "Recursive directory walk"
    1583        
     1583
    15841584        for name in os.listdir(root):
    15851585                canon = os.path.join(root, name)
    1586                
     1586
    15871587                if (os.path.isfile(canon)):
    15881588                        fcomp = split_tokens(canon, ["."])
    15891589                        cname = canon.split("/")
    1590                        
     1590
    15911591                        if (fcomp[-1] == ".adl"):
    15921592                                output_path = os.path.join(output, cname[-1])
    15931593                                open_adl(base, root, canon, output, output_path)
    1594                
     1594
    15951595                if (os.path.isdir(canon)):
    15961596                        recursion(base, canon, output, level + 1)
     
    15981598def merge_dot_frame(prefix, name, frame, outf, indent):
    15991599        "Dump Dot frame"
    1600        
     1600
    16011601        outf.write("%ssubgraph cluster_%s {\n" % (tabs(indent), prefix))
    16021602        outf.write("%s\tlabel=\"%s\";\n" % (tabs(indent), name))
     
    16051605        outf.write("%s\tfillcolor=yellow;\n" % tabs(indent))
    16061606        outf.write("%s\t\n" % tabs(indent))
    1607        
     1607
    16081608        if ('provides' in frame):
    16091609                outf.write("%s\t%s__provides [label=\"\", shape=doublecircle, style=filled, color=green, fillcolor=yellow];\n" % (tabs(indent), prefix))
    1610        
     1610
    16111611        if ('requires' in frame):
    16121612                outf.write("%s\t%s__requires [label=\"\", shape=circle, style=filled, color=red, fillcolor=yellow];\n" % (tabs(indent), prefix))
    1613        
     1613
    16141614        outf.write("%s}\n" % tabs(indent))
    16151615        outf.write("%s\n" % tabs(indent))
     
    16171617def merge_dot_arch(prefix, name, arch, outf, indent):
    16181618        "Dump Dot subarchitecture"
    1619        
     1619
    16201620        outf.write("%ssubgraph cluster_%s {\n" % (tabs(indent), prefix))
    16211621        outf.write("%s\tlabel=\"%s\";\n" % (tabs(indent), name))
    16221622        outf.write("%s\tcolor=red;\n" % tabs(indent))
    16231623        outf.write("%s\t\n" % tabs(indent))
    1624        
     1624
    16251625        if ('inst' in arch):
    16261626                for inst in arch['inst']:
     
    16341634                                else:
    16351635                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    1636        
     1636
    16371637        if ('bind' in arch):
    16381638                labels = {}
     
    16421642                        else:
    16431643                                label = bind['from'][1]
    1644                        
     1644
    16451645                        if (not (bind['from'][0], bind['to'][0]) in labels):
    16461646                                labels[(bind['from'][0], bind['to'][0])] = []
    1647                        
     1647
    16481648                        labels[(bind['from'][0], bind['to'][0])].append(label)
    1649                
     1649
    16501650                for bind in arch['bind']:
    16511651                        if (not (bind['from'][0], bind['to'][0]) in labels):
    16521652                                continue
    1653                        
     1653
    16541654                        attrs = []
    1655                        
     1655
    16561656                        if (bind['from'][0] != bind['to'][0]):
    16571657                                attrs.append("ltail=cluster_%s_%s" % (prefix, bind['from'][0]))
    16581658                                attrs.append("lhead=cluster_%s_%s" % (prefix, bind['to'][0]))
    1659                        
     1659
    16601660                        attrs.append("label=\"%s\"" % "\\n".join(labels[(bind['from'][0], bind['to'][0])]))
    16611661                        del labels[(bind['from'][0], bind['to'][0])]
    1662                        
     1662
    16631663                        outf.write("%s\t%s_%s__requires -> %s_%s__provides [%s];\n" % (tabs(indent), prefix, bind['from'][0], prefix, bind['to'][0], ", ".join(attrs)))
    1664        
     1664
    16651665        if ('delegate' in arch):
    16661666                outf.write("%s\t%s__provides [label=\"\", shape=doublecircle, color=green];\n" % (tabs(indent), prefix))
    1667                
     1667
    16681668                labels = {}
    16691669                for delegate in arch['delegate']:
     
    16721672                        else:
    16731673                                label = delegate['from']
    1674                        
     1674
    16751675                        if (not delegate['to'][0] in labels):
    16761676                                labels[delegate['to'][0]] = []
    1677                        
     1677
    16781678                        labels[delegate['to'][0]].append(label)
    1679                
     1679
    16801680                for delegate in arch['delegate']:
    16811681                        if (not delegate['to'][0] in labels):
    16821682                                continue
    1683                        
     1683
    16841684                        attrs = []
    16851685                        attrs.append("color=gray")
     
    16871687                        attrs.append("label=\"%s\"" % "\\n".join(labels[delegate['to'][0]]))
    16881688                        del labels[delegate['to'][0]]
    1689                        
     1689
    16901690                        outf.write("%s\t%s__provides -> %s_%s__provides [%s];\n" % (tabs(indent), prefix, prefix, delegate['to'][0], ", ".join(attrs)))
    1691        
     1691
    16921692        if ('subsume' in arch):
    16931693                outf.write("%s\t%s__requires [label=\"\", shape=circle, color=red];\n" % (tabs(indent), prefix))
    1694                
     1694
    16951695                labels = {}
    16961696                for subsume in arch['subsume']:
     
    16991699                        else:
    17001700                                label = subsume['to']
    1701                        
     1701
    17021702                        if (not subsume['from'][0] in labels):
    17031703                                labels[subsume['from'][0]] = []
    1704                        
     1704
    17051705                        labels[subsume['from'][0]].append(label)
    1706                
     1706
    17071707                for subsume in arch['subsume']:
    17081708                        if (not subsume['from'][0] in labels):
    17091709                                continue
    1710                        
     1710
    17111711                        attrs = []
    17121712                        attrs.append("color=gray")
     
    17141714                        attrs.append("label=\"%s\"" % "\\n".join(labels[subsume['from'][0]]))
    17151715                        del labels[subsume['from'][0]]
    1716                        
     1716
    17171717                        outf.write("%s\t%s_%s__requires -> %s__requires [%s];\n" % (tabs(indent), prefix, subsume['from'][0], prefix, ", ".join(attrs)))
    1718        
     1718
    17191719        outf.write("%s}\n" % tabs(indent))
    17201720        outf.write("%s\n" % tabs(indent))
     
    17221722def dump_dot(outdir):
    17231723        "Dump Dot architecture"
    1724        
     1724
    17251725        global opt_dot
    1726        
     1726
    17271727        arch = get_system_arch()
    1728        
     1728
    17291729        if (arch is None):
    17301730                print("Unable to find system architecture")
    17311731                return
    1732        
     1732
    17331733        if (opt_dot):
    17341734                outname = os.path.join(outdir, "%s.dot" % arch['name'])
    17351735                outf = open(outname, "w")
    1736                
     1736
    17371737                outf.write("digraph {\n")
    17381738                outf.write("\tlabel=\"%s\";\n" % arch['name'])
     
    17411741                outf.write("\tedge [fontsize=8];\n")
    17421742                outf.write("\t\n")
    1743                
     1743
    17441744                if ('inst' in arch):
    17451745                        for inst in arch['inst']:
     
    17531753                                        else:
    17541754                                                print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    1755                
     1755
    17561756                if ('bind' in arch):
    17571757                        labels = {}
     
    17611761                                else:
    17621762                                        label = bind['from'][1]
    1763                                
     1763
    17641764                                if (not (bind['from'][0], bind['to'][0]) in labels):
    17651765                                        labels[(bind['from'][0], bind['to'][0])] = []
    1766                                
     1766
    17671767                                labels[(bind['from'][0], bind['to'][0])].append(label)
    1768                        
     1768
    17691769                        for bind in arch['bind']:
    17701770                                if (not (bind['from'][0], bind['to'][0]) in labels):
    17711771                                        continue
    1772                                
     1772
    17731773                                attrs = []
    1774                                
     1774
    17751775                                if (bind['from'][0] != bind['to'][0]):
    17761776                                        attrs.append("ltail=cluster_%s" % bind['from'][0])
    17771777                                        attrs.append("lhead=cluster_%s" % bind['to'][0])
    1778                                
     1778
    17791779                                attrs.append("label=\"%s\"" % "\\n".join(labels[(bind['from'][0], bind['to'][0])]))
    17801780                                del labels[(bind['from'][0], bind['to'][0])]
    1781                                
     1781
    17821782                                outf.write("\t%s__requires -> %s__provides [%s];\n" % (bind['from'][0], bind['to'][0], ", ".join(attrs)))
    1783                
     1783
    17841784                if ('delegate' in arch):
    17851785                        for delegate in arch['delegate']:
    17861786                                print("Unable to delegate interface in system architecture")
    17871787                                break
    1788                
     1788
    17891789                if ('subsume' in arch):
    17901790                        for subsume in arch['subsume']:
    17911791                                print("Unable to subsume interface in system architecture")
    17921792                                break
    1793                
     1793
    17941794                outf.write("}\n")
    1795                
     1795
    17961796                outf.close()
    17971797
     
    18041804        global opt_adl
    18051805        global opt_dot
    1806        
     1806
    18071807        if (len(sys.argv) < 3):
    18081808                usage(sys.argv[0])
    18091809                return
    1810        
     1810
    18111811        opt_bp = False
    18121812        opt_ebp = False
    18131813        opt_adl = False
    18141814        opt_dot = False
    1815        
     1815
    18161816        for arg in sys.argv[1:(len(sys.argv) - 1)]:
    18171817                if (arg == "--bp"):
     
    18281828                        print("Error: Unknown command line option '%s'" % arg)
    18291829                        return
    1830        
     1830
    18311831        if ((opt_bp) and (opt_ebp)):
    18321832                print("Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols")
    18331833                return
    1834        
     1834
    18351835        path = os.path.abspath(sys.argv[-1])
    18361836        if (not os.path.isdir(path)):
    18371837                print("Error: <OUTPUT> is not a directory")
    18381838                return
    1839        
     1839
    18401840        iface_properties = {}
    18411841        frame_properties = {}
    18421842        arch_properties = {}
    1843        
     1843
    18441844        recursion(".", ".", path, 0)
    18451845        dump_archbp(path)
Note: See TracChangeset for help on using the changeset viewer.