Link wasm runtime status constructors
This commit is contained in:
@@ -151,6 +151,8 @@ if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
message(STATUS "LinuxCNC wasm blocked sources: ${linuxcnc_wasm_blocked_source_count}")
|
||||
|
||||
set(cnc_sim_wasm_safe_preinclude_options "SHELL:-include wctype.h")
|
||||
set(cnc_sim_wasm_safe_section_options -ffunction-sections -fdata-sections)
|
||||
set(cnc_sim_wasm_safe_link_options "-Wl,--gc-sections")
|
||||
if(EMSCRIPTEN)
|
||||
list(APPEND cnc_sim_wasm_safe_preinclude_options "SHELL:-include libgen.h")
|
||||
find_path(CNC_SIM_FMT_INCLUDE_DIR fmt/format.h
|
||||
@@ -166,7 +168,9 @@ if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/emc_status_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/gettext_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/linuxcnc_runtime_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/nml_status_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/python_c_api_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/rcs_print_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/rtapi_compat.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/tooldata/tooldata_mmap_backend.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/tooldata/tooldata_runtime_stubs.cc
|
||||
@@ -179,7 +183,10 @@ if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
)
|
||||
target_compile_features(linuxcnc_rs274_wasm_safe_probe_objects PUBLIC cxx_std_20)
|
||||
target_compile_definitions(linuxcnc_rs274_wasm_safe_probe_objects PRIVATE ULAPI)
|
||||
target_compile_options(linuxcnc_rs274_wasm_safe_probe_objects PRIVATE ${cnc_sim_wasm_safe_preinclude_options})
|
||||
target_compile_options(linuxcnc_rs274_wasm_safe_probe_objects PRIVATE
|
||||
${cnc_sim_wasm_safe_preinclude_options}
|
||||
${cnc_sim_wasm_safe_section_options}
|
||||
)
|
||||
target_include_directories(linuxcnc_rs274_wasm_safe_probe_objects
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
@@ -306,6 +313,7 @@ if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
ULAPI
|
||||
)
|
||||
target_compile_options(linuxcnc_rs274_wasm_safe_probe PRIVATE ${cnc_sim_wasm_safe_preinclude_options})
|
||||
target_link_options(linuxcnc_rs274_wasm_safe_probe PRIVATE ${cnc_sim_wasm_safe_link_options})
|
||||
target_include_directories(linuxcnc_rs274_wasm_safe_probe
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
@@ -332,6 +340,7 @@ if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
target_compile_features(cnc_sim_wasm_runtime_probe PRIVATE cxx_std_20)
|
||||
target_compile_definitions(cnc_sim_wasm_runtime_probe PRIVATE ULAPI)
|
||||
target_compile_options(cnc_sim_wasm_runtime_probe PRIVATE ${cnc_sim_wasm_safe_preinclude_options})
|
||||
target_link_options(cnc_sim_wasm_runtime_probe PRIVATE ${cnc_sim_wasm_safe_link_options})
|
||||
target_include_directories(cnc_sim_wasm_runtime_probe
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
@@ -492,6 +501,7 @@ if(EMSCRIPTEN)
|
||||
)
|
||||
|
||||
target_link_options(cnc_sim_wasm PRIVATE
|
||||
${cnc_sim_wasm_safe_link_options}
|
||||
"--no-entry"
|
||||
"-sMODULARIZE=1"
|
||||
"-sEXPORT_NAME=createCncSimModule"
|
||||
|
||||
@@ -78,6 +78,8 @@ int main() {
|
||||
const char program[] =
|
||||
"G21 G90 G17\n"
|
||||
"G0 X1\n"
|
||||
"F100\n"
|
||||
"G2 X2 Y0 I0.5 J0\n"
|
||||
"M30\n";
|
||||
if (cnc_sim_parse_program(sim, program, sizeof(program) - 1) != 0) {
|
||||
cnc_sim_destroy(sim);
|
||||
@@ -85,15 +87,20 @@ int main() {
|
||||
}
|
||||
|
||||
bool saw_linuxcnc_rapid = false;
|
||||
bool saw_linuxcnc_arc = false;
|
||||
bool saw_program_end = false;
|
||||
for (const auto &event : events) {
|
||||
saw_linuxcnc_rapid = saw_linuxcnc_rapid ||
|
||||
(event.type == CNC_SIM_EVENT_RAPID &&
|
||||
event.line == 2 &&
|
||||
near(event.end.x, 1.0));
|
||||
saw_linuxcnc_arc = saw_linuxcnc_arc ||
|
||||
(event.type == CNC_SIM_EVENT_ARC_FEED &&
|
||||
event.line == 4 &&
|
||||
near(event.end.x, 2.0));
|
||||
saw_program_end = saw_program_end || event.type == CNC_SIM_EVENT_PROGRAM_END;
|
||||
}
|
||||
|
||||
cnc_sim_destroy(sim);
|
||||
return saw_linuxcnc_rapid && saw_program_end ? 0 : 4;
|
||||
return saw_linuxcnc_rapid && saw_linuxcnc_arc && saw_program_end ? 0 : 4;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "nml_intf/emc_nml.hh"
|
||||
|
||||
EMC_STAT *emcStatus = nullptr;
|
||||
|
||||
// LinuxCNC src/emc/sai/dummyemcstat.cc uses the same source-backed status
|
||||
// object when the interpreter runs without the task controller.
|
||||
EMC_STAT *emcStatus = new EMC_STAT;
|
||||
|
||||
71
core/wasm_shims/nml_status_shim.cc
Normal file
71
core/wasm_shims/nml_status_shim.cc
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "libnml/nml/nmlmsg.hh"
|
||||
#include "libnml/nml/stat_msg.hh"
|
||||
#include "libnml/rcs/rcs_print.hh"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
int NMLmsg::automatically_clear = 1;
|
||||
|
||||
NMLmsg::NMLmsg(NMLTYPE t, long s) {
|
||||
_type = t;
|
||||
size = s;
|
||||
if (automatically_clear) {
|
||||
clear();
|
||||
}
|
||||
if (size < static_cast<long>(sizeof(NMLmsg))) {
|
||||
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
|
||||
size = sizeof(NMLmsg);
|
||||
}
|
||||
if (_type <= 0) {
|
||||
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
|
||||
}
|
||||
}
|
||||
|
||||
NMLmsg::NMLmsg(NMLTYPE t, size_t s) {
|
||||
_type = t;
|
||||
size = static_cast<long>(s);
|
||||
if (automatically_clear) {
|
||||
clear();
|
||||
}
|
||||
if (size < static_cast<long>(sizeof(NMLmsg))) {
|
||||
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
|
||||
size = sizeof(NMLmsg);
|
||||
}
|
||||
if (_type <= 0) {
|
||||
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
|
||||
}
|
||||
}
|
||||
|
||||
NMLmsg::NMLmsg(NMLTYPE t, long s, int noclear) {
|
||||
if (automatically_clear && !noclear) {
|
||||
clear();
|
||||
}
|
||||
_type = t;
|
||||
size = s;
|
||||
if (size < static_cast<long>(sizeof(NMLmsg))) {
|
||||
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
|
||||
size = sizeof(NMLmsg);
|
||||
}
|
||||
if (_type <= 0) {
|
||||
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
|
||||
}
|
||||
}
|
||||
|
||||
void NMLmsg::clear() {
|
||||
const long temp_size = size;
|
||||
const NMLTYPE temp_type = _type;
|
||||
std::memset(static_cast<void *>(this), 0, static_cast<size_t>(size));
|
||||
size = temp_size;
|
||||
_type = temp_type;
|
||||
if (size < static_cast<long>(sizeof(NMLmsg))) {
|
||||
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
|
||||
size = sizeof(NMLmsg);
|
||||
}
|
||||
}
|
||||
|
||||
RCS_STAT_MSG::RCS_STAT_MSG(NMLTYPE t, size_t sz) : NMLmsg(t, sz) {
|
||||
command_type = -1;
|
||||
echo_serial_number = -1;
|
||||
status = RCS_STATUS::UNINITIALIZED;
|
||||
_state = -1;
|
||||
}
|
||||
14
core/wasm_shims/rcs_print_shim.cc
Normal file
14
core/wasm_shims/rcs_print_shim.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
extern "C" int set_print_rcs_error_info(const char *, int) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int print_rcs_error_new(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
const int rc = std::vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user