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 { ...@@ -206,8 +206,8 @@ class Decoder {
if (failed()) { if (failed()) {
TRACE("Result error: %s\n", error_msg_.get()); TRACE("Result error: %s\n", error_msg_.get());
result.error_code = kError; result.error_code = kError;
result.start = start_; DCHECK_GE(error_pc_, start_);
result.error_pc = error_pc_; result.error_offset = static_cast<uint32_t>(error_pc_ - start_);
// transfer ownership of the error to the result. // transfer ownership of the error to the result.
result.error_msg.reset(error_msg_.release()); result.error_msg.reset(error_msg_.release());
} else { } else {
......
...@@ -215,7 +215,6 @@ class ModuleDecoder : public Decoder { ...@@ -215,7 +215,6 @@ class ModuleDecoder : public Decoder {
: Decoder(module_start, module_end), : Decoder(module_start, module_end),
module_zone(zone), module_zone(zone),
origin_(FLAG_assume_asmjs_origin ? kAsmJsOrigin : origin) { origin_(FLAG_assume_asmjs_origin ? kAsmJsOrigin : origin) {
result_.start = start_;
if (end_ < start_) { if (end_ < start_) {
error(start_, "end is less than start"); error(start_, "end is less than start");
end_ = start_; end_ = start_;
......
...@@ -28,7 +28,7 @@ enum ErrorCode { ...@@ -28,7 +28,7 @@ enum ErrorCode {
// The overall result of decoding a function or a module. // The overall result of decoding a function or a module.
template <typename T> template <typename T>
struct Result { 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(Result&& other) { *this = std::move(other); }
Result& operator=(Result&& other) { Result& operator=(Result&& other) {
MoveFrom(other); MoveFrom(other);
...@@ -38,8 +38,7 @@ struct Result { ...@@ -38,8 +38,7 @@ struct Result {
T val; T val;
ErrorCode error_code; ErrorCode error_code;
const byte* start; uint32_t error_offset;
const byte* error_pc;
std::unique_ptr<char[]> error_msg; std::unique_ptr<char[]> error_msg;
bool ok() const { return error_code == kSuccess; } bool ok() const { return error_code == kSuccess; }
...@@ -48,8 +47,7 @@ struct Result { ...@@ -48,8 +47,7 @@ struct Result {
template <typename V> template <typename V>
void MoveFrom(Result<V>& that) { void MoveFrom(Result<V>& that) {
error_code = that.error_code; error_code = that.error_code;
start = that.start; error_offset = that.error_offset;
error_pc = that.error_pc;
error_msg = std::move(that.error_msg); error_msg = std::move(that.error_msg);
} }
...@@ -67,12 +65,7 @@ std::ostream& operator<<(std::ostream& os, const Result<T>& result) { ...@@ -67,12 +65,7 @@ std::ostream& operator<<(std::ostream& os, const Result<T>& result) {
os << "success (no value)"; os << "success (no value)";
} }
} else if (result.error_msg.get() != nullptr) { } else if (result.error_msg.get() != nullptr) {
ptrdiff_t offset = result.error_pc - result.start; os << result.error_msg.get() << " @" << result.error_offset;
if (offset < 0) {
os << result.error_msg.get() << " @" << offset;
} else {
os << result.error_msg.get() << " @+" << offset;
}
} else { } else {
os << result.error_code; os << result.error_code;
} }
......
...@@ -389,7 +389,7 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, ...@@ -389,7 +389,7 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
result = BuildTFGraph(zone->allocator(), &builder, sig, start, end); 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; std::ostringstream str;
str << "Verification failed: " << result.error_code << " pc = +" << pc str << "Verification failed: " << result.error_code << " pc = +" << pc
<< ", msg = " << result.error_msg.get(); << ", msg = " << result.error_msg.get();
......
...@@ -136,7 +136,7 @@ class FunctionBodyDecoderTest : public TestWithZone { ...@@ -136,7 +136,7 @@ class FunctionBodyDecoderTest : public TestWithZone {
start, end); start, end);
if (result.error_code != expected) { if (result.error_code != expected) {
ptrdiff_t pc = result.error_pc - result.start; uint32_t pc = result.error_offset;
std::ostringstream str; std::ostringstream str;
if (expected == kSuccess) { if (expected == kSuccess) {
str << "Verification failed: " << result.error_code << " pc = +" << pc 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