| 3921 | char flip(char c) { return (c == '0') ? '1' : '0'; } |
| 3922 | |
| 3923 | std::string twosComplement(std::string_view bin) { |
| 3924 | int32_t n = bin.length(); |
| 3925 | int32_t i; |
| 3926 | std::string ones, twos; |
| 3927 | for (i = 0; i < n; i++) ones += flip(bin[i]); |
| 3928 | twos = ones; |
| 3929 | for (i = n - 1; i >= 0; i--) { |
| 3930 | if (ones[i] == '1') |
| 3931 | twos[i] = '0'; |
| 3932 | else { |
| 3933 | twos[i] = '1'; |
| 3934 | break; |
| 3935 | } |
| 3936 | } |
| 3937 | if (i == -1) twos = '1' + twos; |
| 3938 | return twos; |
| 3939 | } |
| 3940 | |
| 3941 | UHDM::constant* CompileHelper::adjustSize(const UHDM::typespec* ts, |
| 3942 | DesignComponent* component, |