Skip to content

Commit

Permalink
Add TIME opcode (#89)
Browse files Browse the repository at this point in the history
Closes #88
  • Loading branch information
vlopes11 authored Aug 3, 2022
1 parent 8a1b892 commit e28441f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
3 changes: 2 additions & 1 deletion fuel-asm/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ impl From<Instruction> for u32 {
| OpcodeRepr::SRW
| OpcodeRepr::SRWQ
| OpcodeRepr::SWW
| OpcodeRepr::SWWQ => a | b,
| OpcodeRepr::SWWQ
| OpcodeRepr::TIME => a | b,

OpcodeRepr::RET
| OpcodeRepr::ALOC
Expand Down
9 changes: 9 additions & 0 deletions fuel-asm/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ pub enum Opcode {
/// Store 32 bytes in contract storage.
SWWQ(RegisterId, RegisterId),

/// Get timestamp of block at given height.
TIME(RegisterId, RegisterId),

/// Transfer coins to a contract unconditionally.
TR(RegisterId, RegisterId, RegisterId),

Expand Down Expand Up @@ -364,6 +367,7 @@ impl Opcode {
OpcodeRepr::SRWQ => Opcode::SRWQ(ra, rb),
OpcodeRepr::SWW => Opcode::SWW(ra, rb),
OpcodeRepr::SWWQ => Opcode::SWWQ(ra, rb),
OpcodeRepr::TIME => Opcode::TIME(ra, rb),
OpcodeRepr::TR => Opcode::TR(ra, rb, rc),
OpcodeRepr::TRO => Opcode::TRO(ra, rb, rc, rd),
OpcodeRepr::ECR => Opcode::ECR(ra, rb, rc),
Expand Down Expand Up @@ -468,6 +472,7 @@ impl Opcode {
Self::SRWQ(ra, rb) => [Some(*ra), Some(*rb), None, None],
Self::SWW(ra, rb) => [Some(*ra), Some(*rb), None, None],
Self::SWWQ(ra, rb) => [Some(*ra), Some(*rb), None, None],
Self::TIME(ra, rb) => [Some(*ra), Some(*rb), None, None],
Self::TR(ra, rb, rc) => [Some(*ra), Some(*rb), Some(*rc), None],
Self::TRO(ra, rb, rc, rd) => [Some(*ra), Some(*rb), Some(*rc), Some(*rd)],
Self::ECR(ra, rb, rc) => [Some(*ra), Some(*rb), Some(*rc), None],
Expand Down Expand Up @@ -554,6 +559,7 @@ impl Opcode {
| Self::SRWQ(_, _)
| Self::SWW(_, _)
| Self::SWWQ(_, _)
| Self::TIME(_, _)
| Self::TR(_, _, _)
| Self::TRO(_, _, _, _)
| Self::ECR(_, _, _)
Expand Down Expand Up @@ -966,6 +972,9 @@ impl From<Opcode> for u32 {
Opcode::SWWQ(ra, rb) => {
((OpcodeRepr::SWWQ as u32) << 24) | ((ra as u32) << 18) | ((rb as u32) << 12)
}
Opcode::TIME(ra, rb) => {
((OpcodeRepr::TIME as u32) << 24) | ((ra as u32) << 18) | ((rb as u32) << 12)
}
Opcode::TR(ra, rb, rc) => {
((OpcodeRepr::TR as u32) << 24)
| ((ra as u32) << 18)
Expand Down
54 changes: 27 additions & 27 deletions fuel-asm/src/opcode/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub enum OpcodeRepr {
K256 = 0x3f,
/// S256
S256 = 0x40,
/// RESERV41
RESERV41 = 0x41,
/// TIME
TIME = 0x41,
/// RESERV42
RESERV42 = 0x42,
/// RESERV43
Expand Down Expand Up @@ -567,34 +567,34 @@ fn check_predicate_allowed() {

let should_allow = match repr {
BAL | BHEI | BHSH | BURN | CALL | CB | CCP | CROO | CSIZ | LDC | LOG | LOGD | MINT
| RETD | RVRT | SMO | SRW | SRWQ | SWW | SWWQ | TR | TRO => false,
| RETD | RVRT | SMO | SRW | SRWQ | SWW | SWWQ | TIME | TR | TRO => false,

RESERV00 | RESERV01 | RESERV02 | RESERV03 | RESERV04 | RESERV05 | RESERV06
| RESERV07 | RESERV08 | RESERV09 | RESERV0A | RESERV0B | RESERV0C | RESERV0D
| RESERV0E | RESERV0F | RESERV22 | RESERV23 | RESERV37 | RESERV41 | RESERV42
| RESERV43 | RESERV44 | RESERV45 | RESERV46 | RESERV4D | RESERV4E | RESERV4F
| RESERV62 | RESERV63 | RESERV64 | RESERV65 | RESERV66 | RESERV67 | RESERV68
| RESERV69 | RESERV6A | RESERV6B | RESERV6C | RESERV6D | RESERV6E | RESERV6F
| RESERV74 | RESERV75 | RESERV76 | RESERV77 | RESERV78 | RESERV79 | RESERV7A
| RESERV7B | RESERV7C | RESERV7D | RESERV7E | RESERV7F | RESERV80 | RESERV81
| RESERV82 | RESERV83 | RESERV84 | RESERV85 | RESERV86 | RESERV87 | RESERV88
| RESERV89 | RESERV8A | RESERV8B | RESERV8C | RESERV8D | RESERV8E | RESERV8F
| RESERV93 | RESERV94 | RESERV95 | RESERV96 | RESERV97 | RESERV98 | RESERV99
| RESERV9A | RESERV9B | RESERV9C | RESERV9D | RESERV9E | RESERV9F | RESERVA0
| RESERVA1 | RESERVA2 | RESERVA3 | RESERVA4 | RESERVA5 | RESERVA6 | RESERVA7
| RESERVA8 | RESERVA9 | RESERVAA | RESERVAB | RESERVAC | RESERVAD | RESERVAE
| RESERVAF | RESERVB0 | RESERVB1 | RESERVB2 | RESERVB3 | RESERVB4 | RESERVB5
| RESERVB6 | RESERVB7 | RESERVB8 | RESERVB9 | RESERVBA | RESERVBB | RESERVBC
| RESERVBD | RESERVBE | RESERVBF | RESERVC0 | RESERVC1 | RESERVC2 | RESERVC3
| RESERVC4 | RESERVC5 | RESERVC6 | RESERVC7 | RESERVC8 | RESERVC9 | RESERVCA
| RESERVCB | RESERVCC | RESERVCD | RESERVCE | RESERVCF | RESERVD0 | RESERVD1
| RESERVD2 | RESERVD3 | RESERVD4 | RESERVD5 | RESERVD6 | RESERVD7 | RESERVD8
| RESERVD9 | RESERVDA | RESERVDB | RESERVDC | RESERVDD | RESERVDE | RESERVDF
| RESERVE0 | RESERVE1 | RESERVE2 | RESERVE3 | RESERVE4 | RESERVE5 | RESERVE6
| RESERVE7 | RESERVE8 | RESERVE9 | RESERVEA | RESERVEB | RESERVEC | RESERVED
| RESERVEE | RESERVEF | RESERVF0 | RESERVF1 | RESERVF2 | RESERVF3 | RESERVF4
| RESERVF5 | RESERVF6 | RESERVF7 | RESERVF8 | RESERVF9 | RESERVFA | RESERVFB
| RESERVFC | RESERVFD | RESERVFE | RESERVFF => false,
| RESERV0E | RESERV0F | RESERV22 | RESERV23 | RESERV37 | RESERV42 | RESERV43
| RESERV44 | RESERV45 | RESERV46 | RESERV4D | RESERV4E | RESERV4F | RESERV62
| RESERV63 | RESERV64 | RESERV65 | RESERV66 | RESERV67 | RESERV68 | RESERV69
| RESERV6A | RESERV6B | RESERV6C | RESERV6D | RESERV6E | RESERV6F | RESERV74
| RESERV75 | RESERV76 | RESERV77 | RESERV78 | RESERV79 | RESERV7A | RESERV7B
| RESERV7C | RESERV7D | RESERV7E | RESERV7F | RESERV80 | RESERV81 | RESERV82
| RESERV83 | RESERV84 | RESERV85 | RESERV86 | RESERV87 | RESERV88 | RESERV89
| RESERV8A | RESERV8B | RESERV8C | RESERV8D | RESERV8E | RESERV8F | RESERV93
| RESERV94 | RESERV95 | RESERV96 | RESERV97 | RESERV98 | RESERV99 | RESERV9A
| RESERV9B | RESERV9C | RESERV9D | RESERV9E | RESERV9F | RESERVA0 | RESERVA1
| RESERVA2 | RESERVA3 | RESERVA4 | RESERVA5 | RESERVA6 | RESERVA7 | RESERVA8
| RESERVA9 | RESERVAA | RESERVAB | RESERVAC | RESERVAD | RESERVAE | RESERVAF
| RESERVB0 | RESERVB1 | RESERVB2 | RESERVB3 | RESERVB4 | RESERVB5 | RESERVB6
| RESERVB7 | RESERVB8 | RESERVB9 | RESERVBA | RESERVBB | RESERVBC | RESERVBD
| RESERVBE | RESERVBF | RESERVC0 | RESERVC1 | RESERVC2 | RESERVC3 | RESERVC4
| RESERVC5 | RESERVC6 | RESERVC7 | RESERVC8 | RESERVC9 | RESERVCA | RESERVCB
| RESERVCC | RESERVCD | RESERVCE | RESERVCF | RESERVD0 | RESERVD1 | RESERVD2
| RESERVD3 | RESERVD4 | RESERVD5 | RESERVD6 | RESERVD7 | RESERVD8 | RESERVD9
| RESERVDA | RESERVDB | RESERVDC | RESERVDD | RESERVDE | RESERVDF | RESERVE0
| RESERVE1 | RESERVE2 | RESERVE3 | RESERVE4 | RESERVE5 | RESERVE6 | RESERVE7
| RESERVE8 | RESERVE9 | RESERVEA | RESERVEB | RESERVEC | RESERVED | RESERVEE
| RESERVEF | RESERVF0 | RESERVF1 | RESERVF2 | RESERVF3 | RESERVF4 | RESERVF5
| RESERVF6 | RESERVF7 | RESERVF8 | RESERVF9 | RESERVFA | RESERVFB | RESERVFC
| RESERVFD | RESERVFE | RESERVFF => false,

_ => true,
};
Expand Down
1 change: 1 addition & 0 deletions fuel-asm/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn opcode() {
Opcode::SRWQ(r, r),
Opcode::SWW(r, r),
Opcode::SWWQ(r, r),
Opcode::TIME(r, r),
Opcode::TR(r, r, r),
Opcode::TRO(r, r, r, r),
Opcode::ECR(r, r, r),
Expand Down

0 comments on commit e28441f

Please sign in to comment.