// TODO(AFL): Redo this such that r13 contains absolute address of result. // IDEA: put result in tempvar, pass on absolute address to it public void Visit(ReturnNode n) { var table = (FunctionSymbolTableEntry)n.SymTable; var children = n.GetChildren(); foreach (var child in children) { child.Accept(this); } var valueVar = children[0].TemporaryVariableName; var valueOffset = table.MemoryLayout.GetOffset(valueVar); var r13 = Registers.R13; var r15 = Registers.R15; // Set return value register to absolute address of return value _writer.WriteInstruction(Instructions.Sub, r13, r13, r13); _writer.WriteInstruction(Instructions.Add, r13, r13, FSPReg); _writer.WriteInstruction(Instructions.Addi, r13, r13, $"{valueOffset}"); // Jump to return address _writer.WriteInstruction(Instructions.Lw, r15, $"-4({FSPReg})"); _writer.WriteInstruction(Instructions.Jr, r15); }
public void Visit(ReturnNode n) { var children = n.GetChildren(); foreach (var child in children) { child.Accept(this); } }
public void Visit(ReturnNode n) { PrintDOTIDLabel(n); PrintDOTParentChild(n); foreach (var child in n.GetChildren()) { child.Accept(this); } }
public void Visit(ReturnNode n) { var children = n.GetChildren(); foreach (var node in children) { node.SymTable = n.SymTable; node.Accept(this); } var table = (FunctionSymbolTableEntry)n.SymTable; if (!string.Equals(children.Last().ExprType.Type, table.ReturnType?.Lexeme ?? "") && !(children.Last().ExprType.Type == null && string.Equals(table.ReturnType?.Lexeme ?? "", "void"))) { _errorStream.WriteLine($"Type of value for return is invalid (line: {n.Token.StartLine}), expected: {table.ReturnType?.Lexeme ?? "void"}, received: {children.Last().ExprType.Type}"); Console.WriteLine($"Error: Type of value for return is invalid (line: {n.Token.StartLine}), expected: {table.ReturnType?.Lexeme ?? "void"}, received: {children.Last().ExprType.Type}"); } }