gdrr.c 2.39 KB
Newer Older
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * gdrr.c
 *
 *  Created on: Feb 22, 2013
 *      Author: jucs
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <dis.h>
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
12
#include "gdrr.h"
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
13

Julian Kranz's avatar
Gdrr    
Julian Kranz committed
14
15
static gdrr_sem_stmt_t *gdrr_convert_sem_stmt(__obj sem_stmt_obj,
		struct gddr_callbacks *callbacks) {
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	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_ITE: {
			sem_stmt = callbacks->sem_stmt.sem_ite(NULL, NULL, NULL);
			break;
		}
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
35
36
37
38
39
40
41
42
43
44
		case __SEM_WHILE: {
			sem_stmt = callbacks->sem_stmt.sem_while(NULL, NULL);
			break;
		}
		case __SEM_CBRANCH: {
			sem_stmt = callbacks->sem_stmt.sem_cbranch(NULL, NULL, NULL);
			break;
		}
		case __SEM_BRANCH: {
			sem_stmt = callbacks->sem_stmt.sem_branch(NULL, NULL);
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
45
46
47
48
49
50
51
			break;
		}
	}

	return sem_stmt;
}

Julian Kranz's avatar
Gdrr    
Julian Kranz committed
52
53
static gdrr_sem_stmts_t *gdrr_convert_sem_stmts(__obj sem_stmts_obj,
		struct gddr_callbacks *callbacks) {
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	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;
}

Julian Kranz's avatar
Gdrr    
Julian Kranz committed
71
72
static gdrr_sem_stmts_t *gdrr_convert_sem_stmts_list(__obj sem_stmts_obj,
		struct gddr_callbacks *callbacks) {
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	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);
}

Julian Kranz's avatar
Gdrr    
Julian Kranz committed
93
94
gdrr_sem_stmt_t *gdrr_convert_list(__obj semantics,
		struct gddr_callbacks *callbacks) {
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
95
	return gdrr_convert_sem_stmts_list(semantics, callbacks);
Julian Kranz's avatar
Gdrr    
Julian Kranz committed
96
}