Skip to content

Commit

Permalink
integrate-bh-solver-into-web-fc-solve: merge; wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Aug 19, 2023
1 parent b9d8c01 commit 09e23e3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
/fc-solve/site/wml/lib/out-babel/js/*.js
/fc-solve/site/wml/lib/out-babel/js/tests/*.js
/fc-solve/site/wml/lib/repos/Solitairey/
/fc-solve/site/wml/lib/repos/black-hole-solitaire--build/
/fc-solve/site/wml/lib/repos/black-hole-solitaire/
/fc-solve/site/wml/lib/repos/rinutils-include/
/fc-solve/site/wml/lib/repos/rinutils/
/fc-solve/site/wml/lib/sgml/
Expand Down
36 changes: 33 additions & 3 deletions fc-solve/scripts/Makefile.to-javascript.mak
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ifeq ($(CMAKE_DIR),)
CMAKE_DIR := .
endif

BHS_SRC_DIR := ../../lib/repos/black-hole-solitaire/black-hole-solitaire/c-solver
BHS_CMAKE_DIR := ../../lib/repos/black-hole-solitaire--build
BHS_DEST_DIR := ./bhsolver-dest

BITCODE_EXT = o
DATA_DESTDIR ?= __DESTDIR
RESULT_NODE_JS_EXE = fc-solve.js
Expand Down Expand Up @@ -58,8 +62,21 @@ rate_state.c \

C_FILES = $(LIB_C_FILES)

BHS_LIB_C_FILES = \
fcs_hash.c \
meta_alloc.c \
rank_reach_prune.c \

BHS_cmakedir_C_FILES = \
can_move.c \
generated/lib.c \

BHS_C_FILES = $(BHS_LIB_C_FILES)

SRC_C_FILES = $(patsubst %.c,$(SRC_DIR)/%.c,$(C_FILES))
SRC_BHS_LIB_C_FILES = $(patsubst %.c,$(BHS_SRC_DIR)/%.c,$(BHS_LIB_C_FILES))
DEST_BHS_LLVM_BITCODE_FILES = $(patsubst %.c,$(BHS_DEST_DIR)/%.$(BITCODE_EXT),$(BHS_LIB_C_FILES))
DEST_BHS_cmakedir_LLVM_BITCODE_FILES = $(patsubst %.c,$(BHS_DEST_DIR)/%.$(BITCODE_EXT),$(BHS_cmakedir_C_FILES))
SRC_CMAKE_C_FILES = $(patsubst %.c,$(CMAKE_DIR)/%.c,$(CMAKE_C_FILES))
LLVM_BITCODE_FILES = $(patsubst %.c,%.$(BITCODE_EXT),$(C_FILES))
LLVM_BITCODE_LIB_FILES = $(patsubst %.c,%.$(BITCODE_EXT),$(LIB_C_FILES))
Expand All @@ -68,6 +85,8 @@ LLVM_BITCODE_CMAKE_FILES = $(patsubst %.c,%.$(BITCODE_EXT),$(CMAKE_C_FILES))
all: $(RESULT_JS_LIB)

NEEDED_FUNCTIONS = \
black_hole_solver_create \
black_hole_solver_free \
fc_solve__hll_ms_rand__get_singleton \
fc_solve__hll_ms_rand__init \
fc_solve__hll_ms_rand__mod_rand \
Expand Down Expand Up @@ -142,18 +161,29 @@ $(LLVM_BITCODE_FILES): %.$(BITCODE_EXT): $(SRC_DIR)/%.c $(INCLUDE_CFLAGS_FN)
mkdir -p "$$(dirname "$@")"
$(EMCC) $(EMCC_CFLAGS) $< -c -o $@

LLVM_AND_FILES_TARGETS = $(LLVM_BITCODE_FILES) $(LLVM_BITCODE_CMAKE_FILES)
# SRC_BHS_LIB_C_FILES = $(patsubst %.c,$(BHS_SRC_DIR)/%.c,$(BHS_LIB_C_FILES))
# DEST_BHS_LLVM_BITCODE_FILES = $(patsubst %.c,$(BHS_DEST_DIR)/%.$(BITCODE_EXT),$(BHS_LIB_C_FILES))

$(DEST_BHS_LLVM_BITCODE_FILES): $(BHS_DEST_DIR)/%.$(BITCODE_EXT): $(BHS_SRC_DIR)/%.c $(INCLUDE_CFLAGS_FN)
mkdir -p "$$(dirname "$@")"
$(EMCC) -I $(BHS_CMAKE_DIR) -I $(BHS_SRC_DIR)/include -I $(BHS_SRC_DIR) $(EMCC_CFLAGS) $< -c -o $@

$(DEST_BHS_cmakedir_LLVM_BITCODE_FILES): $(BHS_DEST_DIR)/%.$(BITCODE_EXT): $(BHS_CMAKE_DIR)/%.c $(INCLUDE_CFLAGS_FN)
mkdir -p "$$(dirname "$@")"
$(EMCC) -I $(BHS_CMAKE_DIR) -I $(BHS_SRC_DIR)/include -I $(BHS_SRC_DIR) $(EMCC_CFLAGS) $< -c -o $@

LLVM_AND_FILES_TARGETS = $(DEST_BHS_LLVM_BITCODE_FILES) $(LLVM_BITCODE_FILES) $(LLVM_BITCODE_CMAKE_FILES) $(DEST_BHS_cmakedir_LLVM_BITCODE_FILES)

$(LLVM_AND_FILES_TARGETS): $(RINUTILS_PIVOT)

$(RINUTILS_PIVOT):
rin="$$(perl -MPath::Tiny -e 'print path(shift)->absolute' "$(RINUTILS_DIR)")"; unset CFLAGS ; (git clone https://github.com/shlomif/rinutils && cd rinutils && mkdir b && cd b && cmake -DWITH_TEST_SUITE=OFF -DCMAKE_INSTALL_PREFIX="$$rin" .. && make && make install && cd ../.. && rm -fr rinutils)

$(RESULT_NODE_JS_EXE): $(LLVM_AND_FILES_TARGETS) $(INCLUDE_CFLAGS_FN) $(NEEDED_FUNCTIONS_STR__FN)
$(EMCC) $(EMCC_LDFLAGS) -o $@ $(LLVM_BITCODE_FILES) $(LLVM_BITCODE_CMAKE_FILES) $(EMCC_POST_FLAGS)
$(EMCC) $(EMCC_LDFLAGS) -o $@ $(LLVM_AND_FILES_TARGETS) $(EMCC_POST_FLAGS)

$(RESULT_JS_LIB): $(LLVM_AND_FILES_TARGETS) $(INCLUDE_CFLAGS_FN) $(NEEDED_FUNCTIONS_STR__FN)
$(EMCC) $(EMCC_LDFLAGS) -o $@ $(LLVM_BITCODE_LIB_FILES) $(LLVM_BITCODE_CMAKE_FILES) $(EMCC_POST_FLAGS)
$(EMCC) $(EMCC_LDFLAGS) -o $@ $(LLVM_AND_FILES_TARGETS) $(EMCC_POST_FLAGS)

clean:
rm -f $(LLVM_BITCODE_FILES) $(RESULT_NODE_JS_EXE)
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/site/wml/Tests/style-trailing-space.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ my $finder = Test::TrailingSpace->new(
|
(?: lib/repos/Solitairey )
|
(?: lib/repos/black-hole-solitaire--build )
|
(?:lib/out-babel/js/$bigint)
|
(?:
Expand Down
16 changes: 16 additions & 0 deletions fc-solve/site/wml/gen-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ qq#cd lib/repos/ && ( test -e rinutils || git clone https://github.com/shlomif/r
);
}

my $bhsolver = path("lib/repos/black-hole-solitaire--build")->absolute;
my $bhsolversrc = path("lib/repos/black-hole-solitaire")->absolute;
my $bhsolversrcsrc =
path("lib/repos/black-hole-solitaire/black-hole-solitaire/c-solver")
->absolute;

if ( not -e $bhsolver )
{
_exec(
[
qq#cd lib/repos/ && ( test -e black-hole-solitaire || git clone --recurse-submodules https://github.com/shlomif/black-hole-solitaire ) && mkdir "$bhsolver" && cd "$bhsolver" && cmake -DWITH_TEST_SUITE=OFF -DCMAKE_INSTALL_PREFIX="$bhsolver" "$bhsolversrcsrc" && cd ..#
],
"rinutils"
);
}

if ( not -e "lib/jquery/jquery-phoenix/" )
{
_exec(
Expand Down
20 changes: 20 additions & 0 deletions fc-solve/site/wml/src/ts/tests/fcs-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,26 @@ function my_func(qunit: QUnit, _my_mod, my_callback: () => void) {
);
}
});
qunit.test("black_hole_solver_create", (assert) => {
assert.expect(3);

const ptr_buf = module_wrapper.alloc_wrap(4 * 2, "ptr buf", "Seed");
{
const ret = module_wrapper.bh_create(ptr_buf);
// TEST
assert.equal(ret, 0, "bh_create ret");
}
const ptr_type: string = "i32";
const ptr = module_wrapper.Module.getValue(ptr_buf, ptr_type);
// TEST
assert.ok(ptr, "ptr");

{
const ret = module_wrapper.bh_free(ptr);
// TEST
assert.equal(ret, 0, "bh_free ret");
}
});
});

my_callback();
Expand Down
4 changes: 4 additions & 0 deletions fc-solve/site/wml/src/ts/web-fc-solve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { rank_re, suit_re } from "./french-cards";

export interface ModuleWrapper extends BaseApi.ModuleWrapper {
alloc_wrap: (size: number, desc: string, error: string) => number;
bh_create: (buffer: number) => number;
bh_free: (instance: number) => number;
c_free: (buffer: number) => number;
fc_solve_allocate_i8: (pointer: number) => number;
fc_solve_Pointer_stringify: (buffer: number) => string;
Expand Down Expand Up @@ -38,6 +40,8 @@ export function FC_Solve_init_wrappers_with_module(Module): ModuleWrapper {
module_wrapper.fc_solve_allocate_i8 = (p1) => {
return Module.allocate(p1, "i8", Module.ALLOC_STACK);
};
module_wrapper.bh_create = Module._black_hole_solver_create;
module_wrapper.bh_free = Module._black_hole_solver_free;
module_wrapper.user_alloc = Module._freecell_solver_user_alloc;
module_wrapper.user_solve_board = Module.cwrap(
"freecell_solver_user_solve_board",
Expand Down

0 comments on commit 09e23e3

Please sign in to comment.