/*
 * Copyright (c) 1996 by Satish Chandra, Brad Richards, Mark D. Hill, 
 * James R. Larus, and David A. Wood.
 *
 * Teapot is distributed under the following conditions:
 * 
 *     You may make copies of Teapot for your own use and modify those copies.
 * 
 *     All copies of Teapot must retain our names and copyright notice.
 * 
 *     You may not sell Teapot or distributed Teapot in conjunction with a
 *     commercial product or service without the expressed written consent of
 *     the copyright holders.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

Procedure AccChg(id:ID; tag_chg: TAG_CHG);
Begin
    Alias me: Nodes[cur_node] Do
      Switch tag_chg
	Case TPPI_Blk_Invalidate:
	    Assert (me.AccCtrl[id] != Blk_Invalid) "invalidating already inv";
	    me.AccCtrl[id] := Blk_Invalid;
	Case TPPI_Blk_Validate_RO:
    	    Assert (me.AccCtrl[id] = Blk_Invalid) "validating RO non invalid";
    	    me.AccCtrl[id] := Blk_ReadOnly;
	Case TPPI_Blk_Validate_RW:
	    me.AccCtrl[id] := Blk_Writable;
	Case TPPI_Blk_Downgrade_RO:
	    Assert (me.AccCtrl[id] = Blk_Writable) "downgrading non wr";
	    me.AccCtrl[id] := Blk_ReadOnly;
	Case TPPI_Blk_Upgrade_RW:
	    Assert (me.AccCtrl[id] = Blk_ReadOnly) "upgrading non RO";
	    me.AccCtrl[id] := Blk_Writable;
	Case TPPI_Blk_No_Tag_Change:
      End;
    End;
End;

Procedure Send(dest: NODE; msg: MSG; id: ID);
Begin
	NW_Send(dest, msg, id, cur_node);
End;

Procedure SendWithBits(dest: NODE; msg: MSG; id: ID; Var info: INFO);
Begin
	NW_Send_w_Bits(dest, msg, id, cur_node, info);
End;


Procedure SendData(dest:NODE; msg:MSG; id:ID; post_tag_chg:TAG_CHG; Var info:INFO);
Begin
	Alias me: Nodes[cur_node] Do
		NW_SendData(dest, msg, id, cur_node, me.Dram[id].Data, info);
		AccChg(id, post_tag_chg);
	End
End;


Procedure RecvData(id: ID; pre_tag_chg: TAG_CHG; post_tag_chg: TAG_CHG);
Begin
	AccChg(id, pre_tag_chg);
	Alias me : Nodes[cur_node] Do
		NW_RecvData(id, cur_msg, cur_node);
		Undefine cur_msg;
	End;
	AccChg(id, post_tag_chg);
End;
