/* Copyright (c) 1979 Regents of the University of California */
static char sccsid
[] = "@(#)var.c 1.10 7/8/81";
* 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].curtmps.om_off = -DPOFF1;
int vline
, *vidl
, *vtype
;
for (vl
= vidl
; vl
!= NIL
; vl
= vl
[2]) {
send(REVVAR
, vline
, vidl
, vtype
);
for (; vidl
!= NIL
; vidl
= vidl
[2]) {
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(vidl
[1], VAR
, np
, o2
));
if ( np
-> nl_flags
& NFILES
) {
putprintf( " .data" , 0 );
putprintf( " .align %d" , 0 , dotalign(align(np
)));
putprintf( " .comm " , 1 );
putprintf( EXTFORMAT
, 1 , vidl
[1] );
putprintf( ",%d" , 0 , w
);
putprintf( " .text" , 0 );
stabgvar( vidl
[1] , p2type( np
) , o2
, 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
;
return ((w
+1) & 0xfffffffe);
* 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]));
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 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
) {
* given an alignment, return power of two for .align pseudo-op
* A_POINT, A_INT, A_FLOAT, A_DOUBLE,
* A_STACK, A_FILET, A_SET
* 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)