Commit a683a499 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Handle writing of return value.

parent e6484e19
......@@ -13,6 +13,8 @@ package net.multiphasicapps.squirreljme.jit;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;
import net.multiphasicapps.util.unmodifiable.UnmodifiableList;
/**
* This is used to store the information such as which registers and the stack
......@@ -35,6 +37,9 @@ public final class ArgumentAllocation
/** String representation. */
private volatile Reference<String> _string;
/** List of registers. */
private volatile Reference<List<Register>> _lregs;
/**
* Initializes the argument allocation with the specified registers.
*
......@@ -185,6 +190,26 @@ public final class ArgumentAllocation
return (registers == null ? 0 : registers.length);
}
/**
* Returns the list of registers that are available for usage.
*
* @return The list of registers, this list is not modifiable.
* @since 2017/03/31
*/
public List<Register> registerList()
{
Reference<List<Register>> ref = this._lregs;
List<Register> rv;
// Cache?
if (ref == null || null == (rv = ref.get()))
this._lregs = new WeakReference<>((rv =
UnmodifiableList.<Register>of(Arrays.<Register>asList(
this._registers))));
return rv;
}
/**
* Returns all of the allocated registers.
*
......
......@@ -236,6 +236,17 @@ public abstract class CacheState
new Register[registers.size()]));
}
/**
* Are registers used in this slot?
*
* @return {@code true} if registers are used in the slot.
* @since 2017/03/31
*/
public final boolean thisHasRegisters()
{
return !thisRegisters().isEmpty();
}
/**
* Returns the registers using the given type.
*
......@@ -315,6 +326,17 @@ public abstract class CacheState
return value().thisAllocation(__a);
}
/**
* Are registers used in the value?
*
* @return {@code true} if registers are used in the value.
* @since 2017/03/31
*/
public final boolean valueHasRegisters()
{
return value().thisHasRegisters();
}
/**
* Returns the value index of this slot.
*
......
......@@ -455,7 +455,15 @@ class __JITCodeStream__
// If a return value is used then handle moving it
if (__rv != null)
{
throw new todo.TODO();
// Return to registers
DataType rt = rvalloc.type();
List<Register> rl = rvalloc.registerList();
if (rv.thisHasRegisters())
engine.moveRegister(rt, rl, rv.thisRegisters());
// Return to stack
else
engine.storeRegister(rt, rl, rv.thisStackOffset(), fp);
}
// Because the values are stack cached they do not need to be read from
......
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