Пример #1
0
static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
{
  c->opt = opt;

  // Get the first package and the builtin package.
  ast_t* package = ast_child(program);
  ast_t* builtin = ast_sibling(package);

  // If we have only one package, we are compiling builtin itself.
  if(builtin == NULL)
    builtin = package;

  c->reach = reach_new();

  // The name of the first package is the name of the program.
  c->filename = package_filename(package);

  // LLVM context and machine settings.
  if(c->opt->library || target_is_ilp32(opt->triple))
    c->callconv = LLVMCCallConv;
  else
    c->callconv = LLVMFastCallConv;

  if(!c->opt->release || c->opt->library || c->opt->extfun)
    c->linkage = LLVMExternalLinkage;
  else
    c->linkage = LLVMPrivateLinkage;

  c->context = LLVMContextCreate();
  c->machine = make_machine(opt);
  c->target_data = LLVMGetTargetMachineData(c->machine);

  // Create a module.
  c->module = LLVMModuleCreateWithNameInContext(c->filename, c->context);

  // Set the target triple.
  LLVMSetTarget(c->module, opt->triple);

  // Set the data layout.
  char* layout = LLVMCopyStringRepOfTargetData(c->target_data);
  LLVMSetDataLayout(c->module, layout);
  LLVMDisposeMessage(layout);

  // IR builder.
  c->builder = LLVMCreateBuilderInContext(c->context);
  c->di = LLVMNewDIBuilder(c->module);

  // TODO: what LANG id should be used?
  c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di, 0x0004,
    package_filename(package), package_path(package), "ponyc-" PONY_VERSION,
    c->opt->release);

  // Empty frame stack.
  c->frame = NULL;
}
Пример #2
0
/* Ensure that the directories we need exist and are empty.
 *
 * Our base directory has the name:
 *    output/progname-docs/
 * where output/progname is the executable we are producing (without any
 * extension).
 *
 * Within this base directory we have the following:
 *    mkdocs.yml
 *    docs/
 *      *.md
 */
static void doc_setup_dirs(docgen_t* docgen, ast_t* program, pass_opt_t* opt)
{
  assert(docgen != NULL);
  assert(program != NULL);
  assert(opt != NULL);

  // First build our directory strings
  const char* output = opt->output;
  const char* progname = package_filename(ast_child(program));

  docgen->base_dir = doc_cat(output, "/", progname, "-docs/", "",
    &docgen->base_dir_buf_len);

  docgen->sub_dir = doc_cat(docgen->base_dir, "docs/", "", "", "",
    &docgen->sub_dir_buf_len);

  printf("Writing docs to %s\n", docgen->base_dir);

  // Create and clear out base directory
  pony_mkdir(docgen->base_dir);
  doc_rm_star(docgen->base_dir);

  // Create and clear out sub directory
  pony_mkdir(docgen->sub_dir);
  doc_rm_star(docgen->sub_dir);
}
Пример #3
0
Файл: dwarf.c Проект: ozra/ponyc
void dwarf_compileunit(dwarf_t* dwarf, ast_t* program)
{
  assert(ast_id(program) == TK_PROGRAM);
  ast_t* package = ast_child(program);

  const char* path = package_path(package);
  const char* name = package_filename(package); //FIX

  symbols_package(dwarf->symbols, path, name);
}
Пример #4
0
void generate_docs(ast_t* program, pass_opt_t* options)
{
  assert(program != NULL);

  if(ast_id(program) != TK_PROGRAM)
    return;

  docgen_t docgen;
  docgen.errors = options->check.errors;

  doc_setup_dirs(&docgen, program, options);

  // Open the index and home files
  docgen.index_file = doc_open_file(&docgen, false, "mkdocs", ".yml");
  docgen.home_file = doc_open_file(&docgen, true, "index", ".md");
  docgen.type_file = NULL;

  // Write documentation files
  if(docgen.index_file != NULL && docgen.home_file != NULL)
  {
    ast_t* package = ast_child(program);
    const char* name = package_filename(package);

    fprintf(docgen.home_file, "Packages\n\n");

    fprintf(docgen.index_file, "site_name: %s\n", name);
    fprintf(docgen.index_file, "theme: readthedocs\n");
    fprintf(docgen.index_file, "pages:\n");
    fprintf(docgen.index_file, "- %s: index.md\n", name);

    doc_packages(&docgen, program);
  }

  // Tidy up
  if(docgen.index_file != NULL)
    fclose(docgen.index_file);

  if(docgen.home_file != NULL)
   fclose(docgen.home_file);

  if(docgen.base_dir != NULL)
    ponyint_pool_free_size(docgen.base_dir_buf_len, (void*)docgen.base_dir);

  if(docgen.sub_dir != NULL)
    ponyint_pool_free_size(docgen.sub_dir_buf_len, (void*)docgen.sub_dir);
}
Пример #5
0
static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
{
  c->opt = opt;

  // Get the first package and the builtin package.
  ast_t* package = ast_child(program);
  ast_t* builtin = ast_sibling(package);

  // If we have only one package, we are compiling builtin itself.
  if(builtin == NULL)
    builtin = package;

  c->reachable = reach_new();
  reach_primitives(c->reachable, opt, builtin);

  // The name of the first package is the name of the program.
  c->filename = package_filename(package);

  // LLVM context and machine settings.
  c->context = LLVMContextCreate();
  c->machine = make_machine(opt);
  c->target_data = LLVMGetTargetMachineData(c->machine);

  // Create a module.
  c->module = LLVMModuleCreateWithNameInContext(c->filename, c->context);

  // Set the target triple.
  LLVMSetTarget(c->module, opt->triple);

  // Set the data layout.
  char* layout = LLVMCopyStringRepOfTargetData(c->target_data);
  LLVMSetDataLayout(c->module, layout);
  LLVMDisposeMessage(layout);

  // IR builder.
  c->builder = LLVMCreateBuilderInContext(c->context);

  // Empty frame stack.
  c->frame = NULL;
}
Пример #6
0
int main(int argc, char *argv[])
{
    static const advgetopt::getopt::option options[] = {
        {
            '\0',
            0,
            NULL,
            NULL,
            "Usage: dep2graph [-<opt>] <package> ...",
            advgetopt::getopt::help_argument
        },
        {
            '\0',
            0,
            "admindir",
            "var/lib/wpkg",
            "define the administration directory (i.e. wpkg database folder), default is /var/lib/wpkg",
            advgetopt::getopt::required_argument
        },
        {
            '\0',
            0,
            "instdir",
            "",
            "specify the installation directory, where files get unpacked, by default the root is used",
            advgetopt::getopt::required_argument
        },
        {
            '\0',
            0,
            "root",
            "/",
            "define the root directory (i.e. where everything is installed), default is /",
            advgetopt::getopt::required_argument
        },
        {
            'o',
            0,
            "output",
            NULL,
            "define a filename where the final PNG is saved",
            advgetopt::getopt::required_argument
        },
        {
            'f',
            0,
            "filename",
            NULL,
            NULL, // hidden argument in --help screen
            advgetopt::getopt::default_multiple_argument
        },
        {
            'h',
            0,
            "help",
            NULL,
            "print this help message",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "help-nobr",
            NULL,
            NULL,
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "version",
            NULL,
            "show the version of deb2graph",
            advgetopt::getopt::no_argument
        },
        {
            'v',
            0,
            "verbose",
            NULL,
            "print additional information as available",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "license",
            NULL,
            "displays the license of this tool",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "licence", // French spelling
            NULL,
            NULL, // hidden argument in --help screen
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            NULL,
            NULL,
            NULL,
            advgetopt::getopt::end_of_options
        }
    };

    std::vector<std::string> configuration_files;
    advgetopt::getopt opt(argc, argv, options, configuration_files, "");

    if(opt.is_defined("help") || opt.is_defined("help-nobr"))
    {
        opt.usage(opt.is_defined("help-nobr") ? advgetopt::getopt::no_error_nobr : advgetopt::getopt::no_error, "Usage: deb2graph [-<opt>] <package> ...");
        /*NOTREACHED*/
    }

    if(opt.is_defined("version"))
    {
        printf("%s\n", debian_packages_version_string());
        exit(1);
    }

    if(opt.is_defined("license") || opt.is_defined("licence"))
    {
        license::license();
        exit(1);
    }

    bool verbose(opt.is_defined("verbose"));

    // get the size, if zero it's undefined
    int max(opt.size("filename"));
    if(max == 0)
    {
        opt.usage(advgetopt::getopt::error, "at least one debian package must be specified on the command line");
        /*NOTREACHED*/
    }

    // all these directories have a default if not specified on the command line
    manager.set_root_path(opt.get_string("root"));
    manager.set_inst_path(opt.get_string("instdir"));
    manager.set_database_path(opt.get_string("admindir"));
    manager.set_control_file_state(std::shared_ptr<wpkg_control::control_file::control_file_state_t>(new wpkg_control::control_file::contents_control_file_state_t));

    // start creating the .dot file
    dot.create(memfile::memory_file::file_format_other);
    dot.printf("digraph {\nrankdir=BT;\nlabel=\"Debian Package Dependency Graph\";\n");

    node_names_t nodes;
    node_names_t deps; // dependencies not found on the command line

    // load all the packages
    dot.printf("/* Explicit Packages */\n");
    for(int i = 0; i < max; ++i)
    {
        std::string package_filename(opt.get_string("filename", i));
        // avoid adding the exact same package more than once
        if(verbose)
        {
            printf("Package \"%s\" loaded.\n", package_filename.c_str());
        }
        manager.load_package(package_filename);
        std::string package(manager.get_field(package_filename, "Package"));
        package_info_t info;
        info.f_package = package;
        info.f_filename = package_filename;
        info.f_nodecount = node_count;
        nodes.push_back(info);
        std::string version(manager.get_field(package_filename, "Version"));
        std::string architecture(manager.get_field(package_filename, "Architecture"));
        dot.printf("n%d [label=\"%s %s\\n%s\",shape=box];\n", node_count, package.c_str(), version.c_str(), architecture.c_str());
        ++node_count;
    }

    // edges font size to small
    dot.printf("edge [fontsize=8,fontcolor=\"#990033\",color=\"#cccccc\"];\n");

    // use the dependency fields to define all the nodes of the graph
    dot.printf("edge [style=dashed];\n");
    add_nodes(nodes, deps, "Build-Depends");
    dot.printf("edge [style=bold,color=\"#8888ff\"];\n");
    add_nodes(nodes, deps, "Pre-Depends");
    dot.printf("edge [style=solid,color=\"#aaaaaa\"];\n");
    add_nodes(nodes, deps, "Depends");
    dot.printf("edge [color=\"#ff8888\"];\n");
    add_nodes(nodes, deps, "Breaks");
    dot.printf("edge [style=bold,arrowhead=tee];\n");
    add_nodes(nodes, deps, "Conflicts");

    // close the digraph
    dot.printf("}\n");

    dot.write_file("deb2graph.dot");

    std::string cmd("dot -Tsvg deb2graph.dot >");
    if(opt.is_defined("output"))
    {
        cmd += opt.get_string("output");
    }
    else
    {
        cmd += "deb2graph.svg";
    }

    const int status = system(cmd.c_str());
    if( status == -1 )
    {
        // TODO: Add a message here stating the command could not be launched...
        return 1;
    }

    return status;
}