Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove the argc/argv version of simcall_process_create
[simgrid.git] / src / mc / Type.hpp
1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_TYPE_HPP
7 #define SIMGRID_MC_TYPE_HPP
8
9 #include <cstddef>
10
11 #include <vector>
12 #include <string>
13
14 #include "xbt/asserts.h"
15 #include "xbt/base.h"
16
17 #include "src/mc/mc_forward.hpp"
18 #include "src/mc/LocationList.hpp"
19
20 namespace simgrid {
21 namespace mc {
22
23 /** A member of a structure, union
24  *
25  *  Inheritance is seen as a special member as well.
26  */
27 class Member {
28 public:
29   typedef int flags_type;
30   static constexpr flags_type INHERITANCE_FLAG = 1;
31   static constexpr flags_type VIRTUAL_POINTER_FLAG = 2;
32
33   Member() = default;
34
35   /** Whether this member represent some inherited part of the object */
36   flags_type flags = 0;
37
38   /** Name of the member (if any) */
39   std::string name;
40
41   /** DWARF location expression for locating the location of the member */
42   simgrid::dwarf::DwarfExpression location_expression;
43
44   std::size_t byte_size = 0; // Do we really need this?
45
46   unsigned type_id = 0;
47   simgrid::mc::Type* type = nullptr;
48
49   bool isInheritance() const
50   {
51     return this->flags & INHERITANCE_FLAG;
52   }
53   bool isVirtualPointer() const
54   {
55     return this->flags & VIRTUAL_POINTER_FLAG;
56   }
57
58   /** Whether the member is at a fixed offset from the base address */
59   bool has_offset_location() const
60   {
61     // Recognize the expression `DW_OP_plus_uconst(offset)`:
62     return location_expression.size() == 1 &&
63       location_expression[0].atom == DW_OP_plus_uconst;
64   }
65
66   /** Get the offset of the member
67   *
68   *  This is only valid is the member is at a fixed offset from the base.
69   *  This is often the case (for C types, C++ type without virtual
70   *  inheritance).
71   *
72   *  If the location is more complex, the location expression has
73   *  to be evaluated (which might need accessing the memory).
74   */
75   int offset() const
76   {
77     xbt_assert(this->has_offset_location());
78     return this->location_expression[0].number;
79   }
80
81   /** Set the location of the member as a fixed offset */
82   void offset(int new_offset)
83   {
84     // Set the expression to be `DW_OP_plus_uconst(offset)`:
85     Dwarf_Op op;
86     op.atom = DW_OP_plus_uconst;
87     op.number = new_offset;
88     this->location_expression = { op };
89   }
90
91 };
92
93 /** A type in the model-checked program */
94 class Type {
95 public:
96   Type() = default;
97
98   /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
99   int type = 0;
100   unsigned id = 0; /* Offset in the section (in hexadecimal form) */
101   std::string name; /* Name of the type */
102   int byte_size = 0; /* Size in bytes */
103   int element_count = 0; /* Number of elements for array type */
104   unsigned type_id = 0; /* DW_AT_type id */
105   std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
106
107   simgrid::mc::Type* subtype = nullptr; // DW_AT_type
108   simgrid::mc::Type* full_type = nullptr; // The same (but more complete) type
109 };
110
111 }
112 }
113
114 #endif