Class AssemblyNumericTerminal
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol
-
- ghidra.app.plugin.assembler.sleigh.symbol.AssemblyTerminal
-
- ghidra.app.plugin.assembler.sleigh.symbol.AssemblyNumericTerminal
-
- All Implemented Interfaces:
java.lang.Comparable<AssemblySymbol>
- Direct Known Subclasses:
AssemblyFixedNumericTerminal
,AssemblyNumericMapTerminal
public class AssemblyNumericTerminal extends AssemblyTerminal
A terminal that accepts any numeric value or program label The literal may take any form accepted by UNIX strtol() with base=0. By default, the literal is interpreted in base 10, but it may be prefixed such that it's interpreted in an alternative base. With the prefix '0x', it is interpreted in hexadecimal. With the prefix '0', it is interpreted in octal.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bitsize
protected static int
MAX_LABEL_SUGGESTIONS
The maximum number of labels to suggeststatic java.lang.String
PREFIX_HEX
static java.lang.String
PREFIX_OCT
protected static java.util.Collection<java.lang.String>
suggestions
Some suggestions, other than labels, to provide-
Fields inherited from class ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol
name
-
-
Constructor Summary
Constructors Constructor Description AssemblyNumericTerminal(java.lang.String name, int bitsize)
Construct a terminal with the given name, accepting any numeric value or program label
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getBitSize()
java.util.Collection<java.lang.String>
getSuggestions(java.lang.String got, java.util.Map<java.lang.String,java.lang.Long> labels)
Provide a collection of strings that this terminal would have acceptedprotected java.util.Collection<AssemblyParseNumericToken>
makeToken(java.lang.String str, java.lang.String num, int radix, boolean neg, AssemblyGrammar grammar)
Construct a numeric tokenprotected java.util.Collection<AssemblyParseNumericToken>
match(int s, java.lang.String buffer, AssemblyGrammar grammar, java.util.Map<java.lang.String,java.lang.Long> labels)
Try to match a sign-less numeric literal, or a program labelAssemblyParseNumericToken
match(java.lang.String buffer)
This is only a convenience for testing Please use#match(String, AssemblyGrammar, Map
.) java.util.Collection<AssemblyParseNumericToken>
match(java.lang.String buffer, int pos, AssemblyGrammar grammar, java.util.Map<java.lang.String,java.lang.Long> labels)
Attempt to match a token from the input buffer starting at a given positionprotected java.util.Collection<AssemblyParseNumericToken>
matchDec(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a decimal literal, following the optional sign and optional prefixprotected java.util.Collection<AssemblyParseNumericToken>
matchHex(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a hexadecimal literal, following the optional sign and prefixprotected java.util.Collection<AssemblyParseNumericToken>
matchLiteral(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a numeric literal, after the optional sign, encoded in hex, decimal, or octalprotected java.util.Collection<AssemblyParseNumericToken>
matchOct(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match an octal literal, following the optional sign and prefixjava.lang.String
toString()
-
Methods inherited from class ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol
compareTo, equals, getName, hashCode, takesOperandIndex
-
-
-
-
Field Detail
-
PREFIX_HEX
public static final java.lang.String PREFIX_HEX
- See Also:
- Constant Field Values
-
PREFIX_OCT
public static final java.lang.String PREFIX_OCT
- See Also:
- Constant Field Values
-
suggestions
protected static final java.util.Collection<java.lang.String> suggestions
Some suggestions, other than labels, to provide
-
MAX_LABEL_SUGGESTIONS
protected static final int MAX_LABEL_SUGGESTIONS
The maximum number of labels to suggest- See Also:
- Constant Field Values
-
bitsize
protected final int bitsize
-
-
Method Detail
-
toString
public java.lang.String toString()
- Specified by:
toString
in classAssemblySymbol
-
match
public AssemblyParseNumericToken match(java.lang.String buffer)
This is only a convenience for testing Please use#match(String, AssemblyGrammar, Map
.) - Parameters:
buffer
- the input buffer- Returns:
- the parsed token
-
match
public java.util.Collection<AssemblyParseNumericToken> match(java.lang.String buffer, int pos, AssemblyGrammar grammar, java.util.Map<java.lang.String,java.lang.Long> labels)
Description copied from class:AssemblyTerminal
Attempt to match a token from the input buffer starting at a given position- Specified by:
match
in classAssemblyTerminal
- Parameters:
buffer
- the input bufferpos
- the cursor position in the buffergrammar
- the grammar containing this terminallabels
- the program labels, if applicable- Returns:
- the matched token, or null
-
match
protected java.util.Collection<AssemblyParseNumericToken> match(int s, java.lang.String buffer, AssemblyGrammar grammar, java.util.Map<java.lang.String,java.lang.Long> labels)
Try to match a sign-less numeric literal, or a program label- Parameters:
s
- the buffer cursor where the literal or label is expectedbuffer
- the input buffergrammar
- the grammar containing this terminallabels
- the program labels, mapped to their values- Returns:
- the parsed token, or null
-
matchLiteral
protected java.util.Collection<AssemblyParseNumericToken> matchLiteral(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a numeric literal, after the optional sign, encoded in hex, decimal, or octal- Parameters:
s
- buffer cursor where the literal is expectedbuffer
- the input bufferpos
- the start offset of the token parsed so farneg
- true if the the optional-
is presentgrammar
- the grammar containing this terminal- Returns:
- the parsed token, or null
-
makeToken
protected java.util.Collection<AssemblyParseNumericToken> makeToken(java.lang.String str, java.lang.String num, int radix, boolean neg, AssemblyGrammar grammar)
Construct a numeric token- Parameters:
str
- the string value of the token taken verbatim from the buffernum
- portion of the token following the optional sign and prefixradix
- the radix ofnum
neg
- true if the the optional-
is presentgrammar
- the grammar containing this terminal- Returns:
- the parsed token, or null
-
matchHex
protected java.util.Collection<AssemblyParseNumericToken> matchHex(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a hexadecimal literal, following the optional sign and prefix- Parameters:
s
- the buffer cursor where the hex portion startsbuffer
- the input bufferpos
- the start offset of the token parsed so farneg
- true if the the optional-
is presentgrammar
- the grammar containing this terminal- Returns:
- the parsed token, or null
-
matchDec
protected java.util.Collection<AssemblyParseNumericToken> matchDec(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match a decimal literal, following the optional sign and optional prefix- Parameters:
s
- the buffer cursor where the hex portion startsbuffer
- the input bufferpos
- the start offset of the token parsed so farneg
- true if the the optional-
is presentgrammar
- the grammar containing this terminal- Returns:
- the parsed token, or null
-
matchOct
protected java.util.Collection<AssemblyParseNumericToken> matchOct(int s, java.lang.String buffer, int pos, boolean neg, AssemblyGrammar grammar)
Try to match an octal literal, following the optional sign and prefix- Parameters:
s
- the buffer cursor where the hex portion startsbuffer
- the input bufferpos
- the start offset of the token parsed so farneg
- true if the the optional-
is presentgrammar
- the grammar containing this terminal- Returns:
- the parsed token, or null
-
getSuggestions
public java.util.Collection<java.lang.String> getSuggestions(java.lang.String got, java.util.Map<java.lang.String,java.lang.Long> labels)
Description copied from class:AssemblyTerminal
Provide a collection of strings that this terminal would have accepted- Specified by:
getSuggestions
in classAssemblyTerminal
- Parameters:
got
- the remaining contents of the input bufferlabels
- the program labels, if applicable- Returns:
- a, possibly empty, collection of suggestions
-
getBitSize
public int getBitSize()
-
-