mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-08 08:26:55 +00:00
board_inspector: extend DSDT parser to allow parsing arbitrary trees
With AML templates for devices in the board XML, the parser now needs to be able to parse a stream as an arbitrary object. This patch adds the `parse_tree` method to the acpiparser.aml.parser module for this purpose. Tracked-On: #6287 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
parent
94d517b514
commit
5cf9ac714c
@ -167,15 +167,20 @@ class Context:
|
||||
# Mode switches
|
||||
self.__skip_external_on_lookup = False
|
||||
|
||||
def switch_stream(self, filepath):
|
||||
if not filepath in self.streams.keys():
|
||||
with open(filepath, "rb") as f:
|
||||
def switch_stream(self, val):
|
||||
if isinstance(val, str):
|
||||
if not val in self.streams.keys():
|
||||
with open(val, "rb") as f:
|
||||
stream = Stream(f.read())
|
||||
self.streams[filepath] = stream
|
||||
self.streams[val] = stream
|
||||
self.current_stream = stream
|
||||
else:
|
||||
self.current_stream = self.streams[filepath]
|
||||
self.current_stream = self.streams[val]
|
||||
self.current_stream.reset()
|
||||
elif isinstance(val, (bytes, bytearray)):
|
||||
self.current_stream = Stream(val)
|
||||
else:
|
||||
raise NotImplementedError(f"Cannot use {val} as a stream.")
|
||||
|
||||
def get_scope(self):
|
||||
return self.realpath(self.__current_scope, "")
|
||||
|
@ -7,7 +7,7 @@ import os
|
||||
import logging
|
||||
|
||||
from acpiparser.aml.stream import Stream
|
||||
from acpiparser.aml.parser import AMLCode, DeferredExpansion
|
||||
from acpiparser.aml import parser
|
||||
from acpiparser.aml.tree import Tree
|
||||
from acpiparser.aml.context import Context
|
||||
from acpiparser.aml.interpreter import ConcreteInterpreter
|
||||
@ -26,8 +26,8 @@ def DSDT(val):
|
||||
logging.info(f"Loading {t}")
|
||||
context.switch_stream(t)
|
||||
tree = Tree()
|
||||
AMLCode.parse(context, tree)
|
||||
tree = DeferredExpansion(context).transform(tree)
|
||||
parser.AMLCode.parse(context, tree)
|
||||
tree = parser.DeferredExpansion(context).transform(tree)
|
||||
context.trees[os.path.basename(t)] = tree
|
||||
except Exception as e:
|
||||
context.current_stream.dump()
|
||||
@ -38,3 +38,11 @@ def DSDT(val):
|
||||
for tree in context.trees.values():
|
||||
visitor.visit(tree)
|
||||
return context
|
||||
|
||||
def parse_tree(label, data):
|
||||
context = Context()
|
||||
context.switch_stream(data)
|
||||
tree = Tree()
|
||||
getattr(parser, label).parse(context, tree)
|
||||
tree = parser.DeferredExpansion(context).transform(tree)
|
||||
return tree
|
||||
|
Loading…
Reference in New Issue
Block a user