ytab.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package x86
  5. // argListMax specifies upper arg count limit expected to be carried by obj.Prog.
  6. // Max len(obj.Prog.RestArgs) can be inferred from this to be 4.
  7. const argListMax int = 6
  8. type argList [argListMax]uint8
  9. type ytab struct {
  10. zcase uint8
  11. zoffset uint8
  12. // Last arg is usually destination.
  13. // For unary instructions unaryDst is used to determine
  14. // if single argument is a source or destination.
  15. args argList
  16. }
  17. // Returns true if yt is compatible with args.
  18. //
  19. // Elements from args and yt.args are used
  20. // to index ycover table like `ycover[args[i]+yt.args[i]]`.
  21. // This means that args should contain values that already
  22. // multiplied by Ymax.
  23. func (yt *ytab) match(args []int) bool {
  24. // Trailing Yxxx check is required to avoid a case
  25. // where shorter arg list is matched.
  26. // If we had exact yt.args length, it could be `yt.argc != len(args)`.
  27. if len(args) < len(yt.args) && yt.args[len(args)] != Yxxx {
  28. return false
  29. }
  30. for i := range args {
  31. if ycover[args[i]+int(yt.args[i])] == 0 {
  32. return false
  33. }
  34. }
  35. return true
  36. }