Class IntegerValue

java.lang.Object
svm.value.Value
svm.value.IntegerValue

public class IntegerValue extends Value

IntegerValue.

integer_value ::= c-int integer_literal:string

character_value ::= c-char byte

size_value
	::= c-size type
	::= NOSIZE

attribute_address	::= c-aaddr attribute:tag


An integer literal is a string:

	< <radix> R>? <sign>? <digit>+

where digit is one of the (ISO coded) decimal digits, and sign may be + or -. The letter R, if included,
signals that the integer is specified with a radix preceding R. The only legal radices are 2, 4, 8 and 16.
If the radix is 16, <digit> may also be one of the (ISO-coded) letters A-F, with the obvious meaning.

Note that an integer literal may not contain spaces.

Link to GitHub: Source File.

Author:
S-Port: Definition of S-code, Øystein Myhre Andersen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The int value

    Fields inherited from class Value

    type
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Default Constructor
    private
    IntegerValue(Type type, int value)
    Construct a new IntegerValue
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Value other)
    Returns the result of: this value + other value
    and(Value other)
    Returns the result of: this value and other value
    boolean
    compare(int relation, Value other)
    Compare this Value with the given Value according to the given relation.
    div(Value other)
    Returns the result of: this value / other value
    void
    Add this value to the given DataSegment
    static int
    Returns the int value of the given IntegerValue
    mult(Value other)
    Returns the result of: this value * other value
    neg()
    Returns the negative value of this Value object.
    of(Type type, int value)
    Create a new IntegerValue with the given parameters
    Scans the remaining S-Code belonging to this character_value.
    Scans the remaining S-Code belonging to this integer_value.
    Scans the remaining S-Code belonging to this size_value.
    Scans the remaining S-Code belonging to this attribute_address.
    or(Value other)
    Returns the result of: this value or other value
    Reads a IntegerValue from the given input.
    rem(Value other)
    Returns the result of: this value rem other value
    shift(int instr, Value other)
    Returns the result of: this value shiftInstr other value S_LSHIFTA: Signed Left Shift << The left shift operator moves all bits by a given number of bits to the left. S_LSHIFTL: Unsigned Left Shift << The left shift operator moves all bits by a given number of bits to the left. S_RSHIFTA: Signed Right Shift >> The right shift operator moves all bits by a given number of bits to the right.
    sub(Value other)
    Returns the result of: this value - other value
    double
    Returns the double value of this Value object.
    float
    Returns the float value of this Value object.
     
    void
    Writes this Value to the given output.
    xor(Value other)
    Returns the result of: this value xor other value

    Methods inherited from class Value

    copy, eqv, imp, print, read

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • value

      public int value
      The int value
  • Constructor Details

    • IntegerValue

      public IntegerValue()
      Default Constructor
    • IntegerValue

      private IntegerValue(Type type, int value)
      Construct a new IntegerValue
      Parameters:
      type - the s-type: INT, CHAR, SIZE, AADDR
      value - the int value
  • Method Details

    • of

      public static IntegerValue of(Type type, int value)
      Create a new IntegerValue with the given parameters
      Parameters:
      type - the s-type: INT, CHAR, SIZE, AADDR
      value - the int value
      Returns:
      an IntegerValue or null
    • ofScode_INT

      public static IntegerValue ofScode_INT()
      Scans the remaining S-Code belonging to this integer_value. Then construct a new IntegerValue with type INT.
      Returns:
      that IntegerValue instance.
    • ofScode_CHAR

      public static IntegerValue ofScode_CHAR()
      Scans the remaining S-Code belonging to this character_value. Then construct a new IntegerValue with type CHAR.
      Returns:
      that IntegerValue instance.
    • ofScode_SIZE

      public static IntegerValue ofScode_SIZE()
      Scans the remaining S-Code belonging to this size_value. Then construct a new IntegerValue with type SIZE.
      Returns:
      that IntegerValue instance.
    • ofScode_AADDR

      public static IntegerValue ofScode_AADDR()
      Scans the remaining S-Code belonging to this attribute_address. Then construct a new IntegerValue with type AADDR.
      Returns:
      that IntegerValue instance.
    • intValue

      public static int intValue(IntegerValue val)
      Returns the int value of the given IntegerValue
      Parameters:
      val - the IntegerValue
      Returns:
      the int value of the given IntegerValue
    • emit

      public void emit(DataSegment dseg)
      Description copied from class: Value
      Add this value to the given DataSegment
      Overrides:
      emit in class Value
      Parameters:
      dseg - the DataSegment
    • toFloat

      public float toFloat()
      Description copied from class: Value
      Returns the float value of this Value object.
      Overrides:
      toFloat in class Value
      Returns:
      the float value of this Value object.
    • toDouble

      public double toDouble()
      Description copied from class: Value
      Returns the double value of this Value object.
      Overrides:
      toDouble in class Value
      Returns:
      the double value of this Value object.
    • neg

      public Value neg()
      Description copied from class: Value
      Returns the negative value of this Value object.
      Overrides:
      neg in class Value
      Returns:
      the negative value of this Value object.
    • add

      public Value add(Value other)
      Description copied from class: Value
      Returns the result of: this value + other value
      Overrides:
      add in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value + other value
    • sub

      public Value sub(Value other)
      Description copied from class: Value
      Returns the result of: this value - other value
      Overrides:
      sub in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value - other value
    • mult

      public Value mult(Value other)
      Description copied from class: Value
      Returns the result of: this value * other value
      Overrides:
      mult in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value * other value
    • div

      public Value div(Value other)
      Description copied from class: Value
      Returns the result of: this value / other value
      Overrides:
      div in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value / other value
    • rem

      public Value rem(Value other)
      Description copied from class: Value
      Returns the result of: this value rem other value
      Overrides:
      rem in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value rem other value
    • and

      public Value and(Value other)
      Description copied from class: Value
      Returns the result of: this value and other value
      Overrides:
      and in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value and other value
    • or

      public Value or(Value other)
      Description copied from class: Value
      Returns the result of: this value or other value
      Overrides:
      or in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value or other value
    • xor

      public Value xor(Value other)
      Description copied from class: Value
      Returns the result of: this value xor other value
      Overrides:
      xor in class Value
      Parameters:
      other - the other value
      Returns:
      the result of: this value xor other value
    • compare

      public boolean compare(int relation, Value other)
      Description copied from class: Value
      Compare this Value with the given Value according to the given relation.
      Overrides:
      compare in class Value
      Parameters:
      relation - one of: LT, LE, EQ, GE, GT, NE
      other - the other Value
      Returns:
      true: if the relation holds
    • shift

      public Value shift(int instr, Value other)
      Description copied from class: Value
      Returns the result of: this value shiftInstr other value S_LSHIFTA: Signed Left Shift << The left shift operator moves all bits by a given number of bits to the left. S_LSHIFTL: Unsigned Left Shift << The left shift operator moves all bits by a given number of bits to the left. S_RSHIFTA: Signed Right Shift >> The right shift operator moves all bits by a given number of bits to the right. S_RSHIFTL: Unsigned Right Shift >>> It is the same as the signed right shift, but the vacant leftmost position is filled with 0 instead of the sign bit.
      Overrides:
      shift in class Value
      Parameters:
      instr - the actual shift instruction
      other - the other value
      Returns:
      the result of: this value shiftInstr other value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • write

      public void write(AttributeOutputStream oupt) throws IOException
      Description copied from class: Value
      Writes this Value to the given output.
      Overrides:
      write in class Value
      Parameters:
      oupt - the output stream
      Throws:
      IOException - if IOException occur
    • read

      public static IntegerValue read(AttributeInputStream inpt) throws IOException
      Reads a IntegerValue from the given input.
      Parameters:
      inpt - the AttributeInputStream
      Returns:
      the IntegerValue read
      Throws:
      IOException - if IOException occur