ubiviz 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. #
  3. # The LLVM Compiler Infrastructure
  4. #
  5. # This file is distributed under the University of Illinois Open Source
  6. # License. See LICENSE.TXT for details.
  7. #
  8. ##===----------------------------------------------------------------------===##
  9. #
  10. # This script reads visualization data emitted by the static analyzer for
  11. # display in Ubigraph.
  12. #
  13. ##===----------------------------------------------------------------------===##
  14. import xmlrpclib
  15. import sys
  16. def Error(message):
  17. print >> sys.stderr, 'ubiviz: ' + message
  18. sys.exit(1)
  19. def StreamData(filename):
  20. file = open(filename)
  21. for ln in file:
  22. yield eval(ln)
  23. file.close()
  24. def Display(G, data):
  25. action = data[0]
  26. if action == 'vertex':
  27. vertex = data[1]
  28. G.new_vertex_w_id(vertex)
  29. for attribute in data[2:]:
  30. G.set_vertex_attribute(vertex, attribute[0], attribute[1])
  31. elif action == 'edge':
  32. src = data[1]
  33. dst = data[2]
  34. edge = G.new_edge(src,dst)
  35. for attribute in data[3:]:
  36. G.set_edge_attribute(edge, attribute[0], attribute[1])
  37. elif action == "vertex_style":
  38. style_id = data[1]
  39. parent_id = data[2]
  40. G.new_vertex_style_w_id(style_id, parent_id)
  41. for attribute in data[3:]:
  42. G.set_vertex_style_attribute(style_id, attribute[0], attribute[1])
  43. elif action == "vertex_style_attribute":
  44. style_id = data[1]
  45. for attribute in data[2:]:
  46. G.set_vertex_style_attribute(style_id, attribute[0], attribute[1])
  47. elif action == "change_vertex_style":
  48. vertex_id = data[1]
  49. style_id = data[2]
  50. G.change_vertex_style(vertex_id,style_id)
  51. def main(args):
  52. if len(args) == 0:
  53. Error('no input files')
  54. server = xmlrpclib.Server('http://127.0.0.1:20738/RPC2')
  55. G = server.ubigraph
  56. for arg in args:
  57. G.clear()
  58. for x in StreamData(arg):
  59. Display(G,x)
  60. sys.exit(0)
  61. if __name__ == '__main__':
  62. main(sys.argv[1:])