• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include "pw_tokenizer/tokenize.h"
17 
18 //
19 // Baseline data container structure.
20 //
21 // This structure is a container for data used to establish a baseline for size
22 // report diffs.
23 //
24 // The baseline contains one global instance of this structure. Other binaries
25 // should contain one global instance of a subclass of this structure, adding
26 // any data that should be a part of the size report diff.
27 //
28 // This structure may be used to load sections of code and data in order to
29 // establish a basline for size report diffs. This structure causes sections to
30 // be loaded by referencing symbols within those sections.
31 //
32 // Simple references to symbols can be optimized out if they don't have any
33 // external effects. The LoadData method uses functions and other symbols to
34 // generate and return a run-time value. In this way, the symbol references
35 // cannot be optimized out.
36 //
37 struct BaseContainer {
38   // Causes code and data sections to be loaded. Returns a generated value
39   // based on symbols in those sections to force them to be loaded. The caller
40   // should ensure that the return value has some external effect (e.g.,
41   // returning the value from the "main" function).
LoadDataBaseContainer42   virtual long LoadData() {
43     // Prevent this object and token from being optimized out.
44     return reinterpret_cast<long>(this) ^ base_token;
45   }
46 
47   // Destructor.
~BaseContainerBaseContainer48   virtual ~BaseContainer() {}
49 
50   // Reference the tokenizer.
51   uint32_t base_token = PW_TOKENIZE_STRING("base_token");
52 
53   // Explicit padding. If this structure is empty, the baseline will include
54   // padding that won't appear in subclasses, so the padding is explicitly
55   // added here so it appears in both the baseline and all subclasses.
56   char padding[4];
57 };
58