Commit 1fa59081 authored by Julian Kranz's avatar Julian Kranz

Gdrr

- Continued to implement gdrr
parent c3d60bb0
......@@ -10,6 +10,43 @@
#include <dis.h>
void test(__obj semantics);
typedef void gdrr_sem_stmt_t;
typedef void gdrr_sem_stmts_t;
typedef void gdrr_sem_linear_t;
typedef void gdrr_sem_var_t;
typedef void gdrr_sem_op_t;
typedef void gdrr_sem_address_t;
struct gddr_sem_stmts_callbacks {
gdrr_sem_stmts_t *(*sem_cons)(gdrr_sem_stmt_t *hd, gdrr_sem_stmts_t *tl);
gdrr_sem_stmts_t *(*sem_nil)(void);
};
struct gddr_sem_stmts_list_callbacks {
gdrr_sem_stmts_t *(*list_init)(void);
gdrr_sem_stmts_t *(*list_next)(gdrr_sem_stmt_t *next, gdrr_sem_stmts_t *list);
};
struct gddr_sem_stmt_callbacks {
gdrr_sem_stmt_t *(*sem_assign)(gdrr_sem_var_t *lhs, gdrr_sem_op_t *rhs);
gdrr_sem_stmt_t *(*sem_load)(gdrr_sem_var_t *lhs, __word size,
gdrr_sem_address_t *address);
gdrr_sem_stmt_t *(*sem_store)(gdrr_sem_var_t *lhs, gdrr_sem_op_t *rhs);
gdrr_sem_stmt_t *(*sem_ite)(gdrr_sem_linear_t *cond,
gdrr_sem_stmts_t *then_branch, gdrr_sem_stmts_t *else_branch);
};
struct gddr_callbacks {
union {
struct gddr_sem_stmts_callbacks sem_stmts;
struct gddr_sem_stmts_list_callbacks sem_stmts_list;
};
struct gddr_sem_stmt_callbacks sem_stmt;
};
gdrr_sem_stmt_t *gdrr_convert(__obj semantics, struct gddr_callbacks *callbacks);
gdrr_sem_stmt_t *gdrr_convert_list(__obj semantics,
struct gddr_callbacks *callbacks);
#endif /* GDRR_H_ */
......@@ -9,33 +9,79 @@
#include <stdio.h>
#include <stdint.h>
#include <dis.h>
#include "gdrr.h"
void test(__obj semantics) {
printf(":-)\n");
while (__CASETAGCON(semantics)==__SEM_CONS) {
__obj rec = __DECON(semantics);
__obj instr = __RECORD_SELECT(rec, ___hd);
switch (__CASETAGCON(instr)) {
case __SEM_ASSIGN: {
printf("assign\n");
break;
}
case __SEM_XOR: {
printf("xor\n");
break;
}
case __SEM_ITE: {
printf("ite\n");
break;
}
default: {
printf("%d\n", __CASETAGCON(instr));
break;
}
}
semantics = __RECORD_SELECT(rec, ___tl);
};
static gdrr_sem_stmt_t *gdrr_convert_sem_stmt(__obj sem_stmt_obj, struct gddr_callbacks *callbacks) {
gdrr_sem_stmt_t *sem_stmt = NULL;
switch(__CASETAGCON(sem_stmt_obj)) {
case __SEM_ASSIGN: {
sem_stmt = callbacks->sem_stmt.sem_assign(NULL, NULL);
break;
}
case __SEM_LOAD: {
sem_stmt = callbacks->sem_stmt.sem_load(NULL, 0, NULL);
break;
}
case __SEM_STORE: {
sem_stmt = callbacks->sem_stmt.sem_store(NULL, NULL);
break;
}
case __SEM_XOR: {
break;
}
case __SEM_ITE: {
sem_stmt = callbacks->sem_stmt.sem_ite(NULL, NULL, NULL);
break;
}
default: {
// printf("%d\n", __CASETAGCON(instr));
break;
}
}
return sem_stmt;
}
static gdrr_sem_stmts_t *gdrr_convert_sem_stmts(__obj sem_stmts_obj, struct gddr_callbacks *callbacks) {
gdrr_sem_stmts_t *sem_stmts = NULL;
if(__CASETAGCON(sem_stmts_obj) == __SEM_CONS) {
__obj rec = __DECON(sem_stmts_obj);
__obj instr = __RECORD_SELECT(rec, ___hd);
__obj tl_obj = __RECORD_SELECT(rec, ___tl);
gdrr_sem_stmts_t *tl = gdrr_convert_sem_stmts(tl_obj, callbacks);
gdrr_sem_stmt_t *hd = gdrr_convert_sem_stmt(instr, callbacks);
sem_stmts = callbacks->sem_stmts.sem_cons(hd, tl);
} else
sem_stmts = callbacks->sem_stmts.sem_nil();
return sem_stmts;
}
static gdrr_sem_stmts_t *gdrr_convert_sem_stmts_list(__obj sem_stmts_obj, struct gddr_callbacks *callbacks) {
gdrr_sem_stmts_t *list = callbacks->sem_stmts_list.list_init();
while(__CASETAGCON(sem_stmts_obj) == __SEM_CONS) {
__obj rec = __DECON(sem_stmts_obj);
__obj instr = __RECORD_SELECT(rec, ___hd);
__obj tl_obj = __RECORD_SELECT(rec, ___tl);
gdrr_sem_stmt_t *next = gdrr_convert_sem_stmt(instr, callbacks);
list = callbacks->sem_stmts_list.list_next(next, list);
sem_stmts_obj = tl_obj;
}
return list;
}
gdrr_sem_stmt_t *gdrr_convert(__obj semantics, struct gddr_callbacks *callbacks) {
return gdrr_convert_sem_stmts(semantics, callbacks);
}
gdrr_sem_stmt_t *gdrr_convert_list(__obj semantics, struct gddr_callbacks *callbacks) {
return gdrr_convert_sem_stmts_list(semantics, callbacks);
}
......@@ -30,7 +30,7 @@ main:
#notq %rcx
negq %r10
#negq %r10
#mulq (%ebx)
......
......@@ -6,6 +6,42 @@
#include <dis.h>
#include <gdrr.h>
gdrr_sem_stmts_t *list_next(gdrr_sem_stmt_t *next, gdrr_sem_stmts_t *list) {
printf("next statement\n");
return NULL;
}
gdrr_sem_stmts_t *list_init() {
printf("init\n");
return NULL;
}
gdrr_sem_stmt_t *sem_assign(gdrr_sem_var_t *lhs, gdrr_sem_op_t *rhs) {
printf("assign\n");
return NULL;
}
gdrr_sem_stmt_t *sem_load(gdrr_sem_var_t *lhs, __word size, gdrr_sem_address_t *address) {
printf("load\n");
return NULL;
}
gdrr_sem_stmt_t *sem_store(gdrr_sem_var_t *lhs, gdrr_sem_op_t *rhs) {
printf("store\n");
return NULL;
}
gdrr_sem_stmt_t *sem_ite(gdrr_sem_linear_t *cond, gdrr_sem_stmts_t *then_branch, gdrr_sem_stmts_t *else_branch) {
printf("ite\n");
return NULL;
}
int main (int argc, char** argv) {
__char blob[15];
char fmt[1024];
......@@ -38,8 +74,17 @@ done:
else {
__pretty(__rreil_pretty__,r,fmt,1024);
puts(fmt);
test(r);
struct gddr_callbacks callbacks;
callbacks.sem_stmts_list.list_init = &list_init;
callbacks.sem_stmts_list.list_next = &list_next;
callbacks.sem_stmt.sem_assign = &sem_assign;
callbacks.sem_stmt.sem_load = &sem_load;
callbacks.sem_stmt.sem_store = &sem_store;
callbacks.sem_stmt.sem_ite = &sem_ite;
gdrr_convert(r, &callbacks);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment