Changeset 28f4adb in mainline for contrib/arch/hadlbppp.py


Ignore:
Timestamp:
2010-11-02T11:13:36Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4687a26c, e06ef614
Parents:
458619f7
git-author:
Vojtech Horky <> (2010-11-02 11:13:36)
git-committer:
Martin Decky <martin@…> (2010-11-02 11:13:36)
Message:

update scripts for compatibility with Python 3 (thx Vojtech Horky and Martin Sucha)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/arch/hadlbppp.py

    r458619f7 r28f4adb  
    4242        "Print usage syntax"
    4343       
    44         print "%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname
    45         print
    46         print "--bp   Dump original Behavior Protocols (dChecker, BPSlicer)"
    47         print "--ebp  Dump Extended Behavior Protocols (bp2promela)"
    48         print "--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)"
    49         print "--dot  Dump Dot architecture diagram (GraphViz)"
    50         print "--nop  Do not dump anything (just input files syntax check)"
    51         print
     44        print("%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname)
     45        print()
     46        print("--bp   Dump original Behavior Protocols (dChecker, BPSlicer)")
     47        print("--ebp  Dump Extended Behavior Protocols (bp2promela)")
     48        print("--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)")
     49        print("--dot  Dump Dot architecture diagram (GraphViz)")
     50        print("--nop  Do not dump anything (just input files syntax check)")
     51        print()
    5252
    5353def tabs(cnt):
     
    163163                                                result.append(tokens[i])
    164164                                else:
    165                                         print "%s: Syntax error in tentative statement" % name
     165                                        print("%s: Syntax error in tentative statement" % name)
    166166                        else:
    167                                 print "%s: Expected '{' for tentative statement" % name
     167                                print("%s: Expected '{' for tentative statement" % name)
    168168                else:
    169169                        result.append(tokens[i])
     
    231231                                                                result.append(tokens[i])
    232232                                                else:
    233                                                         print "%s: Syntax error in alternative statement" % name
     233                                                        print("%s: Syntax error in alternative statement" % name)
    234234                                        else:
    235                                                 print "%s: Expected '{' for alternative statement body" % name
     235                                                print("%s: Expected '{' for alternative statement body" % name)
    236236                                else:
    237                                         print "%s: At least one pattern and one replacement required for alternative statement" % name
     237                                        print("%s: At least one pattern and one replacement required for alternative statement" % name)
    238238                        else:
    239                                 print "%s: Expected '(' for alternative statement head" % name
     239                                print("%s: Expected '(' for alternative statement head" % name)
    240240                else:
    241241                        result.append(tokens[i])
     
    269269                                        result.append(tokens[i])
    270270                        else:
    271                                 print "%s: Unexpected end of protocol" % name
     271                                print("%s: Unexpected end of protocol" % name)
    272272               
    273273                i += 1
     
    349349                elif (token == ")"):
    350350                        if (indent < base_indent):
    351                                 print "%s: Too many parentheses" % name
     351                                print("%s: Too many parentheses" % name)
    352352                       
    353353                        indent -= 1
     
    358358                elif (token == "}"):
    359359                        if (indent < base_indent):
    360                                 print "%s: Too many parentheses" % name
     360                                print("%s: Too many parentheses" % name)
    361361                       
    362362                        indent -= 1
     
    370370       
    371371        if (indent > base_indent):
    372                 print "%s: Missing parentheses" % name
     372                print("%s: Missing parentheses" % name)
    373373       
    374374        output = output.strip()
     
    405405                        result.extend(inherited_protocols(supiface))
    406406                else:
    407                         print "%s: Extends unknown interface '%s'" % (iface['name'], iface['extends'])
     407                        print("%s: Extends unknown interface '%s'" % (iface['name'], iface['extends']))
    408408       
    409409        return result
     
    459459                                                protocols.append(proto)
    460460                        else:
    461                                 print "%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface'])
     461                                print("%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface']))
    462462       
    463463        if (opt_bp):
    464                 outf = file(outname, "w")
     464                outf = open(outname, "w")
    465465                outf.write(parse_bp(outname, merge_bp(initialization, finalization, protocols), 0))
    466466                outf.close()
    467467       
    468468        if (opt_ebp):
    469                 outf = file(outname, "w")
     469                outf = open(outname, "w")
    470470                outf.write(parse_ebp(frame['name'], outname, merge_bp(initialization, finalization, protocols), 0))
    471471                outf.close()
     
    514514       
    515515        if (opt_bp):
    516                 outf = file(outname, "w")
     516                outf = open(outname, "w")
    517517                outf.write("NULL")
    518518                outf.close()
    519519       
    520520        if (opt_ebp):
    521                 outf = file(outname, "w")
     521                outf = open(outname, "w")
    522522                outf.write("component null {\n\tbehavior {\n\t\tNULL\n\t}\n}")
    523523                outf.close()
     
    587587                                        insts.append({'var': "%s_%s" % (prefix, inst['var']), 'frame': subframe})
    588588                                else:
    589                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     589                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    590590       
    591591        if ('bind' in arch):
     
    612612       
    613613        if (arch is None):
    614                 print "Unable to find system architecture"
     614                print("Unable to find system architecture")
    615615                return
    616616       
     
    634634                                        insts.append({'var': inst['var'], 'frame': subframe})
    635635                                else:
    636                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     636                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    637637       
    638638        if ('bind' in arch):
     
    642642        if ('delegate' in arch):
    643643                for delegate in arch['delegate']:
    644                         print "Unable to delegate interface in system architecture"
     644                        print("Unable to delegate interface in system architecture")
    645645                        break
    646646       
    647647        if ('subsume' in arch):
    648648                for subsume in arch['subsume']:
    649                         print "Unable to subsume interface in system architecture"
     649                        print("Unable to subsume interface in system architecture")
    650650                        break
    651651       
     
    654654        outname = os.path.join(outdir, "%s.archbp" % arch['name'])
    655655        if ((opt_bp) or (opt_ebp)):
    656                 outf = file(outname, "w")
     656                outf = open(outname, "w")
    657657        else:
    658658                outf = None
     
    709709               
    710710                if (not os.path.isfile(path)):
    711                         print "%s: Unable to include file %s" % (inname, path)
     711                        print("%s: Unable to include file %s" % (inname, path))
    712712                        return ""
    713713        else:
     
    716716                nested_root = root
    717717       
    718         inf = file(path, "r")
     718        inf = open(path, "r")
    719719       
    720720        raw = preproc_adl(inf.read(), inarg)
     
    733733                if (POST_INC in context):
    734734                        if (token != "]"):
    735                                 print "%s: Expected ]" % inname
     735                                print("%s: Expected ]" % inname)
    736736                       
    737737                        context.remove(POST_INC)
     
    774774                        if (NULL in context):
    775775                                if (token != ";"):
    776                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     776                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    777777                                else:
    778778                                        output += "%s\n" % token
     
    798798                                               
    799799                                                if ('finalization' in frame_properties[frame]):
    800                                                         print "%s: Finalization protocol for frame '%s' already defined" % (inname, frame)
     800                                                        print("%s: Finalization protocol for frame '%s' already defined" % (inname, frame))
    801801                                                else:
    802802                                                        frame_properties[frame]['finalization'] = bp
     
    832832                                               
    833833                                                if ('initialization' in frame_properties[frame]):
    834                                                         print "%s: Initialization protocol for frame '%s' already defined" % (inname, frame)
     834                                                        print("%s: Initialization protocol for frame '%s' already defined" % (inname, frame))
    835835                                                else:
    836836                                                        frame_properties[frame]['initialization'] = bp
     
    866866                                               
    867867                                                if ('protocol' in frame_properties[frame]):
    868                                                         print "%s: Protocol for frame '%s' already defined" % (inname, frame)
     868                                                        print("%s: Protocol for frame '%s' already defined" % (inname, frame))
    869869                                                else:
    870870                                                        frame_properties[frame]['protocol'] = bp
     
    889889                                        if (FIN in context):
    890890                                                if (token != ";"):
    891                                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     891                                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    892892                                                else:
    893893                                                        output += "%s" % token
     
    898898                                        if (VAR in context):
    899899                                                if (not identifier(token)):
    900                                                         print "%s: Variable name expected in frame '%s'" % (inname, frame)
     900                                                        print("%s: Variable name expected in frame '%s'" % (inname, frame))
    901901                                                else:
    902902                                                        if (not frame in frame_properties):
     
    919919                                        else:
    920920                                                if (not identifier(token)):
    921                                                         print "%s: Interface name expected in frame '%s'" % (inname, frame)
     921                                                        print("%s: Interface name expected in frame '%s'" % (inname, frame))
    922922                                                else:
    923923                                                        arg0 = token
     
    930930                                        if (FIN in context):
    931931                                                if (token != ";"):
    932                                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     932                                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    933933                                                else:
    934934                                                        output += "%s" % token
     
    939939                                        if (VAR in context):
    940940                                                if (not identifier(token)):
    941                                                         print "%s: Variable name expected in frame '%s'" % (inname, frame)
     941                                                        print("%s: Variable name expected in frame '%s'" % (inname, frame))
    942942                                                else:
    943943                                                        if (not frame in frame_properties):
     
    960960                                        else:
    961961                                                if (not identifier(token)):
    962                                                         print "%s: Interface name expected in frame '%s'" % (inname, frame)
     962                                                        print("%s: Interface name expected in frame '%s'" % (inname, frame))
    963963                                                else:
    964964                                                        arg0 = token
     
    970970                                if (token == "}"):
    971971                                        if (indent != 2):
    972                                                 print "%s: Wrong number of parentheses in frame '%s'" % (inname, frame)
     972                                                print("%s: Wrong number of parentheses in frame '%s'" % (inname, frame))
    973973                                        else:
    974974                                                indent = 0
     
    10101010                                        continue
    10111011                               
    1012                                 print "%s: Unknown token '%s' in frame '%s'" % (inname, token, frame)
     1012                                print("%s: Unknown token '%s' in frame '%s'" % (inname, token, frame))
    10131013                                continue
    10141014                       
     
    10271027                                        continue
    10281028                               
    1029                                 print "%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame)
     1029                                print("%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame))
    10301030                               
    10311031                                continue
    10321032                       
    10331033                        if (not identifier(token)):
    1034                                 print "%s: Expected frame name" % inname
     1034                                print("%s: Expected frame name" % inname)
    10351035                        else:
    10361036                                frame = token
     
    10501050                        if (NULL in context):
    10511051                                if (token != ";"):
    1052                                         print "%s: Expected ';' in interface '%s'" % (inname, interface)
     1052                                        print("%s: Expected ';' in interface '%s'" % (inname, interface))
    10531053                                else:
    10541054                                        output += "%s\n" % token
     
    10741074                                               
    10751075                                                if ('protocol' in iface_properties[interface]):
    1076                                                         print "%s: Protocol for interface '%s' already defined" % (inname, interface)
     1076                                                        print("%s: Protocol for interface '%s' already defined" % (inname, interface))
    10771077                                                else:
    10781078                                                        iface_properties[interface]['protocol'] = bp
     
    10941094                                        if (FIN in context):
    10951095                                                if (token != ";"):
    1096                                                         print "%s: Expected ';' in interface '%s'" % (inname, interface)
     1096                                                        print("%s: Expected ';' in interface '%s'" % (inname, interface))
    10971097                                                else:
    10981098                                                        output += "%s" % token
     
    11241124                                        if (PAR_LEFT in context):
    11251125                                                if (token != "("):
    1126                                                         print "%s: Expected '(' in interface '%s'" % (inname, interface)
     1126                                                        print("%s: Expected '(' in interface '%s'" % (inname, interface))
    11271127                                                else:
    11281128                                                        output += "%s" % token
     
    11331133                                       
    11341134                                        if (not identifier(token)):
    1135                                                 print "%s: Method identifier expected in interface '%s'" % (inname, interface)
     1135                                                print("%s: Method identifier expected in interface '%s'" % (inname, interface))
    11361136                                        else:
    11371137                                                output += "%s" % token
     
    11421142                                if (token == "}"):
    11431143                                        if (indent != 2):
    1144                                                 print "%s: Wrong number of parentheses in interface '%s'" % (inname, interface)
     1144                                                print("%s: Wrong number of parentheses in interface '%s'" % (inname, interface))
    11451145                                        else:
    11461146                                                indent = 0
     
    11631163                                        continue
    11641164                               
    1165                                 print "%s: Unknown token '%s' in interface '%s'" % (inname, token, interface)
     1165                                print("%s: Unknown token '%s' in interface '%s'" % (inname, token, interface))
    11661166                                continue
    11671167                       
     
    11831183                                                continue
    11841184                                               
    1185                                         print "%s: Expected '{' or ';' in interface head '%s'" % (inname, interface)
     1185                                        print("%s: Expected '{' or ';' in interface head '%s'" % (inname, interface))
    11861186                                        continue
    11871187                               
    11881188                                if (EXTENDS in context):
    11891189                                        if (not identifier(token)):
    1190                                                 print "%s: Expected inherited interface name in interface head '%s'" % (inname, interface)
     1190                                                print("%s: Expected inherited interface name in interface head '%s'" % (inname, interface))
    11911191                                        else:
    11921192                                                output += "%s " % token
     
    12181218                                        continue
    12191219                               
    1220                                 print "%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface)
     1220                                print("%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface))
    12211221                                continue
    12221222                       
    12231223                        if (not identifier(token)):
    1224                                 print "%s: Expected interface name" % inname
     1224                                print("%s: Expected interface name" % inname)
    12251225                        else:
    12261226                                interface = token
     
    12401240                        if (NULL in context):
    12411241                                if (token != ";"):
    1242                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1242                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    12431243                                else:
    12441244                                        output += "%s\n" % token
     
    12541254                                        if (FIN in context):
    12551255                                                if (token != ";"):
    1256                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1256                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    12571257                                                else:
    12581258                                                        output += "%s" % token
     
    12641264                                        if (VAR in context):
    12651265                                                if (not descriptor(token)):
    1266                                                         print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1266                                                        print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    12671267                                                else:
    12681268                                                        if (not architecture in arch_properties):
     
    12831283                                        if (TO in context):
    12841284                                                if (token != "to"):
    1285                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1285                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    12861286                                                else:
    12871287                                                        output += "%s " % token
     
    12921292                                       
    12931293                                        if (not identifier(token)):
    1294                                                 print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     1294                                                print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
    12951295                                        else:
    12961296                                                output += "%s " % token
     
    13031303                                        if (FIN in context):
    13041304                                                if (token != ";"):
    1305                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1305                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    13061306                                                else:
    13071307                                                        output += "%s" % token
     
    13131313                                        if (VAR in context):
    13141314                                                if (not identifier(token)):
    1315                                                         print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     1315                                                        print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
    13161316                                                else:
    13171317                                                        if (not architecture in arch_properties):
     
    13321332                                        if (TO in context):
    13331333                                                if (token != "to"):
    1334                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1334                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    13351335                                                else:
    13361336                                                        output += "%s " % token
     
    13411341                                       
    13421342                                        if (not descriptor(token)):
    1343                                                 print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1343                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    13441344                                        else:
    13451345                                                output += "%s " % token
     
    13521352                                        if (FIN in context):
    13531353                                                if (token != ";"):
    1354                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1354                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    13551355                                                else:
    13561356                                                        output += "%s" % token
     
    13621362                                        if (VAR in context):
    13631363                                                if (not descriptor(token)):
    1364                                                         print "%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture)
     1364                                                        print("%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture))
    13651365                                                else:
    13661366                                                        if (not architecture in arch_properties):
     
    13811381                                        if (TO in context):
    13821382                                                if (token != "to"):
    1383                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1383                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    13841384                                                else:
    13851385                                                        output += "%s " % token
     
    13901390                                       
    13911391                                        if (not descriptor(token)):
    1392                                                 print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1392                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    13931393                                        else:
    13941394                                                output += "%s " % token
     
    14011401                                        if (FIN in context):
    14021402                                                if (token != ";"):
    1403                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1403                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    14041404                                                else:
    14051405                                                        output += "%s" % token
     
    14111411                                        if (VAR in context):
    14121412                                                if (not identifier(token)):
    1413                                                         print "%s: Expected instance name in architecture '%s'" % (inname, architecture)
     1413                                                        print("%s: Expected instance name in architecture '%s'" % (inname, architecture))
    14141414                                                else:
    14151415                                                        if (not architecture in arch_properties):
     
    14291429                                       
    14301430                                        if (not identifier(token)):
    1431                                                 print "%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture)
     1431                                                print("%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture))
    14321432                                        else:
    14331433                                                output += "%s " % token
     
    14391439                                if (token == "}"):
    14401440                                        if (indent != 1):
    1441                                                 print "%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture)
     1441                                                print("%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture))
    14421442                                        else:
    14431443                                                indent -= 1
     
    14681468                                        continue
    14691469                               
    1470                                 print "%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture)
     1470                                print("%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture))
    14711471                                continue
    14721472                       
     
    14871487                               
    14881488                                if (not word(token)):
    1489                                         print "%s: Expected word in architecture head '%s'" % (inname, architecture)
     1489                                        print("%s: Expected word in architecture head '%s'" % (inname, architecture))
    14901490                                else:
    14911491                                        output += "%s " % token
     
    14941494                       
    14951495                        if (not identifier(token)):
    1496                                 print "%s: Expected architecture name" % inname
     1496                                print("%s: Expected architecture name" % inname)
    14971497                        else:
    14981498                                architecture = token
     
    15141514                if (SYSTEM in context):
    15151515                        if (token != "architecture"):
    1516                                 print "%s: Expected 'architecture'" % inname
     1516                                print("%s: Expected 'architecture'" % inname)
    15171517                        else:
    15181518                                output += "%s " % token
     
    15411541                        continue
    15421542               
    1543                 print "%s: Unknown token '%s'" % (inname, token)
     1543                print("%s: Unknown token '%s'" % (inname, token))
    15441544       
    15451545        inf.close()
     
    15751575       
    15761576        if ((output != "") and (opt_adl)):
    1577                 outf = file(outname, "w")
     1577                outf = open(outname, "w")
    15781578                outf.write(output)
    15791579                outf.close()
     
    16331633                                        merge_dot_frame("%s_%s" % (prefix, inst['var']), inst['var'], subframe, outf, indent + 1)
    16341634                                else:
    1635                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     1635                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    16361636       
    16371637        if ('bind' in arch):
     
    17281728       
    17291729        if (arch is None):
    1730                 print "Unable to find system architecture"
     1730                print("Unable to find system architecture")
    17311731                return
    17321732       
    17331733        if (opt_dot):
    17341734                outname = os.path.join(outdir, "%s.dot" % arch['name'])
    1735                 outf = file(outname, "w")
     1735                outf = open(outname, "w")
    17361736               
    17371737                outf.write("digraph {\n")
     
    17521752                                                merge_dot_frame("%s" % inst['var'], inst['var'], subframe, outf, 1)
    17531753                                        else:
    1754                                                 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     1754                                                print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    17551755               
    17561756                if ('bind' in arch):
     
    17841784                if ('delegate' in arch):
    17851785                        for delegate in arch['delegate']:
    1786                                 print "Unable to delegate interface in system architecture"
     1786                                print("Unable to delegate interface in system architecture")
    17871787                                break
    17881788               
    17891789                if ('subsume' in arch):
    17901790                        for subsume in arch['subsume']:
    1791                                 print "Unable to subsume interface in system architecture"
     1791                                print("Unable to subsume interface in system architecture")
    17921792                                break
    17931793               
     
    18261826                        pass
    18271827                else:
    1828                         print "Error: Unknown command line option '%s'" % arg
     1828                        print("Error: Unknown command line option '%s'" % arg)
    18291829                        return
    18301830       
    18311831        if ((opt_bp) and (opt_ebp)):
    1832                 print "Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols"
     1832                print("Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols")
    18331833                return
    18341834       
    18351835        path = os.path.abspath(sys.argv[-1])
    18361836        if (not os.path.isdir(path)):
    1837                 print "Error: <OUTPUT> is not a directory"
     1837                print("Error: <OUTPUT> is not a directory")
    18381838                return
    18391839       
Note: See TracChangeset for help on using the changeset viewer.