translate: handle more cases with args
[ia32rtools.git] / run_sed.sh
... / ...
CommitLineData
1#!/bin/sh -x
2
3# sed -i -e '/.model flat/i\
4# \t\t.xmm\r' StarCraft.asm
5
6usyms="copy_start ___from_strstr_to_strchr unknown_libname_36 unknown_libname_41 unknown_libname_58"
7
8f=/tmp/sedcmd_
9echo -n "sed -i -e '/.model flat/i\\\t\t.xmm\r' -e '" > $f
10for sym in $usyms; do
11 echo -n "s/^\<$sym\>:\([^:]\)/$sym::\1/g;" >> $f
12done
13
14echo "\
15s/^\([ +-]\?loc[r_].*[0-9A-F]:\)[^:]\(.*\;\)/\1:\t\2/g;\
16s/dd[[:blank:]]rva/dd/;\
17s/\<fldcw\>\t\[esp+4+var_4\]/fldcw\tword ptr \[esp\]/;\
18s/\<large \(.*fs:\)/\1/;\
19s/lea\t\(e.[px]\), \[\1+0\]/align 10h/;\
20s/\[\(e..\)+\(e.p\)\]/\[\2+\1\]/;\
21s/\<lea\t\(e..\), \[\(e.p\)+\(e.x\)+/lea\t\1, \[\3+\2+/;\
22s/\[\(e.p\)+\(e.i\)+/\[\2+\1+/;\
23s/\<pushf\>/pushfd/;\
24s/\<popf\>/popfd/;\
25s/\(\<j[mn]\?[abceglopszp]e\?\>\)\tloc_/\1\tnear ptr loc_/;\
26s/\<jmp\tsub_/jmp\tnear ptr sub_/;\
27' $1" >> $f
28. $f
29
30# manual fixup:
31# - 'end start' -> 'end'
32# - 'mov edi, edi', 'lea ...' -> align
33# - add 'near ptr' to some jumps
34# - 'cmp [ebp+edx+0], cl' -> 'cmp [ebp+edx*1+0], cl'
35# - 0FFxxh constants - masm treats a byte, ONLY sometimes prefix with 'word ptr'
36# - jmp near:
37# - jmp _strchr
38# - search for 'dword_xx+N', make byte/word, also word->byte
39# - get rid of type propagation, regenerate as 'simple' var_
40# - convert ds:0[eax*4] -> [eax*4+0] (h hotkey)
41# - rm function chunks - they're funcs reached by tailcalls (usually)