-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathassemble.sh
executable file
·37 lines (30 loc) · 1.05 KB
/
assemble.sh
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
#!/usr/bin/bash
# This script will be used by pocl
export PATH=${VENTUS_INSTALL_PREFIX}/bin:$PATH
if [[ -f $1.vmem ]];then
rm $1.vmem
fi
llvm-objdump -d --mattr=+v,+zfinx $1.riscv > $1.dump
# Add a flag to mark .text section
found_text_section=0
# Traverse line in dump file
while IFS= read -r line; do
# Judge if meet .text section
if [[ $line == *"Disassembly of section .text:"* ]]; then
found_text_section=1
continue
fi
# Ignore other non .text section
if [[ $line == *"Disassembly of section"* ]]; then
found_text_section=0
fi
if [[ $found_text_section -eq 1 ]]; then
# Only deal with the line starting with hex data
if [[ $line =~ ^[0-9a-fA-F]+: ]]; then
# Print column 2-5 in reverse order
hex_data=$(awk 'function is_hex(s) { return match(s, /^[0-9a-fA-F]+$/) } { for (i = 5; i >= 2; i--) { if (is_hex($i)) printf "%s", $i } print "" }' <<< "$line")
echo "$hex_data" >> $1.vmem
fi
fi
done < $1.dump
# echo "finish converting to vmem file!"