CGRA-ME
LoopParser.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 '''
4 /*******************************************************************************
5  * The software programs comprising "CGRA-ME" and the documentation provided
6  * with them are copyright by its authors and the University of Toronto. Only
7  * non-commercial, not-for-profit use of this software is permitted without ex-
8  * plicit permission. This software is provided "as is" with no warranties or
9  * guarantees of support. See the LICENCE for more details. You should have re-
10  * ceived a copy of the full licence along with this software. If not, see
11  * <http://cgra-me.ece.utoronto.ca/license/>.
12  ******************************************************************************/
13 '''
14 
15 import sys
16 import os
17 import string
18 
19 def loop_parser(input_source, output_source, output_tag):
20 
21  #Generate absolute path from reletive path
22  dir = os.path.dirname(os.path.realpath("__file__"))
23  input_src_path = os.path.join(dir, input_source)
24  output_src_path = os.path.join(dir, output_source)
25  output_tag_path = os.path.join(dir, output_tag)
26 
27  input_src_f = open(input_src_path, 'r')
28  output_src_f = open(output_src_path, 'w')
29  output_tag_f = open(output_tag_path, 'w')
30 
31  tag_string = "//DFGLoop:"
32  tag_count = 1
33 
34  output_src_f.write("__attribute__((noinline)) void DFGLOOP_TAG(int index);\n")
35 
36  for line in input_src_f:
37  tag_loc = line.find(tag_string)
38  if tag_loc != -1: #Found a tag
39  tag_name = line[tag_loc + len(tag_string) : -1].strip()
40  output_tag_f.write(str(tag_count) + ' ' + tag_name + '\n')
41  output_src_f.write("DFGLOOP_TAG(" + str(tag_count) + ");\n")
42  tag_count+=1
43  else:
44  output_src_f.write(line)
45 
46  input_src_f.close()
47  output_src_f.close()
48  output_tag_f.close()
49  return
50 
51 if __name__ == "__main__":
52  loop_parser(sys.argv[1], sys.argv[2], sys.argv[3])
LoopParser.loop_parser
def loop_parser(input_source, output_source, output_tag)
Definition: LoopParser.py:19