Ejemplo n.º 1
0
 public long ActualMemoryDistanceFrom(Placeholder other)
 {
     //these requires might be wrong for some specific cases
     Require.True(region.MemoryLocation != 0);
     Require.True(other.region.MemoryLocation != 0);
     return((region.MemoryLocation + offset) - (other.region.MemoryLocation + other.offset));
 }
Ejemplo n.º 2
0
 public void AddVariable(Identifier name, TypeReference type, int slot, bool readOnly)
 {
     if (name.Data == "this")
     {
         Require.True(readOnly);
     }
     contexts.Peek().AddVariable(name, type, slot, readOnly);
 }
Ejemplo n.º 3
0
 public void Align(int alignment, byte fill)
 {
     Require.True(alignment >= 1);
     Require.True(alignment <= 16);
     while ((stream.Position % alignment) != 0)
     {
         WriteByte(fill);
     }
 }
Ejemplo n.º 4
0
 public void RevertLookahead()
 {
     Require.True(lookaheadEnabled);
     lookaheadEnabled = false;
     while (lookahead.Count > 0)
     {
         buffer.Insert(0, lookahead.Pop());
     }
 }
Ejemplo n.º 5
0
        public void EnterDefinitionContext(Definition definition)
        {
            Require.True(contexts.Count == 0);
            Require.Unassigned(currentDefinition);
            currentDefinition = definition;
            Context context = CreateContext();

            context.Setup(null, false);
            contexts.Push(context);
        }
Ejemplo n.º 6
0
 public void CheckEmpty()
 {
     foreach (Field field in fieldWritten.Keys)
     {
         Require.True(field.GetModifiers.Static);
     }
     Require.True(variables.Count == 0);
     Require.True(varBySlot.Count == 0);
     Require.True(variableIncomplete.Count == 0);
     Require.True(variableWrite.Count == 0);
     Require.True(variableRead.Count == 0);
 }
Ejemplo n.º 7
0
        public void SetValue(int data)
        {
            Require.True(data <= short.MaxValue);
            Require.True(data >= short.MinValue);
            long pos = stream.Position;

            stream.Position = position;
            unchecked
            {
                stream.WriteByte((byte)((data >> 0) & 0xff));
                stream.WriteByte((byte)((data >> 8) & 0xff));
            }
            stream.Position = pos;
        }
Ejemplo n.º 8
0
 private void FillBuf()
 {
     if (length == -1)
     {
         return;               // eof
     }
     Require.True(length - offset == 0);
     length = reader.Read(rbuffer, 0, rbuffer.Length);
     if (length == 0)
     {
         length = -1;
     }
     offset = 0;
 }
Ejemplo n.º 9
0
 public string FirstFromSet(Set <string> filenames)
 {
     Require.True(filenames.Count > 0);
     while (true)
     {
         lock (responses_lock) {
             foreach (var file in responses.Keys)
             {
                 if (filenames.Contains(file))
                 {
                     return(file);
                 }
             }
         }
         newResponse.WaitOne();
     }
 }
Ejemplo n.º 10
0
        public static byte[] GetBytes(string hex)
        {
            if (hex == null)
            {
                throw new ArgumentNullException("hex");
            }
            Require.True((hex.Length & 1) == 0);
            byte[] result = new byte[hex.Length / 2];

            for (int i = 0; i < result.Length; ++i)
            {
                byte c = byte.Parse(hex.Substring(i * 2, 1), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                byte d = byte.Parse(hex.Substring(i * 2 + 1, 1), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                result[i] = (byte)((c << 4) + d);
            }
            return(result);
        }
Ejemplo n.º 11
0
 public void WriteULEB(long data)
 {
     Require.True(data >= 0);
     while (true)
     {
         byte x = (byte)(data & 0x7f);
         data = data >> 7;
         if (data != 0)
         {
             x |= 0x80;
         }
         WriteByte(x);
         if (data == 0)
         {
             break;
         }
     }
 }
Ejemplo n.º 12
0
 public void SetImplicitFields(int slot, TypeReference type)
 {
     Require.True(type.IsDefinition || type.IsStatic);
     contexts.Peek().SetImplicitFields(slot, type);
 }
Ejemplo n.º 13
0
        public Expression Reduce()
        {
            int level = 0;
            while (list.Count > 1)
            {
                Require.True(level <= precedence.highestLevel);
                // needs to be a for loop, the list gets modified in action
                //forward
                Opera_nd_tor item;
                for (int j = 0; j < 2; ++j)
                {
                    bool leftToRight = j == 0;
                    int i;
                    if (leftToRight)
                        i = -1;
                    else
                        i = list.Count;                        
                    while (true)
                    {
                        if (leftToRight)
                        {
                            i++;
                            if (i == list.Count)
                                break;
                        }
                        else
                        {
                            if (i == 0)
                                break;
                            i--;
                        }
                        item = list[i];
                        if (item.IsOperator && (item.Precedence == level) && (item.LeftToRight == leftToRight))
                        {
                            switch (item.Kind)
                            {
                                case OperatorKind.Infix:
                                    {
                                        i = i - 1;
                                        Expression left = list[i].Expression;
                                        Expression right = list[i + 2].Expression;
                                        list.RemoveRange(i, 3);
                                        list.Insert(i, item.ReduceInfix(left, right));
                                        break;
                                    }
                                case OperatorKind.Prefix:
                                    {
                                        Expression right = list[i + 1].Expression;
                                        list.RemoveRange(i, 2);
                                        list.Insert(i, item.ReducePrefix(right));
                                        break;
                                    }
                                case OperatorKind.Postfix:
                                    {
                                        i = i - 1;
                                        Expression left = list[i].Expression;
                                        list.RemoveRange(i, 2);
                                        list.Insert(i, item.ReducePostFix(left));
                                        break;
                                    }
                                default:
                                    {
                                        Require.NotCalled();
                                        break;
                                    }
                            }
                        }
                    }
                }

                level++;
            }
            Expression result = list[0].Expression;
            list.Clear();
            return result;
        }
Ejemplo n.º 14
0
 public long MemoryDistanceFrom(Placeholder other)
 {
     Require.True(region == other.region);
     return(offset - other.offset);
 }