scale.backend
Class Intrinsics

java.lang.Object
  extended by scale.backend.Intrinsics
Direct Known Subclasses:
TripsIntrinsics

public abstract class Intrinsics
extends java.lang.Object

This class represents a target independent implementation for compiler intrinsics.

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

Intrinsics are invoked dynamically using Java reflection and are expected to be found inside the callers Generator instance (i.e. AlphaGenerator). The method invoked to implement the intrinsic is set at the time an intrinsic is installed. By default the method called is set to the same name as the external function name being turned into an intrinsic. See installIntrinsic() below for more details.

The current implementation assumes that before a function call is replaced with an intrinsic, the arguments to the function call have been setup exactly as they would have been if the call took place. This allows the method which implements an intrinsic to make assumptions about where arguments reside.


Constructor Summary
protected Intrinsics(Generator gen, java.lang.Class<Generator> c)
          Constructor used to instantiate a new intrinsic handler.
 
Method Summary
static int created()
          Return the number of instances of this class created.
protected  void installIntrinsic(java.lang.String name, Type[] args, Type rt)
          Called by a backend wishing to install a compiler intrinsic.
protected  void installIntrinsic(java.lang.String name, Type[] args, Type rt, java.lang.String methodName)
          Called by a backend wishing to install a compiler intrinsic.
 boolean invokeIntrinsic(java.lang.String name, Expr[] args, Type rt)
          Called by a backend to convert a function call into an intrinsic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Intrinsics

protected Intrinsics(Generator gen,
                     java.lang.Class<Generator> c)
Constructor used to instantiate a new intrinsic handler.

Parameters:
gen - the instance of Generator that instantiated this class.
c - the class type of Generator, ex. AlphaGenerator.class.
Method Detail

created

public static int created()
Return the number of instances of this class created.


installIntrinsic

protected void installIntrinsic(java.lang.String name,
                                Type[] args,
                                Type rt)
Called by a backend wishing to install a compiler intrinsic. This version will set the internal method name to be the same as the external intrinsic. ex. if __builtin_abs() is the external function name, then __builtin_abs() will be the method called in Generator to implement the intrinsic.

Parameters:
name - the function name, i.e. "abs"
args - the parameters to the function
rt - the return type

installIntrinsic

protected void installIntrinsic(java.lang.String name,
                                Type[] args,
                                Type rt,
                                java.lang.String methodName)
Called by a backend wishing to install a compiler intrinsic. This version will set the internal method name called to implement the intrinsic to "methodName". ex. if __builtin_abs() is the external function name, and "absIntrinsic" is passed as "methodName", absIntrinsic() will be called in Generator to implement the intrinsic.

Parameters:
name - the function name, i.e. "abs"
args - the parameters to the function
rt - the return type
methodName - the name of the method that implements this intrinsic in the compiler

invokeIntrinsic

public boolean invokeIntrinsic(java.lang.String name,
                               Expr[] args,
                               Type rt)
Called by a backend to convert a function call into an intrinsic.

Parameters:
name - the function name, i.e. "abs"
args - the parameters to the function
rt - the return type
Returns:
true if the function call was converted into an intrinsic.