Skip to content

Commit

Permalink
Refine variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
vacantron committed Aug 7, 2024
1 parent 6ab5812 commit 2b492f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/t2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ FORCE_INLINE void t2c_gen_call_io_func(LLVMValueRef start,
&io_param, 1, "");
}

static LLVMTypeRef t2c_cache_func_proto;
static LLVMTypeRef jit_cache_ty;
static LLVMTypeRef t2c_jit_cache_func_type;
static LLVMTypeRef t2c_jit_cache_struct_type;

#include "t2c_template.c"
#undef T2C_OP
Expand Down Expand Up @@ -260,12 +260,13 @@ void t2c_compile(riscv_t *rv, block_t *block)
module, "start", LLVMFunctionType(LLVMVoidType(), param_types, 1, 0));

LLVMTypeRef t2c_args[1] = {LLVMInt64Type()};
t2c_cache_func_proto = LLVMFunctionType(LLVMVoidType(), t2c_args, 1, false);
t2c_jit_cache_func_type =
LLVMFunctionType(LLVMVoidType(), t2c_args, 1, false);

/* Notice to the alignment */
LLVMTypeRef jit_cache_memb[2] = {LLVMInt64Type(),
LLVMPointerType(LLVMVoidType(), 0)};
jit_cache_ty = LLVMStructType(jit_cache_memb, 2, false);
t2c_jit_cache_struct_type = LLVMStructType(jit_cache_memb, 2, false);

LLVMBasicBlockRef first_block = LLVMAppendBasicBlock(start, "first_block");
LLVMBuilderRef first_builder = LLVMCreateBuilder();
Expand Down
16 changes: 8 additions & 8 deletions src/t2c_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
/* get jit-cache base address */
LLVMValueRef base = LLVMConstIntToPtr(
LLVMConstInt(LLVMInt64Type(), (long) rv->jit_cache, false),
LLVMPointerType(jit_cache_ty, 0));
LLVMPointerType(t2c_jit_cache_struct_type, 0));

/* get index */
LLVMValueRef hash = LLVMBuildAnd(
Expand All @@ -59,10 +59,10 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
/* get jit_cache_t::pc */
LLVMValueRef cast =
LLVMBuildIntCast2(*builder, hash, LLVMInt64Type(), false, "");
LLVMValueRef element_ptr =
LLVMBuildInBoundsGEP2(*builder, jit_cache_ty, base, &cast, 1, "");
LLVMValueRef pc_ptr =
LLVMBuildStructGEP2(*builder, jit_cache_ty, element_ptr, 0, "");
LLVMValueRef element_ptr = LLVMBuildInBoundsGEP2(
*builder, t2c_jit_cache_struct_type, base, &cast, 1, "");
LLVMValueRef pc_ptr = LLVMBuildStructGEP2(
*builder, t2c_jit_cache_struct_type, element_ptr, 0, "");
LLVMValueRef pc = LLVMBuildLoad2(*builder, LLVMInt32Type(), pc_ptr, "");

/* compare with calculated destination */
Expand All @@ -71,14 +71,14 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
LLVMBuildCondBr(*builder, cmp, true_path, false_path);

/* get jit_cache_t::entry */
LLVMValueRef entry_ptr =
LLVMBuildStructGEP2(true_builder, jit_cache_ty, element_ptr, 1, "");
LLVMValueRef entry_ptr = LLVMBuildStructGEP2(
true_builder, t2c_jit_cache_struct_type, element_ptr, 1, "");

/* invoke T2C JIT-ed code */
LLVMValueRef t2c_args[1] = {
LLVMConstInt(LLVMInt64Type(), (long) rv, false)};

LLVMBuildCall2(true_builder, t2c_cache_func_proto,
LLVMBuildCall2(true_builder, t2c_jit_cache_func_type,
LLVMBuildLoad2(true_builder, LLVMInt64Type(), entry_ptr, ""),
t2c_args, 1, "");
LLVMBuildRetVoid(true_builder);
Expand Down

0 comments on commit 2b492f4

Please sign in to comment.