Skip to content

Commit 51f53ca

Browse files
Extract convert_const function
1 parent d627638 commit 51f53ca

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+40-32
Original file line numberDiff line numberDiff line change
@@ -1342,38 +1342,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13421342
else if(statement==patternt("?const"))
13431343
{
13441344
assert(results.size()==1);
1345-
1346-
const char type_char=statement[0];
1347-
const bool is_double('d'==type_char);
1348-
const bool is_float('f'==type_char);
1349-
1350-
if(is_double || is_float)
1351-
{
1352-
const ieee_float_spect spec(
1353-
is_float?ieee_float_spect::single_precision():
1354-
ieee_float_spect::double_precision());
1355-
1356-
ieee_floatt value(spec);
1357-
if(arg0.type().id()!=ID_floatbv)
1358-
{
1359-
mp_integer number;
1360-
bool ret=to_integer(to_constant_expr(arg0), number);
1361-
DATA_INVARIANT(!ret, "failed to convert constant");
1362-
value.from_integer(number);
1363-
}
1364-
else
1365-
value.from_expr(to_constant_expr(arg0));
1366-
1367-
results[0]=value.to_expr();
1368-
}
1369-
else
1370-
{
1371-
mp_integer value;
1372-
bool ret=to_integer(to_constant_expr(arg0), value);
1373-
DATA_INVARIANT(!ret, "failed to convert constant");
1374-
const typet type=java_type_from_char(statement[0]);
1375-
results[0]=from_integer(value, type);
1376-
}
1345+
results = convert_const(statement, arg0, results);
13771346
}
13781347
else if(statement==patternt("?ipush"))
13791348
{
@@ -2004,6 +1973,45 @@ codet java_bytecode_convert_methodt::convert_instructions(
20041973
return code;
20051974
}
20061975

1976+
exprt::operandst &java_bytecode_convert_methodt::convert_const(
1977+
const irep_idt &statement,
1978+
const exprt &arg0,
1979+
exprt::operandst &results) const
1980+
{
1981+
const char type_char = statement[0];
1982+
const bool is_double('d' == type_char);
1983+
const bool is_float('f' == type_char);
1984+
1985+
if(is_double || is_float)
1986+
{
1987+
const ieee_float_spect spec(
1988+
is_float ? ieee_float_spect::single_precision()
1989+
: ieee_float_spect::double_precision());
1990+
1991+
ieee_floatt value(spec);
1992+
if(arg0.type().id() != ID_floatbv)
1993+
{
1994+
mp_integer number;
1995+
bool ret = to_integer(to_constant_expr(arg0), number);
1996+
DATA_INVARIANT(!ret, "failed to convert constant");
1997+
value.from_integer(number);
1998+
}
1999+
else
2000+
value.from_expr(to_constant_expr(arg0));
2001+
2002+
results[0] = value.to_expr();
2003+
}
2004+
else
2005+
{
2006+
mp_integer value;
2007+
bool ret = to_integer(to_constant_expr(arg0), value);
2008+
DATA_INVARIANT(!ret, "failed to convert constant");
2009+
const typet type = java_type_from_char(statement[0]);
2010+
results[0] = from_integer(value, type);
2011+
}
2012+
return results;
2013+
}
2014+
20072015
void java_bytecode_convert_methodt::convert_invoke(
20082016
source_locationt location,
20092017
const irep_idt &statement,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+5
Original file line numberDiff line numberDiff line change
@@ -451,5 +451,10 @@ class java_bytecode_convert_methodt:public messaget
451451
exprt &arg0,
452452
codet &c,
453453
exprt::operandst &results);
454+
455+
exprt::operandst &convert_const(
456+
const irep_idt &statement,
457+
const exprt &arg0,
458+
exprt::operandst &results) const;
454459
};
455460
#endif

0 commit comments

Comments
 (0)