summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pysc-v/InstructionSets/RV32I.py25
-rw-r--r--pysc-v/InstructionSets/instructions.py14
2 files changed, 34 insertions, 5 deletions
diff --git a/pysc-v/InstructionSets/RV32I.py b/pysc-v/InstructionSets/RV32I.py
index dcdee36..ab03bb7 100644
--- a/pysc-v/InstructionSets/RV32I.py
+++ b/pysc-v/InstructionSets/RV32I.py
@@ -65,6 +65,7 @@ class J(Instruction):
)
+@RV32I.instruction
class add(R):
name = "add"
opcode = 0b0110011
@@ -74,10 +75,32 @@ class add(R):
def execute(self):
return pc + self.size
+@RV32I.instruction
class addi(I):
name = "addi"
opcode = 0b0010011
funct3 = 0b000
+@RV32I.instruction
+class jal(J):
+ name = "jal"
+ opcode = 0b1101111
+
def execute(self):
- pass
+ # TODO
+ # - Save current pc in rd
+ # - Make pc from `imm`
+ # - Return new pc
+ return pc
+
+
+@RV32I.pseudoinstruction
+class j(J):
+ name = "j"
+ def __new__(cls, imm):
+ return jal("x0", imm)
+
+
+if __name__ == "__main__":
+ print(RV32I)
+ print(RV32I.instructions)
diff --git a/pysc-v/InstructionSets/instructions.py b/pysc-v/InstructionSets/instructions.py
index 5587f2e..625226a 100644
--- a/pysc-v/InstructionSets/instructions.py
+++ b/pysc-v/InstructionSets/instructions.py
@@ -16,12 +16,18 @@ class Instruction:
return
class InstructionSet:
+
def __init__(self, init=None):
- self.data = dict()
+ self.instructions = dict()
+
+ def instruction(self, ins):
+ if ins.name not in self.instructions:
+ self.instructions[ins.name] = ins
+ return ins
- def add_instruction(self, ins):
- if ins.name not in self.data:
- self.data[ins.name] = ins
+ # NOTE: We don't need to treat pseudoinstructions in an special way yet,
+ # but we separate the decorator for clarity
+ pseudoinstruction = instruction
if __name__ == "__main__":