/// <summary>
        /// Allocate a field of the state machine of the given type, to serve as a temporary.
        /// </summary>
        private SynthesizedFieldSymbolBase AllocTemp(TypeSymbol type)
        {
            SynthesizedFieldSymbolBase result = null;

            // See if we've allocated a temp field we can reuse.  Not particularly efficient, but
            // there should not normally be a lot of hoisted temps.
            for (int i = 0; i < availableFields.Count; i++)
            {
                SynthesizedFieldSymbolBase f = availableFields[i];
                if (f.Type == type)
                {
                    result = f;
                    availableFields.RemoveAt(i);
                    break;
                }
            }

            if ((object)result == null)
            {
                var fieldName = GeneratedNames.SpillTempName(nextTempNumber++);
                result = F.StateMachineField(type, fieldName, isPublic: true);
            }

            return(result);
        }
Ejemplo n.º 2
0
            internal void AllocateField(BoundSpillTemp spill)
            {
                Debug.Assert(!realizedSpills.ContainsKey(spill));

                FieldSymbol field;

                if (!allocatedFields.TryPop(spill.Type, out field))
                {
                    field = F.SynthesizeField(spill.Type, GeneratedNames.SpillTempName(CompilationState.GenerateTempNumber()));
                }

                realizedSpills[spill] = field;
            }