wok-6.x diff linld/stuff/src/pipehole.awk @ rev 20634

linld: fix open()
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 08 17:51:51 2019 +0100 (2019-01-08)
parents ab907169f156
children cbcb33ee9044
line diff
     1.1 --- a/linld/stuff/src/pipehole.awk	Sat Jan 05 17:23:23 2019 +0100
     1.2 +++ b/linld/stuff/src/pipehole.awk	Tue Jan 08 17:51:51 2019 +0100
     1.3 @@ -2,6 +2,7 @@
     1.4  function isnum(n) { return match(n,/^[0-9+-]/) }
     1.5  {
     1.6  	sub(/segment word public/,"segment byte public")
     1.7 +
     1.8  	if (hold == 0) {
     1.9  		s=$0
    1.10  		if (/^	mov	.[ix],bx$/ || /^	mov	.[ix],.i$/) {
    1.11 @@ -27,6 +28,13 @@
    1.12  		if (/^	cmp	word ptr DGROUP:.*,0$/)  {
    1.13  			hold=8; split($2,regs,","); next
    1.14  		}
    1.15 +		if (/^	cbw/)		  { hold=11; kept=0; next }
    1.16 +		if (/^	add	[abcds][ix],2$/) {
    1.17 +			split($2,regs,","); hold=12; next
    1.18 +		}
    1.19 +		if (/^	sub	[abcds][ix],2$/) {
    1.20 +			split($2,regs,","); hold=13; next
    1.21 +		}
    1.22  	}
    1.23  	else if (hold == 1) {
    1.24  		if (/^   ;/) { line[kept++]=$0; next }
    1.25 @@ -130,6 +138,39 @@
    1.26  		}
    1.27  		for (i = 0; i < kept; i++) print line[i]
    1.28  	}
    1.29 +	else if (hold == 11) {
    1.30 +		if (/^	inc	ax$/ || /^	dec	ax$/) {
    1.31 +			line[kept++]=$0; next
    1.32 +		}
    1.33 +		split($2,args,",")
    1.34 +		if (/^	mov	cl,/) {
    1.35 +			split($2,args,",")
    1.36 +			if (args[2] >= 8) {
    1.37 +				line[kept++]=$0; next
    1.38 +			}
    1.39 +		}
    1.40 +		if (!/^	shl	ax,/ || (args[2] != "cl" && args[2] < 8)) {
    1.41 +			print "	cbw	"
    1.42 +		}
    1.43 +		for (i = 0; i < kept; i++) print line[i]
    1.44 +		hold=kept=0
    1.45 +	}
    1.46 +	else if (hold == 12) {
    1.47 +		hold=0
    1.48 +		if ($1 != "adc" && $1 != "sbb" && ! /^	jn?[abc]/) {
    1.49 +			print "	inc	" regs[1]
    1.50 +			print "	inc	" regs[1]
    1.51 +		}
    1.52 +		else	print "	add	" regs[1] ",2"
    1.53 +	}
    1.54 +	else if (hold == 13) {
    1.55 +		hold=0
    1.56 +		if ($1 != "adc" && $1 != "sbb" && ! /^	jn?[abc]/) {
    1.57 +			print "	dec	" regs[1]
    1.58 +			print "	dec	" regs[1]
    1.59 +		}
    1.60 +		else	print "	sub	" regs[1] ",2"
    1.61 +	}
    1.62  	s=$0
    1.63  	# These optimisation may break ZF or CF
    1.64  	if (/^	sub	sp,2$/) { print "	push	ax"; next }