Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61f679e

Browse files
committed
Added toolchain.cpp
1 parent 33b4a4f commit 61f679e

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

buildcc/lib/toolchain/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
set(TOOLCHAIN_SRCS
2-
include/toolchain/toolchain.h
3-
4-
include/toolchain/common/file_ext.h
5-
2+
# COMMON
63
src/common/toolchain_config.cpp
74
include/toolchain/common/toolchain_config.h
5+
include/toolchain/common/file_ext.h
6+
include/toolchain/common/function_lock.h
7+
8+
# API
9+
include/toolchain/api/flag_api.h
10+
11+
src/toolchain/toolchain.cpp
12+
include/toolchain/toolchain.h
813

914
# Features
1015
src/api/toolchain_verify.cpp
1116
include/toolchain/api/toolchain_verify.h
12-
include/toolchain/api/flag_api.h
1317
)
1418
if (${TESTING})
1519
add_library(mock_toolchain

buildcc/lib/toolchain/include/toolchain/common/function_lock.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ namespace buildcc {
2727

2828
class FunctionLock {
2929
public:
30-
void Lock() { lock_ = true; }
31-
void Unlock() { lock_ = false; }
30+
FunctionLock(bool initial_value = false) : lock_(initial_value) {}
31+
32+
void SetLock(bool lock) { lock_ = lock; }
33+
void Lock() { SetLock(true); }
34+
void Unlock() { SetLock(false); }
35+
3236
bool IsLocked() const { return lock_; }
3337
// TODO, Make this better
3438
void ExpectsUnlock(std::string_view tag) const {

buildcc/lib/toolchain/include/toolchain/toolchain.h

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@
2929

3030
namespace buildcc {
3131

32-
// TODO, Make this private
33-
struct UserToolchainSchema {
34-
std::unordered_set<std::string> preprocessor_flags;
35-
std::unordered_set<std::string> common_compile_flags;
36-
std::unordered_set<std::string> pch_compile_flags;
37-
std::unordered_set<std::string> pch_object_flags;
38-
std::unordered_set<std::string> asm_compile_flags;
39-
std::unordered_set<std::string> c_compile_flags;
40-
std::unordered_set<std::string> cpp_compile_flags;
41-
std::unordered_set<std::string> link_flags;
42-
};
43-
4432
// Base toolchain class
4533
class Toolchain : public internal::FlagApi<Toolchain>,
4634
public ToolchainVerify<Toolchain> {
@@ -58,21 +46,18 @@ class Toolchain : public internal::FlagApi<Toolchain>,
5846
explicit Toolchain(Id id, std::string_view name,
5947
std::string_view asm_compiler, std::string_view c_compiler,
6048
std::string_view cpp_compiler, std::string_view archiver,
61-
std::string_view linker, bool locked = true,
49+
std::string_view linker, bool lock = true,
6250
const ToolchainConfig &config = ToolchainConfig())
6351
: id_(id), name_(name), asm_compiler_(asm_compiler),
6452
c_compiler_(c_compiler), cpp_compiler_(cpp_compiler),
65-
archiver_(archiver), linker_(linker), config_(config) {
66-
locked ? lock_.Lock() : lock_.Unlock();
67-
UpdateConfig(config_);
53+
archiver_(archiver), linker_(linker), config_(config), lock_(lock) {
54+
Initialize();
6855
}
6956

7057
Toolchain(Toolchain &&toolchain) = default;
7158
Toolchain(const Toolchain &toolchain) = delete;
72-
void Lock() {
73-
lock_.Lock();
74-
// TODO, In the future add some more code here
75-
}
59+
60+
void Lock();
7661

7762
// Getters
7863
Id GetId() const { return id_; }
@@ -86,8 +71,21 @@ class Toolchain : public internal::FlagApi<Toolchain>,
8671
const FunctionLock &GetLockInfo() const { return lock_; }
8772
const ToolchainConfig &GetConfig() const { return config_; }
8873

74+
private:
75+
struct UserSchema {
76+
std::unordered_set<std::string> preprocessor_flags;
77+
std::unordered_set<std::string> common_compile_flags;
78+
std::unordered_set<std::string> pch_compile_flags;
79+
std::unordered_set<std::string> pch_object_flags;
80+
std::unordered_set<std::string> asm_compile_flags;
81+
std::unordered_set<std::string> c_compile_flags;
82+
std::unordered_set<std::string> cpp_compile_flags;
83+
std::unordered_set<std::string> link_flags;
84+
};
85+
8986
private:
9087
virtual void UpdateConfig(ToolchainConfig &config) { (void)config; }
88+
void Initialize();
9189

9290
private:
9391
friend class internal::FlagApi<Toolchain>;
@@ -106,10 +104,10 @@ class Toolchain : public internal::FlagApi<Toolchain>,
106104
std::string archiver_;
107105
std::string linker_;
108106
ToolchainConfig config_;
107+
FunctionLock lock_;
109108

110109
//
111-
UserToolchainSchema user_;
112-
FunctionLock lock_;
110+
UserSchema user_;
113111
};
114112

115113
typedef Toolchain::Id ToolchainId;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021-2022 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "toolchain/toolchain.h"
18+
19+
namespace buildcc {
20+
21+
void Toolchain::Initialize() { UpdateConfig(config_); }
22+
23+
void Toolchain::Lock() { lock_.Lock(); }
24+
25+
} // namespace buildcc

0 commit comments

Comments
 (0)