Add recording support for the ISA 3.1 PowerPC instructions.
[binutils-gdb.git] / include / dis-asm.h
index 0b91ab47ff3865633815de715d3d4930eb8a74bd..4f91df1249852f2c6277af33f44a72f92b8b3f98 100644 (file)
@@ -1,6 +1,6 @@
 /* Interface between the opcode library and its callers.
 
-   Copyright (C) 1999-2021 Free Software Foundation, Inc.
+   Copyright (C) 1999-2022 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -35,8 +35,6 @@ extern "C" {
 #include <string.h>
 #include "bfd.h"
 
-  typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;
-
 enum dis_insn_type
 {
   dis_noninsn,                 /* Not a valid instruction.  */
@@ -49,6 +47,76 @@ enum dis_insn_type
   dis_dref2                    /* Two data references in instruction.  */
 };
 
+/* When printing styled disassembler output, this describes what style
+   should be used.  */
+
+enum disassembler_style
+{
+  /* This is the default style, use this for any additional syntax
+     (e.g. commas between operands, brackets, etc), or just as a default if
+     no other style seems appropriate.  */
+  dis_style_text,
+
+  /* Use this for all instruction mnemonics, or aliases for mnemonics.
+     These should be things that correspond to real machine
+     instructions.  */
+  dis_style_mnemonic,
+
+  /* For things that aren't real machine instructions, but rather
+     assembler directives, e.g. .byte, etc.  */
+  dis_style_assembler_directive,
+
+  /* Use this for any register names.  This may or may-not include any
+     register prefix, e.g. '$', '%', at the discretion of the target,
+     though within each target the choice to include prefixes for not
+     should be kept consistent.  If the prefix is not printed with this
+     style, then dis_style_text should be used.  */
+  dis_style_register,
+
+  /* Use this for any constant values used within instructions or
+     directives, unless the value is an absolute address, or an offset
+     that will be added to an address (no matter where the address comes
+     from) before use.  This style may, or may-not be used for any
+     prefix to the immediate value, e.g. '$', at the discretion of the
+     target, though within each target the choice to include these
+     prefixes should be kept consistent.  */
+  dis_style_immediate,
+
+  /* The style for the numerical representation of an absolute address.
+     Anything that is an address offset should use the immediate style.
+     This style may, or may-not be used for any prefix to the immediate
+     value, e.g. '$', at the discretion of the target, though within
+     each target the choice to include these prefixes should be kept
+     consistent.  */
+  dis_style_address,
+
+  /* The style for any constant value within an instruction or directive
+     that represents an offset that will be added to an address before
+     use.  This style may, or may-not be used for any prefix to the
+     immediate value, e.g. '$', at the discretion of the target, though
+     within each target the choice to include these prefixes should be
+     kept consistent.  */
+  dis_style_address_offset,
+
+  /* The style for a symbol's name.  The numerical address of a symbol
+     should use the address style above, this style is reserved for the
+     name.  */
+  dis_style_symbol,
+
+  /* The start of a comment that runs to the end of the line.  Anything
+     printed after a comment start might be styled differently,
+     e.g. everything might be styled as a comment, regardless of the
+     actual style used.  The disassembler itself should not try to adjust
+     the style emitted for comment content, e.g. an address emitted within
+     a comment should still be given dis_style_address, in this way it is
+     up to the user of the disassembler to decide how comments should be
+     styled.  */
+  dis_style_comment_start
+};
+
+typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;
+typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...) ATTRIBUTE_FPTR_PRINTF_3;
+
 /* This struct is passed into the instruction decoding routine,
    and is passed back out into each callback.  The various fields are used
    for conveying information from your main routine into your callbacks,
@@ -62,6 +130,7 @@ enum dis_insn_type
 typedef struct disassemble_info
 {
   fprintf_ftype fprintf_func;
+  fprintf_styled_ftype fprintf_styled_func;
   void *stream;
   void *application_data;
 
@@ -228,6 +297,9 @@ typedef struct disassemble_info
      disassembling such as the way mapping symbols are found on AArch64.  */
   bfd_vma stop_offset;
 
+  /* Set to true if the disassembler applied styling to the output,
+     otherwise, set to false.  */
+  bool created_styled_output;
 } disassemble_info;
 
 /* This struct is used to pass information about valid disassembler
@@ -307,6 +379,7 @@ extern void print_arm_disassembler_options (FILE *);
 extern void print_arc_disassembler_options (FILE *);
 extern void print_s390_disassembler_options (FILE *);
 extern void print_wasm32_disassembler_options (FILE *);
+extern void print_loongarch_disassembler_options (FILE *);
 extern bool aarch64_symbol_is_valid (asymbol *, struct disassemble_info *);
 extern bool arm_symbol_is_valid (asymbol *, struct disassemble_info *);
 extern bool csky_symbol_is_valid (asymbol *, struct disassemble_info *);
@@ -319,6 +392,7 @@ extern const disasm_options_and_args_t *disassembler_options_arc (void);
 extern const disasm_options_and_args_t *disassembler_options_arm (void);
 extern const disasm_options_and_args_t *disassembler_options_mips (void);
 extern const disasm_options_and_args_t *disassembler_options_powerpc (void);
+extern const disasm_options_and_args_t *disassembler_options_riscv (void);
 extern const disasm_options_and_args_t *disassembler_options_s390 (void);
 
 /* Fetch the disassembler for a given architecture ARC, endianess (big
@@ -335,6 +409,10 @@ extern void disassemble_init_for_target (struct disassemble_info *);
 /* Tidy any memory allocated by targets, such as info->private_data.  */
 extern void disassemble_free_target (struct disassemble_info *);
 
+/* Set the basic disassembler print functions.  */
+extern void disassemble_set_printf (struct disassemble_info *, void *,
+                                   fprintf_ftype, fprintf_styled_ftype);
+
 /* Document any target specific options available from the disassembler.  */
 extern void disassembler_usage (FILE *);
 
@@ -392,11 +470,13 @@ extern bool generic_symbol_is_valid
 /* Method to initialize a disassemble_info struct.  This should be
    called by all applications creating such a struct.  */
 extern void init_disassemble_info (struct disassemble_info *dinfo, void *stream,
-                                  fprintf_ftype fprintf_func);
+                                  fprintf_ftype fprintf_func,
+                                  fprintf_styled_ftype fprintf_styled_func);
 
 /* For compatibility with existing code.  */
-#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
-  init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
+#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC, FPRINTF_STYLED_FUNC)  \
+  init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC), \
+                        (fprintf_styled_ftype) (FPRINTF_STYLED_FUNC))
 
 #ifdef __cplusplus
 }