// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: XactorBinTree.vr
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
#include <vera_defines.vrh>
#include "XactorUtilities.vrh"
#include "XactorBasePacket.vrh"
#include "XactorBaseExpectDataStruct.vrh"
#include "XactorDefines.vri"
#include "XactorComponentsDefines.vri"
// This class declares and implements the node used by the binary tree data structure.
event RemoveEvents[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]; // Removed is an event flag that will be
// triggered when the node is removed
XactorBasePacket Item; // Xactor Packet
TreeNode Left; // Pointer to the left node
TreeNode Right; // Pointer to the right node
TreeNode Parent; // Pointer to the parent node
task new (XactorBasePacket i,
var event e[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
for(EventCnt = 0; EventCnt <= XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS - 1; EventCnt++) {
RemoveEvents[EventCnt] = e[EventCnt];
// This is the class that declares and implements the binary tree
class XactorBinTree extends XactorBaseExpectDataStruct {
// Head node of the binary tree
virtual protected task AssignEvent(var event Dest[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS],
var event Src[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
// Local method. Will search Key within the binary tree.
virtual protected function TreeNode WCTreeSearch(TreeNode x,
// Local method. Will search Key within the binary tree.
virtual protected function TreeNode TreeSearch(TreeNode x,
// Local method. Will search Key within the binary tree.
virtual protected function TreeNode RefTreeSearch(TreeNode x,
// Local method. Will return the left most node of the tree (the one
// with the minimum value)
virtual protected function TreeNode TreeMin(TreeNode x);
// Local method. Returns the successor to node x
virtual protected function TreeNode TreeSuccessor(TreeNode x);
// Public method. Inserts a new node with the specified values.
virtual task Insert (XactorBasePacket Item,
var event e[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
virtual protected task DeleteNode (var TreeNode z);
// Checks if there are duplicated packets after a node is deleted.
virtual protected task CheckDuplicatedExpects (XactorBasePacket Key,
// Public method. Deletes a node with the specified values and returns
// Success = 1 if the node was found and deleted and Success = 0 otherwise.
virtual task Delete (XactorBasePacket Key,
// Public method. Deletes a node with the specified values and returns
// Success = 1 if the node was found and deleted and Success = 0 otherwise.
virtual task RefDelete (XactorBasePacket Key,
// Checks for duplicated expects after a node is deleted
virtual protected task CheckWCDuplicatedExpects (XactorBasePacket Key,
// Using Wildcards, deletes first node that match Key
virtual task WildCardDelete1 (XactorBasePacket Key,
// Local method. Will do and inorder traversal of the binary tree
// and will return the number of nodes through Counter
virtual protected task InorderCount(TreeNode Node,
// Public method. Will return the number of nodes in the binary tree.
virtual function integer CountNodes();
// Local method. will do an inorder walk of the binary tree and will
// print every node. Each "compressed" expected value is decoded by
// a packet object. Once decoded, each field will be stored within the
// same packet and printed.
virtual protected task InorderPrint(TreeNode Node);
// Public method. Calls InorderPrint to print the nodes within the
virtual task PrintNodes();
// Public method. Returns 1 if Item is within the binary tree and
// 0 otherwise. Accepts "wildcards"
virtual function bit InStructure(XactorBasePacket Item);
// Public method. Returns 1 if the binary tree is empty and 0 otherwise.
virtual function bit Empty();
// Local method. Inorder walk of the binary tree. It triggers the event
virtual protected task InorderReset(TreeNode Node);
// Public method. Calls InorderReset and after that, it deletes the complete
task XactorBinTree::new () {
task XactorBinTree::AssignEvent(var event Dest[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS],
var event Src[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
for(EventCnt = 0; EventCnt <= XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS - 1; EventCnt++) {
Dest[EventCnt] = Src[EventCnt];
// Local method. Will search Key within the binary tree.
function TreeNode XactorBinTree::WCTreeSearch(TreeNode x,
if((x == null) || (x.Item.PktCompare("=?=", Key)))
if(x.Item.PktCompare(">", Key))
WCTreeSearch = WCTreeSearch(x.Left, Key);
WCTreeSearch = WCTreeSearch(x.Right, Key);
// Local method. Will search Key within the binary tree.
function TreeNode XactorBinTree::TreeSearch(TreeNode x,
if((x == null) || (x.Item.PktCompare("===", Key)))
if(x.Item.PktCompare(">", Key))
TreeSearch = TreeSearch(x.Left, Key);
TreeSearch = TreeSearch(x.Right, Key);
// Local method. Will search Key within the binary tree.
function TreeNode XactorBinTree::RefTreeSearch(TreeNode x,
if((x == null) || (x.Item === Key))
if(x.Item.PktCompare(">", Key))
RefTreeSearch = RefTreeSearch(x.Left, Key);
RefTreeSearch = RefTreeSearch(x.Right, Key);
// Local method. Will return the left most node of the tree (the one
// with the minimum value)
function TreeNode XactorBinTree::TreeMin(TreeNode x) {
// Local method. Returns the successor to node x
function TreeNode XactorBinTree::TreeSuccessor(TreeNode x) {
TreeSuccessor = TreeMin(x.Right);
while((y != null) && (x == y.Right)) {
// Public method. Inserts a new node with the specified values.
task XactorBinTree::Insert (XactorBasePacket Item,
var event e[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
if((x.Item.PktCompare("<", z.Item)) || (x.Item.PktCompare("=?=", z.Item))) {
if(x.Item.PktCompare("=?=", z.Item)) {
x.Item.PktDisplay(RTYP_XACTOR_FMWORK_DUP_EXPECT_ERR, "Posting a duplicated Expect");
if((y.Item.PktCompare("<", z.Item)) || (y.Item.PktCompare("=?=", z.Item)))
task XactorBinTree::DeleteNode (var TreeNode z) {
if((z.Left == null) || (z.Right == null))
AssignEvent(z.RemoveEvents, y.RemoveEvents);
// Checks if there are duplicated packets after a node is deleted.
task XactorBinTree::CheckDuplicatedExpects (XactorBasePacket Key,
z = TreeSearch(NodePtr, Key);
z.Item.PktDisplay(RTYP_XACTOR_FMWORK_SAMPLED_DUP_XACTION_ERR, "Sampled Transaction satisfies duplicated Expect");
CheckDuplicatedExpects (Key,
// Public method. Deletes a node with the specified values and returns
// Success = 1 if the node was found and deleted and Success = 0 otherwise.
task XactorBinTree::Delete (XactorBasePacket Key,
z = TreeSearch(Head, Key);
Key.SetID(z.Item.GetID());
CheckDuplicatedExpects(Key,
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_EVENT]); // Remove event
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_BY_XACTOR_EVENT]); // Removed by xactor
// Public method. Deletes a node with the specified values and returns
// Success = 1 if the node was found and deleted and Success = 0 otherwise.
task XactorBinTree::RefDelete (XactorBasePacket Key,
z = RefTreeSearch(Head, Key);
Key.SetID(z.Item.GetID());
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_EVENT]); // Remove event
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_BY_USER_EVENT]); // Removed by user
// Checks for duplicated expects after a node is deleted
task XactorBinTree::CheckWCDuplicatedExpects (XactorBasePacket Key,
z = WCTreeSearch(NodePtr, Key);
z.Item.PktDisplay(RTYP_XACTOR_FMWORK_SAMPLED_DUP_XACTION_ERR, "Sampled Transaction satisfies duplicated Expect");
CheckWCDuplicatedExpects (Key,
// Using Wildcards, deletes first node that match Key
task XactorBinTree::WildCardDelete1 (XactorBasePacket Key,
z = WCTreeSearch(Head, Key);
Key.SetID(z.Item.GetID());
z.Item.PktCopy(Key); // Copy contents of sampled packet to expected packet
CheckWCDuplicatedExpects(Key, z.Right);
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_EVENT]); // Remove event
trigger(ON, z.RemoveEvents[XACT_COMP_EXPECT_REMOVED_BY_XACTOR_EVENT]); // Removed by xactor
// Local method. Will do and inorder traversal of the binary tree
// and will return the number of nodes through Counter
task XactorBinTree::InorderCount(TreeNode Node,
InorderCount(Node.Left, Counter);
InorderCount(Node.Right, Counter);
// Public method. Will return the number of nodes in the binary tree.
function integer XactorBinTree::CountNodes() {
InorderCount(Head, Counter);
// Local method. will do an inorder walk of the binary tree and will
// print every node. Each "compressed" expected value is decoded by
// a packet object. Once decoded, each field will be stored within the
// same packet and printed.
task XactorBinTree::InorderPrint(TreeNode Node
Node.Item.PktDisplay(RTYP_INFO, "Dump Expect List");
InorderPrint(Node.Right);
// Public method. Calls InorderPrint to print the nodes within the
task XactorBinTree::PrintNodes() {
// Public method. Returns 1 if Item is within the binary tree and
// 0 otherwise. Accepts "wildcards"
function bit XactorBinTree::InStructure (XactorBasePacket Item
x = TreeSearch(Head, Item);
// Public method. Returns 1 if the binary tree is empty and 0 otherwise.
function bit XactorBinTree::Empty() {
// Local method. Inorder walk of the binary tree. It triggers the event
task XactorBinTree::InorderReset(TreeNode Node
trigger(ON, Node.RemoveEvents[XACT_COMP_EXPECT_REMOVED_EVENT]); // Trigger remove event
trigger(ON, Node.RemoveEvents[XACT_COMP_EXPECT_REMOVED_BY_USER_EVENT]); // Trigger removed
InorderReset(Node.Right);
// Public method. Calls InorderReset and after that, it deletes the complete
task XactorBinTree::Reset() {