Make TUI borders respect "set style enabled"
[deliverable/binutils-gdb.git] / opcodes / wasm32-dis.c
index 179a4402ceff66de75bb074a9b1da26c166b19b1..aea93b81c2f3bc76230bdae5610bbf434ecf9bf7 100644 (file)
@@ -1,5 +1,5 @@
 /* Opcode printing code for the WebAssembly target
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   Copyright (C) 2017-2020 Free Software Foundation, Inc.
 
    This file is part of libopcodes.
 
@@ -19,7 +19,7 @@
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
-#include "dis-asm.h"
+#include "disassemble.h"
 #include "opintl.h"
 #include "safe-ctype.h"
 #include "floatformat.h"
@@ -27,7 +27,7 @@
 #include "elf-bfd.h"
 #include "elf/internal.h"
 #include "elf/wasm32.h"
-#include <stdint.h>
+#include "bfd_stdint.h"
 
 /* Type names for blocks and signatures.  */
 #define BLOCK_TYPE_NONE              0x40
@@ -192,29 +192,36 @@ wasm_read_leb128 (bfd_vma                   pc,
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte = 0;
-  bfd_boolean success = FALSE;
+  int status = 1;
 
   while (info->read_memory_func (pc + num_read, &byte, 1, info) == 0)
     {
       num_read++;
 
-      result |= ((bfd_vma) (byte & 0x7f)) << shift;
+      if (shift < sizeof (result) * 8)
+       {
+         result |= ((uint64_t) (byte & 0x7f)) << shift;
+         if ((result >> shift) != (byte & 0x7f))
+           /* Overflow.  */
+           status |= 2;
+         shift += 7;
+       }
+      else if ((byte & 0x7f) != 0)
+       status |= 2;
 
-      shift += 7;
       if ((byte & 0x80) == 0)
-        {
-          success = TRUE;
-          break;
-        }
+       {
+         status &= ~1;
+         if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
+           result |= -((uint64_t) 1 << shift);
+         break;
+       }
     }
 
   if (length_return != NULL)
     *length_return = num_read;
   if (error_return != NULL)
-    *error_return = ! success;
-
-  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
-    result |= -((uint64_t) 1 << shift);
+    *error_return = status != 0;
 
   return result;
 }
@@ -269,7 +276,7 @@ print_insn_wasm32 (bfd_vma pc, struct disassemble_info *info)
   long flags = 0;
   long offset = 0;
   long depth = 0;
-  long index = 0;
+  long function_index = 0;
   long target_count = 0;
   long block_type = 0;
   int len = 1;
@@ -416,14 +423,14 @@ print_insn_wasm32 (bfd_vma pc, struct disassemble_info *info)
           break;
 
         case wasm_call:
-          index = wasm_read_leb128
+          function_index = wasm_read_leb128
             (pc + len, info, &error, &bytes_read, FALSE);
           if (error)
             return -1;
           len += bytes_read;
           prin (stream, " ");
           private_data->section_prefix = ".space.function_index";
-          (*info->print_address_func) ((bfd_vma) index, info);
+          (*info->print_address_func) ((bfd_vma) function_index, info);
           private_data->section_prefix = NULL;
           break;
 
This page took 0.026762 seconds and 4 git commands to generate.