Commit ab019da7 authored by Michael Pratt's avatar Michael Pratt Committed by Russ Cox

cmd/internal/obj: document Prog

Change-Id: Iafc392ba06452419542ec85e91d44991839eb6f8
Reviewed-on: https://go-review.googlesource.com/19593
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 0a55a16c
...@@ -203,32 +203,55 @@ const ( ...@@ -203,32 +203,55 @@ const (
TYPE_REGLIST TYPE_REGLIST
) )
// TODO(rsc): Describe prog. // Prog describes a single machine instruction.
// TODO(rsc): Describe TEXT/GLOBL flag in from3 //
// The general instruction form is:
//
// As.Scond From, Reg, From3, To, RegTo2
//
// where As is an opcode and the others are arguments:
// From, Reg, From3 are sources, and To, RegTo2 are destinations.
// Usually, not all arguments are present.
// For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2.
// The Scond field holds additional condition bits for systems (like arm)
// that have generalized conditional execution.
//
// Jump instructions use the Pcond field to point to the target instruction,
// which must be in the same linked list as the jump instruction.
//
// The Progs for a given function are arranged in a list linked through the Link field.
//
// Each Prog is charged to a specific source line in the debug information,
// specified by Lineno, an index into the line history (see LineHist).
// Every Prog has a Ctxt field that defines various context, including the current LineHist.
// Progs should be allocated using ctxt.NewProg(), not new(Prog).
//
// The other fields not yet mentioned are for use by the back ends and should
// be left zeroed by creators of Prog lists.
type Prog struct { type Prog struct {
Ctxt *Link Ctxt *Link // linker context
Link *Prog Link *Prog // next Prog in linked list
From Addr From Addr // first source operand
From3 *Addr // optional From3 *Addr // third source operand (second is Reg below)
To Addr To Addr // destination operand (second is RegTo2 below)
Opt interface{} Pcond *Prog // target of conditional jump
Forwd *Prog Opt interface{} // available to optimization passes to hold per-Prog state
Pcond *Prog Forwd *Prog // for x86 back end
Rel *Prog // Source of forward jumps on x86; pcrel on arm Rel *Prog // for x86, arm back ends
Pc int64 Pc int64 // for back ends or assembler: virtual or actual program counter, depending on phase
Lineno int32 Lineno int32 // line number of this instruction
Spadj int32 Spadj int32 // effect of instruction on stack pointer (increment or decrement amount)
As As // Assembler opcode. As As // assembler opcode
Reg int16 Reg int16 // 2nd source operand
RegTo2 int16 // 2nd register output operand RegTo2 int16 // 2nd destination operand
Mark uint16 // bitmask of arch-specific items Mark uint16 // bitmask of arch-specific items
Optab uint16 Optab uint16 // arch-specific opcode index
Scond uint8 Scond uint8 // condition bits for conditional instruction (e.g., on ARM)
Back uint8 Back uint8 // for x86 back end: backwards branch state
Ft uint8 Ft uint8 // for x86 back end: type index of Prog.From
Tt uint8 Tt uint8 // for x86 back end: type index of Prog.To
Isize uint8 // size of the instruction in bytes (x86 only) Isize uint8 // for x86 back end: size of the instruction in bytes
Mode int8 Mode int8 // for x86 back end: 32- or 64-bit mode
} }
// From3Type returns From3.Type, or TYPE_NONE when From3 is nil. // From3Type returns From3.Type, or TYPE_NONE when From3 is nil.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment