Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / os / bootprom / breadth.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: breadth.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)breadth.fth 2.5 02/05/02
43purpose:
44copyright: Copyright 1990-2002 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ Tree searching code:
48\ This implements a funny-order search of an n-ary tree.
49\ First, all the child nodes at this level are searched.
50\ If not found, then the first child node is made the current node
51\ and the process is repeated recursively. If that fails, the second
52\ child node is selected, and so on.
53\ All the descendents of the first node will thus be searched before
54\ any of the descendents of the second node.
55\ This is not quite a breadth-first search.
56
57\ Interface to code in devtree.fth:
58\ first-child ( -- another? )
59\ If current-node has a first child, sets current-node to that
60\ child and returns true.
61\ next-child ( -- another? )
62\ If current-node has a next peer, sets current-node to that peer
63\ and returns true, else sets current-node to the parent of
64\ current-node and returns false.
65\
66\ This rather strange interface turns out to be extremely convenient
67\ to use in a loop over all children; e.g.
68\
69\ first-child begin while XXX next-child repeat
70\
71\ where XXX is the code to be executed for each child.
72
73headerless
74
75create found 0 c,
76create not-found ," Device not found"
77
78: (search-level) ( ? acf -- ? acf )
79 first-child begin while ( ? acf )
80
81 dup execute if found throw then ( ? acf )
82
83 next-child repeat ( ? acf )
84;
85
86: (search-preorder) ( ? acf -- ? acf ) recursive
87 (search-level)
88
89 first-child begin while (search-preorder) next-child repeat
90;
91
92: invert-signal ( ? acf -- ? acf )
93 catch case
94 0 of not-found throw endof
95 found of endof
96 ( default ) throw
97 endcase
98;
99: search-preorder ( ? acf -- ? acf ) ['] (search-preorder) invert-signal ;
100: search-level ( ? acf -- ? acf ) ['] (search-level) invert-signal ;
101headers