Class: Rubycc::IR::Function
- Inherits:
-
Object
- Object
- Rubycc::IR::Function
- Defined in:
- lib/rubycc/ir/ir.rb
Overview
A function in IR form: a name, a flat list of instructions and the number
of virtual registers used (so the backend can size its stack frame).
param_count is the number of ABI argument slots, not the number of C
parameters: a scalar parameter is one slot, a by-value struct parameter one
per piece its convention cuts it into, and the hidden result pointer of a
function whose result does not come back in registers an extra leading
slot. Those slots occupy
the first param_count virtual registers (0..param_count-1) in that order,
so the backend can spill the incoming argument registers into them; the
generator then reassembles a struct parameter's slots into a stack object.
param_kinds is an array of length param_count giving each slot's arrival
under the target's calling convention (IR::CallConvention), in that
flattened order, which the generator has fixed by the same placement
simulation a call's arguments use: :gp (integer register), :sse4 (float
vector register), :sse8 (double vector register — also each eightbyte of a
struct arriving in one, and each member of an AAPCS64 HFA of doubles) or
:mem (the stack overflow area). How many registers there are to hand out
before a scalar spills to :mem, and how an aggregate is cut into slots at
all, are the target's business — which is why the tags are fixed here and
not by a backend: System V AMD64 offers six integer registers and AAPCS64
eight, and struct { float a, b; } is one :sse8 slot on the first and two
:sse4 slots on the second, so the same C call classifies differently on the
two. One further kind names a mechanism only some conventions have: an
:indirect_result slot is the implicit pointer to a caller-provided result
buffer when the convention reserves a register of its own for it (AAPCS64's
x8). An aggregate passed by reference needs no kind of its own — the
generator reduces it to an ordinary :gp pointer to a caller-made copy. The
prologue
spills each slot straight from its location, and a variadic function derives
its gp_offset / fp_offset / overflow start for :va_start from the counts of
each kind.
stack_objects is an array indexed by object id whose entries are the
byte sizes of aggregate stack objects (arrays); the backend lays these
out below the virtual-register slots and resolves :object_addr against
them.
linkage is :external for an ordinary function (a global symbol the
linker can resolve across translation units) or :internal for a static
one (a file-local symbol, emitted STB_LOCAL so it stays private to this
object and never collides with a same-named function elsewhere).
variadic is true for a "..."-terminated definition, which makes the
backend emit a register-save-area prologue so :va_start / __builtin_va_arg
can reach the variable arguments; a fixed-arity function leaves it false.
Instance Attribute Summary collapse
-
#insts ⇒ Object
readonly
Returns the value of attribute insts.
-
#linkage ⇒ Object
readonly
Returns the value of attribute linkage.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#param_count ⇒ Object
readonly
Returns the value of attribute param_count.
-
#param_kinds ⇒ Object
readonly
Returns the value of attribute param_kinds.
-
#stack_objects ⇒ Object
readonly
Returns the value of attribute stack_objects.
-
#variadic ⇒ Object
readonly
Returns the value of attribute variadic.
-
#vreg_count ⇒ Object
readonly
Returns the value of attribute vreg_count.
Instance Method Summary collapse
-
#initialize(name, insts, vreg_count, param_count, stack_objects, linkage, variadic, param_kinds) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(name, insts, vreg_count, param_count, stack_objects, linkage, variadic, param_kinds) ⇒ Function
Returns a new instance of Function.
342 343 344 345 346 347 348 349 350 351 |
# File 'lib/rubycc/ir/ir.rb', line 342 def initialize(name, insts, vreg_count, param_count, stack_objects, linkage, variadic, param_kinds) @name = name @insts = insts @vreg_count = vreg_count @param_count = param_count @stack_objects = stack_objects @linkage = linkage @variadic = variadic @param_kinds = param_kinds end |
Instance Attribute Details
#insts ⇒ Object (readonly)
Returns the value of attribute insts.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def insts @insts end |
#linkage ⇒ Object (readonly)
Returns the value of attribute linkage.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def linkage @linkage end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def name @name end |
#param_count ⇒ Object (readonly)
Returns the value of attribute param_count.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def param_count @param_count end |
#param_kinds ⇒ Object (readonly)
Returns the value of attribute param_kinds.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def param_kinds @param_kinds end |
#stack_objects ⇒ Object (readonly)
Returns the value of attribute stack_objects.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def stack_objects @stack_objects end |
#variadic ⇒ Object (readonly)
Returns the value of attribute variadic.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def variadic @variadic end |
#vreg_count ⇒ Object (readonly)
Returns the value of attribute vreg_count.
340 341 342 |
# File 'lib/rubycc/ir/ir.rb', line 340 def vreg_count @vreg_count end |