|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectat.dms.util.Utils
public abstract class Utils
This class defines severals utilities methods used in source code
Field Summary | |
---|---|
static LinkedList<SIRStream> |
EMPTY_LIST
|
static boolean |
getForLoopCallers
Set to true to get a stack trace of callers inserted as a comment. |
Constructor Summary | |
---|---|
Utils()
|
Method Summary | ||
---|---|---|
static String |
asPercent(double val)
Returns |
|
static String |
cellMathEquivalent(JExpression prefix,
String ident)
Return the name of a math method for vector processing using IBM's vector headers for the Cell processor (or null if none) |
|
static String |
cMathEquivalent(JExpression prefix,
String ident)
Return the name of a math method for emitting C code |
|
static String |
cppMathEquivalent(JExpression prefix,
String ident)
Return the name of a math method for emitting C++ code |
|
Object |
deepClone()
Returns a deep clone of this object. |
|
protected void |
deepCloneInto(Utils other)
Clones all fields of this into |
|
static boolean |
equalArrays(int[] a1,
int[] a2)
Returns whether or not two integer arrays have the same length and entries |
|
static void |
fail(String str)
Signal a failure with given error message |
|
static String |
getEnvironmentVariable(String var)
Returns value of environment variable named |
|
static JExpression |
getExpression(JStatement orig)
Given a statement, return the expression that this statement is composed of, if not an expression statement return null. |
|
static boolean |
hasPeeks(SIRCodeUnit filter)
Asks the question "Is a peek present in this unit of code?". |
|
static int[] |
initArray(int n,
int val)
Returns a new array of length n with all values set to val |
|
static JExpression[] |
initArray(int n,
JExpression exp)
Returns a new array of length n with all values set to val |
|
static JExpression[] |
initLiteralArray(int n,
int val)
Returns a new array of length n with all values as JIntLiterals set to val |
|
static List<Integer> |
intArrayToList(int[] arr)
Returns a list of Integers containing same elements as |
|
static boolean |
isMathMethod(JExpression prefix,
String ident)
Is the passed method name (broken into prefix and identifier) a Java math method? Limited to those methods that we can emit code for... |
|
static boolean |
isUniform(JExpression[] arr)
Returns whether all elements of an array of JExpressions are JLiterals with the same value. |
|
static void |
kopi_assert(boolean b)
Check if an assertion is valid |
|
static void |
kopi_assert(boolean b,
String str)
Check if an assertion is valid with a given error message |
|
static JStatement |
makeCountdownForLoop(JStatement body,
JExpression count,
JVariableDefinition loopIndex)
Returns a block with a loop counter declaration and a for loop that executes body for count number of times. |
|
static String |
makeDotFileName(String prefix,
SIRStream strName)
Make a name for a dot file from a supplied prefix and the name of the top-level SIRStream. |
|
static JStatement |
makeForLoop(JStatement body,
int count)
Returns a block with a loop counter declaration and a for loop that executes body for count number of times. |
|
static JStatement |
makeForLoop(JStatement body,
JExpression count)
Returns a block with a loop counter declaration and a for loop that executes body for count number of times. |
|
static JStatement |
makeForLoop(JStatement body,
JExpression count,
JVariableDefinition loopIndex)
Returns a block with a loop counter declaration and a for loop that executes body for count number of times. |
|
static JStatement |
makeForLoopFieldIndex(JStatement body,
JVariableDefinition var,
JExpression count)
Returns a for loop that uses field var to count count times with the body of the loop being body. |
|
static JStatement |
makeForLoopLocalIndex(JStatement body,
JVariableDefinition local,
JExpression count)
Returns a for loop that uses local var to count count times with the body of the loop being body. |
|
static int |
nextPow2(int val)
Returns a power of 2 that is greater than or equal to |
|
static JExpression |
passThruParens(JExpression orig)
Return the first non-parentheses expressions contained in |
|
static JStatement |
peelMarkers(JStatement stmt)
If the first and last SIRMarker's in |
|
static boolean |
popBeforePeek(JStatement stmt)
Returns whether or not there are any pop expressions before peek expressions in the dynamic execution of |
|
static StringBuffer |
readFile(String fileName)
Returns the contents of |
|
static JStatement |
removeUnusedPops(JStatement stmt)
Returns a version of |
|
static String |
replaceAll(String orig,
String oldSubStr,
String newSubStr)
/** replaces in all occurances. |
|
static void |
setupDotFileName(int _numSubGraphs)
Record the number of subgraphs for future dot filenames. |
|
static JExpression |
simplifyMathMethod(JMethodCallExpression applyMath)
Simplify an call to a math function with literal arguments. |
|
static String[] |
splitQualifiedName(String name)
Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out" |
|
static String[] |
splitQualifiedName(String name,
char separator)
Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out" |
|
static Object[] |
toArray(Vector vect,
Class type)
Deprecated. |
|
static int[] |
toIntArray(Vector<Integer> vect)
Creates a int array from a vector. |
|
static
|
toVector(T[] array)
Creates a vector and fills it with the elements of the specified array. |
|
static CType |
voidToInt(CType type)
If |
|
static void |
writeFile(String filename,
String str)
Writes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean getForLoopCallers
public static final LinkedList<SIRStream> EMPTY_LIST
Constructor Detail |
---|
public Utils()
Method Detail |
---|
public static final void kopi_assert(boolean b)
RuntimeException
- the entire token referencepublic static final void kopi_assert(boolean b, String str)
RuntimeException
- the entire token referencepublic static final void fail(String str)
RuntimeException
- the entire token referencepublic static StringBuffer readFile(String fileName) throws IOException
fileNameas a string buffer.
IOException
public static void writeFile(String filename, String str) throws IOException
strto
filename, overwriting it if it's already there.
IOException
public static String replaceAll(String orig, String oldSubStr, String newSubStr)
public static JExpression simplifyMathMethod(JMethodCallExpression applyMath)
applyMath
- application of math function to simplify
public static boolean isMathMethod(JExpression prefix, String ident)
prefix
- JExpression that is method name prefixident
- String that is method name
public static String cellMathEquivalent(JExpression prefix, String ident)
prefix
- Prefix portion of the method nameident
- ident portion of the method name.
public static String cMathEquivalent(JExpression prefix, String ident)
prefix
- Prefix portion of the method nameident
- ident portion of the method name.
public static String cppMathEquivalent(JExpression prefix, String ident)
prefix
- Prefix portion of the method nameident
- ident portion of the method name.
public static boolean isUniform(JExpression[] arr)
arr
-
public static String asPercent(double val)
valas a percentage with maximum of 4 digits
public static int nextPow2(int val)
val.
public static List<Integer> intArrayToList(int[] arr)
arr
public static <T> Vector<T> toVector(T[] array)
array
- the array of elementspublic static Object[] toArray(Vector vect, Class type)
vect
- the vector containing the elementstype
- the type of the elementspublic static int[] toIntArray(Vector<Integer> vect)
vect
- the vector containing the elementspublic static int[] initArray(int n, int val)
n
- the desired number of elements in the arrayval
- the value of each elementpublic static JExpression[] initArray(int n, JExpression exp)
n
- the desired number of elements in the arrayexp
- the value of each elementpublic static JExpression[] initLiteralArray(int n, int val)
n
- the desired number of elements in the arrayval
- the value of each elementpublic static boolean equalArrays(int[] a1, int[] a2)
public static JExpression getExpression(JStatement orig)
orig
- The statement
origdoes not contain an expression or the expression if it does.
public static JExpression passThruParens(JExpression orig)
orig
public static String[] splitQualifiedName(String name, char separator)
public static String[] splitQualifiedName(String name)
public static JStatement peelMarkers(JStatement stmt)
stmtmark the beginning and end of the same segment, then move those markers to the outermost edges of
stmt. The purpose of this routine is to lift markers of filter boundaries out of loops.
public static JStatement removeUnusedPops(JStatement stmt)
stmtwith all standalone pops (i.e., pop() as a statement rather than as an expression) removed.
public static boolean popBeforePeek(JStatement stmt)
stmt.
public static JStatement makeForLoop(JStatement body, int count)
public static JStatement makeForLoop(JStatement body, JExpression count)
public static JStatement makeForLoop(JStatement body, JExpression count, JVariableDefinition loopIndex)
public static JStatement makeCountdownForLoop(JStatement body, JExpression count, JVariableDefinition loopIndex)
public static JStatement makeForLoopLocalIndex(JStatement body, JVariableDefinition local, JExpression count)
body
- The body of the for loop. (null OK: returns empty statement)local
- The local to use as the index variable.count
- The trip count of the loop.
public static JStatement makeForLoopFieldIndex(JStatement body, JVariableDefinition var, JExpression count)
body
- The body of the for loop. (null OK: returns empty statement)var
- The field to use as the index variable.count
- The trip count of the loop.
public static CType voidToInt(CType type)
typeis void, then return
inttype; otherwise return
type. This is a hack to get around the disallowance of void arrays in C--should fix this better post-asplos.
public static String getEnvironmentVariable(String var)
var, or null if the variable is undefined.
public static void setupDotFileName(int _numSubGraphs)
public static String makeDotFileName(String prefix, SIRStream strName)
public static boolean hasPeeks(SIRCodeUnit filter)
filter
- Anything that implements SIRCodeUnit so that its methods can be scanned.
public Object deepClone()
deepClone
in interface DeepCloneable
protected void deepCloneInto(Utils other)
other
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |