Ejemplo n.º 1
0
int main(int argc, char **argv) {
    bool          succeed  = false;
    char         *redirout = (char*)stdout;
    char         *redirerr = (char*)stderr;
    char         *defs     = NULL;

    con_init();
    OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;

    /*
     * Command line option parsing commences now We only need to support
     * a few things in the test suite.
     */
    while (argc > 1) {
        ++argv;
        --argc;

        if (argv[0][0] == '-') {
            if (parsecmd("redirout", &argc, &argv, &redirout, 1, false))
                continue;
            if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false))
                continue;
            if (parsecmd("defs",     &argc, &argv, &defs,     1, false))
                continue;

            con_change(redirout, redirerr);

            if (!strcmp(argv[0]+1, "debug")) {
                OPTS_OPTION_BOOL(OPTION_DEBUG) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "memchk")) {
                OPTS_OPTION_BOOL(OPTION_MEMCHK) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "nocolor")) {
                con_color(0);
                continue;
            }

            con_err("invalid argument %s\n", argv[0]+1);
            return -1;
        }
    }
    con_change(redirout, redirerr);
    succeed = test_perform("tests", defs);
    stat_info();

    return (succeed) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 2
0
static void code_stats(const char *filename, const char *lnofile, code_t *code, prog_header_t *code_header) {
    if (OPTS_OPTION_BOOL(OPTION_QUIET) ||
        OPTS_OPTION_BOOL(OPTION_PP_ONLY))
            return;

    con_out("\nFile statistics:\n");
    con_out("    dat:\n");
    con_out("        name: %s\n",         filename);
    con_out("        size: %u (bytes)\n", code_size_binary(code, code_header));
    con_out("        crc:  0x%04X\n",     code->crc);

    if (lnofile) {
        con_out("    lno:\n");
        con_out("        name: %s\n",  lnofile);
        con_out("        size: %u (bytes)\n",  code_size_debug(code, code_header));
    }

    con_out("\n");
}
Ejemplo n.º 3
0
void stat_info() {
    if (OPTS_OPTION_BOOL(OPTION_MEMCHK) ||
        OPTS_OPTION_BOOL(OPTION_STATISTICS)) {
        uint64_t mem = 0;

        con_out("Memory Statistics:\n\
    Total vectors allocated:       %llu\n\
    Total string duplicates:       %llu\n\
    Total string duplicate memory: %f (MB)\n\
    Total hashtables allocated:    %llu\n\
    Total unique vector sizes:     %llu\n",
            stat_used_vectors,
            stat_used_strdups,
            (float)(stat_mem_strdups) / 1048576.0f,
            stat_used_hashtables,
            stat_type_vectors
        );

        stat_dump_stats_table (
            stat_size_vectors,
            "        %2u| # of %5u byte vectors: %u\n",
            &mem
        );

        con_out (
            "    Total unique hashtable sizes: %llu\n",
            stat_type_hashtables
        );

        stat_dump_stats_table (
            stat_size_hashtables,
            "        %2u| # of %5u element hashtables: %u\n",
            NULL
        );

        con_out (
            "    Total vector memory:          %f (MB)\n\n",
            (float)(mem) / 1048576.0f
        );
    }
Ejemplo n.º 4
0
static void opts_setdefault(void) {
    memset(&opts, 0, sizeof(opts_cmd_t));
    OPTS_OPTION_BOOL(OPTION_CORRECTION) = true;
    OPTS_OPTION_STR(OPTION_PROGSRC)     = "progs.src";

    /* warnings */
    opts_set(opts.warn,  WARN_UNUSED_VARIABLE,           true);
    opts_set(opts.warn,  WARN_USED_UNINITIALIZED,        true);
    opts_set(opts.warn,  WARN_UNKNOWN_CONTROL_SEQUENCE,  true);
    opts_set(opts.warn,  WARN_EXTENSIONS,                true);
    opts_set(opts.warn,  WARN_FIELD_REDECLARED,          true);
    opts_set(opts.warn,  WARN_MISSING_RETURN_VALUES,     true);
    opts_set(opts.warn,  WARN_INVALID_PARAMETER_COUNT,   true);
    opts_set(opts.warn,  WARN_LOCAL_CONSTANTS,           true);
    opts_set(opts.warn,  WARN_VOID_VARIABLES,            true);
    opts_set(opts.warn,  WARN_IMPLICIT_FUNCTION_POINTER, true);
    opts_set(opts.warn,  WARN_VARIADIC_FUNCTION,         true);
    opts_set(opts.warn,  WARN_FRAME_MACROS,              true);
    opts_set(opts.warn,  WARN_EFFECTLESS_STATEMENT,      true);
    opts_set(opts.warn,  WARN_END_SYS_FIELDS,            true);
    opts_set(opts.warn,  WARN_ASSIGN_FUNCTION_TYPES,     true);
    opts_set(opts.warn,  WARN_CPP,                       true);
    opts_set(opts.warn,  WARN_MULTIFILE_IF,              true);
    opts_set(opts.warn,  WARN_DOUBLE_DECLARATION,        true);
    opts_set(opts.warn,  WARN_CONST_VAR,                 true);
    opts_set(opts.warn,  WARN_MULTIBYTE_CHARACTER,       true);
    opts_set(opts.warn,  WARN_UNKNOWN_PRAGMAS,           true);
    opts_set(opts.warn,  WARN_UNREACHABLE_CODE,          true);
    opts_set(opts.warn,  WARN_UNKNOWN_ATTRIBUTE,         true);
    opts_set(opts.warn,  WARN_RESERVED_NAMES,            true);
    opts_set(opts.warn,  WARN_UNINITIALIZED_CONSTANT,    true);
    opts_set(opts.warn,  WARN_DEPRECATED,                true);
    opts_set(opts.warn,  WARN_PARENTHESIS,               true);
    opts_set(opts.warn,  WARN_CONST_OVERWRITE,           true);
    opts_set(opts.warn,  WARN_DIRECTIVE_INMACRO,         true);
    opts_set(opts.warn,  WARN_BUILTINS,                  true);
    opts_set(opts.warn,  WARN_INEXACT_COMPARES,          true);

    /* flags */
    opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
    opts_set(opts.flags, CORRECT_TERNARY,                true);
    opts_set(opts.flags, BAIL_ON_WERROR,                 true);
    opts_set(opts.flags, LEGACY_VECTOR_MATHS,            true);
    opts_set(opts.flags, DARKPLACES_STRING_TABLE_BUG,    true);

    /* options */
    OPTS_OPTION_U32(OPTION_STATE_FPS) = 10;
}
Ejemplo n.º 5
0
static void code_create_header(code_t *code, prog_header_t *code_header, const char *filename, const char *lnofile) {
    size_t i;

    code_header->statements.offset = sizeof(prog_header_t);
    code_header->statements.length = vec_size(code->statements);
    code_header->defs.offset       = code_header->statements.offset + (sizeof(prog_section_statement_t) * vec_size(code->statements));
    code_header->defs.length       = vec_size(code->defs);
    code_header->fields.offset     = code_header->defs.offset       + (sizeof(prog_section_def_t)       * vec_size(code->defs));
    code_header->fields.length     = vec_size(code->fields);
    code_header->functions.offset  = code_header->fields.offset     + (sizeof(prog_section_field_t)     * vec_size(code->fields));
    code_header->functions.length  = vec_size(code->functions);
    code_header->globals.offset    = code_header->functions.offset  + (sizeof(prog_section_function_t)  * vec_size(code->functions));
    code_header->globals.length    = vec_size(code->globals);
    code_header->strings.offset    = code_header->globals.offset    + (sizeof(int32_t)                  * vec_size(code->globals));
    code_header->strings.length    = vec_size(code->chars);
    code_header->version           = 6;
    code_header->skip              = 0;

    if (OPTS_OPTION_BOOL(OPTION_FORCECRC))
        code_header->crc16         = OPTS_OPTION_U16(OPTION_FORCED_CRC);
    else
        code_header->crc16         = code->crc;
    code_header->entfield          = code->entfields;

    if (OPTS_FLAG(DARKPLACES_STRING_TABLE_BUG)) {
        /* >= + P */
        vec_push(code->chars, '\0'); /* > */
        vec_push(code->chars, '\0'); /* = */
        vec_push(code->chars, '\0'); /* P */
    }

    /* ensure all data is in LE format */
    util_swap_header(code_header);

    /*
     * These are not part of the header but we ensure LE format here to save on duplicated
     * code.
     */

    util_swap_statements (code->statements);
    util_swap_defs_fields(code->defs);
    util_swap_defs_fields(code->fields);
    util_swap_functions  (code->functions);
    util_swap_globals    (code->globals);

    if (!OPTS_OPTION_BOOL(OPTION_QUIET)) {
        if (lnofile)
            con_out("writing '%s' and '%s'...\n", filename, lnofile);
        else
            con_out("writing '%s'\n", filename);
    }

    if (!OPTS_OPTION_BOOL(OPTION_QUIET) &&
        !OPTS_OPTION_BOOL(OPTION_PP_ONLY))
    {
        char buffer[1024];
        con_out("\nOptimizations:\n");
        for (i = 0; i < COUNT_OPTIMIZATIONS; ++i) {
            if (opts_optimizationcount[i]) {
                util_optimizationtostr(opts_opt_list[i].name, buffer, sizeof(buffer));
                con_out(
                    "    %s: %u\n",
                    buffer,
                    (unsigned int)opts_optimizationcount[i]
                );
            }
        }
    }
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {
    bool          extract   = true;
    char         *redirout  = (char*)stdout;
    char         *redirerr  = (char*)stderr;
    char         *file      = NULL;
    char        **files     = NULL;
    pak_file_t   *pak       = NULL;
    size_t        iter      = 0;

    con_init();

    /*
     * Command line option parsing commences now We only need to support
     * a few things in the test suite.
     */
    while (argc > 1) {
        ++argv;
        --argc;

        if (argv[0][0] == '-') {
            if (parsecmd("redirout",  &argc, &argv, &redirout,  1, false))
                continue;
            if (parsecmd("redirerr",  &argc, &argv, &redirerr,  1, false))
                continue;
            if (parsecmd("file",      &argc, &argv, &file,      1, false))
                continue;

            con_change(redirout, redirerr);

            switch (argv[0][1]) {
                case 'e': extract = true;  continue;
                case 'c': extract = false; continue;
            }

            if (!strcmp(argv[0]+1, "debug")) {
                OPTS_OPTION_BOOL(OPTION_DEBUG) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "memchk")) {
                OPTS_OPTION_BOOL(OPTION_MEMCHK) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "nocolor")) {
                con_color(0);
                continue;
            }
        }

        vec_push(files, argv[0]);
    }
    con_change(redirout, redirerr);


    if (!file) {
        con_err("-file must be specified for output/input PAK file\n");
        vec_free(files);
        return EXIT_FAILURE;
    }

    if (extract) {
        if (!(pak = pak_open(file, "r"))) {
            con_err("failed to open PAK file %s\n", file);
            vec_free(files);
            return EXIT_FAILURE;
        }

        if (!pak_extract_all(pak, "./")) {
            con_err("failed to extract PAK %s (files may be missing)\n", file);
            pak_close(pak);
            vec_free(files);
            return EXIT_FAILURE;
        }

        /* not possible */
        pak_close(pak);
        vec_free(files);
        stat_info();

        return EXIT_SUCCESS;
    }

    if (!(pak = pak_open(file, "w"))) {
        con_err("failed to open PAK %s for writing\n", file);
        vec_free(files);
        return EXIT_FAILURE;
    }

    for (iter = 0; iter < vec_size(files); iter++) {
        if (!(pak_insert_one(pak, files[iter]))) {
            con_err("failed inserting %s for PAK %s\n", files[iter], file);
            pak_close(pak);
            vec_free(files);
            return EXIT_FAILURE;
        }
    }

    /* not possible */
    pak_close(pak);
    vec_free(files);

    stat_info();
    return EXIT_SUCCESS;
}