Class Voodoo::MIPSGasGenerator
In: voodoo/generators/mips_gas_generator.rb
Parent: CommonCodeGenerator

MIPS GNU Assembler Code Generator

The MIPS code generator generates assembly code for use with the GNU assembler.

Calling Convention

The first four arguments are passed in the registers $4 through $7. Any additional arguments are passed on the stack, starting at $sp + 16. Words $sp through $sp + 12 will be available for the called function to use. $sp will always be a multiple of 8.

The return address for the called function is passed in $31.

When performing a position-independent call, the address of the called function is passed in $25.

The called function will store its return value in $2.

The called function is required to preserve the values of registers $16 through $23 and register $30.

This calling convention is compatible with the System V ELF ABI.

Call Frames

Call frames have the following layout:

When a function is called, it receives a stack frame that looks like the following:

  :
  old frame
  argn
  :
  arg4
  empty3
  empty2
  empty1
  empty0    <-- $sp points here

The function prologue of functions generated by this code generator creates activation frames that look as follows:

: old frame argn : arg4 arg3 arg2 arg1 arg0 return address pointer to Global Offset Table local0 : local7 local8 : localn padding <— $sp points here

In words:

The four empty slots provided by the caller are used to store arguments 0 through 3 (originally passed in $4 through $7), if necessary.

The stack frame created below the four slots provided by the caller contains the following data, in order:

  • Saved return address (originally passed in $31), if necessary.
  • Saved pointer to global offset table (computed from $25), if necessary.
  • Saved values of caller‘s locals 0 through 7 (originally in $16 through $23), if necessary.
  • Values of our locals > 8, if necessary.
  • Padding to align $sp on a multiple of 8, if necessary.

In accordance with the System V ELF ABI for MIPS, the pointer to the global offset table is calculated as follows:

$gp = _gp_disp + $25

where $gp is the register to store the pointer, $25 is the register holding the address of the called function, and _gp_disp is the offset between the beginning of the function and the global offset table.

Methods

Public Class methods

Public Instance methods

Return the offset from $sp at which the nth (0-based) argument is stored.

Return an $sp-relative reference for the nth (0-based) argument

Return the register in which the nth (0-based) argument is stored, or nil if not stored in a register

Test if op is a binary operation

Test if a value is an at-expression

Begins a new block.

Emit function prologue and declare formals as function arguments

Test if op is a binary operation

Define a byte with the given value

Start a conditional using the specified branch instruction after the comparison.

Counts the number of local variables created in a sequence of statements.

Creates an activation frame which can store nlocals local variables

Ends the current block.

End a conditional.

Evaluate the binary operation expr and store the result in register

Evaluate the expression expr and store the result in register

Export symbols from the current section

Add a function to the current section

Load byte from base + offset into register

Load word from base + offset * _@WORDSIZE_ into register

Test if a symbol refers to a global

Jump to a label.

Start the false path of a conditional.

Test if x is equal to y

Test if x is greater than or equal to y

Test if x is strictly greater than y

Test if x is less than or equal to y

Test if x is strictly less than y

Test if x different from y

Import labels into the current section

Test if a value is an integer

Introduce a new local variable

Load the value at the given address.

Load a value into a register. Returns the name of the register. If the value was already in a register, the name of that register is returned. Else, the value is loaded into a register and the name of that register is returned. The register to use in that case may be specified using the optional second argument.

Load a value into a specific register

Return the offset from $sp at which the nth (0-based) local variable is stored. For register locals this is the offset at which the saved value (from the calling function) is stored.

Return an $sp-relative reference for the nth (0-based) local

Return the register in which the nth local (0-based) is stored, or nil if not stored in a register

Compute the maximum number of locals that would fit in the current frame size.

Calculate the number of stack arguments, given the total number of arguments.

Returns true if the nth (0-based) argument is stored in a register

Returns true if the nth (0-based) local is stored in a register

Return a from a function.

words may contain an expression to be evaluated. The result of the evaluation is returned from the function.

Set a variable to the result of evaluating an expression

Set the byte at base + offset to value

Set the word at base + offset * +@WORDSIZE+ to value

Define a string with the given value

Test if a value is a symbol

Test if op is a symmetric binary operation (i.e. it will yield the same result if the order of its source operands is changed).

Call a function, re-using the current call frame if possible.

Define a word with the given value

Write generated code to the given IO object.

[Validate]