Exemplo n.º 1
0
        public void Visit(AssignmentNode n)
        {
            var children = n.GetChildren();
            var subCalls = children.SkipLast().ToList();
            var table    = (FunctionSymbolTableEntry)n.SymTable;

            _writer.WriteComment($"Assignment");

            var rhsNode = children.Last();

            rhsNode.Accept(this);

            var rhsVarName = rhsNode.TemporaryVariableName;
            var rhsOffset  = table.MemoryLayout.GetOffset(rhsVarName);

            WriteCallchainCode(subCalls, FSPReg); // r12 has absolute address of variable to write to.

            var finalValSize = Utils.GetTypeFullSize(_globalSymbolTable, subCalls.Last().ExprType);
            var srcReg       = Registers.R12;
            var dstReg       = PopRegister();
            var sizeReg      = PopRegister();

            _writer.WriteInstruction(Instructions.Addi, sizeReg, sizeReg, $"{finalValSize}");
            _writer.WriteInstruction(Instructions.Add, dstReg, dstReg, FSPReg);
            _writer.WriteInstruction(Instructions.Addi, dstReg, dstReg, $"{rhsOffset}");

            // src dst inverted, because bugs
            WriteMultiByteCopy(dstReg, srcReg, sizeReg);

            PushRegister(sizeReg);
            PushRegister(dstReg);
        }
Exemplo n.º 2
0
 public void Visit(AssignmentNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Exemplo n.º 3
0
        public void Visit(AssignmentNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.SymTable = n.SymTable;
                child.Accept(this);
            }
        }
        public void Visit(AssignmentNode n)
        {
            var table = (FunctionSymbolTableEntry)n.SymTable;

            n._CallchainAddressVarName = table.MemoryLayout.AddTemporaryVariable();

            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
Exemplo n.º 5
0
        public void Visit(AssignmentNode n)
        {
            var children = n.GetChildren();

            var rhs = children.Last();

            rhs.SymTable          = n.SymTable;
            rhs.SecondarySymTable = n.SymTable;
            rhs.Accept(this);
            var rhsType = rhs.ExprType;

            var first = children.First();

            first.SymTable          = n.SymTable;
            first.SecondarySymTable = n.SymTable;
            first.Accept(this);
            var currentScopeSpec = first.ScopeSpec;

            var line = ((IdentifierNode)first.LeftmostChildNode).Token.StartLine;

            for (int i = 1; i < children.Count - 1; ++i)
            {
                if (string.IsNullOrEmpty(currentScopeSpec))
                {
                    _errorStream.WriteLine($"Use of variable with no scopespec.");
                    Console.WriteLine($"Error: Use of variable with no scopespec.");
                    break;
                }

                var classTable = _globalTable.GetClassSymbolTableByName(currentScopeSpec);
                if (classTable == null)
                {
                    _errorStream.WriteLine($"ScopeSpec \"{currentScopeSpec}\" refers to a non existing class.");
                    Console.WriteLine($"Error: ScopeSpec \"{currentScopeSpec}\" refers to a non existing class.");
                    break;
                }

                children[i].SymTable          = classTable;
                children[i].SecondarySymTable = n.SymTable;
                children[i].Accept(this);
                currentScopeSpec = children[i].ScopeSpec;
            }

            var lhsType = children[children.Count - 2].ExprType;

            if (!string.Equals(lhsType.Type, rhsType.Type) || !rhsType.Dims.SequenceEqual(lhsType.Dims))
            {
                _errorStream.WriteLine($"Assignment type missmatch! {lhsType.Type} <-> {rhsType.Type} (line: {line})");
                Console.WriteLine($"Error: Assignment type missmatch! {lhsType.Type} <-> {rhsType.Type} (line: {line})");
            }
        }