Changeset 57688fe2 in mainline for contrib/arch/hadlbppp.py
- Timestamp:
- 2009-09-16T22:45:48Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cf7b3e0
- Parents:
- e5d4294
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/arch/hadlbppp.py
re5d4294 r57688fe2 34 34 import os 35 35 36 # TODO: 37 # - alternative token 38 # - iface protocol repetition 39 # - interface inheritance 40 36 41 INC, POST_INC, BLOCK_COMMENT, LINE_COMMENT, SYSTEM, ARCH, HEAD, BODY, NULL, \ 37 42 INST, VAR, FIN, BIND, TO, SUBSUME, DELEGATE, IFACE, PROTOTYPE, PAR_LEFT, \ … … 277 282 return None 278 283 279 def dump_frame(frame, outdir ):284 def dump_frame(frame, outdir, var, archf): 280 285 "Dump Behavior Protocol of a given frame" 281 286 282 outname = os.path.join(outdir, "%s.bp" % frame['name']) 283 if (os.path.isfile(outname)): 284 print "%s: File already exists, overwriting" % outname 287 fname = "%s.bp" % frame['name'] 288 289 archf.write("instantiate %s from \"%s\"\n" % (var, fname)) 290 outname = os.path.join(outdir, fname) 285 291 286 292 protocols = [] … … 332 338 return None 333 339 334 def create_null_bp( name, outdir):340 def create_null_bp(fname, outdir, archf): 335 341 "Create null frame protocol" 336 342 337 outname = os.path.join(outdir, name) 338 if (not os.path.isfile(outname)): 339 outf = file(outname, "w") 340 outf.write("NULL") 341 outf.close() 342 343 def dump_arch(arch, outdir): 344 "Dump architecture Behavior Protocol" 345 346 outname = os.path.join(outdir, "%s.archbp" % arch['name']) 347 if (os.path.isfile(outname)): 348 print "%s: File already exists, overwriting" % outname 343 archf.write("frame \"%s\"\n" % fname) 344 outname = os.path.join(outdir, fname) 349 345 350 346 outf = file(outname, "w") 351 352 create_null_bp("null.bp", outdir) 353 outf.write("frame \"null.bp\"\n\n") 347 outf.write("NULL") 348 outf.close() 349 350 def merge_subarch(prefix, arch, outdir): 351 "Merge subarchitecture into architexture" 352 353 insts = [] 354 binds = [] 355 delegates = [] 356 subsumes = [] 354 357 355 358 if ('inst' in arch): … … 357 360 subarch = get_arch(inst['type']) 358 361 if (not subarch is None): 359 outf.write("instantiate %s from \"%s.archbp\"\n" % (inst['var'], inst['type'])) 360 dump_arch(subarch, outdir) 362 (subinsts, subbinds, subdelegates, subsubsumes) = merge_subarch("%s_%s" % (prefix, subarch['name']), subarch, outdir) 363 insts.extend(subinsts) 364 binds.extend(subbinds) 365 delegates.extend(subdelegates) 366 subsumes.extend(subsubsumes) 361 367 else: 362 368 subframe = get_frame(inst['type']) 363 369 if (not subframe is None): 364 outf.write("instantiate %s from \"%s.bp\"\n" % (inst['var'], inst['type'])) 365 dump_frame(subframe, outdir) 370 insts.append({'var': "%s_%s" % (prefix, inst['var']), 'frame': subframe}) 366 371 else: 367 print "%s: '%s' is neither architecture nor frame" % (arch['name'], inst['type']) 368 369 outf.write("\n") 372 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']) 370 373 371 374 if ('bind' in arch): 372 375 for bind in arch['bind']: 373 outf.write("bind %s.%s to %s.%s\n" % (bind['from'][0], bind['from'][1], bind['to'][0], bind['to'][1])) 376 binds.append({'from': "%s_%s.%s" % (prefix, bind['from'][0], bind['from'][1]), 'to': "%s_%s.%s" % (prefix, bind['to'][0], bind['to'][1])}) 377 378 if ('delegate' in arch): 379 for delegate in arch['delegate']: 380 delegates.append({'to': "%s.%s" % (prefix, delegate['from']), 'rep': "%s_%s.%s" % (prefix, delegate['to'][0], delegate['to'][1])}) 381 382 if ('subsume' in arch): 383 for subsume in arch['subsume']: 384 subsumes.append({'from': "%s.%s" % (prefix, subsume['to']), 'rep': "%s_%s.%s" % (prefix, subsume['from'][0], subsume['from'][1])}) 385 386 return (insts, binds, delegates, subsumes) 387 388 def dump_archbp(outdir): 389 "Dump system architecture Behavior Protocol" 390 391 arch = get_system_arch() 392 393 if (arch is None): 394 print "Unable to find system architecture" 395 return 396 397 insts = [] 398 binds = [] 399 delegates = [] 400 subsumes = [] 401 402 if ('inst' in arch): 403 for inst in arch['inst']: 404 subarch = get_arch(inst['type']) 405 if (not subarch is None): 406 (subinsts, subbinds, subdelegates, subsubsumes) = merge_subarch(subarch['name'], subarch, outdir) 407 insts.extend(subinsts) 408 binds.extend(subbinds) 409 delegates.extend(subdelegates) 410 subsumes.extend(subsubsumes) 411 else: 412 subframe = get_frame(inst['type']) 413 if (not subframe is None): 414 insts.append({'var': inst['var'], 'frame': subframe}) 415 else: 416 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']) 417 418 if ('bind' in arch): 419 for bind in arch['bind']: 420 binds.append({'from': "%s.%s" % (bind['from'][0], bind['from'][1]), 'to': "%s.%s" % (bind['to'][0], bind['to'][1])}) 421 422 if ('delegate' in arch): 423 for delegate in arch['delegate']: 424 print "Unable to delegate interface in system architecture" 425 break 426 427 if ('subsume' in arch): 428 for subsume in arch['subsume']: 429 print "Unable to subsume interface in system architecture" 430 break 431 432 outname = os.path.join(outdir, "%s.archbp" % arch['name']) 433 outf = file(outname, "w") 434 435 create_null_bp("null.bp", outdir, outf) 436 437 for inst in insts: 438 dump_frame(inst['frame'], outdir, inst['var'], outf) 439 440 for bind in binds: 441 for delegate in delegates: 442 if (bind['to'] == delegate['to']): 443 bind['to'] = delegate['rep'] 444 break 445 446 for subsume in subsumes: 447 if (bind['from'] == subsume['from']): 448 bind['from'] = subsume['rep'] 449 break 450 451 outf.write("bind %s to %s\n" % (bind['from'], bind['to'])) 374 452 375 453 outf.close() … … 797 875 output += "%s\n" % token 798 876 context.remove(HEAD) 799 context.remove( ARCH)877 context.remove(IFACE) 800 878 continue 801 879 … … 1155 1233 1156 1234 if (output != ""): 1157 if (os.path.isfile(outname)):1158 print "%s: File already exists, overwriting" % outname1159 1160 1235 outf = file(outname, "w") 1161 1236 outf.write(output) 1162 1237 outf.close() 1163 else:1164 if (os.path.isfile(outname)):1165 print "%s: File already exists, but should be empty" % outname1166 1238 1167 1239 def recursion(base, root, output, level): … … 1201 1273 1202 1274 recursion(".", ".", path, 0) 1203 1204 system_arch = get_system_arch() 1205 1206 if (not system_arch is None): 1207 dump_arch(system_arch, path) 1275 dump_archbp(path) 1208 1276 1209 1277 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.