Writes the GNU assembler code of one function on the registers that Color assigned. More...
#include <mim/plug/mach/emit.h>
Public Member Functions | |
| Emitter (const Target &target, std::ostream &os, AsmEmit &emit, Lam *fun) | |
| virtual | ~Emitter ()=default |
| void | emit (bool global) |
Protected Member Functions | |
| template<class... Args> | |
| void | line (std::format_string< Args... > fmt, Args &&... args) |
| void | label_here (std::string_view label) |
| const Target & | target () const |
| std::string_view | backend () const |
| Lam * | fun () const |
| std::string | label (Lam *lam) const |
| std::string | symbol (Lam *lam) |
| nat_t | nat (const Def *def) const |
| size_t | def_reg (const Def *def) const |
The register of the result def. | |
| size_t | use_reg (const Def *def) const |
The register of the operand def, a Target::in, possibly under a Target::is_view. | |
| std::optional< size_t > | isa_reg (const Def *def) const |
| Src | source (const Def *def) const |
| std::ostringstream & | body () |
| size_t | frame_size () const |
| The bytes of the callee-saved registers, slots, and spill slots, rounded up to keep sp 16-byte aligned. | |
Hooks | |
| virtual void | step (const App *app)=0 |
| virtual void | move (Reg dst, Reg src)=0 |
| virtual void | mov_imm (Reg dst, const Def *litlit)=0 |
| virtual void | swap (Reg, Reg) |
| Exchanges two registers of one class; only called if there is no scratch(). | |
| virtual std::optional< Reg > | scratch (Target::Class) const |
A register of class cls that breaks a copy cycle instead of swap(), if any. | |
| virtual void | push_slot (size_t i)=0 |
Pushes the spill slot i; the pops come in reverse order. | |
| virtual void | pop_slot (size_t i)=0 |
| virtual void | spill (Src src, const Def *type, size_t i)=0 |
Stores src, a value of type, into the spill slot i. | |
| virtual void | reload (Reg dst, const Def *type, size_t i)=0 |
Loads the spill slot i, a value of type, into dst. | |
| virtual void | load_arg (Reg dst, const Def *type, size_t i)=0 |
Loads the i-th argument that the caller passed on the stack, a value of type, into dst. | |
| virtual void | slot_addr (size_t dst, size_t first, size_t n)=0 |
Puts the address of the n slots from first on into the register dst. | |
| virtual void | jmp (std::string_view label)=0 |
| virtual void | branch_cc (size_t cc, std::string_view label)=0 |
Branches to label if the condition code cc holds. | |
| virtual void | branch_if (size_t r, std::string_view label, bool unless=false)=0 |
Branches to label if the Bool in register r is set, or with unless, if it is clear. | |
| virtual void | call_insn (std::string_view sym, std::optional< std::array< size_t, Target::Num_Classes > > num_args)=0 |
Calls sym with num_args arguments per register class in the ABI's argument registers. | |
| virtual void | prologue (std::ostream &os)=0 |
| The code between the function's label and its body; slots() and saved() are final by then. | |
| virtual void | leave ()=0 |
| Tears down the frame that prologue() built. | |
| virtual std::string_view | function_type () const |
| The argument of .type, e.g. @function. | |
Flags | |
| void | set_flags (const Def *fl) |
| void | clobber_flags () |
| bool | flags_clobbered () const |
| void | use_flags (const Def *fl) const |
Rejects a use of the flags fl if something clobbered them since. | |
Frame | |
The frame holds 8-byte slots: spill slots and the areas of slot instructions. | |
| size_t | spill_slot (const Def *def) |
| size_t | alloc_slots (nat_t bytes) |
Reserves bytes and yields the index of their first slot. | |
| size_t | num_slots () const |
| const fe::Vector< size_t > & | saved (Target::Class cls) const |
The callee-saved registers of class cls that hold values. | |
| size_t | num_saved () const |
Friends | |
| void | mim_mach_emit (Emitter &emitter, bool global) |
| Emitter::emit, compiled once into libmim_mach; Emitter reaches it via GET_FUN_PTR. | |
Writes the GNU assembler code of one function on the registers that Color assigned.
The control flow is target-independent: jumps, calls, returns, and the entry are parallel copies, the blocks are laid out by layout(), and the callee-saved registers that hold values are saved. A backend derives from it and emits its instructions, moves, branches, prologue, and epilogue.
|
virtualdefault |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
protectedpure virtual |
Branches to label if the condition code cc holds.
References label().
|
protectedpure virtual |
Branches to label if the Bool in register r is set, or with unless, if it is clear.
References label().
|
protectedpure virtual |
Calls sym with num_args arguments per register class in the ABI's argument registers.
A known() callee has no num_args: it is not variadic and its parameters may be in any register.
|
inlineprotected |
|
inlineprotected |
The register of the result def.
Definition at line 111 of file emit.h.
References backend(), and mim::Def::blame().
|
inline |
|
inlineprotected |
|
inlineprotected |
The bytes of the callee-saved registers, slots, and spill slots, rounded up to keep sp 16-byte aligned.
Definition at line 168 of file emit.h.
References num_saved().
|
inlineprotected |
|
inlineprotectedvirtual |
|
inlineprotected |
|
protectedpure virtual |
References label().
|
inlineprotected |
Definition at line 103 of file emit.h.
References mim::plug::mach::Target::local_prefix(), and mim::Def::unique_name().
Referenced by branch_cc(), branch_if(), jmp(), and label_here().
|
inlineprotected |
|
protectedpure virtual |
Tears down the frame that prologue() built.
|
inlineprotected |
|
protectedpure virtual |
Loads the i-th argument that the caller passed on the stack, a value of type, into dst.
Definition at line 105 of file emit.h.
References backend(), mim::Def::blame(), and mim::Lit::isa().
|
inlineprotected |
Definition at line 160 of file emit.h.
Referenced by frame_size().
|
inlineprotected |
|
protectedpure virtual |
|
protectedpure virtual |
The code between the function's label and its body; slots() and saved() are final by then.
|
protectedpure virtual |
Pushes the spill slot i; the pops come in reverse order.
|
protectedpure virtual |
Loads the spill slot i, a value of type, into dst.
|
inlineprotected |
|
inlineprotectedvirtual |
|
inlineprotected |
|
protectedpure virtual |
Puts the address of the n slots from first on into the register dst.
Definition at line 125 of file emit.h.
References mim::Lit::isa(), mim::plug::mach::Target::strip(), and use_reg().
|
protectedpure virtual |
Stores src, a value of type, into the spill slot i.
|
inlineprotected |
|
protectedpure virtual |
Emits the instruction app on the chain.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
Rejects a use of the flags fl if something clobbered them since.
Definition at line 137 of file emit.h.
References backend(), and mim::Def::blame().
|
inlineprotected |
The register of the operand def, a Target::in, possibly under a Target::is_view.
Definition at line 116 of file emit.h.
References backend(), mim::Def::blame(), mim::plug::mach::Target::in_reg(), mim::plug::mach::Target::is_in(), mim::Lit::isa(), and mim::plug::mach::Target::unview().
Referenced by source().
|
friend |
Emitter::emit, compiled once into libmim_mach; Emitter reaches it via GET_FUN_PTR.
Definition at line 371 of file emit.cpp.
References Emitter(), and mim_mach_emit.
Referenced by emit(), and mim_mach_emit.