コード例 #1
0
        public void Push(T newElement)
        {
            StackElement temp = new StackElement(newElement, _peek);

            _peek = temp;
            Length++;
        }
コード例 #2
0
        /// <summary>
        /// Emits a not instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement value  = context.CurrentStack.Pop();
            ValueRef     result = LLVM.BuildNot(builder, value.Value, "not");

            context.CurrentStack.Push(new StackElement(result, value.ILType, value.Type));
        }
コード例 #3
0
        /// <summary>
        /// Emits a rem instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement value2 = context.CurrentStack.Pop();
            StackElement value1 = context.CurrentStack.Pop();

            if (TypeHelper.IsFloatingPoint(value1) || TypeHelper.IsFloatingPoint(value2))
            {
                ValueRef result = LLVM.BuildFRem(builder, value1.Value, value2.Value, "remfp");
                context.CurrentStack.Push(new StackElement(result, value1.ILType, value1.Type));
            }
            else
            {
                CastHelper.HelpIntCast(builder, ref value1, ref value2);
                ValueRef result;

                if (instruction.OpCode.Code == Code.Rem)
                {
                    result = LLVM.BuildSRem(builder, value1.Value, value2.Value, "remsi");
                }
                else /* Rem_Un */
                {
                    result = LLVM.BuildURem(builder, value1.Value, value2.Value, "remui");
                }

                context.CurrentStack.Push(new StackElement(result, value1.ILType, value1.Type));
            }
        }
コード例 #4
0
ファイル: EmitLdind.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a Ldind instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            Code         code    = instruction.OpCode.Code;
            StackElement pointer = context.CurrentStack.Pop();

            ValueRef ptr     = pointer.Value;
            TypeRef  ptrType = LLVM.PointerType(TypeHelper.GetTypeRefFromStOrLdind(code), 0);

            if (pointer.Type != ptrType)
            {
                CastHelper.HelpIntAndPtrCast(builder, ref ptr, ref pointer.Type, ptrType, "ldindcast");
            }

            ValueRef res = LLVM.BuildLoad(builder, ptr, "elem");

            // Some need to be pushed as an int32 on the stack.
            if (code == Code.Ldind_I1 || code == Code.Ldind_I2 || code == Code.Ldind_I4 ||
                code == Code.Ldind_U1 || code == Code.Ldind_U2 || code == Code.Ldind_U4)
            {
                res = LLVM.BuildIntCast(builder, res, TypeHelper.Int32, "tmp");
            }

            TypeRef type = LLVM.TypeOf(res);

            context.CurrentStack.Push(new StackElement(res, TypeHelper.GetBasicTypeFromTypeRef(type), type));
        }
コード例 #5
0
        public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
        {
            if (args[0].Variability == Msil.EVariability.ExternVariable)
                throw new NotSupportedException("Delegate calls must have constant target!");

            Delegate deleg = (Delegate)args[0].Sample;
            if (deleg == null)
                return false;

            StackElement[] callArgs;
            if (deleg.Method.IsStatic)
            {
                callArgs = new StackElement[args.Length - 1];
                Array.Copy(args, 1, callArgs, 0, args.Length - 1);
            }
            else
            {
                callArgs = new StackElement[args.Length];
                Array.Copy(args, callArgs, args.Length);
                callArgs[0].Sample = deleg.Target;
                callArgs[0].Expr = LiteralReference.CreateConstant(deleg.Target);
                callArgs[0].Variability = Msil.EVariability.Constant;
            }
            stack.ImplementCall(deleg.Method, callArgs);
            return true;
        }
コード例 #6
0
        /// <summary>
        /// Добавить значение в стек
        /// </summary>
        /// <param name="value">Значение</param>
        public void Push(T value)
        {
            StackElement newElement = new StackElement(head, value);

            head = newElement;
            ++Length;
        }
コード例 #7
0
 public void Push(int value)
 {
     if (count < capacity)
     {
         if (count == 0)
         {
             stack[count] = new StackElement()
             {
                 Value = value, MaxValue = value
             };
             count++;
         }
         else
         {
             StackElement element = new StackElement();
             element.Value = value;
             if (value < stack[count - 1].MaxValue)
             {
                 element.MaxValue = stack[count - 1].MaxValue;
             }
             else
             {
                 element.MaxValue = value;
             }
             stack[count] = element;
             count++;
         }
     }
 }
コード例 #8
0
ファイル: Stack.cs プロジェクト: DolgopolovaMaria/Old
        /// <summary>
        /// добавить значение в стек
        /// </summary>
        /// <param name="value">значение для добавления</param>
        public void Push(T value)
        {
            StackElement newHead = new StackElement(value, head);

            head = newHead;
            length++;
        }
コード例 #9
0
 /// <summary>
 /// Pushes new element to the stack.
 /// </summary>
 /// <param name="num"></param>
 public void Push(int num)
 {
     StackElement temp = new StackElement();
     temp.value = num;
     temp.next = head;
     head = temp;
 }
コード例 #10
0
 /// <summary>
 /// Pops the element from the top of stack.
 /// </summary>
 public int Pop()
 {
     int result = Top();
     if (!IsEmpty())
         head = head.next;
     return result;
 }
コード例 #11
0
ファイル: EmitStloc.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a stloc instruction
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            Code code = instruction.OpCode.Code;

            int index;

            if (code >= Code.Stloc_0 && code <= Code.Stloc_3)
            {
                index = instruction.OpCode.Code - Code.Stloc_0;
            }
            else
            {
                VariableDefinition def = (VariableDefinition)instruction.Operand;
                index = def.Index;
            }

            StackElement element  = context.CurrentStack.Pop();
            ValueRef     data     = element.Value;
            TypeRef      destType = context.LocalTypes[index];

            // Possible cast needed.
            if (element.Type != destType)
            {
                CastHelper.HelpIntAndPtrCast(builder, ref data, ref element.Type, destType, "stloccast");
            }

            LLVM.BuildStore(builder, data, context.LocalValues[index]);
        }
コード例 #12
0
ファイル: EmitLdfld.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a ldfld instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement   obj   = context.CurrentStack.Pop();
            FieldReference field = (FieldReference)instruction.Operand;

            uint index = context.Compiler.Lookup.GetFieldIndex(field);

            // Create pointer if not yet a pointer.
            if (obj.ILType.IsValueType && !obj.ILType.IsPointer)
            {
                ValueRef objPtr = LLVM.BuildAlloca(builder, obj.Type, "objptr");
                LLVM.BuildStore(builder, obj.Value, objPtr);
                obj.Value = objPtr;
            }

            ValueRef ptr    = LLVM.BuildInBoundsGEP(builder, obj.Value, new ValueRef[] { LLVM.ConstInt(TypeHelper.Int32, 0, false), LLVM.ConstInt(TypeHelper.Int32, index, false) }, "field");
            ValueRef result = LLVM.BuildLoad(builder, ptr, "field");

            if (instruction.HasPrefix(Code.Volatile))
            {
                LLVM.SetVolatile(result, true);
            }

            context.CurrentStack.Push(new StackElement(result, field.FieldType));
        }
コード例 #13
0
        /// <summary>
        /// Helps with the pointer casting so that both values are of the same type.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="value1">The first value.</param>
        /// <param name="value2">The second value.</param>
        /// <param name="isPtrVal1">If the first value was a pointer.</param>
        /// <param name="isPtrVal2">If the second value was a pointer.</param>
        /// <param name="name">The name of the cast.</param>
        public static void HelpPossiblePtrCast(BuilderRef builder, ref StackElement value1, ref StackElement value2, out bool isPtrVal1, out bool isPtrVal2, string name)
        {
            isPtrVal1 = TypeHelper.IsPointer(value1);
            isPtrVal2 = TypeHelper.IsPointer(value2);

            if (isPtrVal1 || isPtrVal2)
            {
                if (isPtrVal1)
                {
                    value1.Value = LLVM.BuildPtrToInt(builder, value1.Value, TypeHelper.NativeIntType, "tmp");
                }
                else
                {
                    value1.Value = LLVM.BuildIntCast(builder, value1.Value, TypeHelper.NativeIntType, "tmp");
                }

                if (isPtrVal2)
                {
                    value2.Value = LLVM.BuildPtrToInt(builder, value2.Value, TypeHelper.NativeIntType, "tmp");
                }
                else
                {
                    value2.Value = LLVM.BuildIntCast(builder, value2.Value, TypeHelper.NativeIntType, "tmp");
                }
            }
        }
コード例 #14
0
 /// <summary>
 /// Ensure the this element is properly placed in the SSML markup
 /// </summary>
 private static void ValidateElement(StackElement stackElement, SsmlElement currentElement)
 {
     if ((stackElement._possibleChildren & currentElement) == 0)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, SR.Get(SRID.PromptBuilderInvalidElement), currentElement.ToString(), stackElement._state.ToString()));
     }
 }
コード例 #15
0
ファイル: Stack.cs プロジェクト: RudenkoDmitriy/for_study
 public void Push(int num)
 {
     StackElement temp = new StackElement();
     temp.Num = num;
     temp.Next = this.head;
     this.head = temp;
 }
コード例 #16
0
ファイル: EmitStind.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a stind instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement value   = context.CurrentStack.Pop();
            StackElement pointer = context.CurrentStack.Pop();

            ValueRef val         = value.Value;
            ValueRef ptr         = pointer.Value;
            TypeRef  destType    = TypeHelper.GetTypeRefFromStOrLdind(instruction.OpCode.Code);
            TypeRef  destPtrType = LLVM.PointerType(destType, 0);

            if (destPtrType != pointer.Type)
            {
                // There is no instruction for a Stind to store a boolean, so we need to check manually.
                if (pointer.Type == LLVM.PointerType(TypeHelper.Boolean, 0))
                {
                    destType = TypeHelper.Boolean;
                }
                // We treat char as 8-bit.
                else if (pointer.Type == LLVM.PointerType(TypeHelper.Int8, 0))
                {
                    destType = TypeHelper.Int8;
                }

                val = LLVM.BuildIntCast(builder, val, destType, "stindcast");

                // If the pointer is a native int, convert to a pointer of the appropriate type.
                if (pointer.Type == TypeHelper.NativeIntType)
                {
                    ptr = LLVM.BuildIntToPtr(builder, ptr, destPtrType, "int2ptr");
                }
            }

            LLVM.BuildStore(builder, val, ptr);
        }
コード例 #17
0
 public static IEnumerable<T> FindAllVisualDescendantByNameOfType<T>(this FrameworkElement parent, String name) where T : FrameworkElement
 {
     if (parent == null)
         yield break;
     Stack<StackElement> stack = new Stack<StackElement>();
     int i = 0;
     while (true)
     {
         if (i < VisualTreeHelper.GetChildrenCount(parent))
         {
             FrameworkElement child = VisualTreeHelper.GetChild(parent, i) as FrameworkElement;
             if (child != null)
             {
                 T t = child as T;
                 if (t != null && t.Name == name)
                     yield return t;
                 stack.Push(new StackElement { Element = parent, Position = i });
                 parent = child;
                 i = 0;
                 continue;
             }
             ++i;
         }
         else
         {
             // back at the root of the search
             if (stack.Count == 0)
                 yield break;
             StackElement element = stack.Pop();
             parent = element.Element;
             i = element.Position;
             ++i;
         }
     }
 }
コード例 #18
0
        // deletes an element in the top of the stack
        public int Pop()
        {
            int value = top.Value;

            top = top.Next;
            return(value);
        }
コード例 #19
0
        public void StartSentence(CultureInfo culture)
        {
            // check for well formed document
            StackElement stackElement = _elementStack.Peek();

            ValidateElement(stackElement, SsmlElement.Sentence);

            Element startSentence = new(ElementType.StartSentence);

            _elements.Add(startSentence);

            if (culture != null)
            {
                if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    throw new ArgumentException(SR.Get(SRID.InvariantCultureInfo), nameof(culture));
                }

                startSentence._attributes = new Collection <AttributeItem>();
                startSentence._attributes.Add(new AttributeItem("xml", "lang", culture.Name));
            }
            else
            {
                culture = stackElement._culture;
            }
            _elementStack.Push(new StackElement(SsmlElement.AudioMarkTextWithStyle, SsmlState.Sentence, culture));
        }
コード例 #20
0
ファイル: EmitStfld.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a stfld instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement   value = context.CurrentStack.Pop();
            StackElement   obj   = context.CurrentStack.Pop();
            FieldReference field = (FieldReference)instruction.Operand;

            uint index = context.Compiler.Lookup.GetFieldIndex(field);

            ValueRef ptr = LLVM.BuildInBoundsGEP(builder, obj.Value, new ValueRef[] { LLVM.ConstInt(TypeHelper.Int32, 0, false), LLVM.ConstInt(TypeHelper.Int32, index, false) }, "field");

            // Possible cast needed.
            TypeRef destType = TypeHelper.GetTypeRefFromType(field.FieldType);

            if (value.Type != destType)
            {
                CastHelper.HelpIntAndPtrCast(builder, ref value.Value, ref value.Type, destType, "stfldcast");
            }

            ValueRef store = LLVM.BuildStore(builder, value.Value, ptr);

            if (instruction.HasPrefix(Code.Volatile))
            {
                LLVM.SetVolatile(store, true);
            }
        }
コード例 #21
0
        /// <summary>
        /// Emits a localloc instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement size   = context.CurrentStack.Pop();
            ValueRef     result = LLVM.BuildArrayAlloca(builder, TypeHelper.Int8, size.Value, "stackalloc");

            context.CurrentStack.Push(new StackElement(result, typeof(byte[]).GetTypeReference()));
        }
コード例 #22
0
        public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
        {
            if (args[0].Variability == Msil.EVariability.ExternVariable)
            {
                throw new NotSupportedException("Delegate calls must have constant target!");
            }

            Delegate deleg = (Delegate)args[0].Sample;

            if (deleg == null)
            {
                return(false);
            }

            StackElement[] callArgs;
            if (deleg.Method.IsStatic)
            {
                callArgs = new StackElement[args.Length - 1];
                Array.Copy(args, 1, callArgs, 0, args.Length - 1);
            }
            else
            {
                callArgs = new StackElement[args.Length];
                Array.Copy(args, callArgs, args.Length);
                callArgs[0].Sample      = deleg.Target;
                callArgs[0].Expr        = LiteralReference.CreateConstant(deleg.Target);
                callArgs[0].Variability = Msil.EVariability.Constant;
            }
            stack.ImplementCall(deleg.Method, callArgs);
            return(true);
        }
コード例 #23
0
ファイル: EmitCompare.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a compare instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement value2 = context.CurrentStack.Pop();
            StackElement value1 = context.CurrentStack.Pop();
            ValueRef     ret;

            if (TypeHelper.IsFloatingPoint(value2) || TypeHelper.IsFloatingPoint(value1))
            {
                ret = LLVM.BuildFCmp(builder, PredicateHelper.GetRealPredicateFromCode(instruction.OpCode.Code), value1.Value, value2.Value, "fcmp");
            }
            else
            {
                if (value2.Type != value1.Type)
                {
                    ValueRef tmp = LLVM.BuildIntCast(builder, value2.Value, value1.Type, "tmp");
                    ret = LLVM.BuildICmp(builder, PredicateHelper.GetIntPredicateFromCode(instruction.OpCode.Code), value1.Value, tmp, "icmp");
                }
                else
                {
                    ret = LLVM.BuildICmp(builder, PredicateHelper.GetIntPredicateFromCode(instruction.OpCode.Code), value1.Value, value2.Value, "icmp");
                }
            }

            context.CurrentStack.Push(new StackElement(ret, typeof(bool).GetTypeReference(), TypeHelper.Boolean));
        }
コード例 #24
0
        /// <summary>
        /// Emits an add instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement value2 = context.CurrentStack.Pop();
            StackElement value1 = context.CurrentStack.Pop();

            if (TypeHelper.IsFloatingPoint(value1) || TypeHelper.IsFloatingPoint(value2))
            {
                ValueRef result = LLVM.BuildFAdd(builder, value1.Value, value2.Value, "addfp");
                context.CurrentStack.Push(new StackElement(result, value1.ILType, value1.Type));
            }
            else
            {
                bool isPtrVal1, isPtrVal2;
                CastHelper.HelpPossiblePtrCast(builder, ref value1, ref value2, out isPtrVal1, out isPtrVal2, "addcast");

                // If one of the two values is a pointer, then the result will be a pointer as well.
                if (isPtrVal1 || isPtrVal2)
                {
                    ValueRef      result          = LLVM.BuildAdd(builder, value1.Value, value2.Value, "addptr");
                    TypeRef       resultingType   = (isPtrVal1 ? value1.Type : value2.Type);
                    TypeReference resultingILType = (isPtrVal1 ? value1.ILType : value2.ILType);
                    ValueRef      ptr             = LLVM.BuildIntToPtr(builder, result, resultingType, "ptr");
                    context.CurrentStack.Push(new StackElement(ptr, resultingILType, resultingType));
                }
                // Cast to different int size.
                else
                {
                    CastHelper.HelpIntCast(builder, ref value1, ref value2);
                    ValueRef result = LLVM.BuildAdd(builder, value1.Value, value2.Value, "addi");
                    context.CurrentStack.Push(new StackElement(result, value1.ILType, value1.Type));
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Добавление элемента в стек
        /// </summary>
        public void Push(Type value)
        {
            StackElement newElement = new StackElement();

            newElement.next  = head;
            newElement.value = value;
            head             = newElement;
        }
コード例 #26
0
ファイル: EmitLdftn.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a ldftn instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            MethodDefinition method  = (MethodDefinition)instruction.Operand;
            ValueRef         result  = LLVM.BuildIntToPtr(builder, context.Compiler.Lookup.GetFunction(NameHelper.CreateMethodName(method)).Value, TypeHelper.NativeIntType, "ldftn");
            StackElement     element = new StackElement(result, typeof(IntPtr).GetTypeReference(), TypeHelper.NativeIntType);

            context.CurrentStack.Push(element);
        }
コード例 #27
0
 public void Pop()
 {
     if (head == null)
     {
         throw new InvalidOperationException("Stack is empty");
     }
     head = head.next;
 }
コード例 #28
0
ファイル: Stack.cs プロジェクト: AndreiKorac/CTCI
        public void Push(int value)
        {
            StackElement stackElement = new StackElement(value);

            stackElement.NextElement = Top;
            Top = stackElement;
            Count++;
        }
コード例 #29
0
        public int Pop()
        {
            var tempValue = head.Value;

            head = head.Next;
            Count--;
            return(tempValue);
        }
コード例 #30
0
ファイル: StackOnList.cs プロジェクト: kosya/for_study
        public void Push(int num)
        {
            StackElement temp = new StackElement();

            temp.num  = num;
            temp.next = this.head;
            this.head = temp;
        }
コード例 #31
0
 /// <summary>
 /// Helps with the int casting so that both values are of the same type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="value1">The first value.</param>
 /// <param name="value2">The second value.</param>
 public static void HelpIntCast(BuilderRef builder, ref StackElement value1, ref StackElement value2)
 {
     if (value1.Type != value2.Type)
     {
         value2.Value  = LLVM.BuildIntCast(builder, value2.Value, value1.Type, "tmpintcast");
         value2.Type   = value1.Type;
         value2.ILType = value1.ILType;
     }
 }
コード例 #32
0
        /// <summary>
        /// Удаление элемента
        /// </summary>
        public void Pop()
        {
            if (head == null)
            {
                throw new InvalidOperationException("Стек пуст");
            }

            head = head.next;
        }
コード例 #33
0
ファイル: EmitLdelema.cs プロジェクト: SharpNative/CSharpLLVM
        /// <summary>
        /// Emits a ldelema instruction.
        /// </summary>
        /// <param name="instruction">The instruction.</param>
        /// <param name="context">The context.</param>
        /// <param name="builder">The builder.</param>
        public void Emit(Instruction instruction, MethodContext context, BuilderRef builder)
        {
            StackElement index = context.CurrentStack.Pop();
            StackElement array = context.CurrentStack.Pop();

            ValueRef gep = LLVM.BuildGEP(builder, array.Value, new ValueRef[] { index.Value }, "arrayelemptr");

            context.CurrentStack.Push(new StackElement(gep, array.ILType, array.Type));
        }
コード例 #34
0
            public void SetEnd(DateTime endDate, string className, string method)
            {
                StackElement temp = _root.Find(className, method);

                if (temp != null)
                {
                    temp.SetEnd(endDate);
                }
            }
コード例 #35
0
ファイル: Stack.cs プロジェクト: Julia-Khramyshkina/homeworks
 /// <summary>
 /// Push value to a stack.
 /// </summary>
 /// <param name="value">Value to be pushed.</param>
 public void Push(int value)
 {
     var newElement = new StackElement(value)
     {
         Next = head,
         Value = value
     };
     head = newElement;
 }
コード例 #36
0
ファイル: StackClass.cs プロジェクト: Gosed/HomeWorks
 /// <summary>
 /// Taking an element from stack
 /// </summary>
 public void Pop()
 {
     StackElement iterator = this.head;
     if (iterator == null)
     {
         throw new Exception("Stack is empty");
     }
     this.head = iterator.Next;
     Console.WriteLine(iterator.Data);
 }
コード例 #37
0
ファイル: Stack.cs プロジェクト: Julia-Khramyshkina/homeworks
 /// <summary>
 /// Get value from stack.
 /// </summary>
 public int Pop()
 {
     if (head == null)
     {
         return -1;
     }
     var temp = head.Value;
     head = head.Next;
     return temp;
 }
コード例 #38
0
ファイル: Stack.cs プロジェクト: Julia-Khramyshkina/homeworks
        /// <summary>
        /// Get value from stack.
        /// </summary>
        public int Pop()
        {
            if (IsEmpty())
            {
                return -33333;
            }

            var temp = head.Value;
            head = head.Next;
            return temp;
        }
コード例 #39
0
ファイル: Stack.cs プロジェクト: GalinaSazonova/2semester
        /// <summary>
        /// Returns head value 
        /// </summary>
        public int Pop()
        {
            if (head == null)
            {
                throw new Exception();
            }

            var temp = head.Value;
            head = head.Next;
            return temp;
        }
コード例 #40
0
        public void Push(int value)
        {
            StackElement newElement = new StackElement(value);
            if (this.head == null)
            {
                this.head = newElement;
                return;
            }

            newElement.Next = this.head;
            this.head = newElement;
        }
コード例 #41
0
        public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
        {
            var side = args[0].Sample as IXilinxBlockMemSide;
            if (side == null)
                return false;

            var code = IntrinsicFunctions.XILOpCode(
                DefaultInstructionSet.Instance.WrMem(side),
                typeof(void));
            builder.Call(code.Callee, args[1].Expr, args[2].Expr);
            return true;
        }
コード例 #42
0
ファイル: Stack.cs プロジェクト: RudenkoDmitriy/for_study
 public int Pop()
 {
     if (head == null)
     {
         Console.WriteLine("Stack is empty!");
         return 0;
     }
     int temp = this.head.Num;
     StackElement pos = this.head;
     this.head = this.head.Next;
     return temp;
 }
コード例 #43
0
 public void Push(int i)
 {
     StackElement element = new StackElement(i);
     if (top == null)
     {
         top = element;
     }
     else
     {
         element.Next = top;
         top = element;
     }
 }
コード例 #44
0
        public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
        {
            var side = args[0].Sample as IXilinxBlockMemSide;
            if (side == null)
                return false;

            var sample = StdLogicVector._0s(side.DataReadWidth);
            var code = IntrinsicFunctions.XILOpCode(
                DefaultInstructionSet.Instance.RdMem(side),
                TypeDescriptor.GetTypeOf(sample),
                args[1].Expr);
            stack.Push(code, sample);
            return true;
        }
コード例 #45
0
ファイル: Stack.cs プロジェクト: Gosed/HomeWorks
 /// <summary>
 /// Adds value to the list
 /// </summary>
 /// <param name="value">Value to add</param>
 public void push(int value)
 {
     StackElement tmp = new StackElement(value);
     if (this.head == null)
     {
         this.head = tmp;
         return;
     }
     StackElement iterator = this.head;
     while (iterator.Next != null)
     {
         iterator = iterator.Next;
     }
     iterator.Next = tmp;
 }
コード例 #46
0
ファイル: Stack.cs プロジェクト: koson/.NETMF_for_LPC17xx
        public object Pop()
        {
            if (top == null) return null;

            var elem = top;

            top = elem.Next;

            if (top == null)
            {
                bottom = null;
            }
            count--;
            return elem.Item;
        }
コード例 #47
0
ファイル: Stack.cs プロジェクト: koson/.NETMF_for_LPC17xx
        public void Push(object o)
        {
            var elem = new StackElement(o);

            if (bottom == null)
            {
                bottom = elem;
                top = elem;
            }
            else
            {
                bottom.Next = elem;
                bottom = elem;
            }
            count++;
        }
コード例 #48
0
ファイル: Stack.cs プロジェクト: GalinaSazonova/2semester
 /// <summary>
 /// Makes stack empty
 /// </summary>
 public void ClearStack()
 {
     head = null;
 }
コード例 #49
0
 public StackElement(int data, StackElement next)
 {
     this.data = data;
     this.next = next;
 }
コード例 #50
0
 public void SetTop(StackElement top)
 {
     this.top = top;
 }
コード例 #51
0
 public int Pop()
 {
     StackElement ret = top;
     top = top.Next;
     return ret.Data;
 }
コード例 #52
0
            public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
            {
                var ctx = stack.QueryAttribute<AsyncMethodDecompiler>();
                if (ctx.ImplStyle == EAsyncImplStyle.FSM)
                {
                    if (args.Length == 2 &&
                        ctx._curCoFSM.ResultVar != null)
                    {
                        builder.Store(ctx._curCoFSM.ResultVar, args[1].Expr);
                        if (args[1].Expr.ResultType.IsComplete)
                            ctx._curCoFSM.ResultVar.UpgradeType(args[1].Expr.ResultType);
                    }
                    
                    var si = ctx.ForkInitialSI();
                    var pi = new ProceedWithStateInfo()
                    {
                        TargetState = si,
                        TargetWaitState = false,
                        LambdaTransition = false
                    };

                    if (ctx._curCoFSM != null &&
                        ctx._curCoFSM.DoneVar != null)
                    {
                        var tr = LiteralReference.CreateConstant(true);
                        builder.Store(ctx._curCoFSM.DoneVar, tr);
                        pi.TargetState = null;
                    }

                    var fspec = new FunctionSpec(typeof(void))
                    {
                        IntrinsicRep = IntrinsicFunctions.ProceedWithState(pi)
                    };
                    builder.Call(fspec, LiteralReference.CreateConstant(pi));
                }
                return true;
            }
コード例 #53
0
ファイル: Stack.cs プロジェクト: koson/.NETMF_for_LPC17xx
 public void Clear()
 {
     top = null;
     bottom = null;
     count = 0;
 }
コード例 #54
0
 public override void RewriteWrite(CodeDescriptor decompilee, FieldInfo field, object instance, StackElement value, IDecompiler stack, IFunctionBuilder builder)
 {
     var me = stack.QueryAttribute<AsyncMethodDecompiler>();
     me._tasks[field.Name] = value;
 }
コード例 #55
0
 public override void RewriteWrite(CodeDescriptor decompilee, FieldInfo field, object instance, StackElement value, IDecompiler stack, IFunctionBuilder builder)
 {
     var me = stack.QueryAttribute<AsyncMethodDecompiler>();
     var v = me._argFields[field.Name];
     if (!me._declared.Contains(v))
     {
         builder.DeclareLocal(v);
         me._declared.Add(v);
     }
     builder.Store(v, value.Expr);
     if (value.Sample != null)
         v.UpgradeType(TypeDescriptor.GetTypeOf(value.Sample));
     if (me._curSI != null)
         me._curSI.LVState[field.Name] = value.Sample;
 }
コード例 #56
0
 public override void RewriteWrite(CodeDescriptor decompilee, FieldInfo field, object instance, StackElement value, IDecompiler stack, IFunctionBuilder builder)
 {
     var me = stack.QueryAttribute<AsyncMethodDecompiler>();
     try
     {
         field.SetValue(me._fsmInstance, value.Sample);
     }
     catch (Exception)
     {
         var task = me.GetTaskFromAwaiter(value.Sample);
         var awaiterType = field.FieldType;
         var targetAwaiter = Activator.CreateInstance(awaiterType);
         var targetAwaiterField = awaiterType.GetField("m_task", BindingFlags.Instance | BindingFlags.NonPublic);
         targetAwaiterField.SetValue(targetAwaiter, task);
         field.SetValue(me._fsmInstance, targetAwaiter);
     }
 }
コード例 #57
0
 public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
 {
     return true;
 }
コード例 #58
0
		void QSort3(int loSt, int hiSt, int dSt) 
		{
			int unLo, unHi, ltLo, gtHi, med, n, m;
			int lo, hi, d;
			
			StackElement[] stack = new StackElement[QSORT_STACK_SIZE];

			int sp = 0;
			
			stack[sp].ll = loSt;
			stack[sp].hh = hiSt;
			stack[sp].dd = dSt;
			sp++;
			
			while (sp > 0) {
				if (sp >= QSORT_STACK_SIZE) {
					Panic();
				}
				
				sp--;
				lo = stack[sp].ll;
				hi = stack[sp].hh;
				d = stack[sp].dd;
				
				if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {
					SimpleSort(lo, hi, d);
					if (workDone > workLimit && firstAttempt) {
						return;
					}
					continue;
				}
				
				med = Med3(block[zptr[lo] + d + 1],
						   block[zptr[hi            ] + d + 1],
						   block[zptr[(lo + hi) >> 1] + d + 1]);
				
				unLo = ltLo = lo;
				unHi = gtHi = hi;
				
				while (true) {
					while (true) {
						if (unLo > unHi) {
							break;
						}
						n = ((int)block[zptr[unLo]+d + 1]) - med;
						if (n == 0) {
							int temp = zptr[unLo];
							zptr[unLo] = zptr[ltLo];
							zptr[ltLo] = temp;
							ltLo++;
							unLo++;
							continue;
						}
						if (n >  0) {
							break;
						}
						unLo++;
					}

					while (true) {
						if (unLo > unHi) {
							break;
						}
						n = ((int)block[zptr[unHi]+d + 1]) - med;
						if (n == 0) {
							int temp = zptr[unHi];
							zptr[unHi] = zptr[gtHi];
							zptr[gtHi] = temp;
							gtHi--;
							unHi--;
							continue;
						}
						if (n <  0) {
							break;
						}
						unHi--;
					}

					if (unLo > unHi) {
						break;
					}

					{
						int temp = zptr[unLo];
						zptr[unLo] = zptr[unHi];
						zptr[unHi] = temp;
						unLo++;
						unHi--;
					}
				}
				
				if (gtHi < ltLo) {
					stack[sp].ll = lo;
					stack[sp].hh = hi;
					stack[sp].dd = d+1;
					sp++;
					continue;
				}
				
				n = ((ltLo-lo) < (unLo-ltLo)) ? (ltLo-lo) : (unLo-ltLo);
				Vswap(lo, unLo-n, n);
				m = ((hi-gtHi) < (gtHi-unHi)) ? (hi-gtHi) : (gtHi-unHi);
				Vswap(unLo, hi-m+1, m);
				
				n = lo + unLo - ltLo - 1;
				m = hi - (gtHi - unHi) + 1;
				
				stack[sp].ll = lo;
				stack[sp].hh = n;
				stack[sp].dd = d;
				sp++;
				
				stack[sp].ll = n + 1;
				stack[sp].hh = m - 1;
				stack[sp].dd = d+1;
				sp++;
				
				stack[sp].ll = m;
				stack[sp].hh = hi;
				stack[sp].dd = d;
				sp++;
			}
		}
コード例 #59
0
 public Stack()
 {
     top = null;
 }
コード例 #60
0
            public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
            {
                var ctx = stack.QueryAttribute<AsyncMethodDecompiler>();
                if (ctx == null)
                    throw new InvalidOperationException("Method must be decompiled using AsyncMethodDecompiler.");
                if (ctx.ImplStyle != EAsyncImplStyle.FSM)
                    throw new InvalidOperationException("Awaiting other tasks is only possible when decompiling to FSM.");

                ctx.ImplementAwait(decompilee, callee, args, stack, builder);

                return true;
            }