Skip to content

Commit

Permalink
feat: Provide users ability to use compiler option "SYSPARM" (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Sweta Shah <swetas04@gmail.com>
  • Loading branch information
SWETAS04 authored Mar 11, 2021
1 parent c5b233d commit ccb3a0a
Show file tree
Hide file tree
Showing 24 changed files with 207 additions and 19 deletions.
18 changes: 17 additions & 1 deletion clients/vscode-hlasmplugin/proc_grps_schema
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
"required": [ "path" ]
}
]
}

},
"asm_options": {
"type": "object",
"description": "List of assembler options",
"properties": {
"SYSPARM": {
"type": "string",
"description": "It 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."
}
}
}
},
Expand All @@ -43,4 +59,4 @@
}
},
"required" : ["pgroups"]
}
}
4 changes: 4 additions & 0 deletions example_workspace/.hlasmplugin/pgm_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"program": "JULSUB",
"pgroup": "JULSUB_PG"
},
{
"program": "factorial.hlasm",
"pgroup": "P1"
}
],
"alwaysRecognize": ["*.hlasm"]
Expand Down
11 changes: 7 additions & 4 deletions example_workspace/.hlasmplugin/proc_grps.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"pgroups": [
{
"name": "P1",
"libs": [
"libs","libs2"
]
"name": "P1",
"libs": [
"libs","libs2"
],
"asm_options": {
"SYSPARM": "SEVEN"
}
},
{
"name": "JULSUB_PG",
Expand Down
3 changes: 3 additions & 0 deletions example_workspace/factorial.hlasm
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ LEN120 DS CL(&RES)
* than 12 because it does not fit into 32 bit variable.
FACT 6
LEN720 DS CL(&RES)
AIF ('&SYSPARM' EQ 'SEVEN').HERE
ANOP
.HERE FACT 7
2 changes: 0 additions & 2 deletions parser_library/include/workspace_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class PARSER_LIBRARY_EXPORT workspace_manager
private:
impl* impl_;
};


} // namespace parser_library
} // namespace hlasm_plugin
#endif // !HLASMPLUGIN_PARSERLIBRARY_WORKSPACE_MANAGER_H
2 changes: 1 addition & 1 deletion parser_library/src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ analyzer::analyzer(const std::string& text,
: analyzer(text,
file_name,
lib_provider,
new context::hlasm_context(file_name),
new context::hlasm_context(file_name, lib_provider.get_asm_options(file_name)),
library_data { processing::processing_kind::ORDINARY, context::id_storage::empty_id },
true,
tracer,
Expand Down
30 changes: 30 additions & 0 deletions parser_library/src/compiler_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2019 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_COMPILER_OPTIONS_H
#define HLASMPARSER_PARSERLIBRARY_COMPILER_OPTIONS_H

#include <string>

// This file contains assembler compiler options definitions.

namespace hlasm_plugin::parser_library {
struct asm_option

{
std::string sysparm;
std::string profile;
};
} // namespace hlasm_plugin::parser_library
#endif
10 changes: 8 additions & 2 deletions parser_library/src/context/hlasm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "expressions/conditional_assembly/terms/ca_symbol_attribute.h"
#include "instruction.h"


namespace hlasm_plugin::parser_library::context {

code_scope* hlasm_context::curr_scope() { return &scope_stack_.back(); }
Expand Down Expand Up @@ -223,6 +224,9 @@ void hlasm_context::add_global_system_vars()

{
auto val = std::make_shared<set_symbol<C_t>>(SYSPARM, true, true);

val->set_value(asm_options_.sysparm);

globals_.insert({ SYSPARM, std::move(val) });
}
{
Expand All @@ -248,8 +252,10 @@ bool hlasm_context::is_opcode(id_index symbol) const
return macros_.find(symbol) != macros_.end() || instruction_map_.find(symbol) != instruction_map_.end();
}

hlasm_context::hlasm_context(std::string file_name)
: instruction_map_(init_instruction_map())
hlasm_context::hlasm_context(std::string file_name, asm_option asm_options)

: asm_options_(std::move(asm_options))
, instruction_map_(init_instruction_map())
, SYSNDX_(0)
, ord_ctx(ids_)
, lsp_ctx(std::make_shared<lsp_context>())
Expand Down
7 changes: 6 additions & 1 deletion parser_library/src/context/hlasm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef CONTEXT_HLASM_CONTEXT_H
#define CONTEXT_HLASM_CONTEXT_H

#include <compiler_options.h>
#include <deque>
#include <memory>
#include <set>
Expand All @@ -26,6 +27,7 @@
#include "ordinary_assembly/ordinary_assembly_context.h"
#include "processing_context.h"


namespace hlasm_plugin::parser_library::context {

class hlasm_context;
Expand Down Expand Up @@ -67,6 +69,9 @@ class hlasm_context
// all files processes via macro or copy member invocation
std::set<std::string> visited_files_;

// Compiler options
asm_option asm_options_;

// map of all instruction in HLASM
const instruction_storage instruction_map_;
instruction_storage init_instruction_map();
Expand All @@ -79,7 +84,7 @@ class hlasm_context
bool is_opcode(id_index symbol) const;

public:
hlasm_context(std::string file_name = "");
hlasm_context(std::string file_name = "", asm_option asm_opts = {});

// gets name of file where is open-code located
const std::string& opencode_file_name() const;
Expand Down
6 changes: 6 additions & 0 deletions parser_library/src/debugging/debug_lib_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class debug_lib_provider : public workspaces::parse_lib_provider

return false;
}
const asm_option& get_asm_options(const std::string& file_name) override
{
auto& proc_grp = ws_.get_proc_grp_by_program(file_name);

return proc_grp.asm_options();
}
};

} // namespace hlasm_plugin::parser_library::debugging
Expand Down
5 changes: 5 additions & 0 deletions parser_library/src/workspaces/parse_lib_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,24 @@ class parse_lib_provider

virtual bool has_library(const std::string& library, context::hlasm_context& hlasm_ctx) const = 0;

virtual const asm_option& get_asm_options(const std::string&) = 0;

virtual ~parse_lib_provider() = default;
};

// Parse lib provider that does not provide any libraries.
class empty_parse_lib_provider : public parse_lib_provider
{
asm_option asm_opts;

public:
virtual parse_result parse_library(const std::string&, context::hlasm_context&, const library_data) override
{
return false;
};
virtual bool has_library(const std::string&, context::hlasm_context&) const override { return false; };

const asm_option& get_asm_options(const std::string&) override { return asm_opts; };
static empty_parse_lib_provider instance;
};

Expand Down
12 changes: 10 additions & 2 deletions parser_library/src/workspaces/processor_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "diagnosable_impl.h"
#include "library.h"

namespace hlasm_plugin::parser_library::workspaces {

// Represents a named set of libraries (processor_group)
Expand All @@ -38,14 +37,23 @@ class processor_group : public diagnosable_impl

void add_library(std::unique_ptr<library> library) { libs_.push_back(std::move(library)); }

void add_asm_options(std::map<std::string, std::string> asm_options)
{
asm_optns.sysparm = asm_options.count("SYSPARM") ? asm_options.at("SYSPARM") : "";
asm_optns.profile = asm_options.count("PROFILE") ? asm_options.at("PROFILE") : "";
}

const std::string& name() const { return name_; }

const std::vector<std::unique_ptr<library>>& libraries() const { return libs_; }

const asm_option& asm_options() const { return asm_optns; }


private:
std::vector<std::unique_ptr<library>> libs_;
std::string name_;
asm_option asm_optns;
};

} // namespace hlasm_plugin::parser_library::workspaces
#endif // !HLASMPLUGIN_PARSERLIBRARY_PROCESSOR_GROUP_H
25 changes: 24 additions & 1 deletion parser_library/src/workspaces/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,20 @@ bool workspace::load_and_process_config()
{
const std::string& name = pg["name"].get<std::string>();
const json& libs = pg["libs"];

std::map<std::string, std::string> asm_options;
try
{
if (pg.count("asm_options"))
{
asm_options = pg.at("asm_options").get<std::map<std::string, std::string>>();
}
}
catch (const nlohmann::basic_json<>::exception&)
{
file_ptr proc_grps_file =
file_manager_.add_file((ws_path / HLASM_PLUGIN_FOLDER / FILENAME_PROC_GRPS).string());
config_diags_.push_back(diagnostic_s::error_W002(proc_grps_file->get_file_name(), name_));
}
processor_group prc_grp(name);

for (auto& lib_path_json : libs)
Expand Down Expand Up @@ -347,6 +360,10 @@ bool workspace::load_and_process_config()
// else ignore, publish warning
}
}
if (!asm_options.empty())
{
prc_grp.add_asm_options(asm_options);
}

add_proc_grp(std::move(prc_grp));
}
Expand Down Expand Up @@ -501,4 +518,10 @@ bool workspace::has_library(const std::string& library, context::hlasm_context&
return false;
}

const asm_option& workspace::get_asm_options(const std::string& file_name)
{
auto& proc_grp = get_proc_grp_by_program(file_name);

return proc_grp.asm_options();
}
} // namespace hlasm_plugin::parser_library::workspaces
1 change: 1 addition & 0 deletions parser_library/src/workspaces/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class workspace : public diagnosable_impl, public parse_lib_provider
virtual parse_result parse_library(
const std::string& library, context::hlasm_context& hlasm_ctx, const library_data data) override;
virtual bool has_library(const std::string& library, context::hlasm_context& hlasm_ctx) const override;
const asm_option& get_asm_options(const std::string& file_name) override;

const ws_uri& uri();

Expand Down
3 changes: 3 additions & 0 deletions parser_library/test/context/data_attribute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ TEST(data_attributes, O_opencode_var)

class O_mock : public workspaces::parse_lib_provider
{
asm_option asm_options;

public:
virtual workspaces::parse_result parse_library(
const std::string& library, context::hlasm_context& hlasm_ctx, const workspaces::library_data data) override
Expand All @@ -723,6 +725,7 @@ class O_mock : public workspaces::parse_lib_provider
return true;
}
virtual bool has_library(const std::string& lib, context::hlasm_context&) const override { return lib == "MAC"; }
virtual const asm_option& get_asm_options(const std::string&) { return asm_options; }

private:
const std::string M =
Expand Down
3 changes: 3 additions & 0 deletions parser_library/test/context/macro_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ TEST(macro, arguments_continuation)

class bad_mock : public parse_lib_provider
{
asm_option asm_options;

public:
bad_mock(int lib_code)
: current_content(lib_code == 0 ? &content_bad_name : lib_code == 1 ? &content_bad_begin : &content_comment)
Expand All @@ -532,6 +534,7 @@ class bad_mock : public parse_lib_provider
return true;
}
virtual bool has_library(const std::string&, context::hlasm_context&) const { return true; }
virtual const asm_option& get_asm_options(const std::string&) { return asm_options; }
std::unique_ptr<analyzer> a;

private:
Expand Down
3 changes: 3 additions & 0 deletions parser_library/test/context/ord_sym_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ X3 EQU F-E

class loc_mock : public workspaces::parse_lib_provider
{
asm_option asm_options;
virtual workspaces::parse_result parse_library(
const std::string& library, context::hlasm_context& hlasm_ctx, const workspaces::library_data data)
{
Expand All @@ -294,6 +295,8 @@ class loc_mock : public workspaces::parse_lib_provider
}

virtual bool has_library(const std::string&, context::hlasm_context&) const { return true; }

virtual const asm_option& get_asm_options(const std::string&) { return asm_options; }
};

TEST(ordinary_symbols, symbol_location)
Expand Down
3 changes: 3 additions & 0 deletions parser_library/test/copy_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace hlasm_plugin::parser_library {

class copy_mock : public workspaces::parse_lib_provider
{
asm_option asm_options;
const std::string* find_content(const std::string& library) const
{
if (library == "COPYR")
Expand Down Expand Up @@ -74,6 +75,8 @@ class copy_mock : public workspaces::parse_lib_provider
(void)hlasm_ctx;
return find_content(library);
}

virtual const asm_option& get_asm_options(const std::string&) { return asm_options; }
std::vector<std::unique_ptr<analyzer>> holder;
std::unique_ptr<analyzer> a;

Expand Down
Loading

0 comments on commit ccb3a0a

Please sign in to comment.