protected sealed override IEnumerator ProcessPayload(VisualPayload payload) { var window = GetWindowVisualizer(payload); var disasmsEntries = new List <DisasmEntryDescriptor>(); foreach (var entry in CollectionScope.GetEntries(payload.Data)) { var index = InstructionIndex.GetValue(entry); var disasmText = DisasmText.GetValue(entry); disasmsEntries.Add(new DisasmEntryDescriptor(index, disasmText)); } window.DisasmEntries = disasmsEntries; yield return(null); }
private int[] InstructionSparsity(InstructionIndex instr, SparsityInfo[] children, Dictionary <Variable, SparsityInfo> mapping) { var idx = instr.Indices; var c = children[0]; var ret = new List <int>(); // Sample the sparsity of the child using the slice, correct for offset for (int i = 0; i < idx.Length; i++) { if (SparsityContains(c.Sparsity, idx[i])) { ret.Add(i); } } return(ret.ToArray()); }
public override int GetHashCode() { return(InstructionIndex.GetHashCode()); }
/* * Translate an index instruction. The index instruction contains the * indices of the slice it should return inside the instruction. The * expression to index is the first child of the current context node. * * This method allocates a temporary storage for the result of the * expression to index of necessary. This is necessary if: * * 1. The expression is multidimensional AND * 2. The expression is not already stored in global network memory * * The second condition holds for example for variables which are in * the state table. In addition, for languages that support first class * arrays, a temporary variable never needs to be allocated since the * results of the expression are simply stored in an array on the * stack, allocated by the return result of the expression. * * If the result of the indexing is multidimensional, then there are * two separate cases. * * 1. The indexing operation is a simple _offset_ + length in the * expression (i.e. a slice of adjacent elements) * 2. The indexing operation indexes randomly * * The following conditions determine how to deal with these cases: * * 1. Return value of indexing needs to be stored in temporary * 1.1 Use language specific memcpy to copy the result to the temporary * 1.2 Assign each element to the temporary using comma operators * 2. SupportsPointers * 2.1 Add offset to child expression pointer * 2.2 Case does not occur since temporary has been allocated for this case * 3. FirstClassArrays * 3.1 Use language specific array slice operation * 3.2 Use language specific array slice indices operation */ protected virtual string Translate(InstructionIndex instruction, Context context) { var child = context.Node.Children[0]; string tmp = null; string toindex; if (child.Dimension.IsOne || InstructionHasStorage(child.Instruction, context)) { context.PushRet(null); toindex = Translate(context, child); context.PopRet(); } else { tmp = context.AcquireTemporary(child); context.PushRet(tmp); toindex = Translate(context, child); context.PopRet(); } string ret = null; // Check if the thing to index is just one thing, then we can // directly return that thing if (child.Dimension.IsOne) { return(toindex); } // Check if the result is just 1x1 if (context.Node.Dimension.IsOne) { ret = String.Format("({0})[{1}]", toindex, instruction.Indices[0]); } else if (instruction.IndexType == Cdn.InstructionIndexType.Offset) { var retvar = context.PeekRet(); if (retvar != null) { // Need to copy to retvar ret = context.MemCpy(retvar, "0", toindex, instruction.Offset.ToString(), "ValueType", context.Node.Dimension.Size()); } else if (context.SupportsPointers) { // Otherwise we can jsut return it ret = String.Format("(({0}) + {1})", toindex, instruction.Offset); } else if (context.SupportsFirstClassArrays) { var size = context.Node.Dimension.Size(); ret = context.ArraySlice(toindex, instruction.Offset.ToString(), (instruction.Offset + size).ToString()); } else { // TODO throw new Exception("Don't know what to do without pointers."); } } else { // Too bad! Really just need to index here var retvar = context.PeekRet(); var indices = instruction.Indices; if (retvar != null) { StringBuilder rets = new StringBuilder(); if (tmp != null) { rets.Append(toindex); } for (int i = 0; i < indices.Length; ++i) { if (i != 0 || tmp != null) { rets.Append(", "); } rets.AppendFormat("({0})[{1}] = ({2})[{3}]", retvar, i, tmp != null ? tmp : toindex, indices[i]); } ret = String.Format("({0}, {1})", rets.ToString(), retvar); } else if (context.SupportsFirstClassArrays) { ret = context.ArraySliceIndices(toindex, indices); } else { throw new Exception("Can't random index without first class arrays support"); } } return(ret); }
protected virtual string TranslateV(InstructionIndex instruction, Context context) { return(Translate(instruction, context)); }