49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using TMPro;
|
||
using UnityEngine;
|
||
using VMdemo.Simulation;
|
||
|
||
namespace VMdemo.UI
|
||
{
|
||
public class SimulationTablesView : MonoBehaviour
|
||
{
|
||
[SerializeField] private TMP_Text tlbText;
|
||
[SerializeField] private TMP_Text pageTableText;
|
||
[SerializeField] private TMP_Text fifoText;
|
||
|
||
public void ShowNotInitialized()
|
||
{
|
||
SetText(tlbText, "TLB:N/A");
|
||
SetText(pageTableText, "页表:N/A");
|
||
SetText(fifoText, "FIFO:N/A");
|
||
}
|
||
|
||
public void Render(TranslatorEngine engine)
|
||
{
|
||
if (engine == null)
|
||
{
|
||
ShowNotInitialized();
|
||
return;
|
||
}
|
||
|
||
var vpnBits = engine.VaBits - engine.OffsetBits;
|
||
var pfnBits = SimulationUIFormatter.ComputeBitsForCount(engine.PhysicalMemoryManager.FrameCount);
|
||
SetText(
|
||
tlbText,
|
||
SimulationUIFormatter.FormatTlbTable(
|
||
engine.TlbCache.GetEntriesMostRecentFirst(),
|
||
vpnBits,
|
||
pfnBits));
|
||
SetText(pageTableText, SimulationUIFormatter.FormatCurrentPageTableEntry(engine.State, engine.PageTable, engine.LastEviction));
|
||
SetText(fifoText, SimulationUIFormatter.FormatFifoQueue(engine.PhysicalMemoryManager.GetFifoVpnOrder()));
|
||
}
|
||
|
||
private static void SetText(TMP_Text target, string value)
|
||
{
|
||
if (target != null)
|
||
{
|
||
target.text = value;
|
||
}
|
||
}
|
||
}
|
||
}
|