...
1
2
3
4
5 package x86csv
6
7 import (
8 "encoding/csv"
9 "io"
10 )
11
12
13 type Reader struct {
14 csv *csv.Reader
15 }
16
17
18
19 func NewReader(r io.Reader) *Reader {
20 rcsv := csv.NewReader(r)
21 rcsv.Comment = '#'
22 return &Reader{csv: rcsv}
23 }
24
25
26
27
28
29
30
31
32
33 func (r *Reader) ReadAll() ([]*Inst, error) {
34 var err error
35 var insts []*Inst
36 for inst, err := r.Read(); err == nil; inst, err = r.Read() {
37 insts = append(insts, inst)
38 }
39 if err == io.EOF {
40 return insts, nil
41 }
42 return insts, err
43 }
44
45
46
47 func (r *Reader) Read() (*Inst, error) {
48 cols, err := r.csv.Read()
49 if err != nil {
50 return nil, err
51 }
52
53
54
55 inst := &Inst{
56 Intel: cols[0],
57 Go: cols[1],
58 GNU: cols[2],
59 Encoding: cols[3],
60 Mode32: cols[4],
61 Mode64: cols[5],
62 CPUID: cols[6],
63 Tags: cols[7],
64 Action: cols[8],
65 Multisize: cols[9],
66 DataSize: cols[10],
67 }
68 return inst, nil
69 }
70
View as plain text