© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
Theos

❔ LLVM problem with creating number

public (Context, LLVMValueRef) VisitNumber(Context ctx, NumberAST expr)
{
    LLVMTypeRef typeRef = LLVMTypeRef.Double;
    if (expr.Type == typeof(long)) typeRef = LLVMTypeRef.Int64;
    else if (expr.Type == typeof(int)) typeRef = LLVMTypeRef.Int32;
    else if (expr.Type == typeof(short)) typeRef = LLVMTypeRef.Int16;
    else if (expr.Type == typeof(sbyte)) typeRef = LLVMTypeRef.Int8;

    else if (expr.Type == typeof(ulong)) typeRef = LLVMTypeRef.Int64;
    else if (expr.Type == typeof(uint)) typeRef = LLVMTypeRef.Int32;
    else if (expr.Type == typeof(ushort)) typeRef = LLVMTypeRef.Int16;
    else if (expr.Type == typeof(byte)) typeRef = LLVMTypeRef.Int8;


    return new(ctx, LLVMValueRef.CreateConstIntOfString(typeRef, expr.Value, 10));
}
public (Context, LLVMValueRef) VisitNumber(Context ctx, NumberAST expr)
{
    LLVMTypeRef typeRef = LLVMTypeRef.Double;
    if (expr.Type == typeof(long)) typeRef = LLVMTypeRef.Int64;
    else if (expr.Type == typeof(int)) typeRef = LLVMTypeRef.Int32;
    else if (expr.Type == typeof(short)) typeRef = LLVMTypeRef.Int16;
    else if (expr.Type == typeof(sbyte)) typeRef = LLVMTypeRef.Int8;

    else if (expr.Type == typeof(ulong)) typeRef = LLVMTypeRef.Int64;
    else if (expr.Type == typeof(uint)) typeRef = LLVMTypeRef.Int32;
    else if (expr.Type == typeof(ushort)) typeRef = LLVMTypeRef.Int16;
    else if (expr.Type == typeof(byte)) typeRef = LLVMTypeRef.Int8;


    return new(ctx, LLVMValueRef.CreateConstIntOfString(typeRef, expr.Value, 10));
}

var res = VisitNumber(ctx, new("10")).Item2; 
var res = VisitNumber(ctx, new("10")).Item2; 

for some reason the result is
{i0 0}
{i0 0}

Any ideas why?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ LLVM problem with creating number
C#CC# / help
3y ago
Problem with creating a project
C#CC# / help
2y ago
✅ Creating a number generically?
C#CC# / help
4y ago
Problem with creating controller based on EF Core
C#CC# / help
4y ago