コード例 #1
0
 public void Visit(ReadNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
コード例 #2
0
ファイル: DOTPrinterVisitor.cs プロジェクト: sebdesl/COMP442
 public void Visit(ReadNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
コード例 #3
0
        public void Visit(ReadNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
コード例 #4
0
        public void Visit(ReadNode n)
        {
            var table    = (FunctionSymbolTableEntry)n.SymTable;
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child._ReturnRawAddress = true;
                child.Accept(this);
            }

            var valueVarVar    = children[0].TemporaryVariableName;
            var valueVarOffset = table.MemoryLayout.GetOffset(valueVarVar);

            // NOTE(AFL): Code adapted from the util.m file. Maybe make it into a function.
            var getint1   = $"getint1_{_readLabelCounter}";
            var getint2   = $"getint2_{_readLabelCounter}";
            var getint3   = $"getint3_{_readLabelCounter}";
            var getint4   = $"getint4_{_readLabelCounter}";
            var getint5   = $"getint5_{_readLabelCounter}";
            var getint6   = $"getint6_{_readLabelCounter}";
            var getint9   = $"getint9_{_readLabelCounter}";
            var getintEnd = $"getint_end_{_readLabelCounter}";

            ++_readLabelCounter;

            _writer.WriteComment("Read Op");

            var r0 = Registers.R0;
            var r1 = PopRegister();
            var r2 = PopRegister();
            var r3 = PopRegister();
            var r4 = PopRegister();

            // getint
            _writer.WriteTag(getint1);
            _writer.WriteInstruction(Instructions.Getc, r1);
            _writer.WriteInstruction(Instructions.Ceqi, r3, r1, "43");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint1);
            _writer.WriteInstruction(Instructions.Ceqi, r3, r1, "45");
            _writer.WriteInstruction(Instructions.Bz, r3, getint2);
            _writer.WriteInstruction(Instructions.Addi, r4, r0, "1");
            _writer.WriteInstruction(Instructions.J, getint1);
            _writer.WriteTag(getint2);
            _writer.WriteInstruction(Instructions.Clti, r3, r1, "48");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint3);
            _writer.WriteInstruction(Instructions.Cgti, r3, r1, "57");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint3);
            _writer.WriteInstruction(Instructions.Sb, $"{getint9}({r2})", r1);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.J, getint1);
            _writer.WriteTag(getint3);
            _writer.WriteInstruction(Instructions.Sb, $"{getint9}({r2})", r0);
            _writer.WriteInstruction(Instructions.Add, r1, r0, r0);
            _writer.WriteInstruction(Instructions.Add, r2, r0, r0);
            _writer.WriteInstruction(Instructions.Add, r3, r0, r0);
            _writer.WriteTag(getint4);
            _writer.WriteInstruction(Instructions.Lb, r3, $"{getint9}({r2})");
            _writer.WriteInstruction(Instructions.Bz, r3, getint5);
            _writer.WriteInstruction(Instructions.Subi, r3, r3, "48");
            _writer.WriteInstruction(Instructions.Muli, r1, r1, "10");
            _writer.WriteInstruction(Instructions.Add, r1, r1, r3);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.J, getint4);
            _writer.WriteTag(getint5);
            _writer.WriteInstruction(Instructions.Bz, r4, getint6);
            _writer.WriteInstruction(Instructions.Sub, r1, r0, r1);
            _writer.WriteTag(getint6);
            _writer.WriteInstruction(Instructions.J, getintEnd);
            _writer.WriteTag(getint9);
            _writer.WriteInstruction(Instructions.Res, "12");
            _writer.WriteInstruction(Instructions.Align);
            _writer.WriteTag(getintEnd);

            // Store value we got
            var addrReg = PopRegister();

            _writer.WriteInstruction(Instructions.Lw, addrReg, $"{valueVarOffset}({FSPReg})");
            _writer.WriteInstruction(Instructions.Sw, $"0({addrReg})", r1);

            PushRegister(addrReg);


            PushRegister(r4);
            PushRegister(r3);
            PushRegister(r2);
            PushRegister(r1);
        }