Пример #1
0
def parse_config(file_name):
    # Before parsing, clean old data
    CompilerSpecs.all_comp_specs = dict()
    CompilerTarget.all_targets = []

    # Parse
    config_file = common.check_and_open_file(file_name, "r")
    config = config_file.read().splitlines()
    config_file.close()
    if not any(s.startswith(comp_specs_line) for s in config) or not any(s.startswith(test_sets_line) for s in config):
        common.print_and_exit("Invalid config file! Check it!")
    config_iter = iter(config)
    for config_line in config_iter:
        if skip_line(config_line):
            continue
        if config_line.startswith(comp_specs_line):
            read_compiler_specs(config_iter, add_specs, test_sets_line)
            read_compiler_specs(config_iter, add_sets, stats_capt_opt_line)
            read_compiler_specs(config_iter, add_stats_options)
Пример #2
0
def gen_makefile(out_file_name,
                 force,
                 config_file,
                 only_target=None,
                 inject_blame_opt=None,
                 creduce_file=None,
                 stat_targets=None):
    # Somebody can prepare test specs and target, so we don't need to parse config file
    check_if_std_defined()
    if config_file is not None:
        parse_config(config_file)
    output = ""
    if stat_targets is not None:
        stat_targets = list(set(stat_targets))
    # 1. License
    license_file = common.check_and_open_file(
        os.path.abspath(common.yarpgen_scripts + os.sep + ".." + os.sep +
                        license_file_name), "r")
    for license_str in license_file:
        output += "#" + license_str
    license_file.close()
    output += "###############################################################################\n"

    output += "#This file was generated automatically.\n"
    output += "#If you want to make a permanent changes, you should edit gen_test_makefile.py\n"
    output += "###############################################################################\n\n"

    # 2. Define common variables
    for makefile_variable in Makefile_variable_list:
        test_pwd = ""
        if creduce_file and makefile_variable.name == "CXXFLAGS":
            test_pwd = " -I$(TEST_PWD)"
        output += makefile_variable.name + "=" + makefile_variable.value + test_pwd + "\n"
    output += "\n"

    # 3. Define build targets
    for target in CompilerTarget.all_targets:
        if only_target is not None and only_target.name != target.name:
            continue
        compiler_name = None
        if selected_standard.is_c():
            compiler_name = target.specs.comp_c_name
        if selected_standard.is_cxx():
            compiler_name = target.specs.comp_cxx_name
        output += target.name + ": " + "COMPILER=" + compiler_name + "\n"

        optflags_str = target.name + ": " + "OPTFLAGS=" + target.args
        if target.arch.comp_name != "":
            optflags_str += " " + target.specs.arch_prefix + target.arch.comp_name
        optflags_str += "\n"
        output += optflags_str
        # For performance reasons driver should always be compiled with -O0
        output += re.sub("-O\d", "-O0",
                         (optflags_str.replace("OPTFLAGS", "DRIVER_OPTFLAGS")))

        if inject_blame_opt is not None:
            output += target.name + ": " + "BLAMEOPTS=" + inject_blame_opt + "\n"
        #TODO: one day we can decide to use gcc also.
        if stat_targets is not None:
            for stat_target in stat_targets:
                if target.name == stat_target:
                    output += target.name + ": " + stat_options.name + "=" + \
                              StatisticsOptions.get_options(target.specs) + "\n"
                    stat_targets.remove(stat_target)
        output += target.name + ": " + "EXECUTABLE=" + target.name + "_" + executable.value + "\n"
        output += target.name + ": " + "$(addprefix " + target.name + "_,"
        if common.selected_gen_std != common.GenStdID.ISPC:
            output += "$(SOURCES:" + get_file_ext() + "=.o))\n"
        else:
            output += "$(patsubst %.ispc,%.o," + "$(SOURCES:" + get_file_ext(
            ) + "=.o))" + ")\n"
        output += "\t" + "$(COMPILER) $(LDFLAGS) $(STDFLAGS) $(OPTFLAGS) -o $(EXECUTABLE) $^\n\n"

    if stat_targets is not None and len(stat_targets) != 0:
        common.log_msg(logging.WARNING,
                       "Can't find relevant stat_targets: " +
                       str(stat_targets),
                       forced_duplication=True)

    # 4. Force make to rebuild everything
    # TODO: replace with PHONY
    output += "FORCE:\n\n"

    for source in sources.value.split():
        source_prefix = ""
        force_str = " FORCE\n"
        if creduce_file and creduce_file != source:
            source_prefix = "$(TEST_PWD)/"
            force_str = "\n"
        source_name = source.split(".")[0]
        output += "%" + source_name + ".o: " + source_prefix + source + force_str
        # For performance reasons driver should always be compiled with -O0
        optflags_name = "$(OPTFLAGS)" if source_name != "driver" else "$(DRIVER_OPTFLAGS)"
        output += "\t" + "$(COMPILER) $(CXXFLAGS) $(STDFLAGS) " + optflags_name + " -o $@ -c $<"
        if source_name == "func":
            output += " $(STATFLAGS) "
            if inject_blame_opt is not None:
                output += " $(BLAMEOPTS) "
        output += "\n\n"

    output += "clean:\n"
    output += "\trm *.o *_$(EXECUTABLE)\n\n"

    # 5. Define run targets
    native_arch = detect_native_arch()
    for target in CompilerTarget.all_targets:
        if only_target is not None and only_target.name != target.name:
            continue
        output += "run_" + target.name + ": " + target.name + "_" + executable.value + "\n"
        output += "\t@"
        required_sde_arch = define_sde_arch(native_arch, target.arch.sde_arch)
        if required_sde_arch != "":
            output += "sde -" + required_sde_arch + " -- "
        output += "." + os.sep + target.name + "_" + executable.value + "\n\n"

    out_file = None
    if not os.path.isfile(out_file_name):
        out_file = open(out_file_name, "w")
    else:
        if force:
            out_file = open(out_file_name, "w")
        else:
            common.print_and_exit(
                "File already exists. Use -f if you want to rewrite it.")
    out_file.write(output)
    out_file.close()