Skip to content

Commit 8b0f665

Browse files
committed
add setenv pass
1 parent b66897e commit 8b0f665

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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. String values must be\n");
36+
log("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+
setenv(args[1].c_str(), args[2].c_str(), 1);
45+
46+
}
47+
} SetenvPass;
48+
49+
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)