-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert EMCC code to generate both libfreecell-solver and libfind-deal
optimization of a bare libfind-deal for https://fc-solve.shlomifish.org/js-fc-solve/find-deal/
- Loading branch information
Showing
17 changed files
with
243 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
fc-solve/site/wml/bin/gen_emcc_libs_makefile_fragments.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#! /usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use 5.014; | ||
use autodie; | ||
|
||
use Carp qw/ confess /; | ||
use Path::Tiny qw/ cwd path tempdir tempfile /; | ||
|
||
my $TEMPLATE = <<'EOF'; | ||
LIBFREECELL_SOLVER_JS_MEM_BASE = libfreecell-solver.wasm | ||
LIBFREECELL_SOLVER_JS_MEM_BASE__ASMJS = libfreecell-solver-asm.js.mem | ||
LIBFREECELL_SOLVER_JS_DIR := lib/freecell-solver-for-javascript | ||
LIBFREECELL_SOLVER_ASMJS_JS_DIR = $(LIBFREECELL_SOLVER_JS_DIR)-asmjs | ||
LIBFREECELL_SOLVER_WASM_STAMP := $(LIBFREECELL_SOLVER_JS_DIR)/finish.stamp | ||
LIBFREECELL_SOLVER_ASMJS_STAMP := $(LIBFREECELL_SOLVER_ASMJS_JS_DIR)/finish.stamp | ||
LIBFREECELL_SOLVER_JS = $(LIBFREECELL_SOLVER_JS_DIR)/libfreecell-solver.js | ||
LIBFREECELL_SOLVER_ASMJS_JS = $(LIBFREECELL_SOLVER_ASMJS_JS_DIR)/libfreecell-solver-asm.js | ||
DEST_LIBFREECELL_SOLVER_JS = $(DEST_JS_DIR)/libfreecell-solver.min.js | ||
DEST_LIBFREECELL_SOLVER_ASMJS_JS = $(DEST_JS_DIR)/libfreecell-solver-asm.js | ||
DEST_LIBFREECELL_SOLVER_JS_NON_MIN = $(DEST_JS_DIR)/libfreecell-solver.js | ||
DEST_LIBFREECELL_SOLVER_JS_MEM = $(patsubst %,%/$(LIBFREECELL_SOLVER_JS_MEM_BASE),$(DEST_mem_dirs)) | ||
DEST_LIBFREECELL_SOLVER_JS_MEM__ASMJS = $(patsubst %,%/$(LIBFREECELL_SOLVER_JS_MEM_BASE__ASMJS),$(DEST_mem_dirs)) | ||
LIBFREECELL_SOLVER_JS_DIR__CMAKE_DIR = $(LIBFREECELL_SOLVER_JS_DIR)/CMAKE-BUILD-dir | ||
LIBFREECELL_SOLVER_JS_DIR__CMAKE_CACHE = $(LIBFREECELL_SOLVER_JS_DIR__CMAKE_DIR)/CMakeCache.txt | ||
LIBFREECELL_SOLVER_JS_DIR__DESTDIR = $(PWD)/$(LIBFREECELL_SOLVER_JS_DIR)/__DESTDIR | ||
LIBFREECELL_SOLVER_JS_DIR__DESTDIR_DATA = $(LIBFREECELL_SOLVER_JS_DIR__DESTDIR)/fc-solve/share/freecell-solver/presetrc | ||
LIBFREECELL_SOLVER_JS_DIR__DESTDIR__ASMJS = $(PWD)/$(LIBFREECELL_SOLVER_ASMJS_JS_DIR)/__DESTDIR | ||
LIBFREECELL_SOLVER_FC_SOLVE_CMAKE_DIR := $(PWD)/$(LIBFREECELL_SOLVER_JS_DIR__CMAKE_DIR) | ||
ifeq ($(SKIP_EMCC),1) | ||
LIBFREECELL_SOLVER_JS__NODE__TARGETS = | ||
LIBFREECELL_SOLVER_JS__TARGETS = | ||
else | ||
LIBFREECELL_SOLVER_JS__NODE__TARGETS = lib/for-node/js/libfreecell-solver.min.js lib/for-node/js/libfreecell-solver-asm.js | ||
LIBFREECELL_SOLVER_JS__TARGETS = $(DEST_LIBFREECELL_SOLVER_JS) $(DEST_LIBFREECELL_SOLVER_JS_NON_MIN) $(DEST_LIBFREECELL_SOLVER_JS_MEM) $(DEST_LIBFREECELL_SOLVER_ASMJS_JS) $(DEST_LIBFREECELL_SOLVER_JS_MEM__ASMJS) | ||
endif | ||
real_all: $(LIBFREECELL_SOLVER_JS__TARGETS) | ||
$(DEST_LIBFREECELL_SOLVER_JS): $(LIBFREECELL_SOLVER_WASM_STAMP) | ||
cp -f $(LIBFREECELL_SOLVER_JS) $@ | ||
$(DEST_LIBFREECELL_SOLVER_ASMJS_JS): $(LIBFREECELL_SOLVER_ASMJS_STAMP) | ||
cp -f $(LIBFREECELL_SOLVER_ASMJS_JS) $@ | ||
$(LIBFREECELL_SOLVER_JS): $(LIBFREECELL_SOLVER_WASM_STAMP) | ||
LIBFREECELL_SOLVER_JS__gmake = gmake -j4 -f $(FC_SOLVE_SOURCE_DIR)/../scripts/Makefile.to-javascript.mak RINUTILS_DIR="$(PWD)/lib/repos/rinutils-include" SRC_DIR=$(FC_SOLVE_SOURCE_DIR) CMAKE_DIR=$(LIBFREECELL_SOLVER_FC_SOLVE_CMAKE_DIR) FIND_DEAL_ONLY=$(LIBFREECELL_SOLVER_build_only_flag) | ||
$(LIBFREECELL_SOLVER_WASM_STAMP): $(LIBFREECELL_SOLVER_JS_DIR__DESTDIR_DATA) | ||
( cd $(LIBFREECELL_SOLVER_JS_DIR) && $(LIBFREECELL_SOLVER_JS__gmake) ASMJS=0 && $(STRIP_TRAIL_SPACE) *.js ) | ||
touch $(LIBFREECELL_SOLVER_WASM_STAMP) | ||
$(LIBFREECELL_SOLVER_ASMJS_JS): $(LIBFREECELL_SOLVER_ASMJS_STAMP) | ||
$(LIBFREECELL_SOLVER_ASMJS_JS_DIR)/$(LIBFREECELL_SOLVER_JS_MEM_BASE__ASMJS): $(LIBFREECELL_SOLVER_ASMJS_STAMP) | ||
$(LIBFREECELL_SOLVER_ASMJS_STAMP): $(LIBFREECELL_SOLVER_JS_DIR__DESTDIR_DATA) | ||
( cd $(LIBFREECELL_SOLVER_ASMJS_JS_DIR) && $(LIBFREECELL_SOLVER_JS__gmake) ASMJS=1 DATA_DESTDIR=$(LIBFREECELL_SOLVER_JS_DIR__DESTDIR) && touch $(LIBFREECELL_SOLVER_JS_MEM_BASE__ASMJS) && $(STRIP_TRAIL_SPACE) *.js ) | ||
touch $@ | ||
$(LIBFREECELL_SOLVER_JS_DIR__CMAKE_CACHE): | ||
mkdir -p $(LIBFREECELL_SOLVER_JS_DIR__CMAKE_DIR) | ||
( cd $(LIBFREECELL_SOLVER_JS_DIR__CMAKE_DIR) && cmake -DCMAKE_INSTALL_PREFIX=/fc-solve $(FC_SOLVE_SOURCE_DIR) && make -j4 generate_c_files) | ||
$(DEST_LIBFREECELL_SOLVER_JS_NON_MIN): $(LIBFREECELL_SOLVER_JS) | ||
$(call COPY) | ||
$(DEST_LIBFREECELL_SOLVER_JS_MEM): %: $(LIBFREECELL_SOLVER_WASM_STAMP) | ||
cp -f $(LIBFREECELL_SOLVER_JS_DIR)/$(LIBFREECELL_SOLVER_JS_MEM_BASE) $@ | ||
$(DEST_LIBFREECELL_SOLVER_JS_MEM__ASMJS): %: $(LIBFREECELL_SOLVER_ASMJS_STAMP) | ||
cp -f $(LIBFREECELL_SOLVER_ASMJS_JS_DIR)/$(LIBFREECELL_SOLVER_JS_MEM_BASE__ASMJS) $@ | ||
EOF | ||
|
||
my $flagname = "LIBFREECELL_SOLVER_build_only_flag"; | ||
|
||
my $text = "$flagname = 0\n\n" . $TEMPLATE; | ||
my $find_deal_text = "$flagname = 1\n\n" . $TEMPLATE; | ||
my $FROM = "LIBFREECELL_SOLVER_JS_DIR__DESTDIR_DATA"; | ||
my $TO = "LIBFREECELL_SOLVER_JS_DIR__CMAKE_CACHE"; | ||
$find_deal_text =~ s#^\Q$FROM\E :?=[^\n]+\n##gms | ||
or Carp::confess("no matches!"); | ||
$find_deal_text =~ s#: \$\(\Q$FROM\E\)#: \$($TO)#gms | ||
or Carp::confess("no matches!"); | ||
|
||
$find_deal_text =~ s#LIBFREECELL_SOLVER#LIBFIND_DEAL#gms | ||
or Carp::confess("no matches!"); | ||
$find_deal_text =~ s#freecell-solver#find-deal#gms | ||
or Carp::confess("no matches!"); | ||
$text .= $find_deal_text; | ||
|
||
path("lib/make/generated/emcc_libs.mak")->touchpath()->spew_utf8($text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
function mydef(x, y) { | ||
if (typeof define !== 'function') { | ||
return require('amdefine')(module)(x, y); | ||
} else { | ||
return define(x, y); | ||
} | ||
} | ||
// Taken from https://stackoverflow.com/questions/47879864/ | ||
// thanks! | ||
const supported = (() => { | ||
try { | ||
if (typeof WebAssembly === "object" && | ||
typeof WebAssembly.instantiate === "function") { | ||
const module = new WebAssembly.Module( | ||
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); | ||
if (module instanceof WebAssembly.Module) { | ||
return (new WebAssembly.Instance(module) instanceof | ||
WebAssembly.Instance); | ||
} | ||
} | ||
} catch (e) { | ||
} | ||
return false; | ||
})(); | ||
|
||
mydef([(supported ? "libfind-deal.min" : | ||
// mydef([(false ? "libfind-deal.min" : | ||
"libfind-deal-asm")], function(M) { | ||
return M; | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
3 changes: 3 additions & 0 deletions
3
fc-solve/site/wml/lib/freecell-solver-for-javascript-asmjs/prefix.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define FREECELL_SOLVER_PREFIX "/fc-solve" | ||
|
||
#define FREECELL_SOLVER_PKG_DATA_DIR "/fc-solve/share/freecell-solver" |
Empty file.
3 changes: 3 additions & 0 deletions
3
fc-solve/site/wml/lib/freecell-solver-for-javascript/prefix.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define FREECELL_SOLVER_PREFIX "/fc-solve" | ||
|
||
#define FREECELL_SOLVER_PKG_DATA_DIR "/fc-solve/share/freecell-solver" |
Oops, something went wrong.