ocebuild.parsers.asl#

Helper functions for parsing ASL source code.

Module Contents#

Functions#

parse_definition_block(→ collections.OrderedDict)

Parses arguments from a definition block line.

parse_ssdt_namespace(→ dict)

Parses an SSDT's namespace for imports and statement exports.

Attributes#

ASL_COMPILER_CONTROLS

Types of AST nodes that represent compiler controls.

ASL_TYPES_SCOPES

Types of AST nodes that represent scopes.

ASL_TYPES_CONDITIONALS

Types of AST nodes that represent conditionals.

ASL_PREFIX_MODIFIERS

ASL name modifier prefixes.

DEFINITION_BLOCK_ARGS

The arguments of a definition block.

RE_BLOCK_ARGS

Regular expression for matching block arguments.

RE_IMPORT_TYPE

Regular expression for matching import types.

RE_LOCAL_VAR

Regular expression for matching local-scoped object names.

RE_STATEMENT

Regular expression for matching statements.

RE_NAME

Regular expression for matching object names.

ocebuild.parsers.asl.ASL_COMPILER_CONTROLS = ('External', 'Include')[source]#

Types of AST nodes that represent compiler controls.

For ASL Compiler Controls (19.16; Table), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#asl-compiler-controls

ocebuild.parsers.asl.ASL_TYPES_SCOPES = ('DefinitionBlock', 'Scope')[source]#

Types of AST nodes that represent scopes.

ocebuild.parsers.asl.ASL_TYPES_CONDITIONALS = ('If', 'ElseIf', 'Else')[source]#

Types of AST nodes that represent conditionals.

ocebuild.parsers.asl.ASL_PREFIX_MODIFIERS = ('\\', '^')[source]#

ASL name modifier prefixes.

For Definition Block Name Modifier Encodings (19.3; Table), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#definition-block-name-modifier-encodings

Example

```cpp Scope (PCI0) {

Name (X, 3) Scope () {

Method (RQ) {Return (0)}

} Name (^Y, 4)

}#

# ACPI Namespace -> PCI0.X, RQ, Y

ocebuild.parsers.asl.DEFINITION_BLOCK_ARGS = ('AMLFileName', 'TableSignature', 'ComplianceRevision', 'OEMID', 'TableID', 'OEMRevision')[source]#

The arguments of a definition block.

For DefinitionBlock (19.6.29), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#definitionblock-declare-definition-block

ocebuild.parsers.asl.RE_BLOCK_ARGS = '\\(((?:.*?),?\\s?)\\)'[source]#

Regular expression for matching block arguments.

Groups:

0: The matched line 1: The block arguments

ocebuild.parsers.asl.RE_IMPORT_TYPE = '\\(.*?,\\s?([a-zA-Z]+),?\\)?'[source]#

Regular expression for matching import types.

For External (Declare External Objects, 19.6.45), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#external-declare-external-objects

Groups:

0: The import type

ocebuild.parsers.asl.RE_LOCAL_VAR = '^(Arg|Local)(\\d+)$'[source]#

Regular expression for matching local-scoped object names.

For ArgX Objects (19.3.5.8.1), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#argx-objects

For LocalX Objects (19.3.5.8.2), see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/19_ASL_Reference/ACPI_Source_Language_Reference.html#localx-objects

Groups:

0: The object type 1: The variable index

ocebuild.parsers.asl.RE_STATEMENT = '^([a-zA-Z]+)\\s?\\((.*?)[,\\)]+?'[source]#

Regular expression for matching statements.

Groups:

0: The statement type. 1: The object name.

ocebuild.parsers.asl.RE_NAME = '^[A-Z\\^\\_\\\\][a-zA-Z0-9\\^\\_\\.\\\\]+$'[source]#

Regular expression for matching object names.

Groups:

0: The object name.

ocebuild.parsers.asl.parse_definition_block(string: str) collections.OrderedDict[source]#

Parses arguments from a definition block line.

Parameters:

string – A definition block line.

Returns:

A dictionary of definition block arguments.

Raises:

ValueError – If the line is not a valid definition block.

Example

>>> parse_definition_block('DefinitionBlock ("", "DSDT", 2, "_ASUS_", ...)')
OrderedDict([('AMLFileName', ''),
             ('TableSignature', 'DSDT'),
             ('ComplianceRevision', 2),
             ('OEMID', '_ASUS_'),
             ('TableID', 'Notebook'),
             ('OEMRevision', '0x01072009')])
ocebuild.parsers.asl.parse_ssdt_namespace(lines: List[str] | io.TextIOWrapper) dict[source]#

Parses an SSDT’s namespace for imports and statement exports.

Parameters:

lines – A list of SSDT lines.

Returns:

A dictionary of extracted SSDT information.

Example

>>> parse_ssdt_namespace(open('path/to/ssdt.dsl', encoding='UTF-8'))
>>> with open('path/to/ssdt.dsl', encoding='UTF-8') as ssdt_file:
...   ssdt_lines = [f.strip() for f in ssdt_file.readlines()]
...   parse_ssdt_namespace(ssdt_lines)