1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_TYPE_HPP
7 #define SIMGRID_MC_TYPE_HPP
14 #include "xbt/asserts.h"
17 #include "src/mc/inspect/LocationList.hpp"
18 #include "src/mc/mc_forward.hpp"
23 /** A member of a structure, union
25 * Inheritance is seen as a special member as well.
29 typedef int flags_type;
30 static constexpr flags_type INHERITANCE_FLAG = 1;
31 static constexpr flags_type VIRTUAL_POINTER_FLAG = 2;
35 /** Whether this member represent some inherited part of the object */
38 /** Name of the member (if any) */
41 /** DWARF location expression for locating the location of the member */
42 simgrid::dwarf::DwarfExpression location_expression;
44 std::size_t byte_size = 0; // Do we really need this?
47 simgrid::mc::Type* type = nullptr;
49 bool isInheritance() const { return this->flags & INHERITANCE_FLAG; }
50 bool isVirtualPointer() const { return this->flags & VIRTUAL_POINTER_FLAG; }
52 /** Whether the member is at a fixed offset from the base address */
53 bool has_offset_location() const
55 // Recognize the expression `DW_OP_plus_uconst(offset)`:
56 return location_expression.size() == 1 && location_expression[0].atom == DW_OP_plus_uconst;
59 /** Get the offset of the member
61 * This is only valid is the member is at a fixed offset from the base.
62 * This is often the case (for C types, C++ type without virtual
65 * If the location is more complex, the location expression has
66 * to be evaluated (which might need accessing the memory).
70 xbt_assert(this->has_offset_location());
71 return this->location_expression[0].number;
74 /** Set the location of the member as a fixed offset */
75 void offset(int new_offset)
77 // Set the expression to be `DW_OP_plus_uconst(offset)`:
79 op.atom = DW_OP_plus_uconst;
80 op.number = new_offset;
81 this->location_expression = {op};
85 /** A type in the model-checked program */
90 /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
92 unsigned id = 0; /* Offset in the section (in hexadecimal form) */
93 std::string name; /* Name of the type */
94 int byte_size = 0; /* Size in bytes */
95 int element_count = 0; /* Number of elements for array type */
96 unsigned type_id = 0; /* DW_AT_type id */
97 std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
99 simgrid::mc::Type* subtype = nullptr; // DW_AT_type
100 simgrid::mc::Type* full_type = nullptr; // The same (but more complete) type
104 } // namespace simgrid