diff --git a/core/src/main/java/org/lflang/pretvm/instruction/ADD.java b/core/src/main/java/org/lflang/pretvm/instruction/ADD.java index 6ef712815f..f82342d008 100644 --- a/core/src/main/java/org/lflang/pretvm/instruction/ADD.java +++ b/core/src/main/java/org/lflang/pretvm/instruction/ADD.java @@ -1,6 +1,5 @@ package org.lflang.pretvm.instruction; -import java.util.Objects; import org.lflang.pretvm.register.Register; /** @@ -11,7 +10,6 @@ public class ADD extends Instruction { public ADD(Register target, Register source, Register source2) { - this.opcode = Opcode.ADD; this.operand1 = target; this.operand2 = source; this.operand3 = source2; @@ -22,18 +20,6 @@ public Instruction clone() { return new ADD(this.operand1, this.operand2, this.operand3); } - @Override - public boolean equals(Object inst) { - if (inst instanceof ADD that) { - if (Objects.equals(this.operand1, that.operand1) - && Objects.equals(this.operand2, that.operand2) - && Objects.equals(this.operand3, that.operand3)) { - return true; - } - } - return false; - } - @Override public String toString() { return "Increment " + this.operand1 + " by adding " + this.operand2 + " and " + this.operand3; diff --git a/core/src/main/java/org/lflang/pretvm/instruction/Instruction.java b/core/src/main/java/org/lflang/pretvm/instruction/Instruction.java index e6a04fcb4a..2eb64a6a53 100644 --- a/core/src/main/java/org/lflang/pretvm/instruction/Instruction.java +++ b/core/src/main/java/org/lflang/pretvm/instruction/Instruction.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import org.lflang.pretvm.Label; import org.lflang.pretvm.dag.Node; @@ -13,63 +14,9 @@ */ public abstract class Instruction { - /** - * PretVM Instruction Set - * - *

ADD rs1, rs2, rs3 : Add to an integer variable (rs2) by an integer variable (rs3) and store - * the result in a destination variable (rs1). - * - *

ADDI rs1, rs2, rs3 : Add to an integer variable (rs2) by an immediate (rs3) and store the - * result in a destination variable (rs1). - * - *

BEQ rs1, rs2, rs3 : Take the branch (rs3) if rs1 is equal to rs2. - * - *

BGE rs1, rs2, rs3 : Take the branch (rs3) if rs1 is greater than or equal to rs2. - * - *

BLT rs1, rs2, rs3 : Take the branch (rs3) if rs1 is less than rs2. - * - *

BNE rs1, rs2, rs3 : Take the branch (rs3) if rs1 is not equal to rs2. - * - *

DU rs1, rs2 : Delay Until a physical timepoint (rs1) plus an offset (rs2) is reached. - * - *

EXE rs1 : EXEcute a reaction (rs1) (used for known triggers such as startup, shutdown, and - * timers). - * - *

JAL rs1 rs2 : Store the return address to rs1 and jump to a label (rs2). - * - *

JALR rs1, rs2, rs3 : Store the return address in destination (rs1) and jump to baseAddr - * (rs2) + immediate (rs3) - * - *

STP : SToP the execution. - * - *

WLT rs1, rs2 : Wait until a variable (rs1) owned by a worker (rs2) to be less than a desired - * value (rs3). - * - *

WU rs1, rs2 : Wait Until a variable (rs1) owned by a worker (rs2) to be greater than or - * equal to a desired value (rs3). - */ - public enum Opcode { - ADD, - ADDI, - BEQ, - BGE, - BLT, - BNE, - DU, - EXE, - JAL, - JALR, - STP, - WLT, - WU, - } - ////////////////////////////////////////////////////////////////////// /// Protected Variables - /** Opcode of this instruction */ - protected Opcode opcode; - /** The first operand */ protected T1 operand1; @@ -127,6 +74,20 @@ public void addNode(Node node) { this.nodes.add(node); } + @Override + public boolean equals(Object o) { + if (o instanceof Instruction that + // Check if instructions are the same. + && this.getClass() == that.getClass() + // Check if operands are the same. + && (Objects.equals(this.operand1, that.operand1) + && Objects.equals(this.operand2, that.operand2) + && Objects.equals(this.operand3, that.operand3))) { + return true; + } + return false; + } + /** Return the first label. */ public Label getLabel() { if (this.label.isEmpty()) return null; @@ -158,11 +119,6 @@ public List getNodes() { return this.nodes; } - /** Getter of the opcode */ - public Opcode getOpcode() { - return this.opcode; - } - /** * Getter for the first operand * @@ -236,7 +192,7 @@ public void setWorker(int worker) { @Override public String toString() { - return opcode.toString() + return this.getClass() + " " + operand1.toString() + " "