|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: SMV Language Interface |
| 4 | +
|
| 5 | +Author: Daniel Kroening, dkr@amazon.com |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// SMV Language Interface |
| 11 | + |
| 12 | +#include "smv_ebmc_language.h" |
| 13 | + |
| 14 | +#include <util/cmdline.h> |
| 15 | +#include <util/get_module.h> |
| 16 | +#include <util/unicode.h> |
| 17 | + |
| 18 | +#include <ebmc/ebmc_error.h> |
| 19 | +#include <ebmc/transition_system.h> |
| 20 | + |
| 21 | +#include "smv_parser.h" |
| 22 | +#include "smv_typecheck.h" |
| 23 | + |
| 24 | +#include <fstream> |
| 25 | +#include <iostream> |
| 26 | + |
| 27 | +std::string smv_file_name(const cmdlinet &cmdline) |
| 28 | +{ |
| 29 | + if(cmdline.args.size() == 0) |
| 30 | + throw ebmc_errort{} << "no file name given"; |
| 31 | + |
| 32 | + if(cmdline.args.size() >= 2) |
| 33 | + throw ebmc_errort{}.with_exit_code(1) << "SMV only uses a single file"; |
| 34 | + |
| 35 | + return cmdline.args.front(); |
| 36 | +} |
| 37 | + |
| 38 | +smv_parse_treet smv_ebmc_languaget::parse() |
| 39 | +{ |
| 40 | + smv_parsert smv_parser{message_handler}; |
| 41 | + |
| 42 | + auto file_name = smv_file_name(cmdline); |
| 43 | + |
| 44 | + std::ifstream infile{widen_if_needed(file_name)}; |
| 45 | + |
| 46 | + if(!infile) |
| 47 | + throw ebmc_errort{}.with_exit_code(1) << "failed to open " << file_name; |
| 48 | + |
| 49 | + smv_parser.set_file(file_name); |
| 50 | + smv_parser.in = &infile; |
| 51 | + |
| 52 | + if(smv_parser.parse()) |
| 53 | + throw ebmc_errort{}.with_exit_code(1); |
| 54 | + |
| 55 | + return std::move(smv_parser.parse_tree); |
| 56 | +} |
| 57 | + |
| 58 | +std::optional<transition_systemt> smv_ebmc_languaget::transition_system() |
| 59 | +{ |
| 60 | + if(cmdline.isset("preprocess")) |
| 61 | + { |
| 62 | + throw ebmc_errort{}.with_exit_code(1) << "SMV does not use preprocessing"; |
| 63 | + } |
| 64 | + |
| 65 | + auto parse_tree = parse(); |
| 66 | + |
| 67 | + if(cmdline.isset("show-parse")) |
| 68 | + { |
| 69 | + parse_tree.show(std::cout); |
| 70 | + return {}; |
| 71 | + } |
| 72 | + |
| 73 | + if( |
| 74 | + cmdline.isset("show-modules") || cmdline.isset("modules-xml") || |
| 75 | + cmdline.isset("json-modules")) |
| 76 | + { |
| 77 | + //show_modules(cmdline, message_handler); |
| 78 | + return {}; |
| 79 | + } |
| 80 | + |
| 81 | + if(cmdline.isset("show-module-hierarchy")) |
| 82 | + { |
| 83 | + //show_module_hierarchy(cmdline, message_handler); |
| 84 | + return {}; |
| 85 | + } |
| 86 | + |
| 87 | + transition_systemt result; |
| 88 | + |
| 89 | + if(smv_typecheck( |
| 90 | + parse_tree, result.symbol_table, "smv::main", message_handler)) |
| 91 | + { |
| 92 | + messaget message{message_handler}; |
| 93 | + message.error() << "CONVERSION ERROR" << messaget::eom; |
| 94 | + throw ebmc_errort{}.with_exit_code(2); |
| 95 | + } |
| 96 | + |
| 97 | + if(cmdline.isset("show-symbol-table")) |
| 98 | + { |
| 99 | + std::cout << result.symbol_table; |
| 100 | + return {}; |
| 101 | + } |
| 102 | + |
| 103 | + result.main_symbol = |
| 104 | + &get_module(result.symbol_table, "main", message_handler); |
| 105 | + |
| 106 | + result.trans_expr = |
| 107 | + to_trans_expr(result.main_symbol->value); |
| 108 | + |
| 109 | + return result; |
| 110 | +} |
0 commit comments