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