1/*
2 * Copyright (c) 2021-2022 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
16#ifndef ES2PANDA_COMPILER_DEBUGGER_DEBUGINFO_DUMPER_H
17#define ES2PANDA_COMPILER_DEBUGGER_DEBUGINFO_DUMPER_H
18
19#include <assembly-ins.h>
20#include <assembly-program.h>
21#include <macros.h>
22
23namespace panda::es2panda::debuginfo {
24
25using Value = std::variant<std::string, size_t, int32_t>;
26
27class DebugInfoDumper {
28public:
29    explicit DebugInfoDumper(const pandasm::Program *prog);
30    ~DebugInfoDumper() = default;
31    NO_COPY_SEMANTIC(DebugInfoDumper);
32    NO_MOVE_SEMANTIC(DebugInfoDumper);
33
34    void Dump();
35
36private:
37    template <typename T>
38    void WrapArray(const char *name, const std::vector<T> &array, bool comma = true);
39    void WriteIns(const pandasm::Ins &ins);
40    void WriteMetaData(const std::vector<pandasm::AnnotationData> &metaData);
41    void WriteProperty(const char *key, const Value &value, bool comma = true);
42    void WritePosInfo(const pandasm::debuginfo::Ins &posInfo);
43    void WriteVariableInfo(const pandasm::debuginfo::LocalVariable &localVariableDebug);
44    void Indent();
45
46    const pandasm::Program *prog_;
47    std::stringstream ss_;
48    int32_t indent_ {0};
49};
50
51}  // namespace panda::es2panda::debuginfo
52
53#endif  // UTIL_DEBUGINFO_DUMPER_H
54