OpcodeDescription is a humman readable string of the specific offset
(offset int)
| 244 | |
| 245 | // OpcodeDescription is a humman readable string of the specific offset |
| 246 | func (c *Code) OpcodeDescription(offset int) string { |
| 247 | buf := &bytes.Buffer{} |
| 248 | |
| 249 | op := InstOp(c.Codes[offset]) |
| 250 | fmt.Fprintf(buf, "%06d ", offset) |
| 251 | |
| 252 | if opcodeBacktracks(op & Mask) { |
| 253 | buf.WriteString("*") |
| 254 | } else { |
| 255 | buf.WriteString(" ") |
| 256 | } |
| 257 | buf.WriteString(operatorDescription(op)) |
| 258 | buf.WriteString("(") |
| 259 | op &= Mask |
| 260 | |
| 261 | switch op { |
| 262 | case One, Notone, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, |
| 263 | Oneloopatomic, Notoneloopatomic: |
| 264 | buf.WriteString("Ch = ") |
| 265 | buf.WriteString(CharDescription(rune(c.Codes[offset+1]))) |
| 266 | |
| 267 | case Set, Setrep, Setloop, Setlazy, Setloopatomic: |
| 268 | buf.WriteString("Set = ") |
| 269 | buf.WriteString(c.Sets[c.Codes[offset+1]].String()) |
| 270 | |
| 271 | case Multi: |
| 272 | fmt.Fprintf(buf, "String = %s", string(c.Strings[c.Codes[offset+1]])) |
| 273 | |
| 274 | case Ref, Testref: |
| 275 | fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) |
| 276 | |
| 277 | case Capturemark: |
| 278 | fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) |
| 279 | if c.Codes[offset+2] != -1 { |
| 280 | fmt.Fprintf(buf, ", Unindex = %d", c.Codes[offset+2]) |
| 281 | } |
| 282 | |
| 283 | case Nullcount, Setcount: |
| 284 | fmt.Fprintf(buf, "Value = %d", c.Codes[offset+1]) |
| 285 | |
| 286 | case Goto, Lazybranch, Branchmark, Lazybranchmark, Branchcount, Lazybranchcount: |
| 287 | fmt.Fprintf(buf, "Addr = %d", c.Codes[offset+1]) |
| 288 | } |
| 289 | |
| 290 | switch op { |
| 291 | case Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, Setrep, Setloop, Setlazy, |
| 292 | Oneloopatomic, Notoneloopatomic, Setloopatomic: |
| 293 | buf.WriteString(", Rep = ") |
| 294 | if c.Codes[offset+2] == math.MaxInt32 { |
| 295 | buf.WriteString("inf") |
| 296 | } else { |
| 297 | fmt.Fprintf(buf, "%d", c.Codes[offset+2]) |
| 298 | } |
| 299 | |
| 300 | case Branchcount, Lazybranchcount: |
| 301 | buf.WriteString(", Limit = ") |
| 302 | if c.Codes[offset+2] == math.MaxInt32 { |
| 303 | buf.WriteString("inf") |
no test coverage detected