Skip to content

Commit fda805c

Browse files
authored
Merge pull request #3 from mkn-mod/next
more options
2 parents a8f7635 + 598bada commit fda805c

File tree

3 files changed

+67
-22
lines changed

3 files changed

+67
-22
lines changed

.github/workflows/build_nix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
MKN_LIB_LINK_LIB: 1
1919
KUL_GIT_CO: --depth 1
2020
run: |
21+
sudo apt update && sudo apt install -y llvm
2122
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
2223
chmod +x mkn
2324
KLOG=2 ./mkn clean build run -dtOa "-std=c++17 -fPIC"

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1+
12
# clang.llvm-mca
2-
LLVM MCA module
3+
4+
** LLVM MCA module **
5+
6+
Multi phase module to analyse binary instructions
7+
Puts output file in bin/$profile/res
8+
9+
## Prerequisites
10+
[maiken](https://github.com/mkn/mkn)
11+
12+
## Usage
13+
14+
```yaml
15+
mod:
16+
- name: clang.format
17+
link:
18+
bin: $str #[optional, default="llvm-mca"]
19+
out: $str #[optional, default="llvm-mca.txt"]
20+
```
21+
22+
## Building
23+
24+
Windows cl:
25+
26+
mkn clean build -tSa -EHsc -d
27+
28+
29+
*nix gcc:
30+
31+
mkn clean build -tSa "-O2 -fPIC" -d -l "-pthread -ldl"
32+
33+
34+
## Testing
35+
36+
Windows cl:
37+
38+
mkn clean build -tSa -EHsc -dp test run
39+
40+
41+
*nix gcc:
42+
43+
mkn clean build -tSa "-O2 -fPIC" -dp test -l "-pthread -ldl" run
44+

mod.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@ class AppHack : public maiken::Application {
3939
std::string_view constexpr static base0 = " -save-temps=obj";
4040

4141
auto static drop_file_type(std::string filename) {
42-
mkn::kul::File file{filename};
43-
filename = file.name();
42+
filename = mkn::kul::File{filename}.name();
4443
return filename.substr(0, filename.rfind("."));
4544
}
4645

47-
public:
46+
public:
4847
auto update(maiken::Source const &s) {
49-
std::string arg = s.args() + std::string{base0};
48+
std::string const arg = s.args() + std::string{base0};
5049
return maiken::Source{s.in(), arg};
5150
}
5251
void hack() {
53-
if (this->main_)
54-
this->main_ = update(*this->main_);
52+
if (this->main_) this->main_ = update(*this->main_);
5553
}
5654

5755
auto hack_link() { return drop_file_type(this->main_->in()) + ".s"; }
@@ -60,40 +58,44 @@ class AppHack : public maiken::Application {
6058
};
6159

6260
class LLVM_MCA_Module : public maiken::Module {
63-
public:
64-
void compile(maiken::Application &a, YAML::Node const &node)
65-
KTHROW(std::exception) override {
61+
public:
62+
void compile(maiken::Application &a, YAML::Node const &node) KTHROW(std::exception) override {
6663
reinterpret_cast<AppHack *>(&a)->hack();
6764
}
6865

69-
void link(maiken::Application &a, YAML::Node const &node)
70-
KTHROW(std::exception) override {
66+
void link(maiken::Application &a, YAML::Node const &node) KTHROW(std::exception) override {
7167
AppHack *hack = reinterpret_cast<AppHack *>(&a);
72-
if (!hack->valid())
73-
return;
68+
if (!hack->valid()) return;
7469

75-
mkn::kul::Dir res{"res", a.buildDir()};
70+
mkn::kul::Dir const res{"res", a.buildDir()};
7671
res.mk();
7772

78-
mkn::kul::Dir tmp{"tmp", a.buildDir()};
73+
mkn::kul::Dir const tmp{"tmp", a.buildDir()};
7974
mkn::kul::File sss{hack->hack_link(), tmp};
8075

81-
mkn::kul::Process p{"llvm-mca-14"};
76+
auto const mca_bin = [&]() -> std::string {
77+
if (node["bin"]) return node["bin"].Scalar();
78+
return "llvm-mca";
79+
}();
80+
mkn::kul::Process p{mca_bin};
8281
mkn::kul::ProcessCapture pc{p};
8382
p << sss.mini();
8483
p.start();
8584

86-
mkn::kul::File outfile{"llvm-mca.txt", res};
85+
auto const mca_out = [&]() -> std::string {
86+
if (node["out"]) return node["out"].Scalar();
87+
return "llvm-mca.txt";
88+
}();
89+
90+
mkn::kul::File const outfile{mca_out, res};
8791
mkn::kul::io::Writer{outfile} << pc.outs();
8892
}
8993
};
9094

91-
} // namespace mkn::clang
95+
} // namespace mkn::clang
9296

9397
extern "C" KUL_PUBLISH maiken::Module *maiken_module_construct() {
9498
return new mkn ::clang ::LLVM_MCA_Module;
9599
}
96100

97-
extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) {
98-
delete p;
99-
}
101+
extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) { delete p; }

0 commit comments

Comments
 (0)