ce13cf4e2929 — Vesa Norilo 5 months ago
update binaryen
M src/backends/BinaryenEmitter.cpp +14 -14
@@ 6,11 6,11 @@ 
 namespace K3 {
 	namespace Backends {
 		BinaryenExpressionRef BinaryenEmitter::FnArg(int i, BinaryenType ty) {
-			return BinaryenLocalGet(M, i, ty);
+			return BinaryenGetLocal(M, i, ty);
 		}
 
 		BinaryenExpressionRef BinaryenEmitter::FnArg(int i) {
-			return BinaryenLocalGet(M, i, BinaryenFunctionTypeGetParam(fn.d->ty, i));
+			return BinaryenGetLocal(M, i, BinaryenFunctionTypeGetParam(fn.d->ty, i));
 		}
 
 		int BinaryenEmitter::NumFnArgs() {

          
@@ 23,7 23,7 @@ namespace K3 {
 			if (!Mod->getGlobalOrNull(name)) {
 				BinaryenAddGlobal(M, name.c_str(), BinaryenTypeInt32(), 1, Const(0));
 			}
-			return BinaryenGlobalGet(M, name.c_str(), BinaryenTypeInt32());
+			return BinaryenGetGlobal(M, name.c_str(), BinaryenTypeInt32());
 		}
 
 		static void DeclareGVar(BinaryenModuleRef M, const std::string& name, BinaryenType ty, BinaryenExpressionRef constant = nullptr) {

          
@@ 42,7 42,7 @@ namespace K3 {
 
 		BinaryenExpressionRef BinaryenEmitter::GVar(const std::string& name, BinaryenType ty) {
 			DeclareGVar(M, name, ty);
-			b->instr.push_back(BinaryenGlobalGet(M, name.c_str(), ty));
+			b->instr.push_back(BinaryenGetGlobal(M, name.c_str(), ty));
 			return b->instr.back();
 		}
 

          
@@ 52,14 52,14 @@ namespace K3 {
 				DeclareGVar(M, name, BinaryenExpressionGetType(value), value);
 			} else {
 				DeclareGVar(M, name, BinaryenExpressionGetType(value), constant);
-				b->instr.push_back(BinaryenGlobalSet(M, name.c_str(), value));
+				b->instr.push_back(BinaryenSetGlobal(M, name.c_str(), value));
 			}
 		}
 
 
 		void BinaryenEmitter::SetSlot(int index, BinaryenExpressionRef val) {
 			Use(val);
-			b->instr.emplace_back(BinaryenGlobalSet(M, ("slot" + std::to_string(index)).c_str(), val));
+			b->instr.emplace_back(BinaryenSetGlobal(M, ("slot" + std::to_string(index)).c_str(), val));
 		}
 
 		BinaryenExpressionRef BinaryenEmitter::PtrToInt(BinaryenExpressionRef ptr) { return ptr; }

          
@@ 135,14 135,14 @@ namespace K3 {
 			outSubIdx = bitIdx % 32;
 			auto sigmask = "sigmask" + std::to_string(wordIdx);
 			DeclareGVar(M, sigmask, BinaryenTypeInt32());
-			return BinaryenGlobalGet(M, sigmask.c_str(), BinaryenTypeInt32());
+			return BinaryenGetGlobal(M, sigmask.c_str(), BinaryenTypeInt32());
 		}
 
 		void BinaryenEmitter::StoreSignalMaskWord(int bitIdx, BinaryenExpressionRef word) {
 			int wordIdx = bitIdx / 32;
 			auto sigmask = "sigmask" + std::to_string(wordIdx);
 			DeclareGVar(M, sigmask, BinaryenTypeInt32());
-			b->instr.push_back(BinaryenGlobalSet(M, sigmask.c_str(), word));
+			b->instr.push_back(BinaryenSetGlobal(M, sigmask.c_str(), word));
 		}
 
 		BinaryenExpressionRef BinaryenEmitter::NonZero(BinaryenExpressionRef v) {

          
@@ 212,8 212,8 @@ namespace K3 {
 				}
 
 				BinaryenExpressionRef saveStack[] = {
-					BinaryenLocalSet(d->M, BinaryenFunctionTypeGetNumParams(d->ty),
-					BinaryenGlobalGet(d->M, STACK_PTR, BinaryenTypeInt32())),
+					BinaryenSetLocal(d->M, BinaryenFunctionTypeGetNumParams(d->ty),
+					BinaryenGetGlobal(d->M, STACK_PTR, BinaryenTypeInt32())),
 					bl
 				};
 

          
@@ 501,9 501,9 @@ namespace K3 {
 		BinaryenExpressionRef BinaryenEmitter::GlobalExternal(BinaryenType t, const std::string& mod, const std::string& sym) {
 			auto Mod = (wasm::Module*)M;
 			if (Mod->getGlobalOrNull(sym) == nullptr) {
-				BinaryenAddGlobalImport(M, sym.c_str(), mod.c_str(), sym.c_str(), t, 0);
+				BinaryenAddGlobalImport(M, sym.c_str(), mod.c_str(), sym.c_str(), t);
 			}
-			return BinaryenGlobalGet(M, sym.c_str(), t);
+			return BinaryenGetGlobal(M, sym.c_str(), t);
 		}
 
 		BinaryenExpressionRef BinaryenEmitter::CallExternal(BinaryenType returnTy, const std::string& sym, const std::vector<BinaryenExpressionRef>& params) {

          
@@ 537,7 537,7 @@ namespace K3 {
 			auto fty = BinaryenAddFunctionType(M, nullptr, returnTy, paramTys.data(), (int)paramTys.size());
 
 			auto Mod = (wasm::Module*)M;
-			if (Mod->getFunctionOrNull(sym.c_str()) == nullptr) {
+			if (Mod->getImportOrNull(sym.c_str()) == nullptr) {
 				BinaryenAddFunctionImport(M, sym.c_str(), "import", sym.c_str(), fty);
 			}
 

          
@@ 547,7 547,7 @@ namespace K3 {
 			}
 #endif
 
-			auto fncall = BinaryenCall(M, sym.c_str(), (BinaryenExpressionRef*)pass.data(), (int)pass.size(), returnTy);
+			auto fncall = BinaryenCallImport(M, sym.c_str(), (BinaryenExpressionRef*)pass.data(), (int)pass.size(), returnTy);
 
 			if (returnByHeap) {
 				b->instr.emplace_back(fncall);

          
M src/backends/BinaryenEmitter.h +9 -9
@@ 87,12 87,12 @@ namespace K3 {
 						return;
 					}
 					KRONOS_UNREACHABLE;
-				} else if (BinaryenExpressionGetId(expr) == BinaryenLocalGetId() && 
-						   BinaryenLocalGetGetIndex(expr) < BinaryenFunctionTypeGetNumParams(fn.d->ty)) {
-					idx = BinaryenLocalGetGetIndex(expr);
+				} else if (BinaryenExpressionGetId(expr) == BinaryenGetLocalId() && 
+						   BinaryenGetLocalGetIndex(expr) < BinaryenFunctionTypeGetNumParams(fn.d->ty)) {
+					idx = BinaryenGetLocalGetIndex(expr);
 				} else {
 					idx = fn.LVar("", L.type);
-					b.instr.emplace_back(BinaryenLocalSet(fn.d->M, idx, expr));
+					b.instr.emplace_back(BinaryenSetLocal(fn.d->M, idx, expr));
 				}
 			}
 

          
@@ 101,7 101,7 @@ namespace K3 {
 					return BinaryenConst(M, L);
 				}
 				assert(L.type != BinaryenTypeNone());
-				return BinaryenLocalGet(M, idx, L.type);
+				return BinaryenGetLocal(M, idx, L.type);
 			}
 		};
 

          
@@ 245,7 245,7 @@ namespace K3 {
 			void Ret(BinaryenExpressionRef v = nullptr) {
 				auto retVal = v ? (BinaryenExpressionRef)TmpVar(v) : nullptr;
 				b->instr.emplace_back(
-					BinaryenGlobalSet(M, STACK_PTR, BinaryenLocalGet(M, BinaryenFunctionTypeGetNumParams(fn.d->ty), BinaryenTypeInt32())));
+					BinaryenSetGlobal(M, STACK_PTR, BinaryenGetLocal(M, BinaryenFunctionTypeGetNumParams(fn.d->ty), BinaryenTypeInt32())));
 				b->instr.emplace_back(BinaryenReturn(M, retVal));
 			}
 

          
@@ 374,16 374,16 @@ namespace K3 {
 			void Set(BinaryenIndex i, BinaryenExpressionRef val) {
 				Use(val);
 				assert(BinaryenExpressionGetType(val) != BinaryenTypeNone());
-				b->instr.push_back(BinaryenLocalSet(M, i, val));
+				b->instr.push_back(BinaryenSetLocal(M, i, val));
 			}
 
 			BinaryenExpressionRef Get(BinaryenIndex i, BinaryenType ty) {
 				assert(ty != BinaryenTypeNone());
-				return BinaryenLocalGet(M, i, ty);
+				return BinaryenGetLocal(M, i, ty);
 			}
 
 			BinaryenExpressionRef Get(BinaryenIndex i) {
-				return BinaryenLocalGet(M, i, fn.TypeOfVar(i - BinaryenFunctionTypeGetNumParams(fn.d->ty)));
+				return BinaryenGetLocal(M, i, fn.TypeOfVar(i - BinaryenFunctionTypeGetNumParams(fn.d->ty)));
 			}
 
 			BinaryenExpressionRef False() { return Const(0); }

          
M src/backends/BinaryenModule.cpp +17 -17
@@ 43,8 43,8 @@ namespace K3 {
 			if (flags & Kronos::BuildFlags::WasmStandaloneModule) {
 				StandaloneModule = true;
 			} else {
-				BinaryenAddGlobalImport(M, STATIC_DATA, "DS", "addr", BinaryenTypeInt32(), 0);
-				StaticData = BinaryenGlobalGet(M, STATIC_DATA, BinaryenTypeInt32());
+				BinaryenAddGlobalImport(M, STATIC_DATA, "DS", "addr", BinaryenTypeInt32());
+				StaticData = BinaryenGetGlobal(M, STATIC_DATA, BinaryenTypeInt32());
 			}
 
 			RegionAllocator alloc;

          
@@ 79,11 79,11 @@ namespace K3 {
 				std::string setter = "set_" + key.str(), getter = "get_" + key.str();
 
 				BinaryenAddFunction(M, setter.c_str(), slotSetterTy, nullptr, 0,
-									BinaryenGlobalSet(M, nm.c_str(),
-										BinaryenLocalGet(M, 0, BinaryenTypeInt32())));
+									BinaryenSetGlobal(M, nm.c_str(),
+										BinaryenGetLocal(M, 0, BinaryenTypeInt32())));
 
 				BinaryenAddFunction(M, getter.c_str(), slotGetterTy, nullptr, 0,
-									BinaryenGlobalGet(M, nm.c_str(), BinaryenTypeInt32()));
+									BinaryenGetGlobal(M, nm.c_str(), BinaryenTypeInt32()));
 
 				BinaryenAddFunctionExport(M, setter.c_str(), setter.c_str());
 				BinaryenAddFunctionExport(M, getter.c_str(), getter.c_str());

          
@@ 140,18 140,18 @@ namespace K3 {
 				auto addInstance = CreateFunction("AddInstance", Int32Ty(), { }, true);
 				{
 					BuilderTy b{ addInstance };
-					auto inst = b.TmpVar(BinaryenGlobalGet(M, HEAP_TOP, BinaryenTypeInt32()));
+					auto inst = b.TmpVar(BinaryenGetGlobal(M, HEAP_TOP, BinaryenTypeInt32()));
 					auto sz = b.TmpVar(b.PureCall(sizeExport, {}, false));
-					b.Sfx(BinaryenGlobalSet(M, HEAP_TOP, b.AddInt32(inst, sz)));
+					b.Sfx(BinaryenSetGlobal(M, HEAP_TOP, b.AddInt32(inst, sz)));
 					auto newSize = b.AddInt32(b.Const(16), b.DivSInt32(sz, b.Const(0x10000)));
-					b.Sfx(BinaryenHost(M, BinaryenMemoryGrow(), nullptr, &newSize, 1));
+					b.Sfx(BinaryenHost(M, BinaryenGrowMemory(), nullptr, &newSize, 1));
 					b.Ret(inst);
 				}
 
 				auto unwindStack = CreateFunction("UnwindStack", VoidTy(), {}, true);
 				{
 					BuilderTy b{ unwindStack };
-					b.Set(0, BinaryenGlobalGet(M, HEAP_TOP, BinaryenTypeInt32()));
+					b.Set(0, BinaryenGetGlobal(M, HEAP_TOP, BinaryenTypeInt32()));
 					b.Ret();
 				}
 

          
@@ 161,19 161,19 @@ namespace K3 {
 				BinaryenAddFunctionExport(M, "UnwindStack", "UnwindStack");
 				BinaryenAddGlobal(M, HEAP_TOP, BinaryenTypeInt32(), 1, BinaryenConst(M, BinaryenLiteralInt32((int)dataSegment.staticDataOffset)));
 			} else {
-				BinaryenAddMemoryImport(M, "mem", "import", "heap", 0);
+				BinaryenAddMemoryImport(M, "0", "import", "heap");
 			}
 
 			auto getStackPointer = CreateFunction("GetStackPointer", Int32Ty(), {}, true);
 			{
 				BuilderTy b{ getStackPointer };
-				b.Ret(BinaryenGlobalGet(M, STACK_PTR, BinaryenTypeInt32()));
+				b.Ret(BinaryenGetGlobal(M, STACK_PTR, BinaryenTypeInt32()));
 			}
 
 			auto setStackPointer = CreateFunction("SetStackPointer", VoidTy(), { Int32Ty() }, true);
 			{
 				BuilderTy b{ setStackPointer };
-				b.Sfx(BinaryenGlobalSet(M, STACK_PTR, b.FnArg(0)));
+				b.Sfx(BinaryenSetGlobal(M, STACK_PTR, b.FnArg(0)));
 				b.RetNoUnwind();
 			}
 

          
@@ 354,7 354,7 @@ namespace K3 {
 				sz = BinaryenUnary(M, BinaryenWrapInt64(), sz);
 			}		
 			
-			auto sp = BinaryenGlobalGet(M, STACK_PTR, BinaryenTypeInt32());
+			auto sp = BinaryenGetGlobal(M, STACK_PTR, BinaryenTypeInt32());
 
 			if (align > 4) {
 				sp =  BinaryenBinary(M, BinaryenAndInt32(), 

          
@@ 365,7 365,7 @@ namespace K3 {
 			auto mem = TmpVar(sp);
 			
 			sp = BinaryenBinary(M, BinaryenAddInt32(), mem, sz);
-			b->instr.emplace_back(BinaryenGlobalSet(M, STACK_PTR, sp));
+			b->instr.emplace_back(BinaryenSetGlobal(M, STACK_PTR, sp));
 			return mem;
 		}
 

          
@@ 382,7 382,7 @@ namespace K3 {
 		static BinaryenExpressionRef Relocatable(BinaryenModuleRef M, BinaryenExpressionRef offset) {
 			wasm::Module *mod = (wasm::Module*)M;
 			if (auto ds = mod->getGlobalOrNull(STATIC_DATA)) {
-				return BinaryenBinary(M, BinaryenAddInt32(), offset, BinaryenGlobalGet(M, STATIC_DATA, BinaryenTypeInt32()));
+				return BinaryenBinary(M, BinaryenAddInt32(), offset, BinaryenGetGlobal(M, STATIC_DATA, BinaryenTypeInt32()));
 			}
 			return offset;
 		}

          
@@ 429,7 429,7 @@ namespace K3 {
 
 			wasm::Module *mod = (wasm::Module*)M;
 			BinaryenExpressionRef segOffset[] = {
-				mod->getGlobalOrNull(STATIC_DATA) ? BinaryenGlobalGet(M, STATIC_DATA, BinaryenTypeInt32()) : BinaryenConst(M, BinaryenLiteralInt32(0))
+				mod->getGlobalOrNull(STATIC_DATA) ? BinaryenGetGlobal(M, STATIC_DATA, BinaryenTypeInt32()) : BinaryenConst(M, BinaryenLiteralInt32(0))
 			};
 
 			BinaryenIndex segSize[] = {

          
@@ 440,7 440,7 @@ namespace K3 {
 				0
 			};
 
-			BinaryenSetMemory(M, (((int)dataBlob.size() + 65536) / 65536), -1, memExportName, segData, segPassive, segOffset, segSize, 1, 0);
+			BinaryenSetMemory(M, (((int)dataBlob.size() + 65536) / 65536), 65535, memExportName, segData, segOffset, segSize, 1);
 			return dataBlob.size();
 		}