/// <summary> /// Visit a parse tree produced by <see cref="Generated.Z80AsmParser.compoundOperation"/>. /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public override object VisitCompoundOperation(Z80AsmParser.CompoundOperationContext context) { if (IsInvalidContext(context)) { return(null); } var op = new CompoundOperation { Mnemonic = context.GetChild(0).NormalizeToken() }; var operandFound = false; foreach (var child in context.children) { // --- Collect operands if (child is Z80AsmParser.OperandContext operandChild) { if (!operandFound) { op.Operand = (Operand)VisitOperand(operandChild); } else { op.Operand2 = (Operand)VisitOperand(operandChild); } operandFound = true; continue; } // --- Collect optional condition if (child is Z80AsmParser.ConditionContext condChild) { op.Condition = condChild.GetText().NormalizeToken(); continue; } // --- Collect optional bit index if (child is Z80AsmParser.ExprContext exprChild) { op.BitIndex = (ExpressionNode)VisitExpr(exprChild); } } return(AddLine(op, context)); }
/// <summary> /// Compounds data to create new operand. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="binders"></param> /// <returns></returns> public T Compound <T>([NotEmptyArray] params PinBinder[] binders) where T : PinBinder { Pin[] inputs = new Pin[binders.Length]; for (int i = 0; i < binders.Length; i++) { if (binders[i] == null || binders[i].Generator != this) { throw new ArgumentException("Mixing generators."); } inputs[i] = binders[i].Pin; } CompoundOperation op = new CompoundOperation(); op.BindInputs(inputs); // We create output, it may not match (cast exception thrown). return((T)CreateFrom(op.Outputs[0])); }
internal static Pin Compound(out CodeGenerator generator, params object[] objs) { generator = null; Pin[] pins = new Pin[objs.Length]; for (int i = 0; i < objs.Length; i++) { object obj = objs[i]; if (obj is PinBinder) { pins[i] = ((PinBinder)obj).Pin; CodeGenerator g = ((PinBinder)obj).Generator; if (generator != null) { if (generator != g) { throw new ArgumentException("Mixing generators."); } } else { generator = g; } } else { pins[i] = generator.dag.CreateFixed(obj).Outputs[0]; } } // Create compounds operation and return. CompoundOperation op = new CompoundOperation(); op.BindInputs(pins); return(op.Outputs[0]); }