-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharch.py
More file actions
110 lines (91 loc) · 2.96 KB
/
Copy patharch.py
File metadata and controls
110 lines (91 loc) · 2.96 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from typing import Optional
from dataclasses import dataclass, field
from .ir import *
@dataclass
class Component:
name: str
# Common interpretation of an argument: `$(<part>).*`
# e.g. `pc.read`, `pc.write`, `kind.float`, `kind.mem.read`
attributes: list[str] # = field(default_factory=list)
@dataclass
class Snippet:
name: str
seq: StatementSeq
@dataclass
class Operation(Component):
inputs: list[int]
outputs: list[int]
semantic_base: Optional[str] = None
semantic_func: Optional[str] = None # Snippet
semantic_func_128: Optional[str] = None # Snippet
semantic_table: Optional[str] = None # TableInt
def __eq__(self, other):
if not isinstance(other, Operation):
return NotImplemented
return (self.name, self.attributes, self.inputs, self.outputs,
self.semantic_base, self.semantic_func,
self.semantic_func_128, self.semantic_table) == \
(other.name, other.attributes, other.inputs, other.outputs,
other.semantic_base, other.semantic_func,
other.semantic_func_128, other.semantic_table)
@dataclass
class Register(Component):
def __init__(self, name, attributes: list[str] = []):
super().__init__(name=name, attributes=attributes)
@dataclass
class RegisterFile(Component):
reg_size: Shape
regs: list[Register]
def reg_names(self) -> list[str]:
return [r.name for r in self.regs]
def regs_num(self) -> int:
return len(self.regs)
@dataclass
class EnvironmentFunction(Component):
inputs: list[int]
outputs: list[int]
@dataclass
class SystemRegisterField(Component):
lsb: int
msb: int
@dataclass
class SystemRegister(Component):
size: int
fields: list[SystemRegisterField]
@dataclass
class TableInt(Component):
values: list[int]
@dataclass
class InstructionEncoding:
encoded_size: int
# Used to reuse same encode/constraint_decode for multiple instructions
const_encoding_part: int
const_mask: int
# `[encoding_size -> operand_size]`
decode: list[str] # Snippet
# `[operand_size] -> encoding_size`
encode: str # Snippet
# `[encoding_size -> 1]`
constraint_decode: str # Snippet
# `[operand_size] -> 1`
constraint_encode: str # Snippet
@dataclass
class Instruction(Component):
operand_sizes: list[int]
operand_names: list[str]
encoding: InstructionEncoding
# disassemble is relatively simple, but defining assembling...
# syntax: InstructionSyntax
semantic: StatementSeq
@dataclass
class Arch(Component):
# Constant Architecture part
register_files: list[RegisterFile]
system_registers: list[SystemRegister]
environment_functions: list[EnvironmentFunction]
# Variable Architecture part
# Same architecture can be defined with different instruction grouping
tables_int: list[TableInt]
operations: list[Operation]
snippets: list[Snippet]
instructions: list[Instruction]