Пример #1
0
void assert_printed_local_expr(struct string *expected, enum vm_type type,
			       unsigned long local_index)
{
	struct expression *expr;

	expr = local_expr(type, local_index);
	assert_print_expr(expected, expr);
}
Пример #2
0
void test_should_print_monitorexit_statement(void)
{
	struct expression *expr;
	struct statement *stmt;

	expr = local_expr(J_INT, 0);

	stmt = alloc_statement(STMT_MONITOR_EXIT);
	stmt->expression = &expr->node;

	assert_print_stmt(str_aprintf(
		"MONITOR_EXIT:\n"
		"  expression: [local int 0]\n"), stmt);
}
Пример #3
0
void test_should_print_arraycheck_statement(void)
{
	struct expression *expression;
	struct statement *stmt;

	expression = local_expr(J_INT, 0);

	stmt = alloc_statement(STMT_ARRAY_CHECK);
	stmt->expression = &expression->node;

	assert_print_stmt(str_aprintf(
		"ARRAY_CHECK:\n"
		"  expression: [local int 0]\n"), stmt);
}
Пример #4
0
void test_should_print_expression_statement(void)
{
	struct expression *expression;
	struct statement *stmt;

	expression = local_expr(J_INT, 0);

	stmt = alloc_statement(STMT_EXPRESSION);
	stmt->expression = &expression->node;

	assert_print_stmt(str_aprintf(
		"EXPRESSION:\n"
		"  expression: [local int 0]\n"), stmt);
}
Пример #5
0
void test_should_print_return_statement(void)
{
	struct expression *return_value;
	struct statement *stmt;

	return_value = local_expr(J_INT, 0);

	stmt = alloc_statement(STMT_RETURN);
	stmt->return_value = &return_value->node;

	assert_print_stmt(str_aprintf(
		"RETURN:\n"
		"  return_value: [local int 0]\n"), stmt);
}
Пример #6
0
int convert_iinc(struct parse_context *ctx)
{
	struct statement *store_stmt;
	struct expression *local_expression, *binop_expression,
	    *const_expression;
	unsigned int index;
	int const_value;

	store_stmt = alloc_statement(STMT_STORE);
	if (!store_stmt)
		goto failed;

	if (ctx->is_wide) {
		index = bytecode_read_u16(ctx->buffer);
		const_value = bytecode_read_s16(ctx->buffer);
	} else {
		index = bytecode_read_u8(ctx->buffer);
		const_value = bytecode_read_s8(ctx->buffer);
	}

	local_expression = local_expr(J_INT, index);
	if (!local_expression)
		goto failed;

	store_stmt->store_dest = &local_expression->node;

	const_expression = value_expr(J_INT, const_value);
	if (!const_expression)
		goto failed;

	expr_get(local_expression);

	binop_expression = binop_expr(J_INT, OP_ADD, local_expression,
				      const_expression);
	if (!binop_expression) {
		expr_put(local_expression);
		expr_put(const_expression);
		goto failed;
	}

	store_stmt->store_src = &binop_expression->node;
	convert_statement(ctx, store_stmt);

	return 0;

      failed:
	free_statement(store_stmt);
	return warn("out of memory"), -ENOMEM;
}
Пример #7
0
void test_should_print_store_statement(void)
{
	struct expression *dest, *src;
	struct statement *stmt;

	dest = local_expr(J_INT, 0);
	src = value_expr(J_INT, 1);

	stmt = alloc_statement(STMT_STORE);
	stmt->store_dest = &dest->node;
	stmt->store_src = &src->node;

	assert_print_stmt(str_aprintf(
		"STORE:\n  store_dest: [local int 0]\n"
		"  store_src: [value int 0x1]\n"), stmt);
}
Пример #8
0
void test_should_print_checkcast_statement(void)
{
	struct expression *expr;
	struct statement *stmt;

	expr = local_expr(J_INT, 0);

	stmt = alloc_statement(STMT_CHECKCAST);
	stmt->checkcast_ref = &expr->node;
	stmt->checkcast_class = &vmc;

	assert_print_stmt(str_aprintf(
		"CHECKCAST:\n"
		"  checkcast_type: [%p '%s']\n"
		"  checkcast_ref: [local int 0]\n", &vmc, vmc.name), stmt);
}
Пример #9
0
void test_should_print_if_statement(void)
{
	struct expression *if_conditional;
	struct statement *stmt;
	struct basic_block *if_true = (void *) 0xdeadbeef;

	if_conditional = local_expr(J_BOOLEAN, 0);

	stmt = alloc_statement(STMT_IF);
	stmt->if_conditional = &if_conditional->node;
	stmt->if_true = if_true;

	assert_print_stmt(str_aprintf(
		"IF:\n"
		"  if_conditional: [local boolean 0]\n"
		"  if_true: [bb %p]\n", if_true), stmt);
}