| 776 | } |
| 777 | |
| 778 | bool CommandLineParser::parseCommandLine(int32_t argc, const char** argv) { |
| 779 | FileSystem* const fileSystem = FileSystem::getInstance(); |
| 780 | std::string pname = argv[0]; |
| 781 | if (pname == "read_systemverilog") { |
| 782 | // When surelog is embedded as a plugin in yosys, the program name is |
| 783 | // "read_systemverilog", which breaks the -lowmem option |
| 784 | pname = "surelog"; |
| 785 | std::filesystem::path programPath = FileSystem::getProgramPath(); |
| 786 | programPath = programPath.parent_path(); |
| 787 | programPath = programPath / pname; |
| 788 | m_programId = fileSystem->toPathId(programPath.string(), m_symbolTable); |
| 789 | } else { |
| 790 | m_programId = fileSystem->getProgramFile(pname, m_symbolTable); |
| 791 | } |
| 792 | std::vector<std::string> cmd_line; |
| 793 | for (int32_t i = 1; i < argc; i++) { |
| 794 | cmd_line.emplace_back(undecorateArg(argv[i])); |
| 795 | const std::string& arg = cmd_line.back(); |
| 796 | |
| 797 | if (arg.empty() || (arg[0] != '-')) { |
| 798 | continue; |
| 799 | } else if (arg == "-help" || arg == "-h" || arg == "--help") { |
| 800 | m_help = true; |
| 801 | std::string help = printStringArray(helpText); |
| 802 | m_errors->init(); |
| 803 | logBanner(argc, argv); |
| 804 | std::cout << help; |
| 805 | return true; |
| 806 | } else if (arg == "--version") { |
| 807 | std::cout << BuildIdentifier() << std::flush; |
| 808 | m_help = true; |
| 809 | return true; |
| 810 | } else if (arg == "-builtin") { |
| 811 | ++i; // Deprecated and ignored! |
| 812 | } else if (arg.find("-D") == 0) { |
| 813 | std::string def; |
| 814 | std::string value; |
| 815 | const size_t loc = arg.find('='); |
| 816 | if (loc == std::string::npos) { |
| 817 | def = arg.substr(2); |
| 818 | } else { |
| 819 | def = arg.substr(2, loc - 2); |
| 820 | value = arg.substr(loc + 1); |
| 821 | } |
| 822 | if (!def.empty()) { |
| 823 | StringUtils::registerEnvVar(def, value); |
| 824 | SymbolId id = m_symbolTable->registerSymbol(def); |
| 825 | m_defineList.emplace(id, value); |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | std::vector<std::string> all_arguments; |
| 831 | processOutputDirectory_(cmd_line); |
| 832 | |
| 833 | // Setup a few dependent input & output directories |
| 834 | if (!m_outputDirId) { |
| 835 | m_outputDirId = |