有没有办法将预先编写的LLVM IR插入到模块中

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

我正在开发一个编译器,我的语言要求某些功能已经实现并可用。

例如,如果我想用我的语言(软件)实现堆栈,我将使用以下 IR:

@.stack = common global [1024 x i64]
@.sp = common global i64 0

define void @push(i64 %val) {
    %sp = load i64, i64* @.sp
    %addr = getelementptr [1024 x i64], [1024 x i64]* @.stack, i64 0, i64 %sp

    ; store the value
    store i64 %val, i64* %addr

    ; update the stack pointer
    %sp2 = add i64 %sp, 1
    store i64 %sp2, i64* @.sp

    ret void
}
[... other stack operations]

我只找到了通过创建

llvm::Function*
来做到这一点的方法,但代码对于我想要做的事情来说似乎有点冗长。

我将如何使用 LLVM API 直接插入此代码(以

std::string
const char*
的形式插入我的模块的开头(如果可能的话)?

c++ llvm
© www.soinside.com 2019 - 2024. All rights reserved.