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