|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbyucc.jhdl.util.BVFormat.BVFormat
This class is used to convert BVs into formatted strings for display purposes. The class can split a BV into several fields and display each field in its own radix. Specifiers for different radices are as follows:
%[width]{type}[extras]{bit specification}An explanation of the parts of a field specification is given below:
(classname,methodname)The BVFormat class will use reflection to find the class and static method passed as parameters. The method must be static and accept a single BV as its parameter and return a String (ie. public static String methodname(BV field);). The BVFormat class will strip the specified range from the complete BV and pass this to the static method. The method will return the String to display. This type of field can be used to display state names for a state machine, etc.
Here are some example field formats:
%8d[15:8] - diplays bits 15 through 8 as a signed decimal number. The resulting String will be at least 8 characters long.
%u[7:4.3:0] - diplays a 4.4 fixed point number as in unsigned decimal. Bits 7 to 4 represent the whole part and bits 3 to 0 represent the fractional part.
%10c(StateMachine,StateNames)[4:0] - Passes bits 4 through 0 to the static method StateNames in the class StateMachine. The BVFormat class will add spaces as necessary to ensure that the resulting String is at least 10 characters in length.
%b[12] - diplays bit 12 as a binary number.
It is also possible to add arbitrary text to the format string (excluding the '%' character, as this is used to denote the start of a field specification). The characters will be added to the format string exactly as they are entered. For example, the first two examples above could be combined into the following format string:
a: %8d[15:8] b: %u[7:4.3:0]If passed a BV with the following binary value 0011010100110101, the above format would be displayed as:
a: 53 b: 3.3125
Field Summary | |
static BVFormat |
BINARY
|
static BVFormat |
HEXADECIMAL
|
static BVFormat |
SIGNED_DECIMAL
|
static BVFormat |
UNSIGNED_DECIMAL
|
Constructor Summary | |
BVFormat(int width,
java.lang.String format)
Constructs a new BVFormat object with the given format. |
Method Summary | |
java.lang.String |
formatBV(BV number)
Method takes a BV and returns a string according to the current format specified. |
static java.lang.String |
formatBV(java.lang.String format,
BV number)
Method takes a BV and a format specifier and formats the BV according to the specifier. |
static void |
main(java.lang.String[] args)
Main method is used to test the BVFormat class. |
void |
setFormat(java.lang.String format)
Method used to change the format for a given instance of a BVFormat object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final BVFormat HEXADECIMAL
public static final BVFormat SIGNED_DECIMAL
public static final BVFormat UNSIGNED_DECIMAL
public static final BVFormat BINARY
Constructor Detail |
public BVFormat(int width, java.lang.String format) throws BVFormatException
width
- Width of BVs that will be passed to this object. Passing a negative number
for this parameter will cause the class to attempt to format all BVs passed to the fieldFormat()
method, regardless of width. Please note: This may result in an ArrayIndexOutOfBoundsException which
will not be caught.format
- String representing the format to use for this BVFormat object.
BVFormatException
- Throws a BVFormatException if the format string is not valid.Method Detail |
public void setFormat(java.lang.String format) throws BVFormatException
format
- String representing the format to use for this BVFormat object.
BVFormatException
- Throws a BVFormatException if the format string is not valid.
java.lang.IllegalArgumentException
- if one of this classes' constants are changed.public java.lang.String formatBV(BV number) throws BVFormatException
number
- BV to be formatted.
BVFormatException
- If width checking is enabled, throws a BVFormatException
if the BV does not have the proper width.public static java.lang.String formatBV(java.lang.String format, BV number) throws BVFormatException
format
- Format to use.number
- BV to be formatted.
BVFormatException
- If width checking is enabled, throws a BVFormatException
if the BV does not have the proper width.public static void main(java.lang.String[] args)
args
- Command line arguments. First argument is the format string
all other arguments are binary representations of the BitVectors to test.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |