pkg/ifuzz: use serializer

Simplifies code and reduces size of generated code from 820K to 310K.
This commit is contained in:
Dmitry Vyukov 2017-09-04 19:53:02 +02:00
parent dbb49d0211
commit b5c5217623
3 changed files with 2181 additions and 2183 deletions

View File

@ -14,6 +14,7 @@ import (
"strings"
"github.com/google/syzkaller/pkg/ifuzz"
"github.com/google/syzkaller/pkg/serializer"
)
func main() {
@ -138,6 +139,10 @@ func main() {
var deduped []*ifuzz.Insn
nextInsn:
for _, insn := range insns {
if insn.Extension == "AVX512VEX" || insn.Extension == "AVX512EVEX" {
skipped++
continue
}
mod0 := insn.Mod
for j := len(deduped) - 1; j >= 0; j-- {
insn1 := deduped[j]
@ -159,19 +164,8 @@ nextInsn:
fmt.Printf("// AUTOGENERATED FILE\n")
fmt.Printf("package ifuzz\n\n")
fmt.Printf("var Insns = []*Insn{\n")
for _, insn := range insns {
if insn.Extension == "AVX512VEX" || insn.Extension == "AVX512EVEX" {
skipped++
continue
}
text := fmt.Sprintf("%#v", insn)
text = strings.Replace(text, "ifuzz.Insn", "Insn", -1)
text = strings.Replace(text, ", generator:(func(*ifuzz.Config, *rand.Rand) []uint8)(nil)", "", -1)
fmt.Printf(" %v,\n", text)
}
fmt.Printf("}\n")
fmt.Printf("var Insns = ")
serializer.Write(os.Stdout, insns)
fmt.Fprintf(os.Stderr, "handled %v, skipped %v\n", len(insns), skipped)
}

File diff suppressed because it is too large Load Diff

View File

@ -102,6 +102,8 @@ func (w *writer) do(v reflect.Value, sliceElem bool) {
fmt.Fprintf(w.w, "%v", v.Uint())
case reflect.String:
fmt.Fprintf(w.w, "%q", v.String())
case reflect.Func:
// Skip, no way to serialize this.
default:
panic(fmt.Sprintf("unsupported type: %#v", v.Type().String()))
}
@ -159,6 +161,8 @@ func isDefaultValue(v reflect.Value) bool {
return v.Uint() == 0
case reflect.String:
return v.String() == ""
case reflect.Func:
return true
default:
return false
}