Files
ark_js_runtime/ecmascript/compiler/assembler_module.h
T
sunzhe23 10ebc065d8 Support stackless callnew for asm interpreter
description:
1 use JSCallDispatch implments call new
2 refactor js common call

issue: I5AKJU

Signed-off-by: sunzhe23 <sunzhe23@huawei.com>
2022-06-08 13:28:04 +08:00

121 lines
3.3 KiB
C++

/*
* Copyright (c) 2022 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.
*/
#ifndef ECMASCRIPT_COMPILER_ASSEMBLER_MODULE_H
#define ECMASCRIPT_COMPILER_ASSEMBLER_MODULE_H
#include <string>
#include <vector>
#include "ecmascript/compiler/assembler/assembler.h"
#include "ecmascript/compiler/call_signature.h"
#include "ecmascript/compiler/rt_call_signature.h"
#include "ecmascript/frames.h"
#include "ecmascript/stubs/runtime_stubs.h"
namespace panda::ecmascript::kungfu {
class CompilationConfig;
class AssemblerModule {
public:
AssemblerModule() = default;
~AssemblerModule()
{
for (auto it : symbolTable_) {
delete it.second;
}
}
void Run(const CompilationConfig *cfg, Chunk* chunk);
size_t GetFunctionCount() const
{
return symbolTable_.size();
}
size_t GetFunction(int id) const
{
panda::ecmascript::Label *label = GetFunctionLabel(id);
if (label->IsBound()) {
return label->GetPos();
} else {
UNREACHABLE();
}
}
panda::ecmascript::Label* GetFunctionLabel(int id) const
{
return symbolTable_.at(id);
}
uint8_t* GetBuffer() const
{
return buffer_;
}
size_t GetBufferSize() const
{
return bufferSize_;
}
void SetUpForAsmStubs();
const std::vector<const CallSignature*> &GetCSigns() const
{
return asmCallSigns_;
}
size_t GetCodeBufferOffset() const
{
return codeBufferOffset_;
}
void SetCodeBufferOffset(size_t offset)
{
codeBufferOffset_ = offset;
}
void GenerateStubsX64(Chunk* chunk);
void GenerateStubsAarch64(Chunk* chunk);
static int GetJumpSizeFromJSCallMode(JSCallMode mode);
static int GetArgcFromJSCallMode(JSCallMode mode);
static bool JSModeHaveThisArg(JSCallMode mode);
static bool JSModeHaveNewTargetArg(JSCallMode mode);
private:
std::vector<const CallSignature *> asmCallSigns_;
std::map<int, panda::ecmascript::Label *> symbolTable_;
size_t codeBufferOffset_ {0};
uint8_t* buffer_ {nullptr};
size_t bufferSize_ {0};
};
class AssemblerStub {
public:
virtual void GenerateX64(Assembler* assembler) = 0;
virtual void GenerateAarch64(Assembler* assembler) = 0;
virtual ~AssemblerStub() = default;
};
#define DECLARE_ASM_STUB_CLASS(name) \
class name##Stub : public AssemblerStub { \
public: \
~name##Stub() = default; \
void GenerateX64(Assembler* assembler) override; \
void GenerateAarch64(Assembler* assembler) override; \
};
RUNTIME_ASM_STUB_LIST(DECLARE_ASM_STUB_CLASS)
#undef DECLARE_ASM_STUB_CLASS
} // namespace panda::ecmascript::kunfu
#endif // ECMASCRIPT_COMPILER_ASSEMBLER_MODULE_H