Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / mc / Type.hpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_TYPE_HPP
8 #define SIMGRID_MC_TYPE_HPP
9
10 #include <vector>
11 #include <string>
12
13 #include <xbt/base.h>
14
15 #include "src/mc/mc_forward.h"
16 #include "src/mc/LocationList.hpp"
17
18 namespace simgrid {
19 namespace mc {
20
21 /** A member of a structure, union
22  *
23  *  Inheritance is seen as a special member as well.
24  */
25 class Member {
26 public:
27   Member() {}
28
29   /** Whether this member represent some inherited part of the object */
30   bool inheritance = false;
31
32   /** Name of the member (if any) */
33   std::string name;
34
35   /** DWARF location expression for locating the location of the member */
36   simgrid::dwarf::DwarfExpression location_expression;
37
38   std::size_t byte_size = 0; // Do we really need this?
39
40   unsigned type_id = 0;
41   simgrid::mc::Type* type = nullptr;
42
43   /** Whether the member is at a fixed offset from the base address */
44   bool has_offset_location() const
45   {
46     // Recognize the expression `DW_OP_plus_uconst(offset)`:
47     return location_expression.size() == 1 &&
48       location_expression[0].atom == DW_OP_plus_uconst;
49   }
50
51   /** Get the offset of the member
52   *
53   *  This is only valid is the member is at a fixed offset from the base.
54   *  This is often the case (for C types, C++ type without virtual
55   *  inheritance).
56   *
57   *  If the location is more complex, the location expression has
58   *  to be evaluated (which might need accessing the memory).
59   */
60   int offset() const
61   {
62     xbt_assert(this->has_offset_location());
63     return this->location_expression[0].number;
64   }
65
66   /** Set the location of the member as a fixed offset */
67   void offset(int new_offset)
68   {
69     // Set the expression to be `DW_OP_plus_uconst(offset)`:
70     Dwarf_Op op;
71     op.atom = DW_OP_plus_uconst;
72     op.number = new_offset;
73     this->location_expression = { op };
74   }
75
76 };
77
78 /** A type in the model-checked program */
79 class Type {
80 public:
81   Type() {}
82
83   /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
84   int type = 0;
85   unsigned id = 0; /* Offset in the section (in hexadecimal form) */
86   std::string name; /* Name of the type */
87   int byte_size = 0; /* Size in bytes */
88   int element_count = 0; /* Number of elements for array type */
89   unsigned type_id = 0; /* DW_AT_type id */
90   std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
91
92   simgrid::mc::Type* subtype = nullptr; // DW_AT_type
93   simgrid::mc::Type* full_type = nullptr; // The same (but more complete) type
94 };
95
96 }
97 }
98
99 #endif