[applied] abilint: Support --annotate

Message ID 87leaenfcb.fsf@redhat.com
State New
Headers
Series [applied] abilint: Support --annotate |

Commit Message

Dodji Seketeli Dec. 1, 2023, 2:54 p.m. UTC
  Hello,

It turns out abilint doesn't support the "--annotate" option like
abidw does.  Annoying.  Added thus.

	* tools/abilint.cc (options::annotate): Define new data member.
	(options::options): Initialize.
	(display_usage): Add help string.
	(parse_command): Support the --annotate command options.
	(main): Set the annotate option on the context.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.
---
 doc/manuals/abilint.rst |  7 +++++++
 tools/abilint.cc        | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
  

Patch

diff --git a/doc/manuals/abilint.rst b/doc/manuals/abilint.rst
index 4213a22e..594dd4c2 100644
--- a/doc/manuals/abilint.rst
+++ b/doc/manuals/abilint.rst
@@ -27,6 +27,13 @@  Invocation
 Options
 =======
 
+  * ``--annotate``
+
+    Annotate the ABIXML output with comments above most elements.  The
+    comments are made of the pretty-printed form of types, declaration
+    or even ELF symbols.  The purpose is to make the ABIXML output
+    more human-readable for debugging or documenting purposes.
+
   * ``--help``
 
     Display a short help message and exits.
diff --git a/tools/abilint.cc b/tools/abilint.cc
index 91718067..9c6ed897 100644
--- a/tools/abilint.cc
+++ b/tools/abilint.cc
@@ -81,6 +81,7 @@  struct options
   bool				read_tu;
   bool				diff;
   bool				noout;
+  bool				annotate;
 #ifdef WITH_CTF
   bool				use_ctf;
 #endif
@@ -97,7 +98,8 @@  struct options
       read_from_stdin(false),
       read_tu(false),
       diff(false),
-      noout(false)
+      noout(false),
+      annotate(false)
 #ifdef WITH_CTF
     ,
       use_ctf(false)
@@ -493,6 +495,7 @@  display_usage(const string& prog_name, ostream& out)
     << "  --diff  for xml inputs, perform a text diff between "
     "the input and the memory model saved back to disk\n"
     << "  --noout  do not display anything on stdout\n"
+    << "  --annotate  annotate the ABI artifacts emitted in the output\n"
     << "  --stdin  read abi-file content from stdin\n"
     << "  --tu  expect a single translation unit file\n"
 #ifdef WITH_CTF
@@ -583,6 +586,8 @@  parse_command_line(int argc, char* argv[], options& opts)
 	  opts.diff = true;
 	else if (!strcmp(argv[i], "--noout"))
 	  opts.noout = true;
+	else if (!strcmp(argv[i], "--annotate"))
+	  opts.annotate = true;
 #ifdef WITH_SHOW_TYPE_USE_IN_ABILINT
       else if (!strcmp(argv[i], "--show-type-use"))
 	{
@@ -723,6 +728,7 @@  main(int argc, char* argv[])
 	    {
 	      const write_context_sptr& ctxt
 		  = create_write_context(env, cout);
+	      set_annotate(*ctxt, opts.annotate);
 	      write_translation_unit(*ctxt, *tu, 0);
 	    }
 	  return 0;
@@ -739,6 +745,7 @@  main(int argc, char* argv[])
 	    {
 	      const write_context_sptr& ctxt
 		  = create_write_context(env, cout);
+	      set_annotate(*ctxt, opts.annotate);
 	      write_corpus(*ctxt, corp, /*indent=*/0);
 	    }
 	  return 0;
@@ -879,6 +886,7 @@  main(int argc, char* argv[])
 	    {
 	      if (!opts.noout)
 		{
+		  set_annotate(*ctxt, opts.annotate);
 		  if (corp)
 		    is_ok = write_corpus(*ctxt, corp, 0);
 		  else if (group)