mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Bug 1628835: Use RegExpShared in JSRegExp r=tcampbell
In preparation for actually compiling regexps in the next patch, hook up the V8 and irregexp representations of a compiled regexp. Differential Revision: https://phabricator.services.mozilla.com/D70694
This commit is contained in:
1 parent
b35e56e40a
commit
1712150f66
3 files changed
+38
-19
No files matched your search
@@ -17,6 +17,11 @@ class MatchPairs;
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class ByteArrayData {
|
||||
public:
|
||||
uint32_t length;
|
||||
uint8_t* data();
|
||||
};
|
||||
class Isolate;
|
||||
class RegExpStack;
|
||||
class RegExpStackScope;
|
||||
@@ -50,6 +55,8 @@ namespace irregexp {
|
||||
using Isolate = v8::internal::Isolate;
|
||||
using RegExpStack = v8::internal::RegExpStack;
|
||||
using RegExpStackScope = v8::internal::RegExpStackScope;
|
||||
using ByteArrayData = v8::internal::ByteArrayData;
|
||||
using ByteArray = js::UniquePtr<v8::internal::ByteArrayData, JS::FreePolicy>;
|
||||
using InputOutputData = v8::internal::InputOutputData;
|
||||
|
||||
} // namespace irregexp
|
||||
|
||||
@@ -547,12 +547,6 @@ class FixedArray : public HeapObject {
|
||||
inline static FixedArray cast(Object object) { MOZ_CRASH("TODO"); }
|
||||
};
|
||||
|
||||
class ByteArrayData {
|
||||
public:
|
||||
uint32_t length;
|
||||
uint8_t* data();
|
||||
};
|
||||
|
||||
/*
|
||||
* Conceptually, ByteArrayData is a variable-size structure. To
|
||||
* implement this in a C++-approved way, we allocate a struct
|
||||
@@ -767,7 +761,7 @@ class String : public HeapObject {
|
||||
JSString* str() const { return value_.toString(); }
|
||||
|
||||
public:
|
||||
String() : HeapObject() {}
|
||||
String() = default;
|
||||
String(JSString* str) { value_ = JS::StringValue(str); }
|
||||
|
||||
operator JSString*() const { return str(); }
|
||||
@@ -891,6 +885,9 @@ class MOZ_STACK_CLASS FlatStringReader {
|
||||
|
||||
class JSRegExp : public HeapObject {
|
||||
public:
|
||||
JSRegExp() : HeapObject() {}
|
||||
JSRegExp(js::RegExpShared* re) { value_ = JS::PrivateGCThingValue(re); }
|
||||
|
||||
// ******************************************************
|
||||
// Methods that are called from inside the implementation
|
||||
// ******************************************************
|
||||
@@ -898,10 +895,12 @@ class JSRegExp : public HeapObject {
|
||||
bool MarkedForTierUp() const {
|
||||
return false; /*inner()->markedForTierUp();*/
|
||||
}
|
||||
Object Bytecode(bool is_latin1) const {
|
||||
return Object(JS::PrivateValue(inner()->getByteCode(is_latin1)));
|
||||
}
|
||||
|
||||
// TODO: hook these up
|
||||
Object Code(bool is_latin1) const { return Object(JS::UndefinedValue()); }
|
||||
Object Bytecode(bool is_latin1) const { return Object(JS::UndefinedValue()); }
|
||||
|
||||
uint32_t BacktrackLimit() const {
|
||||
return 0; /*inner()->backtrackLimit();*/
|
||||
@@ -918,12 +917,6 @@ class JSRegExp : public HeapObject {
|
||||
// Static constants
|
||||
// ******************************
|
||||
|
||||
// Meaning of Type:
|
||||
// NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
|
||||
// ATOM: A simple string to match against using an indexOf operation.
|
||||
// IRREGEXP: Compiled with Irregexp.
|
||||
enum Type { NOT_COMPILED, ATOM, IRREGEXP };
|
||||
|
||||
// Maximum number of captures allowed.
|
||||
static constexpr int kMaxCaptures = 1 << 16;
|
||||
|
||||
@@ -945,9 +938,9 @@ class JSRegExp : public HeapObject {
|
||||
static constexpr int kNoBacktrackLimit = 0;
|
||||
|
||||
private:
|
||||
js::RegExpShared* inner() {
|
||||
return value_.toGCThing()->as<js::RegExpShared>();
|
||||
}
|
||||
js::RegExpShared* inner() const {
|
||||
return value_.toGCThing()->as<js::RegExpShared>();
|
||||
}
|
||||
};
|
||||
|
||||
class Histogram {
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
#include "js/RegExpFlags.h" // JS::RegExpFlag, JS::RegExpFlags
|
||||
#include "js/UbiNode.h"
|
||||
#include "js/Vector.h"
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
# include "new-regexp/RegExpTypes.h"
|
||||
#endif
|
||||
#include "vm/ArrayObject.h"
|
||||
#include "vm/JSAtom.h"
|
||||
|
||||
@@ -74,7 +77,13 @@ class RegExpShared : public gc::TenuredCell {
|
||||
enum ForceByteCodeEnum { DontForceByteCode, ForceByteCode };
|
||||
enum class Kind { Unparsed, Atom, RegExp };
|
||||
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
using ByteCode = js::irregexp::ByteArrayData;
|
||||
using JitCodeTable = js::irregexp::ByteArray;
|
||||
#else
|
||||
using ByteCode = uint8_t;
|
||||
using JitCodeTable = UniquePtr<uint8_t[], JS::FreePolicy>;
|
||||
#endif
|
||||
using JitCodeTables = Vector<JitCodeTable, 0, SystemAllocPolicy>;
|
||||
|
||||
private:
|
||||
@@ -83,7 +92,7 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
struct RegExpCompilation {
|
||||
WeakHeapPtr<jit::JitCode*> jitCode;
|
||||
uint8_t* byteCode = nullptr;
|
||||
ByteCode* byteCode = nullptr;
|
||||
|
||||
bool compiled(ForceByteCodeEnum force = DontForceByteCode) const {
|
||||
return byteCode || (force == DontForceByteCode && jitCode);
|
||||
@@ -91,8 +100,12 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
size_t byteCodeLength() const {
|
||||
MOZ_ASSERT(byteCode);
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
return byteCode->length;
|
||||
#else
|
||||
auto header = reinterpret_cast<RegExpByteCodeHeader*>(byteCode);
|
||||
return header->length;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -170,8 +183,14 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
// Use simple string matching for this regexp.
|
||||
void useAtomMatch(HandleAtom pattern);
|
||||
#endif
|
||||
void setByteCode(ByteCode* code, bool latin1) {
|
||||
compilation(latin1).byteCode = code;
|
||||
}
|
||||
ByteCode* getByteCode(bool latin1) const {
|
||||
return compilation(latin1).byteCode;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
JSAtom* getSource() const { return headerAndSource.ptr(); }
|
||||
|
||||
|
||||
Reference in new issue
Block a user