8000 How to make "..." arg type? · Issue #178 · llir/llvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How to make "..." arg type? #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Nv7-GitHub opened this issue May 16, 2021 · 2 comments
Closed

How to make "..." arg type? #178

Nv7-GitHub opened this issue May 16, 2021 · 2 comments
Labels

Comments

@Nv7-GitHub
Copy link
Contributor

I want to call printf. When using clang, it emits:

declare i32 @printf(i8*, ...)

How do I make a new function with llir, with ... as the argument?

@mewmew
Copy link
Member
mewmew commented May 16, 2021

Hi @Nv7-GitHub,

Glad to see you experimenting with LLVM IR in Go :)

How do I make a new function with llir, with ... as the argument?

Set the Variadic field of ir.Func.Sig to true.

package main

import (
	"fmt"

	"github.com/llir/llvm/ir"
	irtypes "github.com/llir/llvm/ir/types"
)

func main() {
	i32Type := irtypes.I32
	i8PtrType := irtypes.NewPointer(irtypes.I8)
	param := ir.NewParam("format", i8PtrType)
	printfFunc := ir.NewFunc("printf", i32Type, param)
	printfFunc.Sig.Variadic = true

	module := ir.NewModule()
	module.Funcs = append(module.Funcs, printfFunc)
	fmt.Println(module)
}

Output:

declare i32 @printf(i8* %format, ...)

Cheers,
Robin

@mewmew mewmew added the howto label May 16, 2021
@mewmew
Copy link
Member
mewmew commented May 16, 2021

Closing this issue for now as resolved. Hope it helped. And if not, just write a comment and we can re-open it.

Cheers,
Robin

< 6FDA /task-lists>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0