<commit_before>#include <csignal>
#include <cstdlib>
#include <string>
#include <vector>
#ifndef _WIN32
#include <cstring>
#include <execinfo.h>
#include <unistd.h>
#endif
#pragma warning(push, 0)
#include <llvm/ADT/ArrayRef.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_ostream.h>
#pragma warning(pop)
#include "../driver/driver.h"
#include "../driver/repl.h"
#include "../support/utility.h"

using namespace delta;

static void printHelp() {
    llvm::outs() << "OVERVIEW: Delta compiler\n"
                    "\n"
                    "USAGE: delta [options] <inputs>\n"
                    "\n"
                    "OPTIONS:\n"
                    "  -c                    - Compile only, generating an .o file; don't link\n"
                    "  -emit-assembly        - Emit assembly code\n"
                    "  -emit-llvm-bitcode    - Emit LLVM bitcode\n"
                    "  -F<directory>         - Add a search path for C framework header import\n"
                    "  -fPIC                 - Emit position-independent code\n"
                    "  -help                 - Display this help\n"
                    "  -I<directory>         - Add a search path for module and C header import\n"
                    "  -o<filename>          - Use the given filename for the output executable\n"
                    "  -parse                - Perform parsing\n"
                    "  -print-ast            - Print the abstract syntax tree to stdout\n"
                    "  -print-ir             - Print the generated LLVM IR to stdout\n"
                    "  -typecheck            - Perform parsing and type checking\n"
                    "  -Werror               - Treat warnings as errors\n";
}

extern "C" void signalHandler(int signal) {
#ifndef _WIN32
    void* stacktrace[128];
    int size = backtrace(stacktrace, 128);
    llvm::errs() << strsignal(signal) << '\n';
    backtrace_symbols_fd(stacktrace, size, STDERR_FILENO);
#endif
    std::exit(signal);
}

int main(int argc, const char** argv) {
    std::signal(SIGINT, signalHandler);
    std::signal(SIGILL, signalHandler);
    std::signal(SIGABRT, signalHandler);
    std::signal(SIGFPE, signalHandler);
    std::signal(SIGSEGV, signalHandler);
    std::signal(SIGTERM, signalHandler);

    const char* argv0 = argv[0];

    --argc;
    ++argv;

    if (argc == 0) {
        return replMain();
    }

    llvm::StringRef command = argv[0];
    bool build = command == "build";
    bool run = command == "run";

    if (build || run) {
        --argc;
        ++argv;
    }

    std::vector<std::string> inputs;
    std::vector<llvm::StringRef> args;

    for (int i = 0; i < argc; ++i) {
        llvm::StringRef arg = argv[i];

        if (arg == "help" || arg == "-help" || arg == "--help" || arg == "-h") {
            printHelp();<commit_msg>Use InitLLVM for stack traces<commit_after>#include <string>
#include <vector>
#pragma warning(push, 0)
#include <llvm/ADT/ArrayRef.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/InitLLVM.h>
#include <llvm/Support/raw_ostream.h>
#pragma warning(pop)
#include "../driver/driver.h"
#include "../driver/repl.h"
#include "../support/utility.h"

using namespace delta;

static void printHelp() {
    llvm::outs() << "OVERVIEW: Delta compiler\n"
                    "\n"
                    "USAGE: delta [options] <inputs>\n"
                    "\n"
                    "OPTIONS:\n"
                    "  -c                    - Compile only, generating an .o file; don't link\n"
                    "  -emit-assembly        - Emit assembly code\n"
                    "  -emit-llvm-bitcode    - Emit LLVM bitcode\n"
                    "  -F<directory>         - Add a search path for C framework header import\n"
                    "  -fPIC                 - Emit position-independent code\n"
                    "  -help                 - Display this help\n"
                    "  -I<directory>         - Add a search path for module and C header import\n"
                    "  -o<filename>          - Use the given filename for the output executable\n"
                    "  -parse                - Perform parsing\n"
                    "  -print-ast            - Print the abstract syntax tree to stdout\n"
                    "  -print-ir             - Print the generated LLVM IR to stdout\n"
                    "  -typecheck            - Perform parsing and type checking\n"
                    "  -Werror               - Treat warnings as errors\n";
}

int main(int argc, const char** argv) {
    llvm::InitLLVM x(argc, argv);

    const char* argv0 = argv[0];
    --argc;
    ++argv;

    if (argc == 0) {
        return replMain();
    }

    llvm::StringRef command = argv[0];
    bool build = command == "build";
    bool run = command == "run";

    if (build || run) {
        --argc;
        ++argv;
    }

    std::vector<std::string> inputs;
    std::vector<llvm::StringRef> args;

    for (int i = 0; i < argc; ++i) {
        llvm::StringRef arg = argv[i];

        if (arg == "help" || arg == "-help" || arg == "--help" || arg == "-h") {
            printHelp();
{'fraction_non_alphanumeric': 0.13415101571483326, 'fraction_numerical': 0.004216174779609045, 'mean_word_length': 1.6108054027013508, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306866', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1538, 'n_words': 418}