1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #include <cmajor/symbols/FunctionIndex.hpp>
 7 #include <cmajor/symbols/Module.hpp>
 8 #include <cmajor/symbols/FunctionSymbol.hpp>
 9 #include <cmajor/cmdebug/DebugInfoIo.hpp>
10 #include <soulng/util/Unicode.hpp>
11 
12 namespace cmajor { namespace symbols {
13 
14 using namespace soulng::unicode;
15 
16 FunctionIndex::FunctionIndex(Module* module_) : module(module_)mainFunctionId(boost::uuids::nil_uuid())
17 {
18 }
19 
20 void FunctionIndex::AddFunction(const boost::uuids::uuid& functionIdFunctionSymbol* functionSymbol)
21 {
22     std::lock_guard<std::recursive_mutex> lock(module->GetLock());
23     if (functionMap.find(functionId) == functionMap.cend())
24     {
25         functionMap[functionId] = functionSymbol;
26     }
27 }
28 
29 void FunctionIndex::SetMainFunctionId(const boost::uuids::uuid& functionId)
30 {
31     mainFunctionId = functionId;
32 }
33 
34 void FunctionIndex::Write(BinaryWriter& writer)
35 {
36     int32_t numFunctions = functionMap.size();
37     cmajor::debug::WriteNumberOfFunctionIndexFunctionRecords(writernumFunctions);
38     for (const auto& p : functionMap)
39     {
40         FunctionSymbol* functionSymbol = p.second;
41         cmajor::debug::WriteFunctionIndexFunctionRecord(writerp.firstToUtf8(functionSymbol->FullName())ToUtf8(functionSymbol->MangledName()));
42     }
43 }
44 
45 } } // namespace cmajor::symbols