Ejemplo n.º 1
0
int
sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
        PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
{
    int	i, n, nparts;
    char *db_mrg = "unable to merge package and system information";

    if (a_zoneName == (char *)NULL) {
        echo(gettext("## Processing package information."));
    } else {
        echo(gettext("## Processing package information in zone <%s>."),
             a_zoneName);
    }

    /*
     * The following instruction puts the client-relative basedir
     * into the environment iff it's a relocatable package and
     * we're installing to a client. Otherwise, it uses the regular
     * basedir. The only reason for this is so that mappath() upon
     * finding $BASEDIR in a path will properly resolve it to the
     * client-relative path. This way eval_path() can properly
     * construct the server-relative path.
     */
    if (is_relocatable() && is_an_inst_root())
        putparam("BASEDIR", get_info_basedir());

    /*
     * read the pkgmap provided by this package into
     * memory; map parameters specified in the pathname
     * and sort in memory by pathname
     */

    vfpRewind(pkgmapVfp);		/* rewind input file */

    *extlist = pkgobjmap(pkgmapVfp, 2, NULL);

    if (*extlist == NULL) {
        progerr(gettext("unable to process pkgmap"));
        quit(99);
    }

    /* Make all paths client-relative if necessary. */
    if (is_an_inst_root()) {
        (void) client_refer(*extlist);
    }

    if (a_zoneName == (char *)NULL) {
        echo(gettext("## Processing system information."));
    } else {
        echo(gettext("## Processing system information in zone <%s>."),
             a_zoneName);
    }

    /*
     * calculate the number of parts in this package
     * by locating the entry with the largest "volno"
     * associated with it
     */
    nparts = 0;
    if (is_depend_pkginfo_DB() == B_FALSE) {
        for (i = 0; (*extlist)[i]; i++) {
            n = (*extlist)[i]->cf_ent.volno;
            if (n > nparts)
                nparts = n;
        }

        vfpTruncate(tmpvfp);

        dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
        if (dbchg < 0) {
            progerr(gettext(db_mrg));
            quit(99);
        }
    }

    /* Restore the original BASEDIR. */
    if (is_relocatable() && is_an_inst_root())
        putparam("BASEDIR", get_basedir());

    if (is_an_inst_root()) {
        (void) server_refer(*extlist);
    }

    return (nparts);
}
int main(int argc, char **argv)
{
	char *output_file = NULL;
	char *entry_table_file = NULL;
	FILE *output = stdout;
	FILE *export_file;
	struct brw_program_instruction *entry, *entry1, *tmp_entry;
	int err, inst_offset;
	char o;
	void *mem_ctx;

	while ((o = getopt_long(argc, argv, "e:l:o:g:abW", longopts, NULL)) != -1) {
		switch (o) {
		case 'o':
			if (strcmp(optarg, "-") != 0)
				output_file = optarg;

			break;

		case 'g': {
			char *dec_ptr, *end_ptr;
			unsigned long decimal;

			gen_level = strtol(optarg, &dec_ptr, 10) * 10;

			if (*dec_ptr == '.') {
				decimal = strtoul(++dec_ptr, &end_ptr, 10);
				if (end_ptr != dec_ptr && *end_ptr == '\0') {
					if (decimal > 10) {
						fprintf(stderr, "Invalid Gen X decimal version\n");
						exit(1);
					}
					gen_level += decimal;
				}
			}

			if (gen_level < 40 || gen_level > 90) {
				usage();
				exit(1);
			}

			break;
		}

		case 'a':
			advanced_flag = 1;
			break;
		case 'b':
			binary_like_output = 1;
			break;

		case 'e':
			need_export = 1;
			if (strcmp(optarg, "-") != 0)
				export_filename = optarg;
			break;

		case 'l':
			if (strcmp(optarg, "-") != 0)
				entry_table_file = optarg;
			break;

		case 'W':
			warning_flags |= WARN_ALL;
			break;

		default:
			usage();
			exit(1);
		}
	}
	argc -= optind;
	argv += optind;
	if (argc != 1) {
		usage();
		exit(1);
	}

	if (strcmp(argv[0], "-") != 0) {
		input_filename = argv[0];
		yyin = fopen(input_filename, "r");
		if (yyin == NULL) {
			perror("Couldn't open input file");
			exit(1);
		}
	}

	brw_init_context(&genasm_brw_context, gen_level);
	mem_ctx = ralloc_context(NULL);
	brw_init_compile(&genasm_brw_context, &genasm_compile, mem_ctx);

	err = yyparse();

	if (strcmp(argv[0], "-"))
		fclose(yyin);

	yylex_destroy();

	if (err || errors)
		exit (1);

	if (output_file) {
		output = fopen(output_file, "w");
		if (output == NULL) {
			perror("Couldn't open output file");
			exit(1);
		}

	}

	if (read_entry_file(entry_table_file)) {
		fprintf(stderr, "Read entry file error\n");
		exit(1);
	}
	inst_offset = 0 ;
	for (entry = compiled_program.first;
		entry != NULL; entry = entry->next) {
	    entry->inst_offset = inst_offset;
	    entry1 = entry->next;
	    if (entry1 && is_label(entry1) && is_entry_point(entry1)) {
		// insert NOP instructions until (inst_offset+1) % 4 == 0
		while (((inst_offset+1) % 4) != 0) {
		    tmp_entry = calloc(sizeof(*tmp_entry), 1);
		    tmp_entry->insn.gen.header.opcode = BRW_OPCODE_NOP;
		    entry->next = tmp_entry;
		    tmp_entry->next = entry1;
		    entry = tmp_entry;
		    tmp_entry->inst_offset = ++inst_offset;
		}
	    }
	    if (!is_label(entry))
              inst_offset++;
	}

	for (entry = compiled_program.first; entry; entry = entry->next)
	    if (is_label(entry))
		add_label(entry);

	if (need_export) {
		if (export_filename) {
			export_file = fopen(export_filename, "w");
		} else {
			export_file = fopen("export.inc", "w");
		}
		for (entry = compiled_program.first;
			entry != NULL; entry = entry->next) {
		    if (is_label(entry))
			fprintf(export_file, "#define %s_IP %d\n",
				label_name(entry), (IS_GENx(5) ? 2 : 1)*(entry->inst_offset));
		}
		fclose(export_file);
	}

	for (entry = compiled_program.first; entry; entry = entry->next) {
	    struct relocation *reloc = &entry->reloc;

	    if (!is_relocatable(entry))
		continue;

	    if (reloc->first_reloc_target)
		reloc->first_reloc_offset = label_to_addr(reloc->first_reloc_target, entry->inst_offset) - entry->inst_offset;

	    if (reloc->second_reloc_target)
		reloc->second_reloc_offset = label_to_addr(reloc->second_reloc_target, entry->inst_offset) - entry->inst_offset;

	    if (reloc->second_reloc_offset) { // this is a branch instruction with two offset arguments
                set_branch_two_offsets(entry, reloc->first_reloc_offset, reloc->second_reloc_offset);
	    } else if (reloc->first_reloc_offset) {
                set_branch_one_offset(entry, reloc->first_reloc_offset);
	    }
	}

	if (binary_like_output)
		fprintf(output, "%s", binary_prepend);

	for (entry = compiled_program.first;
		entry != NULL;
		entry = entry1) {
	    entry1 = entry->next;
	    if (!is_label(entry))
		print_instruction(output, &entry->insn.gen);
	    else
		free(entry->insn.label.name);
	    free(entry);
	}
	if (binary_like_output)
		fprintf(output, "};");

	free_entry_point_table(entry_point_table);
	free_hash_table(declared_register_table);
	free_label_table(label_table);

	fflush (output);
	if (ferror (output)) {
	    perror ("Could not flush output file");
	    if (output_file)
		unlink (output_file);
	    err = 1;
	}
	return err;
}