blob: 56d772b1069ba90a92314b9d87de2ef8b3dca459 [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4"""Generate SystemVerilog UVM agent extended freom our DV lib
5"""
6
7import os
8
Eunchan Kimcb28a172019-10-08 16:35:48 -07009from mako import exceptions
lowRISC Contributors802543a2019-08-31 12:12:56 +010010from mako.template import Template
11from pkg_resources import resource_filename
12
13
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070014def gen_agent(name, has_separate_host_device_driver, root_dir, vendor):
lowRISC Contributors802543a2019-08-31 12:12:56 +010015 # set sub name
16 agent_dir = root_dir + "/" + name + "_agent"
17
18 # yapf: disable
Srikrishna Iyer77a30c22021-03-08 21:49:17 -080019 # flake8: noqa
lowRISC Contributors802543a2019-08-31 12:12:56 +010020 # 4-tuple - path, ip name, class name, file ext
21 agent_srcs = [(agent_dir, name + '_', 'if', '.sv'),
22 (agent_dir, name + '_', 'item', '.sv'),
23 (agent_dir, name + '_', 'agent_cfg', '.sv'),
24 (agent_dir, name + '_', 'agent_cov', '.sv'),
25 (agent_dir, name + '_', 'monitor', '.sv'),
26 (agent_dir, name + '_', 'driver', '.sv'),
27 (agent_dir, name + '_', 'host_driver', '.sv'),
28 (agent_dir, name + '_', 'device_driver', '.sv'),
29 (agent_dir, name + '_', 'agent_pkg', '.sv'),
30 (agent_dir, name + '_', 'agent', '.sv'),
31 (agent_dir, name + '_', 'agent', '.core'),
32 (agent_dir, "", 'README', '.md'),
33 (agent_dir + "/seq_lib", name + '_', 'seq_list', '.sv'),
34 (agent_dir + "/seq_lib", name + '_', 'base_seq', '.sv')]
35 # yapf: enable
36
37 for tup in agent_srcs:
38 path_dir = tup[0]
39 src_prefix = tup[1]
40 src = tup[2]
41 src_suffix = tup[3]
42
43 if has_separate_host_device_driver:
44 if src == "driver": continue
45 else:
46 if src == "host_driver": continue
47 if src == "device_driver": continue
48
49 ftpl = src + src_suffix + '.tpl'
50 fname = src_prefix + src + src_suffix
51
52 # read template
53 tpl = Template(filename=resource_filename('uvmdvgen', ftpl))
54
55 if not os.path.exists(path_dir): os.system("mkdir -p " + path_dir)
56 with open(path_dir + "/" + fname, 'w') as fout:
Eunchan Kimcb28a172019-10-08 16:35:48 -070057 try:
58 fout.write(
59 tpl.render(name=name,
60 has_separate_host_device_driver=
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070061 has_separate_host_device_driver,
62 vendor=vendor))
Eunchan Kimcb28a172019-10-08 16:35:48 -070063 except:
64 log.error(exceptions.text_error_template().render())