use of com.oracle.truffle.sl.nodes.local.SLReadArgumentNode in project graal by oracle.
the class SLNodeFactory method addFormalParameter.
public void addFormalParameter(Token nameToken) {
/*
* Method parameters are assigned to local variables at the beginning of the method. This
* ensures that accesses to parameters are specialized the same way as local variables are
* specialized.
*/
final SLReadArgumentNode readArg = new SLReadArgumentNode(parameterCount);
SLExpressionNode assignment = createAssignment(createStringLiteral(nameToken, false), readArg);
methodNodes.add(assignment);
parameterCount++;
}
use of com.oracle.truffle.sl.nodes.local.SLReadArgumentNode in project graal by oracle.
the class SLContext method installBuiltin.
public void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory) {
/*
* The builtin node factory is a class that is automatically generated by the Truffle DSL.
* The signature returned by the factory reflects the signature of the @Specialization
*
* methods in the builtin classes.
*/
int argumentCount = factory.getExecutionSignature().size();
SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount];
/*
* Builtin functions are like normal functions, i.e., the arguments are passed in as an
* Object[] array encapsulated in SLArguments. A SLReadArgumentNode extracts a parameter
* from this array.
*/
for (int i = 0; i < argumentCount; i++) {
argumentNodes[i] = new SLReadArgumentNode(i);
}
/* Instantiate the builtin node. This node performs the actual functionality. */
SLBuiltinNode builtinBodyNode = factory.createNode((Object) argumentNodes);
builtinBodyNode.addRootTag();
/* The name of the builtin function is specified via an annotation on the node class. */
String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName();
builtinBodyNode.setUnavailableSourceSection();
/* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */
SLRootNode rootNode = new SLRootNode(language, new FrameDescriptor(), builtinBodyNode, BUILTIN_SOURCE.createUnavailableSection(), name);
/* Register the builtin function in our function registry. */
getFunctionRegistry().register(name, Truffle.getRuntime().createCallTarget(rootNode));
}
Aggregations