|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: variable sensitivity domain configuration |
| 4 | +
|
| 5 | + Author: Jez Higgins |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | +/// \file |
| 9 | +/// Captures the user-supplied configuration for VSD, determining which |
| 10 | +/// domain abstractions are used, flow sensitivity, etc |
| 11 | +#include "variable_sensitivity_configuration.h" |
| 12 | + |
| 13 | +vsd_configt vsd_configt::from_options(const optionst &options) |
| 14 | +{ |
| 15 | + vsd_configt config{}; |
| 16 | + |
| 17 | + if( |
| 18 | + options.get_bool_option("value-set") && |
| 19 | + options.get_bool_option("data-dependencies")) |
| 20 | + { |
| 21 | + throw invalid_command_line_argument_exceptiont{ |
| 22 | + "Value set is not currently supported with data dependency analysis", |
| 23 | + "--value-set --data-dependencies", |
| 24 | + "--data-dependencies"}; |
| 25 | + } |
| 26 | + |
| 27 | + config.value_abstract_type = |
| 28 | + option_to_abstract_type(options, "values", value_option_mappings, CONSTANT); |
| 29 | + |
| 30 | + config.pointer_abstract_type = option_to_abstract_type( |
| 31 | + options, "pointers", pointer_option_mappings, POINTER_INSENSITIVE); |
| 32 | + |
| 33 | + config.struct_abstract_type = option_to_abstract_type( |
| 34 | + options, "structs", struct_option_mappings, STRUCT_INSENSITIVE); |
| 35 | + |
| 36 | + config.array_abstract_type = option_to_abstract_type( |
| 37 | + options, "arrays", array_option_mappings, ARRAY_INSENSITIVE); |
| 38 | + |
| 39 | + config.union_abstract_type = option_to_abstract_type( |
| 40 | + options, "unions", union_option_mappings, UNION_INSENSITIVE); |
| 41 | + |
| 42 | + // This should always be on (for efficeny with 3-way merge) |
| 43 | + // Does not work with value set |
| 44 | + config.context_tracking.last_write_context = |
| 45 | + (config.value_abstract_type != VALUE_SET) && |
| 46 | + (config.pointer_abstract_type != VALUE_SET); |
| 47 | + config.context_tracking.data_dependency_context = |
| 48 | + options.get_bool_option("data-dependencies"); |
| 49 | + config.advanced_sensitivities.new_value_set = |
| 50 | + options.get_bool_option("new-value-set"); |
| 51 | + |
| 52 | + config.flow_sensitivity = (options.get_bool_option("flow-insensitive")) |
| 53 | + ? flow_sensitivityt::insensitive |
| 54 | + : flow_sensitivityt::sensitive; |
| 55 | + |
| 56 | + return config; |
| 57 | +} |
| 58 | + |
| 59 | +vsd_configt vsd_configt::constant_domain() |
| 60 | +{ |
| 61 | + vsd_configt config{}; |
| 62 | + config.context_tracking.last_write_context = true; |
| 63 | + config.value_abstract_type = CONSTANT; |
| 64 | + config.pointer_abstract_type = POINTER_SENSITIVE; |
| 65 | + config.struct_abstract_type = STRUCT_SENSITIVE; |
| 66 | + config.array_abstract_type = ARRAY_SENSITIVE; |
| 67 | + return config; |
| 68 | +} |
| 69 | + |
| 70 | +vsd_configt vsd_configt::value_set() |
| 71 | +{ |
| 72 | + vsd_configt config{}; |
| 73 | + config.value_abstract_type = VALUE_SET; |
| 74 | + config.pointer_abstract_type = VALUE_SET; |
| 75 | + config.struct_abstract_type = STRUCT_SENSITIVE; |
| 76 | + config.array_abstract_type = ARRAY_SENSITIVE; |
| 77 | + return config; |
| 78 | +} |
| 79 | + |
| 80 | +vsd_configt vsd_configt::intervals() |
| 81 | +{ |
| 82 | + vsd_configt config{}; |
| 83 | + config.context_tracking.last_write_context = true; |
| 84 | + config.value_abstract_type = INTERVAL; |
| 85 | + config.pointer_abstract_type = POINTER_SENSITIVE; |
| 86 | + config.struct_abstract_type = STRUCT_SENSITIVE; |
| 87 | + config.array_abstract_type = ARRAY_SENSITIVE; |
| 88 | + return config; |
| 89 | +} |
| 90 | + |
| 91 | +const vsd_configt::option_mappingt vsd_configt::value_option_mappings = { |
| 92 | + {"intervals", INTERVAL}, |
| 93 | + {"constants", CONSTANT}, |
| 94 | + {"set-of-constants", VALUE_SET}}; |
| 95 | + |
| 96 | +const vsd_configt::option_mappingt vsd_configt::pointer_option_mappings = { |
| 97 | + {"top-bottom", POINTER_INSENSITIVE}, |
| 98 | + {"constants", POINTER_SENSITIVE}, |
| 99 | + {"value-set", VALUE_SET}}; |
| 100 | + |
| 101 | +const vsd_configt::option_mappingt vsd_configt::struct_option_mappings = { |
| 102 | + {"top-bottom", STRUCT_INSENSITIVE}, |
| 103 | + {"every-field", STRUCT_SENSITIVE}}; |
| 104 | + |
| 105 | +const vsd_configt::option_mappingt vsd_configt::array_option_mappings = { |
| 106 | + {"top-bottom", ARRAY_INSENSITIVE}, |
| 107 | + {"every-element", ARRAY_SENSITIVE}}; |
| 108 | + |
| 109 | +const vsd_configt::option_mappingt vsd_configt::union_option_mappings = { |
| 110 | + {"top-bottom", UNION_INSENSITIVE}}; |
| 111 | + |
| 112 | +invalid_command_line_argument_exceptiont vsd_configt::invalid_argument( |
| 113 | + const std::string &option_name, |
| 114 | + const std::string &bad_argument, |
| 115 | + const option_mappingt &mapping) |
| 116 | +{ |
| 117 | + auto option = "--vsd-" + option_name; |
| 118 | + auto choices = std::string(""); |
| 119 | + for(auto &kv : mapping) |
| 120 | + { |
| 121 | + choices += (!choices.empty() ? "|" : ""); |
| 122 | + choices += kv.first; |
| 123 | + } |
| 124 | + |
| 125 | + return invalid_command_line_argument_exceptiont{ |
| 126 | + "Unknown argument '" + bad_argument + "'", option, option + " " + choices}; |
| 127 | +} |
| 128 | + |
| 129 | +ABSTRACT_OBJECT_TYPET vsd_configt::option_to_abstract_type( |
| 130 | + const optionst &options, |
| 131 | + const std::string &option_name, |
| 132 | + const option_mappingt &mapping, |
| 133 | + ABSTRACT_OBJECT_TYPET default_type) |
| 134 | +{ |
| 135 | + const auto argument = options.get_option(option_name); |
| 136 | + |
| 137 | + if(argument.empty()) |
| 138 | + return default_type; |
| 139 | + |
| 140 | + auto selected = mapping.find(argument); |
| 141 | + if(selected == mapping.end()) |
| 142 | + { |
| 143 | + throw invalid_argument(option_name, argument, mapping); |
| 144 | + } |
| 145 | + return selected->second; |
| 146 | +} |
0 commit comments