Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
93fcab8
initial commit of llvm-ir backend
bmdhacks Dec 14, 2025
12d3aba
Initial commit of aarch64 support
bmdhacks Dec 4, 2025
4faa017
now SDL solely uses GLES
bmdhacks Dec 15, 2025
01d2030
small compiler compatibility fix
bmdhacks Dec 18, 2025
77f5d35
fix spilling high floating point registers
bmdhacks Dec 19, 2025
1d3bb8e
fix arm64 jit
JamesKim2998 Dec 20, 2025
18c4154
various fixes and improvements for arm64 jit
JamesKim2998 Dec 20, 2025
e9930a9
harden hl_jit_free against double-free and use-after-free
JamesKim2998 Dec 20, 2025
ca2935a
fix arm64 jit: use RTMP2 for offset in op_get_mem to avoid clobbering…
JamesKim2998 Dec 20, 2025
c7e06e9
fix jit build: include stdbool.h for bool type in jit_ctx
JamesKim2998 Dec 20, 2025
0fc094f
fix arm64 jit: prevent using unsaved FP callee-saved registers (V8-V15)
JamesKim2998 Dec 20, 2025
08631a1
fixed misleading comment
JamesKim2998 Dec 20, 2025
fa06f72
fix arm64 jit: safety improvements and refactoring
JamesKim2998 Dec 20, 2025
bacb2bd
fix arm64 jit: implement exception type filtering and switch jump tables
JamesKim2998 Dec 20, 2025
db5e09f
fix arm64 jit: dereference global pointer for exception type check
JamesKim2998 Dec 20, 2025
b9a4f8b
macOS: Fix JIT crash on Apple Silicon
JamesKim2998 Dec 20, 2025
0288fa4
adjust ifdef to support __aarch64__
JamesKim2998 Dec 21, 2025
28798b5
fix arm64 mdbg: add missing semaphore signals and fix memory leaks
JamesKim2998 Dec 21, 2025
289848f
macOS: add debugger entitlements for ARM64
JamesKim2998 Dec 21, 2025
5cd677b
add ARM64 single-step tests: verify MDSCR_EL1.SS bit 0 usage
JamesKim2998 Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ node_modules
/*.tgz
args.txt
/other/benchs/hlc

/CLAUDE.md
/.claude
176 changes: 172 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ include(FindPkgConfig)
include(CTest)

set(WITH_VM_DEFAULT ON)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64" AND (NOT CMAKE_OSX_ARCHITECTURES MATCHES "x86_64"))
set(WITH_VM_DEFAULT OFF)
endif()
# VM now supports x86, x86-64, and AArch64 architectures

option(WITH_VM "Whether to build the Hashlink virtual machine" ${WITH_VM_DEFAULT})
option(WITH_LLVM_AOT "Whether to build the hl2llvm AOT compiler" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(BUILD_SHARED_LIBS)
# ensure third-party static libs are built with PIC
Expand Down Expand Up @@ -199,9 +198,24 @@ set_target_properties(libhl
)

if (WITH_VM)
# Select JIT backend based on architecture
# Note: macOS uses "arm64" while Linux uses "aarch64"
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(JIT_SOURCES
src/jit_aarch64.c
src/jit_aarch64_emit.c
src/jit_shared.c
)
else()
set(JIT_SOURCES
src/jit_x86.c
src/jit_shared.c
)
endif()

add_executable(hl
src/code.c
src/jit.c
${JIT_SOURCES}
src/main.c
src/module.c
src/debugger.c
Expand Down Expand Up @@ -236,6 +250,83 @@ else()
endif()
endif()

#####################
# LLVM AOT Compiler (hl2llvm)
if(WITH_LLVM_AOT)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

# LLVM definitions and includes
add_definitions(${LLVM_DEFINITIONS})

# Source files for hl2llvm
set(HL2LLVM_SOURCES
src/llvm/hl2llvm_main.c
src/llvm/llvm_codegen.c
src/llvm/llvm_types.c
src/llvm/llvm_runtime.c
src/llvm/llvm_ops_constants.c
src/llvm/llvm_ops_arith.c
src/llvm/llvm_ops_control.c
src/llvm/llvm_ops_memory.c
src/llvm/llvm_ops_calls.c
src/llvm/llvm_ops_closures.c
src/llvm/llvm_ops_types.c
src/llvm/llvm_ops_objects.c
src/llvm/llvm_ops_enums.c
src/llvm/llvm_ops_refs.c
src/llvm/llvm_ops_exceptions.c
src/llvm/llvm_ops_misc.c
src/code.c
)

add_executable(hl2llvm ${HL2LLVM_SOURCES})

# AOT runtime library (provides module loading for AOT binaries)
add_library(aot_runtime STATIC
src/llvm/aot_runtime.c
src/module.c
src/code.c
)
target_include_directories(aot_runtime PRIVATE src)
target_link_libraries(aot_runtime libhl)

# Make hl2llvm depend on aot_runtime so both are built together
add_dependencies(hl2llvm aot_runtime)

target_include_directories(hl2llvm
PRIVATE
src
${LLVM_INCLUDE_DIRS}
)

# Get LLVM libraries
llvm_map_components_to_libnames(LLVM_LIBS
core
analysis
bitwriter
target
${LLVM_TARGETS_TO_BUILD}
)

target_link_libraries(hl2llvm
libhl
${LLVM_LIBS}
)

if(APPLE)
set_target_properties(hl2llvm PROPERTIES
INSTALL_RPATH "@executable_path;@executable_path/../${CMAKE_INSTALL_LIBDIR}"
)
elseif(UNIX)
set_target_properties(hl2llvm PROPERTIES
INSTALL_RPATH "$ORIGIN;$ORIGIN/../${CMAKE_INSTALL_LIBDIR}"
)
endif()

endif()

if(BUILD_TESTING)

find_program(
Expand Down Expand Up @@ -402,6 +493,80 @@ if(BUILD_TESTING)
add_test(NAME uvsample.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl 6001
)

#####################
# Minimal JIT Tests
# These test individual opcodes without pulling in the Haxe stdlib

# Common sources for all minimal JIT tests
set(MINIMAL_JIT_SOURCES
src/code.c
${JIT_SOURCES}
src/module.c
src/debugger.c
src/profile.c
)

# Macro to add a minimal JIT test
macro(add_minimal_jit_test name)
add_executable(${name}
${CMAKE_SOURCE_DIR}/other/tests/minimal/${name}.c
${MINIMAL_JIT_SOURCES}
)
target_include_directories(${name}
PRIVATE ${CMAKE_SOURCE_DIR}/other/tests/minimal
)
target_link_libraries(${name}
libhl
)
set_target_properties(${name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/minimal
)
add_test(NAME ${name} COMMAND ${name})
endmacro()

# Add all minimal JIT tests
add_minimal_jit_test(test_int_ops)
add_minimal_jit_test(test_float_ops)
add_minimal_jit_test(test_bool_ops)
add_minimal_jit_test(test_control_flow)
add_minimal_jit_test(test_i64_ops)
add_minimal_jit_test(test_calls)
add_minimal_jit_test(test_strings)
add_minimal_jit_test(test_globals)
add_minimal_jit_test(test_natives)
add_minimal_jit_test(test_closures)
add_minimal_jit_test(test_objects)
add_minimal_jit_test(test_dynamic)
add_minimal_jit_test(test_callbacks)
add_minimal_jit_test(test_native_field)
add_minimal_jit_test(test_binop_inplace)
add_minimal_jit_test(test_enum)
add_minimal_jit_test(test_instance_closure)
add_minimal_jit_test(test_memory_ops)
add_minimal_jit_test(test_array_ops)
add_minimal_jit_test(test_ref_ops)
add_minimal_jit_test(test_unsigned_ops)
add_minimal_jit_test(test_switch)
add_minimal_jit_test(test_jumps_unsigned)
add_minimal_jit_test(test_type_ops)
add_minimal_jit_test(test_exceptions)
add_minimal_jit_test(test_methods)
add_minimal_jit_test(test_virtual_fields)
add_minimal_jit_test(test_fp_pressure)

# Bytecode dump utility (needs code.c for hl_code_read)
add_executable(hldump
${CMAKE_SOURCE_DIR}/other/tests/minimal/hldump.c
${CMAKE_SOURCE_DIR}/src/code.c
)
target_link_libraries(hldump libhl)
set_target_properties(hldump
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/minimal
)

endif()

add_test(NAME hello
Expand Down Expand Up @@ -442,6 +607,9 @@ set(INSTALL_TARGETS libhl)
if (WITH_VM)
list(APPEND INSTALL_TARGETS hl)
endif()
if (WITH_LLVM_AOT)
list(APPEND INSTALL_TARGETS hl2llvm)
endif()

install(
TARGETS
Expand Down
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ STD = src/std/array.o src/std/buffer.o src/std/bytes.o src/std/cast.o src/std/da
src/std/socket.o src/std/string.o src/std/sys.o src/std/types.o src/std/ucs2.o src/std/thread.o src/std/process.o \
src/std/track.o

HL = src/code.o src/jit.o src/main.o src/module.o src/debugger.o src/profile.o
# Conditional JIT backend selection based on architecture
ifeq ($(ARCH),aarch64)
HL_JIT = src/jit_aarch64.o src/jit_aarch64_emit.o src/jit_shared.o
else ifeq ($(ARCH),arm64)
HL_JIT = src/jit_aarch64.o src/jit_aarch64_emit.o src/jit_shared.o
else
HL_JIT = src/jit_x86.o src/jit_shared.o
endif

HL = src/code.o $(HL_JIT) src/main.o src/module.o src/debugger.o src/profile.o

FMT_INCLUDE = -I include/mikktspace -I include/minimp3

Expand Down Expand Up @@ -222,19 +231,12 @@ ifdef DEBUG
CFLAGS += -g
endif

all: libhl libs
ifeq ($(ARCH),arm64)
$(warning HashLink vm is not supported on arm64, skipping)
else
all: hl
endif
all: libhl libs hl

install:
$(UNAME)==Darwin && ${MAKE} uninstall
ifneq ($(ARCH),arm64)
mkdir -p $(INSTALL_BIN_DIR)
cp hl $(INSTALL_BIN_DIR)
endif
mkdir -p $(INSTALL_LIB_DIR)
cp *.hdll $(INSTALL_LIB_DIR)
cp libhl.${LIBEXT} $(INSTALL_LIB_DIR)
Expand Down
2 changes: 1 addition & 1 deletion include/mdbg/mach_excServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/* Module mach_exc */

#ifdef __x86_64__
#if defined(__x86_64__) || defined(__aarch64__)

#define __MIG_check__Request__mach_exc_subsystem__ 1

Expand Down
2 changes: 1 addition & 1 deletion include/mdbg/mach_excUser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OPTIONS:
*/

#ifdef __x86_64__
#if defined(__x86_64__) || defined(__aarch64__)

#define __MIG_check__Reply__mach_exc_subsystem__ 1

Expand Down
Loading