Commit e313bc17 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Refactor the Result object

Instead of storing {start} and {error_pc} we now store the
{error_offset}, which is anyways the only value we use.

R=clemensh@chromium.org

Change-Id: Ifd9791eff5c9efce2e7e2a1989bf3b5eaa464a02
Reviewed-on: https://chromium-review.googlesource.com/471527
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44510}
parent c8bc0cac
......@@ -206,8 +206,8 @@ class Decoder {
if (failed()) {
TRACE("Result error: %s\n", error_msg_.get());
result.error_code = kError;
result.start = start_;
result.error_pc = error_pc_;
DCHECK_GE(error_pc_, start_);
result.error_offset = static_cast<uint32_t>(error_pc_ - start_);
// transfer ownership of the error to the result.
result.error_msg.reset(error_msg_.release());
} else {
......
......@@ -215,7 +215,6 @@ class ModuleDecoder : public Decoder {
: Decoder(module_start, module_end),
module_zone(zone),
origin_(FLAG_assume_asmjs_origin ? kAsmJsOrigin : origin) {
result_.start = start_;
if (end_ < start_) {
error(start_, "end is less than start");
end_ = start_;
......
......@@ -28,7 +28,7 @@ enum ErrorCode {
// The overall result of decoding a function or a module.
template <typename T>
struct Result {
Result() : val(), error_code(kSuccess), start(nullptr), error_pc(nullptr) {}
Result() : val(), error_code(kSuccess), error_offset(0) {}
Result(Result&& other) { *this = std::move(other); }
Result& operator=(Result&& other) {
MoveFrom(other);
......@@ -38,8 +38,7 @@ struct Result {
T val;
ErrorCode error_code;
const byte* start;
const byte* error_pc;
uint32_t error_offset;
std::unique_ptr<char[]> error_msg;
bool ok() const { return error_code == kSuccess; }
......@@ -48,8 +47,7 @@ struct Result {
template <typename V>
void MoveFrom(Result<V>& that) {
error_code = that.error_code;
start = that.start;
error_pc = that.error_pc;
error_offset = that.error_offset;
error_msg = std::move(that.error_msg);
}
......@@ -67,12 +65,7 @@ std::ostream& operator<<(std::ostream& os, const Result<T>& result) {
os << "success (no value)";
}
} else if (result.error_msg.get() != nullptr) {
ptrdiff_t offset = result.error_pc - result.start;
if (offset < 0) {
os << result.error_msg.get() << " @" << offset;
} else {
os << result.error_msg.get() << " @+" << offset;
}
os << result.error_msg.get() << " @" << result.error_offset;
} else {
os << result.error_code;
}
......
......@@ -389,7 +389,7 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
result = BuildTFGraph(zone->allocator(), &builder, sig, start, end);
}
ptrdiff_t pc = result.error_pc - result.start;
uint32_t pc = result.error_offset;
std::ostringstream str;
str << "Verification failed: " << result.error_code << " pc = +" << pc
<< ", msg = " << result.error_msg.get();
......
......@@ -136,7 +136,7 @@ class FunctionBodyDecoderTest : public TestWithZone {
start, end);
if (result.error_code != expected) {
ptrdiff_t pc = result.error_pc - result.start;
uint32_t pc = result.error_offset;
std::ostringstream str;
if (expected == kSuccess) {
str << "Verification failed: " << result.error_code << " pc = +" << pc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment