Commit 91953857 authored by Julian Kranz's avatar Julian Kranz

RReil: Moved SEM_ARB to sem_sexpr

RReil: sem_op => sem_expr
RReil: Moved sem_prim to sem_stmt
RReil: SEM_LIN / SEM_CMP => SEM_SEXPR in sem_expr
parent 489d7ad3
......@@ -370,6 +370,10 @@ public class NativeInterface {
private Object sem_sexpr_cmp(Object _this) {
return builder.sem_sexpr_cmp((ICompare) _this);
}
private Object sem_sexpr_arb() {
return builder.sem_sexpr_arb();
}
/*
* sem_op_cmp
......@@ -473,10 +477,6 @@ public class NativeInterface {
(ILinearExpression) opnd1);
}
private Object sem_arb(Object size) {
return builder.sem_arb((Long) size);
}
/*
* sem_varl
*/
......@@ -589,8 +589,9 @@ public class NativeInterface {
* sem_stmts
*/
@SuppressWarnings("unchecked")
private Object list_next(Object next, Object list) {
return builder.list_next((IStatement) next, (IRReilCollection) list);
return builder.list_next((IStatement) next, (IRReilCollection<IStatement>) list);
}
private Object list_init() {
......
......@@ -442,6 +442,10 @@ static obj_t sem_sexpr_cmp(state_t state, obj_t this) {
jobject ret = java_method_call(state, "sem_sexpr_cmp", 1, (jobject)this);
return (obj_t)ret;
}
static obj_t sem_sexpr_arb(state_t state, obj_t nothing) {
jobject ret = java_method_call(state, "sem_sexpr_arb", 0);
return (obj_t)ret;
}
// sem_op_cmp
static obj_t sem_cmpeq(state_t state, int_t size, obj_t opnd1, obj_t opnd2) {
......@@ -540,10 +544,6 @@ static obj_t sem_zx(state_t state, int_t size, int_t fromsize, obj_t opnd1) {
java_long_create(state, (long int)fromsize), (jobject)opnd1);
return (obj_t)ret;
}
static obj_t sem_arb(state_t state, int_t size) {
jobject ret = java_method_call(state, "sem_arb", 1, java_long_create(state, (long int)size));
return (obj_t)ret;
}
// sem_varl
static obj_t sem_varl(state_t state, obj_t id, int_t offset, int_t size) {
......@@ -716,7 +716,8 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
unboxed_sem_sexpr_callbacks_t sem_sexpr_callbacks = {
.sem_sexpr_lin = &sem_sexpr_lin,
.sem_sexpr_cmp = &sem_sexpr_cmp
.sem_sexpr_cmp = &sem_sexpr_cmp,
.sem_sexpr_arb = &sem_sexpr_arb
};
unboxed_sem_op_cmp_callbacks_t sem_op_cmp_callbacks = {
......@@ -742,7 +743,6 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
.sem_xor = &sem_xor,
.sem_sx = &sem_sx,
.sem_zx = &sem_zx,
.sem_arb = &sem_arb
};
unboxed_sem_varl_callbacks_t sem_varl_callbacks = {
......
package rreil;
import rreil.expression.And;
import rreil.expression.Arbitrary;
import rreil.expression.CompareEqual;
import rreil.expression.CompareLessOrEqualSigned;
import rreil.expression.CompareLessOrEqualUnsigned;
......@@ -44,6 +43,7 @@ import rreil.linear.LinearImmediateExpression;
import rreil.linear.LinearScaleExpression;
import rreil.linear.LinearSubtractionExpression;
import rreil.linear.LinearVariableExpression;
import rreil.sexpression.Arbitrary;
import rreil.sexpression.ISimpleExpression;
import rreil.sexpression.SimpleCompareExpression;
import rreil.sexpression.SimpleExpression;
......@@ -460,6 +460,11 @@ public class DefaultRReilBuilder implements IRReilBuilder {
public SimpleCompareExpression sem_sexpr_cmp(ICompare _this) {
return new SimpleCompareExpression((Compare) _this);
}
@Override
public SimpleExpression sem_sexpr_arb() {
return new Arbitrary();
}
/*
* sem_op_cmp
......@@ -596,11 +601,6 @@ public class DefaultRReilBuilder implements IRReilBuilder {
return new ZeroExtend(size, fromsize, (LinearExpression) opnd1);
}
@Override
public Expression sem_arb(long size) {
return new Arbitrary(size);
}
/*
* sem_varl
*/
......
......@@ -180,6 +180,8 @@ public interface IRReilBuilder {
ISimpleExpression sem_sexpr_cmp(ICompare _this);
ISimpleExpression sem_sexpr_arb();
/*
* sem_op_cmp
*/
......@@ -242,8 +244,6 @@ public interface IRReilBuilder {
IExpression sem_zx(long size, long fromsize, ILinearExpression opnd1);
IExpression sem_arb(long size);
/*
* sem_varl
*/
......
package rreil.expression;
public class Arbitrary extends Expression {
public Arbitrary(long size) {
super(size);
}
@Override
public String toString() {
return "arbitrary:" + size;
}
}
package rreil.sexpression;
public class Arbitrary extends SimpleExpression {
@Override
public String toString() {
return "arbitrary";
}
}
......@@ -18,6 +18,7 @@ public class WhileStatement extends Statement {
public WhileStatement(SimpleExpression condition,
DefaultStatementCollection body) {
this.condition = condition;
this.body = body;
}
......
......@@ -133,6 +133,12 @@ static struct data simulator_sexpr_simulate(struct context *context, struct rrei
result = simulator_comparator_simulate(context, sexpr->cmp);
break;
}
case RREIL_SEXPR_TYPE_ARB: {
result.data = (uint8_t*)calloc(bit_length / 8 + 1, 1);
result.bit_length = bit_length;
context_data_undefine(&result);
break;
}
}
return result;
}
......@@ -250,13 +256,6 @@ static struct data simulator_expr_simulate(struct context *context, struct rreil
context_data_clear(&opnd);
break;
}
case RREIL_EXPR_TYPE_ARB: {
size = expr->arb.size;
result.data = (uint8_t*)calloc(size / 8 + 1, 1);
result.bit_length = size;
context_data_undefine(&result);
break;
}
}
return result;
}
......
......@@ -152,6 +152,9 @@ static void tracking_sexpr_trace(struct tracking_trace *trace, struct rreil_sexp
tracking_comparator_trace(trace, sexpr->cmp);
break;
}
case RREIL_SEXPR_TYPE_ARB: {
break;
}
}
}
......@@ -224,9 +227,6 @@ static size_t tracking_expr_trace(struct tracking_trace *trace, struct rreil_exp
tracking_linear_trace(trace, SIMULATOR_ACCESS_TYPE_READ, expr->zx.opnd, expr->zx.fromsize);
return expr->zx.size;
}
case RREIL_EXPR_TYPE_ARB: {
return expr->arb.size;
}
default:
return 0;
}
......
......@@ -18,7 +18,7 @@ extern struct rreil_comparator *rreil_comparator_copy(struct rreil_comparator *c
extern struct rreil_id *rreil_id_copy(struct rreil_id *id);
extern struct rreil_linear *rreil_linear_copy(struct rreil_linear *linear);
extern struct rreil_size_change rreil_size_change_copy(struct rreil_size_change size_change);
extern struct rreil_expr *rreil_op_copy(struct rreil_expr *op);
extern struct rreil_expr *rreil_expr_copy(struct rreil_expr *op);
extern struct rreil_sexpr *rreil_sexpr_copy(struct rreil_sexpr *sexpr);
extern struct rreil_variable *rreil_variable_copy(struct rreil_variable *variable);
extern struct rreil_statement *rreil_statement_copy(struct rreil_statement *statement);
......
......@@ -26,8 +26,7 @@ enum rreil_expr_type {
RREIL_EXPR_TYPE_OR,
RREIL_EXPR_TYPE_XOR,
RREIL_EXPR_TYPE_SX,
RREIL_EXPR_TYPE_ZX,
RREIL_EXPR_TYPE_ARB
RREIL_EXPR_TYPE_ZX
};
struct rreil_size_change {
......@@ -52,9 +51,6 @@ struct rreil_expr {
struct rreil_arity2 xor_;
struct rreil_size_change sx;
struct rreil_size_change zx;
struct {
uint64_t size;
} arb;
};
};
......
......@@ -13,7 +13,8 @@
enum rreil_sexpr_type {
RREIL_SEXPR_TYPE_LIN,
RREIL_SEXPR_TYPE_CMP
RREIL_SEXPR_TYPE_CMP,
RREIL_SEXPR_TYPE_ARB
};
struct rreil_sexpr {
......
......@@ -114,71 +114,67 @@ struct rreil_size_change rreil_size_change_copy(struct rreil_size_change size_ch
return size_change_copy;
}
struct rreil_expr *rreil_op_copy(struct rreil_expr *op) {
struct rreil_expr *op_copy = (struct rreil_expr*)malloc(sizeof(struct rreil_expr));
struct rreil_expr *rreil_expr_copy(struct rreil_expr *op) {
struct rreil_expr *expr_copy = (struct rreil_expr*)malloc(sizeof(struct rreil_expr));
op_copy->type = op->type;
expr_copy->type = op->type;
switch (op->type) {
case RREIL_EXPR_TYPE_SEXPR: {
op_copy->sexpr = rreil_arity1_sexpr_copy(op->sexpr);
expr_copy->sexpr = rreil_arity1_sexpr_copy(op->sexpr);
break;
}
case RREIL_EXPR_TYPE_MUL: {
op_copy->mul = rreil_arity2_copy(op->mul);
expr_copy->mul = rreil_arity2_copy(op->mul);
break;
}
case RREIL_EXPR_TYPE_DIV: {
op_copy->div = rreil_arity2_copy(op->div);
expr_copy->div = rreil_arity2_copy(op->div);
break;
}
case RREIL_EXPR_TYPE_DIVS: {
op_copy->divs = rreil_arity2_copy(op->divs);
expr_copy->divs = rreil_arity2_copy(op->divs);
break;
}
case RREIL_EXPR_TYPE_MOD: {
op_copy->mod = rreil_arity2_copy(op->mod);
expr_copy->mod = rreil_arity2_copy(op->mod);
break;
}
case RREIL_EXPR_TYPE_SHL: {
op_copy->shl = rreil_arity2_copy(op->shl);
expr_copy->shl = rreil_arity2_copy(op->shl);
break;
}
case RREIL_EXPR_TYPE_SHR: {
op_copy->shr = rreil_arity2_copy(op->shr);
expr_copy->shr = rreil_arity2_copy(op->shr);
break;
}
case RREIL_EXPR_TYPE_SHRS: {
op_copy->shrs = rreil_arity2_copy(op->shrs);
expr_copy->shrs = rreil_arity2_copy(op->shrs);
break;
}
case RREIL_EXPR_TYPE_AND: {
op_copy->and_ = rreil_arity2_copy(op->and_);
expr_copy->and_ = rreil_arity2_copy(op->and_);
break;
}
case RREIL_EXPR_TYPE_OR: {
op_copy->or_ = rreil_arity2_copy(op->or_);
expr_copy->or_ = rreil_arity2_copy(op->or_);
break;
}
case RREIL_EXPR_TYPE_XOR: {
op_copy->xor_ = rreil_arity2_copy(op->xor_);
expr_copy->xor_ = rreil_arity2_copy(op->xor_);
break;
}
case RREIL_EXPR_TYPE_SX: {
op_copy->sx = rreil_size_change_copy(op->sx);
expr_copy->sx = rreil_size_change_copy(op->sx);
break;
}
case RREIL_EXPR_TYPE_ZX: {
op_copy->zx = rreil_size_change_copy(op->zx);
break;
}
case RREIL_EXPR_TYPE_ARB: {
op_copy->arb.size = op->arb.size;
expr_copy->zx = rreil_size_change_copy(op->zx);
break;
}
}
return op_copy;
return expr_copy;
}
struct rreil_sexpr *rreil_sexpr_copy(struct rreil_sexpr *sexpr) {
......@@ -195,6 +191,9 @@ struct rreil_sexpr *rreil_sexpr_copy(struct rreil_sexpr *sexpr) {
sexpr_copy->cmp = rreil_comparator_copy(sexpr->cmp);
break;
}
case RREIL_SEXPR_TYPE_ARB: {
break;
}
}
return sexpr_copy;
......@@ -247,7 +246,7 @@ struct rreil_statement *rreil_statement_copy(struct rreil_statement *statement)
switch (statement->type) {
case RREIL_STATEMENT_TYPE_ASSIGN: {
statement_copy->assign.lhs = rreil_variable_copy(statement->assign.lhs);
statement_copy->assign.rhs = rreil_op_copy(statement->assign.rhs);
statement_copy->assign.rhs = rreil_expr_copy(statement->assign.rhs);
break;
}
case RREIL_STATEMENT_TYPE_LOAD: {
......@@ -258,7 +257,7 @@ struct rreil_statement *rreil_statement_copy(struct rreil_statement *statement)
}
case RREIL_STATEMENT_TYPE_STORE: {
statement_copy->store.address = rreil_address_copy(statement->store.address);
statement_copy->store.rhs = rreil_op_copy(statement->store.rhs);
statement_copy->store.rhs = rreil_expr_copy(statement->store.rhs);
break;
}
case RREIL_STATEMENT_TYPE_ITE: {
......
......@@ -124,9 +124,6 @@ void rreil_op_free(struct rreil_expr *op) {
rreil_size_change_clear(&op->zx);
break;
}
case RREIL_EXPR_TYPE_ARB: {
break;
}
}
free(op);
}
......@@ -141,6 +138,9 @@ void rreil_sexpr_free(struct rreil_sexpr *sexpr) {
rreil_comparator_free(sexpr->cmp);
break;
}
case RREIL_SEXPR_TYPE_ARB: {
break;
}
}
free(sexpr);
}
......
......@@ -158,6 +158,12 @@ static obj_t sem_sexpr_cmp(state_t state, obj_t this) {
sexpr->cmp = (struct rreil_comparator*)this;
return (obj_t)sexpr;
}
static obj_t sem_sexpr_arb(state_t state, obj_t nothing) {
struct rreil_sexpr *sexpr = (struct rreil_sexpr*)malloc(
sizeof(struct rreil_sexpr));
sexpr->type = RREIL_SEXPR_TYPE_ARB;
return (obj_t)sexpr;
}
// sem_op_cmp
static obj_t sem_cmpeq(state_t state, int_t size,
......@@ -338,12 +344,6 @@ static obj_t sem_zx(state_t state, int_t size, int_t fromsize,
op->zx.opnd = (struct rreil_linear*)opnd1;
return (obj_t)op;
}
static obj_t sem_arb(state_t state, int_t size) {
struct rreil_expr *op = (struct rreil_expr*)malloc(sizeof(struct rreil_expr));
op->type = RREIL_EXPR_TYPE_ARB;
op->arb.size = size;
return (obj_t)op;
}
// sem_varl
static obj_t sem_varl(state_t state, obj_t id, int_t offset, int_t size) {
......@@ -549,7 +549,8 @@ callbacks_t rreil_gdrr_builder_callbacks_get(state_t state) {
unboxed_sem_sexpr_callbacks_t sem_sexpr_callbacks = {
.sem_sexpr_lin = &sem_sexpr_lin,
.sem_sexpr_cmp = &sem_sexpr_cmp
.sem_sexpr_cmp = &sem_sexpr_cmp,
.sem_sexpr_arb = &sem_sexpr_arb
};
unboxed_sem_op_cmp_callbacks_t sem_op_cmp_callbacks = {
......@@ -574,8 +575,7 @@ callbacks_t rreil_gdrr_builder_callbacks_get(state_t state) {
.sem_or = &sem_or,
.sem_xor = &sem_xor,
.sem_sx = &sem_sx,
.sem_zx = &sem_zx,
.sem_arb = &sem_arb
.sem_zx = &sem_zx
};
unboxed_sem_varl_callbacks_t sem_varl_callbacks = {
......
......@@ -217,10 +217,6 @@ void rreil_op_print(struct rreil_expr *op) {
rreil_linear_print(op->zx.opnd);
break;
}
case RREIL_EXPR_TYPE_ARB: {
printf("{%lu} arbitrary", op->arb.size);
break;
}
}
}
......@@ -234,6 +230,10 @@ void rreil_sexpr_print(struct rreil_sexpr *sexpr) {
rreil_comparator_print(sexpr->cmp);
break;
}
case RREIL_SEXPR_TYPE_ARB: {
printf("arbitrary");
break;
}
}
}
......
......@@ -12,9 +12,9 @@ type sem_id_callbacks = {shared:int, virt_t:int, arch:int}
type sem_address_callbacks = {sem_address_:int}
type sem_var_callbacks = {sem_var_:int}
type sem_linear_callbacks = {sem_lin_var:int, sem_lin_imm:int, sem_lin_add:int, sem_lin_sub:int, sem_lin_scale:int}
type sem_sexpr_callbacks = {sem_sexpr_lin:int, sem_sexpr_cmp:int}
type sem_sexpr_callbacks = {sem_sexpr_lin:int, sem_sexpr_cmp:int, sem_sexpr_arb:int}
type sem_op_cmp_callbacks = {sem_cmpeq:int, sem_cmpneq:int, sem_cmples:int, sem_cmpleu:int, sem_cmplts:int, sem_cmpltu:int}
type sem_expr_callbacks = {sem_sexpr:int, sem_mul:int, sem_div:int, sem_divs:int, sem_mod:int, sem_shl:int, sem_shr:int, sem_shrs:int, sem_and:int, sem_or:int, sem_xor:int, sem_sx:int, sem_zx:int, sem_arb:int}
type sem_expr_callbacks = {sem_sexpr:int, sem_mul:int, sem_div:int, sem_divs:int, sem_mod:int, sem_shl:int, sem_shr:int, sem_shrs:int, sem_and:int, sem_or:int, sem_xor:int, sem_sx:int, sem_zx:int}
type sem_varl_callbacks = {sem_varl_:int}
type sem_varls_callbacks = {sem_varls_next:int, sem_varls_init:int}
type sem_flop_callbacks = {sem_flop_:int}
......@@ -82,6 +82,7 @@ end
val rreil-convert-sem-sexpr cbs sexpr = case sexpr of
SEM_SEXPR_LIN l: cbs.sem_sexpr.sem_sexpr_lin (rreil-convert-sem-linear cbs l)
| SEM_SEXPR_CMP c: cbs.sem_sexpr.sem_sexpr_cmp (rreil-convert-sem-op-cmp cbs c)
| SEM_SEXPR_ARB: cbs.sem_sexpr.sem_sexpr_arb void #Note: init is a function and, hence, has to be called by applying it to an argument
end
val rreil-convert-sem-op-cmp cbs op-cmp = case op-cmp of
......@@ -107,7 +108,6 @@ val rreil-convert-sem-expr cbs op = case op of
| SEM_XOR x: cbs.sem_expr.sem_xor x.size (rreil-convert-sem-linear cbs x.opnd1) (rreil-convert-sem-linear cbs x.opnd2)
| SEM_SX s: cbs.sem_expr.sem_sx s.size s.fromsize (rreil-convert-sem-linear cbs s.opnd1)
| SEM_ZX s: cbs.sem_expr.sem_zx s.size s.fromsize (rreil-convert-sem-linear cbs s.opnd1)
| SEM_ARB a: cbs.sem_expr.sem_arb a.size
end
val rreil-convert-branch-hint cbs hint = cbs.branch_hint.branch_hint_ (index hint)
......
......@@ -87,7 +87,7 @@ val lv-gen gens stmt =
| SEM_SX x: visit-lin gens x.fromsize x.opnd1
| SEM_ZX x: visit-lin gens x.fromsize x.opnd1
#Todo (grammar): | SEM_CMP c: visit-op-cmp gens c
| SEM_ARB x: gens
#Todo (grammar): | SEM_ARB x: gens
end
val visit-address gens x = visit-lin gens x.size x.address
......
......@@ -87,7 +87,6 @@ val rreil-show-expr expr =
| SEM_XOR x: "xor" +++ rreil-show-arity2 x
| SEM_SX x: "sx[" +++ show-int x.fromsize +++ "->" +++ show-int x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ ")"
| SEM_ZX x: "zx[" +++ show-int x.fromsize +++ "->" +++ show-int x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ ")"
| SEM_ARB x: "arbitrary[" +++ show-int x.size +++ "]"
end
val rreil-show-arity1-sexpr x = "[" +++ show-int x.size +++ "](" +++ rreil-show-sexpr x.opnd1 +++ ")"
......@@ -120,6 +119,7 @@ val rreil-show-sexpr sexpr =
case sexpr of
SEM_SEXPR_LIN l: rreil-show-linear l
| SEM_SEXPR_CMP c: rreil-show-op-cmp c
| SEM_SEXPR_ARB: "arbitrary"
end
val rreil-show-id id =
......
......@@ -22,6 +22,7 @@ type sem_linear =
type sem_sexpr =
SEM_SEXPR_LIN of sem_linear
| SEM_SEXPR_CMP of sem_op_cmp
| SEM_SEXPR_ARB
type sem_op_cmp =
SEM_CMPEQ of sem_cmp
......@@ -45,7 +46,6 @@ type sem_expr =
| SEM_XOR of sem_arity2
| SEM_SX of {size:int, fromsize:int, opnd1:sem_linear}
| SEM_ZX of {size:int, fromsize:int, opnd1:sem_linear}
| SEM_ARB of {size:int}
type sem_varl = {id:sem_id, offset:int, size:int}
......@@ -93,7 +93,6 @@ val rreil-sizeOf op =
| SEM_XOR x: x.size
| SEM_SX x: x.size
| SEM_ZX x: x.size
| SEM_ARB x: x.size
end
val rreil-stmts-rev stmts =
......@@ -198,7 +197,7 @@ val stack-set stmt = do
end
val mov sz a b = push (/ASSIGN a (SEM_SEXPR {size=sz, opnd1=(SEM_SEXPR_LIN b)}))
val undef sz a = push (/ASSIGN a (SEM_ARB{size=sz}))
val undef sz a = push (/ASSIGN a (SEM_SEXPR {size=sz, opnd1=SEM_SEXPR_ARB}))
val load sz a psz b = push (/LOAD sz a {size=psz,address=b})
val store a b = push (/STORE a b)
val add sz a b c = push (/ASSIGN a (SEM_SEXPR {size=sz, opnd1=SEM_SEXPR_LIN (/ADD b c)}))
......
......@@ -333,6 +333,10 @@ static obj_t sem_sexpr_cmp(state_t state, obj_t this) {
printf("=> sem_sexpr_cmp\n");
return NULL ;
}
static obj_t sem_sexpr_arb(state_t state, obj_t nothing) {
printf("=> sem_sexpr_arb\n");
return NULL ;
}
// sem_op_cmp
static obj_t sem_cmpeq(state_t state, int_t size,
......@@ -432,10 +436,6 @@ static obj_t sem_zx(state_t state, int_t size, int_t fromsize,
printf("=> zx {size=%lu, fromsize=%lu}\n", size, fromsize);
return NULL ;
}
static obj_t sem_arb(state_t state, int_t size) {
printf("=> arb {size=%lu}\n", size);
return NULL ;
}
// sem_varl
static obj_t sem_varl(state_t state, obj_t id, int_t offset, int_t size) {
......@@ -591,7 +591,8 @@ int main(int argc, char** argv) {
unboxed_sem_sexpr_callbacks_t sem_sexpr_callbacks = {
.sem_sexpr_lin = &sem_sexpr_lin,
.sem_sexpr_cmp = &sem_sexpr_cmp
.sem_sexpr_cmp = &sem_sexpr_cmp,
.sem_sexpr_arb = &sem_sexpr_arb
};
unboxed_sem_op_cmp_callbacks_t sem_op_cmp_callbacks = {
......@@ -616,8 +617,7 @@ int main(int argc, char** argv) {
.sem_or = &sem_or,
.sem_xor = &sem_xor,
.sem_sx = &sem_sx,
.sem_zx = &sem_zx,
.sem_arb = &sem_arb
.sem_zx = &sem_zx
};
unboxed_sem_varl_callbacks_t sem_varl_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