arch_amd64.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. "unsafe"
  19. "github.com/twitchyliquid64/golang-asm/asm/arch"
  20. "github.com/twitchyliquid64/golang-asm/obj"
  21. )
  22. var (
  23. _AC = arch.Set("amd64")
  24. )
  25. func As(op string) obj.As {
  26. if ret, ok := _AC.Instructions[op]; ok {
  27. return ret
  28. } else {
  29. panic("invalid instruction: " + op)
  30. }
  31. }
  32. func ImmPtr(imm unsafe.Pointer) obj.Addr {
  33. return obj.Addr {
  34. Type : obj.TYPE_CONST,
  35. Offset : int64(uintptr(imm)),
  36. }
  37. }
  38. func Imm(imm int64) obj.Addr {
  39. return obj.Addr {
  40. Type : obj.TYPE_CONST,
  41. Offset : imm,
  42. }
  43. }
  44. func Reg(reg string) obj.Addr {
  45. if ret, ok := _AC.Register[reg]; ok {
  46. return obj.Addr{Reg: ret, Type: obj.TYPE_REG}
  47. } else {
  48. panic("invalid register name: " + reg)
  49. }
  50. }
  51. func Ptr(reg obj.Addr, offs int64) obj.Addr {
  52. return obj.Addr {
  53. Reg : reg.Reg,
  54. Type : obj.TYPE_MEM,
  55. Offset : offs,
  56. }
  57. }
  58. func Sib(reg obj.Addr, idx obj.Addr, scale int16, offs int64) obj.Addr {
  59. return obj.Addr {
  60. Reg : reg.Reg,
  61. Index : idx.Reg,
  62. Scale : scale,
  63. Type : obj.TYPE_MEM,
  64. Offset : offs,
  65. }
  66. }