1 /* radare - LGPL - Copyright 2014-2019 - pancake, dso */
2 
3 #include <r_anal.h>
4 
__switch_op_new(void)5 static RAnalSwitchOp *__switch_op_new(void) {
6 	RAnalSwitchOp * swop = R_NEW0 (RAnalSwitchOp);
7 	if (swop) {
8 		swop->cases = r_list_new ();
9 		if (!swop->cases) {
10 			free (swop);
11 			return NULL;
12 		}
13 		swop->cases->free = (void *)free;
14 		swop->min_val = swop->def_val = swop->max_val = 0;
15 	}
16 	return swop;
17 }
18 
r_anal_switch_op_new(ut64 addr,ut64 min_val,ut64 max_val,ut64 def_val)19 R_API RAnalSwitchOp *r_anal_switch_op_new(ut64 addr, ut64 min_val, ut64 max_val, ut64 def_val) {
20 	RAnalSwitchOp *swop = __switch_op_new ();
21 	if (swop) {
22 		swop->addr = addr;
23 		swop->min_val = min_val;
24 		swop->def_val = def_val;
25 		swop->max_val = max_val;
26 	}
27 	return swop;
28 }
29 
r_anal_case_op_new(ut64 addr,ut64 val,ut64 jump)30 R_API RAnalCaseOp * r_anal_case_op_new(ut64 addr, ut64 val, ut64 jump) {
31 	RAnalCaseOp *c = R_NEW0 (RAnalCaseOp);
32 	if (c) {
33 		c->addr = addr;
34 		c->value = val;
35 		c->jump = jump;
36 	}
37 	return c;
38 }
39 
r_anal_switch_op_free(RAnalSwitchOp * swop)40 R_API void r_anal_switch_op_free(RAnalSwitchOp * swop) {
41 	if (swop) {
42 		r_list_free (swop->cases);
43 		free (swop);
44 	}
45 }
46 
r_anal_switch_op_add_case(RAnalSwitchOp * swop,ut64 addr,ut64 value,ut64 jump)47 R_API RAnalCaseOp* r_anal_switch_op_add_case(RAnalSwitchOp * swop, ut64 addr, ut64 value, ut64 jump) {
48 	r_return_val_if_fail (swop && addr != UT64_MAX, NULL);
49 	RAnalCaseOp * caseop = r_anal_case_op_new (addr, value, jump);
50 	if (caseop) {
51 		r_list_append (swop->cases, caseop);
52 	}
53 	return caseop;
54 }
55