C
C#16mo 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
TheosOP16mo 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
phaseshift16mo ago
well you need to pass three arguments...
Accord
Accord16mo 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
TheosOP16mo 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
phaseshift16mo 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
Accord16mo 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
TheosOP16mo ago
Thanks! so I guess I can do something like CreateConstIntOfString(LLVMTypeRef.Int64, "1054594", 10) and it should parse my string into Int64
phaseshift
phaseshift16mo ago
yes
Accord
Accord16mo 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.
Want results from more Discord servers?
Add your server