Add validAsType 'static' typeclass function

This commit is contained in:
Peter Rugg
2019-03-19 18:00:54 +00:00
parent aaa150091f
commit 9524138c09
2 changed files with 10 additions and 0 deletions

View File

@@ -830,6 +830,7 @@ instance CHERICap #(CapMem, 18, 64);
function nullWithAddr = error("feature not implemented for this cap type");
function almightyCap = error("feature not implemented for this cap type");
function nullCap = error("feature not implemented for this cap type");
function validAsType = error("feature not implemented for this cap type");
endinstance
instance CHERICap #(CapReg, 18, 64);
@@ -854,6 +855,7 @@ instance CHERICap #(CapReg, 18, 64);
function nullWithAddr = error("feature not implemented for this cap type");
function almightyCap = defaultCapFat;
function nullCap = null_cap;
function validAsType = error("feature not implemented for this cap type");
endinstance
instance CHERICap #(CapPipe, 18, 64);
@@ -978,6 +980,11 @@ instance CHERICap #(CapPipe, 18, 64);
function nullCap = CapPipe { capFat: nullCap, tempFields: getTempFields(nullCap) };
function Bool validAsType (CapPipe dummy, Bit#(64) checkType);
UInt#(64) checkTypeUnsigned = unpack(checkType);
UInt#(64) otypeMaxUnsigned = unpack(zeroExtend(otype_max));
return checkTypeUnsigned <= otypeMaxUnsigned;
endfunction
endinstance
instance Cast#(CapMem, CapReg);

View File

@@ -151,6 +151,9 @@ typeclass CHERICap#(type t, numeric type ot, numeric type n)
// Return the null capability
function t nullCap;
// Check if a type is valid
function Bool validAsType (t dummy, Bit#(n) checkType);
endtypeclass
function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, n));