File: instruction.go

package info (click to toggle)
golang-golang-x-arch 0.0~git20201207.1e68675-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,724 kB
  • sloc: ansic: 1,832; makefile: 42
file content (64 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"strings"

	"golang.org/x/arch/x86/xeddata"
)

// argument is a describes single instruction operand properties.
type argument struct {
	// ytype is argument class as returned by asm6 "oclass" function.
	ytype string

	// zkind is a partial Z-case matcher.
	// Determines which Z-case handles the encoding of instruction.
	zkind string
}

// instruction is decoded XED instruction.
// Used to produce ytabs and optabs in later phases.
type instruction struct {
	// opcode is instruction symbolic name.
	opcode string

	pset xeddata.PatternSet
	enc  *encoding

	// mask is EVEX K-register argument; points to args element.
	// Used to emit Yk0+Yknot0 table entries.
	// Nil for VEX-encoded insts.
	mask *argument
	args []*argument

	// zform is a pattern that determines which encoder Z-case is used.
	// We store zform instead of zcase directly because it's further
	// expanded during optabs generation.
	zform string
}

// String returns short inst printed representation.
func (inst *instruction) String() string { return inst.opcode }

// YtypeListString joins each argument Y-type and returns the result.
func (inst *instruction) YtypeListString() string {
	var parts []string
	for _, arg := range inst.args {
		parts = append(parts, arg.ytype)
	}
	return strings.Join(parts, " ")
}

// ArgIndexByZkind returns first argument matching given zkind or -1.
func (inst *instruction) ArgIndexByZkind(zkind string) int {
	for i, arg := range inst.args {
		if arg.zkind == zkind {
			return i
		}
	}
	return -1
}