-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Assembler options can be specified in pgm_conf.json to override…
… values from proc_grps.json
- Loading branch information
1 parent
7ac224c
commit bf24968
Showing
27 changed files
with
622 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"type": "object", | ||
"description": "List of assembler options", | ||
"properties": { | ||
"GOFF": { | ||
"type": "boolean", | ||
"description": "Produces Generalized Object File format dataset." | ||
}, | ||
"OPTABLE": { | ||
"type": "string", | ||
"description": "Specifies the instruction set to use.", | ||
"enum": [ | ||
"UNI", | ||
"DOS", | ||
"370", | ||
"XA", | ||
"ESA", | ||
"ZOP", | ||
"ZS1", | ||
"YOP", | ||
"ZS2", | ||
"Z9", | ||
"ZS3", | ||
"Z10", | ||
"ZS4", | ||
"Z11", | ||
"ZS5", | ||
"Z12", | ||
"ZS6", | ||
"Z13", | ||
"ZS7", | ||
"Z14", | ||
"ZS8", | ||
"Z15", | ||
"ZS9" | ||
] | ||
}, | ||
"SYSPARM": { | ||
"type": "string", | ||
"description": "Specifies the character string the assembler assigns to the &SYSPARM system variable symbol.", | ||
"maxLength": 255 | ||
}, | ||
"PROFILE": { | ||
"type": "string", | ||
"description": "Profile Member to be copied into the source program." | ||
}, | ||
"SYSTEM_ID": { | ||
"type": "string", | ||
"description": "Provides the value for the SYSTEM_ID system variable. Defaults to 'z/OS 02.04.00' when omitted." | ||
}, | ||
"XOBJECT": { | ||
"type": "boolean", | ||
"description": "Synonym for the GOFF option." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright (c) 2022 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
*/ | ||
|
||
#include "assembler_options.h" | ||
|
||
#include "compiler_options.h" | ||
#include "nlohmann/json.hpp" | ||
|
||
namespace hlasm_plugin::parser_library::config { | ||
|
||
|
||
namespace { | ||
bool optable_valid(std::string_view optable) noexcept | ||
{ | ||
#ifdef __cpp_lib_ranges | ||
return optable.size() == 0 | ||
|| std::ranges::any_of(instr_set_version_equivalents, [optable](auto item) { return optable == item.first; }); | ||
#else | ||
return optable.size() == 0 | ||
|| std::any_of(std::begin(instr_set_version_equivalents), | ||
std::end(instr_set_version_equivalents), | ||
[optable](auto item) { return optable == item.first; }); | ||
#endif | ||
} | ||
} // namespace | ||
|
||
bool assembler_options::valid() const noexcept | ||
{ | ||
if (sysparm.has_value() && sysparm.value().size() >= 256) | ||
return false; | ||
if (optable.has_value() && !optable_valid(optable.value())) | ||
return false; | ||
return true; | ||
} | ||
|
||
namespace { | ||
std::optional<instruction_set_version> find_instruction_set(std::string_view optable) | ||
{ | ||
#ifdef __cpp_lib_ranges | ||
auto it = std::ranges::lower_bound( | ||
instr_set_version_equivalents, optable, {}, [](const auto& instr) { return instr.first; }); | ||
#else | ||
auto it = std::lower_bound(std::begin(instr_set_version_equivalents), | ||
std::end(instr_set_version_equivalents), | ||
optable, | ||
[](const auto& l, const auto& r) { return l.first < r; }); | ||
#endif | ||
|
||
if (it == std::end(instr_set_version_equivalents) || it->first != optable) | ||
return std::nullopt; | ||
|
||
return it->second; | ||
} | ||
} // namespace | ||
|
||
void assembler_options::apply(asm_option& opts) const | ||
{ | ||
if (sysparm.has_value()) | ||
opts.sysparm = sysparm.value(); | ||
if (profile.has_value()) | ||
opts.profile = profile.value(); | ||
if (optable.has_value()) | ||
{ | ||
if (auto translated = find_instruction_set(optable.value()); translated.has_value()) | ||
{ | ||
opts.instr_set = translated.value(); | ||
} | ||
} | ||
if (system_id.has_value()) | ||
opts.system_id = system_id.value(); | ||
if (goff.has_value()) | ||
opts.sysopt_xobject = goff.value(); | ||
} | ||
|
||
bool assembler_options::has_value() const noexcept | ||
{ | ||
return sysparm.has_value() || profile.has_value() || optable.has_value() || system_id.has_value() | ||
|| goff.has_value(); | ||
} | ||
|
||
template<typename T> | ||
void optional_to_json(nlohmann::json& j, std::string name, const std::optional<T>& o) | ||
{ | ||
if (o.has_value()) | ||
j[name] = o.value(); | ||
} | ||
|
||
template<typename T> | ||
void optional_from_json(const nlohmann::json& j, std::string_view name, std::optional<T>& o) | ||
{ | ||
if (auto it = j.find(name); it != j.end()) | ||
o = it->get<T>(); | ||
else | ||
o.reset(); | ||
} | ||
|
||
void to_json(nlohmann::json& j, const assembler_options& p) | ||
{ | ||
j = nlohmann::json::object(); | ||
optional_to_json(j, "GOFF", p.goff); // GOFF and XOBJECTS are synonyms | ||
optional_to_json(j, "OPTABLE", p.optable); | ||
optional_to_json(j, "PROFILE", p.profile); | ||
optional_to_json(j, "SYSPARM", p.sysparm); | ||
optional_to_json(j, "SYSTEM_ID", p.system_id); | ||
} | ||
|
||
namespace { | ||
std::optional<bool> get_goff_from_json(const nlohmann::json& j) | ||
{ | ||
bool present = false; | ||
bool goff = false; | ||
bool xobject = false; | ||
|
||
if (auto it = j.find("GOFF"); it != j.end()) | ||
{ | ||
it->get_to(goff); | ||
present = true; | ||
} | ||
|
||
if (auto it = j.find("XOBJECT"); it != j.end()) | ||
{ | ||
it->get_to(xobject); | ||
present = true; | ||
} | ||
if (present) | ||
return goff || xobject; // GOFF and XOBJECTS are synonyms | ||
else | ||
return std::nullopt; | ||
} | ||
} // namespace | ||
|
||
void from_json(const nlohmann::json& j, assembler_options& p) | ||
{ | ||
if (!j.is_object()) | ||
throw nlohmann::json::other_error::create(501, "asm_options must be an object."); | ||
|
||
p.goff = get_goff_from_json(j); | ||
optional_from_json(j, "OPTABLE", p.optable); | ||
optional_from_json(j, "PROFILE", p.profile); | ||
optional_from_json(j, "SYSPARM", p.sysparm); | ||
optional_from_json(j, "SYSTEM_ID", p.system_id); | ||
} | ||
} // namespace hlasm_plugin::parser_library::config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2022 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
*/ | ||
|
||
#ifndef HLASMPARSER_PARSERLIBRARY_CONFIG_ASSEMBLER_OPTIONS_H | ||
#define HLASMPARSER_PARSERLIBRARY_CONFIG_ASSEMBLER_OPTIONS_H | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
#include "nlohmann/json_fwd.hpp" | ||
|
||
namespace hlasm_plugin::parser_library { | ||
struct asm_option; | ||
} // namespace hlasm_plugin::parser_library | ||
|
||
namespace hlasm_plugin::parser_library::config { | ||
|
||
struct assembler_options | ||
{ | ||
std::optional<std::string> sysparm; | ||
std::optional<std::string> profile; | ||
std::optional<std::string> optable; | ||
std::optional<std::string> system_id; | ||
std::optional<bool> goff; | ||
|
||
bool operator==(const assembler_options&) const = default; | ||
bool valid() const noexcept; | ||
void apply(asm_option& opts) const; | ||
bool has_value() const noexcept; | ||
}; | ||
void to_json(nlohmann::json& j, const assembler_options& p); | ||
void from_json(const nlohmann::json& j, assembler_options& p); | ||
} // namespace hlasm_plugin::parser_library::config | ||
#endif |
Oops, something went wrong.