Browse Source

feat: klotski cli interface demo

legacy
Dnomd343 2 years ago
parent
commit
f77c4baed7
  1. 2
      CMakeLists.txt
  2. 6
      src/CMakeLists.txt
  3. 7
      src/demo.py
  4. 24
      src/klotski/CMakeLists.txt
  5. 14
      src/klotski/ffi/klotski.h
  6. 17
      src/klotski/ffi/tmain.cc
  7. 3
      src/main.c

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(klotski) project(klotski)
set(CMAKE_CXX_STANDARD 14) #set(CMAKE_CXX_STANDARD 14)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)

6
src/CMakeLists.txt

@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(klotski-cli LANGUAGES C)
include_directories(klotski/ffi) include_directories(klotski/ffi)
add_subdirectory(klotski) add_subdirectory(klotski)
add_executable(demo main.c) add_executable(cli main.c)
target_link_libraries(demo PUBLIC klotski) target_link_libraries(cli PUBLIC klotski)

7
src/demo.py

@ -0,0 +1,7 @@
#!/usr/bin/env python3
import ctypes
lib = ctypes.CDLL('../cmake-build-release/src/klotski/libklotski.so')
lib.tmain()

24
src/klotski/CMakeLists.txt

@ -32,22 +32,22 @@ add_subdirectory(fast_cal)
################################################################ ################################################################
add_library(klotski-core OBJECT ffi/codec.cc ffi/tmain.cc) add_library(klotski-ffi OBJECT ffi/codec.cc ffi/tmain.cc)
target_link_libraries(klotski-core utils) ################################################################
target_link_libraries(klotski-core all_cases)
target_link_libraries(klotski-core raw_code) add_library(klotski SHARED $<TARGET_OBJECTS:klotski-ffi>)
target_link_libraries(klotski-core short_code) #add_library(klotski STATIC $<TARGET_OBJECTS:klotski-core>)
target_link_libraries(klotski-core common_code)
target_link_libraries(klotski-core core) target_link_libraries(klotski PRIVATE utils)
target_link_libraries(klotski-core analyse) target_link_libraries(klotski PRIVATE all_cases)
target_link_libraries(klotski-core fast_cal)
################################################################ target_link_libraries(klotski PRIVATE raw_code)
target_link_libraries(klotski PRIVATE short_code)
target_link_libraries(klotski PRIVATE common_code)
#add_library(klotski SHARED $<TARGET_OBJECTS:klotski-core>) target_link_libraries(klotski PRIVATE core)
add_library(klotski STATIC $<TARGET_OBJECTS:klotski-core>) target_link_libraries(klotski PRIVATE analyse)
target_link_libraries(klotski PRIVATE fast_cal)
################################################################ ################################################################

14
src/klotski/ffi/klotski.h

@ -1,23 +1,21 @@
#pragma once #pragma once
/// klotski test interface
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// TODO: remove after test
void tmain(); extern void tmain();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/// klotski codec interface
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern void short_code_speed_up();
void short_code_speed_up(); extern void short_code_speed_up_fast();
void short_code_speed_up_fast();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

17
src/klotski/ffi/tmain.cc

@ -1,10 +1,20 @@
#include <iostream> /// WARN: c-style lib should not using `iostream`
/// using `printf` for screen output in test process
#include <cstdio>
#include <cstdint>
#include "klotski.h" #include "klotski.h"
#include "core.h" #include "common.h"
//#include "core.h"
void tmain() { void tmain() {
std::cout << "tmain start" << std::endl; printf("tmain start\n");
uint64_t common_code = 0x1A9BC0C00;
Common::range_reverse(common_code);
// uint64_t raw_code = 0x0603EDF5CAFFF5E2; // uint64_t raw_code = 0x0603EDF5CAFFF5E2;
@ -16,4 +26,5 @@ void tmain() {
// core.next_cases(raw_code, 0); // core.next_cases(raw_code, 0);
// } // }
printf("tmain exit\n");
} }

3
src/main.c

@ -2,9 +2,10 @@
#include "klotski.h" #include "klotski.h"
int main() { int main() {
// printf("interface test\n"); printf("cli boot\n");
tmain(); tmain();
printf("cli exit\n");
return 0; return 0;
} }

Loading…
Cancel
Save