|
| 1 | +/* |
| 2 | + * Copyright 2019 Alain Dargelas |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <uhdm/uhdm.h> |
| 18 | + |
| 19 | +#include <algorithm> |
| 20 | +#include <filesystem> |
| 21 | +#include <iostream> |
| 22 | +#include <memory> |
| 23 | +#include <string> |
| 24 | + |
| 25 | +namespace fs = std::filesystem; |
| 26 | + |
| 27 | +static int32_t usage(const char *progName) { |
| 28 | + std::cerr << "Usage:" << std::endl |
| 29 | + << " " << progName << " <uhdm-file> <uhdm-file>" << std::endl |
| 30 | + << std::endl |
| 31 | + << "Reads input uhdm binary representations of two files and " |
| 32 | + "compares them topographically." |
| 33 | + << std::endl |
| 34 | + << std::endl |
| 35 | + << "Exits with code" << std::endl |
| 36 | + << " = 0, if input files are equal" << std::endl |
| 37 | + << " < 0, if input files are not equal" << std::endl |
| 38 | + << " > 0, for any failures" << std::endl; |
| 39 | + return 1; |
| 40 | +} |
| 41 | + |
| 42 | +int32_t main(int32_t argc, char **argv) { |
| 43 | + if (argc != 3) { |
| 44 | + return usage(argv[0]); |
| 45 | + } |
| 46 | + |
| 47 | + fs::path fileA = argv[1]; |
| 48 | + fs::path fileB = argv[2]; |
| 49 | + |
| 50 | + std::error_code ec; |
| 51 | + if (!fs::is_regular_file(fileA, ec) || ec) { |
| 52 | + std::cerr << fileA << ": File does not exist!" << std::endl; |
| 53 | + return usage(argv[0]); |
| 54 | + } |
| 55 | + |
| 56 | + if (!fs::is_regular_file(fileB, ec) || ec) { |
| 57 | + std::cerr << fileB << ": File does not exist!" << std::endl; |
| 58 | + return usage(argv[0]); |
| 59 | + } |
| 60 | + |
| 61 | + std::unique_ptr<UHDM::Serializer> serializerA(new UHDM::Serializer); |
| 62 | + std::vector<vpiHandle> handlesA = serializerA->Restore(fileA); |
| 63 | + |
| 64 | + std::unique_ptr<UHDM::Serializer> serializerB(new UHDM::Serializer); |
| 65 | + std::vector<vpiHandle> handlesB = serializerB->Restore(fileB); |
| 66 | + |
| 67 | + if (handlesA.empty()) { |
| 68 | + std::cerr << fileA << ": Failed to load." << std::endl; |
| 69 | + return 1; |
| 70 | + } |
| 71 | + |
| 72 | + if (handlesB.empty()) { |
| 73 | + std::cerr << fileB << ": Failed to load." << std::endl; |
| 74 | + return 1; |
| 75 | + } |
| 76 | + |
| 77 | + if (handlesA.size() != handlesB.size()) { |
| 78 | + std::cerr << "Number of designs mismatch." << std::endl; |
| 79 | + return -1; |
| 80 | + } |
| 81 | + |
| 82 | + std::function<const UHDM::design *(vpiHandle handle)> to_design = |
| 83 | + [](vpiHandle handle) { |
| 84 | + return (const UHDM::design *)((const uhdm_handle *)handle)->object; |
| 85 | + }; |
| 86 | + |
| 87 | + std::vector<const UHDM::design *> designsA; |
| 88 | + designsA.reserve(handlesA.size()); |
| 89 | + std::transform(handlesA.begin(), handlesA.end(), std::back_inserter(designsA), |
| 90 | + to_design); |
| 91 | + |
| 92 | + std::vector<const UHDM::design *> designsB; |
| 93 | + designsB.reserve(handlesB.size()); |
| 94 | + std::transform(handlesB.begin(), handlesB.end(), std::back_inserter(designsB), |
| 95 | + to_design); |
| 96 | + |
| 97 | + for (size_t i = 0, n = designsA.size(); i < n; ++i) { |
| 98 | + UHDM::AnySet visited; |
| 99 | + if (designsA[i]->Compare(designsB[i], visited) != 0) { |
| 100 | + return -1; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + return 0; |
| 105 | +} |
0 commit comments