forked from tudortimi/rgen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ipxact2verilog.py
executable file
·83 lines (59 loc) · 2.28 KB
/
ipxact2verilog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
sys.path.append('ipyxact')
from ipyxact.ipyxact import Component
from mako.lookup import TemplateLookup
from mako.template import Template
from mako.runtime import Context
import argparse
import yaml
parser = argparse.ArgumentParser(description='Generate Verilog RTL for Config/Status-Register')
parser.add_argument('xml_path', metavar='<ipcore.xml>', type=file, nargs=1,
help='path to IP-XACT xml-file to be parse')
args = parser.parse_args()
inputname = os.path.splitext(args.xml_path[0].name)[0] + ".yml"
try:
with open(inputname, 'r') as configfile:
cfg = yaml.load(configfile)
except IOError:
with open("config.yml", 'r') as configfile:
cfg = yaml.load(configfile)
'''debug print of config sections
for section in cfg:
print(section)
'''
clk = str(cfg['General']['Clock'])
rst = str(cfg['General']['Reset'])
rst_level = int(cfg['General']['ResetActiveLevel'])
rst_is_sync = int(cfg['General']['ResetIsSync'])
component = Component()
component.load(args.xml_path[0].name)
addressBlock = component.memoryMaps.memoryMap[0].addressBlock[0]
busByteWidth = component.memoryMaps.memoryMap[0].addressBlock[0].width / 8
busBitWidth = component.memoryMaps.memoryMap[0].addressBlock[0].width
addr_width = component.memoryMaps.memoryMap[0].addressBlock[0].width
data_width = component.memoryMaps.memoryMap[0].addressBlock[0].register[0].size
fileName = component.name.lower() + '_regs.v'
lookup = TemplateLookup(directories=['templates'],
input_encoding='utf-8',
output_encoding='utf-8',
default_filters=['decode.utf8'],
encoding_errors='replace')
buffer = open(fileName, 'w')
for reg in addressBlock.register:
template = lookup.get_template('verilog_regs_wr.mako')
ctx = Context(buffer,
reg = reg,
cfg = cfg,
addr_width = addr_width,
data_width = data_width)
template.render_context(ctx)
template = lookup.get_template('verilog_regs_rd.mako')
ctx = Context(buffer,
register = addressBlock.register,
cfg = cfg,
addr_width = addr_width,
data_width = data_width)
template.render_context(ctx)