Bug 1319879 - Baldr: tweak header dependencies (r=yury)
authorLuke Wagner <luke@mozilla.com>
Mon, 28 Nov 2016 17:34:27 -0600
changeset 324503 c837438ca4532da5a87949f8c416017889e1cb1d
parent 324502 af5401b40b582b8effd44505bdf2dd4c71ed4f3f
child 324504 1e932a9badfac50e6dcfa4a4da395c7644cbc73a
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersyury
bugs1319879
milestone53.0a1
Bug 1319879 - Baldr: tweak header dependencies (r=yury) MozReview-Commit-ID: BZYBrBDIvjO
js/src/wasm/WasmBinaryConstants.h
js/src/wasm/WasmBinaryToExperimentalText.h
js/src/wasm/WasmBinaryToText.h
js/src/wasm/WasmCode.h
js/src/wasm/WasmGeneratedSourceMap.h
js/src/wasm/WasmTextUtils.cpp
js/src/wasm/WasmTextUtils.h
--- a/js/src/wasm/WasmBinaryConstants.h
+++ b/js/src/wasm/WasmBinaryConstants.h
@@ -22,33 +22,34 @@
 #include "builtin/SIMD.h"
 
 namespace js {
 namespace wasm {
 
 static const uint32_t MagicNumber        = 0x6d736100; // "\0asm"
 static const uint32_t EncodingVersion    = 0x0d;
 
-enum class SectionId {
+static const char NameSectionName[]      = "name";
+
+enum class SectionId
+{
     UserDefined                          = 0,
     Type                                 = 1,
     Import                               = 2,
     Function                             = 3,
     Table                                = 4,
     Memory                               = 5,
     Global                               = 6,
     Export                               = 7,
     Start                                = 8,
     Elem                                 = 9,
     Code                                 = 10,
     Data                                 = 11
 };
 
-static const char NameSectionName[] = "name";
-
 enum class TypeCode
 {
     I32                                  = 0x7f,  // SLEB128(-0x01)
     I64                                  = 0x7e,  // SLEB128(-0x02)
     F32                                  = 0x7d,  // SLEB128(-0x03)
     F64                                  = 0x7c,  // SLEB128(-0x04)
 
     // Only emitted internally for asm.js, likely to get collapsed into I128
--- a/js/src/wasm/WasmBinaryToExperimentalText.h
+++ b/js/src/wasm/WasmBinaryToExperimentalText.h
@@ -18,17 +18,17 @@
 
 #ifndef wasm_binary_to_experimental_text_h
 #define wasm_binary_to_experimental_text_h
 
 #include "NamespaceImports.h"
 
 #include "gc/Rooting.h"
 #include "js/Class.h"
-#include "wasm/WasmGeneratedSourceMap.h"
+#include "wasm/WasmCode.h"
 
 namespace js {
 
 class StringBuffer;
 
 namespace wasm {
 
 struct ExperimentalTextFormatting
--- a/js/src/wasm/WasmBinaryToText.h
+++ b/js/src/wasm/WasmBinaryToText.h
@@ -18,17 +18,17 @@
 
 #ifndef wasm_binary_to_text_h
 #define wasm_binary_to_text_h
 
 #include "NamespaceImports.h"
 
 #include "gc/Rooting.h"
 #include "js/Class.h"
-#include "wasm/WasmGeneratedSourceMap.h"
+#include "wasm/WasmCode.h"
 
 namespace js {
 
 class StringBuffer;
 
 namespace wasm {
 
 // Translate the given binary representation of a wasm module into the module's textual
--- a/js/src/wasm/WasmCode.h
+++ b/js/src/wasm/WasmCode.h
@@ -14,17 +14,16 @@
  * 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.
  */
 
 #ifndef wasm_code_h
 #define wasm_code_h
 
-#include "wasm/WasmGeneratedSourceMap.h"
 #include "wasm/WasmTypes.h"
 
 namespace js {
 
 struct AsmJSMetadata;
 
 namespace wasm {
 
@@ -478,16 +477,74 @@ struct Metadata : ShareableBase<Metadata
                              TwoByteName* name) const;
 
     WASM_DECLARE_SERIALIZABLE_VIRTUAL(Metadata);
 };
 
 typedef RefPtr<Metadata> MutableMetadata;
 typedef RefPtr<const Metadata> SharedMetadata;
 
+// The generated source location for the AST node/expression. The offset field refers
+// an offset in an binary format file.
+
+struct ExprLoc
+{
+    uint32_t lineno;
+    uint32_t column;
+    uint32_t offset;
+    ExprLoc() : lineno(0), column(0), offset(0) {}
+    ExprLoc(uint32_t lineno_, uint32_t column_, uint32_t offset_)
+      : lineno(lineno_), column(column_), offset(offset_)
+    {}
+};
+
+typedef Vector<ExprLoc, 0, TempAllocPolicy> ExprLocVector;
+
+// The generated source WebAssembly function lines and expressions ranges.
+
+struct FunctionLoc
+{
+    size_t startExprsIndex;
+    size_t endExprsIndex;
+    uint32_t startLineno;
+    uint32_t endLineno;
+    FunctionLoc(size_t startExprsIndex_, size_t endExprsIndex_, uint32_t startLineno_, uint32_t endLineno_)
+      : startExprsIndex(startExprsIndex_),
+        endExprsIndex(endExprsIndex_),
+        startLineno(startLineno_),
+        endLineno(endLineno_)
+    {}
+};
+
+typedef Vector<FunctionLoc, 0, TempAllocPolicy> FunctionLocVector;
+
+// The generated source map for WebAssembly binary file. This map is generated during
+// building the text buffer (see BinaryToExperimentalText).
+
+class GeneratedSourceMap
+{
+    ExprLocVector exprlocs_;
+    FunctionLocVector functionlocs_;
+    uint32_t totalLines_;
+
+  public:
+    explicit GeneratedSourceMap(JSContext* cx)
+     : exprlocs_(cx),
+       functionlocs_(cx),
+       totalLines_(0)
+    {}
+    ExprLocVector& exprlocs() { return exprlocs_; }
+    FunctionLocVector& functionlocs() { return functionlocs_; }
+
+    uint32_t totalLines() { return totalLines_; }
+    void setTotalLines(uint32_t val) { totalLines_ = val; }
+};
+
+typedef UniquePtr<GeneratedSourceMap> UniqueGeneratedSourceMap;
+
 // Code objects own executable code and the metadata that describes it. At the
 // moment, Code objects are owned uniquely by instances since CodeSegments are
 // not shareable. However, once this restriction is removed, a single Code
 // object will be shared between a module and all its instances.
 
 class Code
 {
     const UniqueCodeSegment  segment_;
deleted file mode 100644
--- a/js/src/wasm/WasmGeneratedSourceMap.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 et sw=4 tw=99:
- *
- * Copyright 2016 Mozilla Foundation
- *
- * 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.
- */
-
-#ifndef wasm_generated_source_map_h
-#define wasm_generated_source_map_h
-
-#include "mozilla/Vector.h"
-
-#include "vm/StringBuffer.h"
-
-namespace js {
-
-namespace wasm {
-
-// The generated source location for the AST node/expression. The offset field refers
-// an offset in an binary format file.
-struct ExprLoc
-{
-    uint32_t lineno;
-    uint32_t column;
-    uint32_t offset;
-    ExprLoc() : lineno(0), column(0), offset(0) {}
-    ExprLoc(uint32_t lineno_, uint32_t column_, uint32_t offset_) : lineno(lineno_), column(column_), offset(offset_) {}
-};
-
-typedef mozilla::Vector<ExprLoc, 0, TempAllocPolicy> ExprLocVector;
-
-// The generated source WebAssembly function lines and expressions ranges.
-struct FunctionLoc
-{
-    size_t startExprsIndex;
-    size_t endExprsIndex;
-    uint32_t startLineno;
-    uint32_t endLineno;
-    FunctionLoc(size_t startExprsIndex_, size_t endExprsIndex_, uint32_t startLineno_, uint32_t endLineno_)
-      : startExprsIndex(startExprsIndex_),
-        endExprsIndex(endExprsIndex_),
-        startLineno(startLineno_),
-        endLineno(endLineno_)
-    {}
-};
-
-typedef mozilla::Vector<FunctionLoc, 0, TempAllocPolicy> FunctionLocVector;
-
-// The generated source map for WebAssembly binary file. This map is generated during
-// building the text buffer (see BinaryToExperimentalText).
-class GeneratedSourceMap
-{
-    ExprLocVector exprlocs_;
-    FunctionLocVector functionlocs_;
-    uint32_t totalLines_;
-
-  public:
-    explicit GeneratedSourceMap(JSContext* cx)
-     : exprlocs_(cx),
-       functionlocs_(cx),
-       totalLines_(0)
-    {}
-    ExprLocVector& exprlocs() { return exprlocs_; }
-    FunctionLocVector& functionlocs() { return functionlocs_; }
-
-    uint32_t totalLines() { return totalLines_; }
-    void setTotalLines(uint32_t val) { totalLines_ = val; }
-};
-
-typedef UniquePtr<GeneratedSourceMap> UniqueGeneratedSourceMap;
-
-// Helper class, StringBuffer wrapper, to track the position (line and column)
-// within the generated source.
-class WasmPrintBuffer
-{
-    StringBuffer& stringBuffer_;
-    uint32_t lineno_;
-    uint32_t column_;
-
-  public:
-    explicit WasmPrintBuffer(StringBuffer& stringBuffer)
-      : stringBuffer_(stringBuffer),
-        lineno_(1),
-        column_(1)
-    {}
-    inline char processChar(char ch) {
-        if (ch == '\n') {
-            lineno_++; column_ = 1;
-        } else
-            column_++;
-        return ch;
-    }
-    inline char16_t processChar(char16_t ch) {
-        if (ch == '\n') {
-            lineno_++; column_ = 1;
-        } else
-            column_++;
-        return ch;
-    }
-    bool append(const char ch) {
-        return stringBuffer_.append(processChar(ch));
-    }
-    bool append(const char16_t ch) {
-        return stringBuffer_.append(processChar(ch));
-    }
-    bool append(const char* str, size_t length) {
-        for (size_t i = 0; i < length; i++)
-            processChar(str[i]);
-        return stringBuffer_.append(str, length);
-    }
-    bool append(const char16_t* begin, const char16_t* end) {
-        for (const char16_t* p = begin; p != end; p++)
-            processChar(*p);
-        return stringBuffer_.append(begin, end);
-    }
-    bool append(const char16_t* str, size_t length) {
-        return append(str, str + length);
-    }
-    template <size_t ArrayLength>
-    bool append(const char (&array)[ArrayLength]) {
-        static_assert(ArrayLength > 0, "null-terminated");
-        MOZ_ASSERT(array[ArrayLength - 1] == '\0');
-        return append(array, ArrayLength - 1);
-    }
-    char16_t getChar(size_t index) {
-        return stringBuffer_.getChar(index);
-    }
-    size_t length() {
-        return stringBuffer_.length();
-    }
-    StringBuffer& stringBuffer() { return stringBuffer_; }
-    uint32_t lineno() { return lineno_; }
-    uint32_t column() { return column_; }
-};
-
-}  // namespace wasm
-
-}  // namespace js
-
-#endif // namespace wasm_generated_source_map_h
--- a/js/src/wasm/WasmTextUtils.cpp
+++ b/js/src/wasm/WasmTextUtils.cpp
@@ -17,23 +17,24 @@
  */
 
 #include "wasm/WasmTextUtils.h"
 
 #include "vm/StringBuffer.h"
 #include "wasm/WasmTypes.h"
 
 using namespace js;
-using namespace js::jit;
+using namespace jit;
+using namespace wasm;
 
 using mozilla::IsNaN;
 
 template<size_t base>
 bool
-js::wasm::RenderInBase(StringBuffer& sb, uint64_t num)
+wasm::RenderInBase(StringBuffer& sb, uint64_t num)
 {
     uint64_t n = num;
     uint64_t pow = 1;
     while (n) {
         pow *= base;
         n /= base;
     }
     pow /= base;
@@ -44,21 +45,21 @@ js::wasm::RenderInBase(StringBuffer& sb,
             return false;
         n -= (n / pow) * pow;
         pow /= base;
     }
 
     return true;
 }
 
-template bool js::wasm::RenderInBase<10>(StringBuffer& sb, uint64_t num);
+template bool wasm::RenderInBase<10>(StringBuffer& sb, uint64_t num);
 
 template<class T>
 bool
-js::wasm::RenderNaN(StringBuffer& sb, Raw<T> num)
+wasm::RenderNaN(StringBuffer& sb, Raw<T> num)
 {
     typedef typename mozilla::SelectTrait<T> Traits;
 
     MOZ_ASSERT(IsNaN(num.fp()));
 
     if ((num.bits() & Traits::kSignBit) && !sb.append("-"))
         return false;
     if (!sb.append("nan"))
@@ -68,10 +69,10 @@ js::wasm::RenderNaN(StringBuffer& sb, Ra
     // Only render the payload if it's not the spec's default NaN.
     if (payload == ((Traits::kSignificandBits + 1) >> 1))
         return true;
 
     return sb.append(":0x") &&
            RenderInBase<16>(sb, payload);
 }
 
-template MOZ_MUST_USE bool js::wasm::RenderNaN(StringBuffer& b, Raw<float> num);
-template MOZ_MUST_USE bool js::wasm::RenderNaN(StringBuffer& b, Raw<double> num);
+template MOZ_MUST_USE bool wasm::RenderNaN(StringBuffer& b, Raw<float> num);
+template MOZ_MUST_USE bool wasm::RenderNaN(StringBuffer& b, Raw<double> num);
--- a/js/src/wasm/WasmTextUtils.h
+++ b/js/src/wasm/WasmTextUtils.h
@@ -16,30 +16,93 @@
  * limitations under the License.
  */
 
 #ifndef wasm_text_utils
 #define wasm_text_utils
 
 #include "NamespaceImports.h"
 
-namespace js {
+#include "vm/StringBuffer.h"
 
-class StringBuffer;
-
+namespace js {
 namespace wasm {
 
 template<size_t base>
 MOZ_MUST_USE bool
 RenderInBase(StringBuffer& sb, uint64_t num);
 
 template<class T>
 class Raw;
 
 template<class T>
 MOZ_MUST_USE bool
 RenderNaN(StringBuffer& sb, Raw<T> num);
 
+// Helper class, StringBuffer wrapper, to track the position (line and column)
+// within the generated source.
+
+class WasmPrintBuffer
+{
+    StringBuffer& stringBuffer_;
+    uint32_t lineno_;
+    uint32_t column_;
+
+  public:
+    explicit WasmPrintBuffer(StringBuffer& stringBuffer)
+      : stringBuffer_(stringBuffer),
+        lineno_(1),
+        column_(1)
+    {}
+    inline char processChar(char ch) {
+        if (ch == '\n') {
+            lineno_++; column_ = 1;
+        } else
+            column_++;
+        return ch;
+    }
+    inline char16_t processChar(char16_t ch) {
+        if (ch == '\n') {
+            lineno_++; column_ = 1;
+        } else
+            column_++;
+        return ch;
+    }
+    bool append(const char ch) {
+        return stringBuffer_.append(processChar(ch));
+    }
+    bool append(const char16_t ch) {
+        return stringBuffer_.append(processChar(ch));
+    }
+    bool append(const char* str, size_t length) {
+        for (size_t i = 0; i < length; i++)
+            processChar(str[i]);
+        return stringBuffer_.append(str, length);
+    }
+    bool append(const char16_t* begin, const char16_t* end) {
+        for (const char16_t* p = begin; p != end; p++)
+            processChar(*p);
+        return stringBuffer_.append(begin, end);
+    }
+    bool append(const char16_t* str, size_t length) {
+        return append(str, str + length);
+    }
+    template <size_t ArrayLength>
+    bool append(const char (&array)[ArrayLength]) {
+        static_assert(ArrayLength > 0, "null-terminated");
+        MOZ_ASSERT(array[ArrayLength - 1] == '\0');
+        return append(array, ArrayLength - 1);
+    }
+    char16_t getChar(size_t index) {
+        return stringBuffer_.getChar(index);
+    }
+    size_t length() {
+        return stringBuffer_.length();
+    }
+    StringBuffer& stringBuffer() { return stringBuffer_; }
+    uint32_t lineno() { return lineno_; }
+    uint32_t column() { return column_; }
+};
+
 }  // namespace wasm
-
 }  // namespace js
 
 #endif // namespace wasm_text_utils