Skip to content

Commit

Permalink
3.3.0 - Add more advanced SVD support
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Jul 6, 2024
1 parent 0137dd7 commit e2df322
Show file tree
Hide file tree
Showing 30 changed files with 364 additions and 100 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
env:
TWINE_PASSWORD: ${{secrets.TWINE_PASSWORD}}
GITHUB_API_TOKEN: ${{secrets.API_TOKEN}}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}

jobs:
build:
Expand All @@ -18,7 +19,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.11"
- "3.12"
system:
- ubuntu-latest
Expand Down Expand Up @@ -57,29 +57,33 @@ jobs:

- run: mk docs
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
- run: mk python-test
env:
PY_TEST_EXTRA_ARGS: --cov-report=xml

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v3.1.5
with:
fail_ci_if_error: true
verbose: true
token: ${{secrets.CODECOV_TOKEN}}

- run: mk pypi-upload-ci
env:
TWINE_USERNAME: __token__
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
&& env.TWINE_PASSWORD != ''
&& github.ref_name == 'master'
- run: |
mk python-release owner=vkottler \
repo=ifgen version=3.2.1
repo=ifgen version=3.3.0
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
&& env.GITHUB_API_TOKEN != ''
&& github.ref_name == 'master'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage*.xml
tags
mklocal
docs
src
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[DESIGN]
max-args=8
max-args=9
max-attributes=8
max-locals=17

[MESSAGES CONTROL]
disable=duplicate-code
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Vaughn Kottler
Copyright (c) 2024 Vaughn Kottler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=c432187b0744b91a3bf18c6fc28df5eb
hash=35493b15233479037424afb95e796e3e
=====================================
-->

# ifgen ([3.2.1](https://pypi.org/project/ifgen/))
# ifgen ([3.3.0](https://pypi.org/project/ifgen/))

[![python](https://img.shields.io/pypi/pyversions/ifgen.svg)](https://pypi.org/project/ifgen/)
![Build Status](https://github.com/vkottler/ifgen/workflows/Python%20Package/badge.svg)
Expand All @@ -29,7 +29,6 @@

This package is tested with the following Python minor versions:

* [`python3.11`](https://docs.python.org/3.11/)
* [`python3.12`](https://docs.python.org/3.12/)

## Platform Support
Expand Down
2 changes: 1 addition & 1 deletion config
4 changes: 2 additions & 2 deletions ifgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=302dd11b12a573508cf3316546a384ef
# hash=bf2c126f5c469e9b0483e934ee695f9e
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "An interface generator for distributed computing."
PKG_NAME = "ifgen"
VERSION = "3.2.1"
VERSION = "3.3.0"
16 changes: 14 additions & 2 deletions ifgen/commands/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# built-in
from argparse import ArgumentParser as _ArgumentParser
from argparse import Namespace as _Namespace
import sys

# third-party
from vcorelib.args import CommandFunction as _CommandFunction
Expand All @@ -22,6 +23,8 @@ def gen_cmd(args: _Namespace) -> int:

root = normalize(args.root)

sys.setrecursionlimit(args.recursion)

generate(root.resolve(), load(combine_if_not_absolute(root, args.config)))

return 0
Expand All @@ -30,16 +33,25 @@ def gen_cmd(args: _Namespace) -> int:
def add_gen_cmd(parser: _ArgumentParser) -> _CommandFunction:
"""Add gen-command arguments to its parser."""

parser.add_argument(
"--recursion",
type=int,
default=10000,
help="recursion limit to set (default: '%(default)s')",
)
parser.add_argument(
"-c",
"--config",
default=f"{PKG_NAME}.yaml",
help="configuration file to use",
help="configuration file to use (default: '%(default)s')",
)
parser.add_argument(
"-r",
"--root",
default=".",
help="root directory to use for relative paths",
help=(
"root directory to use for relative "
"paths (default: '%(default)s')"
),
)
return gen_cmd
28 changes: 21 additions & 7 deletions ifgen/commands/svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# internal
from ifgen import PKG_NAME
from ifgen.config.svd import SvdConfig
from ifgen.svd import register_processors
from ifgen.svd.group import base, enums
from ifgen.svd.task import SvdProcessingTask
Expand All @@ -23,23 +24,26 @@ def svd_cmd(args: _Namespace) -> int:
"""Execute the svd command."""

register_processors()
logger = getLogger(__name__)

Check warning on line 27 in ifgen/commands/svd.py

View check run for this annotation

Codecov / codecov/patch

ifgen/commands/svd.py#L27

Added line #L27 was not covered by tests

path = find_file(
args.svd_file,
package=PKG_NAME,
logger=getLogger(__name__),
include_cwd=True,
args.svd_file, package=PKG_NAME, logger=logger, include_cwd=True
)
assert path is not None, args.svd_file

enable_pruning = path.with_suffix("").name in {"XMC4700"}
config = SvdConfig.decode(

Check warning on line 34 in ifgen/commands/svd.py

View check run for this annotation

Codecov / codecov/patch

ifgen/commands/svd.py#L34

Added line #L34 was not covered by tests
find_file(args.config, logger=logger, include_cwd=True)
)

# Only enable certain pruning strategies for certain processors.
enable_pruning = path.with_suffix("").name in config.data.setdefault(

Check warning on line 39 in ifgen/commands/svd.py

View check run for this annotation

Codecov / codecov/patch

ifgen/commands/svd.py#L39

Added line #L39 was not covered by tests
"enable_pruning", []
)
enums.PRUNE_ENUMS = enable_pruning
base.PRUNE_STRUCTS = enable_pruning

SvdProcessingTask.svd(path, args.min_enum_width).generate_configs(
args.output
args.output, config
)

return 0
Expand All @@ -56,7 +60,17 @@ def add_svd_cmd(parser: _ArgumentParser) -> _CommandFunction:
"--output",
type=Path,
default=f"{PKG_NAME}-out",
help="output directory for configuration files",
help=(
"output directory for configuration "
"files (default '%(default)s')"
),
)

parser.add_argument(
"-c",
"--config",
default="package://ifgen/svd.yaml",
help="configuration rules to use (default: '%(default)s')",
)

parser.add_argument(
Expand Down
13 changes: 13 additions & 0 deletions ifgen/config/svd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
A module implementing an SVD-command configuration interface for the package.
"""

# third-party
from vcorelib.dict.codec import BasicDictCodec as _BasicDictCodec

# internal
from ifgen.schemas import IfgenDictCodec


class SvdConfig(IfgenDictCodec, _BasicDictCodec):
"""The top-level configuration object for the package."""
18 changes: 18 additions & 0 deletions ifgen/data/schemas/SvdConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
type: object
additionalProperties: false
required: []

properties:
enable_pruning:
type: array
default: [XMC4700]
items:
type: string

devices:
type: object
additionalProperties: false
patternProperties:
"^[a-zA-Z0-9-_.]+$":
$ref: package://ifgen/schemas/SvdInstanceConfig.yaml
18 changes: 18 additions & 0 deletions ifgen/data/schemas/SvdInstanceConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
type: object
additionalProperties: false
required: []

properties:
ignore_peripherals:
type: array
items:
type: object
additionalProperties: false
required: [name, reason]

properties:
name:
type: string
reason:
type: string
15 changes: 15 additions & 0 deletions ifgen/data/svd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

# Note: ignored peripherals still get generated YAML outputs, they're just
# not included in the generated top-level ifgen.yaml.

devices:
mimxrt1176_cm4: &rt1176
ignore_peripherals:
- name: caam
reason: Register map not in reference manual / (#64).
- name: dcic1
reason: (#64) dimIncrement not supported.
- name: rdc
reason: (#64) dimIncrement not supported.
mimxrt1176_cm7: *rt1176
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ifgen/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ sphinx-book-theme
pytest-cov
setuptools-wrapper
types-setuptools
yambs
yambs>=3.0.4
2 changes: 1 addition & 1 deletion ifgen/environment/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def process_field(
difference = expected - size

assert difference >= 0, (
f"({struct_name}.{field_name}) current={size} "
f"{difference} ({struct_name}.{field_name}) current={size} "
f"!= expected={expected}"
)

Expand Down
4 changes: 2 additions & 2 deletions ifgen/svd/group/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def translate_enums(enum: EnumeratedValues) -> EnumValues:
enum_data: dict[str, Any] = {}
value.handle_description(enum_data)

value_str: str = value.raw_data["value"]
value_str: str = value.raw_data["value"].lower()

Check warning on line 147 in ifgen/svd/group/enums.py

View check run for this annotation

Codecov / codecov/patch

ifgen/svd/group/enums.py#L147

Added line #L147 was not covered by tests

prefix = ""
for possible_prefix in ("#", "0b", "0x"):
Expand All @@ -154,7 +154,7 @@ def translate_enums(enum: EnumeratedValues) -> EnumValues:

if prefix in ("#", "0b"):
enum_data["value"] = int(
value_str[len(prefix) :].replace("X", "1"), 2
value_str[len(prefix) :].replace("x", "1"), 2
)
elif prefix == "0x":
enum_data["value"] = int(value_str[len(prefix) :], 16)
Expand Down
Loading

0 comments on commit e2df322

Please sign in to comment.