private void AddStatement(EPStatement stmt) { // statement may be added already if (_listeners.ContainsKey(stmt)) { return; } // attach listener UpdateEventHandler updateEventHandler; if (_collector == null) { updateEventHandler = new EmitterUpdateListener( _emittables, _submitEventBean).Update; } else { var emitterForCollector = new LocalEmitter(_emittables); updateEventHandler = new EmitterCollectorUpdateListener( _collector, emitterForCollector, _collectorDataTL, _submitEventBean).Update; } stmt.Events += updateEventHandler; // save listener instance _listeners.Put(stmt, updateEventHandler); }
public EmitterCollectorUpdateListener(EPDataFlowIRStreamCollector collector, LocalEmitter emitterForCollector, IThreadLocal <EPDataFlowIRStreamCollectorContext> collectorDataTL, bool submitEventBean) { _collector = collector; _emitterForCollector = emitterForCollector; _collectorDataTL = collectorDataTL; _submitEventBean = submitEventBean; }
public override void PatchContents(IReadOnlyList <TranslationContent> contents) { foreach (var method in ModModule.Types.SelectMany(x => x.Methods).Where(x => x.HasBody)) { var emitter = new LocalEmitter(method, Provider); var instructions = method.Body.Instructions; for (var i = 0; i < instructions.Count; i++) { var instruction = instructions[i]; if (instruction.OpCode != OpCodes.Call || !(instruction.Operand is IMethodDefOrRef m) || !m.IsMethod( nameof(Terraria.ModLoader.Mod), nameof(Terraria.ModLoader.Mod.CreateTranslation))) { continue; } var stloc = instructions[i + 1]; if (!stloc.IsStloc()) { continue; } var key = (string)method.Body.FindStringLiteralBefore(instruction)?.Operand; if (key == null) { continue; } var content = contents.SingleOrDefault(x => string.Equals(key, x.Key, StringComparison.Ordinal)); if (content == null) { continue; } emitter.Emit(stloc, content.Value); } } }
public void EmitLocals(BoundTypeManager typeManager) { _magicTypes = _body.TypeManager.MagicTypes.ToDictionary(p => p.MagicType, p => p.Type); // Create the arguments local if it's required and there isn't // a closure field for it. if ((_body.Flags & BoundBodyFlags.ArgumentsReferenced) != 0 && ArgumentsEmitter == null) { var type = _magicTypes[BoundMagicVariableType.Arguments]; var argumentsEmitter = CreateEmitter(type); argumentsEmitter.DeclareLocal(); ArgumentsEmitter = argumentsEmitter; _locals.Add(type, argumentsEmitter); } if ((_body.Flags & BoundBodyFlags.GlobalReferenced) != 0) { _globalLocal = IL.DeclareLocal(typeof(JsGlobal)); EmitLoad(SpecialLocal.Runtime); IL.EmitCall(_runtimeGetGlobal); IL.Emit(OpCodes.Stloc, _globalLocal); } if ((_body.Flags & BoundBodyFlags.GlobalScopeReferenced) != 0) { var type = _magicTypes[BoundMagicVariableType.Global]; GlobalScopeEmitter = CreateEmitter(type); GlobalScopeEmitter.DeclareLocal(); GlobalScopeEmitter.EmitSetValue(new BoundEmitExpression( BoundValueType.Object, () => { EmitLoad(SpecialLocal.Runtime); IL.EmitCall(_runtimeGetGlobalScope); } )); _locals.Add(type, GlobalScopeEmitter); } if ((_body.Flags & BoundBodyFlags.ThisReferenced) != 0) { // We can't set assign to _thisLocal because then EmitLoad // would return the local. var type = _magicTypes[BoundMagicVariableType.This]; var thisLocal = CreateEmitter(type); thisLocal.DeclareLocal(); thisLocal.EmitSetValue(new BoundEmitExpression( BoundValueType.Unknown, () => EmitLoad(SpecialLocal.This) )); _thisLocal = thisLocal; _locals.Add(type, _thisLocal); } var getUnknown = new BoundGetVariable(BoundMagicVariable.Undefined); foreach (var type in typeManager.Types) { if (type.Type == BoundValueType.Unset) continue; if (type.Kind == BoundTypeKind.Local || type.Kind == BoundTypeKind.Temporary) { var emitter = CreateEmitter(type); emitter.DeclareLocal(); if (type.Kind == BoundTypeKind.Local) emitter.Local.SetLocalSymInfo(type.Name); if (!type.DefinitelyAssigned) emitter.EmitSetValue(getUnknown); _locals.Add(type, emitter); } else if (type.Kind == BoundTypeKind.ClosureField) { _locals.Add(type, new ClosureFieldEmitter( Generator, Closure.Fields[type.Name] )); } } }