Пример #1
0
 @Specialization(contains = "doDirect")
 protected Object doIndirect(
     VirtualFrame frame,
     LLVMFunction function,
     Object[] arguments, //
     @Cached("create()") IndirectCallNode callNode) {
   return callNode.call(frame, context.getFunction(function), arguments);
 }
Пример #2
0
 @Override
 public Object executeGeneric(VirtualFrame frame) {
   CompilerDirectives.transferToInterpreter();
   if (functionNode instanceof LLVMFunctionLiteralNode) {
     LLVMFunction function = functionNode.executeFunction(frame);
     CallTarget callTarget = context.getFunction(function);
     if (callTarget == null) {
       NativeFunctionHandle nativeHandle = context.getNativeHandle(function, args);
       if (nativeHandle == null) {
         throw new IllegalStateException("could not find function " + function.getName());
       }
       return replace(getResolvedNativeCall(function, nativeHandle, args)).executeGeneric(frame);
     } else {
       return replace(new LLVMResolvedDirectCallNode(callTarget, args)).executeGeneric(frame);
     }
   } else {
     LLVMFunctionCallChain rootNode = LLVMFunctionCallChainNodeGen.create(context, args);
     return replace(new LLVMFunctionCallChainStartNode(functionNode, rootNode, args))
         .executeGeneric(frame);
   }
 }
Пример #3
0
    public static CallTarget getIndirectCallTarget(
        LLVMContext context, LLVMFunction function, LLVMExpressionNode[] args) {
      CallTarget callTarget = context.getFunction(function);
      if (callTarget == null) {
        final NativeFunctionHandle nativeHandle = context.getNativeHandle(function, args);
        if (nativeHandle == null) {
          throw new IllegalStateException("could not find function " + function.getName());
        } else {
          return Truffle.getRuntime()
              .createCallTarget(
                  new RootNode(LLVMLanguage.class, null, null) {

                    @Override
                    public Object execute(VirtualFrame frame) {
                      return nativeHandle.call(frame.getArguments());
                    }
                  });
        }
      } else {
        return callTarget;
      }
    }