/* Copyright (c) 1979 Regents of the University of California */
static char sccsid
[] = "@(#)var.c 1.3 9/2/80";
* 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
/* 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");
if ( parts
[ cbn
] & VPRT
) {
error("All variables should be declared in one var part");
* sizes[cbn].om_max = sizes[cbn].om_off = -DPOFF1;
int vline
, *vidl
, *vtype
;
for (vl
= vidl
; vl
!= NIL
; vl
= vl
[2]) {
send(REVVAR
, vline
, vidl
, vtype
);
w
= (lwidth(np
) + 1) &~ 1;
for (; vidl
!= NIL
; vidl
= vidl
[2]) {
op
-> om_off
= roundup( op
-> om_off
- w
, align( np
) );
* global variables are not accessed off the fp
* but rather by their names.
* locals are aligned, too.
op
-> om_off
= roundup( op
-> om_off
- w
enter(defnl(vidl
[1], VAR
, np
, o2
));
if ( np
-> nl_flags
& NFILES
) {
putprintf( " .data" , 0 );
putprintf( " .comm " , 1 );
putprintf( EXTFORMAT
, 1 , vidl
[1] );
putprintf( ",%d" , 0 , w
);
putprintf( " .text" , 0 );
stabvar( vidl
[1] , p2type( np
) , cbn
, o2
, w
, line
);
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
].om_off
;
* Find the width of a type in bytes.
return ( sizeof ( int * ) );
return ( sizeof ( int * ) );
return ( sizeof(struct iorec
)
if (p
->type
== nl
+TDOUBLE
)
return (bytes(p
->range
[0], p
->range
[1]));
return roundup( ( set
.uprbp
>> 3 ) + 1 , A_SET
);
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 aligned as their component types
if ( p
-> type
== nl
+TDOUBLE
) {
switch ( bytes( p
-> range
[0] , p
-> range
[1] ) ) {
* follow chain through all fields in record,
* taking max of alignments of types of fields.
* short circuit out if i reach the maximum alignment.
* this is pretty likely, as A_MAX is only 4.
register long fieldalign
;
while ( ( p
!= NIL
) && ( recalign
< A_MAX
) ) {
fieldalign
= align( p
-> type
);
if ( fieldalign
> recalign
) {
* Return the width of an element
* of a n time subscripted np.
* 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)