C
C#2y ago
Theos

❔ LLVMSharp weird function

Hey, so I'm trynig to convert my class into a LLVM const. I have a class callled NumberAST:
class NumberAST
{
public NumberType type = NumberType.Int64;
public string value = "100000";
}
class NumberAST
{
public NumberType type = NumberType.Int64;
public string value = "100000";
}
And I was wondering how to convert it into llvm const. I found this thingy LLVMValueRef.CreateConstIntOfString() but I can't find it in the docs so i'm not sure how to use it
10 Replies
Theos
TheosOP2y ago
public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, string Text, byte Radix) => CreateConstIntOfString(IntTy, Text.AsSpan(), Radix);

public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, ReadOnlySpan<char> Text, byte Radix)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstIntOfString(IntTy, marshaledText, Radix);
}
public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, string Text, byte Radix) => CreateConstIntOfString(IntTy, Text.AsSpan(), Radix);

public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, ReadOnlySpan<char> Text, byte Radix)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstIntOfString(IntTy, marshaledText, Radix);
}
thats the origin of this function
[DllImport("libLLVM", CallingConvention = CallingConvention.Cdecl, EntryPoint = "LLVMConstIntOfString", ExactSpelling = true)]
[return: NativeTypeName("LLVMValueRef")]
public static extern LLVMOpaqueValue* ConstIntOfString([NativeTypeName("LLVMTypeRef")] LLVMOpaqueType* IntTy, [NativeTypeName("const char *")] sbyte* Text, [NativeTypeName("uint8_t")] byte Radix);
[DllImport("libLLVM", CallingConvention = CallingConvention.Cdecl, EntryPoint = "LLVMConstIntOfString", ExactSpelling = true)]
[return: NativeTypeName("LLVMValueRef")]
public static extern LLVMOpaqueValue* ConstIntOfString([NativeTypeName("LLVMTypeRef")] LLVMOpaqueType* IntTy, [NativeTypeName("const char *")] sbyte* Text, [NativeTypeName("uint8_t")] byte Radix);
any ideas if i'm even trying to use the right thing?
phaseshift
phaseshift2y ago
well you need to pass three arguments...
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Theos
TheosOP2y ago
really? I had no idea. That's now what I'm asking tho. I don't really understand whats the use case of this function what does it do whats the radix used for there's nothing in the documentation
phaseshift
phaseshift2y ago
Radix specifies how many numbers are possible for each digit. Eg for "100" is it binary? Hex? Decimal? Use the radix to specify 2, 16, or 10, respectively
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Theos
TheosOP2y ago
Thanks! so I guess I can do something like CreateConstIntOfString(LLVMTypeRef.Int64, "1054594", 10) and it should parse my string into Int64
phaseshift
phaseshift2y ago
yes
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?