本文整理汇总了C++中r_egg_printf函数的典型用法代码示例。如果您正苦于以下问题:C++ r_egg_printf函数的具体用法?C++ r_egg_printf怎么用?C++ r_egg_printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_egg_printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emit_branch
static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) {
char *p, str[64];
char *arg = NULL;
char *op = "beq";
/* NOTE that jb/ja are inverted to fit cmp opcode */
if (b) {
*b = '\0';
op = e?"bge":"bgt";
arg = b+1;
} else
if (g) {
*g = '\0';
op = e?"ble":"blt";
arg = g+1;
}
if (arg == NULL) {
if (e) {
arg = e+1;
op = "bne";
} else {
arg = "0";
op = n?"bne":"beq";
}
}
if (*arg=='=') arg++; /* for <=, >=, ... */
p = r_egg_mkvar (egg, str, arg, 0);
r_egg_printf (egg, " pop "R_AX"\n"); /* TODO: add support for more than one arg get arg0 */
r_egg_printf (egg, " cmp %s, "R_AX"\n", p);
// if (context>0)
r_egg_printf (egg, " %s %s\n", op, dst);
}
示例2: emit_mathop
static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, const char *p) {
char *op;
switch(ch) {
case '^': op = "xor"; break;
case '&': op = "and"; break;
case '|': op = "or"; break;
case '-': op = "sub"; break;
case '+': op = "add"; break;
case '*': op = "mul"; break;
case '/': op = "div"; break;
default: op = "mov"; break;
}
if (attsyntax) {
if (eq == NULL) eq = "%"R_AX;
if (p == NULL) p = "%"R_AX;
r_egg_printf (egg, " %s%c %c%s, %s\n", op, vs, type, eq, p);
} else {
if (eq == NULL) eq = R_AX;
if (p == NULL) p = R_AX;
// TODO:
#if 0
eprintf ("TYPE = %c\n", type);
eprintf (" %s%c %c%s, %s\n", op, vs, type, eq, p);
eprintf (" %s %s, [%s]\n", op, p, eq);
#endif
if (type == '*') r_egg_printf (egg, " %s %s, [%s]\n", op, p, eq);
else r_egg_printf (egg, " %s %s, %s\n", op, p, eq);
}
}
示例3: emit_frame
static void emit_frame (REgg *egg, int sz) {
r_egg_printf (egg, " push {fp,lr}\n");
if (sz>0) r_egg_printf (egg,
//" mov "R_BP", "R_SP"\n"
" add fp, sp, $4\n" // size of arguments
" sub sp, $%d\n", sz); // size of stackframe 8, 16, ..
}
示例4: parsedatachar
static int parsedatachar(REgg *egg, char c) {
static int inlinectr = 0;
char *str;
int i, j;
if (!dstval) {
return 0;
}
/* skip until '{' */
if (c == '{') { /* XXX: repeated code!! */
rcc_context (egg, 1);
if (++inlinectr==1)
return (ndstval = 0);
} else if (inlinectr == 0) {
/* capture value between parenthesis [email protected](NNN) { ... } */
if (c==')') {
stackframe = atoi (dstval);
ndstval = 0;
} else {
dstval[ndstval++] = c;
}
return 0;
}
/* capture body */
if (c == '}') { /* XXX: repeated code!! */
if (CTX< 2) {
inlinectr = 0;
rcc_context (egg, -1);
slurp = 0;
mode = NORMAL;
/* register */
if (dstval != NULL && dstvar != NULL) {
dstval[ndstval]='\0';
egg->remit->comment (egg, "data (%s)(%s)size=(%d)\n",
dstvar, dstval, stackframe);
r_egg_printf (egg, ".data\n");
for (str=dstval; is_space (*str); str++);
j = (stackframe)? stackframe: 1;
/* emit label */
r_egg_printf (egg, "%s:\n", dstvar);
for (i=1; i<=j; i++) {
if (*str=='"')
r_egg_printf (egg, ".ascii %s%s\n", dstval, (i==j)?"\"\\x00\"":"");
else r_egg_printf (egg, ".long %s\n", dstval);
}
r_egg_printf (egg, ".text\n");
R_FREE (dstvar);
R_FREE (dstval);
ndstval = 0;
CTX = 0;
return 1;
}
}
}
dstval[ndstval++] = c;
return 0;
}
示例5: emit_comment
static void emit_comment(REgg *egg, const char *fmt, ...) {
va_list ap;
char buf[1024];
va_start (ap, fmt);
vsnprintf (buf, sizeof (buf), fmt, ap);
if (attsyntax) r_egg_printf (egg, " /* %s */\n", buf);
else r_egg_printf (egg, "# %s\n", buf);
va_end (ap);
}
示例6: emit_arg
static void emit_arg (REgg *egg, int xs, int num, const char *str) {
int d = atoi (str);
if (!attsyntax && (*str=='$'))
str = str +1;
switch (xs) {
case 0:
r_egg_printf (egg, " push %s\n", str);
break;
case '*':
if (attsyntax) r_egg_printf (egg, " push (%s)\n", str);
else r_egg_printf (egg, " push [%s]\n", str);
break;
case '&':
if (attsyntax) {
if (d != 0) r_egg_printf (egg, " addl $%d, %%"R_BP"\n", d);
r_egg_printf (egg, " pushl %%"R_BP"\n");
if (d != 0) r_egg_printf (egg, " subl $%d, %%"R_BP"\n", d);
} else {
if (d != 0) r_egg_printf (egg, " add "R_BP", %d\n", d);
r_egg_printf (egg, " push "R_BP"\n");
if (d != 0) r_egg_printf (egg, " sub "R_BP", %d\n", d);
}
break;
}
}
示例7: emit_branch
static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) {
char *p, str[64];
char *arg = NULL;
char *op = "jz";
int signed_value = 1; // XXX: add support for signed/unsigned variables
/* NOTE that jb/ja are inverted to fit cmp opcode */
if (b) {
*b = '\0';
if (signed_value) {
if (e) op = "jge";
else op = "jg";
} else {
if (e) op = "jae";
else op = "ja";
}
arg = b+1;
} else
if (g) {
*g = '\0';
if (signed_value) {
if (e) op = "jle";
else op = "jl";
} else {
if (e) op = "jbe";
else op = "jb";
}
arg = g+1;
}
if (arg == NULL) {
if (e) {
arg = e+1;
op = "jne";
} else {
arg = attsyntax? "$0": "0";
if (n) op = "jnz";
else op ="jz";
}
}
if (*arg=='=') arg++; /* for <=, >=, ... */
p = r_egg_mkvar (egg, str, arg, 0);
if (attsyntax) {
r_egg_printf (egg, " pop %%"R_AX"\n"); /* TODO: add support for more than one arg get arg0 */
r_egg_printf (egg, " cmp%c %s, %%"R_AX"\n", sz, p);
} else {
r_egg_printf (egg, " pop "R_AX"\n"); /* TODO: add support for more than one arg get arg0 */
r_egg_printf (egg, " cmp "R_AX", %s\n", p);
}
// if (context>0)
free (p);
r_egg_printf (egg, " %s %s\n", op, dst);
}
示例8: emit_call
static void emit_call(REgg *egg, const char *str, int atr) {
int i;
//r_egg_printf (egg, " ARGS=%d CALL(%s,%d)\n", lastarg, str, atr);
for (i=0;i<lastarg;i++) {
r_egg_printf (egg, " ldr r%d, [%s]\n", lastarg-1-i, lastargs[i]);
lastargs[i][0] = 0;
}
if (atr) {
r_egg_printf (egg, " ldr r0, %s", str);
r_egg_printf (egg, " blx r0\n");
} else r_egg_printf (egg, " bl %s\n", str);
}
示例9: emit_frame_end
static void emit_frame_end (REgg *egg, int sz, int ctx) {
if (sz>0) {
if (attsyntax) {
r_egg_printf (egg, " add $%d, %%"R_SP"\n", sz);
r_egg_printf (egg, " pop %%"R_BP"\n");
} else {
r_egg_printf (egg, " add "R_SP", %d\n", sz);
r_egg_printf (egg, " pop "R_BP"\n");
}
}
if (ctx>0)
r_egg_printf (egg, " ret\n");
}
示例10: emit_frame
static void emit_frame (REgg *egg, int sz) {
if (sz<1)
return;
if (attsyntax)
r_egg_printf (egg,
" push %%"R_BP"\n"
" mov %%"R_SP", %%"R_BP"\n"
" sub $%d, %%"R_SP"\n", sz);
else r_egg_printf (egg,
" push "R_BP"\n"
" mov "R_BP", "R_SP"\n"
" sub "R_SP", %d\n", sz);
}
示例11: emit_load_ptr
static void emit_load_ptr(REgg *egg, const char *dst) {
int d = atoi (dst);
if (d == 0) { // hack to handle stackvarptrz
char *p = strchr (dst, '+');
if (p) d = atoi (p+1);
}
//eprintf ("emit_load_ptr: HACK\n");
// XXX: 32/64bit care
//r_egg_printf (egg, "# DELTA IS (%s)\n", dst);
if (attsyntax) r_egg_printf (egg, " leal %d(%%"R_BP"), %%"R_AX"\n", d);
else r_egg_printf (egg, " lea "R_AX", ["R_BP"+%d]\n", d);
//r_egg_printf (egg, " movl %%"R_BP", %%"R_AX"\n");
//r_egg_printf (egg, " addl $%d, %%"R_AX"\n", d);
}
示例12: emit_syscall_args
static void emit_syscall_args(REgg *egg, int nargs) {
int j, k;
for (j=0; j<nargs; j++) {
k = j*R_SZ;
if (attsyntax)
r_egg_printf (egg, " mov %d(%%"R_SP"), %%%s\n", k, regs[j+1]);
else {
if (k>0)
r_egg_printf (egg, " mov %s, ["R_SP"+%d]\n", regs[j+1], k);
else if (k<0)
r_egg_printf (egg, " mov %s, ["R_SP"%d]\n", regs[j+1], k);
else r_egg_printf (egg, " mov %s, ["R_SP"]\n", regs[j+1]);
}
}
}
示例13: emit_syscall_args
static void emit_syscall_args(REgg *egg, int nargs) {
int j, k;
for (j=0; j<nargs; j++) {
k = j*R_SZ;
r_egg_printf (egg, " ldr %s, [sp, #%c%d]\n", regs[j+1], k>0?'+':' ', k);
}
}
示例14: emit_syscall_args
static void emit_syscall_args(REgg *egg, int nargs) {
int j, k;
for (j = 0; j < nargs; j++) {
k = j * R_SZ;
r_egg_printf (egg, " ldr %s, [sp, %d]\n",
regs[j+1], k?k+4:k+8);
}
}
示例15: emit_set_string
static void emit_set_string(REgg *egg, const char *dstvar, const char *str, int j) {
int rest, off = 0;
off = strlen (str)+1;
rest = (off%4);
if (rest) rest = 4-rest;
off += rest-8;
r_egg_printf (egg, " add pc, $%d\n", (off));
// XXX: does not handle \n and so on.. must use r_util
r_egg_printf (egg, ".string \"%s\"\n", str);
if (rest) r_egg_printf (egg, ".fill %d, 1, 0\n", (rest));
r_egg_printf (egg, " sub r0, pc, $%d\n", off+16);
{
char str[32], *p = r_egg_mkvar (egg, str, dstvar, 0);
//r_egg_printf (egg, "DSTVAR=%s --> %s\n", dstvar, p);
r_egg_printf (egg, " str r0, [%s]\n", p);
free (p);
}
}