#!/bin/rc CC=`{sed -n 's/^CC=//p' /$objtype/mkfile} # # produce a file to compile which has the necessary info in it # fn file{ echo 'typedef union Align Align; union Align { double dd; long ll; long long LL; void (*ff)(void); }; typedef struct Word Word; struct Word{ char ww; int :0; /* fills to a "word" */ }; typedef struct Struct Struct; struct Struct{ /* smallest struct */ char cc; }; typedef struct Sensitive Sensitive; struct Sensitive{ /* sensitive to bit field type? */ char cc[7]; /* if so, size > 8 */ int :2; }; typedef struct Packed Packed; struct Packed{ /* packs bit fields? */ char cc[7]; /* if not, size > 8 */ char :2; char :2; }; typedef struct Info Info; #define xx(type,name) \ Align a/**/name; /* maximally align */ \ char off/**/name; /* misalign minimanlly */ \ type name #define yy(type,name) \ type z/**/name[8]; /* aligns any type */ \ char name/**/sz struct Info{ xx(char,c); xx(short,s); xx(int,i); xx(long,l); xx(long long,v); xx(float,f); xx(double,d); xx(long double,D); xx(Struct,S); xx(char*,p); xx(Word*,w); yy(char,c); yy(short,s); yy(int,i); yy(long,l); yy(long long,v); yy(float,f); yy(double,d); yy(long double,D); yy(Struct,S); yy(char*,p); yy(Word*,w); };' } # # print out info about chars, words, and bit fields # echo ' typedef struct Word Word; struct Word{ char ww; int :0; /* fills to a "word" */ }; typedef struct Struct Struct; struct Struct{ /* smallest struct */ char cc; }; ' | $CC -o/dev/null -a | tr -d ';' | awk ' ' # # print out size and alignment info # file | $CC -o/dev/null -a | tr -d ';' | awk ' BEGIN { kind["c"] = "CHAR" kind["s"] = "SHORT" kind["i"] = "INT" kind["l"] = "LONG" kind["v"] = "VLONG" kind["f"] = "FLOAT" kind["d"] = "DOUBLE" kind["D"] = "LDOUBLE" kind["S"] = "STRUCT" kind["w"] = "WPTR" kind["p"] = "BPTR" lastoff = 0; } $1 == "sizeofWord" { print "DBI_IN_BYTE 8" printf "DBI_IN_WORD %d\n", 8 * $3 printf "DSZ_WORD %d\n", $3 pow = 128 for(i = 1; i < $3; i++) pow = pow * 256 printf "DLARGEST_INT %d\n", pow - 1 } $1 == "sizeofSensitive" { if($3 > 8) print "DF_SENSITIVE 1"; else print "DF_SENSITIVE 0"; } $1 == "sizeofPacked" { if($3 > 8) print "DF_OPTIMIZED 0" else print "DF_OPTIMIZED 1" } NR > 3{ off = NF - 1 k = kind[$NF] if (k != "") printf "DAL_%s %d\n", k, $off - lastoff else if ($NF ~ /^.sz$/){ k = kind[substr($NF, 1, 1)]; printf "DSZ_%s %d\n", k, ($off - lastoff) / 8 } lastoff = $2 }'