ROSE 0.11.145.192
|
Describes a pattern of bits in a finite number of words.
A BitPattern is a set of one or more alternative values for certain significant bits in a finite sequence of words. The words have type T
and are numbered starting at zero. The bits are numbered independently in each word so that the least significant bit of a word is bit number zero.
A BitPattern matches a sequence of value words if, for each pattern word that has significant bits, the value of those bits matches the corresponding bits in the value words. A BitPattern that has no significant bits matches all sequences of value words.
A BitPattern may have multiple sets of pattern words that serve as alternative values to match. A BitPattern will match a sequence of value words if any of the pattern word sets match. All pattern word sets use the same significant bits.
Here are examples of creating a BitPattern for a single 32-bit word where the high order byte must be the value 0x33 and the low-order byte must be the value 0x66.
The following example uses the same pattern, but treats the input as four separate 8-bit values:
Matching these patterns against actual data proceeds like follows. Since the 32-bit word pattern has only one word, we can use the more convenient match_word() method. On the other hand, we need to supply four words at a time for the 8-bit word pattern.
Definition at line 56 of file BitPattern.h.
#include <frontend/Disassemblers/BitPattern.h>
Public Member Functions | |
BitPattern () | |
Creates a new, empty bit pattern. | |
BitPattern (T msk, T pat, size_t wordnum) | |
Creates a new bit pattern for a single word using a mask and value. | |
BitPattern (size_t lo_bit, size_t hi_bit, T pat, size_t wordnum) | |
Create a new bit pattern for a single word using bit offsets. | |
bool | is_consistent () const |
Verify internal consistency. | |
size_t | nsignificant () const |
Returns the number of significant bits. | |
size_t | nwords () const |
Returns the number of words in the pattern. | |
size_t | width () const |
Returns the size of the pattern in bits. | |
T | mask (size_t wordnum) |
Returns the mask for the specified word. | |
std::pair< T, T > | invariants (T msk, size_t wordnum) |
Returns invariant bits. | |
size_t | nalternatives () const |
Returns the number of alternatives. | |
T | conflict (T msk, T pat, size_t wordnum, size_t altnum) const |
Determines if the specified bits conflict with a particular pattern alternative. | |
T | conflict (T msk, T pat, size_t wordnum) const |
Determines if the specified significant bits conflict with any of the existing pattern alternatives. | |
void | check_insertion (T msk, T pat, size_t wordnum) const |
Check that a pattern insertion does not conflict with an existing pattern. | |
bool | any_same (const BitPattern &other, std::pair< size_t, size_t > *alternatives=NULL) const |
Determines whether two patterns can match the same input. | |
BitPattern & | insert (T msk, T pat, size_t wordnum=0) |
Creates a new pattern by adding significant bits to all alternatives of a pattern. | |
BitPattern & | bits (size_t lo_bit, size_t hi_bit, T value, size_t wordnum) |
Adds significant bits to all alternatives of a pattern. | |
BitPattern | shift_left (size_t nbits) const |
Return a new BitPattern with the pattern bits shifted left by the indicated amount. | |
BitPattern & | conjunction (const BitPattern &other) |
Combines this BitPattern with another by forming their conjunction. | |
BitPattern & | disjunction (const BitPattern &other) |
Combines this BitPattern with another by forming their disjunction. | |
bool | matches_word (T value, size_t wordnum) const |
Returns true if one word of this pattern matches the specified value. | |
void | print (std::ostream &o, size_t altnum, bool with_mask=true) const |
Print one pattern alternative. | |
void | print (std::ostream &o) const |
Print all alternatives of the pattern. | |
BitPattern | operator& (const BitPattern &other) const |
Creates a new BitPattern that is the conjunction of two bit patterns. | |
BitPattern & | operator&= (const BitPattern &other) |
Creates a new BitPattern that is the conjunction of two bit patterns. | |
BitPattern | operator| (const BitPattern &other) const |
Creates a new BitPattern that is the inclusive disjunction of two bit patterns. | |
BitPattern & | operator|= (const BitPattern &other) |
Creates a new BitPattern that is the inclusive disjunction of two bit patterns. | |
bool | matches (const std::vector< T > value_words) const |
Returns true if this pattern matches the specified values. | |
bool | matches (const T *value_words, size_t sz) const |
Returns true if this pattern matches the specified values. | |
|
inline |
Creates a new, empty bit pattern.
An empty pattern matches all values.
Definition at line 64 of file BitPattern.h.
|
inline |
Creates a new bit pattern for a single word using a mask and value.
The pattern is bit-wise AND'd with the mask, and none of its other bits should be set.
Definition at line 68 of file BitPattern.h.
References Rose::BitPattern< T >::insert().
|
inline |
Create a new bit pattern for a single word using bit offsets.
The pattern is left shifted into the specified bits, and none of its higher order bits should be set. The range of significant bits is from lo_bit
through hi_bit
, inclusive.
Definition at line 75 of file BitPattern.h.
References Rose::BitPattern< T >::bits().
|
inline |
Verify internal consistency.
This is asserted at the beginning and end of methods that modify a bit pattern.
Definition at line 80 of file BitPattern.h.
References Rose::BitPattern< T >::print().
Referenced by Rose::BitPattern< T >::conjunction(), Rose::BitPattern< T >::disjunction(), Rose::BitPattern< T >::insert(), and Rose::BitPattern< T >::shift_left().
|
inline |
Returns the number of significant bits.
Returns zero if the pattern is empty.
Definition at line 97 of file BitPattern.h.
References IntegerOps::countSet().
|
inline |
Returns the number of words in the pattern.
Although the final word of the pattern will have at least one significant bit, the previous pattern words might not be significant.
Definition at line 106 of file BitPattern.h.
Referenced by Rose::BitPattern< T >::any_same(), Rose::BitPattern< T >::conjunction(), Rose::BitPattern< T >::disjunction(), Rose::BitPattern< T >::matches(), Rose::BitPattern< T >::matches_word(), Rose::BitPattern< T >::print(), and Rose::BitPattern< T >::print().
|
inline |
Returns the size of the pattern in bits.
If the pattern has no significant bits, then zero is returned. Otherwise the return value is the one-origin position of the most significant bit of the pattern mask.
Definition at line 112 of file BitPattern.h.
References IntegerOps::msb_set().
Referenced by Rose::BitPattern< T >::shift_left().
|
inline |
Returns the mask for the specified word.
The mask determines which bits the pattern cares about.
Definition at line 120 of file BitPattern.h.
|
inline |
Returns invariant bits.
Given a set of of bits and a word number, this method returns values for bits that must be set or cleared and a mask indicating which bits are invariant. For instance, if a pattern's alternatives all require that bits at positions 24 (inclusive) to 32 (exclusive) have the value 0xbe, don't care about bits at positions 8 to 24, and each alternative is different in bits 0-8, then the return value wil be the value 0xbe000000 (first member of the returned pair) and mask 0xff000000 (second member of the pair).
Definition at line 131 of file BitPattern.h.
|
inline |
Returns the number of alternatives.
Returns zero if the pattern is empty.
Definition at line 142 of file BitPattern.h.
Referenced by Rose::BitPattern< T >::any_same(), Rose::BitPattern< T >::conflict(), Rose::BitPattern< T >::conjunction(), Rose::BitPattern< T >::disjunction(), Rose::BitPattern< T >::insert(), Rose::BitPattern< T >::matches(), Rose::BitPattern< T >::matches_word(), Rose::BitPattern< T >::print(), and Rose::BitPattern< T >::print().
|
inline |
Determines if the specified bits conflict with a particular pattern alternative.
If the new pattern (the arguments) conflicts with an existing pattern, then a mask describing the bits in conflict is returned. This function returns zero if there is no conflict with the specified alternative.
Definition at line 149 of file BitPattern.h.
Referenced by Rose::BitPattern< T >::check_insertion(), and Rose::BitPattern< T >::conflict().
|
inline |
Determines if the specified significant bits conflict with any of the existing pattern alternatives.
If the new pattern (the arguments) conflicts with an existing pattern, then a mask describing the bits in conflict is returned. If there is no conflict, then this function returns zero.
Definition at line 163 of file BitPattern.h.
References Rose::BitPattern< T >::conflict(), and Rose::BitPattern< T >::nalternatives().
|
inline |
Check that a pattern insertion does not conflict with an existing pattern.
If a conflict is present, print information about the conflict to stderr and abort.
Definition at line 175 of file BitPattern.h.
References Rose::StringUtility::addrToString(), Rose::BitPattern< T >::conflict(), and Rose::BitPattern< T >::print().
Referenced by Rose::BitPattern< T >::conjunction(), and Rose::BitPattern< T >::insert().
|
inline |
Determines whether two patterns can match the same input.
Returns true if this pattern can match at least one of the same input values as the other
BitPattern.
Definition at line 191 of file BitPattern.h.
References Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
|
inline |
Creates a new pattern by adding significant bits to all alternatives of a pattern.
The msk
and pat
are a mask and bits for the specified word.
Definition at line 215 of file BitPattern.h.
References Rose::BitPattern< T >::check_insertion(), Rose::BitPattern< T >::is_consistent(), and Rose::BitPattern< T >::nalternatives().
Referenced by Rose::BitPattern< T >::BitPattern(), and Rose::BitPattern< T >::bits().
|
inline |
Adds significant bits to all alternatives of a pattern.
The pattern is over the inclusive range of bits for the specified word. E.g., when called as "bits(8,11,0xc,1)", the pattern will match where bits 8 and 9 of word 1 are clear and bits 10 and 11 of word 1 are set.
Definition at line 242 of file BitPattern.h.
References Rose::BitPattern< T >::insert(), and IntegerOps::shiftLeft2().
Referenced by Rose::BitPattern< T >::BitPattern().
|
inline |
Return a new BitPattern with the pattern bits shifted left by the indicated amount.
Definition at line 249 of file BitPattern.h.
References Rose::BitPattern< T >::is_consistent(), IntegerOps::shiftLeft2(), IntegerOps::shiftRightLogical2(), and Rose::BitPattern< T >::width().
|
inline |
Combines this BitPattern with another by forming their conjunction.
After this operation, this BitPattern will match values where both original patterns matched the value. The two original bit patterns need not have the same mask; in fact, it's most useful when their masks don't overlap. Either (or both) original patterns can have multiple alternatives; the number of alternatives in the result will be on the order of the product of the number of alternatives in the originals.
Definition at line 288 of file BitPattern.h.
References Rose::BitPattern< T >::check_insertion(), Rose::BitPattern< T >::is_consistent(), Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
Referenced by Rose::BitPattern< T >::operator&(), and Rose::BitPattern< T >::operator&=().
|
inline |
Combines this BitPattern with another by forming their disjunction.
After the operation, this BitPattern will match values where either of the original patterns matched. The two original bit patterns (and thus the result) must have the same set of significant bits.
Definition at line 334 of file BitPattern.h.
References Rose::BitPattern< T >::is_consistent(), Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
Referenced by Rose::BitPattern< T >::operator|(), and Rose::BitPattern< T >::operator|=().
|
inline |
Creates a new BitPattern that is the conjunction of two bit patterns.
The new pattern matches wherever both of the original patterns matched.
Definition at line 364 of file BitPattern.h.
References Rose::BitPattern< T >::conjunction().
|
inline |
Creates a new BitPattern that is the conjunction of two bit patterns.
The new pattern matches wherever both of the original patterns matched.
Definition at line 368 of file BitPattern.h.
References Rose::BitPattern< T >::conjunction().
|
inline |
Creates a new BitPattern that is the inclusive disjunction of two bit patterns.
The new pattern matches wherever either of the original patterns matched.
Definition at line 376 of file BitPattern.h.
References Rose::BitPattern< T >::disjunction().
|
inline |
Creates a new BitPattern that is the inclusive disjunction of two bit patterns.
The new pattern matches wherever either of the original patterns matched.
Definition at line 380 of file BitPattern.h.
References Rose::BitPattern< T >::disjunction().
|
inline |
Returns true if this pattern matches the specified values.
Definition at line 387 of file BitPattern.h.
References Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
Referenced by Rose::BitPattern< T >::matches().
|
inline |
Returns true if this pattern matches the specified values.
Definition at line 401 of file BitPattern.h.
References Rose::BitPattern< T >::matches().
|
inline |
Returns true if one word of this pattern matches the specified value.
Definition at line 410 of file BitPattern.h.
References Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
|
inline |
Print one pattern alternative.
Definition at line 421 of file BitPattern.h.
References Rose::StringUtility::addrToString(), Rose::BitPattern< T >::nalternatives(), and Rose::BitPattern< T >::nwords().
Referenced by Rose::BitPattern< T >::check_insertion(), Rose::BitPattern< T >::is_consistent(), and Rose::BitPattern< T >::print().
|
inline |
Print all alternatives of the pattern.
Definition at line 433 of file BitPattern.h.
References Rose::StringUtility::addrToString(), Rose::BitPattern< T >::nalternatives(), Rose::BitPattern< T >::nwords(), and Rose::BitPattern< T >::print().