53 explicit InitialImage(std::size_t bytes) : data_(bytes) {}
54 InitialImage(InitialImage &&that) =
default;
56 std::size_t size()
const {
return data_.size(); }
59 Result Add(ConstantSubscript, std::size_t,
const A &,
FoldingContext &) {
63 Result Add(ConstantSubscript offset, std::size_t bytes,
const Constant<T> &x,
65 if (offset < 0 || offset + bytes > data_.size()) {
68 auto elementBytes{ToInt64(x.GetType().MeasureSizeInBytes(context,
true))};
71 x.values().size() *
static_cast<std::size_t
>(*elementBytes)) {
73 }
else if (bytes == 0) {
78 StoreSerialValues<Scalar<T>>(&data_.at(offset),
80 return changed ? Ok : OkNoChange;
85 Result Add(ConstantSubscript offset, std::size_t bytes,
88 if (offset < 0 || offset + bytes > data_.size()) {
91 auto optElements{TotalElementCount(x.shape())};
95 auto elements{*optElements};
96 auto elementBytes{bytes > 0 ? bytes / elements : 0};
97 if (elements * elementBytes != bytes) {
99 }
else if (bytes == 0) {
102 Result result{OkNoChange};
103 for (
auto at{x.lbounds()}; elements-- > 0; x.IncrementSubscripts(at)) {
105 auto scalarBytes{scalar.size() * KIND};
106 if (scalarBytes != elementBytes) {
107 result = LengthMismatch;
110 auto *to{&data_.at(offset)};
112 scalar.StoreRawBytes(to, elementBytes, &changed);
113 if (changed && result == OkNoChange) {
116 offset += elementBytes;
124 template <
typename T>
125 Result Add(ConstantSubscript offset, std::size_t bytes,
const Expr<T> &x,
127 return common::visit(
128 [&](
const auto &y) {
return Add(offset, bytes, y, c); }, x.u);
134 bool Incorporate(ConstantSubscript toOffset,
const InitialImage &from,
135 ConstantSubscript fromOffset, ConstantSubscript bytes);
139 const DynamicType &, std::optional<std::int64_t> charLength,
140 const ConstantSubscripts &,
bool padWithZero =
false,
141 ConstantSubscript offset = 0)
const;
142 std::optional<Expr<SomeType>> AsConstantPointer(
143 ConstantSubscript offset = 0)
const;
145 friend class AsConstantHelper;
148 std::vector<char> data_;
149 std::map<ConstantSubscript, Expr<SomeType>> pointers_;