Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/sljit"]
path = vendor/sljit
url = https://github.com/zherczeg/sljit
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ file(GLOB PLATFORM_SOURCES src/${PLATFORM}/*.c)
add_executable(butterscotch ${SOURCES} ${PLATFORM_SOURCES})
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src)

option(USE_JIT "Enable JIT compilation" ON)
if(USE_JIT)
add_compile_definitions(USE_JIT SLJIT_HAVE_CONFIG_PRE=1)
target_include_directories(butterscotch PRIVATE vendor/sljit/sljit_src)
target_sources(butterscotch PRIVATE vendor/sljit/sljit_src/sljitLir.c)
target_compile_definitions(butterscotch PRIVATE SLJIT_CONFIG_AUTO=1)
endif()

# stb_ds
target_include_directories(butterscotch PUBLIC vendor/stb/ds)

Expand Down
8 changes: 7 additions & 1 deletion src/data_win.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "data_win.h"
#include "binary_reader.h"

#include "vm_jit.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -1111,6 +1111,7 @@ static void parseCODE(BinaryReader* reader, DataWin* dw, uint32_t chunkLength, s
entry->bytecodeAbsoluteOffset = (uint32_t)((int64_t)relAddrFieldPos + bytecodeRelAddr);

entry->offset = BinaryReader_readUint32(reader);
entry->jitCode = NULL;
}
free(codePtrs);

Expand Down Expand Up @@ -1615,6 +1616,11 @@ void DataWin_free(DataWin* dw) {
hmfree(dw->tpagOffsetMap);

// CODE
#ifdef USE_JIT
repeat(dw->code.count, i) {
VM_jitFree(&dw->code.entries[i]);
}
#endif
free(dw->code.entries);

// VARI
Expand Down
1 change: 1 addition & 0 deletions src/data_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ typedef struct {
uint16_t argumentsCount;
uint32_t bytecodeAbsoluteOffset;
uint32_t offset;
void* jitCode;
} CodeEntry;

typedef struct {
Expand Down
19 changes: 19 additions & 0 deletions src/sljitConfigPre.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef SLJIT_CONFIG_PRE_H_
#define SLJIT_CONFIG_PRE_H_

#ifdef PS2
#include <kernel.h>
#include <malloc.h>

/* PS2-specific SLJIT configuration */
#define SLJIT_UTIL_STACK 0
#define SLJIT_EXECUTABLE_ALLOCATOR 0
#define SLJIT_MALLOC_EXEC(size, exec_allocator_data) malloc(size)
#define SLJIT_FREE_EXEC(ptr, exec_allocator_data) free(ptr)

/* Cache flush for Emotion Engine (MIPS) */
#define SLJIT_CACHE_FLUSH(from, to) FlushCache(0)

#endif

#endif /* SLJIT_CONFIG_PRE_H_ */
Loading