소스 검색

Provide features to control AML parser logging

By default, the AML parser should emit no output. These two features emit
debugging info of different verbosities (major objects and then minor stuff
like every ComputationalData).

There are a still `trace`s scattered about, but these should go away as
the namespace code is cleaned up.
Isaac Woods 5 년 전
부모
커밋
eafd8bae5e
4개의 변경된 파일44개의 추가작업 그리고 8개의 파일을 삭제
  1. 4 0
      aml_parser/Cargo.toml
  2. 2 2
      aml_parser/src/name_object.rs
  3. 26 1
      aml_parser/src/parser.rs
  4. 12 5
      aml_parser/src/term_object.rs

+ 4 - 0
aml_parser/Cargo.toml

@@ -12,3 +12,7 @@ edition = "2018"
 [dependencies]
 log = "0.4"
 bit_field = "0.9"
+
+[features]
+debug_parser = []
+debug_parser_verbose = []

+ 2 - 2
aml_parser/src/name_object.rs

@@ -1,6 +1,6 @@
 use crate::{
     opcode::{opcode, DUAL_NAME_PREFIX, MULTI_NAME_PREFIX, NULL_NAME, PREFIX_CHAR, ROOT_CHAR},
-    parser::{choice, comment_scope, consume, n_of, take, Parser},
+    parser::{choice, comment_scope_verbose, consume, n_of, take, Parser},
     AmlContext,
     AmlError,
 };
@@ -18,7 +18,7 @@ where
     let root_name_string =
         opcode(ROOT_CHAR).then(name_path()).map(|((), name_path)| String::from("\\") + &name_path);
 
-    comment_scope("NameString", move |input: &'a [u8], context: &'c mut AmlContext| {
+    comment_scope_verbose("NameString", move |input: &'a [u8], context: &'c mut AmlContext| {
         let first_char = match input.first() {
             Some(&c) => c,
             None => return Err((input, context, AmlError::UnexpectedEndOfStream)),

+ 26 - 1
aml_parser/src/parser.rs

@@ -205,10 +205,35 @@ where
     P: Parser<'a, 'c, R>,
 {
     move |input, context| {
+        #[cfg(feature = "debug_parser")]
         trace!("--> {}", scope_name);
+
         // Return if the parse fails, so we don't print the tail. Makes it easier to debug.
         let (new_input, context, result) = parser.parse(input, context)?;
-        trace!("<-- {}({:?})", scope_name, result);
+
+        #[cfg(feature = "debug_parser")]
+        trace!("<-- {}", scope_name);
+
+        Ok((new_input, context, result))
+    }
+}
+
+pub fn comment_scope_verbose<'a, 'c, P, R>(scope_name: &'a str, parser: P) -> impl Parser<'a, 'c, R>
+where
+    'c: 'a,
+    R: core::fmt::Debug,
+    P: Parser<'a, 'c, R>,
+{
+    move |input, context| {
+        #[cfg(feature = "debug_parser_verbose")]
+        trace!("--> {}", scope_name);
+
+        // Return if the parse fails, so we don't print the tail. Makes it easier to debug.
+        let (new_input, context, result) = parser.parse(input, context)?;
+
+        #[cfg(feature = "debug_parser_verbose")]
+        trace!("<-- {}", scope_name);
+
         Ok((new_input, context, result))
     }
 }

+ 12 - 5
aml_parser/src/term_object.rs

@@ -4,6 +4,7 @@ use crate::{
     parser::{
         choice,
         comment_scope,
+        comment_scope_verbose,
         take,
         take_to_end_of_pkglength,
         take_u16,
@@ -47,7 +48,7 @@ where
     /*
      * TermObj := NamespaceModifierObj | NamedObj | Type1Opcode | Type2Opcode
      */
-    comment_scope("TermObj", choice!(namespace_modifier(), named_obj()))
+    comment_scope_verbose("TermObj", choice!(namespace_modifier(), named_obj()))
 }
 
 pub fn namespace_modifier<'a, 'c>() -> impl Parser<'a, 'c, ()>
@@ -73,7 +74,13 @@ where
      * XXX: DefMethod and DefMutex (at least) are not included in any rule in the AML grammar,
      * but are defined in the NamedObj section so we assume they're part of NamedObj
      */
-    comment_scope("NamedObj", choice!(def_op_region(), def_field(), def_method(), def_device()))
+    comment_scope_verbose(
+        "NamedObj",
+        choice!(
+            def_op_region(),
+            def_field(),
+            def_method(),
+            def_device(),
 }
 
 pub fn def_name<'a, 'c>() -> impl Parser<'a, 'c, ()>
@@ -311,7 +318,7 @@ where
      * TermArg := Type2Opcode | DataObject | ArgObj | LocalObj
      */
     // TODO: this doesn't yet parse Term2Opcode, ArgObj, or LocalObj
-    comment_scope("TermArg", choice!(data_object()))
+    comment_scope_verbose("TermArg", choice!(data_object()))
 }
 
 pub fn data_ref_object<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
@@ -321,7 +328,7 @@ where
     /*
      * DataRefObject := DataObject | ObjectReference | DDBHandle
      */
-    comment_scope("DataRefObject", choice!(data_object()))
+    comment_scope_verbose("DataRefObject", choice!(data_object()))
 }
 
 pub fn data_object<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
@@ -378,7 +385,7 @@ where
         }
     };
 
-    comment_scope(
+    comment_scope_verbose(
         "ComputationalData",
         choice!(
             ext_opcode(opcode::EXT_REVISION_OP)