arch_amd64.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2021 ByteDance Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package jit
  17. import (
  18. `github.com/twitchyliquid64/golang-asm/asm/arch`
  19. `github.com/twitchyliquid64/golang-asm/obj`
  20. )
  21. var (
  22. _AC = arch.Set("amd64")
  23. )
  24. func As(op string) obj.As {
  25. if ret, ok := _AC.Instructions[op]; ok {
  26. return ret
  27. } else {
  28. panic("invalid instruction: " + op)
  29. }
  30. }
  31. func Imm(imm int64) obj.Addr {
  32. return obj.Addr {
  33. Type : obj.TYPE_CONST,
  34. Offset : imm,
  35. }
  36. }
  37. func Reg(reg string) obj.Addr {
  38. if ret, ok := _AC.Register[reg]; ok {
  39. return obj.Addr{Reg: ret, Type: obj.TYPE_REG}
  40. } else {
  41. panic("invalid register name: " + reg)
  42. }
  43. }
  44. func Ptr(reg obj.Addr, offs int64) obj.Addr {
  45. return obj.Addr {
  46. Reg : reg.Reg,
  47. Type : obj.TYPE_MEM,
  48. Offset : offs,
  49. }
  50. }
  51. func Sib(reg obj.Addr, idx obj.Addr, scale int16, offs int64) obj.Addr {
  52. return obj.Addr {
  53. Reg : reg.Reg,
  54. Index : idx.Reg,
  55. Scale : scale,
  56. Type : obj.TYPE_MEM,
  57. Offset : offs,
  58. }
  59. }