diff options
Diffstat (limited to 'src/passes/InstrumentMemory.cpp')
-rw-r--r-- | src/passes/InstrumentMemory.cpp | 138 |
1 files changed, 72 insertions, 66 deletions
diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp index a929478df..4a479db34 100644 --- a/src/passes/InstrumentMemory.cpp +++ b/src/passes/InstrumentMemory.cpp @@ -52,26 +52,26 @@ // ) // ) -#include <wasm.h> -#include <wasm-builder.h> -#include <pass.h> -#include "shared-constants.h" -#include "asmjs/shared-constants.h" #include "asm_v_wasm.h" +#include "asmjs/shared-constants.h" #include "ir/function-type-utils.h" +#include "shared-constants.h" +#include <pass.h> +#include <wasm-builder.h> +#include <wasm.h> namespace wasm { -static Name load_ptr("load_ptr"), - load_val_i32("load_val_i32"), - load_val_i64("load_val_i64"), - load_val_f32("load_val_f32"), - load_val_f64("load_val_f64"), - store_ptr("store_ptr"), - store_val_i32("store_val_i32"), - store_val_i64("store_val_i64"), - store_val_f32("store_val_f32"), - store_val_f64("store_val_f64"); +static Name load_ptr("load_ptr"); +static Name load_val_i32("load_val_i32"); +static Name load_val_i64("load_val_i64"); +static Name load_val_f32("load_val_f32"); +static Name load_val_f64("load_val_f64"); +static Name store_ptr("store_ptr"); +static Name store_val_i32("store_val_i32"); +static Name store_val_i64("store_val_i64"); +static Name store_val_f32("store_val_f32"); +static Name store_val_f64("store_val_f64"); // TODO: Add support for atomicRMW/cmpxchg @@ -79,66 +79,74 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> { void visitLoad(Load* curr) { id++; Builder builder(*getModule()); - curr->ptr = builder.makeCall(load_ptr, - { - builder.makeConst(Literal(int32_t(id))), - builder.makeConst(Literal(int32_t(curr->bytes))), - builder.makeConst(Literal(int32_t(curr->offset.addr))), - curr->ptr - }, - i32 - ); + curr->ptr = + builder.makeCall(load_ptr, + {builder.makeConst(Literal(int32_t(id))), + builder.makeConst(Literal(int32_t(curr->bytes))), + builder.makeConst(Literal(int32_t(curr->offset.addr))), + curr->ptr}, + i32); Name target; switch (curr->type) { - case i32: target = load_val_i32; break; - case i64: target = load_val_i64; break; - case f32: target = load_val_f32; break; - case f64: target = load_val_f64; break; - default: return; // TODO: other types, unreachable, etc. + case i32: + target = load_val_i32; + break; + case i64: + target = load_val_i64; + break; + case f32: + target = load_val_f32; + break; + case f64: + target = load_val_f64; + break; + default: + return; // TODO: other types, unreachable, etc. } - replaceCurrent(builder.makeCall(target, - { - builder.makeConst(Literal(int32_t(id))), - curr - }, - curr->type - )); + replaceCurrent(builder.makeCall( + target, {builder.makeConst(Literal(int32_t(id))), curr}, curr->type)); } void visitStore(Store* curr) { id++; Builder builder(*getModule()); - curr->ptr = builder.makeCall(store_ptr, - { builder.makeConst(Literal(int32_t(id))), - builder.makeConst(Literal(int32_t(curr->bytes))), - builder.makeConst(Literal(int32_t(curr->offset.addr))), - curr->ptr }, - i32 - ); + curr->ptr = + builder.makeCall(store_ptr, + {builder.makeConst(Literal(int32_t(id))), + builder.makeConst(Literal(int32_t(curr->bytes))), + builder.makeConst(Literal(int32_t(curr->offset.addr))), + curr->ptr}, + i32); Name target; switch (curr->value->type) { - case i32: target = store_val_i32; break; - case i64: target = store_val_i64; break; - case f32: target = store_val_f32; break; - case f64: target = store_val_f64; break; - default: return; // TODO: other types, unreachable, etc. + case i32: + target = store_val_i32; + break; + case i64: + target = store_val_i64; + break; + case f32: + target = store_val_f32; + break; + case f64: + target = store_val_f64; + break; + default: + return; // TODO: other types, unreachable, etc. } - curr->value = builder.makeCall(target, - { - builder.makeConst(Literal(int32_t(id))), - curr->value - }, - curr->value->type - ); + curr->value = + builder.makeCall(target, + {builder.makeConst(Literal(int32_t(id))), curr->value}, + curr->value->type); } - void visitModule(Module *curr) { - addImport(curr, load_ptr, "iiiii"); - addImport(curr, load_val_i32, "iii"); - addImport(curr, load_val_i64, "jij"); - addImport(curr, load_val_f32, "fif"); - addImport(curr, load_val_f64, "did"); - addImport(curr, store_ptr, "iiiii"); + void visitModule(Module* curr) { + addImport(curr, load_ptr, "iiiii"); + addImport(curr, load_val_i32, "iii"); + addImport(curr, load_val_i64, "jij"); + addImport(curr, load_val_f32, "fif"); + addImport(curr, load_val_f64, "did"); + addImport(curr, store_ptr, "iiiii"); addImport(curr, store_val_i32, "iii"); addImport(curr, store_val_i64, "jij"); addImport(curr, store_val_f32, "fif"); @@ -148,7 +156,7 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> { private: Index id; - void addImport(Module *curr, Name name, std::string sig) { + void addImport(Module* curr, Name name, std::string sig) { auto import = new Function; import->name = name; import->module = ENV; @@ -160,8 +168,6 @@ private: } }; -Pass *createInstrumentMemoryPass() { - return new InstrumentMemory(); -} +Pass* createInstrumentMemoryPass() { return new InstrumentMemory(); } } // namespace wasm |