Make generating atomics optional in translate-to-fuzz (#1513)
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 88785be..c433a81 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -120,7 +120,8 @@
std::cout << "shrink level: " << options.passOptions.shrinkLevel << '\n';
}
- void build() {
+ void build(bool initEmitAtomics = true) {
+ emitAtomics = initEmitAtomics;
setupMemory();
setupTable();
setupGlobals();
@@ -175,7 +176,7 @@
static const bool DE_NAN = true;
// Whether to emit atomics
- static const bool ATOMICS = true;
+ bool emitAtomics = true;
// Whether to emit atomic waits (which in single-threaded mode, may hang...)
static const bool ATOMIC_WAITS = false;
@@ -915,7 +916,7 @@
Expression* makeLoad(Type type) {
auto* ret = makeNonAtomicLoad(type);
if (type != i32 && type != i64) return ret;
- if (!ATOMICS || oneIn(2)) return ret;
+ if (!emitAtomics || oneIn(2)) return ret;
// make it atomic
wasm.memory.shared = true;
ret->isAtomic = true;
@@ -975,7 +976,7 @@
Store* makeStore(Type type) {
auto* ret = makeNonAtomicStore(type);
if (ret->value->type != i32 && ret->value->type != i64) return ret;
- if (!ATOMICS || oneIn(2)) return ret;
+ if (!emitAtomics || oneIn(2)) return ret;
// make it atomic
wasm.memory.shared = true;
ret->isAtomic = true;
@@ -1098,7 +1099,7 @@
case i32: {
switch (upTo(4)) {
case 0: {
- if (ATOMICS) {
+ if (emitAtomics) {
return makeUnary({ pick(EqZInt32, ClzInt32, CtzInt32, PopcntInt32, ExtendS8Int32, ExtendS16Int32), make(i32) });
} else {
return makeUnary({ pick(EqZInt32, ClzInt32, CtzInt32, PopcntInt32), make(i32) });
@@ -1114,7 +1115,7 @@
case i64: {
switch (upTo(4)) {
case 0: {
- if (ATOMICS) {
+ if (emitAtomics) {
return makeUnary({ pick(ClzInt64, CtzInt64, PopcntInt64, ExtendS8Int64, ExtendS16Int64, ExtendS32Int64), make(i64) });
} else {
return makeUnary({ pick(ClzInt64, CtzInt64, PopcntInt64), make(i64) });
@@ -1243,7 +1244,7 @@
}
Expression* makeAtomic(Type type) {
- if (!ATOMICS || (type != i32 && type != i64)) return makeTrivial(type);
+ if (!emitAtomics || (type != i32 && type != i64)) return makeTrivial(type);
wasm.memory.shared = true;
if (type == i32 && oneIn(2)) {
if (ATOMIC_WAITS && oneIn(2)) {