On Wed, Apr 26, 2023 at 4:21 PM Chris Zhang <mayerche...@gmail.com> wrote:
>
> I am trying to dump certain IRNode in src/cmd/internal/ssagen/ssa.go file in 
> 1.19. Suppose n is an IRNode, then I tried `fmt.Printf(“%+v”, n)`, and I can 
> see something like
>
> .    NAME-strong.u esc(no) Class:PPARAM Offset:24 OnStack Used uint64 tc(1) # 
> itoa.go:88:29
>
> I am interested in the last part “itoa.go:88:29” and I wonder how to get this 
> substring. Based on my understanding, “%+v” basically print all fields in a 
> struct. Also seems like these two statements are equivalent: 
> `fmt.Printf(“%+v”, n)` versus
> `fmt.Printf(“%+v”, n.Name())`. I’ve tried to dump all fields for n.Name() but 
> still cannot see “itoa.go…”.
>
> Any thoughts on how to get this substring or what's the actual step of 
> converting `n.Name()` into the output string?

It's more complicated than what you describe because most ir.Node
implementations implement the fmt.Formatter interface, so the Format
method is called to implement %+v.  Anyhow, the itoa.go:88:28 is
almost certainly coming from the n.Pos() value.  At HEAD this is being
printed by the code at
https://go.googlesource.com/go/+/refs/heads/master/src/cmd/compile/internal/ir/fmt.go#1080
.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWhrcevOBF3NDuoWB94JJJhFSJCJJ2K7SZvnwbe-AmH3A%40mail.gmail.com.

Reply via email to