File: asm-hppa.sh

package info (click to toggle)
ffcall 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,808 kB
  • sloc: asm: 43,409; ansic: 23,224; sh: 5,383; makefile: 1,517; cpp: 2
file content (68 lines) | stat: -rwxr-xr-x 2,027 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# Translate the assembler syntax of hppa assembler programs
# Usage: asm-hppa.sh < hppalinux-asm-file > portable-asm-file
# The portable-asm-file has to be
#   1. preprocessed,
#   2. grep -v '^ *#line' | grep -v '^#'
#   3. sed -e "s,!,',g"

# Copyright (C) 2017 Bruno Haible <bruno@clisp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

tmpscript1=sed$$tmp1
tmpscript2=sed$$tmp2
tmpremove='rm -f $tmpscript1 $tmpscript2'
trap "$tmpremove" 1 2 15

cat > $tmpscript1 << \EOF
# ----------- Remove #APP/#NO_APP lines and gcc self-identification
/^#APP$/d
/^#NO_APP$/d
/gcc2_compiled/d
/gnu_compiled_c/d
/\.ident/d
EOF

cat > $tmpscript2 << \EOF
# ----------- Turn ' into !, to avoid trouble in preprocessing
s,',!,g
# ----------- Add some imports
/\.LEVEL/{
s/$/\
	IMPORT_MILLICODE($$dyncall)/
}
# ----------- Section switching
s/\.text/TEXT1()\
	TEXT2()/
# ----------- Declaration of symbols and labels is different
s/^\([A-Za-z0-9_.]\+\):$/DEF(\1)/
# ----------- Label syntax is different
/\.LEVEL/!{
s/\.L\([A-Za-z0-9_]\+\)/L(\1)/
}
# ----------- Introduce macro syntax for assembler pseudo-ops
s/\.globl[ 	]\([A-Za-z0-9_]\+\)/GLOBL(\1)/
# ----------- Massage the beginning of functions
/\.type/{
s/\.type[ 	]\+\([A-Za-z0-9_]*\), *@function/DECLARE_FUNCTION(\1)/
}
# ----------- Massage the end of functions
s/\.size[ 	]\([A-Za-z0-9_]*\),\(.*\)/FUNEND(\1)/
EOF

sed -f $tmpscript1 | \
sed -f $tmpscript2

eval "$tmpremove"