Workaround for default typeclass function definitions

This commit is contained in:
Peter Rugg
2020-04-23 15:44:25 +01:00
parent 80ba19db9f
commit a5f3c776c7
2 changed files with 11 additions and 8 deletions

View File

@@ -904,7 +904,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function setBoundsCombined = error("feature not implemented for this cap type"); function setBoundsCombined = error("feature not implemented for this cap type");
function nullWithAddr = error("feature not implemented for this cap type"); function nullWithAddr = error("feature not implemented for this cap type");
function almightyCap = 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 nullCapFromDummy = error("feature not implemented for this cap type");
function validAsType = error("feature not implemented for this cap type"); function validAsType = error("feature not implemented for this cap type");
function fromMem = error("feature not implemented for this cap type"); function fromMem = error("feature not implemented for this cap type");
function toMem = error("feature not implemented for this cap type"); function toMem = error("feature not implemented for this cap type");
@@ -1030,7 +1030,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function almightyCap = defaultCapFat; function almightyCap = defaultCapFat;
function nullCap = null_cap; function nullCapFromDummy (x) = null_cap;
function Bool validAsType (CapReg dummy, Bit#(CapAddressW) checkType); function Bool validAsType (CapReg dummy, Bit#(CapAddressW) checkType);
UInt#(CapAddressW) checkTypeUnsigned = unpack(checkType); UInt#(CapAddressW) checkTypeUnsigned = unpack(checkType);
@@ -1120,7 +1120,7 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
return CapPipe {capFat: res, tempFields: getTempFields(res)}; return CapPipe {capFat: res, tempFields: getTempFields(res)};
endfunction endfunction
function nullCap; function nullCapFromDummy (x);
CapReg res = nullCap; CapReg res = nullCap;
return CapPipe {capFat: res, tempFields: getTempFields(res)}; return CapPipe {capFat: res, tempFields: getTempFields(res)};
endfunction endfunction

View File

@@ -170,10 +170,13 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n
// Returns a null cap with an address set to the argument // Returns a null cap with an address set to the argument
function t nullWithAddr (Bit#(n) addr); function t nullWithAddr (Bit#(n) addr);
// Workaround to allow null cap to be derived in default implementations
function t nullCapFromDummy(t dummy);
// Return the maximally permissive capability (initial register state) // Return the maximally permissive capability (initial register state)
function t almightyCap; function t almightyCap;
// Return the null capability // Return the null capability
function t nullCap; function t nullCap = nullCapFromDummy(?);
// Check if a type is valid // Check if a type is valid
function Bool validAsType (t dummy, Bit#(n) checkType); function Bool validAsType (t dummy, Bit#(n) checkType);
@@ -196,12 +199,12 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n
// TODO the following do not compile due to "not enough explicit type information" // TODO the following do not compile due to "not enough explicit type information"
// Get representable alignment mask // Get representable alignment mask
// function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request) = function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request) =
// setBoundsCombined(nullCap, length_request).mask; setBoundsCombined(nullCapFromDummy(dummy), length_request).mask;
// Get representable length // Get representable length
// function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request) = function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request) =
// setBoundsCombined(nullCap, length_request).length; setBoundsCombined(nullCapFromDummy(dummy), length_request).length;
// Assert that the encoding is valid // Assert that the encoding is valid
function Bool isDerivable (t cap); function Bool isDerivable (t cap);