Skip to content

Commit

Permalink
more options
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 7, 2024
1 parent a8f7635 commit 598bada
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
MKN_LIB_LINK_LIB: 1
KUL_GIT_CO: --depth 1
run: |
sudo apt update && sudo apt install -y llvm
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
chmod +x mkn
KLOG=2 ./mkn clean build run -dtOa "-std=c++17 -fPIC"
Expand Down
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@

# clang.llvm-mca
LLVM MCA module

** LLVM MCA module **

Multi phase module to analyse binary instructions
Puts output file in bin/$profile/res

## Prerequisites
[maiken](https://github.com/mkn/mkn)

## Usage

```yaml
mod:
- name: clang.format
link:
bin: $str #[optional, default="llvm-mca"]
out: $str #[optional, default="llvm-mca.txt"]
```
## Building
Windows cl:
mkn clean build -tSa -EHsc -d
*nix gcc:
mkn clean build -tSa "-O2 -fPIC" -d -l "-pthread -ldl"
## Testing
Windows cl:
mkn clean build -tSa -EHsc -dp test run
*nix gcc:
mkn clean build -tSa "-O2 -fPIC" -dp test -l "-pthread -ldl" run
44 changes: 23 additions & 21 deletions mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ class AppHack : public maiken::Application {
std::string_view constexpr static base0 = " -save-temps=obj";

auto static drop_file_type(std::string filename) {
mkn::kul::File file{filename};
filename = file.name();
filename = mkn::kul::File{filename}.name();
return filename.substr(0, filename.rfind("."));
}

public:
public:
auto update(maiken::Source const &s) {
std::string arg = s.args() + std::string{base0};
std::string const arg = s.args() + std::string{base0};
return maiken::Source{s.in(), arg};
}
void hack() {
if (this->main_)
this->main_ = update(*this->main_);
if (this->main_) this->main_ = update(*this->main_);
}

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

class LLVM_MCA_Module : public maiken::Module {
public:
void compile(maiken::Application &a, YAML::Node const &node)
KTHROW(std::exception) override {
public:
void compile(maiken::Application &a, YAML::Node const &node) KTHROW(std::exception) override {
reinterpret_cast<AppHack *>(&a)->hack();
}

void link(maiken::Application &a, YAML::Node const &node)
KTHROW(std::exception) override {
void link(maiken::Application &a, YAML::Node const &node) KTHROW(std::exception) override {
AppHack *hack = reinterpret_cast<AppHack *>(&a);
if (!hack->valid())
return;
if (!hack->valid()) return;

mkn::kul::Dir res{"res", a.buildDir()};
mkn::kul::Dir const res{"res", a.buildDir()};
res.mk();

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

mkn::kul::Process p{"llvm-mca-14"};
auto const mca_bin = [&]() -> std::string {
if (node["bin"]) return node["bin"].Scalar();
return "llvm-mca";
}();
mkn::kul::Process p{mca_bin};
mkn::kul::ProcessCapture pc{p};
p << sss.mini();
p.start();

mkn::kul::File outfile{"llvm-mca.txt", res};
auto const mca_out = [&]() -> std::string {
if (node["out"]) return node["out"].Scalar();
return "llvm-mca.txt";
}();

mkn::kul::File const outfile{mca_out, res};
mkn::kul::io::Writer{outfile} << pc.outs();
}
};

} // namespace mkn::clang
} // namespace mkn::clang

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

extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) {
delete p;
}
extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) { delete p; }

0 comments on commit 598bada

Please sign in to comment.