@@ -653,8 +653,7 @@ const char* stringAtAddr(Module& wasm,
653
653
654
654
std::string codeForConstAddr (Module& wasm,
655
655
std::vector<Address> const & segmentOffsets,
656
- Const* addrConst) {
657
- auto address = addrConst->value .geti32 ();
656
+ int32_t address) {
658
657
const char * str = stringAtAddr (wasm, segmentOffsets, address);
659
658
if (!str) {
660
659
// If we can't find the segment corresponding with the address, then we
@@ -710,7 +709,8 @@ struct AsmConstWalker : public LinearExecutionWalker<AsmConstWalker> {
710
709
711
710
private:
712
711
std::string fixupName (Name& name, std::string baseSig, Proxying proxy);
713
- AsmConst& createAsmConst (std::string code, std::string sig, Name name);
712
+ AsmConst&
713
+ createAsmConst (uint32_t id, std::string code, std::string sig, Name name);
714
714
std::string asmConstSig (std::string baseSig);
715
715
Name nameForImportWithSig (std::string sig, Proxying proxy);
716
716
void queueImport (Name importName, std::string baseSig);
@@ -757,29 +757,38 @@ void AsmConstWalker::visitCall(Call* curr) {
757
757
<< " .\n This might be caused by aggressive compiler "
758
758
" transformations. Consider using EM_JS instead." ;
759
759
}
760
- } else if (auto * value = arg->dynCast <Binary>()) {
761
- // In the dynamic linking case the address of the string constant
762
- // is the result of adding its offset to __memory_base.
763
- // In this case are only looking for the offset with the data segment so
764
- // the RHS of the addition is just what we want.
765
- assert (value->op == AddInt32);
766
- arg = value->right ;
767
- } else {
768
- if (!value) {
769
- Fatal () << " Unexpected arg0 type (" << getExpressionName (arg)
770
- << " ) in call to: " << importName;
760
+ continue ;
761
+ }
762
+
763
+ if (auto * setlocal = arg->dynCast <LocalSet>()) {
764
+ // The argument may be a local.tee, in which case we take first child
765
+ // which is the value being copied into the local.
766
+ if (setlocal->isTee ()) {
767
+ arg = setlocal->value ;
768
+ continue ;
771
769
}
772
770
}
771
+
772
+ if (auto * bin = arg->dynCast <Binary>()) {
773
+ if (bin->op == AddInt32) {
774
+ // In the dynamic linking case the address of the string constant
775
+ // is the result of adding its offset to __memory_base.
776
+ // In this case are only looking for the offset from __memory_base
777
+ // the RHS of the addition is just what we want.
778
+ arg = bin->right ;
779
+ continue ;
780
+ }
781
+ }
782
+
783
+ Fatal () << " Unexpected arg0 type (" << getExpressionName (arg)
784
+ << " ) in call to: " << importName;
773
785
}
774
786
775
787
auto * value = arg->cast <Const>();
776
- auto code = codeForConstAddr (wasm, segmentOffsets, value);
777
- auto & asmConst = createAsmConst (code, sig, importName);
788
+ int32_t address = value->value .geti32 ();
789
+ auto code = codeForConstAddr (wasm, segmentOffsets, address);
790
+ auto & asmConst = createAsmConst (address, code, sig, importName);
778
791
fixupName (curr->target , baseSig, asmConst.proxy );
779
-
780
- // Replace the first argument to the call with a Const index
781
- Builder builder (wasm);
782
- curr->operands [0 ] = builder.makeConst (Literal (asmConst.id ));
783
792
}
784
793
785
794
Proxying AsmConstWalker::proxyType (Name name) {
@@ -826,14 +835,15 @@ AsmConstWalker::fixupName(Name& name, std::string baseSig, Proxying proxy) {
826
835
return sig;
827
836
}
828
837
829
- AsmConstWalker::AsmConst&
830
- AsmConstWalker::createAsmConst (std::string code, std::string sig, Name name) {
838
+ AsmConstWalker::AsmConst& AsmConstWalker::createAsmConst (uint32_t id,
839
+ std::string code,
840
+ std::string sig,
841
+ Name name) {
831
842
if (asmConsts.count (code) == 0 ) {
832
843
AsmConst asmConst;
833
- asmConst.id = asmConsts. size () ;
844
+ asmConst.id = id ;
834
845
asmConst.sigs .insert (sig);
835
846
asmConst.proxy = proxyType (name);
836
-
837
847
asmConsts[code] = asmConst;
838
848
}
839
849
return asmConsts[code];
@@ -918,7 +928,8 @@ struct EmJsWalker : public PostWalker<EmJsWalker> {
918
928
Fatal () << " Unexpected generated __em_js__ function body: " << curr->name ;
919
929
}
920
930
auto * addrConst = consts.list [0 ];
921
- auto code = codeForConstAddr (wasm, segmentOffsets, addrConst);
931
+ int32_t address = addrConst->value .geti32 ();
932
+ auto code = codeForConstAddr (wasm, segmentOffsets, address);
922
933
codeByName[funcName] = code;
923
934
}
924
935
};
0 commit comments