From 87f9dac127b387715d8d96ac7ec8fd469d8c2dab Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 3 Dec 2024 11:20:36 -0800 Subject: [NFC] Encapsulate source map reader state (#7132) Move all state relevant to reading source maps out of WasmBinaryReader and into a new utility, SourceMapReader. This is a prerequisite for parallelizing the parsing of function bodies, since the source map reader state is different at the beginning of each function. Also take the opportunity to simplify the way we read source maps, for example by deferring the reading of anything but the position of a debug location until it will be used and by using `std::optional` instead of singleton `std::set`s to store function prologue and epilogue debug locations. --- test/gtest/binary-reader.cpp | 63 -------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 test/gtest/binary-reader.cpp (limited to 'test/gtest/binary-reader.cpp') diff --git a/test/gtest/binary-reader.cpp b/test/gtest/binary-reader.cpp deleted file mode 100644 index b73fe55bd..000000000 --- a/test/gtest/binary-reader.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2024 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "parser/wat-parser.h" -#include "print-test.h" -#include "wasm-binary.h" -#include "gtest/gtest.h" - -using namespace wasm; - -using BinaryReaderTest = PrintTest; - -// Check that debug location parsers can handle single-segment mappings. -TEST_F(BinaryReaderTest, SourceMappingSingleSegment) { - auto moduleText = "(module)"; - Module module; - parseWast(module, moduleText); - - BufferWithRandomAccess buffer; - WasmBinaryWriter(&module, buffer, PassOptions()); - auto moduleBytes = buffer.getAsChars(); - - // A single-segment mapping starting at offset 0. - std::string sourceMap = R"( - { - "version": 3, - "sources": [], - "names": [], - "mappings": "A" - } - )"; - std::stringstream sourceMapStream(sourceMap); - - // Test `readSourceMapHeader` (only check for errors, as there is no mapping - // to print). - { - Module module; - WasmBinaryReader binaryReader(module, FeatureSet::All, moduleBytes); - binaryReader.setDebugLocations(&sourceMapStream); - binaryReader.readSourceMapHeader(); - } - - // Test `readNextDebugLocation`. - { - Module module; - WasmBinaryReader binaryReader(module, FeatureSet::All, moduleBytes); - binaryReader.setDebugLocations(&sourceMapStream); - binaryReader.readNextDebugLocation(); - } -} -- cgit v1.2.3