-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.h
74 lines (61 loc) · 2.85 KB
/
string.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include "program.h"
#include <cstdint>
#include <optional>
#include <string>
namespace flounder {
class String
{
public:
class Descriptor
{
public:
Descriptor(Operand data, const std::size_t size, const bool is_fixed_size, const bool is_pointer) noexcept
: _data(data), _size(size), _is_fixed_size(is_fixed_size), _is_pointer(is_pointer)
{
}
Descriptor(Register data, const std::size_t size, const bool is_fixed_size, const bool is_pointer) noexcept
: Descriptor(Operand{data}, size, is_fixed_size, is_pointer)
{
}
Descriptor(Operand data, const std::int32_t offset, const std::size_t size, const bool is_fixed_size,
const bool is_pointer) noexcept
: _data(data), _offset(offset), _size(size), _is_fixed_size(is_fixed_size), _is_pointer(is_pointer)
{
}
Descriptor(Register data, const std::int32_t offset, const std::size_t size, const bool is_fixed_size,
const bool is_pointer) noexcept
: Descriptor(Operand{data}, offset, size, is_fixed_size, is_pointer)
{
}
~Descriptor() noexcept = default;
[[nodiscard]] Operand data() const noexcept { return _data; }
[[nodiscard]] std::optional<std::int32_t> offset() const noexcept { return _offset; }
[[nodiscard]] std::size_t size() const noexcept { return _size; }
[[nodiscard]] bool is_fixed_size() const noexcept { return _is_fixed_size; }
[[nodiscard]] bool is_pointer() const noexcept { return _is_pointer; }
private:
Operand _data;
const std::optional<std::int32_t> _offset{std::nullopt};
const std::size_t _size;
const bool _is_fixed_size;
const bool _is_pointer;
};
[[nodiscard]] static Register is_equals(Program &program, std::string &&name, Descriptor left, Descriptor right);
private:
[[nodiscard]] static Register is_equals_inlined_and_pointer(Program &program, std::string &&name, Descriptor left,
Descriptor right);
[[nodiscard]] static Register is_equals_fixed_and_variable_size(Program &program, std::string &&name,
Descriptor fixed_size_descriptor,
Descriptor variable_size_descriptor);
[[nodiscard]] static MemoryAddress access(Program &program, const Operand operand, const std::int32_t offset,
const RegisterWidth width)
{
if (operand.is_reg())
{
return program.mem(operand.reg(), offset, width);
}
return program.mem(program.constant64(operand.constant().value_as_int64() + offset), width);
}
};
} // namespace flounder