From: Andrei Ziureaev <andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 0/6] dtc: Add support for signed operations
Date: Tue, 14 Jul 2020 16:45:36 +0100 [thread overview]
Message-ID: <20200714154542.18064-1-andrei.ziureaev@arm.com> (raw)
Following the discussion on v1, I decided to add proper support for all
signed operations.
The first two patches can be useful on their own.
Patches 3/6 to 6/6 add support for signed operations and sign
preservation in high-level output formats.
All operators are supported, which means some of them will behave
differently with negative values, namely: /, %, >>, <, <=, >, >=. I
haven't found any existing dts files using these operators with negative
values.
There is no explicit signed type in the dts format, but the idea is to
infer the sign as intuitively as possible: negative values are signed,
positive values are unsigned. Zero can be either, so the output side
checks for that. I haven't given much thought to overflows, but they
happen to be handled well, I think (at least UB in C is prevented).
This change allows us to validate dts files that contain negative
values. One could argue that (-1 == 0xffffffff), so there's no point in
doing this, but dt-schema is written in Python 3, which uses
arbitrary-precision arithmetic and doesn't have the traditional
overflowing types. This makes it hard to solve this problem in dt-schema
(especially checking if a signed value is within a range, I think).
Thanks,
Andrei.
Changes in v2:
- avoid UB when shifting
- add a bytestring type
- add support for all the operators
- use TYPE_SIGNED, instead of TYPE_NEGATIVE
- use macros on the output side
- add more tests
Andrei Ziureaev (6):
dtc: Avoid UB when shifting
dtc: Add bytestring type
dtc: Turn 'uint64_t integer' into a struct
dtc: Add support for signed operations
dtc: Preserve negative integers in yaml and dts
dtc: Add sign preservation and operation tests
dtc-lexer.l | 10 +-
dtc-parser.y | 190 ++++++++++++++++++++++++++------
dtc.h | 14 +++
tests/integer-expressions.c | 8 ++
tests/operations-expected.dts | 31 ++++++
tests/operations.dt.yaml | 29 +++++
tests/operations.dts | 38 +++++++
tests/run_tests.sh | 13 ++-
tests/sign-preservation.dt.yaml | 23 ++++
tests/sign-preservation.dts | 31 ++++++
tests/type-preservation.dt.yaml | 2 +
tests/type-preservation.dts | 6 +-
treesource.c | 47 +++++---
yamltree.c | 27 ++---
14 files changed, 399 insertions(+), 70 deletions(-)
create mode 100644 tests/operations-expected.dts
create mode 100644 tests/operations.dt.yaml
create mode 100644 tests/operations.dts
create mode 100644 tests/sign-preservation.dt.yaml
create mode 100644 tests/sign-preservation.dts
--
2.17.1
next reply other threads:[~2020-07-14 15:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 15:45 Andrei Ziureaev [this message]
[not found] ` <20200714154542.18064-1-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-14 15:45 ` [PATCH v2 1/6] dtc: Avoid UB when shifting Andrei Ziureaev
[not found] ` <20200714154542.18064-2-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-15 10:41 ` David Gibson
2020-07-14 15:45 ` [PATCH v2 2/6] dtc: Add bytestring type Andrei Ziureaev
2020-07-14 15:45 ` [PATCH v2 3/6] dtc: Turn 'uint64_t integer' into a struct Andrei Ziureaev
2020-07-14 15:45 ` [PATCH v2 4/6] dtc: Add support for signed operations Andrei Ziureaev
[not found] ` <20200714154542.18064-5-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-08-03 10:21 ` David Gibson
2020-07-14 15:45 ` [PATCH v2 5/6] dtc: Preserve negative integers in yaml and dts Andrei Ziureaev
2020-07-14 15:45 ` [PATCH v2 6/6] dtc: Add sign preservation and operation tests Andrei Ziureaev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714154542.18064-1-andrei.ziureaev@arm.com \
--to=andrei.ziureaev-5wv7dgnigg8@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).