Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/ir/runtime-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace {

} // namespace

void RealRuntimeTable::set(std::size_t i, Literal l) {
void RealRuntimeTable::set(Address i, Literal l) {
if (i >= table.size()) {
trap("RuntimeTable::set out of bounds");
WASM_UNREACHABLE("trapped");
Expand All @@ -40,7 +40,7 @@ void RealRuntimeTable::set(std::size_t i, Literal l) {
table[i] = std::move(l);
}

Literal RealRuntimeTable::get(std::size_t i) const {
Literal RealRuntimeTable::get(Address i) const {
if (i >= table.size()) {
trap("out of bounds table access");
WASM_UNREACHABLE("trapped");
Expand All @@ -49,18 +49,18 @@ Literal RealRuntimeTable::get(std::size_t i) const {
return table[i];
}

std::optional<std::size_t> RealRuntimeTable::grow(std::size_t delta,
Literal fill) {
std::size_t newSize;
if (std::ckd_add(&newSize, table.size(), delta)) {
std::optional<Address> RealRuntimeTable::grow(Address delta, Literal fill) {
Address newSize;
if (std::ckd_add(
&newSize.addr, static_cast<Address>(table.size()).addr, delta.addr)) {
return std::nullopt;
}

if (newSize > WebLimitations::MaxTableSize || newSize > tableDefinition.max) {
return std::nullopt;
}

std::size_t oldSize = table.size();
Address oldSize = table.size();
table.resize(newSize, fill);
return oldSize;
}
Expand Down
18 changes: 9 additions & 9 deletions src/ir/runtime-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class RuntimeTable {
RuntimeTable(Table table) : tableDefinition(table) {}
virtual ~RuntimeTable() = default;

virtual void set(std::size_t i, Literal l) = 0;
virtual void set(Address i, Literal l) = 0;

virtual Literal get(std::size_t i) const = 0;
virtual Literal get(Address i) const = 0;

// Returns nullopt if the table grew beyond the max possible size.
[[nodiscard]] virtual std::optional<std::size_t> grow(std::size_t delta,
Literal fill) = 0;
[[nodiscard]] virtual std::optional<Address> grow(Address delta,
Literal fill) = 0;

virtual std::size_t size() const = 0;
virtual Address size() const = 0;

// True iff this is a subtype of the definition `other`. i.e. This table can
// be imported with the definition of `other`
Expand All @@ -66,13 +66,13 @@ class RealRuntimeTable : public RuntimeTable {
RealRuntimeTable(const RealRuntimeTable&) = delete;
RealRuntimeTable& operator=(const RealRuntimeTable&) = delete;

void set(std::size_t i, Literal l) override;
void set(Address i, Literal l) override;

Literal get(std::size_t i) const override;
Literal get(Address i) const override;

std::optional<std::size_t> grow(std::size_t delta, Literal fill) override;
std::optional<Address> grow(Address delta, Literal fill) override;

std::size_t size() const override { return table.size(); }
Address size() const override { return table.size(); }

private:
std::vector<Literal> table;
Expand Down
10 changes: 5 additions & 5 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ class EvallingRuntimeTable : public RuntimeTable {
: RuntimeTable(table), instanceInitialized(instanceInitialized), wasm(wasm),
makeFuncData(std::move(makeFuncData)) {}

void set(std::size_t i, Literal l) override {
void set(Address i, Literal l) override {
if (instanceInitialized) {
throw FailToEvalException("tableStore after init: TODO");
}
}

Literal get(std::size_t index) const override {
Literal get(Address index) const override {
// Look through the segments and find the value. Segments can overlap,
// so we want the last one.
Expression* value = nullptr;
Expand Down Expand Up @@ -164,12 +164,12 @@ class EvallingRuntimeTable : public RuntimeTable {
return Properties::getLiteral(value);
}

[[nodiscard]] virtual std::optional<std::size_t> grow(std::size_t delta,
Literal fill) override {
[[nodiscard]] virtual std::optional<Address> grow(Address delta,
Literal fill) override {
throw FailToEvalException("grow table");
}

std::size_t size() const override {
Address size() const override {
// See set() above, we assume the table is not modified FIXME
return tableDefinition.initial;
}
Expand Down
Loading