rev 52889 : 8214023: Update Graal

   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.core.common.util;
  26 
  27 /**
  28  * Provides low-level sequential write access for signed and unsigned values of size 1, 2, 4, and 8
  29  * bytes.
  30  */
  31 public interface TypeWriter {
  32 
  33     /**
  34      * Returns the number of bytes that have been written, i.e., the byte index of the next byte to
  35      * be written.
  36      */
  37     long getBytesWritten();
  38 
  39     /** Writes a signed 1 byte value. */
  40     void putS1(long value);
  41 
  42     /** Writes an unsigned 1 byte value. */
  43     void putU1(long value);
  44 
  45     /** Writes a signed 2 byte value. */
  46     void putS2(long value);
  47 
  48     /** Writes an unsigned 2 byte value. */
  49     void putU2(long value);
  50 
  51     /** Writes a signed 4 byte value. */
  52     void putS4(long value);
  53 
  54     /** Writes an unsigned 4 byte value. */
  55     void putU4(long value);
  56 
  57     /** Writes a signed 8 byte value. */
  58     void putS8(long value);
  59 
  60     /**
  61      * Writes a signed value in a variable byte size encoding.
  62      */
  63     default void putSV(long value) {
  64         long cur = value;
  65         while (true) {
  66             if (cur >= -64 && cur < 64) {
  67                 putU1(cur & 0x7f);
  68                 return;
  69             }
  70             putU1(0x80 | (cur & 0x7f));
  71             cur = cur >> 7;
  72         }
  73     }
  74 
  75     /**
  76      * Writes an unsigned value in a variable byte size encoding.
  77      */
  78     default void putUV(long value) {
  79         long cur = value;
  80         while (true) {
  81             assert cur >= 0;
  82             if (cur < 128) {
  83                 putU1(cur & 0x7f);
  84                 return;
  85             }
  86             putU1(0x80 | (cur & 0x7f));
  87             cur = cur >> 7;
  88         }
  89     }
  90 }
--- EOF ---