<commit_before>#include <b9.hpp>
#include <b9/loader.hpp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

/// B9run's usage string. Printed when run with -help.
static const char* usage =
    "Usage: b9run [<option>...] [--] [<module> [<main>]]\n"
    "   Or: b9run -help\n"
    "Options:\n"
    "  -callstyle <style>: Set the calling style. One of:\n"
    "      interpreter:   Calls are made through the interpreter\n"
    "      direct:        Calls are made directly, but parameters are on the "
    "operand stack\n"
    "      passparameter: Direct calls, with parameters passed in CPU "
    "registers\n"
    "      operandstack:  Like passparam, but will keep the VM operand stack "
    "updated\n"
    "  -loop <n>:   Run the program <n> times\n"
    "  -inline <n>: Enable inlining\n"
    "  -debug:      Enable debug code\n"
    "  -verbose:    Run with verbose printing\n"
    "  -help:       Print this help message";

/// The b9run program's global configuration.
struct RunConfig {
  b9::VirtualMachineConfig vm;
  const char* module = "program.so";
  const char* mainFunction = "b9main";
  std::size_t loopCount = 1;
  bool verbose = false;
};

/// Print the configuration summary.
std::ostream& operator<<(std::ostream& out, const RunConfig& cfg) {
  return out << "Loading:      " << cfg.module << std::endl
             << "Executing:    " << cfg.mainFunction << std::endl
             << "Looping:      " << cfg.loopCount << " times" << std::endl
             << "Inline depth: " << cfg.vm.jit.maxInlineDepth << std::endl
             << "Call Style:   " << cfg.vm.jit.callStyle;
}

/// Parse CLI arguments and set up the config.
static bool parseArguments(RunConfig& cfg, const int argc, char* argv[]) {
  std::size_t i = 1;

  for (; i < argc; i++) {
    const char* arg = argv[i];

    if (strcmp(arg, "-help") == 0) {
      std::cout << usage << std::endl;
      exit(EXIT_SUCCESS);
    } else if (strcmp(arg, "-loop") == 0) {
      cfg.loopCount = atoi(argv[++i]);
    } else if (strcmp(arg, "-inline") == 0) {
      cfg.vm.jit.maxInlineDepth = atoi(argv[++i]);
    } else if (strcmp(arg, "-verbose") == 0) {
      std::cout << "verbose is enabled" << std::endl;
      cfg.verbose = true;
      cfg.vm.verbose = true;
      cfg.vm.jit.verbose = true;
    } else if (strcmp(arg, "-debug") == 0) {
      cfg.vm.debug = true;
      cfg.vm.jit.debug = true;
    } else if (strcmp(arg, "-callstyle") == 0) {
      i += 1;
      auto callStyle = argv[i];
      if (strcmp("interpreter", callStyle) == 0) {
        cfg.vm.jit.callStyle = b9::CallStyle::interpreter;
      } else if (strcmp("direct", callStyle) == 0) {<commit_msg>Rearrange verbose output<commit_after>#include <b9.hpp>
#include <b9/loader.hpp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

/// B9run's usage string. Printed when run with -help.
static const char* usage =
    "Usage: b9run [<option>...] [--] [<module> [<main>]]\n"
    "   Or: b9run -help\n"
    "Options:\n"
    "  -callstyle <style>: Set the calling style. One of:\n"
    "      interpreter:   Calls are made through the interpreter\n"
    "      direct:        Calls are made directly, but parameters are on the "
    "operand stack\n"
    "      passparameter: Direct calls, with parameters passed in CPU "
    "registers\n"
    "      operandstack:  Like passparam, but will keep the VM operand stack "
    "updated\n"
    "  -loop <n>:   Run the program <n> times\n"
    "  -inline <n>: Enable inlining\n"
    "  -debug:      Enable debug code\n"
    "  -verbose:    Run with verbose printing\n"
    "  -help:       Print this help message";

/// The b9run program's global configuration.
struct RunConfig {
  b9::VirtualMachineConfig vm;
  const char* module = "program.so";
  const char* mainFunction = "b9main";
  std::size_t loopCount = 1;
  bool verbose = false;
};

/// Print the configuration summary.
std::ostream& operator<<(std::ostream& out, const RunConfig& cfg) {
  return out << "Loading:      " << cfg.module << std::endl
             << "Executing:    " << cfg.mainFunction << std::endl
             << "Call Style:   " << cfg.vm.jit.callStyle << std::endl
             << "Looping:      " << cfg.loopCount << " times" << std::endl
             << "Inline depth: " << cfg.vm.jit.maxInlineDepth;
}

/// Parse CLI arguments and set up the config.
static bool parseArguments(RunConfig& cfg, const int argc, char* argv[]) {
  std::size_t i = 1;

  for (; i < argc; i++) {
    const char* arg = argv[i];

    if (strcmp(arg, "-help") == 0) {
      std::cout << usage << std::endl;
      exit(EXIT_SUCCESS);
    } else if (strcmp(arg, "-loop") == 0) {
      cfg.loopCount = atoi(argv[++i]);
    } else if (strcmp(arg, "-inline") == 0) {
      cfg.vm.jit.maxInlineDepth = atoi(argv[++i]);
    } else if (strcmp(arg, "-verbose") == 0) {
      std::cout << "verbose is enabled" << std::endl;
      cfg.verbose = true;
      cfg.vm.verbose = true;
      cfg.vm.jit.verbose = true;
    } else if (strcmp(arg, "-debug") == 0) {
      cfg.vm.debug = true;
      cfg.vm.jit.debug = true;
    } else if (strcmp(arg, "-callstyle") == 0) {
      i += 1;
      auto callStyle = argv[i];
      if (strcmp("interpreter", callStyle) == 0) {
        cfg.vm.jit.callStyle = b9::CallStyle::interpreter;
      } else if (strcmp("direct", callStyle) == 0) {
{'fraction_non_alphanumeric': 0.16514445479962722, 'fraction_numerical': 0.007455731593662628, 'mean_word_length': 2.5701929474384566, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5235941', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1810, 'n_words': 508}