Example #1
0
void parse_options() {
    // Parse command line options, and update the environment to match the
    // specified options.
    argp->usage(
        "Usage: jgdoc [OPTIONS] FILE...\n"
        "Generates documentation from comments found in Jogo source files.\n\n"
        "   -o, --output DIR     Write output to DIR.\n"
        "   -i, --include DIR    Add the directory DIR to the search path.\n"
        "   -h, --help           Print this help message.\n"
        "   -f, --format FORMAT  Set output format to FORMAT.\n"
        "   -v, --verbose        Print extra information.\n"
        "   --version            Print the compiler version number.\n");

    for (ArgToken tok = argp->next(); tok; tok = argp->next()) {
        // Convert abbreviated flags into the longer descriptive form (e.g.,
        // convert -p to --path)
        if (ArgToken::SHORT == tok.type()) {
            parse_short_option(tok.value());
        } else if (ArgToken::LONG == tok.type()) {
            parse_option(tok.value());
        } else {
            env->input(tok.value());
        }
    }

    std::string gen = env->generator();
    if (gen != "Markdown") {
        argp->error("Invalid output format (options: Markdown");
    }
}
Example #2
0
void parse_option(std::string const& flag) {
    if ("library" == flag) {
        env->lib(argp->required_arg());
    } else if ("include" == flag) {
        env->include(argp->required_arg()); 
    } else if ("generator" == flag) {
        env->generator(argp->required_arg());
    } else if ("debug" == flag) {
        env->debug(true);
    } else if ("optimize" == flag) {
        env->optimize(true);
    } else if ("verbose" == flag) {
        env->verbose(true);
    } else if ("clean" == flag) {
        clean(env->build_dir());
        clean("bin");
        clean("lib");
        exit(0);
    } else if ("reset" == flag) {
        File::unlink(".jgmake");
        exit(0);
    } else {
        argp->bad_option(flag);
    }
}
Example #3
0
void parse_option(std::string const& flag) {
    if ("output" == flag) {
        env->output(argp->required_arg());
    } else if ("include" == flag) {
        env->include(argp->required_arg());
    } else if ("format" == flag) {
        env->generator(argp->required_arg());
    } else if ("verbose" == flag) {
        env->verbose(true);
    } else {
        argp->bad_option(flag);
    }
}
Example #4
0
void parse_option(std::string const& flag) {
    // Parses an option and all the corresponding arguments to that option.
    if ("verbose" == flag) {
        env->verbose(true);
    } else if ("optimize" == flag) {
        env->optimize(true);
    } else if ("assembly" == flag) {
        env->assemble(false);
        env->link(false);
    } else if ("compile" == flag) {
        env->link(false);
    } else if ("make" == flag) {
        env->make(true);
    } else if ("debug" == flag) {
        env->debug(true);
    } else if ("dump-ir" == flag) {
        env->dump_ir(true);
    } else if ("dump-ast" == flag) {
        env->dump_ast(true);
    } else if ("dump-lex" == flag) {
        env->dump_lex(true);
    } else if ("dump-liveness" == flag) {
        env->dump_liveness(true);
    } else if ("dump-regalloc" == flag) {
        env->dump_regalloc(true);
    } else if ("dump-reggraph" == flag) {
        env->dump_reggraph(true);
    } else if ("execute" == flag) {
        env->execute(true);
    } else if ("no-default-libs" == flag) {
        env->no_default_libs(true);
        // Debugger flag that prevents default modules from getting
        // loaded automatically by the parser.
    } else if ("include" == flag) {
        env->include(argp->required_arg()); 
    } else if ("output" == flag) {
        env->output(argp->required_arg());
    } else if ("build-dir" == flag) {
        env->build_dir(argp->required_arg());
    } else if ("library" == flag) {
        env->lib(argp->required_arg());
    } else if ("generator" == flag) {
        env->generator(argp->required_arg());
    } else {
        argp->bad_option(flag);
    }
}
Example #5
0
void parse_options() {
    // Parse command line options, and update the environment to match the 
    // specified options.
    argp->usage(
        "Usage: jogo [OPTIONS] FILE...\n\n"
        "Compiles Jogo source files into a library or executable.\n\n"
        "   -a, --assembly       Compile, but do not assemble or link.\n"
        "   -c, --compile        Compile and assemble, but do not link.\n"
        "   -e, --execute        Execute program as a script.\n"
        "   -d, --debug          Emit debug information.\n"
        "   -l, --library LIB    Compile and link with native library LIB.\n"
        "   -i, --include DIR    Add the directory DIR to the search path.\n"
        "   -o, --output FILE    Write compiler output to FILE.\n"
        "   -m, --make           Compile input files and out-of-date dependencies.\n"
        "   -h, --help           Print this help message.\n"
        "   -v, --verbose        Print extra information during compilation.\n"
        "   -g, --generator GEN  Use code generator GEN.\n"
        "   --build-dir DIR      Output directory for object files.\n"
        "   --dump-ir            Output the intermediate representation.\n"
        "   --dump-ast           Output the abstract syntax tree.\n"
        "   --dump-liveness      Output liveness info when printing the IR.\n"
        "   --dump-regalloc      Dump register allocations.\n"
        "   --dump-reggraph      Dump register interference graphs.\n"
        "   --version            Print the compiler version number.\n");

    for (ArgToken tok = argp->next(); tok; tok = argp->next()) {
        // Convert abbreviated flags into the longer descriptive form (e.g.,
        // convert -p to --path)
        if (ArgToken::SHORT == tok.type()) {
            parse_short_option(tok.value());
        } else if (ArgToken::LONG == tok.type()) {
            parse_option(tok.value());
        } else {
            env->input(tok.value());
        }
    } 

    std::string gen = env->generator();
    if (gen != "Intel64" && gen != "C" && gen != "Nasm64") {
        argp->error("Invalid code generator (options: Intel64, NAsm64, C)"); 
    }
    if (!env->inputs()) {
        argp->error("No input files.");
    }
}
Example #6
0
int main(int argc, char** argv) {
    // Create a new empty environment to store the AST and symbols tables, and
    // set the options for compilation.
    argp = new ArgParser(env, argc, argv);
    env->output("doc");
    env->generator("Markdown");

    parse_options();
    File::mkdir(env->output());
    env->workspace_load();

    // Run the compiler.  Output to a temporary file if the compiler will
    // continue on to another stage; otherwise, output the file directly.
    Parser::Ptr parser(new Parser(env));
    SemanticAnalyzer::Ptr semant(new SemanticAnalyzer(env));
    MarkdownGenerator::Ptr md(new MarkdownGenerator(env));

    return 0;
}
Example #7
0
void parse_options() {
    // Parse command line options, and update the environment to match the 
    // specified options.
    argp->usage(
        "Usage: jgmake [OPTIONS] PACKAGE...\n\n"
        "Builds a Jogo project from the current working directory.  Source files should\n"
        "be under ./src; output files go to ./build, ./lib, ./bin, and ./doc.  Options\n"
        "given to jgmake are recorded.  After an option is set, it will remain set the\n"
        "next time jgmake is run.\n\n"
        "   -l, --library LIB    Compile and link with native library LIB.\n"
        "   -i, --include DIR    Add the directory DIR to the search path.\n"
        "   -d, --debug          Emit debug information.\n"
        "   -o, --optimize       Enable compiler optimizations.\n"
        "   -g, --generator GEN  Use code generator GEN.\n"
        "   -h, --help           Print this help message.\n"
        "   -v, --verbose        Print extra information during compilation.\n"
        "   -r, --reset          Erase all build options.\n"
        "   -c, --clean          Remove all output directories.\n"
        "   --version            Print the program version number.\n");

    for (ArgToken tok = argp->next(); tok; tok = argp->next()) {
        // Convert abbreviated flags into the longer descriptive form (e.g.,
        // convert -p to --path)
        if (ArgToken::SHORT == tok.type()) {
            parse_short_option(tok.value());
        } else if (ArgToken::LONG == tok.type()) {
            parse_option(tok.value());
        } else {
            env->input(tok.value());
        }
    } 

    std::string gen = env->generator();
    if (gen != "Intel64" && gen != "C" && gen != "Nasm64") {
        argp->error("Invalid code generator (options: Intel64, Nasm64, C)"); 
    }
}