* Copyright (c) 1980 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)var.c 5.5 (Berkeley) 4/16/91";
* Declare variables of a var part. DPOFF1 is
* the local variable storage for all prog/proc/func
* modules aside from the block mark. The total size
* of all the local variables is entered into the
static bool var_order
= FALSE
;
static bool var_seen
= FALSE
;
/* this allows for multiple declaration
* parts except when the "standard"
* option has been specified.
* If routine segment is being compiled,
* do level one processing.
if ( parts
[ cbn
] & RPRT
) {
error("Variable declarations should precede routine declarations");
error("Variable declarations should precede routine declarations");
if ( parts
[ cbn
] & VPRT
) {
error("All variables should be declared in one var part");
error("All variables should be declared in one var part");
* sizes[cbn].om_max = sizes[cbn].curtmps.om_off = -DPOFF1;
struct tnode
*vidl
, *vtype
;
register struct tnode
*vl
;
for (vl
= vidl
; vl
!= TR_NIL
; vl
= vl
->list_node
.next
) {
send(REVVAR
, vline
, vidl
, vtype
);
register struct tnode
*vidl
;
for (; vidl
!= TR_NIL
; vidl
= vidl
->list_node
.next
) {
roundup((int)(op
->curtmps
.om_off
-w
), (long)align(np
));
o2
= op
-> curtmps
.om_off
;
* global variables are not accessed off the fp
* but rather by their names.
* locals are aligned, too.
roundup((int)(op
->curtmps
.om_off
- w
),
o2
= op
-> curtmps
.om_off
;
vp
= enter(defnl((char *) vidl
->list_node
.list
, VAR
, np
, o2
));
(void) enter(defnl((char *) vidl
->list_node
.list
, VAR
, np
, o2
));
if ( np
!= NLNIL
&& (np
-> nl_flags
& NFILES
) ) {
putprintf( " .data" , 0 );
putprintf( " .comm " , 1 );
putprintf( EXTFORMAT
, 1 , (int) vidl
->list_node
.list
);
putprintf( ",%d" , 0 , (int) w
);
putprintf( " .text" , 0 );
stabgvar( vp
, w
, line
);
vp
-> extra_flags
|= NGLOBAL
;
vp
-> extra_flags
|= NLOCAL
;
pPointer Var
= VarDecl( ovidl
, vtype
);
pSeize( PorFHeader
[ nesting
] );
Vars
= &( pDEF( PorFHeader
[ nesting
] ).PorFVars
);
*Vars
= ListAppend( *Vars
, Var
);
pRelease( PorFHeader
[ nesting
] );
sizes
[cbn
].om_max
= sizes
[cbn
].curtmps
.om_off
;
* Find the width of a type in bytes.
return ( sizeof ( int * ) );
return ( sizeof(struct iorec
) + lwidth( p
-> type
) );
if (p
->type
== nl
+TDOUBLE
)
return (bytes(p
->range
[0], p
->range
[1]));
* Sets are some multiple of longs
return roundup((int)((set
.uprbp
>> 3) + 1),
return ( p
->value
[NL_OFFS
] );
* round up x to a multiple of y
* for computing offsets of aligned things.
* y had better be positive.
* rounding is in the direction of x.
return ( ( ( x
+ ( y
- 1 ) ) / y
) * y
);
return ( ( ( x
- ( y
- 1 ) ) / y
) * y
);
* alignment of an object using the c alignment scheme
* arrays are structures, since they can get
* assigned form/to as structure assignments.
* preserve internal alignment if it is greater.
elementalign
= align(p
-> type
);
return elementalign
> A_STRUCT
? elementalign
: A_STRUCT
;
if ( p
-> type
== nl
+TDOUBLE
) {
switch ( bytes( p
-> range
[0] , p
-> range
[1] ) ) {
* arrays of chars are structs
* the alignment of a record is in its align_info field
* why don't we use this for the rest of the namelist?
* output an alignment pseudo-op.
#if defined(vax) || defined(tahoe)
putprintf(" .align 1", 0);
putprintf(" .align 2", 0);
* Return the width of an element
* of a n time subscripted np.
* If it is a conformant array, we cannot find the width from
if (p
->chain
->class == CRANGE
)
* Arrays of anything but characters are word aligned.
* Skip the first n subscripts
* Sum across remaining subscripts.
if (p
->class != RANGE
&& p
->class != SCAL
)
d
= p
->range
[1] - p
->range
[0] + 1;
* Find the lower bound of a set, and also its size in bits.
if (p
->class != RANGE
&& p
->class != SCAL
)
/* set.(upperbound prime) = number of bits - 1; */
* Return the number of bytes required to hold an arithmetic quantity
if (lb
< -32768 || ub
> 32767)
else if (lb
< -128 || ub
> 127)
if (!hp21mx
&& (lb
< -32768 || ub
> 32767))
if (lb
< -128 || ub
> 127)