public LocalElement GetNewVariable(Type variableType)
        {
            List <VariableStatus> currentList = null;
            VariableStatus        currentVariable;

            if (!currentPool.TryGetValue(variableType, out currentList))
            {
                currentList = new List <VariableStatus>();
                currentPool.Add(variableType, currentList);
            }

            if (!currentList.Where(_1 => _1.IsFree).Any())
            {
                currentVariable          = new VariableStatus();
                currentVariable.Variable = g.DeclareLocal(variableType);
                currentList.Add(currentVariable);
            }
            else
            {
                currentVariable = currentPool[variableType].First(_1 => _1.IsFree);
            }

            currentVariable.IsFree = false;
            return(currentVariable.Variable);
        }
            public bool AddConstant(ulong value)
            {
                if (Status == VariableStatus.OverDefined)
                {
                    return(false);
                }

                if (constants != null)
                {
                    if (constants.Contains(value))
                    {
                        return(false);
                    }
                }
                else
                {
                    constants = new List <ulong>(2);
                    constants.Add(value);
                    Status = VariableStatus.SingleConstant;
                    return(true);
                }

                if (constants.Count > MAXCONSTANTS)
                {
                    Status    = VariableStatus.OverDefined;
                    constants = null;
                    return(true);
                }

                constants.Add(value);
                Status = VariableStatus.MultipleConstants;
                return(true);
            }
        public void MarkVariableLive(VariableReference variableReference, Terminal outputTerminal)
        {
            VariableStatus existingStatus;

            if (_variableStatuses.TryGetValue(variableReference, out existingStatus) && existingStatus.Kind == VariableStatusKind.Consumed)
            {
                throw new InvalidOperationException("Trying to mark a variable live that was already marked consumed");
            }
            _variableStatuses[variableReference] = VariableStatus.CreateLiveStatus(outputTerminal);
        }
            public VariableState(Operand operand)
            {
                Operand = operand;

                if (operand.IsVirtualRegister)
                {
                    Status = VariableStatus.NeverDefined;
                }
                else if (operand.IsConstant && operand.IsInteger)
                {
                    AddConstant(operand.ConstantUnsignedLongInteger);
                }
                else
                {
                    IsOverDefined = true;
                }
            }
            public VariableState(Operand operand)
            {
                Operand = operand;

                if (operand.IsVirtualRegister)
                {
                    Status = VariableStatus.NeverDefined;
                }
                else if (operand.IsConstant && operand.IsInteger)
                {
                    ConstantUnsignedLongInteger = operand.ConstantUnsignedLongInteger;
                    IsConstant = true;
                }
                else
                {
                    IsOverDefined = true;
                }
            }
            public bool AddConstant(ulong value)
            {
                if (Status == VariableStatus.OverDefined)
                    return false;

                if (constants != null)
                {
                    if (constants.Contains(value))
                        return false;
                }
                else
                {
                    constants = new List<ulong>(2);
                    constants.Add(value);
                    Status = VariableStatus.SingleConstant;
                    return true;
                }

                if (constants.Count > MAXCONSTANTS)
                {
                    Status = VariableStatus.OverDefined;
                    constants = null;
                    return true;
                }

                constants.Add(value);
                Status = VariableStatus.MultipleConstants;
                return true;
            }