mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-08-28 04:49:56 -04:00
fb35927a32
when function need call another js function, it will lowering to call "JSCall" trampoline function
JSCall trampoline function will check calltarget function, then correct the arguments, finally jump
the native or optimized code address of the target function.
JSCall(glue, argc, calltarget, ....)
then proxy call(glue, argc, callTarget, argv[])
if proxy->GetHandler is function
tail call JSCall(glue, argc, callTarget, argv); // consider performance
else
//Call(trap, handler, «target, thisArgument, argArray»)
call CreateArrayFromList(glue, argc, argv[]) ---> arrHandle // maybe trigger GC, construct OptimizedWithArgvLeaveFrame, visitor argv[0]..argv[argc-1]
call JSCall(glue, argc, method, argv[])
issue:https://gitee.com/openharmony/ark_js_runtime/issues/I52T6B?from=project-issue
Signed-off-by: songzhengchao <songzhengchao@huawei.com>
Change-Id: I994aae1eb9cbf51982348ae6e203c24c326f617e
209 lines
8.3 KiB
C++
209 lines
8.3 KiB
C++
/*
|
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "test_stubs.h"
|
|
|
|
#include "ecmascript/compiler/llvm_ir_builder.h"
|
|
#include "ecmascript/compiler/stub-inl.h"
|
|
#include "ecmascript/compiler/variable_type.h"
|
|
#include "ecmascript/message_string.h"
|
|
|
|
namespace panda::ecmascript::kungfu {
|
|
using namespace panda::ecmascript;
|
|
void FooAOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
(void)calltarget;
|
|
GateRef barIndex = IntBuildTaggedWithNoGC(Int32(CommonStubCSigns::BarAOT));
|
|
GateRef numArgs = IntBuildTaggedWithNoGC(Int32(2));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, barfunc, newtarget, thisObj, a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void BarAOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
[[maybe_unused]] GateRef argc = Int32Argument(1);
|
|
[[maybe_unused]] GateRef calltarget = TaggedArgument(2);
|
|
[[maybe_unused]] GateRef newtarget = TaggedArgument(3);
|
|
[[maybe_unused]] GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
GateRef result = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void Foo1AOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
(void)calltarget;
|
|
GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::Bar1AOT));
|
|
GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(3));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, barfunc, newtarget, thisObj, a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void Bar1AOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
(void)argc;
|
|
(void)calltarget;
|
|
(void)newtarget;
|
|
(void)thisObj;
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
GateRef c = TaggedArgument(7);
|
|
GateRef result = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {a, b});
|
|
GateRef result2 = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {result, c});
|
|
Return(result2);
|
|
}
|
|
|
|
void Foo2AOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
(void)calltarget;
|
|
GateRef actualArgC = Int32Add(argc, Int32(1));
|
|
GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT));
|
|
GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, actualArgC, barfunc, newtarget, thisObj,
|
|
a, b, Undefined()});
|
|
Return(result);
|
|
}
|
|
|
|
void FooNativeAOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
(void)calltarget;
|
|
GateRef actualArgC = Int32Add(argc, Int32(1));
|
|
GateRef printfunc = CallRuntime(glue, RTSTUB_ID(GetPrintFunc), {});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, actualArgC, printfunc, newtarget, thisObj,
|
|
a, b, Undefined()});
|
|
Return(result);
|
|
}
|
|
|
|
void FooBoundAOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
GateRef bindArguments = IntBuildTaggedTypeWithNoGC(Int32(37));
|
|
(void)calltarget;
|
|
GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2));
|
|
GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
GateRef bindfunc = CallRuntime(glue, RTSTUB_ID(GetBindFunc), {barfunc});
|
|
GateRef newjsfunc = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, Int32(5), bindfunc, newtarget, barfunc,
|
|
Int64(0x02), bindArguments});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, newjsfunc, newtarget, thisObj,
|
|
a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void FooProxyAOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
[[maybe_unused]] GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
|
|
GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT));
|
|
GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
|
|
GateRef proxyfunc = CallRuntime(glue, RTSTUB_ID(DefineProxyFunc), {barfunc});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, proxyfunc, newtarget, thisObj, a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void FooProxy2AOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
GateRef glue = PtrArgument(0);
|
|
GateRef argc = Int32Argument(1);
|
|
[[maybe_unused]] GateRef calltarget = TaggedArgument(2);
|
|
GateRef newtarget = TaggedArgument(3);
|
|
GateRef thisObj = TaggedArgument(4);
|
|
GateRef a = TaggedArgument(5);
|
|
GateRef b = TaggedArgument(6);
|
|
|
|
GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::Bar2AOT));
|
|
GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2));
|
|
GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs});
|
|
GateRef proxyHandler = CallRuntime(glue, RTSTUB_ID(DefineProxyHandler), {barfunc});
|
|
|
|
GateRef proxyfunc = CallRuntime(glue, RTSTUB_ID(DefineProxyFunc2), {barfunc, proxyHandler});
|
|
GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, proxyfunc, newtarget, thisObj, a, b});
|
|
Return(result);
|
|
}
|
|
|
|
void Bar2AOTStub::GenerateCircuit(const CompilationConfig *cfg)
|
|
{
|
|
Stub::GenerateCircuit(cfg);
|
|
[[maybe_unused]] GateRef glue = PtrArgument(0);
|
|
[[maybe_unused]] GateRef argc = Int32Argument(1);
|
|
[[maybe_unused]] GateRef calltarget = TaggedArgument(2);
|
|
[[maybe_unused]] GateRef newtarget = TaggedArgument(3);
|
|
[[maybe_unused]] GateRef thisObj = TaggedArgument(4);
|
|
CallRuntime(glue, RTSTUB_ID(DumpTaggedType), {thisObj});
|
|
Return(thisObj);
|
|
}
|
|
} // namespace panda::ecmascript::kungfu
|