示例#1
0
文件: irargs.c 项目: mj3-16/libfirm
static int bitset_emit(lc_appendable_t *app, const lc_arg_occ_t *occ,
                       const lc_arg_value_t *arg)
{
	int res = 0;
	lc_arg_append(app, occ, "[", 1);
	++res;
	const char *prefix = "";
	bitset_t *b = (bitset_t*)arg->v_ptr;
	bitset_foreach(b, p) {
		char buf[32];
		int  n = snprintf(buf, sizeof(buf), "%s%d", prefix, (int) p);
		lc_arg_append(app, occ, buf, n);
		prefix = ", ";
		res += n;
	}
示例#2
0
static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *val)
{
	char fmt[32];
	int res = 0;

	make_fmt(fmt, sizeof(fmt), occ);

	switch (occ->conversion) {
		/* Store the number of written characters in the given
		 * int pointer location */
		case 'n': {
			int *num = (int*)val->v_ptr;
			*num = (int)app->written;
			break;
		}

		/* strings are dumped directly, since they can get really big. A
		 * buffer of 128 letters for all other types should be enough. */
		case 's': {
			const char *str = (const char*)val->v_ptr;
			res = lc_arg_append(app, occ, str, strlen(str));
			break;
		}

		default: {
			int len = MAX(128, occ->width + 1);
			char *buf = XMALLOCN(char, len);
			res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
			res = lc_appendable_snadd(app, buf, res);
			free(buf);
		}
	}

	return res;
}