Skip to content

Commit a86a88e

Browse files
committed
Support "signed word [N](int)" conversion operator on SMV frontend
1 parent a783f1e commit a86a88e

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

frontends/smvparser.y

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,15 +1286,19 @@ simple_expr: constant {
12861286
SMVnode *word = $3;
12871287
SMVnode::Type word_type = word->getType();
12881288

1289-
if(word_type != SMVnode::Signed && word_type != SMVnode::Unsigned){
1289+
if(word_type != SMVnode::Integer && word_type != SMVnode::Signed && word_type != SMVnode::Unsigned){
12901290
throw PonoException("Resize word type is uncompatible");
12911291
}
12921292

12931293
int integer = stoi($5);
12941294
smt::Sort word_sort = word->getTerm()->get_sort();
1295-
uint64_t word_width = word_sort->get_width();
1295+
uint64_t word_width = word_type != SMVnode::Integer ? word_sort->get_width() : 0;
12961296

1297-
if(integer == word_width){
1297+
if (word_type == SMVnode::Integer){
1298+
smt::Term res = enc.solver_->make_term(smt::Op(smt::Int_To_BV, integer), word->getTerm());
1299+
assert(res);
1300+
$$ = new SMVnode(res, SMVnode::Signed);
1301+
}else if(integer == word_width){
12981302
$$ = word;
12991303
}else if(integer < word_width){
13001304
smt::Term res;
@@ -1319,7 +1323,21 @@ simple_expr: constant {
13191323
}
13201324
}
13211325
| signed_word sizev "(" basic_expr ")"{
1322-
throw PonoException("No resize");
1326+
if(enc.module_flat){
1327+
SMVnode *expr = $4;
1328+
SMVnode::Type expr_type = expr->getType();
1329+
1330+
if(expr_type != SMVnode::Integer){
1331+
throw PonoException("Signed word conversion type is uncompatible");
1332+
}
1333+
assert(expr);
1334+
smt::Term res = enc.solver_->make_term(smt::Op(smt::Int_To_BV, $2), expr->getTerm());
1335+
assert(res);
1336+
$$ = new SMVnode(res, SMVnode::Signed);
1337+
}else{
1338+
SMVnode *integer = new constant(std::to_string($2));
1339+
$$ = new resize_expr($4,integer);
1340+
}
13231341
}
13241342
| unsigned_word sizev "(" basic_expr ")"{
13251343
throw PonoException("No resize");

0 commit comments

Comments
 (0)