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
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
get_filename_component(_EXEC_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
add_subdirectory("myjit")

foreach(i RANGE 1 3)
set(EXEC_NAME "${_EXEC_NAME}_demo_${i}")

set(Source_Files "demo${i}.c")
source_group("${EXEC_NAME} Source Files" FILES "${Source_Files}")

add_executable("${EXEC_NAME}" "${Source_Files}")
set_target_properties(
"${EXEC_NAME}"
PROPERTIES
LINKER_LANGUAGE
C
)
target_link_libraries("${EXEC_NAME}" PRIVATE "myjit")

# install rules

set(installable_libs "${EXEC_NAME}" "${PROJECT_NAME}_compiler_flags")

if (TARGET "${DEPENDANT_LIBRARY}")
list(APPEND installable_libs "${DEPENDANT_LIBRARY}")
endif ()
install(TARGETS ${installable_libs}
DESTINATION "bin"
EXPORT "${EXEC_NAME}Targets")
endforeach ()
68 changes: 68 additions & 0 deletions myjit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
get_filename_component(LIBRARY_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

set(Header_Files
"amd64-codegen.h"
"amd64-specific.h"
"arm32-codegen.h"
"arm32-specific.h"
"common86-codegen.h"
"common86-specific.h"
"cpu-detect.h"
"flow-analysis.h"
"jitlib-core.h"
"jitlib-debug.h"
"jitlib.h"
"llrb.h"
"reg-allocator.h"
"rmap.h"
"set.h"
"sparc-codegen.h"
"sparc-specific.h"
"sse2-specific.h"
"util.h"
"x86-codegen.h"
"x86-specific.h"
)
source_group("Header Files" FILES "${Header_Files}")

set(Source_Files
"code-check.c"
"jitlib-core.c"
"jitlib-debug.c"
"llrb.c"
"x86-common-stuff.c"
)
source_group("Source Files" FILES "${Source_Files}")

add_library("${LIBRARY_NAME}" "${LIBRARY_TYPE_FLAG}" "${Header_Files}" "${Source_Files}")
target_include_directories(
"${LIBRARY_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:include>"
)
set_target_properties(
"${LIBRARY_NAME}"
PROPERTIES
LINKER_LANGUAGE
C
)

# install rules
include(GenerateExportHeader)
set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}_export.h")
generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")

# setup the version numbering
set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "1.0.0")
set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "1")

set(installable_libs "${LIBRARY_NAME}" "${PROJECT_NAME}_compiler_flags")
install(FILES "${Header_Files}" DESTINATION "include")

if (TARGET "${DEPENDANT_LIBRARY}")
list(APPEND installable_libs "${DEPENDANT_LIBRARY}")
endif ()
install(TARGETS ${installable_libs}
DESTINATION "lib"
EXPORT "${LIBRARY_NAME}Targets")
7 changes: 7 additions & 0 deletions myjit/code-check.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "jitlib.h"
#include "jitlib-core.h"
#include "set.h"

/*
* MyJIT
* Copyright (C) 2015 Petr Krajca, <[email protected]>
Expand Down
17 changes: 9 additions & 8 deletions myjit/jitlib-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>

#include "jitlib.h"
#include "llrb.c"
#include "llrb.h"


#define FR_IMM (jit_mkreg(JIT_RTYPE_FLOAT, JIT_RTYPE_IMM, 0))
Expand Down Expand Up @@ -94,7 +95,7 @@ typedef struct jit_prepared_args {
int gp_args; // number of prepared GP arguments
int fp_args; // number od prepared FP arguments
int stack_size; // size of stack occupied by passed arguments
jit_op * op; // corresponding ``PREPARE'' operation
struct jit_op * op; // corresponding ``PREPARE'' operation
struct jit_out_arg {// array of arguments
union {
long generic;
Expand Down Expand Up @@ -175,9 +176,9 @@ int jit_optimize_join_addmul(struct jit * jit);
int jit_optimize_join_addimm(struct jit * jit);
void jit_optimize_frame_ptr(struct jit * jit);
void jit_optimize_unused_assignments(struct jit * jit);
static int is_cond_branch_op(jit_op *op); // FIXME: rename to: jit_op_is_cond_branch
static int is_cond_branch_op(struct jit_op *op); // FIXME: rename to: jit_op_is_cond_branch
static inline void jit_set_free(jit_set * s);
void jit_trace_callback(struct jit *jit, jit_op *op, int verbosity, int trace);
void jit_trace_callback(struct jit *jit, struct jit_op *op, int verbosity, int trace);

/**
* Initialize argpos-th argument.
Expand All @@ -191,11 +192,11 @@ void jit_init_arg_params(struct jit * jit, struct jit_func_info * info, int argp
void jit_assign_regs(struct jit * jit);
struct jit_reg_allocator * jit_reg_allocator_create();
void jit_reg_allocator_free(struct jit_reg_allocator * a);
void jit_gen_op(struct jit * jit, jit_op * op);
void jit_gen_op(struct jit * jit, struct jit_op * op);
char * jit_reg_allocator_get_hwreg_name(struct jit_reg_allocator * al, int reg);
int jit_reg_in_use(jit_op * op, int reg, int fp);
jit_hw_reg * jit_get_unused_reg(struct jit_reg_allocator * al, jit_op * op, int fp);
jit_hw_reg * jit_get_unused_reg_with_index(struct jit_reg_allocator * al, jit_op * op, int fp, int index);
int jit_reg_in_use(struct jit_op * op, int reg, int fp);
jit_hw_reg * jit_get_unused_reg(struct jit_reg_allocator * al, struct jit_op * op, int fp);
jit_hw_reg * jit_get_unused_reg_with_index(struct jit_reg_allocator * al, struct jit_op * op, int fp, int index);
void rmap_free(jit_rmap * regmap);
void jit_allocator_hints_free(jit_tree *);

Expand Down
19 changes: 1 addition & 18 deletions myjit/jitlib-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#define ABS(x) ((x) < 0 ? - (x) : x)

#include "llrb.c"
#include "llrb.h"

#define OUTPUT_BUF_SIZE (8192)
//#define print_padding(buf, size) while (strlen((buf)) < (size)) { strcat((buf), " "); }
Expand Down Expand Up @@ -158,23 +158,6 @@ static void compiler_based_debugger(struct jit * jit)
unlink(obj_file_name);
}

typedef struct jit_disasm {
char *indent_template;
char *reg_template;
char *freg_template;
char *arg_template;
char *farg_template;
char *reg_fp_template;
char *reg_out_template;
char *reg_imm_template;
char *reg_fimm_template;
char *reg_unknown_template;
char *label_template;
char *label_forward_template;
char *generic_addr_template;
char *generic_value_template;
} jit_disasm;

struct jit_disasm jit_disasm_general = {
.indent_template = " ",
.reg_template = "r%i",
Expand Down
46 changes: 46 additions & 0 deletions myjit/jitlib-debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* MyJIT
* Copyright (C) 2010, 2015, 2017, 2018 Petr Krajca, <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef JITLIB_DEBUG_H
#define JITLIB_DEBUG_H

#include "jitlib.h"
#include "llrb.h"
#include "jitlib-core.h"

typedef struct jit_disasm {
char *indent_template;
char *reg_template;
char *freg_template;
char *arg_template;
char *farg_template;
char *reg_fp_template;
char *reg_out_template;
char *reg_imm_template;
char *reg_fimm_template;
char *reg_unknown_template;
char *label_template;
char *label_forward_template;
char *generic_addr_template;
char *generic_value_template;
} jit_disasm;

int print_op(FILE *, struct jit_disasm *, struct jit_op *, jit_tree *, int);

#endif /* JITLIB_DEBUG_H */
4 changes: 3 additions & 1 deletion myjit/jitlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include "cpu-detect.h"
#include "jitlib-debug.h"

/*
* Memory management
Expand Down Expand Up @@ -650,4 +651,5 @@ static inline jit_op *jit_data_bytes(struct jit *jit, jit_value count, unsigned

int jit_regs_active_count(jit_op *op);
void jit_regs_active(jit_op *op, jit_value *dest);
#endif

#endif /* JITLIB_H */
19 changes: 3 additions & 16 deletions myjit/llrb.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


#ifndef LLRB_C
#define LLRB_C
#include <stdlib.h>
#include "jitlib.h"
#include "llrb.h"

#define RED (1)
#define BLACK (0)

typedef jit_value jit_tree_key;
typedef void * jit_tree_value;

typedef struct jit_tree {
struct jit_tree * left;
struct jit_tree * right;
int color;
jit_tree_key key;
jit_tree_value value;
} jit_tree;


static inline int is_red(jit_tree * n)
{
Expand Down Expand Up @@ -277,5 +266,3 @@ static int jit_tree_size(jit_tree *h)
if (h == NULL) return 0;
return jit_tree_size(h->left) + jit_tree_size(h->right) + 1;
}

#endif
34 changes: 34 additions & 0 deletions myjit/llrb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* MyJIT
* Copyright (C) 2010, 2015 Petr Krajca, <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef LLRB_H
#define LLRB_H

typedef jit_value jit_tree_key;
typedef void * jit_tree_value;

typedef struct jit_tree {
struct jit_tree * left;
struct jit_tree * right;
int color;
jit_tree_key key;
jit_tree_value value;
} jit_tree;

#endif /* LLRB_H */