Added a maximize objective API to DeepState.

This commit is contained in:
Peter Goodman
2017-12-10 13:37:47 -05:00
parent 188d4517d8
commit fcd000dc14
6 changed files with 68 additions and 15 deletions

View File

@@ -64,20 +64,39 @@ extern int8_t DeepState_Char(void);
extern uint32_t DeepState_MinUInt(uint32_t);
extern int32_t DeepState_MinInt(int32_t);
extern uint32_t DeepState_MaxUInt(uint32_t);
extern int32_t DeepState_MaxInt(int32_t);
DEEPSTATE_INLINE static uint16_t DeepState_MinUShort(uint16_t v) {
return DeepState_MinUInt(v);
}
DEEPSTATE_INLINE static uint8_t DeepState_MinUChar(uint8_t v) {
return DeepState_MinUInt(v);
return (uint8_t) DeepState_MinUInt(v);
}
DEEPSTATE_INLINE static int16_t DeepState_MinShort(int16_t v) {
return DeepState_MinInt(v);
return (int16_t) DeepState_MinInt(v);
}
DEEPSTATE_INLINE static int8_t DeepState_MinChar(int8_t v) {
return DeepState_MinInt(v);
return (int8_t) DeepState_MinInt(v);
}
DEEPSTATE_INLINE static uint16_t DeepState_MaxUShort(uint16_t v) {
return (uint16_t) DeepState_MaxUInt(v);
}
DEEPSTATE_INLINE static uint8_t DeepState_MaxUChar(uint8_t v) {
return (uint8_t) DeepState_MaxUInt(v);
}
DEEPSTATE_INLINE static int16_t DeepState_MaxShort(int16_t v) {
return (int16_t) DeepState_MaxInt(v);
}
DEEPSTATE_INLINE static int8_t DeepState_MaxChar(int8_t v) {
return (int8_t) DeepState_MaxInt(v);
}
/* Returns `1` if `expr` is true, and `0` otherwise. This is kind of an indirect

View File

@@ -258,6 +258,9 @@ using symbolic_uint64_t = Symbolic<uint64_t>;
#define MAKE_MINIMIZER(Type, type) \
DEEPSTATE_INLINE static type Minimize(type val) { \
return DeepState_Min ## Type(val); \
} \
DEEPSTATE_INLINE static type Maximize(type val) { \
return DeepState_Max ## Type(val); \
}
MAKE_MINIMIZER(UInt, uint32_t)

View File

@@ -204,9 +204,21 @@ uint32_t DeepState_MinUInt(uint32_t v) {
}
int32_t DeepState_MinInt(int32_t v) {
return (int32_t) (DeepState_MinUInt(((uint32_t) v) + 0x80000000U) -
0x80000000U);
}
/* Returns the maximum satisfiable value for a given symbolic value, given
* the constraints present on that value. */
uint32_t DeepState_MaxUInt(uint32_t v) {
return v;
}
int32_t DeepState_MaxInt(int32_t v) {
return (int32_t) (DeepState_MaxUInt(((uint32_t) v) + 0x80000000U) -
0x80000000U);
}
void _DeepState_Assume(int expr, const char *expr_str, const char *file,
unsigned line) {
if (!expr) {
@@ -263,7 +275,7 @@ const struct DeepState_IndexEntry DeepState_API[] = {
{"ConcretizeData", (void *) DeepState_ConcretizeData},
{"ConcretizeCStr", (void *) DeepState_ConcretizeCStr},
{"MinUInt", (void *) DeepState_MinUInt},
{"MinInt", (void *) DeepState_MinInt},
{"MaxUInt", (void *) DeepState_MaxUInt},
/* Logging API. */
{"Log", (void *) DeepState_Log},