Changeset ee5b35a in mainline


Ignore:
Timestamp:
2009-09-16T13:42:23Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fed03a3
Parents:
2a70672
Message:

complete ADL parsing with basic syntax checks
generating of interface and frame BPs
fix syntax in ADLs

Location:
contrib/arch
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • contrib/arch/hadlbppp.py

    r2a70672 ree5b35a  
    3535
    3636INC, POST_INC, BLOCK_COMMENT, LINE_COMMENT, SYSTEM, ARCH, HEAD, BODY, NULL, \
    37         INST, VAR, FIN, BIND, TO, SEEN_NL, IFACE, PROTOTYPE, PAR_LEFT, PAR_RIGHT, SIGNATURE, PROTOCOL = range(21)
    38 
    39 context = set()
    40 interface = None
    41 architecture = None
    42 protocol = None
     37        INST, VAR, FIN, BIND, TO, SUBSUME, DELEGATE, IFACE, PROTOTYPE, PAR_LEFT, \
     38        PAR_RIGHT, SIGNATURE, PROTOCOL, FRAME, PROVIDES, REQUIRES = range(25)
    4339
    4440def usage(prname):
    4541        "Print usage syntax"
    46         print prname + " <OUTPUT>"
     42       
     43        print "%s <OUTPUT>" % prname
    4744
    4845def tabs(cnt):
     
    9188        return tokens
    9289
    93 def preproc_bp(outname, tokens):
    94         "Preprocess tentative statements in Behavior Protocol"
    95        
    96         result = []
    97         i = 0
    98        
    99         while (i < len(tokens)):
    100                 if (tokens[i] == "tentative"):
    101                         if ((i + 1 < len(tokens)) and (tokens[i + 1] == "{")):
    102                                 i += 2
    103                                 start = i
    104                                 level = 1
    105                                
    106                                 while ((i < len(tokens)) and (level > 0)):
    107                                         if (tokens[i] == "{"):
    108                                                 level += 1
    109                                         elif (tokens[i] == "}"):
    110                                                 level -= 1
    111                                        
    112                                         i += 1
    113                                
    114                                 if (level == 0):
    115                                         result.append("(")
    116                                         result.extend(preproc_bp(outname, tokens[start:(i - 1)]))
    117                                         result.append(")")
    118                                         result.append("+")
    119                                         result.append("NULL")
    120                                 else:
    121                                         print "%s: Syntax error in tentative statement" % outname
    122                         else:
    123                                 print "%s: Unexpected tentative statement" % outname
    124                 else:
    125                         result.append(tokens[i])
    126                
    127                 i += 1
    128        
    129         return result
    130 
    131 def preproc_adl(raw, inarg):
    132         "Preprocess %% statements in ADL"
    133        
    134         return raw.replace("%%", inarg)
    135 
    13690def identifier(token):
    13791        "Check whether the token is an identifier"
     
    171125        return True
    172126
    173 def parse_bp(base, root, inname, nested, outname, indent):
     127def preproc_bp(name, tokens):
     128        "Preprocess tentative statements in Behavior Protocol"
     129       
     130        result = []
     131        i = 0
     132       
     133        while (i < len(tokens)):
     134                if (tokens[i] == "tentative"):
     135                        if ((i + 1 < len(tokens)) and (tokens[i + 1] == "{")):
     136                                i += 2
     137                                start = i
     138                                level = 1
     139                               
     140                                while ((i < len(tokens)) and (level > 0)):
     141                                        if (tokens[i] == "{"):
     142                                                level += 1
     143                                        elif (tokens[i] == "}"):
     144                                                level -= 1
     145                                       
     146                                        i += 1
     147                               
     148                                if (level == 0):
     149                                        result.append("(")
     150                                        result.extend(preproc_bp(name, tokens[start:(i - 1)]))
     151                                        result.append(")")
     152                                        result.append("+")
     153                                        result.append("NULL")
     154                                        if (i < len(tokens)):
     155                                                result.append(tokens[i])
     156                                else:
     157                                        print "%s: Syntax error in tentative statement" % name
     158                        else:
     159                                print "%s: Unexpected token in tentative statement" % name
     160                else:
     161                        result.append(tokens[i])
     162               
     163                i += 1
     164       
     165        return result
     166
     167def parse_bp(name, protocol, base_indent):
    174168        "Parse Behavior Protocol"
    175169       
    176         if (nested):
    177                 if (inname[0:1] == "/"):
    178                         path = os.path.join(base, ".%s" % inname)
    179                         nested_root = os.path.dirname(path)
    180                 else:
    181                         path = os.path.join(root, inname)
    182                         nested_root = root
    183                
    184                 if (not os.path.isfile(path)):
    185                         print "%s: Unable to include file %s" % (outname, path)
    186                         return ""
    187         else:
    188                 path = inname
    189                 nested_root = root
    190        
    191         inf = file(path, "r")
    192         tokens = preproc_bp(outname, split_tokens(inf.read(), ["\n", " ", "\t", "(", ")", "{", "}", "[", "]", "/*", "*/", "#", "*", ";", "+", "||", "|", "!", "?"], True, True))
    193        
     170        tokens = preproc_bp(name, split_tokens(protocol, ["\n", " ", "\t", "(", ")", "{", "}", "*", ";", "+", "||", "|", "!", "?"], True, True))
     171       
     172        indent = base_indent
    194173        output = ""
    195         inc = False
    196         comment = False
    197         lcomment = False
    198174       
    199175        for token in tokens:
    200                 if (comment):
    201                         if (token == "*/"):
    202                                 comment = False
    203                         continue
    204                
    205                 if ((not comment) and (token == "/*")):
    206                         comment = True
    207                         continue
    208                
    209                 if (lcomment):
    210                         if (token == "\n"):
    211                                 lcomment = False
    212                         continue
    213                
    214                 if ((not lcomment) and (token == "#")):
    215                         lcomment = True
    216                         continue
    217                
    218176                if (token == "\n"):
    219                         continue
    220                
    221                 if (inc):
    222                         output += "\n%s(" % tabs(indent)
    223                        
    224                         bp = parse_bp(base, nested_root, token, True, outname, indent + 1)
    225                         if (bp.strip() == ""):
    226                                 output += "\n%sNULL" % tabs(indent + 1)
    227                         else:
    228                                 output += bp
    229                        
    230                         output += "\n%s)" % tabs(indent)
    231                         inc = False
    232177                        continue
    233178               
    234179                if ((token == ";") or (token == "+") or (token == "||") or (token == "|")):
    235180                        output += " %s" % token
    236                 elif (token == "["):
    237                         inc = True
    238                 elif (token == "]"):
    239                         inc = False
    240181                elif (token == "("):
    241182                        output += "\n%s%s" % (tabs(indent), token)
    242183                        indent += 1
    243184                elif (token == ")"):
    244                         if (indent <= 0):
    245                                 print "%s: Wrong number of parentheses" % outname
     185                        if (indent < base_indent):
     186                                print "%s: Too many parentheses" % name
    246187                       
    247188                        indent -= 1
     
    251192                        indent += 1
    252193                elif (token == "}"):
    253                         if (indent <= 0):
    254                                 print "%s: Wrong number of parentheses" % outname
     194                        if (indent < base_indent):
     195                                print "%s: Too many parentheses" % name
    255196                       
    256197                        indent -= 1
     
    263204                        output += "%s" % token
    264205       
    265         inf.close()
     206        if (indent > base_indent):
     207                print "%s: Missing parentheses" % name
     208       
     209        output = output.strip()
     210        if (output == ""):
     211                return "NULL"
    266212       
    267213        return output
     214
     215def dump_iface_bp(interface, protocol, outdir):
     216        "Dump Behavior Protocol of a given interface"
     217       
     218        outname = os.path.join(outdir, "iface_%s.bp" % interface)
     219        if (os.path.isfile(outname)):
     220                print "%s: File already exists, overwriting" % outname
     221       
     222        outf = file(outname, "w")
     223        outf.write(parse_bp(outname, protocol, 0))
     224        outf.close()
     225
     226def dump_frame_bp(frame, protocol, outdir):
     227        "Dump Behavior Protocol of a given frame"
     228       
     229        outname = os.path.join(outdir, "frame_%s.bp" % frame)
     230        if (os.path.isfile(outname)):
     231                print "%s: File already exists, overwriting" % outname
     232       
     233        outf = file(outname, "w")
     234        outf.write(parse_bp(outname, protocol, 0))
     235        outf.close()
     236
     237def preproc_adl(raw, inarg):
     238        "Preprocess %% statements in ADL"
     239       
     240        return raw.replace("%%", inarg)
    268241
    269242def parse_adl(base, root, inname, nested, indent):
    270243        "Parse Architecture Description Language"
     244       
     245        global output
     246        global context
     247        global architecture
     248        global interface
     249        global frame
     250        global protocol
     251        global iface_protocols
     252        global frame_protocols
    271253       
    272254        if (nested):
     
    297279        raw = preproc_adl(inf.read(), inarg)
    298280        tokens = split_tokens(raw, ["\n", " ", "\t", "(", ")", "{", "}", "[", "]", "/*", "*/", "#", ";"], True, True)
    299         output = ""
    300281       
    301282        for token in tokens:
     
    305286                if (INC in context):
    306287                        context.remove(INC)
    307                        
    308                         if (PROTOCOL in context):
    309                                 protocol += parse_bp(base, nested_root, token, True, "xxx", indent).strip()
    310                         else:
    311                                 output += "\n%s" % tabs(indent)
    312                                 output += parse_adl(base, nested_root, token, True, indent).strip()
    313                        
     288                        parse_adl(base, nested_root, token, True, indent)
    314289                        context.add(POST_INC)
    315290                        continue
     
    319294                                print "%s: Expected ]" % inname
    320295                       
    321                         context.add(SEEN_NL)
    322296                        context.remove(POST_INC)
    323297                        continue
     
    351325                        continue
    352326               
    353                 # Seen newline
    354                
    355                 if (SEEN_NL in context):
    356                         context.remove(SEEN_NL)
    357                         if (token == "\n"):
    358                                 output += "\n%s" % tabs(indent)
    359                                 continue
    360                 else:
    361                         if (token == "\n"):
    362                                 continue
    363                
    364                 # "interface"
    365                
    366                 if (IFACE in context):
     327                if (token == "\n"):
     328                        continue
     329               
     330                # "frame"
     331               
     332                if (FRAME in context):
    367333                        if (NULL in context):
    368334                                if (token != ";"):
    369                                         print "%s: Expected ;" % inname
     335                                        print "%s: Expected ';' in frame '%s'" % (inname, frame)
    370336                                else:
    371337                                        output += "%s\n" % token
    372338                               
    373339                                context.remove(NULL)
    374                                 context.remove(IFACE)
    375                                 interface = None
     340                                context.remove(FRAME)
     341                                frame = None
    376342                                continue
    377343                       
     
    383349                                                indent -= 1
    384350                                       
    385                                         if (indent == 1):
    386                                                 output += protocol.strip()
     351                                        if (indent == -1):
     352                                                if (frame in frame_protocols):
     353                                                        print "%s: Protocol for frame '%s' already defined" % (inname, frame)
     354                                                else:
     355                                                        frame_protocols[frame] = protocol
     356                                                output += "\n%s" % tabs(2)
     357                                                output += parse_bp(inname, protocol, 2)
    387358                                                protocol = None
    388359                                               
    389360                                                output += "\n%s" % token
     361                                                indent = 0
    390362                                               
    391363                                                context.remove(PROTOCOL)
     
    397369                                        continue
    398370                               
    399                                 if (PROTOTYPE in context):
     371                                if (REQUIRES in context):
    400372                                        if (FIN in context):
    401373                                                if (token != ";"):
    402                                                         print "%s: Expected ;" % inname
     374                                                        print "%s: Expected ';' in frame '%s'" % (inname, frame)
    403375                                                else:
    404376                                                        output += "%s" % token
    405377                                               
    406378                                                context.remove(FIN)
    407                                                 context.remove(PROTOTYPE)
    408                                                 continue
    409                                        
    410                                         if (PAR_RIGHT in context):
    411                                                 if (token == ")"):
    412                                                         output += "%s" % token
    413                                                         context.remove(PAR_RIGHT)
    414                                                         context.add(FIN)
    415                                                 else:
    416                                                         output += " %s" % token
    417                                                
    418                                                 continue
    419                                        
    420                                         if (SIGNATURE in context):
    421                                                 output += "%s" % token
    422                                                 if (token == ")"):
    423                                                         context.remove(SIGNATURE)
    424                                                         context.add(FIN)
    425                                                
    426                                                 context.remove(SIGNATURE)
    427                                                 context.add(PAR_RIGHT)
    428                                                 continue
    429                                        
    430                                         if (PAR_LEFT in context):
    431                                                 if (token != "("):
    432                                                         print "%s: Expected (" % inname
    433                                                 else:
    434                                                         output += "%s" % token
    435                                                
    436                                                 context.remove(PAR_LEFT)
    437                                                 context.add(SIGNATURE)
    438                                                 continue
    439                                        
    440                                         if (not identifier(token)):
    441                                                 print "%s: Method identifier expected" % inname
    442                                         else:
    443                                                 output += "%s" % token
    444                                        
    445                                         context.add(PAR_LEFT)
    446                                         continue
     379                                                continue
     380                                       
     381                                        if (VAR in context):
     382                                                if (not identifier(token)):
     383                                                        print "%s: Instance name expected in frame '%s'" % (inname, frame)
     384                                                else:
     385                                                        output += "%s" % token
     386                                               
     387                                                context.remove(VAR)
     388                                                context.add(FIN)
     389                                                continue
     390                                       
     391                                        if ((token == "}") or (token[-1] == ":")):
     392                                                context.remove(REQUIRES)
     393                                        else:
     394                                                if (not identifier(token)):
     395                                                        print "%s: Interface name expected in frame '%s'" % (inname, frame)
     396                                                else:
     397                                                        output += "\n%s%s " % (tabs(indent), token)
     398                                               
     399                                                context.add(VAR)
     400                                                continue
     401                               
     402                                if (PROVIDES in context):
     403                                        if (FIN in context):
     404                                                if (token != ";"):
     405                                                        print "%s: Expected ';' in frame '%s'" % (inname, frame)
     406                                                else:
     407                                                        output += "%s" % token
     408                                               
     409                                                context.remove(FIN)
     410                                                continue
     411                                       
     412                                        if (VAR in context):
     413                                                if (not identifier(token)):
     414                                                        print "%s: Instance name expected in frame '%s'" % (inname, frame)
     415                                                else:
     416                                                        output += "%s" % token
     417                                               
     418                                                context.remove(VAR)
     419                                                context.add(FIN)
     420                                                continue
     421                                       
     422                                        if ((token == "}") or (token[-1] == ":")):
     423                                                context.remove(PROVIDES)
     424                                        else:
     425                                                if (not identifier(token)):
     426                                                        print "%s: Interface name expected in frame '%s'" % (inname, frame)
     427                                                else:
     428                                                        output += "\n%s%s " % (tabs(indent), token)
     429                                               
     430                                                context.add(VAR)
     431                                                continue
    447432                               
    448433                                if (token == "}"):
    449                                         if (indent != 1):
    450                                                 print "%s: Wrong number of parentheses" % inname
     434                                        if (indent != 2):
     435                                                print "%s: Wrong number of parentheses in frame '%s'" % (inname, frame)
    451436                                        else:
    452437                                                indent = 0
     
    457442                                        continue
    458443                               
    459                                 if (token == "ipcarg_t"):
    460                                         output += "\n%s%s " % (tabs(indent), token)
    461                                         context.add(PROTOTYPE)
     444                                if (token == "provides:"):
     445                                        output += "\n%s%s" % (tabs(indent - 1), token)
     446                                        context.add(PROVIDES)
     447                                        protocol = ""
     448                                        continue
     449                               
     450                                if (token == "requires:"):
     451                                        output += "\n%s%s" % (tabs(indent - 1), token)
     452                                        context.add(REQUIRES)
     453                                        protocol = ""
    462454                                        continue
    463455                               
    464456                                if (token == "protocol:"):
    465457                                        output += "\n%s%s" % (tabs(indent - 1), token)
     458                                        indent = 0
    466459                                        context.add(PROTOCOL)
    467460                                        protocol = ""
    468461                                        continue
    469462                               
    470                                 print "%s: Unknown token %s in interface" % (inname, token)
     463                                print "%s: Unknown token '%s' in frame '%s'" % (inname, token, frame)
    471464                                continue
    472465                       
     
    482475                                        output += "%s\n" % token
    483476                                        context.remove(HEAD)
     477                                        context.remove(FRAME)
     478                                        continue
     479                               
     480                                print "%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame)
     481                               
     482                                continue
     483                       
     484                        if (not identifier(token)):
     485                                print "%s: Expected frame name" % inname
     486                        else:
     487                                frame = token
     488                                output += "%s " % token
     489                       
     490                        context.add(HEAD)
     491                        continue
     492               
     493                # "interface"
     494               
     495                if (IFACE in context):
     496                        if (NULL in context):
     497                                if (token != ";"):
     498                                        print "%s: Expected ';' in interface '%s'" % (inname, interface)
     499                                else:
     500                                        output += "%s\n" % token
     501                               
     502                                context.remove(NULL)
     503                                context.remove(IFACE)
     504                                interface = None
     505                                continue
     506                       
     507                        if (BODY in context):
     508                                if (PROTOCOL in context):
     509                                        if (token == "{"):
     510                                                indent += 1
     511                                        elif (token == "}"):
     512                                                indent -= 1
     513                                       
     514                                        if (indent == -1):
     515                                                if (interface in iface_protocols):
     516                                                        print "%s: Protocol for interface '%s' already defined" % (inname, interface)
     517                                                else:
     518                                                        iface_protocols[interface] = protocol
     519                                               
     520                                                output += "\n%s" % tabs(2)
     521                                                output += parse_bp(inname, protocol, 2)
     522                                                protocol = None
     523                                               
     524                                                output += "\n%s" % token
     525                                                indent = 0
     526                                               
     527                                                context.remove(PROTOCOL)
     528                                                context.remove(BODY)
     529                                                context.add(NULL)
     530                                        else:
     531                                                protocol += token
     532                                       
     533                                        continue
     534                               
     535                                if (PROTOTYPE in context):
     536                                        if (FIN in context):
     537                                                if (token != ";"):
     538                                                        print "%s: Expected ';' in interface '%s'" % (inname, interface)
     539                                                else:
     540                                                        output += "%s" % token
     541                                               
     542                                                context.remove(FIN)
     543                                                context.remove(PROTOTYPE)
     544                                                continue
     545                                       
     546                                        if (PAR_RIGHT in context):
     547                                                if (token == ")"):
     548                                                        output += "%s" % token
     549                                                        context.remove(PAR_RIGHT)
     550                                                        context.add(FIN)
     551                                                else:
     552                                                        output += " %s" % token
     553                                               
     554                                                continue
     555                                       
     556                                        if (SIGNATURE in context):
     557                                                output += "%s" % token
     558                                                if (token == ")"):
     559                                                        context.remove(SIGNATURE)
     560                                                        context.add(FIN)
     561                                               
     562                                                context.remove(SIGNATURE)
     563                                                context.add(PAR_RIGHT)
     564                                                continue
     565                                       
     566                                        if (PAR_LEFT in context):
     567                                                if (token != "("):
     568                                                        print "%s: Expected '(' in interface '%s'" % (inname, interface)
     569                                                else:
     570                                                        output += "%s" % token
     571                                               
     572                                                context.remove(PAR_LEFT)
     573                                                context.add(SIGNATURE)
     574                                                continue
     575                                       
     576                                        if (not identifier(token)):
     577                                                print "%s: Method identifier expected in interface '%s'" % (inname, interface)
     578                                        else:
     579                                                output += "%s" % token
     580                                       
     581                                        context.add(PAR_LEFT)
     582                                        continue
     583                               
     584                                if (token == "}"):
     585                                        if (indent != 2):
     586                                                print "%s: Wrong number of parentheses in interface '%s'" % (inname, interface)
     587                                        else:
     588                                                indent = 0
     589                                                output += "\n%s" % token
     590                                       
     591                                        context.remove(BODY)
     592                                        context.add(NULL)
     593                                        continue
     594                               
     595                                if ((token == "ipcarg_t") or (token == "unative_t")):
     596                                        output += "\n%s%s " % (tabs(indent), token)
     597                                        context.add(PROTOTYPE)
     598                                        continue
     599                               
     600                                if (token == "protocol:"):
     601                                        output += "\n%s%s" % (tabs(indent - 1), token)
     602                                        indent = 0
     603                                        context.add(PROTOCOL)
     604                                        protocol = ""
     605                                        continue
     606                               
     607                                print "%s: Unknown token '%s' in interface '%s'" % (inname, token, interface)
     608                                continue
     609                       
     610                        if (HEAD in context):
     611                                if (token == "{"):
     612                                        output += "%s" % token
     613                                        indent += 2
     614                                        context.remove(HEAD)
     615                                        context.add(BODY)
     616                                        continue
     617                               
     618                                if (token == ";"):
     619                                        output += "%s\n" % token
     620                                        context.remove(HEAD)
    484621                                        context.remove(ARCH)
    485                                         context.discard(SYSTEM)
    486622                                        continue
    487623                               
    488624                                if (not word(token)):
    489                                         print "%s: Expected word" % inname
     625                                        print "%s: Expected word in interface head '%s'" % (inname, interface)
    490626                                else:
    491627                                        output += "%s " % token
     
    507643                        if (NULL in context):
    508644                                if (token != ";"):
    509                                         print "%s: Expected ;" % inname
     645                                        print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
    510646                                else:
    511647                                        output += "%s\n" % token
     
    518654                       
    519655                        if (BODY in context):
     656                                if (DELEGATE in context):
     657                                        if (FIN in context):
     658                                                if (token != ";"):
     659                                                        print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     660                                                else:
     661                                                        output += "%s" % token
     662                                               
     663                                                context.remove(FIN)
     664                                                context.remove(DELEGATE)
     665                                                continue
     666                                       
     667                                        if (VAR in context):
     668                                                if (not descriptor(token)):
     669                                                        print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     670                                                else:
     671                                                        output += "%s" % token
     672                                               
     673                                                context.add(FIN)
     674                                                context.remove(VAR)
     675                                                continue
     676                                       
     677                                        if (TO in context):
     678                                                if (token != "to"):
     679                                                        print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     680                                                else:
     681                                                        output += "%s " % token
     682                                               
     683                                                context.add(VAR)
     684                                                context.remove(TO)
     685                                                continue
     686                                       
     687                                        if (not identifier(token)):
     688                                                print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     689                                        else:
     690                                                output += "%s " % token
     691                                       
     692                                        context.add(TO)
     693                                        continue
     694                               
     695                                if (SUBSUME in context):
     696                                        if (FIN in context):
     697                                                if (token != ";"):
     698                                                        print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     699                                                else:
     700                                                        output += "%s" % token
     701                                               
     702                                                context.remove(FIN)
     703                                                context.remove(SUBSUME)
     704                                                continue
     705                                       
     706                                        if (VAR in context):
     707                                                if (not identifier(token)):
     708                                                        print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     709                                                else:
     710                                                        output += "%s" % token
     711                                               
     712                                                context.add(FIN)
     713                                                context.remove(VAR)
     714                                                continue
     715                                       
     716                                        if (TO in context):
     717                                                if (token != "to"):
     718                                                        print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     719                                                else:
     720                                                        output += "%s " % token
     721                                               
     722                                                context.add(VAR)
     723                                                context.remove(TO)
     724                                                continue
     725                                       
     726                                        if (not descriptor(token)):
     727                                                print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     728                                        else:
     729                                                output += "%s " % token
     730                                       
     731                                        context.add(TO)
     732                                        continue
     733                               
    520734                                if (BIND in context):
    521735                                        if (FIN in context):
    522736                                                if (token != ";"):
    523                                                         print "%s: Expected ;" % inname
     737                                                        print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
    524738                                                else:
    525739                                                        output += "%s" % token
     
    531745                                        if (VAR in context):
    532746                                                if (not descriptor(token)):
    533                                                         print "%s: Expected second interface descriptor" % inname
     747                                                        print "%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture)
    534748                                                else:
    535749                                                        output += "%s" % token
     
    541755                                        if (TO in context):
    542756                                                if (token != "to"):
    543                                                         print "%s: Expected to" % inname
     757                                                        print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
    544758                                                else:
    545759                                                        output += "%s " % token
     
    550764                                       
    551765                                        if (not descriptor(token)):
    552                                                 print "%s: Expected interface descriptor" % inname
     766                                                print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
    553767                                        else:
    554768                                                output += "%s " % token
     
    560774                                        if (FIN in context):
    561775                                                if (token != ";"):
    562                                                         print "%s: Expected ;" % inname
     776                                                        print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
    563777                                                else:
    564778                                                        output += "%s" % token
     
    570784                                        if (VAR in context):
    571785                                                if (not identifier(token)):
    572                                                         print "%s: Expected instance name" % inname
     786                                                        print "%s: Expected instance name in architecture '%s'" % (inname, architecture)
    573787                                                else:
    574788                                                        output += "%s" % token
     
    579793                                       
    580794                                        if (not identifier(token)):
    581                                                 print "%s: Expected frame/architecture type" % inname
     795                                                print "%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture)
    582796                                        else:
    583797                                                output += "%s " % token
     
    588802                                if (token == "}"):
    589803                                        if (indent != 1):
    590                                                 print "%s: Wrong number of parentheses" % inname
     804                                                print "%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture)
    591805                                        else:
    592806                                                indent -= 1
     
    607821                                        continue
    608822                               
    609                                 print "%s: Unknown token %s in architecture" % (inname, token)
     823                                if (token == "subsume"):
     824                                        output += "\n%s%s " % (tabs(indent), token)
     825                                        context.add(SUBSUME)
     826                                        continue
     827                               
     828                                if (token == "delegate"):
     829                                        output += "\n%s%s " % (tabs(indent), token)
     830                                        context.add(DELEGATE)
     831                                        continue
     832                               
     833                                print "%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture)
    610834                                continue
    611835                       
     
    626850                               
    627851                                if (not word(token)):
    628                                         print "%s: Expected word" % inname
     852                                        print "%s: Expected word in architecture head '%s'" % (inname, architecture)
    629853                                else:
    630854                                        output += "%s " % token
     
    645869                if (SYSTEM in context):
    646870                        if (token != "architecture"):
    647                                 print "%s: Expected architecture" % inname
     871                                print "%s: Expected 'architecture'" % inname
    648872                        else:
    649873                                output += "%s " % token
    650874                       
    651875                        context.add(ARCH)
     876                        continue
     877               
     878                if (token == "frame"):
     879                        output += "\n%s " % token
     880                        context.add(FRAME)
    652881                        continue
    653882               
     
    667896                        continue
    668897               
    669                 print "%s: Unknown token %s" % (inname, token)
     898                print "%s: Unknown token '%s'" % (inname, token)
    670899       
    671900        inf.close()
    672        
    673         return output
    674 
    675 def open_adl(base, root, inname, outname):
     901
     902def open_adl(base, root, inname, outdir, outname):
    676903        "Open Architecture Description file"
    677904       
    678         context.clear()
     905        global output
     906        global context
     907        global architecture
     908        global interface
     909        global frame
     910        global protocol
     911       
     912        output = ""
     913        context = set()
     914        architecture = None
    679915        interface = None
    680         architecture = None
     916        frame = None
    681917        protocol = None
    682918       
    683         adl = parse_adl(base, root, inname, False, 0)
    684         if (adl.strip() == ""):
    685                 adl = "/* Empty */\n"
    686        
    687         if (os.path.isfile(outname)):
    688                 print "%s: File already exists, overwriting" % outname
    689        
    690         outf = file(outname, "w")
    691         outf.write(adl.strip())
    692         outf.close()
     919        parse_adl(base, root, inname, False, 0)
     920        output = output.strip()
     921       
     922        if (output != ""):
     923                if (os.path.isfile(outname)):
     924                        print "%s: File already exists, overwriting" % outname
     925               
     926                outf = file(outname, "w")
     927                outf.write(output)
     928                outf.close()
     929        else:
     930                if (os.path.isfile(outname)):
     931                        print "%s: File already exists, but should be empty" % outname
    693932
    694933def recursion(base, root, output, level):
     
    704943                        if (fcomp[-1] == ".adl"):
    705944                                output_path = os.path.join(output, cname[-1])
    706                                 open_adl(base, root, canon, output_path)
     945                                open_adl(base, root, canon, output, output_path)
    707946               
    708947                if (os.path.isdir(canon)):
     
    710949
    711950def main():
     951        global iface_protocols
     952        global frame_protocols
     953       
    712954        if (len(sys.argv) < 2):
    713955                usage(sys.argv[0])
     
    719961                return
    720962       
     963        iface_protocols = {}
     964        frame_protocols = {}
     965       
    721966        recursion(".", ".", path, 0)
     967       
     968        for key, value in iface_protocols.items():
     969                dump_iface_bp(key, value, path)
     970       
     971        for key, value in frame_protocols.items():
     972                dump_frame_bp(key, value, path)
    722973
    723974if __name__ == '__main__':
  • contrib/arch/kernel/kernel.adl

    r2a70672 ree5b35a  
    1212interface kernel_console {
    1313                /* Enable kernel console */
    14                 uintptr_t sys_debug_enable_console(void);
     14                unative_t sys_debug_enable_console(void);
    1515               
    1616                /* Disable kernel console */
    17                 uintptr_t sys_debug_disable_console(void);
     17                unative_t sys_debug_disable_console(void);
    1818        protocol:
    1919                ?sys_debug_enable_console +
  • contrib/arch/uspace/srv/devmap/devmap.adl

    r2a70672 ree5b35a  
    4747               
    4848                /* Get an array of (device_name, handle) pairs */
    49                 ipcarg_t device_get_devices(out_copy stream data)
     49                ipcarg_t device_get_devices(out_copy stream data);
    5050               
    5151                /* Close connection */
  • contrib/arch/uspace/srv/fs/devfs/devfs.adl

    r2a70672 ree5b35a  
    11frame devfs {
    22        provides:
    3                 fs fs
     3                fs fs;
    44        requires:
    55                [/uspace/lib/libc/requires]
  • contrib/arch/uspace/srv/fs/fat/fat.adl

    r2a70672 ree5b35a  
    11frame fat {
    22        provides:
    3                 fs fs
     3                fs fs;
    44        requires:
    55                [/uspace/lib/libc/requires]
  • contrib/arch/uspace/srv/fs/tmpfs/tmpfs.adl

    r2a70672 ree5b35a  
    11frame tmpfs {
    22        provides:
    3                 fs fs
     3                fs fs;
    44        requires:
    55                [/uspace/lib/libc/requires]
Note: See TracChangeset for help on using the changeset viewer.