Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / legion / src / generic / include / list.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: list.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23#ifndef _LIST_H_
24#define _LIST_H_
25
26 /*
27 * Linear list manipulation stuff
28 * primarily used for the parser
29 */
30
31#define LINEAR_LIST_INIT( _list, _type ) do { \
32 (_list).count = 0; \
33 (_list).listbasep = (_type*)0; \
34 } while (0)
35
36#define LINEAR_LIST_ADD( _list, _type ) ( \
37 (_list).count ++, \
38 (_list).listbasep = Xrealloc( (_list).listbasep,\
39 (_list).count * sizeof( _type ) ), \
40 &((_list).listbasep[ (_list).count - 1 ]) \
41 )
42
43#define LINEAR_LIST_ENTRY( _list, _idx ) ( \
44 &((_list).listbasep[ (_idx) ]) \
45 )
46
47#define LINEAR_LIST_DEF( _listname, _type ) \
48 struct { \
49 int count; \
50 _type * listbasep; \
51 } _listname
52
53
54
55 /*
56 * More complicated ..
57 * .. a dynamically allocated linear list of pointers to objects
58 */
59
60#define LIST_INIT( _list, _type ) \
61 LINEAR_LIST_INIT( _list, _type * )
62
63#define LIST_ADD( _list, _type ) ( \
64 *LINEAR_LIST_ADD( _list, _type * ) = (_type*)Xcalloc(1, _type) \
65 )
66
67#define LIST_ADD_PTR( _list, _type, _ptr ) ( \
68 *LINEAR_LIST_ADD( _list, _type * ) = (_type*)(_ptr) \
69 )
70
71#define LIST_ENTRY( _list, _idx ) ( \
72 *LINEAR_LIST_ENTRY( _list, _idx ) \
73 )
74
75#define LIST_DEF( _listname, _type ) \
76 LINEAR_LIST_DEF( _listname, _type *)
77
78
79#endif /* #ifndef _LIST_H_ */