public void Visit(MultOpNode n) { var children = n.GetChildren(); foreach (var node in n.GetChildren()) { node.SymTable = n.SymTable; node.Accept(this); } if (!string.Equals(children[0].ExprType.Type, TypeConstants.IntType) && !string.Equals(children[1].ExprType.Type, TypeConstants.IntType) && !string.Equals(children[0].ExprType.Type, TypeConstants.FloatType) && !string.Equals(children[1].ExprType.Type, TypeConstants.FloatType)) { _errorStream.WriteLine($"Operation must be done with numerical operands! ({n.Token.StartLine}:{n.Token.StartColumn})"); Console.WriteLine($"Error: Operation must be done with numerical operands! ({n.Token.StartLine}:{n.Token.StartColumn})"); } if (children[0].ExprType.Dims.Count > 0 || children[1].ExprType.Dims.Count > 0) { _errorStream.WriteLine($"Cannot multiply/divide arrays! ({n.Token.StartLine}:{n.Token.StartColumn})"); Console.WriteLine($"Error: Cannot multiply/divide arrays! ({n.Token.StartLine}:{n.Token.StartColumn})"); } else if (!string.Equals(children[0].ExprType.Type, children[1].ExprType.Type)) { _errorStream.WriteLine($"Operand types don't match! {children[1].ExprType.Type} <-> {children[0].ExprType.Type} ({n.Token.StartLine}:{n.Token.StartColumn})"); Console.WriteLine($"Error: Operand types don't match! {children[1].ExprType.Type} <-> {children[0].ExprType.Type} ({n.Token.StartLine}:{n.Token.StartColumn})"); } n.ExprType = children[0].ExprType; }
public void Visit(MultOpNode n) { PrintDOTIDLabel(n, n.Op.ToString()); PrintDOTParentChild(n); foreach (var child in n.GetChildren()) { child.Accept(this); } }
public void Visit(MultOpNode n) { var children = n.GetChildren(); foreach (var child in children) { child.SymTable = n.SymTable; child.Accept(this); } }
public void Visit(MultOpNode n) { var table = (FunctionSymbolTableEntry)n.SymTable; n.TemporaryVariableName = table.MemoryLayout.AddTemporaryVariable(); var children = n.GetChildren(); foreach (var child in children) { child.Accept(this); } }
public void Visit(MultOpNode n) { var children = n.GetChildren(); var table = (FunctionSymbolTableEntry)n.SymTable; var resultOffset = table.MemoryLayout.GetOffset(n.TemporaryVariableName); var operandVarOffsets = new List <int>(); foreach (var child in children) { child.Accept(this); var offset = table.MemoryLayout.GetOffset(child.TemporaryVariableName); operandVarOffsets.Add(offset); } Instructions instruction; switch (n.Op) { case MultOp.Multiply: instruction = Instructions.Mul; break; case MultOp.Divide: instruction = Instructions.Div; break; case MultOp.And: instruction = Instructions.And; break; default: throw new InvalidOperationException("Unknown op"); } _writer.WriteComment($"MultOp ({n.Op}) at ({n.Token.StartLine} : {n.Token.StartColumn})"); var destReg = PopRegister(); var op1Reg = PopRegister(); var op2Reg = PopRegister(); _writer.WriteInstruction(Instructions.Lw, op1Reg, $"{operandVarOffsets[0]}({FSPReg})"); _writer.WriteInstruction(Instructions.Lw, op2Reg, $"{operandVarOffsets[1]}({FSPReg})"); _writer.WriteInstruction(instruction, destReg, op2Reg, op1Reg); _writer.WriteInstruction(Instructions.Sw, $"{resultOffset}({FSPReg})", destReg); PushRegister(op2Reg); PushRegister(op1Reg); PushRegister(destReg); }