aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/ATranslator.cs
diff options
context:
space:
mode:
authorAlex Barney <thealexbarney@gmail.com>2018-10-30 19:43:02 -0600
committergdkchan <gab.dark.100@gmail.com>2018-10-30 22:43:02 -0300
commit9cb57fb4bb3bbae0ae052a5af4a96a49fc5d864d (patch)
tree0c97425aeb311c142bc92a6fcc503cb2c07d4376 /ChocolArm64/ATranslator.cs
parent5a87e58183578f5b84ca8d01cbb76aed11820f78 (diff)
Adjust naming conventions for Ryujinx and ChocolArm64 projects (#484)
* Change naming convention for Ryujinx project * Change naming convention for ChocolArm64 project * Fix NaN * Remove unneeded this. from Ryujinx project * Adjust naming from new PRs * Name changes based on feedback * How did this get removed? * Rebasing fix * Change FP enum case * Remove prefix from ChocolArm64 classes - Part 1 * Remove prefix from ChocolArm64 classes - Part 2 * Fix alignment from last commit's renaming * Rename namespaces * Rename stragglers * Fix alignment * Rename OpCode class * Missed a few * Adjust alignment
Diffstat (limited to 'ChocolArm64/ATranslator.cs')
-rw-r--r--ChocolArm64/ATranslator.cs165
1 files changed, 0 insertions, 165 deletions
diff --git a/ChocolArm64/ATranslator.cs b/ChocolArm64/ATranslator.cs
deleted file mode 100644
index 5be41d3e..00000000
--- a/ChocolArm64/ATranslator.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-using ChocolArm64.Decoder;
-using ChocolArm64.Events;
-using ChocolArm64.Memory;
-using ChocolArm64.State;
-using ChocolArm64.Translation;
-using System;
-using System.Reflection.Emit;
-
-namespace ChocolArm64
-{
- public class ATranslator
- {
- private ATranslatorCache Cache;
-
- public event EventHandler<ACpuTraceEventArgs> CpuTrace;
-
- public bool EnableCpuTrace { get; set; }
-
- public ATranslator()
- {
- Cache = new ATranslatorCache();
- }
-
- internal void ExecuteSubroutine(AThread Thread, long Position)
- {
- //TODO: Both the execute A32/A64 methods should be merged on the future,
- //when both ISAs are implemented with the interpreter and JIT.
- //As of now, A32 only has a interpreter and A64 a JIT.
- AThreadState State = Thread.ThreadState;
- AMemory Memory = Thread.Memory;
-
- if (State.ExecutionMode == AExecutionMode.AArch32)
- {
- ExecuteSubroutineA32(State, Memory);
- }
- else
- {
- ExecuteSubroutineA64(State, Memory, Position);
- }
- }
-
- private void ExecuteSubroutineA32(AThreadState State, AMemory Memory)
- {
- do
- {
- AOpCode OpCode = ADecoder.DecodeOpCode(State, Memory, State.R15);
-
- OpCode.Interpreter(State, Memory, OpCode);
- }
- while (State.R15 != 0 && State.Running);
- }
-
- private void ExecuteSubroutineA64(AThreadState State, AMemory Memory, long Position)
- {
- do
- {
- if (EnableCpuTrace)
- {
- CpuTrace?.Invoke(this, new ACpuTraceEventArgs(Position));
- }
-
- if (!Cache.TryGetSubroutine(Position, out ATranslatedSub Sub))
- {
- Sub = TranslateTier0(State, Memory, Position);
- }
-
- if (Sub.ShouldReJit())
- {
- TranslateTier1(State, Memory, Position);
- }
-
- Position = Sub.Execute(State, Memory);
- }
- while (Position != 0 && State.Running);
- }
-
- internal bool HasCachedSub(long Position)
- {
- return Cache.HasSubroutine(Position);
- }
-
- private ATranslatedSub TranslateTier0(AThreadState State, AMemory Memory, long Position)
- {
- ABlock Block = ADecoder.DecodeBasicBlock(State, Memory, Position);
-
- ABlock[] Graph = new ABlock[] { Block };
-
- string SubName = GetSubroutineName(Position);
-
- AILEmitterCtx Context = new AILEmitterCtx(Cache, Graph, Block, SubName);
-
- do
- {
- Context.EmitOpCode();
- }
- while (Context.AdvanceOpCode());
-
- ATranslatedSub Subroutine = Context.GetSubroutine();
-
- Subroutine.SetType(ATranslatedSubType.SubTier0);
-
- Cache.AddOrUpdate(Position, Subroutine, Block.OpCodes.Count);
-
- AOpCode LastOp = Block.GetLastOp();
-
- return Subroutine;
- }
-
- private void TranslateTier1(AThreadState State, AMemory Memory, long Position)
- {
- (ABlock[] Graph, ABlock Root) = ADecoder.DecodeSubroutine(Cache, State, Memory, Position);
-
- string SubName = GetSubroutineName(Position);
-
- AILEmitterCtx Context = new AILEmitterCtx(Cache, Graph, Root, SubName);
-
- if (Context.CurrBlock.Position != Position)
- {
- Context.Emit(OpCodes.Br, Context.GetLabel(Position));
- }
-
- do
- {
- Context.EmitOpCode();
- }
- while (Context.AdvanceOpCode());
-
- //Mark all methods that calls this method for ReJiting,
- //since we can now call it directly which is faster.
- if (Cache.TryGetSubroutine(Position, out ATranslatedSub OldSub))
- {
- foreach (long CallerPos in OldSub.GetCallerPositions())
- {
- if (Cache.TryGetSubroutine(Position, out ATranslatedSub CallerSub))
- {
- CallerSub.MarkForReJit();
- }
- }
- }
-
- ATranslatedSub Subroutine = Context.GetSubroutine();
-
- Subroutine.SetType(ATranslatedSubType.SubTier1);
-
- Cache.AddOrUpdate(Position, Subroutine, GetGraphInstCount(Graph));
- }
-
- private string GetSubroutineName(long Position)
- {
- return $"Sub{Position:x16}";
- }
-
- private int GetGraphInstCount(ABlock[] Graph)
- {
- int Size = 0;
-
- foreach (ABlock Block in Graph)
- {
- Size += Block.OpCodes.Count;
- }
-
- return Size;
- }
- }
-} \ No newline at end of file