public ILEmitterCtx( MemoryManager memory, TranslatorCache cache, TranslatorQueue queue, TranslationTier tier, Block graph) { Memory = memory ?? throw new ArgumentNullException(nameof(memory)); _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _queue = queue ?? throw new ArgumentNullException(nameof(queue)); _currBlock = graph ?? throw new ArgumentNullException(nameof(graph)); Tier = tier; _labels = new Dictionary <long, ILLabel>(); _visitedBlocks = new Dictionary <Block, ILBlock>(); _visitedBlocks.Add(graph, new ILBlock()); _branchTargets = new Queue <Block>(); _ilBlocks = new List <ILBlock>(); _subPosition = graph.Position; ResetBlockState(); if (AdvanceOpCode()) { EmitSynchronization(); _ilBlock.Add(new ILOpCodeLoadState(_ilBlock, isSubEntry: true)); } }
public TranslatedSub GetSubroutine(TranslationTier tier, bool isWorthOptimizing) { RegUsage = new RegisterUsage(); RegUsage.BuildUses(_ilBlocks[0]); DynamicMethod method = new DynamicMethod(_subName, typeof(long), TranslatedSub.FixedArgTypes); long intNiRegsMask = RegUsage.GetIntNotInputs(_ilBlocks[0]); long vecNiRegsMask = RegUsage.GetVecNotInputs(_ilBlocks[0]); TranslatedSub subroutine = new TranslatedSub( method, intNiRegsMask, vecNiRegsMask, tier, isWorthOptimizing); _locals = new Dictionary <Register, int>(); _localsCount = 0; Generator = method.GetILGenerator(); foreach (ILBlock ilBlock in _ilBlocks) { ilBlock.Emit(this); } subroutine.PrepareMethod(); return(subroutine); }
public TranslatedSub GetSubroutine(TranslationTier tier) { LocalAlloc = new LocalAlloc(_ilBlocks, _ilBlocks[0]); DynamicMethod method = new DynamicMethod(_subName, typeof(long), TranslatedSub.FixedArgTypes); Generator = method.GetILGenerator(); TranslatedSub subroutine = new TranslatedSub(method, tier); _locals = new Dictionary <Register, int>(); _localsCount = 0; new ILOpCodeLoadState(_ilBlocks[0]).Emit(this); foreach (ILBlock ilBlock in _ilBlocks) { ilBlock.Emit(this); } subroutine.PrepareMethod(); return(subroutine); }
public void Enqueue(long position, ExecutionMode mode, TranslationTier tier, bool isComplete) { TranslatorQueueItem item = new TranslatorQueueItem(position, mode, tier, isComplete); ConcurrentStack <TranslatorQueueItem> queue = _translationQueue[(int)tier]; queue.Push(item); _queueDataReceivedEvent.Set(); }
public TranslatorQueueItem( long position, ExecutionMode mode, TranslationTier tier, bool isComplete = false) { Position = position; Mode = mode; Tier = tier; IsComplete = isComplete; }
public TranslatedSub( DynamicMethod method, long intNiRegsMask, long vecNiRegsMask, TranslationTier tier, bool isWorthOptimizing) { Method = method ?? throw new ArgumentNullException(nameof(method));; IntNiRegsMask = intNiRegsMask; VecNiRegsMask = vecNiRegsMask; _isWorthOptimizing = isWorthOptimizing; Tier = tier; }
protected Job(JObject json) { if (json == null) { throw new ArgumentNullException("json"); } _readOnly = true; _autoApprove = json.Value <string>("auto_approve") == "1"; _force = json.Value <string>("force") == "1"; _body = json.Value <string>("body_src"); _comment = json.Value <string>("comment"); _customData = json.Value <string>("custom_data"); _slug = json.Value <string>("slug"); _sourceLang = json.Value <string>("lc_src"); _targetLang = json.Value <string>("lc_tgt"); if (json.SelectToken("max_chars") != null) { _maximumCharacters = json.Value <int>("max_chars"); } _type = json.Value <string>("type").ToJobType(); _tier = json.Value <string>("tier").ToTranslationTier(); var callback = json.Value <string>("callback_url"); Uri.TryCreate(callback, UriKind.Absolute, out _callbackUrl); var fileUrl = json.Value <string>("tgt_file_link"); Uri.TryCreate(fileUrl, UriKind.Absolute, out _fileUrl); }
public ILEmitterCtx( MemoryManager memory, TranslatorCache cache, TranslatorQueue queue, TranslationTier tier) { Memory = memory ?? throw new ArgumentNullException(nameof(memory)); _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _queue = queue ?? throw new ArgumentNullException(nameof(queue)); Tier = tier; _labels = new Dictionary <long, ILLabel>(); _irLabels = new Dictionary <ILLabel, BasicBlock>(); _irBlocks = new List <BasicBlock>(); NewNextBlock(); EmitSynchronization(); EmitLoadContext(); }
public ILEmitterCtx(TranslatorCache cache, TranslatorQueue queue, TranslationTier tier, Block graph) { _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _queue = queue ?? throw new ArgumentNullException(nameof(queue)); _currBlock = graph ?? throw new ArgumentNullException(nameof(graph)); Tier = tier; _labels = new Dictionary <long, ILLabel>(); _visitedBlocks = new Dictionary <Block, ILBlock>(); _visitedBlocks.Add(graph, new ILBlock()); _branchTargets = new Queue <Block>(); _ilBlocks = new List <ILBlock>(); _subPosition = graph.Position; ResetBlockState(); AdvanceOpCode(); }
protected Job(JObject json) { if (json == null) throw new ArgumentNullException("json"); _readOnly = true; _autoApprove = json.Value<string>("auto_approve") == "1"; _force = json.Value<string>("force") == "1"; _body = json.Value<string>("body_src"); _comment = json.Value<string>("comment"); _customData = json.Value<string>("custom_data"); _slug = json.Value<string>("slug"); _sourceLang = json.Value<string>("lc_src"); _targetLang = json.Value<string>("lc_tgt"); if (json.SelectToken("max_chars") != null) { _maximumCharacters = json.Value<int>("max_chars"); } _type = json.Value<string>("type").ToJobType(); _tier = json.Value<string>("tier").ToTranslationTier(); var callback = json.Value<string>("callback_url"); Uri.TryCreate(callback, UriKind.Absolute, out _callbackUrl); var fileUrl = json.Value<string>("tgt_file_link"); Uri.TryCreate(fileUrl, UriKind.Absolute, out _fileUrl); }
public TranslatedSub(DynamicMethod method, TranslationTier tier, bool rejit) { Method = method ?? throw new ArgumentNullException(nameof(method));; Tier = tier; _rejit = rejit; }
public TranslatedSub Build(BasicBlock[] blocks, string name, TranslationTier tier, bool rejit = true) { _regUsage = new RegisterUsage(blocks[0], blocks.Length); DynamicMethod method = new DynamicMethod(name, typeof(long), TranslatedSub.FixedArgTypes); TranslatedSub subroutine = new TranslatedSub(method, tier, rejit); _locals = new Dictionary <Register, int>(); Dictionary <ILLabel, Label> labels = new Dictionary <ILLabel, Label>(); ILGenerator generator = method.GetILGenerator(); Label GetLabel(ILLabel label) { if (!labels.TryGetValue(label, out Label ilLabel)) { ilLabel = generator.DefineLabel(); labels.Add(label, ilLabel); } return(ilLabel); } foreach (BasicBlock block in blocks) { for (int index = 0; index < block.Count; index++) { Operation operation = block.GetOperation(index); switch (operation.Type) { case OperationType.Call: generator.Emit(OpCodes.Call, operation.GetArg <MethodInfo>(0)); break; case OperationType.CallVirtual: generator.Emit(OpCodes.Callvirt, operation.GetArg <MethodInfo>(0)); break; case OperationType.IL: generator.Emit(operation.GetArg <OpCode>(0)); break; case OperationType.ILBranch: generator.Emit(operation.GetArg <OpCode>(0), GetLabel(operation.GetArg <ILLabel>(1))); break; case OperationType.LoadArgument: generator.EmitLdarg(operation.GetArg <int>(0)); break; case OperationType.LoadConstant: EmitLoadConstant(generator, operation.GetArg(0)); break; case OperationType.LoadContext: EmitLoadContext(generator, operation.Parent); break; case OperationType.LoadField: generator.Emit(OpCodes.Ldfld, operation.GetArg <FieldInfo>(0)); break; case OperationType.LoadLocal: EmitLoadLocal( generator, operation.GetArg <int>(0), operation.GetArg <RegisterType>(1), operation.GetArg <RegisterSize>(2)); break; case OperationType.MarkLabel: generator.MarkLabel(GetLabel(operation.GetArg <ILLabel>(0))); break; case OperationType.StoreContext: EmitStoreContext(generator, operation.Parent); break; case OperationType.StoreLocal: EmitStoreLocal( generator, operation.GetArg <int>(0), operation.GetArg <RegisterType>(1), operation.GetArg <RegisterSize>(2)); break; } } } subroutine.PrepareMethod(); return(subroutine); }
public TranslatorQueueItem(long position, ExecutionMode mode, TranslationTier tier) { Position = position; Mode = mode; Tier = tier; }
internal static string ToTierString(this TranslationTier tier) { return(tier.ToString().ToLowerInvariant()); }