如何定义字符串类型在getOrInsertFunction()llvm? [英] How to define string type in getOrInsertFunction() llvm?

查看:595
本文介绍了如何定义字符串类型在getOrInsertFunction()llvm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是llvm的新手,正在尝试做乐器。但我发现LLVM API只有原始类型,如:getInt32Ty(Ctx)..我想做什么使用getOrInsertFunction(),函数参数类型是字符串type.As是已知的,当参数类型是int,我们可以做like is:

I'm new to llvm and was trying to do instrument. But I found LLVM API only has primitive types, like: getInt32Ty(Ctx).. What i want to do use getOrInsertFunction(),the function argument type is string type.As is known, when argument type is int, we can do it like is :

 LLVMContext &Ctx = F.getContext();
  Constant *logFunc = F.getParent()->getOrInsertFunction(
    "logop", Type::getVoidTy(Ctx), Type::getInt32Ty(Ctx), NULL );

Type :: getInt32Ty(Ctx)函数参数类型(int),我想要做的是:

Type::getInt32Ty(Ctx) is the function argument type (int), what i want to do is:

getOrInsertFunction(
    "logop", Type::getVoidTy(Ctx), string type, NULL);

字符串类型我不知道如何定义它。如何定义它,谢谢!

The string type i don't know how to define it .In short, could you please tell me how to define it, thanks!

推荐答案

LLVM IR不定义任何特殊字符串或字符类型。

LLVM IR does not define any special string or char types.

通常使用 [N x i8] i8 * 真的取决于你 - 例如,Java风格的字符串可能是一个结构体,其中有 i32 表示字符串长度, i16 * 为UTF-16代码点。

Usually either [N x i8] or i8* are used, but it's really up to you - for example, Java-style strings will probably be a struct with some i32 for string length and an i16* for the UTF-16 code points.

LLVM IR有一个字符串字面值,输入为 i8 array - 例如 chello world\0A\00 [13 x i8] 。但是这不会决定你应该使用什么字符串形式。

LLVM IR does have a "string literal" which is typed as an i8 array - for example c"hello world\0A\00" is [13 x i8]. But that doesn't dictate what string form you should be using.

请记住,如果你的函数应该与一些东西互相配合。一个托管C ++应用程序,那么你需要使用相同的字符串类型 - 在这种情况下,任何 std :: string 正在编译。您可以使用Clang或此在线演示来检查类型是什么。

Keep in mind that if your function is supposed to interop with something, e.g. a hosting C++ application, then you need to use the same string type - in that case whatever std::string is compiling to. You can use Clang or this online demo to check what that type is.

这篇关于如何定义字符串类型在getOrInsertFunction()llvm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆