~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to callback/vacall_r/asmi386.sh

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Translate the assembler syntax of i386 assembler programs
 
3
# Usage: asmsyntax [-no-C] < gas-asm-file > all-asm-file
 
4
# Warning! All comments are stripped.
 
5
 
 
6
tmpscript01=sed$$tmp01
 
7
tmpscript02=sed$$tmp02
 
8
tmpscript03=sed$$tmp03
 
9
tmpscript04=sed$$tmp04
 
10
tmpscript05=sed$$tmp05
 
11
tmpscript06=sed$$tmp06
 
12
tmpscript07=sed$$tmp07
 
13
tmpscript08=sed$$tmp08
 
14
tmpscript09=sed$$tmp09
 
15
tmpscript10=sed$$tmp10
 
16
tmpscript11=sed$$tmp11
 
17
tmpremove='rm -f $tmpscript01 $tmpscript02 $tmpscript03 $tmpscript04 $tmpscript05 $tmpscript06 $tmpscript07 $tmpscript08 $tmpscript09 $tmpscript10 $tmpscript11'
 
18
trap "$tmpremove" 1 2 15
 
19
 
 
20
cat > $tmpscript01 << \EOF
 
21
# ----------- Strip comments
 
22
s,# .*,,
 
23
s,[     ][      ]*$,,
 
24
EOF
 
25
 
 
26
cat > $tmpscript02 << \EOF
 
27
# ----------- Remove #APP/#NO_APP lines, add a blank line at the end
 
28
/^#APP$/d
 
29
/^#NO_APP$/d
 
30
/gcc2_compiled/d
 
31
/gnu_compiled_c/d
 
32
EOF
 
33
 
 
34
cat > $tmpscript03 << \EOF
 
35
# ----------- Global symbols depends on ASM_UNDERSCORE
 
36
s/_\([A-Za-z0-9_:]*\)/C(\1)/
 
37
EOF
 
38
 
 
39
cat > $tmpscript04 << \EOF
 
40
# ----------- Introduce macro syntax for operands
 
41
s/\([-+0-9A-Z_]\+\)[(]%\(e..\)[)]/MEM_DISP(\2,\1)/g
 
42
s/[(]%\(e..\)[)]/MEM(\1)/g
 
43
s/\([-+0-9A-Z_]\+\)[(],%\(e..\),\([0-9]*\)[)]/MEM_DISP_SHINDEX0(\1,\2,\3)/g
 
44
s/\([-+0-9A-Z_]\+\)[(]%\(e..\),%\(e..\),\([0-9]*\)[)]/MEM_DISP_SHINDEX(\2,\1,\3,\4)/g
 
45
s/[(]%\(e..\),%\(e..\),\([0-9]*\)[)]/MEM_SHINDEX(\1,\2,\3)/g
 
46
s/[(]%\(e..\),%\(e..\)[)]/MEM_INDEX(\1,\2)/g
 
47
EOF
 
48
 
 
49
cat > $tmpscript05 << \EOF
 
50
# ----------- Introduce macro syntax for instructions
 
51
s/\(push\|pop\|mul\|div\|not\|neg\|inc\|dec\|fld\|fstp\)\(.\)\( \+\)\(.*\)$/INSN1(\1,\2 ,\4)/
 
52
s/\(call\|jmp\|jc\|jnc\|je\|jne\|jz\|jnz\|ja\|jae\|jb\|jbe\|jl\|jge\|js\|jns\)\( \+\)\(.*\)$/INSN1(\1,_ ,\3)/
 
53
s/\(movs\|movz\)\(.\)l\( \+\)\(.*\)$/INSN2MOVX(\1,\2    ,\4)/
 
54
s/\(mov\|add\|sub\|adc\|sbb\|xor\|test\|cmp\|rcl\|rcr\|and\|or\|sar\|shr\|shl\|lea\)\(.\)\( \+\)\(.*\)$/INSN2(\1,\2     ,\4)/
 
55
s/\(shld\|shrd\)\(.\)\( \+\)shcl\( \+\)\(.*\)$/INSN2SHCL(\1,\2  ,\5)/
 
56
s/rep ;/REP/
 
57
s/repz ;/REPZ/
 
58
EOF
 
59
 
 
60
cat > $tmpscript06 << \EOF
 
61
# ----------- Add size prefixes to memory references' \
 
62
s/\([(]f[^(,]*,s.*\),MEM/\1,X4 MEM/g
 
63
s/\([(]f[^(,]*,l.*\),MEM/\1,X8 MEM/g
 
64
s/\([(][^(,]*,b.*\),MEM/\1,X1 MEM/g
 
65
s/\([(][^(,]*,w.*\),MEM/\1,X2 MEM/g
 
66
s/\([(][^(,]*,l.*\),MEM/\1,X4 MEM/g
 
67
EOF
 
68
 
 
69
cat > $tmpscript07 << \EOF
 
70
# ----------- Introduce macro syntax for register names
 
71
s/%\(e..\)/R(\1)/g
 
72
s/%\(..\)/R(\1)/g
 
73
s/\$\([-0-9]*\)/NUM(\1)/g
 
74
EOF
 
75
 
 
76
cat > $tmpscript08 << \EOF
 
77
# ----------- Treat table jumps (hairy)
 
78
# (Needed because the MSVC inline assembler does not have pseudo-ops.
 
79
# Note that we transform a table of absolute addresses with 4 bytes
 
80
# per entry into a table of absolute addresses with 8 bytes per entry.)
 
81
s/^     \.long \(.*\)$/#ifdef _MSC_VER\
 
82
        nop\
 
83
        nop\
 
84
        push \1\
 
85
#else\
 
86
        .long \1\
 
87
#endif/
 
88
s/^     \(INSN1[(]jmp,_[^,]*,\)\*MEM_DISP_SHINDEX0[(]\([^,)]*\),\([^,)]*\),4[)][)]$/#ifdef _MSC_VER\
 
89
        INSN2(lea,l     ,MEM_DISP_SHINDEX0(\2+8,\3,8),R(\3))\
 
90
        INSN2(mov,l     ,X4 MEM_DISP(\3,-4),R(\3))\
 
91
        INSN1(jmp,_     ,INDIR(R(\3)))\
 
92
#else\
 
93
        \1INDIR(MEM_DISP_SHINDEX0(\2,\3,4)))\
 
94
#endif/
 
95
EOF
 
96
 
 
97
cat > $tmpscript09 << \EOF
 
98
# ----------- Treat indirect calls
 
99
s/\(INSN1[(]\(call\|jmp\),_[^,]*,\)\*\(R[(][^)]*[)]\)[)]$/\1INDIR(\3))/
 
100
EOF
 
101
 
 
102
cat > $tmpscript10 << \EOF
 
103
# ----------- Introduce macro syntax for assembler pseudo-ops
 
104
/\.file\([      ]\+\)/d
 
105
s/\.text/TEXT()/
 
106
s/^\([^#]*\)\.align \(.*\)/\1ALIGN(\2)/
 
107
s/\.globl\( \+\)\(.*\)$/GLOBL(\2)/
 
108
s/^C(\([A-Za-z0-9_]*\):)/FUNBEGIN(\1)/
 
109
# The next 5 lines add FUNEND() after each ret followed by an empty line
 
110
/[      ]ret *$/{
 
111
n
 
112
/^$/s/^$/FUNEND()\
 
113
/
 
114
}
 
115
EOF
 
116
 
 
117
cat > $tmpscript11 << \EOF
 
118
# ----------- Declare global symbols as functions (we have no variables)
 
119
s/GLOBL(C(\([A-Za-z0-9_]*\)))$/GLOBL(C(\1))\
 
120
        DECLARE_FUNCTION(\1)/
 
121
EOF
 
122
 
 
123
sed -f $tmpscript01 | \
 
124
sed -f $tmpscript02 | \
 
125
(cat - ; echo) | \
 
126
(if [ $# = 1 -a "x$1" = "x-no-C" ] ; then cat - ; else sed -f $tmpscript03 ; fi) | \
 
127
sed -f $tmpscript04 | \
 
128
sed -f $tmpscript05 | \
 
129
sed -f $tmpscript06 | \
 
130
sed -f $tmpscript07 | \
 
131
sed -f $tmpscript08 | \
 
132
sed -f $tmpscript09 | \
 
133
sed -f $tmpscript10 | \
 
134
(if [ $# = 1 -a "x$1" = "x-no-C" ] ; then cat - ; else sed -f $tmpscript11 ; fi)
 
135
 
 
136
eval "$tmpremove"
 
137