Commit 36345ada authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Switch source position type to {size_t}.

This switches the source positions consumed by {WasmFunctionBuilder} to
have type {size_t} instead of {int}. All checks for accidental loss due
to overflow in static casts can now be moved into one place.

R=clemensh@chromium.org

Change-Id: Id0b0da5fe799eac794c9d610c4c4c9a72a587b3f
Reviewed-on: https://chromium-review.googlesource.com/857196Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50449}
parent ae45cc1f
......@@ -292,8 +292,7 @@ void AsmJsParser::Begin(AsmJsScanner::token_t label) {
void AsmJsParser::Loop(AsmJsScanner::token_t label) {
BareBegin(BlockKind::kLoop, label);
int position = static_cast<int>(scanner_.Position());
DCHECK_EQ(position, scanner_.Position());
size_t position = scanner_.Position();
current_function_builder_->AddAsmWasmOffset(position, position);
current_function_builder_->EmitWithU8(kExprLoop, kLocalVoid);
}
......@@ -742,8 +741,7 @@ void AsmJsParser::ValidateFunction() {
return_type_ = nullptr;
// Record start of the function, used as position for the stack check.
int start_position = static_cast<int>(scanner_.Position());
current_function_builder_->SetAsmFunctionStartPosition(start_position);
current_function_builder_->SetAsmFunctionStartPosition(scanner_.Position());
CachedVector<AsmType*> params(cached_asm_type_p_vectors_);
ValidateFunctionParams(&params);
......@@ -2066,8 +2064,8 @@ AsmType* AsmJsParser::ParenthesizedExpression() {
AsmType* AsmJsParser::ValidateCall() {
AsmType* return_type = call_coercion_;
call_coercion_ = nullptr;
int call_pos = static_cast<int>(scanner_.Position());
int to_number_pos = static_cast<int>(call_coercion_position_);
size_t call_pos = scanner_.Position();
size_t to_number_pos = call_coercion_position_;
bool allow_peek = (call_coercion_deferred_position_ == scanner_.Position());
AsmJsScanner::token_t function_name = Consume();
......@@ -2113,7 +2111,7 @@ AsmType* AsmJsParser::ValidateCall() {
tmp.emplace(this);
current_function_builder_->EmitSetLocal(tmp->get());
// The position of function table calls is after the table lookup.
call_pos = static_cast<int>(scanner_.Position());
call_pos = scanner_.Position();
} else {
VarInfo* function_info = GetVarInfo(function_name);
if (function_info->kind == VarKind::kUnused) {
......@@ -2176,7 +2174,7 @@ AsmType* AsmJsParser::ValidateCall() {
(return_type == nullptr || return_type->IsA(AsmType::Float()))) {
DCHECK_NULL(call_coercion_deferred_);
call_coercion_deferred_ = AsmType::Signed();
to_number_pos = static_cast<int>(scanner_.Position());
to_number_pos = scanner_.Position();
return_type = AsmType::Signed();
} else if (return_type == nullptr) {
to_number_pos = call_pos; // No conversion.
......
......@@ -140,8 +140,8 @@ void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) {
void WasmFunctionBuilder::SetName(Vector<const char> name) { name_ = name; }
void WasmFunctionBuilder::AddAsmWasmOffset(int call_position,
int to_number_position) {
void WasmFunctionBuilder::AddAsmWasmOffset(size_t call_position,
size_t to_number_position) {
// We only want to emit one mapping per byte offset.
DCHECK(asm_offsets_.size() == 0 || body_.size() > last_asm_byte_offset_);
......@@ -150,21 +150,25 @@ void WasmFunctionBuilder::AddAsmWasmOffset(int call_position,
asm_offsets_.write_u32v(byte_offset - last_asm_byte_offset_);
last_asm_byte_offset_ = byte_offset;
DCHECK_GE(call_position, 0);
asm_offsets_.write_i32v(call_position - last_asm_source_position_);
DCHECK_GE(std::numeric_limits<uint32_t>::max(), call_position);
uint32_t call_position_u32 = static_cast<uint32_t>(call_position);
asm_offsets_.write_i32v(call_position_u32 - last_asm_source_position_);
DCHECK_GE(to_number_position, 0);
asm_offsets_.write_i32v(to_number_position - call_position);
last_asm_source_position_ = to_number_position;
DCHECK_GE(std::numeric_limits<uint32_t>::max(), to_number_position);
uint32_t to_number_position_u32 = static_cast<uint32_t>(to_number_position);
asm_offsets_.write_i32v(to_number_position_u32 - call_position_u32);
last_asm_source_position_ = to_number_position_u32;
}
void WasmFunctionBuilder::SetAsmFunctionStartPosition(int position) {
void WasmFunctionBuilder::SetAsmFunctionStartPosition(
size_t function_position) {
DCHECK_EQ(0, asm_func_start_source_position_);
DCHECK_LE(0, position);
DCHECK_GE(std::numeric_limits<uint32_t>::max(), function_position);
uint32_t function_position_u32 = static_cast<uint32_t>(function_position);
// Must be called before emitting any asm.js source position.
DCHECK_EQ(0, asm_offsets_.size());
asm_func_start_source_position_ = position;
last_asm_source_position_ = position;
asm_func_start_source_position_ = function_position_u32;
last_asm_source_position_ = function_position_u32;
}
void WasmFunctionBuilder::DeleteCodeAfter(size_t position) {
......
......@@ -172,8 +172,8 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
void EmitWithU32V(WasmOpcode opcode, uint32_t immediate);
void EmitDirectCallIndex(uint32_t index);
void SetName(Vector<const char> name);
void AddAsmWasmOffset(int call_position, int to_number_position);
void SetAsmFunctionStartPosition(int position);
void AddAsmWasmOffset(size_t call_position, size_t to_number_position);
void SetAsmFunctionStartPosition(size_t function_position);
size_t GetPosition() const { return body_.size(); }
void FixupByte(size_t position, byte value) {
......
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