It's using the shell's own tokenizer to parse asm! That's glorious!
I don't really understand why the code works since I can't read x86 asm yet, but I think how it works is reasonably clear. Each instruction has its own bash function that writes its opcodes to the output file and the asm script to be assembled is (I think) sourced directly into the running shell session.
I once built a package to allow redistribution of C/Flex/Go-scripts with just-in-time compilation (https://github.com/radiospiel/jit) but mine does not allow to mix the to-be-compiled language into the bash script itself; so count me impressed :)
19 comments
[ 2.9 ms ] story [ 41.8 ms ] threadUh, no? :)
http://lists.gnu.org/archive/html/bug-bash/2001-02/msg00054....
My favourite of the listed reasons.
it's a set of functions for bash that when sourced make the assembly a valid bash script which then runs and assembles itself. this is genius.
I don't really understand why the code works since I can't read x86 asm yet, but I think how it works is reasonably clear. Each instruction has its own bash function that writes its opcodes to the output file and the asm script to be assembled is (I think) sourced directly into the running shell session.
i.e:
cc -fPIC -o $sofile -shared <(cat <<'EOF'
...
EOF
)