Skip to content

Commit

Permalink
c_standards: Add a standard for linux driver programming
Browse files Browse the repository at this point in the history
Linux kernel code does not have stdint or assert header files.
The integer types used are included by default in Linux
and compile time asserts are included in the
build_bug.h header file.
  • Loading branch information
mkahane committed Jun 29, 2024
1 parent db696fc commit 6bb94ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/peakrdl_cheader/c_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def __init__(self, name: str, d: Dict[str, bool]) -> None:
self.anon_unions = d.get("anon_unions", False)
self.static_assert = d.get("static_assert", False)
self.static_assert_needs_assert_h = d.get("static_assert_needs_assert_h", False)
self.static_assert_needs_build_bug_h = d.get("static_assert_needs_build_bug_h", False)
self.needs_stdint_h = d.get("needs_stdint_h", True)

# Prevent Enum from flattening members into aliases
self._value_ = name
Expand Down Expand Up @@ -46,4 +48,12 @@ def __init__(self, name: str, d: Dict[str, bool]) -> None:
"static_assert_needs_assert_h": False,
}

linux = "linux", {
"anon_unions" : True,
"static_assert" :True,
"needs_stdint_h": False,
"static_assert_needs_assert_h" : False,
"static_assert_needs_build_bug_h": True,
}

latest = gnu17 # gnu23 is still unreleased
5 changes: 5 additions & 0 deletions src/peakrdl_cheader/templates/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
extern "C" {
#endif

{%- if ds.std.needs_stdint_h %}
#include <stdint.h>
{%- endif %}
{%- if ds.std.static_assert_needs_assert_h %}
#include <assert.h>
{%- endif %}
{%- if ds.std.static_assert_needs_build_bug_h %}
#include <linux/build_bug.h>
{%- endif %}

0 comments on commit 6bb94ec

Please sign in to comment.