Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Mark some internal symbols as hidden on ELF in mc
[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 "mc_forward.h"
16 #include "mc_location.h"
17
18 namespace simgrid {
19 namespace mc {
20
21 /** Represents a type in the program
22  *
23  *  It is currently used to represent members of structs and unions as well.
24  */
25 class Type {
26 public:
27   Type();
28   Type(Type const& type) = default;
29   Type& operator=(Type const&) = default;
30   Type(Type&& type) = default;
31   Type& operator=(Type&&) = default;
32
33   /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
34   int type;
35   unsigned id; /* Offset in the section (in hexadecimal form) */
36   std::string name; /* Name of the type */
37   int byte_size; /* Size in bytes */
38   int element_count; /* Number of elements for array type */
39   unsigned type_id; /* DW_AT_type id */
40   std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
41   int is_pointer_type;
42
43   // Location (for members) is either of:
44   simgrid::mc::DwarfExpression location_expression;
45
46   simgrid::mc::Type* subtype; // DW_AT_type
47   simgrid::mc::Type* full_type; // The same (but more complete) type
48
49   bool has_offset_location() const
50   {
51     return location_expression.size() == 1 &&
52       location_expression[0].atom == DW_OP_plus_uconst;
53   }
54
55   // TODO, check if this shortcut is really necessary
56   int offset() const
57   {
58     xbt_assert(this->has_offset_location());
59     return this->location_expression[0].number;
60   }
61
62   void offset(int new_offset)
63   {
64     DwarfInstruction op;
65     op.atom = DW_OP_plus_uconst;
66     op.number = new_offset;
67     this->location_expression = { op };
68   }
69 };
70
71 inline
72 Type::Type()
73 {
74   this->type = 0;
75   this->id = 0;
76   this->byte_size = 0;
77   this->element_count = 0;
78   this->is_pointer_type = 0;
79   this->type_id = 0;
80   this->subtype = nullptr;
81   this->full_type = nullptr;
82 }
83
84 }
85 }
86
87 #endif