Add storeimm32 and storeimm64 syntax

These explicitly allow usage of storeimm32 and storeimm64 in the
assembler syntax. It will also warn you if you try to store a value
that's too large using the storeimm32 instruction

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-10 18:59:23 -05:00
parent 15423502f3
commit 0ea3406b71
4 changed files with 29 additions and 7 deletions

View File

@@ -203,6 +203,22 @@ impl<'a> Assemble<'a> {
} }
} }
.r1(*r1), .r1(*r1),
Inst::StoreImm32(r1, imm) => {
let imm = self.get_value(imm).expect("TODO : value label not found");
let imm_truncated = (imm & 0xFFFFFFFF) as u32;
// TODO compile-time warnings
if imm != (imm_truncated as u64) {
eprintln!(
"WARNING: immediate 32 bit value being truncated ({:#x} to {:#x})",
imm, imm_truncated
)
}
builder.op(STOREIMM32).imm32(imm_truncated).r1(*r1)
}
Inst::StoreImm64(r1, imm) => {
let imm = self.get_value(imm).expect("TODO : value label not found");
builder.op(STOREIMM64).imm64(imm).r1(*r1)
}
Inst::MemCopy(r1, r2) => builder.op(MEMCOPY).r1(*r1).r2(*r2), Inst::MemCopy(r1, r2) => builder.op(MEMCOPY).r1(*r1).r2(*r2),
Inst::RegCopy(r1, r2) => builder.op(REGCOPY).r1(*r1).r2(*r2), Inst::RegCopy(r1, r2) => builder.op(REGCOPY).r1(*r1).r2(*r2),
Inst::Nop => builder.op(NOP), Inst::Nop => builder.op(NOP),

View File

@@ -59,6 +59,8 @@ pub enum Inst {
Load(Reg, Reg), Load(Reg, Reg),
Store(Reg, Reg), Store(Reg, Reg),
StoreImm(Reg, ImmValue), StoreImm(Reg, ImmValue),
StoreImm32(Reg, ImmValue),
StoreImm64(Reg, ImmValue),
MemCopy(Reg, Reg), MemCopy(Reg, Reg),
RegCopy(Reg, Reg), RegCopy(Reg, Reg),
@@ -101,6 +103,8 @@ impl Inst {
STOREIMM64 STOREIMM64
} }
} }
Inst::StoreImm32(_, _) => STOREIMM32,
Inst::StoreImm64(_, _) => STOREIMM64,
Inst::MemCopy(_, _) => MEMCOPY, Inst::MemCopy(_, _) => MEMCOPY,
Inst::RegCopy(_, _) => REGCOPY, Inst::RegCopy(_, _) => REGCOPY,

View File

@@ -59,6 +59,8 @@ Inst: Inst = {
"load" <d:Reg> "," <s:Reg> => Inst::Load(d, s), "load" <d:Reg> "," <s:Reg> => Inst::Load(d, s),
"store" <d:Reg> "," <s:Reg> => Inst::Store(d, s), "store" <d:Reg> "," <s:Reg> => Inst::Store(d, s),
"storeimm" <d:Reg> "," <s:ImmValue> => Inst::StoreImm(d, s), "storeimm" <d:Reg> "," <s:ImmValue> => Inst::StoreImm(d, s),
"storeimm32" <d:Reg> "," <s:ImmValue> => Inst::StoreImm32(d, s),
"storeimm64" <d:Reg> "," <s:ImmValue> => Inst::StoreImm64(d, s),
"memcopy" <d:Reg> "," <s:Reg> => Inst::MemCopy(d, s), "memcopy" <d:Reg> "," <s:Reg> => Inst::MemCopy(d, s),
"regcopy" <d:Reg> "," <s:Reg> => Inst::RegCopy(d, s), "regcopy" <d:Reg> "," <s:Reg> => Inst::RegCopy(d, s),
"nop" => Inst::Nop, "nop" => Inst::Nop,

View File

@@ -1,25 +1,25 @@
code $0x0 { code $0x0 {
main: main:
storeimm %r00, $0xDEAD storeimm32 %r00, $0xDEAD
storeimm %r01, $16 storeimm64 %r01, $16
shl %r00, %r01 shl %r00, %r01
storeimm %r01, $0xBEEF storeimm32 %r01, $0xBEEF
or %r00, %r01 or %r00, %r01
storeimm %r01, $0xDEADBEEF storeimm64 %r01, $0xDEADBEEF
cmpeq %r00, %r01 cmpeq %r00, %r01
storeimm %r00, failure storeimm32 %r00, failure
storeimm %r01, ok storeimm64 %r01, ok
jz %r00 jz %r00
jmp %r01 jmp %r01
failure: failure:
storeimm %status, $1 storeimm32 %status, $1
ok: halt ok: halt