/ parsevect
parsevect
 1  #!/usr/bin/python2
 2  print "" # python2.7 is required to run parsevect instead of python3
 3  """
 4  This software is part of libcsdr, a set of simple DSP routines for 
 5  Software Defined Radio.
 6  
 7  Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
 8  All rights reserved.
 9  
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions are met:
12      * Redistributions of source code must retain the above copyright
13        notice, this list of conditions and the following disclaimer.
14      * Redistributions in binary form must reproduce the above copyright
15        notice, this list of conditions and the following disclaimer in the
16        documentation and/or other materials provided with the distribution.
17      * Neither the name of the copyright holder nor the
18        names of its contributors may be used to endorse or promote products
19        derived from this software without specific prior written permission.
20  
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
25  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  """
32  
33  import sys
34  import os
35  
36  try:
37  	vectfile=open(sys.argv[1],"r").readlines()
38  except:
39  	print "parsevect: can't open input file"
40  	quit()
41  
42  lastcfile=""
43  cfile=[]
44  def loadcfile(what):
45  	global lastcfile, cfile
46  	if lastcfile!=what:
47  		cfile=open(what,"r").readlines()
48  		lastcfile=what
49  
50  print """
51  Auto-vectorization built into gcc can increase the execution speed of algorithms with automatic 
52  generation of SIMD instructions if the CPU is capable.
53  We parse the output of the vectorizer to analyze which loops could be optimized (thus speeded up) this way. 
54  Warning! The result may be different on different CPU architectures...
55  
56  Colors: 
57  \033[1;31m  - can't be vectorized
58  \033[1;32m  - successfully vectorized
59  \033[1;33m  - not intended to be vectorized (not important)
60  \033[1;0m"""
61  
62  checkline = lambda k: cfile[linenum-k] if "//@" in cfile[linenum-k] else corresponds
63  fallback=False
64  
65  for row in vectfile:
66  	if "LOOP VECTORIZED" in row or "not vectorized" in row: 
67  		filename=row.split(":")[0]
68  		if not fallback and not os.path.isfile(filename):
69  			print "parsevect: Log format mismatch (perhaps gcc version is older than 4.8.2). Comments and colors will not be matched to rows."
70  			fallback = True
71  		if fallback:
72  			print row[:-1]
73  		else:
74  			loadcfile(filename)
75  			linenum=int(row.split(":")[1])
76  			corresponds="//@"		
77  			corresponds=checkline(1)
78  			corresponds=checkline(2)
79  			corresponds=corresponds.split("//@")[1][:-1]
80  			yellow=corresponds.startswith("@")
81  			if yellow: corresponds=corresponds[1:]
82  			print row[:-1], "\033[1;33m" if yellow else "\033[1;31m" if "not " in row else "\033[1;32m", corresponds, "\033[1;0m"
83