Nico Weber | 8a95329 | 2018-05-15 16:30:30 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cpp -----------------===// |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "PipSqueak.h" |
Frederich Munch | d0c0700 | 2017-04-27 17:33:50 +0000 | [diff] [blame] | 10 | |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 11 | struct Global { |
| 12 | std::string *Str; |
Frederich Munch | ad12580 | 2017-06-05 16:26:58 +0000 | [diff] [blame] | 13 | std::vector<std::string> *Vec; |
| 14 | Global() : Str(nullptr), Vec(nullptr) {} |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 15 | ~Global() { |
Frederich Munch | ad12580 | 2017-06-05 16:26:58 +0000 | [diff] [blame] | 16 | if (Str) { |
| 17 | if (Vec) |
| 18 | Vec->push_back(*Str); |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 19 | *Str = "Global::~Global"; |
Frederich Munch | ad12580 | 2017-06-05 16:26:58 +0000 | [diff] [blame] | 20 | } |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 21 | } |
| 22 | }; |
| 23 | |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 24 | static Global Glb; |
| 25 | |
Frederich Munch | ad12580 | 2017-06-05 16:26:58 +0000 | [diff] [blame] | 26 | struct Local { |
| 27 | std::string &Str; |
| 28 | Local(std::string &S) : Str(S) { |
| 29 | Str = "Local::Local"; |
| 30 | if (Glb.Str && !Glb.Str->empty()) |
| 31 | Str += std::string("(") + *Glb.Str + std::string(")"); |
| 32 | } |
| 33 | ~Local() { Str = "Local::~Local"; } |
| 34 | }; |
| 35 | |
| 36 | |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 37 | extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr, |
| 38 | std::string &LStr) { |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 39 | Glb.Str = &GStr; |
Frederich Munch | ad12580 | 2017-06-05 16:26:58 +0000 | [diff] [blame] | 40 | static Local Lcl(LStr); |
| 41 | } |
| 42 | |
| 43 | extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) { |
| 44 | Glb.Vec = &V; |
Frederich Munch | c1db8cf | 2017-04-27 16:55:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Frederich Munch | 6391c7e | 2017-06-13 19:05:24 +0000 | [diff] [blame] | 47 | #define PIPSQUEAK_TESTA_RETURN "LibCall" |
Nico Weber | 8a95329 | 2018-05-15 16:30:30 +0000 | [diff] [blame] | 48 | #include "ExportedFuncs.cpp" |