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 the types.h header file.
Compile time asserts are included in the build_bug.h header file.
  • Loading branch information
mkahane committed Jul 1, 2024
1 parent db696fc commit faf580d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/peakrdl_cheader/c_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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)
self.needs_types_h = d.get("needs_types_h", False)

# Prevent Enum from flattening members into aliases
self._value_ = name
Expand Down Expand Up @@ -46,4 +49,13 @@ 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,
"needs_types_h" :True,
"static_assert_needs_assert_h" : False,
"static_assert_needs_build_bug_h": True,
}

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

{%- if ds.std.needs_stdint_h %}
#include <stdint.h>
{%- endif %}
{%- if ds.std.needs_types_h %}
#include <linux/types.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 faf580d

Please sign in to comment.