77 lines
3.0 KiB
C++
77 lines
3.0 KiB
C++
//---------------------------------------------------------------------------//
|
|
// 1100101 |_ mov #0, r4 __ //
|
|
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
|
|
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
|
|
// |_ base# + offset |_| /_\_\___/__/ //
|
|
//---------------------------------------------------------------------------//
|
|
// fxos/ai/AbstractDomain: Lattice-based domains for abstract interpretation
|
|
//
|
|
// No, this whole folder has nothing to do with Artifical Intelligence. This is
|
|
// Abstract Interpretation. You may have been bamboozled.
|
|
//
|
|
// This header defines the AbstractDomain typeclass which specifies the
|
|
// interface for lattices for abstract-interpretation-based passes. This is
|
|
// generic, but there are no plans for any other domain than RelConst.
|
|
//
|
|
// The interface assumes 32-bit values and assembler-like semantics.
|
|
//---
|
|
|
|
#ifndef FXOS_AI_ABSTRACTDOMAIN_H
|
|
#define FXOS_AI_ABSTRACTDOMAIN_H
|
|
|
|
#include <cstdint>
|
|
|
|
namespace FxOS {
|
|
|
|
/* An abstract domain over a lattice T modeling CPU operands. */
|
|
template<typename T>
|
|
class AbstractDomain
|
|
{
|
|
public:
|
|
/* Bottom and Top constants */
|
|
virtual T bottom() const noexcept = 0;
|
|
virtual T top() const noexcept = 0;
|
|
|
|
/* Construct abstract value from integer constant */
|
|
virtual T constant(uint32_t value) const noexcept = 0;
|
|
/* Check if value is constant */
|
|
virtual bool is_constant(T) const noexcept = 0;
|
|
/* Unpack a constant. May return anything if is_constant() is false */
|
|
virtual uint32_t constant_value(T) const noexcept = 0;
|
|
|
|
/* Basic arithmetic. Division and modulo are both non-trivial
|
|
instruction sequences usually isolated in easily-identifiable
|
|
subroutines, so we don't care about them. */
|
|
virtual T minus(T) const noexcept = 0;
|
|
virtual T add(T, T) const noexcept = 0;
|
|
virtual T sub(T, T) const noexcept = 0;
|
|
virtual T smul(T, T) const noexcept = 0;
|
|
virtual T umul(T, T) const noexcept = 0;
|
|
|
|
/* Sign extensions */
|
|
virtual T extub(T) const noexcept = 0;
|
|
virtual T extsb(T) const noexcept = 0;
|
|
virtual T extuw(T) const noexcept = 0;
|
|
virtual T extsw(T) const noexcept = 0;
|
|
|
|
/* Logical operations */
|
|
virtual T lnot(T) const noexcept = 0;
|
|
virtual T land(T, T) const noexcept = 0;
|
|
virtual T lor(T, T) const noexcept = 0;
|
|
virtual T lxor(T, T) const noexcept = 0;
|
|
|
|
/* Comparisons. This operation proceeds in two steps:
|
|
* First call cmp(x, y) to check if the values are comparable. If
|
|
this returns false, the test result should be Top.
|
|
* If the values are comparable, call cmpu(x, y) or cmps(x, y), which
|
|
returns a negative number if x < y, 0 if x == y, and a positive
|
|
number if x > y. */
|
|
virtual bool cmp(T, T) const noexcept = 0;
|
|
virtual int cmpu(T, T) const noexcept = 0;
|
|
virtual int cmps(T, T) const noexcept = 0;
|
|
};
|
|
|
|
} /* namespace FxOS */
|
|
|
|
#endif /* FXOS_AI_ABSTRACTDOMAIN_H */
|