Exemple #1
0
 private void HPopTop()
 {
     StackOp.Push(new PHullOp(eOp.Top, Elt[this.Top]));
     //HElt[++Hp] = Elt[Top];
     //Op[Hp] = eStackOp.Top;
     Elt[Top] = -1;
     Top--;
 }
Exemple #2
0
 private void HPopBot()
 {
     StackOp.Push(new PHullOp(eOp.Bot, Elt[this.Bot]));
     //HElt[++Hp] = Elt[Bot];
     //Op[Hp] = eStackOp.Bot;
     Elt[Bot] = -1;
     Bot++;
 }
Exemple #3
0
 private void HPush(int ie)
 {
     Elt[++Top] = ie;
     Elt[--Bot] = ie;
     StackOp.Push(new PHullOp(eOp.Push, ie));
     //HElt[++Hp] = ie;
     //Op[Hp] = eStackOp.Push;
 }
Exemple #4
0
 private void HInit(int ib, int ie)
 {
     Elt[HMax] = ib;
     Top       = HMax + 1;
     Elt[Top]  = ie;
     Bot       = HMax - 1;
     Elt[Bot]  = ie;
     //Hp = 0;
     //HElt[Hp] = ie;
     //Op[Hp] = eStackOp.Push;
     StackOp.Push(new PHullOp(eOp.Push, ie));
 }
Exemple #5
0
 public override void MakeByteCode(StackOp op, ArrayList bytecodeList)
 {
     SymbolInfo si = SymbolTable.LookupExisting(Token);
     if (si is LocalSymbolInfo)
     {
         LocalSymbolInfo lsi = si as LocalSymbolInfo;
         specifiedSize = specifiedSize != 0 ? specifiedSize : 4;
         MakeStackOp(op, specifiedSize, MemorySpace.LOCAL, lsi.Offset, SubscriptExprs(indexExprs, new Expr[0]), bytecodeList);
     }
     else if (si is VarSymbolInfo)
     {
         VarSymbolInfo vsi = si as VarSymbolInfo;
         specifiedSize = specifiedSize != 0 ? specifiedSize : vsi.Size;
         MakeStackOp(op, specifiedSize, MemorySpace.VAR, vsi.Offset, SubscriptExprs(indexExprs, vsi.DimExprs), bytecodeList);
     }
     else if (si is DatSymbolInfo)
     {
         DatSymbolInfo dsi = si as DatSymbolInfo;
         specifiedSize = specifiedSize != 0 ? specifiedSize : dsi.Alignment;
         MakeStackOp(op, specifiedSize, MemorySpace.OBJ, dsi.Dp, SubscriptExprs(indexExprs, new Expr[0]), bytecodeList);
     }
     else
         throw new ParseException("wtf? " + si, this.Token); ; ;
 }
Exemple #6
0
 public override void MakeByteCode(StackOp op, ArrayList bytecodeList)
 {
     MakeStackOp(op, size, indexExpr1, indexExpr2, bytecodeList);
 }
Exemple #7
0
 public override void MakeByteCode(StackOp op, ArrayList bytecodeList)
 {
     SymbolInfo si = SymbolTable.LookupExisting(Token);
     if (si is ConSymbolInfo)
     {
         if (op != StackOp.PUSH)
             throw new ParseException("Internal error: IdExpr.MakeByteCode(non-PUSH)", this.Token);
         ConSymbolInfo csi = si as ConSymbolInfo;
         MakePushInt(csi.Value.AsIntBits(), bytecodeList);
         return;
     }
     if (si is LocalSymbolInfo)
     {
         LocalSymbolInfo lsi = si as LocalSymbolInfo;
         MakeStackOp(op, 4, MemorySpace.LOCAL, lsi.Offset, null, bytecodeList);
         size = 4;
     }
     else if (si is VarSymbolInfo)
     {
         VarSymbolInfo vsi = si as VarSymbolInfo;
         MakeStackOp(op, vsi.Size, MemorySpace.VAR, vsi.Offset, null, bytecodeList);
         size = vsi.Size;
     }
     else if (si is DatSymbolInfo)
     {
         DatSymbolInfo dsi = si as DatSymbolInfo;
         MakeStackOp(op, dsi.Alignment, MemorySpace.OBJ, dsi.Dp, null, bytecodeList);
         size = dsi.Alignment;
     }
     else if (si is ObjSymbolInfo)
     {
         ObjSymbolInfo osi = si as ObjSymbolInfo;
         if (op != StackOp.POP)
             throw new ParseException("IdExpr.MakeByteCode(non-PUSH) ObjSymbolInfo", Token);
         // The TOS is two words: absolute address of an OBJ and absolute address of its VAR space.
         // We're going to subtract the current OBJ's address from the LSW
         // and the current OBJ's VAR (lshifted 16) from the MSW, then store it in the current
         // object table.
         MakePushInt(this.SymbolTable.HubAddress, bytecodeList);
         bytecodeList.Add((byte)0xed);		// SUB
         bytecodeList.Add((byte)0x43);		// PUSH# VAR+0
         bytecodeList.Add((byte)0x37);		// PUSH#kp
         bytecodeList.Add((byte)0x03);		//         16
         bytecodeList.Add((byte)0xe3);		// SHL
         bytecodeList.Add((byte)0xed);		// SUB
         MakeStackOp(StackOp.POP, 4, MemorySpace.OBJ, osi.Index << 2, null, bytecodeList);
     }
     else
         throw new ParseException("Unexpected " + si.ToString(), this.Token);	// should never happen.
 }
Exemple #8
0
        protected void MakeStackOp(StackOp op, int size, MemorySpace space, int offset, Expr indexExpr, ArrayList bytecodeList)
        {
            // Not for MemorySpace.MEM ops.

            if (indexExpr != null)
            {
                indexExpr.MakeByteCode(true, bytecodeList);
            }

            int opcode;
            if (offset < 32
                && size == 4
                && (space == MemorySpace.VAR || space == MemorySpace.LOCAL)
                && indexExpr == null)
            {	// Use the short form if possible
                if ((offset & 3) != 0)
                    throw new ParseException("Non-long offset", Token);

                opcode = space == MemorySpace.VAR ? 0x40 : 0x60;	// VAR / LOCAL
                opcode |= (byte)op;

                bytecodeList.Add((byte)(opcode + offset));
            }
            else	// we have to use the long form
            {
                opcode = 0x80 | ((size >> 1) << 5) | ((int)space << 2) | (int)op;
                if (indexExpr != null)
                {
                    opcode |= 0x10;
                }

                if (offset < 128)
                {
                    bytecodeList.Add((byte)opcode);
                    bytecodeList.Add((byte)offset);
                }
                else
                {
                    bytecodeList.Add((byte)opcode);
                    bytecodeList.Add((byte)(offset >> 8 | 0x80));
                    bytecodeList.Add((byte)offset);
                }
            }
        }
Exemple #9
0
        protected static void MakeStackOp(StackOp op, int size, Expr indexExpr1, Expr indexExpr2, ArrayList bytecodeList)
        {
            // Only for MemorySpace.MEM ops.
            // indexExpr1 should be non-null; indexExpr1 might be null.

            indexExpr1.MakeByteCode(true, bytecodeList);

            if (indexExpr2 != null)
            {
                indexExpr2.MakeByteCode(true, bytecodeList);
            }

            int opcode;
            opcode = 0x80 | ((size >> 1) << 5) | ((int)MemorySpace.MEM << 2) | (int)op;
            if (indexExpr2 != null)
            {
                opcode |= 0x10;
            }
            bytecodeList.Add((byte)opcode);
        }
Exemple #10
0
 public virtual void MakeByteCode(StackOp op, ArrayList bytecodeList)
 {
     throw new ParseException("MakeByteCode(StackOp) undefined", token);
 }