Skip to content

Commit 2ca611b

Browse files
authored
Merge pull request #4778 from YosysHQ/setenv_pass
add setenv pass
2 parents 4a755f5 + 8557455 commit 2ca611b

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

passes/cmds/Makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ OBJS += passes/cmds/box_derive.o
5252
OBJS += passes/cmds/example_dt.o
5353
OBJS += passes/cmds/portarcs.o
5454
OBJS += passes/cmds/wrapcell.o
55+
OBJS += passes/cmds/setenv.o

passes/cmds/setenv.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* yosys -- Yosys Open SYnthesis Suite
3+
*
4+
* Copyright (C) 2024 N. Engelhardt <[email protected]>
5+
*
6+
* Permission to use, copy, modify, and/or distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*
18+
*/
19+
20+
#include "kernel/register.h"
21+
#include "kernel/rtlil.h"
22+
#include "kernel/log.h"
23+
#include <stdlib.h>
24+
25+
USING_YOSYS_NAMESPACE
26+
PRIVATE_NAMESPACE_BEGIN
27+
struct SetenvPass : public Pass {
28+
SetenvPass() : Pass("setenv", "set an environment variable") { }
29+
void help() override
30+
{
31+
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
32+
log("\n");
33+
log(" setenv name value\n");
34+
log("\n");
35+
log("Set the given environment variable on the current process. Values containing\n");
36+
log("whitespace must be passed in double quotes (\").\n");
37+
log("\n");
38+
}
39+
void execute(std::vector<std::string> args, [[maybe_unused]] RTLIL::Design *design) override
40+
{
41+
if(args.size() != 3)
42+
log_cmd_error("Wrong number of arguments given.\n");
43+
44+
std::string name = args[1];
45+
std::string value = args[2];
46+
if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2);
47+
48+
#if defined(_WIN32)
49+
_putenv_s(name.c_str(), value.c_str());
50+
#else
51+
if (setenv(name.c_str(), value.c_str(), 1))
52+
log_cmd_error("Invalid name \"%s\".\n", name.c_str());
53+
#endif
54+
55+
}
56+
} SetenvPass;
57+
58+
PRIVATE_NAMESPACE_END

tests/verific/setenv.flist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${filename}

tests/verific/setenv.ys

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
setenv filename case.sv
2+
verific -f -sv setenv.flist
3+
verific -import top
4+
select -assert-mod-count 1 top

0 commit comments

Comments
 (0)