at.dms.kjc.common
Class MacroConversion

java.lang.Object
  extended by at.dms.kjc.common.MacroConversion

public class MacroConversion
extends Object

This class converts small functions to macros.


Constructor Summary
MacroConversion()
           
 
Method Summary
static void doConvert(JMethodDeclaration decl, boolean declOnly, CodeGenerator toC)
          Performs conversion of into a macro.
static boolean shouldConvert(JMethodDeclaration decl)
          Returns whether or not can be converted to a MACRO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MacroConversion

public MacroConversion()
Method Detail

shouldConvert

public static boolean shouldConvert(JMethodDeclaration decl)
Returns whether or not can be converted to a MACRO. Currently returns true for functions with the following properties: - The KjcOptions.macro option is enabled. - The only statement in the body of the method is a return statement. - Each parameter to the method is referenced at most once. (Otherwise, parameters with side effects [like pop()] would be replicated). - All the expressions in the return statement are either: 1. JParenthesedExpression 2. JConditionalExpression 3. JBinaryExpressions other than JAssignmentExpressions, i.e.: JBinaryArithmeticExpression, JConditionalAndExpression, JConditionalOrExpression, JEqualityExpression, JRelationalExpression 4. JArrayAccessExpression 5. JFieldAccessExpression 6. JLocalVariableExpression 7. JCastExpression 8. JLiteral Also, there are at most MAX_SIZE such expressions. Note that postfix/prefix is not allowed since it might not end up acting on a variable after inlining (leading to syntax error).


doConvert

public static void doConvert(JMethodDeclaration decl,
                             boolean declOnly,
                             CodeGenerator toC)
Performs conversion of into a macro. If is true, returns the macro definition (in place of what would have been the prototype). Otherwise returns an empty string (as nothing goes in place of the actual method; macro decls need to be at the top of the file, before they are used.) is the code generator that was working on the program, will be used to generate code for macro expression.