mirror of
				https://github.com/projectacrn/acrn-hypervisor.git
				synced 2025-10-31 01:09:28 +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:
		| @@ -167,15 +167,20 @@ class Context: | |||||||
|         # Mode switches |         # Mode switches | ||||||
|         self.__skip_external_on_lookup = False |         self.__skip_external_on_lookup = False | ||||||
|  |  | ||||||
|     def switch_stream(self, filepath): |     def switch_stream(self, val): | ||||||
|         if not filepath in self.streams.keys(): |         if isinstance(val, str): | ||||||
|             with open(filepath, "rb") as f: |             if not val in self.streams.keys(): | ||||||
|                 stream = Stream(f.read()) |                 with open(val, "rb") as f: | ||||||
|                 self.streams[filepath] = stream |                     stream = Stream(f.read()) | ||||||
|                 self.current_stream = stream |                     self.streams[val] = stream | ||||||
|  |                     self.current_stream = stream | ||||||
|  |             else: | ||||||
|  |                 self.current_stream = self.streams[val] | ||||||
|  |                 self.current_stream.reset() | ||||||
|  |         elif isinstance(val, (bytes, bytearray)): | ||||||
|  |             self.current_stream = Stream(val) | ||||||
|         else: |         else: | ||||||
|             self.current_stream = self.streams[filepath] |             raise NotImplementedError(f"Cannot use {val} as a stream.") | ||||||
|             self.current_stream.reset() |  | ||||||
|  |  | ||||||
|     def get_scope(self): |     def get_scope(self): | ||||||
|         return self.realpath(self.__current_scope, "") |         return self.realpath(self.__current_scope, "") | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ import os | |||||||
| import logging | import logging | ||||||
|  |  | ||||||
| from acpiparser.aml.stream import Stream | 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.tree import Tree | ||||||
| from acpiparser.aml.context import Context | from acpiparser.aml.context import Context | ||||||
| from acpiparser.aml.interpreter import ConcreteInterpreter | from acpiparser.aml.interpreter import ConcreteInterpreter | ||||||
| @@ -26,8 +26,8 @@ def DSDT(val): | |||||||
|             logging.info(f"Loading {t}") |             logging.info(f"Loading {t}") | ||||||
|             context.switch_stream(t) |             context.switch_stream(t) | ||||||
|             tree = Tree() |             tree = Tree() | ||||||
|             AMLCode.parse(context, tree) |             parser.AMLCode.parse(context, tree) | ||||||
|             tree = DeferredExpansion(context).transform(tree) |             tree = parser.DeferredExpansion(context).transform(tree) | ||||||
|             context.trees[os.path.basename(t)] = tree |             context.trees[os.path.basename(t)] = tree | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         context.current_stream.dump() |         context.current_stream.dump() | ||||||
| @@ -38,3 +38,11 @@ def DSDT(val): | |||||||
|     for tree in context.trees.values(): |     for tree in context.trees.values(): | ||||||
|         visitor.visit(tree) |         visitor.visit(tree) | ||||||
|     return context |     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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user