//--- // fxos.semantics: Analyzed data types and locations (OS semantics) //--- #ifndef LIBFXOS_SEMANTICS_H #define LIBFXOS_SEMANTICS_H #include namespace FxOS { //--- // Data type representation // // The abstract interpreter supports the following data types when analyzing // data movement and access: // Integers i8 u8 i16 u16 i32 u32 (regs, mem) // Bit fields over ints T { } (mem) //--- class DataType { public: enum DataKind { /* Base types */ Integral, /* Bit fields over integers */ BitField, /* Structures (can only reside in memory) */ Struct, /* Arrays (can only reside in memory) */ Array, }; /* Type kind */ DataKind kind; /* Type size in bytes, as would be returned by sizeof(). Must be 1, 2 or 4 for integral types and bit fields. Might be 0 for arrays if the size of the array is unknown */ uint16_t size; /* Type alignment, can only be 1, 2 or 4 */ uint16_t align; /* Type of fields in bit fields */ using Field = std::pair; union { /* For integer types of size 1, whether to display as char (might be extended to more attributes later) */ bool ischar; /* For array types, number of elements (0 if unknown or variable-size NUL-terminated strings) */ int elements; }; /* The following members are not in the union because they have non- trivial destructors/copy and I don't want to care. */ /* For bit field types */ std::vector fields; /* For struct types */ std::vector attributes; }; //--- // Location representation // // The abstract interpreter keeps track of data stored at the following // locations (attribute types in parentheses): // Registers .reg (CpuRegister) // Memory .addr (uint32_t) // MappedModule .addr (uint32_t) //--- struct Location { enum LocationType { /* CPU-held registers accessed with instructions */ Register, /* Standard randomly-addressable memory */ Memory, /* Memory-mapped module registers with specific access */ MappedModule, }; LocationType location; union { /* For registers: register identifier */ CpuRegister reg; /* For memory and mapped modules: addresses */ uint32_t addr; }; /* String representation */ std::string str() const noexcept; }; } /* namespace FxOS */ #endif /* LIBFXOS_SEMANTICS_H */