예제 #1
0
 public static LLVMResolvedDirectNativeCallNode getResolvedNativeCall(
     LLVMFunction function, NativeFunctionHandle nativeHandle, LLVMExpressionNode[] args) {
   if (function.getLlvmReturnType() == LLVMRuntimeType.ADDRESS
       || function.getLlvmReturnType() == LLVMRuntimeType.STRUCT) {
     return new LLVMResolvedNativeAddressCallNode(function, nativeHandle, args);
   } else if (function.getLlvmReturnType() == LLVMRuntimeType.X86_FP80) {
     return new LLVMResolvedNative80BitFloatCallNode(function, nativeHandle, args);
   } else {
     return new LLVMResolvedDirectNativeCallNode(function, nativeHandle, args);
   }
 }
예제 #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;
      }
    }