tools/net/ynl/pyynl/ynl_gen_c.py
Source file repositories/reference/linux-study-clean/tools/net/ynl/pyynl/ynl_gen_c.py
File Facts
- System
- Linux kernel
- Corpus path
tools/net/ynl/pyynl/ynl_gen_c.py- Extension
.py- Size
- 132591 bytes
- Lines
- 3762
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function write_doc_linefunction render_scoped_consts
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
#
# pylint: disable=line-too-long, missing-class-docstring, missing-function-docstring
# pylint: disable=too-many-positional-arguments, too-many-arguments, too-many-statements
# pylint: disable=too-many-branches, too-many-locals, too-many-instance-attributes
# pylint: disable=too-many-nested-blocks, too-many-lines, too-few-public-methods
# pylint: disable=broad-exception-raised, broad-exception-caught, protected-access
"""
ynl_gen_c
A YNL to C code generator for both kernel and userspace protocol stubs.
"""
import argparse
import filecmp
import pathlib
import os
import re
import shutil
import sys
import tempfile
import yaml as pyyaml
# pylint: disable=no-name-in-module,wrong-import-position
sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, SpecEnumEntry
from lib import SpecSubMessage
def c_upper(name):
return name.upper().replace('-', '_')
def c_lower(name):
return name.lower().replace('-', '_')
def limit_to_number(name):
"""
Turn a string limit like u32-max or s64-min into its numerical value
"""
if name[0] == 'u' and name.endswith('-min'):
return 0
width = int(name[1:-4])
if name[0] == 's':
width -= 1
value = (1 << width) - 1
if name[0] == 's' and name.endswith('-min'):
value = -value - 1
return value
class BaseNlLib:
def get_family_id(self):
return 'ys->family_id'
class Type(SpecAttr):
def __init__(self, family, attr_set, attr, value):
super().__init__(family, attr_set, attr, value)
self.attr = attr
self.attr_set = attr_set
self.type = attr['type']
self.checks = attr.get('checks', {})
self.request = False
self.reply = False
Annotation
- Detected declarations: `function write_doc_line`, `function render_scoped_consts`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.