unified setup configs
[reconos.git] / tools / python / preproc.py
blob3789bcd50671bffea7aa684678f537da6efbe2f4
1 #!/usr/bin/env python
2 # coding: utf8
4 # ____ _____
5 # ________ _________ ____ / __ \/ ___/
6 # / ___/ _ \/ ___/ __ \/ __ \/ / / /\__ \
7 # / / / __/ /__/ /_/ / / / / /_/ /___/ /
8 # /_/ \___/\___/\____/_/ /_/\____//____/
9 #
10 # ======================================================================
12 # project: ReconOS
13 # author: Christoph RĂ¼thing, University of Paderborn
14 # description: A simple preprocessor which handles "GENERATE LOOP"
16 # ======================================================================
18 import sys
20 def generate_loop(filename, num_hwts):
21 STATE_COPY = 0
22 STATE_LOOP = 1
24 fin = open(filename, "r")
25 state = STATE_COPY
27 while True:
28 line = fin.readline()
30 if not line:
31 break;
33 if "END GENERATE LOOP" in line:
34 state = STATE_COPY
36 if state == STATE_COPY:
37 sys.stdout.write(line)
38 else:
39 for i in range(num_hwts):
40 loopline = line.replace("#i#", str(i))
41 sys.stdout.write(loopline)
43 if "BEGIN GENERATE LOOP" in line:
44 state = STATE_LOOP
47 fin.close();
49 generate_loop(sys.argv[1], int(sys.argv[2]))