Skip to content

Commit

Permalink
feat: Assembler options can be specified in pgm_conf.json to override…
Browse files Browse the repository at this point in the history
… values from proc_grps.json
  • Loading branch information
slavek-kucera authored Apr 28, 2022
1 parent 7ac224c commit bf24968
Show file tree
Hide file tree
Showing 27 changed files with 622 additions and 324 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Instruction set versioning support
- Basic GOFF, XOBJECT and SYSOPT_XOBJECT support
- MNOTE support
- Assembler options can be specified in pgm_conf.json to override values from proc_grps.json

#### Fixed
- Fixed an issue preventing correct N' attribute evaluation of empty subscript arrays
Expand Down
16 changes: 16 additions & 0 deletions clients/vscode-hlasmplugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ The program name in `pgm_conf.json` can be wildcarded, as in the following examp
```
In this example, GROUP1 is used for all open code programs.

Assmebler options defined by the processor group can be overriden in the `pgm_conf.json` file as shown in the following example:
```
{
"pgms": [
{
"program": "source_code",
"pgroup": "GROUP1",
"asm_options":
{
"SYSPARM": "SYSPARM override value"
}
}
]
}
```

### File Extensions

The `alwaysRecognize` option in `pgm_conf.json` has been deprecated in favour of the standard VSCode user and workspace level setting `file.associations`.
Expand Down
4 changes: 2 additions & 2 deletions clients/vscode-hlasmplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
"jsonValidation": [
{
"fileMatch": "pgm_conf.json",
"url": "./pgm_conf_schema"
"url": "./schema/pgm_conf.json"
},
{
"fileMatch": "proc_grps.json",
"url": "./proc_grps_schema"
"url": "./schema/proc_grps.json"
}
],
"breakpoints": [
Expand Down
56 changes: 56 additions & 0 deletions clients/vscode-hlasmplugin/schema/asm_options.json
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."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"pgroup": {
"type": "string",
"description": "Name of processor group as defined in proc_grps.json"
},
"asm_options": {
"$ref": "asm_options.json"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,60 +46,7 @@
}
},
"asm_options": {
"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."
}
}
"$ref": "asm_options.json"
},
"preprocessor": {
"description": "Defines optional preprocessor pass for open code.",
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/compiler_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct asm_option
bool sysopt_xobject = sysopt_xobject_default;

long long statement_count_limit = 10'000'000;

bool operator==(const asm_option&) const = default;
};
} // namespace hlasm_plugin::parser_library
#endif
2 changes: 2 additions & 0 deletions parser_library/src/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# Broadcom, Inc. - initial API and implementation

target_sources(parser_library PRIVATE
assembler_options.cpp
assembler_options.h
pgm_conf.cpp
pgm_conf.h
proc_grps.cpp
Expand Down
154 changes: 154 additions & 0 deletions parser_library/src/config/assembler_options.cpp
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
45 changes: 45 additions & 0 deletions parser_library/src/config/assembler_options.h
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
Loading

0 comments on commit bf24968

Please sign in to comment.