1da2e3ebdSchin######################################################################## 2da2e3ebdSchin# # 3da2e3ebdSchin# This software is part of the ast package # 4*b30d1939SAndy Fiddaman# Copyright (c) 1982-2012 AT&T Intellectual Property # 5da2e3ebdSchin# and is licensed under the # 6*b30d1939SAndy Fiddaman# Eclipse Public License, Version 1.0 # 77c2fbfb3SApril Chin# by AT&T Intellectual Property # 8da2e3ebdSchin# # 9da2e3ebdSchin# A copy of the License is available at # 10*b30d1939SAndy Fiddaman# http://www.eclipse.org/org/documents/epl-v10.html # 11*b30d1939SAndy Fiddaman# (with md5 checksum b35adb5213ca9657e911e9befb180842) # 12da2e3ebdSchin# # 13da2e3ebdSchin# Information and Software Systems Research # 14da2e3ebdSchin# AT&T Research # 15da2e3ebdSchin# Florham Park NJ # 16da2e3ebdSchin# # 17da2e3ebdSchin# David Korn <dgk@research.att.com> # 18da2e3ebdSchin# # 19da2e3ebdSchin######################################################################## 20da2e3ebdSchin: generate the ksh math builtin table 21da2e3ebdSchin: include math.tab 22da2e3ebdSchin 23*b30d1939SAndy Fiddaman# @(#)math.sh (AT&T Research) 2012-06-13 24da2e3ebdSchin 25da2e3ebdSchincommand=$0 2634f9b3eeSRoland Mainziffeflags="-n -v" 27*b30d1939SAndy Fiddamaniffehdrs="math.h" 28da2e3ebdSchiniffelibs="-lm" 29da2e3ebdSchintable=/dev/null 30da2e3ebdSchin 31da2e3ebdSchineval $1 32da2e3ebdSchinshift 33da2e3ebdSchintable=$1 34da2e3ebdSchin 357c2fbfb3SApril Chin: check long double 367c2fbfb3SApril Chin 377c2fbfb3SApril Chineval `iffe $iffeflags -c "$cc" - typ long.double 2>&$stderr` 387c2fbfb3SApril Chin 3934f9b3eeSRoland Mainz: check ast_standards.h 4034f9b3eeSRoland Mainz 4134f9b3eeSRoland Mainzeval `iffe $iffeflags -F ast_standards.h -c "$cc" - tst use_ast_standards -lm 'note{' 'math.h needs ast_standards.h' '}end' 'link{' '#include <math.h>' '#ifndef isgreater' '#define isgreater(a,b) 0' '#endif' 'int main() { return isgreater(0.0,1.0); }' '}end'` 4234f9b3eeSRoland Mainzcase $_use_ast_standards in 4334f9b3eeSRoland Mainz1) iffeflags="$iffeflags -F ast_standards.h" ;; 4434f9b3eeSRoland Mainzesac 45*b30d1939SAndy Fiddamaneval `iffe $iffeflags -c "$cc" - tst use_ieeefp -lm 'note{' 'ieeefp.h plays nice' '}end' 'link{' '#include <math.h>' '#include <ieeefp.h>' 'int main() { return 0; }' '}end'` 46*b30d1939SAndy Fiddamancase $_use_ieeefp in 47*b30d1939SAndy Fiddaman1) iffehdrs="$iffehdrs ieeefp.h" ;; 48*b30d1939SAndy Fiddamanesac 4934f9b3eeSRoland Mainz 50da2e3ebdSchin: read the table 51da2e3ebdSchin 52da2e3ebdSchinexec < $table 53*b30d1939SAndy Fiddamanifs=$IFS 54*b30d1939SAndy Fiddamanlibs= 55*b30d1939SAndy Fiddamannames= 56*b30d1939SAndy Fiddamannums= 57*b30d1939SAndy Fiddamanwhile read type args name aka 58da2e3ebdSchindo case $type in 59*b30d1939SAndy Fiddaman [fix]) names="$names $name" 60*b30d1939SAndy Fiddaman libs="$libs,$name" 617c2fbfb3SApril Chin case $_typ_long_double in 62*b30d1939SAndy Fiddaman 1) libs="$libs,${name}l" ;; 637c2fbfb3SApril Chin esac 64*b30d1939SAndy Fiddaman for a in $aka 65*b30d1939SAndy Fiddaman do case $a in 66*b30d1939SAndy Fiddaman '{'*) break 67*b30d1939SAndy Fiddaman ;; 68*b30d1939SAndy Fiddaman *=*) IFS='=|' 69*b30d1939SAndy Fiddaman set $a 70*b30d1939SAndy Fiddaman IFS=$ifs 71*b30d1939SAndy Fiddaman case ",$libs" in 72*b30d1939SAndy Fiddaman *,$1,*) ;; 73*b30d1939SAndy Fiddaman *) names="$names $1" 74*b30d1939SAndy Fiddaman libs="$libs,$1" 75*b30d1939SAndy Fiddaman case $_typ_long_double in 76*b30d1939SAndy Fiddaman 1) libs="$libs,${1}l" ;; 77*b30d1939SAndy Fiddaman esac 78*b30d1939SAndy Fiddaman ;; 79*b30d1939SAndy Fiddaman esac 80*b30d1939SAndy Fiddaman shift 81*b30d1939SAndy Fiddaman while : 82*b30d1939SAndy Fiddaman do case $# in 83*b30d1939SAndy Fiddaman 0) break ;; 84*b30d1939SAndy Fiddaman esac 85*b30d1939SAndy Fiddaman case ",$nums" in 86*b30d1939SAndy Fiddaman *,$1,*) ;; 87*b30d1939SAndy Fiddaman *) nums="$nums,$1" ;; 88*b30d1939SAndy Fiddaman esac 89*b30d1939SAndy Fiddaman shift 90*b30d1939SAndy Fiddaman done 91*b30d1939SAndy Fiddaman ;; 92*b30d1939SAndy Fiddaman esac 93*b30d1939SAndy Fiddaman done 94*b30d1939SAndy Fiddaman eval TYPE_$name='$type' ARGS_$name='$args' AKA_$name='$aka' 95da2e3ebdSchin ;; 96da2e3ebdSchin esac 97da2e3ebdSchindone 98da2e3ebdSchin 99da2e3ebdSchin: check the math library 100da2e3ebdSchin 101*b30d1939SAndy Fiddamaneval `iffe $iffeflags -c "$cc" - lib $libs $iffehdrs $iffelibs 2>&$stderr` 102da2e3ebdSchinlib= 103da2e3ebdSchinfor name in $names 104da2e3ebdSchindo eval x='$'_lib_${name}l y='$'_lib_${name} 105da2e3ebdSchin case $x in 106da2e3ebdSchin 1) lib="$lib,${name}l" ;; 107da2e3ebdSchin esac 108da2e3ebdSchin case $y in 109da2e3ebdSchin 1) case $x in 110da2e3ebdSchin '') lib="$lib,${name}" ;; 111da2e3ebdSchin esac 112da2e3ebdSchin ;; 113da2e3ebdSchin esac 114da2e3ebdSchindone 115da2e3ebdSchineval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr` 116*b30d1939SAndy Fiddamaneval `iffe $iffeflags -c "$cc" - num $nums $iffehdrs $iffelibs 2>&$stderr` 117da2e3ebdSchin 118da2e3ebdSchincat <<! 119da2e3ebdSchin#pragma prototyped 120da2e3ebdSchin 121da2e3ebdSchin/* : : generated by $command from $table : : */ 122da2e3ebdSchin 123da2e3ebdSchintypedef Sfdouble_t (*Math_f)(Sfdouble_t,...); 124da2e3ebdSchin 125da2e3ebdSchin! 12634f9b3eeSRoland Mainzcase $_use_ast_standards in 12734f9b3eeSRoland Mainz1) echo "#include <ast_standards.h>" ;; 12834f9b3eeSRoland Mainzesac 129da2e3ebdSchinecho "#include <math.h>" 130da2e3ebdSchincase $_hdr_ieeefp in 13134f9b3eeSRoland Mainz1) echo "#include <ieeefp.h>" ;; 132da2e3ebdSchinesac 13334f9b3eeSRoland Mainzecho 134da2e3ebdSchin 135da2e3ebdSchin: generate the intercept functions and table entries 136da2e3ebdSchin 137da2e3ebdSchinnl=' 138da2e3ebdSchin' 139da2e3ebdSchinht=' ' 140da2e3ebdSchintab= 141da2e3ebdSchinfor name in $names 142da2e3ebdSchindo eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name} 143*b30d1939SAndy Fiddaman case $r in 144*b30d1939SAndy Fiddaman i) L=int R=1 ;; 145*b30d1939SAndy Fiddaman x) L=Sfdouble_t R=4 ;; 146*b30d1939SAndy Fiddaman *) L=Sfdouble_t R=0 ;; 147*b30d1939SAndy Fiddaman esac 148*b30d1939SAndy Fiddaman F=local_$name 149da2e3ebdSchin case $x:$y in 150da2e3ebdSchin 1:*) f=${name}l 151da2e3ebdSchin t=Sfdouble_t 152da2e3ebdSchin local= 153da2e3ebdSchin ;; 154da2e3ebdSchin *:1) f=${name} 155da2e3ebdSchin t=double 156da2e3ebdSchin local=$_typ_long_double 157da2e3ebdSchin ;; 158*b30d1939SAndy Fiddaman *) body= 159*b30d1939SAndy Fiddaman for k in $aka 160*b30d1939SAndy Fiddaman do case $body in 161*b30d1939SAndy Fiddaman ?*) body="$body $k" 162*b30d1939SAndy Fiddaman continue 163*b30d1939SAndy Fiddaman ;; 164*b30d1939SAndy Fiddaman esac 165*b30d1939SAndy Fiddaman case $k in 166*b30d1939SAndy Fiddaman '{'*) body=$k 167*b30d1939SAndy Fiddaman ;; 168*b30d1939SAndy Fiddaman *=*) IFS='=|' 169*b30d1939SAndy Fiddaman set $k 170*b30d1939SAndy Fiddaman IFS=$ifs 171*b30d1939SAndy Fiddaman f=$1 172*b30d1939SAndy Fiddaman shift 173*b30d1939SAndy Fiddaman v=$* 174*b30d1939SAndy Fiddaman eval x='$'_lib_${f}l y='$'_lib_${f} 175*b30d1939SAndy Fiddaman case $x:$y in 176*b30d1939SAndy Fiddaman 1:*) f=${f}l 177*b30d1939SAndy Fiddaman ;; 178*b30d1939SAndy Fiddaman *:1) ;; 179*b30d1939SAndy Fiddaman *) continue 180*b30d1939SAndy Fiddaman ;; 181*b30d1939SAndy Fiddaman esac 182*b30d1939SAndy Fiddaman y= 183*b30d1939SAndy Fiddaman while : 184*b30d1939SAndy Fiddaman do case $# in 185*b30d1939SAndy Fiddaman 0) break ;; 186*b30d1939SAndy Fiddaman esac 187*b30d1939SAndy Fiddaman eval x='$'_num_$1 188*b30d1939SAndy Fiddaman case $x in 189*b30d1939SAndy Fiddaman 1) case $y in 190*b30d1939SAndy Fiddaman ?*) y="$y || " ;; 191*b30d1939SAndy Fiddaman esac 192*b30d1939SAndy Fiddaman y="${y}q == $1" 193*b30d1939SAndy Fiddaman ;; 194*b30d1939SAndy Fiddaman esac 195*b30d1939SAndy Fiddaman shift 196*b30d1939SAndy Fiddaman done 197*b30d1939SAndy Fiddaman case $y in 198*b30d1939SAndy Fiddaman '') ;; 199*b30d1939SAndy Fiddaman *) r=int R=1 200*b30d1939SAndy Fiddaman echo "static $r $F(Sfdouble_t a1) { $r q = $f(a1); return $y; }" 201*b30d1939SAndy Fiddaman tab="$tab$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)(uintptr_t)${F}," 202*b30d1939SAndy Fiddaman break 203*b30d1939SAndy Fiddaman ;; 204*b30d1939SAndy Fiddaman esac 20534f9b3eeSRoland Mainz ;; 206*b30d1939SAndy Fiddaman esac 207*b30d1939SAndy Fiddaman done 208*b30d1939SAndy Fiddaman case $body in 209*b30d1939SAndy Fiddaman ?*) code="static $L $F(" 210*b30d1939SAndy Fiddaman sep= 211*b30d1939SAndy Fiddaman ta= 212*b30d1939SAndy Fiddaman tc= 213*b30d1939SAndy Fiddaman td= 214*b30d1939SAndy Fiddaman for p in 1 2 3 4 5 6 7 8 9 215*b30d1939SAndy Fiddaman do case $R:$p in 216*b30d1939SAndy Fiddaman 4:2) T=int ;; 217*b30d1939SAndy Fiddaman *) T=Sfdouble_t ;; 218*b30d1939SAndy Fiddaman esac 219*b30d1939SAndy Fiddaman code="$code${sep}$T a$p" 220*b30d1939SAndy Fiddaman ta="$ta${sep}a$p" 221*b30d1939SAndy Fiddaman tc="$tc${sep}0" 222*b30d1939SAndy Fiddaman td="${td}$T a$p;" 223*b30d1939SAndy Fiddaman case $a in 224*b30d1939SAndy Fiddaman $p) break ;; 225*b30d1939SAndy Fiddaman esac 226*b30d1939SAndy Fiddaman sep="," 227*b30d1939SAndy Fiddaman done 228*b30d1939SAndy Fiddaman _it_links_=0 229*b30d1939SAndy Fiddaman eval `iffe $iffeflags -c "$cc" - tst it_links_ note{ $F function links }end link{ "static $L $F($ta)$td${body}int main(){return $F($tc)!=0;}" }end sfio.h $iffehdrs $iffelibs 2>&$stderr` 230*b30d1939SAndy Fiddaman case $_it_links_ in 231*b30d1939SAndy Fiddaman 1) code="$code)$body" 232*b30d1939SAndy Fiddaman echo "$code" 233*b30d1939SAndy Fiddaman tab="$tab$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)(uintptr_t)${F}," 23434f9b3eeSRoland Mainz ;; 23534f9b3eeSRoland Mainz esac 23634f9b3eeSRoland Mainz ;; 23734f9b3eeSRoland Mainz esac 23834f9b3eeSRoland Mainz continue 239da2e3ebdSchin ;; 240da2e3ebdSchin esac 241da2e3ebdSchin case $r in 242*b30d1939SAndy Fiddaman i) r=int ;; 243*b30d1939SAndy Fiddaman *) r=$t ;; 244da2e3ebdSchin esac 245*b30d1939SAndy Fiddaman eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f 246da2e3ebdSchin case $d:$m:$n in 247da2e3ebdSchin 1:*:*|*:1:*) 248da2e3ebdSchin ;; 249da2e3ebdSchin *:*:1) code="extern $r $f(" 250da2e3ebdSchin sep= 251da2e3ebdSchin for p in 1 2 3 4 5 6 7 252*b30d1939SAndy Fiddaman do case $p:$f in 253*b30d1939SAndy Fiddaman 2:ldexp*) code="$code${sep}int" ;; 254*b30d1939SAndy Fiddaman *) code="$code${sep}$t" ;; 255*b30d1939SAndy Fiddaman esac 256da2e3ebdSchin case $a in 257da2e3ebdSchin $p) break ;; 258da2e3ebdSchin esac 259da2e3ebdSchin sep="," 260da2e3ebdSchin done 261da2e3ebdSchin code="$code);" 262da2e3ebdSchin echo "$code" 263da2e3ebdSchin ;; 264da2e3ebdSchin esac 265da2e3ebdSchin case $local:$m:$n:$d in 2667c2fbfb3SApril Chin 1:*:*:*|*:1:*:*|*:*:1:) 267da2e3ebdSchin args= 268da2e3ebdSchin code="static $L local_$f(" 269da2e3ebdSchin sep= 270da2e3ebdSchin for p in 1 2 3 4 5 6 7 8 9 271da2e3ebdSchin do args="$args${sep}a$p" 272*b30d1939SAndy Fiddaman case $R:$p in 273*b30d1939SAndy Fiddaman 4:2) T=int ;; 274*b30d1939SAndy Fiddaman *) T=Sfdouble_t ;; 275*b30d1939SAndy Fiddaman esac 276*b30d1939SAndy Fiddaman code="$code${sep}$T a$p" 277da2e3ebdSchin case $a in 278da2e3ebdSchin $p) break ;; 279da2e3ebdSchin esac 280da2e3ebdSchin sep="," 281da2e3ebdSchin done 282da2e3ebdSchin code="$code){return $f($args);}" 283da2e3ebdSchin echo "$code" 284da2e3ebdSchin f=local_$f 285da2e3ebdSchin ;; 286da2e3ebdSchin esac 287da2e3ebdSchin for x in $name $aka 288*b30d1939SAndy Fiddaman do case $x in 289*b30d1939SAndy Fiddaman '{'*) break 290*b30d1939SAndy Fiddaman ;; 291*b30d1939SAndy Fiddaman *=*) continue 292*b30d1939SAndy Fiddaman ;; 293*b30d1939SAndy Fiddaman esac 294*b30d1939SAndy Fiddaman tab="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)(uintptr_t)$f," 295da2e3ebdSchin done 296da2e3ebdSchindone 297da2e3ebdSchintab="$tab$nl$ht\"\",$ht$ht(Math_f)0" 298da2e3ebdSchin 299da2e3ebdSchincat <<! 300da2e3ebdSchin 301da2e3ebdSchin/* 302da2e3ebdSchin * first byte is two-digit octal number. Last digit is number of args 303da2e3ebdSchin * first digit is 0 if return value is double, 1 for integer 304da2e3ebdSchin */ 305da2e3ebdSchinconst struct mathtab shtab_math[] = 306da2e3ebdSchin{$tab 307da2e3ebdSchin}; 308da2e3ebdSchin! 309