Skip to content

Commit

Permalink
Modularize QPKG dev tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Kracken256 committed Jun 20, 2024
1 parent 1e2db25 commit 2611f07
Show file tree
Hide file tree
Showing 25 changed files with 832 additions and 121 deletions.
2 changes: 1 addition & 1 deletion qpkg/src/bench/ansi.cc → qpkg/src/core/ANSI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// ///
////////////////////////////////////////////////////////////////////////////////

#include <bench/bench.hh>
#include <core/ANSI.hh>
#include <iostream>

thread_local qpkg::ansi::AnsiCout qpkg::ansi::acout;
Expand Down
47 changes: 3 additions & 44 deletions qpkg/src/bench/bench.hh → qpkg/src/core/ANSI.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/// ///
////////////////////////////////////////////////////////////////////////////////

#ifndef __QPKG_BENCH_HH__
#define __QPKG_BENCH_HH__
#ifndef __QPKG_CORE_ANSI_HH__
#define __QPKG_CORE_ANSI_HH__

#include <chrono>
#include <cstdint>
Expand All @@ -41,7 +41,6 @@
#include <string_view>

namespace qpkg {

namespace ansi {
enum class Style {
/*==== Text Color ====*/
Expand Down Expand Up @@ -137,46 +136,6 @@ static inline void operator|=(AnsiCout &out, Style style) {
extern thread_local AnsiCout acout;
} // namespace ansi

namespace bench {
int run_benchmark_lexer();
int run_benchmark_parser();
int run_benchmark_quix_ir();
int run_benchmark_delta_ir();
int run_benchmark_llvm_ir();
int run_benchmark_llvm_codegen();
int run_benchmark_c11_codegen();
int run_benchmark_pipeline();

extern const std::string_view test_source_code;

class Progress {
std::string m_title;
std::string m_last_msg;
std::queue<std::pair<std::string, double>> m_queue;
std::chrono::high_resolution_clock::time_point m_last_print;
constexpr static std::chrono::milliseconds m_print_interval =
std::chrono::milliseconds(1000);

void print(double percent, const std::string &msg);

public:
Progress(const std::string &title);

void update(double percent, const std::string &msg = "");
void done(const std::string &outfile_name = "");

enum class Result {
THROUGHPUT,
MEMORY,
TIME,
};

void begin_result(Result type);
void result(const std::string &msg);
void end_result();
};
} // namespace bench

} // namespace qpkg

#endif // __QPKG_BENCH_HH__
#endif // __QPKG_CORE_ANSI_HH__
37 changes: 37 additions & 0 deletions qpkg/src/core/Config.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
////////////////////////////////////////////////////////////////////////////////
/// ///
/// ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░░▒▓███████▓▒░░▒▓█▓▒▒▓███▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ///
/// ░▒▓█▓▒░ ///
/// ░▒▓██▓▒░ ///
/// ///
/// * QUIX PACKAGE MANAGER - The official tool for the Quix language. ///
/// * Copyright (C) 2024 Wesley C. Jones ///
/// ///
/// The QUIX Compiler Suite is free software; you can redistribute it or ///
/// modify it under the terms of the GNU Lesser General Public ///
/// License as published by the Free Software Foundation; either ///
/// version 2.1 of the License, or (at your option) any later version. ///
/// ///
/// The QUIX Compiler Suite is distributed in the hope that it will be ///
/// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ///
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ///
/// Lesser General Public License for more details. ///
/// ///
/// You should have received a copy of the GNU Lesser General Public ///
/// License along with the QUIX Compiler Suite; if not, see ///
/// <https://www.gnu.org/licenses/>. ///
/// ///
////////////////////////////////////////////////////////////////////////////////

#ifndef __QPKG_CORE_CONFIG_HH__
#define __QPKG_CORE_CONFIG_HH__

#define QPKG_DEV_TOOLS 1

#endif // __QPKG_CORE_CONFIG_HH__
86 changes: 86 additions & 0 deletions qpkg/src/dev/bench/bench.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
////////////////////////////////////////////////////////////////////////////////
/// ///
/// ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░░▒▓███████▓▒░░▒▓█▓▒▒▓███▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ///
/// ░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ///
/// ░▒▓█▓▒░ ///
/// ░▒▓██▓▒░ ///
/// ///
/// * QUIX PACKAGE MANAGER - The official tool for the Quix language. ///
/// * Copyright (C) 2024 Wesley C. Jones ///
/// ///
/// The QUIX Compiler Suite is free software; you can redistribute it or ///
/// modify it under the terms of the GNU Lesser General Public ///
/// License as published by the Free Software Foundation; either ///
/// version 2.1 of the License, or (at your option) any later version. ///
/// ///
/// The QUIX Compiler Suite is distributed in the hope that it will be ///
/// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ///
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ///
/// Lesser General Public License for more details. ///
/// ///
/// You should have received a copy of the GNU Lesser General Public ///
/// License along with the QUIX Compiler Suite; if not, see ///
/// <https://www.gnu.org/licenses/>. ///
/// ///
////////////////////////////////////////////////////////////////////////////////

#ifndef __QPKG_BENCH_HH__
#define __QPKG_BENCH_HH__

#include <chrono>
#include <cstdint>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string_view>

namespace qpkg {
namespace dev::bench {
int run_benchmark_lexer();
int run_benchmark_parser();
int run_benchmark_quix_ir();
int run_benchmark_delta_ir();
int run_benchmark_llvm_ir();
int run_benchmark_llvm_codegen();
int run_benchmark_c11_codegen();
int run_benchmark_pipeline();

extern const std::string_view test_source_code;

class Progress {
std::string m_title;
std::string m_last_msg;
std::queue<std::pair<std::string, double>> m_queue;
std::chrono::high_resolution_clock::time_point m_last_print;
constexpr static std::chrono::milliseconds m_print_interval =
std::chrono::milliseconds(1000);

void print(double percent, const std::string &msg);

public:
Progress(const std::string &title);

void update(double percent, const std::string &msg = "");
void done(const std::string &outfile_name = "");

enum class Result {
THROUGHPUT,
MEMORY,
TIME,
};

void begin_result(Result type);
void result(const std::string &msg);
void end_result();
};
} // namespace dev::bench

} // namespace qpkg

#endif // __QPKG_BENCH_HH__
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <quixcc/Quix.h>

#include <bench/bench.hh>
#include <dev/bench/bench.hh>
#include <chrono>
#include <cmath>
#include <fstream>
Expand All @@ -52,8 +52,8 @@ bool do_bench_c11(std::chrono::system_clock::time_point &start,
return false;
}

code = fmemopen((void *)qpkg::bench::test_source_code.data(),
qpkg::bench::test_source_code.size(), "r");
code = fmemopen((void *)qpkg::dev::bench::test_source_code.data(),
qpkg::dev::bench::test_source_code.size(), "r");
if (!code) {
std::cerr << "do_bench (internal error): Failed to open code stream."
<< std::endl;
Expand Down Expand Up @@ -99,7 +99,7 @@ static void write_c11_result_csv(const std::vector<double> &throughput) {
file.close();
}

int qpkg::bench::run_benchmark_c11_codegen() {
int qpkg::dev::bench::run_benchmark_c11_codegen() {
Progress progress("C11 Codegen");
std::vector<double> times;

Expand Down Expand Up @@ -127,7 +127,7 @@ int qpkg::bench::run_benchmark_c11_codegen() {
std::vector<double> throughput; // Kbit/s

for (size_t i = 0; i < ROUNDS; i++) {
size_t total_kbit = qpkg::bench::test_source_code.size() / 1024 * 8;
size_t total_kbit = qpkg::dev::bench::test_source_code.size() / 1024 * 8;
double kbit_per_ns = total_kbit / times[i];
double kbit_per_s = kbit_per_ns * 1e9;
throughput.push_back(kbit_per_s);
Expand Down
10 changes: 5 additions & 5 deletions qpkg/src/bench/delta-ir.cc → qpkg/src/dev/bench/delta-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <quixcc/Quix.h>

#include <bench/bench.hh>
#include <dev/bench/bench.hh>
#include <chrono>
#include <cmath>
#include <fstream>
Expand All @@ -52,8 +52,8 @@ bool do_bench_delta_ir(std::chrono::system_clock::time_point &start,
return false;
}

code = fmemopen((void *)qpkg::bench::test_source_code.data(),
qpkg::bench::test_source_code.size(), "r");
code = fmemopen((void *)qpkg::dev::bench::test_source_code.data(),
qpkg::dev::bench::test_source_code.size(), "r");
if (!code) {
std::cerr << "do_bench (internal error): Failed to open code stream."
<< std::endl;
Expand Down Expand Up @@ -99,7 +99,7 @@ static void write_delta_ir_result_csv(const std::vector<double> &throughput) {
file.close();
}

int qpkg::bench::run_benchmark_delta_ir() {
int qpkg::dev::bench::run_benchmark_delta_ir() {
Progress progress("DeltaIR Codegen");
std::vector<double> times;

Expand Down Expand Up @@ -127,7 +127,7 @@ int qpkg::bench::run_benchmark_delta_ir() {
std::vector<double> throughput; // Kbit/s

for (size_t i = 0; i < ROUNDS; i++) {
size_t total_kbit = qpkg::bench::test_source_code.size() / 1024 * 8;
size_t total_kbit = qpkg::dev::bench::test_source_code.size() / 1024 * 8;
double kbit_per_ns = total_kbit / times[i];
double kbit_per_s = kbit_per_ns * 1e9;
throughput.push_back(kbit_per_s);
Expand Down
10 changes: 5 additions & 5 deletions qpkg/src/bench/lexer.cc → qpkg/src/dev/bench/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <quixcc/Quix.h>

#include <bench/bench.hh>
#include <dev/bench/bench.hh>
#include <chrono>
#include <cmath>
#include <fstream>
Expand All @@ -54,8 +54,8 @@ bool do_bench_lexer(std::chrono::system_clock::time_point &start,
return false;
}

code = fmemopen((void *)qpkg::bench::test_source_code.data(),
qpkg::bench::test_source_code.size(), "r");
code = fmemopen((void *)qpkg::dev::bench::test_source_code.data(),
qpkg::dev::bench::test_source_code.size(), "r");
if (!code) {
std::cerr << "do_bench (internal error): Failed to open code stream."
<< std::endl;
Expand Down Expand Up @@ -115,7 +115,7 @@ static void write_lexer_result_csv(const std::vector<double> &throughput) {
file.close();
}

int qpkg::bench::run_benchmark_lexer() {
int qpkg::dev::bench::run_benchmark_lexer() {
Progress progress("Lexer");
std::vector<double> times;

Expand Down Expand Up @@ -143,7 +143,7 @@ int qpkg::bench::run_benchmark_lexer() {
std::vector<double> throughput; // Kbit/s

for (size_t i = 0; i < ROUNDS; i++) {
size_t total_kbit = qpkg::bench::test_source_code.size() / 1024 * 8;
size_t total_kbit = qpkg::dev::bench::test_source_code.size() / 1024 * 8;
double kbit_per_ns = total_kbit / times[i];
double kbit_per_s = kbit_per_ns * 1e9;
throughput.push_back(kbit_per_s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <quixcc/Quix.h>

#include <bench/bench.hh>
#include <dev/bench/bench.hh>
#include <chrono>
#include <cmath>
#include <fstream>
Expand All @@ -52,8 +52,8 @@ bool do_bench_llvm_codegen(std::chrono::system_clock::time_point &start,
return false;
}

code = fmemopen((void *)qpkg::bench::test_source_code.data(),
qpkg::bench::test_source_code.size(), "r");
code = fmemopen((void *)qpkg::dev::bench::test_source_code.data(),
qpkg::dev::bench::test_source_code.size(), "r");
if (!code) {
std::cerr << "do_bench (internal error): Failed to open code stream."
<< std::endl;
Expand Down Expand Up @@ -99,7 +99,7 @@ static void write_llvm_obj_result_csv(const std::vector<double> &throughput) {
file.close();
}

int qpkg::bench::run_benchmark_llvm_codegen() {
int qpkg::dev::bench::run_benchmark_llvm_codegen() {
Progress progress("LLVM OBJECT CODEGEN");
std::vector<double> times;

Expand Down Expand Up @@ -127,7 +127,7 @@ int qpkg::bench::run_benchmark_llvm_codegen() {
std::vector<double> throughput; // Kbit/s

for (size_t i = 0; i < ROUNDS; i++) {
size_t total_kbit = qpkg::bench::test_source_code.size() / 1024 * 8;
size_t total_kbit = qpkg::dev::bench::test_source_code.size() / 1024 * 8;
double kbit_per_ns = total_kbit / times[i];
double kbit_per_s = kbit_per_ns * 1e9;
throughput.push_back(kbit_per_s);
Expand Down
10 changes: 5 additions & 5 deletions qpkg/src/bench/llvm-ir.cc → qpkg/src/dev/bench/llvm-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <quixcc/Quix.h>

#include <bench/bench.hh>
#include <dev/bench/bench.hh>
#include <chrono>
#include <cmath>
#include <fstream>
Expand All @@ -52,8 +52,8 @@ bool do_bench_llvm_ir(std::chrono::system_clock::time_point &start,
return false;
}

code = fmemopen((void *)qpkg::bench::test_source_code.data(),
qpkg::bench::test_source_code.size(), "r");
code = fmemopen((void *)qpkg::dev::bench::test_source_code.data(),
qpkg::dev::bench::test_source_code.size(), "r");
if (!code) {
std::cerr << "do_bench (internal error): Failed to open code stream."
<< std::endl;
Expand Down Expand Up @@ -99,7 +99,7 @@ static void write_llvm_ir_result_csv(const std::vector<double> &throughput) {
file.close();
}

int qpkg::bench::run_benchmark_llvm_ir() {
int qpkg::dev::bench::run_benchmark_llvm_ir() {
Progress progress("LLVM IR");
std::vector<double> times;

Expand Down Expand Up @@ -127,7 +127,7 @@ int qpkg::bench::run_benchmark_llvm_ir() {
std::vector<double> throughput; // Kbit/s

for (size_t i = 0; i < ROUNDS; i++) {
size_t total_kbit = qpkg::bench::test_source_code.size() / 1024 * 8;
size_t total_kbit = qpkg::dev::bench::test_source_code.size() / 1024 * 8;
double kbit_per_ns = total_kbit / times[i];
double kbit_per_s = kbit_per_ns * 1e9;
throughput.push_back(kbit_per_s);
Expand Down
Loading

0 comments on commit 2611f07

Please sign in to comment.