Skip to content

Commit

Permalink
Merge pull request #61 from vkottler/dev/3.2.0
Browse files Browse the repository at this point in the history
3.2.0 - Some config and other improvements
  • Loading branch information
vkottler authored Oct 20, 2023
2 parents fb810ff + ab6375c commit c369e0d
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=ifgen version=3.1.7
repo=ifgen version=3.2.0
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 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=d3a7ef970e2a79e369d20b7074001b70
hash=d2c1e9d24480cbe7d72337b49a9dc366
=====================================
-->

# ifgen ([3.1.7](https://pypi.org/project/ifgen/))
# ifgen ([3.2.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 Down
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=8dba39fd4ab323a71ee884c236534c9f
# hash=7e93d7f1d0e747a4ad065db36864eb77
# =====================================

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

DESCRIPTION = "An interface generator for distributed computing."
PKG_NAME = "ifgen"
VERSION = "3.1.7"
VERSION = "3.2.0"
18 changes: 17 additions & 1 deletion ifgen/commands/svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def svd_cmd(args: _Namespace) -> int:
enums.PRUNE_ENUMS = enable_pruning
base.PRUNE_STRUCTS = enable_pruning

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

return 0


DEFAULT_MIN_ENUM_WIDTH = 2


def add_svd_cmd(parser: _ArgumentParser) -> _CommandFunction:
"""Add svd-command arguments to its parser."""

Expand All @@ -54,6 +59,17 @@ def add_svd_cmd(parser: _ArgumentParser) -> _CommandFunction:
help="output directory for configuration files",
)

parser.add_argument(
"-m",
"--min-enum-width",
type=int,
default=DEFAULT_MIN_ENUM_WIDTH,
help=(
"minimum number of enumeration elements to warrant "
"generating an enumeration definition (default: %(default)s)"
),
)

parser.add_argument(
"svd_file", type=str, help="path/uri to a CMSIS-SVD file"
)
Expand Down
31 changes: 31 additions & 0 deletions ifgen/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
A module implementing a configuration interface for the package.
"""

# built-in
from typing import Any

# third-party
from vcorelib.dict import merge
from vcorelib.dict.codec import BasicDictCodec as _BasicDictCodec
from vcorelib.io import ARBITER as _ARBITER
from vcorelib.io import DEFAULT_INCLUDES_KEY
from vcorelib.io.types import JsonObject as _JsonObject
from vcorelib.paths import Pathlike, find_file

# internal
Expand All @@ -17,6 +21,33 @@
class Config(IfgenDictCodec, _BasicDictCodec):
"""The top-level configuration object for the package."""

def init(self, data: _JsonObject) -> None:
"""Initialize this instance."""

super().init(data)

common = ["identifier", "unit_test"]

# Forward enum settings.
enum_forwards = common + ["use_map"]
enum: dict[str, Any]
for enum in data.get("enums", {}).values(): # type: ignore
for forward in enum_forwards:
enum.setdefault(
forward,
data["enum"][forward], # type: ignore
)

# Forward struct settings.
struct_forwards = common + ["codec", "stream", "methods"]
struct: dict[str, Any]
for struct in data.get("structs", {}).values(): # type: ignore
for forward in struct_forwards:
struct.setdefault(
forward,
data["struct"][forward], # type: ignore
)


def load(path: Pathlike) -> Config:
"""Load a configuration object."""
Expand Down
4 changes: 4 additions & 0 deletions ifgen/data/default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
struct: {}
structs: {}

enum: {}
enums: {}

ifgen:
common: {}
63 changes: 50 additions & 13 deletions ifgen/data/schemas/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,41 @@ properties:
"^[a-zA-Z0-9-_.]+$":
$ref: package://ifgen/schemas/Struct.yaml

struct_id_underlying: &id_underlying
type: string
default: uint16_t
enum:
- int8_t
- int16_t
- int32_t
- int64_t
# Defaults for struct generation.
struct:
type: object
additionalProperties: false
required: []
properties:
codec:
type: boolean
default: true
stream:
type: boolean
default: true
methods:
type: boolean
default: true
identifier:
type: boolean
default: true
unit_test:
type: boolean
default: true

- uint8_t
- uint16_t
- uint32_t
- uint64_t
id_underlying: &id_underlying
type: string
default: uint16_t
enum:
- int8_t
- int16_t
- int32_t
- int64_t

enum_id_underlying: *id_underlying
- uint8_t
- uint16_t
- uint32_t
- uint64_t

enums:
type: object
Expand All @@ -59,5 +79,22 @@ properties:
"^[a-zA-Z0-9-_.]+$":
$ref: package://ifgen/schemas/Enum.yaml

# Defaults for enum generation.
enum:
type: object
additionalProperties: false
required: []
properties:
id_underlying: *id_underlying
use_map:
type: boolean
default: true
identifier:
type: boolean
default: true
unit_test:
type: boolean
default: true

ifgen:
type: object
7 changes: 3 additions & 4 deletions ifgen/data/schemas/Enum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ includes:
- has_description.yaml
- has_namespace.yaml
- has_json_indent.yaml
- has_unit_test.yaml

required: [enum]

Expand All @@ -22,13 +21,13 @@ properties:
description:
type: string

# Provide defaults from a higher-level configuration.
use_map:
type: boolean
default: true

identifier:
type: boolean
default: true
unit_test:
type: boolean

underlying:
type: string
Expand Down
11 changes: 3 additions & 8 deletions ifgen/data/schemas/Struct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ includes:
- has_namespace.yaml
- has_json_indent.yaml
- has_expected_size.yaml
- has_unit_test.yaml

required: [fields]

properties:
# Provide defaults from a higher-level configuration.
codec:
type: boolean
default: true

stream:
type: boolean
default: true

methods:
type: boolean
default: true

identifier:
type: boolean
default: true
unit_test:
type: boolean

instances:
type: array
Expand Down
5 changes: 0 additions & 5 deletions ifgen/data/schemas/has_unit_test.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion ifgen/enum/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def enum_header(task: GenerateTask, writer: IndentedFileWriter) -> None:
writer.write(
(
"static constexpr "
f"{task.env.config.data['enum_id_underlying']} "
f"{task.env.config.data['enum']['id_underlying']} "
f"{task.name}_id = {runtime.id};"
)
)
Expand Down
5 changes: 4 additions & 1 deletion ifgen/struct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ def create_struct(task: GenerateTask) -> None:
style=CommentStyle.C_DOXYGEN
) as lines:
if task.instance["identifier"]:
underlying = task.env.config.data["struct"][
"id_underlying"
]
lines.append(
(
"static constexpr "
f"{task.env.config.data['struct_id_underlying']} "
f"{underlying} "
f"id = {task.protocol().id};",
f"{task.name}'s identifier.",
)
Expand Down
16 changes: 13 additions & 3 deletions ifgen/svd/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def struct_instance(peripheral: Peripheral) -> dict[str, Any]:


def struct_data(
group: PeripheralGroup, structs: StructMap, enums: EnumMap
group: PeripheralGroup,
structs: StructMap,
enums: EnumMap,
min_enum_members: int,
) -> dict[str, Any]:
"""Get struct data for a peripheral group."""

Expand All @@ -42,7 +45,11 @@ def struct_data(

data["instances"] = [struct_instance(x) for x in group.peripherals]
size, data["fields"] = struct_fields(
peripheral.registers, structs, enums, peripheral.base_name(lower=False)
peripheral.registers,
structs,
enums,
peripheral.base_name(lower=False),
min_enum_members,
)

# Too difficult due to padding.
Expand All @@ -57,6 +64,7 @@ def handle_group(
output_dir: Path,
group: PeripheralGroup,
includes: set[Path],
min_enum_members: int,
) -> None:
"""Handle a peripheral group."""

Expand All @@ -65,5 +73,7 @@ def handle_group(

structs: StructMap = {}
enums: EnumMap = {}
structs[group.root.base_name()] = struct_data(group, structs, enums)
structs[group.root.base_name()] = struct_data(
group, structs, enums, min_enum_members
)
ARBITER.encode(output, {"structs": structs, "enums": enums})
Loading

0 comments on commit c369e0d

Please sign in to comment.