f17f8b390dd2 — Vesa Norilo 2 years ago
Binaryen backend: function import fix
7 files changed, 62 insertions(+), 27 deletions(-)

R .build.yml => 
A => .builds/ubuntu.build
A => .builds/wasm.build
M CMakeLists.txt
M cmake/Binaryen.cmake
M src/backends/BinaryenEmitter.cpp
M src/backends/BinaryenModule.cpp
R .build.yml =>  +0 -23
@@ 1,23 0,0 @@ 
-image: ubuntu/20.04
-packages:
-- cmake
-sources:
-- hg+https://hg.sr.ht/~vnorilo/kronos
-tasks:
-- configure: |
-    set -ex
-    git clone --depth 1 https://github.com/emscripten-core/emsdk.git
-    emsdk/emsdk install latest
-    emsdk/emsdk activate latest
-    chmod 777 emsdk/emsdk_env.sh
-    . ./emsdk/emsdk_env.sh 
-    mkdir build
-    cd build
-    emcmake cmake ../kronos -DCMAKE_BUILD_TYPE=Release
-- build: |
-    cd build
-    make -j
-triggers:
-- action: email
-  condition: failure
-  to: <vn@imap.cc>
  No newline at end of file

          
A => .builds/ubuntu.build +19 -0
@@ 0,0 1,19 @@ 
+image: ubuntu/20.04
+packages:
+- cmake g++ python3 libsndfile-dev libtinyxml-dev libreadline6-dev llvm-6.0-dev
+sources:
+- hg+https://hg.sr.ht/~vnorilo/kronos
+tasks:
+- configure: |
+    mkdir build
+    cd build
+    emcmake cmake ../kronos -DCMAKE_BUILD_TYPE=Release
+- build: |
+    cd build
+    make -j kronos veneer
+- test: |
+    make test
+triggers:
+- action: email
+  condition: failure
+  to: <vn@imap.cc>
  No newline at end of file

          
A => .builds/wasm.build +23 -0
@@ 0,0 1,23 @@ 
+image: ubuntu/20.04
+packages:
+- cmake
+sources:
+- hg+https://hg.sr.ht/~vnorilo/kronos
+tasks:
+- configure: |
+    set -ex
+    git clone --depth 1 https://github.com/emscripten-core/emsdk.git
+    emsdk/emsdk install latest
+    emsdk/emsdk activate latest
+    chmod 777 emsdk/emsdk_env.sh
+    . ./emsdk/emsdk_env.sh 
+    mkdir build
+    cd build
+    emcmake cmake ../kronos -DCMAKE_BUILD_TYPE=Release
+- build: |
+    cd build
+    make -j kronos veneer
+triggers:
+- action: email
+  condition: failure
+  to: <vn@imap.cc>
  No newline at end of file

          
M CMakeLists.txt +1 -1
@@ 263,7 263,7 @@ function(add_o2)
     set(BUILD_WITH_MESSAGE_PRINT OFF)
     set(BUILD_WITH_O2LITE_DISCOVERY OFF)
     set(BUILD_WITH_O2LITE_CLOCKSYNC OFF)
-	add_definitions("-DO2_EXPORT=extern" -DO2L_NO_BROADCAST -DO2_NO_O2DISCOVERY)
+	add_definitions("-DO2_EXPORT=extern" -DO2L_NO_BROADCAST -DO2_NO_ZEROCONF)
 
 	add_subdirectory(${O2_DIR} o2)
 	set_target_properties(o2_static o2lite_static PROPERTIES FOLDER libs)

          
M cmake/Binaryen.cmake +5 -1
@@ 23,7 23,11 @@ ExternalProject_Add(
 	GIT_REPOSITORY https://github.com/WebAssembly/binaryen.git
 	GIT_TAG ${BINARYEN_VERSION}
 	CMAKE_COMMAND "${CMAKE_CMD}"
-	CMAKE_ARGS ${CMAKE_ARGS} -DCMAKE_CXX_STANDARD=17
+	CMAKE_ARGS 
+		${CMAKE_ARGS}
+		"-DCMAKE_CXX_STANDARD=17" 
+		"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" 
+		"-DCMAKE_CONFIGURATION_TYPES=${CMAKE_CONFIGURATION_TYPES}"
 	BUILD_COMMAND cmake --build . --target binaryen --config $<CONFIG>
 	INSTALL_COMMAND "")
 

          
M src/backends/BinaryenEmitter.cpp +2 -1
@@ 551,7 551,8 @@ namespace K3 {
 
 			auto Mod = (wasm::Module*)M;
 			if (Mod->getFunctionOrNull(sym.c_str()) == nullptr) {
-				BinaryenAddFunctionImport(M, sym.c_str(), "import", sym.c_str(), fn.d->GetParamType(), fn.d->ty.returnType);
+				auto paramTypes = BinaryenTypeCreate(paramTys.data(), paramTys.size());
+				BinaryenAddFunctionImport(M, sym.c_str(), "import", sym.c_str(), paramTypes, returnTy);
 			}
 
 			auto fncall = BinaryenCall(M, sym.c_str(), (BinaryenExpressionRef*)pass.data(), (int)pass.size(), returnTy);

          
M src/backends/BinaryenModule.cpp +12 -1
@@ 245,16 245,27 @@ namespace K3 {
 
 			BinaryenModuleAutoDrop(M);
 #ifndef NDEBUG
-			BinaryenModuleValidate(M);
+			if (!BinaryenModuleValidate(M)) {
+				std::cerr << "Invalid code emitted!";
+			}
+			BinaryenModulePrint(M);
 #endif
 #ifdef EMSCRIPTEN
 			std::clog << "Optimizing code...\n";
 #endif
 			if (CL::OptLevel() > 0) {
 				BinaryenSetOptimizeLevel(CL::OptLevel());
+				BinaryenSetFastMath(true);
+				BinaryenSetAllowInliningFunctionsWithLoops(true);
 				BinaryenModuleOptimize(M);
 			}
 
+#ifndef NDEBUG
+			if (!BinaryenModuleValidate(M)) {
+				std::cerr << "Invalid code after optimizer!";
+			}
+#endif
+
 #ifdef EMSCRIPTEN
 			std::clog << "Emitting...\n";
 #endif