Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added yaml dump flag #173

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [3.18.2] - 2024-04-16
- added yaml dump_flag which provides for the functions that dump yaml.

## [3.18.1] - 2024-04-10
- mprv should not be implemented when U mode is absent.
Expand Down
2 changes: 1 addition & 1 deletion riscv_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
__version__ = '3.18.1'
__version__ = '3.18.2'

128 changes: 79 additions & 49 deletions riscv_config/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,8 @@ def check_triggers(spec, logging):
def check_debug_specs(debug_spec, isa_spec,
work_dir,
logging=False,
no_anchors=False):
no_anchors=False,
yaml_dump=True):
'''
Function to perform ensure that the isa and debug specifications confirm
to their schemas. The :py:mod:`Cerberus` module is used to validate that the
Expand All @@ -1713,15 +1714,20 @@ def check_debug_specs(debug_spec, isa_spec,

:param logging: A boolean to indicate whether log is to be printed.

:param yaml_dump: A boolean to indicate whether the dictionary has to be dumped into a yaml or returns a dict

:type logging: bool

:type isa_spec: str

:type yaml_dump: bool

:raise ValidationError: It is raised when the specifications violate the
schema rules. It also contains the specific errors in each of the fields.

:return: A tuple with the first entry being the absolute path to normalized isa file
and the second being the absolute path to the platform spec file.
and the second being the absolute path to the platform spec file (if yaml_dump = True) or
returns the yaml as dictionary(if yaml_dump = False).
'''

foo1 = isa_spec
Expand Down Expand Up @@ -1781,21 +1787,26 @@ def check_debug_specs(debug_spec, isa_spec,
normalized = update_fields(normalized, logging)

outyaml['hart'+str(x)] = trim(normalized)
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
dfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('DebugCheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return dfile

if yaml_dump == True:
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
dfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('DebugCheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return dfile
else:
return outyaml

def check_isa_specs(isa_spec,
work_dir,
logging=False,
no_anchors=False):
no_anchors=False,
dump_yaml=True):
'''
Function to perform ensure that the isa and platform specifications confirm
to their schemas. The :py:mod:`Cerberus` module is used to validate that the
Expand All @@ -1805,6 +1816,8 @@ def check_isa_specs(isa_spec,

:param logging: A boolean to indicate whether log is to be printed.

:param dump_yaml: A boolean to indicate if the yaml has to be dumped or has to be returned as adict

:type logging: bool

:type isa_spec: str
Expand All @@ -1813,7 +1826,8 @@ def check_isa_specs(isa_spec,
schema rules. It also contains the specific errors in each of the fields.

:return: A tuple with the first entry being the absolute path to normalized isa file
and the second being the absolute path to the platform spec file.
and the second being the absolute path to the platform spec file (when dump_yaml=True) or
returns a yaml dict(when dump_yaml=False).
'''
global inp_yaml

Expand Down Expand Up @@ -1868,21 +1882,25 @@ def check_isa_specs(isa_spec,
normalized = update_fields(normalized, logging)

outyaml['hart'+str(x)] = trim(normalized)
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
ifile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('ISACheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return ifile

if dump_yaml==True:
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
ifile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('ISACheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return ifile
else:
return outyaml

def check_custom_specs(custom_spec,
work_dir,
logging=False,
no_anchors=False):
no_anchors=False,
yaml_dump=True):
'''
Function to perform ensure that the isa and platform specifications confirm
to their schemas. The :py:mod:`Cerberus` module is used to validate that the
Expand All @@ -1891,11 +1909,16 @@ def check_custom_specs(custom_spec,
:param isa_spec: The path to the DUT isa specification yaml file.

:param logging: A boolean to indicate whether log is to be printed.

:param yaml_dump: A boolean to idicate whether the log has to be dumped into a yaml
or has to return a dictionary. By default the yaml_dump is `True`

:type logging: bool

:type isa_spec: str

:type yaml_dump: bool

:raise ValidationError: It is raised when the specifications violate the
schema rules. It also contains the specific errors in each of the fields.

Expand Down Expand Up @@ -1936,21 +1959,25 @@ def check_custom_specs(custom_spec,
if errors:
raise ValidationError("Error in " + foo + ".", errors)
outyaml['hart'+str(x)] = trim(inp_yaml)
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
cfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('CustomCheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return cfile

if yaml_dump==True:
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
cfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('CustomCheck: Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(outyaml, outfile, no_anchors )
return cfile
else:
return outyaml

def check_platform_specs(platform_spec,
work_dir,
logging=False,
no_anchors=False):
no_anchors=False,
yaml_dump=True):
foo = platform_spec
schema = constants.platform_schema
if logging:
Expand Down Expand Up @@ -1988,18 +2015,21 @@ def check_platform_specs(platform_spec,
error_list = validator.errors
raise ValidationError("Error in " + foo + ".", error_list)

file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
pfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(trim(normalized), outfile, no_anchors)

return pfile
if yaml_dump == True:
file_name = os.path.split(foo)
file_name_split = file_name[1].split('.')
output_filename = os.path.join(
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
pfile = output_filename
outfile = open(output_filename, 'w')
if logging:
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
utils.dump_yaml(trim(normalized), outfile, no_anchors)

return pfile
else:
return trim(normalized)

def check_csr_specs(ispec=None, customspec=None, dspec=None, pspec=None, work_dir=None, logging=False, no_anchors=True) -> list:
'''
Merge the isa, custom and debug CSR specs into a single CSR spec file.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.18.1
current_version = 3.18.2
commit = True
tag = True

Expand Down
Loading