Output format of IRNode.

90 views
Skip to first unread message

Chris Zhang

unread,
Apr 26, 2023, 7:21:15 PM4/26/23
to golang-nuts

Dear all,

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?

Thanks in advance!

Best,

Chris

Kurtis Rader

unread,
Apr 26, 2023, 11:37:49 PM4/26/23
to Chris Zhang, golang-nuts
This seems like an [XY Problem](https://xyproblem.info/). Tell us what problem you are trying to solve rather than the solution you attempted.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/92613ee9-3c7d-4a1a-ac1e-626712a3d924n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Ian Lance Taylor

unread,
Apr 27, 2023, 7:17:20 PM4/27/23
to Chris Zhang, golang-nuts
On Wed, Apr 26, 2023 at 4:21 PM Chris Zhang <mayer...@gmail.com> wrote:
>
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
Reply all
Reply to author
Forward
0 new messages