libgccjit 导入函数

问题描述 投票:0回答:0

我正在使用 libgccjit 为我的测试构建一个即时函数。特别是,我想导入“memcpy”函数,但我不确定该怎么做。我目前从

https://gcc.gnu.org/onlinedocs/jit/topics/functions.html
的文档中猜测是使用
gcc_jit_context_get_builtin_function
导入 __builtin_memcpy。但我似乎不正确。 我现在的代码如下

void generate_memcpy_code(void){
    gcc_jit_context *ctxt;
    gcc_jit_type *void_ptr_type, *void_type, *int_type;
    gcc_jit_type *param_types[3];
    gcc_jit_param *params[3];
    gcc_jit_function *func;
    gcc_jit_block *block;
    gcc_jit_lvalue *dst_lval, *src_lval;
    gcc_jit_rvalue *size_val;

    ctxt = gcc_jit_context_acquire();

    void_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_VOID );
    void_ptr_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_VOID_PTR );
    int_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_INT );

    param_types[0] = void_ptr_type;
    param_types[1] = void_ptr_type;
    param_types[2] = int_type;

    params[0] = gcc_jit_context_new_param(ctxt, NULL, void_ptr_type, "dst");
    params[1] = gcc_jit_context_new_param(ctxt, NULL, void_ptr_type, "src");
    params[2] = gcc_jit_context_new_param(ctxt, NULL, int_type, "size");

    func = gcc_jit_context_new_function(ctxt, NULL,
        GCC_JIT_FUNCTION_EXPORTED,
        void_type,
        "my_memcpy",
        3, params,
        0 );

    block = gcc_jit_function_new_block(func, "body");

    dst_lval = gcc_jit_param_as_lvalue( gcc_jit_function_get_param(func, 0) );
    src_lval = gcc_jit_param_as_lvalue( gcc_jit_function_get_param(func, 1) );
    size_val = gcc_jit_param_as_rvalue( gcc_jit_function_get_param(func, 2) );

    gcc_jit_rvalue *args[3] = {
        gcc_jit_lvalue_as_rvalue(dst_lval),
        gcc_jit_lvalue_as_rvalue(src_lval),
        size_val
    };

    gcc_jit_rvalue *memcpy_call = gcc_jit_context_new_call(
        ctxt, NULL, gcc_jit_context_get_builtin_function(ctxt, "__builtin_memcpy"),
        3, args);

    gcc_jit_block_add_eval(block, NULL, memcpy_call);
    gcc_jit_context_compile(ctxt);
    gcc_jit_context_release(ctxt);
}

它编译但给我错误

libgccjit.so: error: unimplemented primitive type for builtin: 34
libgccjit.so: error: gcc_jit_context_new_call: NULL function
libgccjit.so: error: gcc_jit_block_add_eval: NULL rvalue
libgccjit.so: error: unterminated block in my_memcpy: body

我不确定如何导入 __builtin_memcpy 以及如何将参数传递给它。

c jit libgccjit
© www.soinside.com 2019 - 2024. All rights reserved.