new OperandParser(tokenStream, symbols)
A parser for MIPS operands
Parameters:
Name | Type | Description |
---|---|---|
tokenStream |
Parser.TokenStream | The stream of tokens to parse |
symbols |
array | An array of pre-defined symbols |
- Source:
Methods
parseConstant(bits) → {number}
Parse a constant expression
Parses a constant expression and checks whether its value is representable as either an
unsigned or a two's complement integer with the given number of bits.
Parameters:
Name | Type | Description |
---|---|---|
bits |
number | The number of bits available for the number |
- Source:
Throws:
-
The value must be representable as an unsigned or two's complement integer with the given number of bits
- Type
- Parser.ParseError
Returns:
The value of the constant
- Type
- number
parseLabel() → {string}
Parse a label
A label is a simple identifier.
- Source:
Throws:
-
The input must start with a label
- Type
- Parser.ParseError
Returns:
The name of the label
- Type
- string
parseLoadStoreAddress(bits) → {Object}
Parse an address for loading or storing.
A load/store-address consists of an (optional) signed offset and a register in parentheses (`imm($rs)`).
Parameters:
Name | Type | Description |
---|---|---|
bits |
number | The number of bits allowed for the offset |
- Source:
Returns:
A dictionary containing the offset in key `imm` and the register name in key `$rs`.
- Type
- Object
parseRegister() → {string}
Parse a register operand
- Source:
Throws:
-
The input must start with a register
- Type
- Parser.ParseError
Returns:
The name of the register
- Type
- string
parseSignedConstant(bits) → {number}
Parse a signed constant expression
Parses a constant expression and checks whether its value is representable as a
two's-complement integer with the given number of bits.
Parameters:
Name | Type | Description |
---|---|---|
bits |
number | The number of bits available (including sign bit) for the number |
- Source:
Throws:
-
The value must be representable as a two's-complement integer with the given number of bits
- Type
- Parser.ParseError
Returns:
The value of the constant
- Type
- number
parseUnsignedConstant(bits) → {number}
Parse an unsigned constant expression
Parses a constant expression and checks whether its value is representable as an
unsigned integer with the given number of bits.
Parameters:
Name | Type | Description |
---|---|---|
bits |
number | The number of bits available for the number |
- Source:
Throws:
-
The value must be representable as an unsigned integer with the given number of bits
- Type
- Parser.ParseError
Returns:
The value of the constant
- Type
- number
parseWritableRegister() → {string}
Parse a writable register operand
Like Parser.OperandParser.parseRegister, but the register must be writable.
- Source:
Throws:
-
The input must start with a writable register
- Type
- Parser.ParseError
Returns:
The name of the register
- Type
- string