• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "ecmascript/compiler/stub.h"
16 #include "ecmascript/compiler/stub_builder.h"
17 #include "ecmascript/compiler/call_signature.h"
18 
19 namespace panda::ecmascript::kungfu {
Stub(const CallSignature * callSignature,Circuit * circuit)20 Stub::Stub(const CallSignature *callSignature, Circuit *circuit)
21     : callSignature_(callSignature), builder_(circuit),
22       acc_(circuit), env_(callSignature->GetParametersCount(), &builder_)
23 {
24 }
25 
InitializeArguments()26 void Stub::InitializeArguments()
27 {
28     auto argLength = callSignature_->GetParametersCount();
29     auto paramsType = callSignature_->GetParametersType();
30     for (size_t i = 0; i < argLength; i++) {
31         GateRef argument = env_.GetArgument(i);
32         if (paramsType[i] == VariableType::NATIVE_POINTER()) {
33             auto type = env_.IsArch64Bit() ? MachineType::I64 : MachineType::I32;
34             acc_.SetMachineType(argument, type);
35         } else {
36             acc_.SetMachineType(argument, paramsType[i].GetMachineType());
37         }
38         acc_.SetGateType(argument, paramsType[i].GetGateType());
39     }
40 }
41 
GenerateCircuit(const CompilationConfig * cfg)42 void Stub::GenerateCircuit(const CompilationConfig *cfg)
43 {
44     env_.SetCompilationConfig(cfg);
45     InitializeArguments();
46     stubBuilder_->GenerateCircuit();
47 }
48 }  // namespace panda::ecmascript::kungfu