Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibJS/Bytecode/Operand.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Types.h>
10
#include <LibJS/Forward.h>
11
12
namespace JS::Bytecode {
13
14
class Operand {
15
public:
16
    enum class Type {
17
        Register,
18
        Local,
19
        Constant,
20
    };
21
22
0
    [[nodiscard]] bool operator==(Operand const&) const = default;
23
24
    explicit Operand(Type type, u32 index)
25
0
        : m_type(type)
26
0
        , m_index(index)
27
0
    {
28
0
    }
29
30
    explicit Operand(Register);
31
32
0
    [[nodiscard]] bool is_register() const { return m_type == Type::Register; }
33
0
    [[nodiscard]] bool is_local() const { return m_type == Type::Local; }
34
0
    [[nodiscard]] bool is_constant() const { return m_type == Type::Constant; }
35
36
0
    [[nodiscard]] Type type() const { return m_type; }
37
0
    [[nodiscard]] u32 index() const { return m_index; }
38
39
    [[nodiscard]] Register as_register() const;
40
41
0
    void offset_index_by(u32 offset) { m_index += offset; }
42
43
private:
44
    Type m_type {};
45
    u32 m_index { 0 };
46
};
47
48
}