lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | # 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 | |
| 7 | import os |
| 8 | |
Eunchan Kim | cb28a17 | 2019-10-08 16:35:48 -0700 | [diff] [blame] | 9 | from mako import exceptions |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 10 | from mako.template import Template |
| 11 | from pkg_resources import resource_filename |
| 12 | |
| 13 | |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 14 | def gen_agent(name, has_separate_host_device_driver, root_dir, vendor): |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 15 | # set sub name |
| 16 | agent_dir = root_dir + "/" + name + "_agent" |
| 17 | |
| 18 | # yapf: disable |
Srikrishna Iyer | 77a30c2 | 2021-03-08 21:49:17 -0800 | [diff] [blame] | 19 | # flake8: noqa |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 20 | # 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 Kim | cb28a17 | 2019-10-08 16:35:48 -0700 | [diff] [blame] | 57 | try: |
| 58 | fout.write( |
| 59 | tpl.render(name=name, |
| 60 | has_separate_host_device_driver= |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 61 | has_separate_host_device_driver, |
| 62 | vendor=vendor)) |
Eunchan Kim | cb28a17 | 2019-10-08 16:35:48 -0700 | [diff] [blame] | 63 | except: |
| 64 | log.error(exceptions.text_error_template().render()) |