collab/polyglot-riscv-arm
what if the same machine code was valid riscv and arm asm
git clone https://git.julia.blue/collab/polyglot-riscv-arm
885cc4e
main
1package main 2 3import ( 4"encoding/json" 5"encoding/xml" 6"flag" 7"fmt" 8"io/fs" 9"log" 10"os" 11"path/filepath" 12"strings" 13 14"github.com/zyedidia/armvis/mra" 15) 16 17func main () { 18base := flag .Bool ("base" ,false ,"only consider instructions from the ARMv8.0 instruction set" ) 19classes := flag .String ("classes" ,"all" ,"comma-separated list of instruction classes" ) 20variant := flag .String ("variant" ,"" ,"ISA version" ) 21 22flag .Parse () 23args := flag .Args () 24 25var allrecords []mra.Record 26 27filepath .WalkDir (args [0 ],func (path string ,insn fs.DirEntry ,err error )error { 28if insn != nil && ! insn .IsDir ()&& strings .HasSuffix (path ,".xml" ) { 29data ,err := os .ReadFile (path ) 30if err != nil { 31log .Fatal (err ) 32 } 33var insn mra.InsnSection 34if err := xml .Unmarshal (data ,& insn );err != nil { 35return nil 36 } 37 38if insn .Type == "instruction" { 39if * base && ! insn .BaseVariant () { 40return nil 41 } 42hasclass := false 43for _ ,class := range strings .Split (* classes ,"," ) { 44if insn .HasClass (class ) { 45hasclass = true 46 } 47 } 48if ! hasclass { 49return nil 50 } 51if * variant != "" && ! insn .VariantLE (* variant ) { 52return nil 53 } 54 55allrecords = append (allrecords ,mra .NewRecords (filepath .Base (path ),insn )... ) 56 } 57 } 58return nil 59 }) 60 61b ,err := json .Marshal (allrecords ) 62if err != nil { 63log .Fatal (err ) 64 } 65fmt .Println (string (b )) 66}