You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to llir/llvm. I need a fonction to do type conversion. My first iteration would be to convert from int and float to string. I guess I'll have to call sprintf from the C library. I don't want to allocate global variables to do so. I saw that entry.malloc to allocate temporary variables. That's pretty much where I am. May I ask if someone could give me some cues on how to proceed?
I tried this, but I return an *ir.InstGetElementPtr:
I still don't know how to use this value to send it to another function like print.
Here is my calling function:
// compilePrintStmt compiles a print statement.
func compilePrintStmt(ctx *Context, node *ast.SpecialStmt) {
zero := constant.NewInt(types.I64, 0)
printf := ctx.lookupFunction("printf")
puts := ctx.lookupFunction("puts")
var value *ir.Global
var str *ir.InstGetElementPtr
for _, arg := range node.Args {
switch arg := arg.(type) {
case *ast.BasicLit:
switch arg.Kind {
case token.StringLit:
value = compileConstant(ctx, arg, "")
case token.LongLit:
str = convertToString(ctx, value)
default:
panic("unknown basic literal")
}
case *ast.Identifier:
// TODO: generalize for any type of identifier, not only global constant
value = ctx.lookupConstant(arg.Name)
}
typ := value.Typ.ElemType
gep := constant.NewGetElementPtr(typ, value, zero, zero)
// TODO: type conversion to string
ctx.Block.NewCall(printf, gep)
}
if node.Semicolon == nil {
value = ctx.lookupConstant("vbEmpty")
typ := value.Typ.ElemType
gep := constant.NewGetElementPtr(typ, value, zero, zero)
ctx.Block.NewCall(puts, gep)
}
The text was updated successfully, but these errors were encountered:
Hi,
I'm new to llir/llvm. I need a fonction to do type conversion. My first iteration would be to convert from int and float to string. I guess I'll have to call sprintf from the C library. I don't want to allocate global variables to do so. I saw that
entry.malloc
to allocate temporary variables. That's pretty much where I am. May I ask if someone could give me some cues on how to proceed?I tried this, but I return an
*ir.InstGetElementPtr
:I still don't know how to use this value to send it to another function like print.
Here is my calling function:
The text was updated successfully, but these errors were encountered: