* Add missing r_egg.h

* Fix r_egg for ARM
This commit is contained in:
pancake 2011-07-27 01:29:22 +02:00
parent 26a070f5aa
commit 7595fe8aa3
4 changed files with 86 additions and 7 deletions

View File

@ -95,8 +95,8 @@ R_API void r_egg_alloc(REgg *egg, int n) {
// add esp, n
}
R_API REggLabel *r_egg_label(REgg *egg, const char *name) {
return NULL;
R_API void r_egg_label(REgg *egg, const char *name) {
r_egg_printf (egg, "%s:\n", name);
}
R_API void r_egg_raw(REgg *egg, const ut8 *b, int len) {
@ -152,10 +152,12 @@ R_API int r_egg_compile(REgg *egg) {
code = r_buf_to_string (egg->buf);
asmcode = r_asm_massemble (egg->rasm, code);
r_buf_append_bytes (egg->bin, asmcode->buf, asmcode->len);
// LEAK r_asm_code_free (asmcode);
if (asmcode) {
r_buf_append_bytes (egg->bin, asmcode->buf, asmcode->len);
// LEAK r_asm_code_free (asmcode);
}
free (code);
return R_TRUE;
return (asmcode != NULL);
}
return R_FALSE;
}

View File

@ -4,6 +4,8 @@ int main() {
int i;
RBuffer *b;
REgg *egg = r_egg_new ();
r_egg_setup (egg, "arm", 32, 0, 0);
r_egg_include (egg, "test.r", 0);
r_egg_compile (egg);

View File

@ -1,4 +1,4 @@
main@global(128) {
printf ("Hello World\n");
: int3
#// printf ("Hello World\n");
: nop
}

75
libr/include/r_egg.h Normal file
View File

@ -0,0 +1,75 @@
#ifndef _INCLUDE_R_EGG_H_
#define _INCLUDE_R_EGG_H_
#include <r_asm.h>
#include <r_util.h>
typedef struct r_egg_t {
RBuffer *src;
RBuffer *buf;
RBuffer *bin;
RList *list;
RAsm *rasm;
struct r_egg_emit_t *emit;
int endian;
int bits;
} REgg;
typedef struct r_egg_emit_t {
const char *arch;
int size; /* in bytes.. 32bit arch is 4, 64bit is 8 .. */
//const char *syscall_body;
const char* (*regs)(REgg *egg, int idx);
void (*call)(REgg *egg, const char *addr, int ptr);
//void (*sc)(int num);
void (*frame)(REgg *egg, int sz);
char* (*syscall)(REgg *egg, int num);
void (*trap)(REgg *egg);
void (*frame_end)(REgg *egg, int sz, int ctx);
void (*comment)(REgg *egg, const char *fmt, ...);
void (*push_arg)(REgg *egg, int xs, int num, const char *str);
void (*set_string)(REgg *egg, const char *dstvar, const char *str, int j);
void (*equ)(REgg *egg, const char *key, const char *value);
void (*get_result)(REgg *egg, const char *ocn);
void (*restore_stack)(REgg *egg, int size);
void (*syscall_args)(REgg *egg, int nargs);
void (*get_var)(REgg *egg, int type, char *out, int idx);
void (*while_end)(REgg *egg, const char *label);
void (*load)(REgg *egg, const char *str, int sz);
void (*load_ptr)(REgg *egg, const char *str);
void (*branch)(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst);
void (*mathop)(REgg *egg, int ch, int sz, int type, const char *eq, const char *p);
void (*get_while_end)(REgg *egg, char *out, const char *ctxpush, const char *label);
} REggEmit;
typedef struct r_egg_lang_t {
int nsyscalls;
int nargs;
int docall;
} REggLang;
#ifdef R_API
R_API REgg *r_egg_new ();
R_API char *r_egg_to_string (REgg *egg);
R_API void r_egg_free (REgg *egg);
R_API void r_egg_reset (REgg *egg);
R_API int r_egg_setup(REgg *egg, const char *arch, int bits, int endian, const char *os);
R_API int r_egg_include(REgg *egg, const char *file, int format);
R_API void r_egg_syscall(REgg *egg, const char *arg, ...);
R_API void r_egg_alloc(REgg *egg, int n);
R_API void r_egg_label(REgg *egg, const char *name);
R_API void r_egg_raw(REgg *egg, const ut8 *b, int len);
R_API void r_egg_if(REgg *egg, const char *reg, char cmp, int v);
R_API void r_egg_printf(REgg *egg, const char *fmt, ...);
R_API int r_egg_compile(REgg *egg);
R_API RBuffer *r_egg_get_bin(REgg *egg);
//R_API int r_egg_dump (REgg *egg, const char *file) { }
R_API char *r_egg_get_source(REgg *egg);
R_API RBuffer *r_egg_get_bin(REgg *egg);
R_API char *r_egg_get_assembly(REgg *egg);
/* lang.c */
R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta);
R_API int r_egg_lang_parsechar(REgg *egg, char c);
#endif
#endif