Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit ea45e8c

Browse files
committed
Add: Verilog support.
1 parent 8342e0a commit ea45e8c

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

bookserver/internal/feedback.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def _platform_edit(
276276
elif ext == ".rs":
277277
# Rust doesn't support `setting line numbers <https://github.com/rust-lang/rfcs/issues/1862>`__ either.
278278
fmt = ""
279+
elif ext == ".v":
280+
# Quoting from section 19.7 of the IEEE Standard for Verilog Hardware Description Language (IEEE Std 1364-2005), the syntax for this compiler directive is ```line number "filename" level``, where ``level == 0`` indicates that this line doesn't precede or follow an include directive.
281+
fmt = '`line 1 "box {}" 0\n'
279282
else:
280283
# This is an unsupported language. It would be nice to report this as an error instead of raising an exception.
281284
raise RuntimeError("Unsupported extension {}".format(ext))

bookserver/internal/scheduled_builder.py

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _scheduled_builder(
8686
"rust": rust_builder,
8787
"pic24-xc16-bullylib": xc16_builder,
8888
"armv7-newlib-sim": armv7_builder,
89+
"verilog": verilog_builder,
8990
}.get(builder, None)
9091
if builder_func is None:
9192
raise RuntimeError(f"Unknown builder {builder}")
@@ -197,21 +198,21 @@ def copy_test_file_to_tmp(
197198
return test_file_name
198199

199200

200-
# Given an list of arguments to pass as the first parameter of ``subprocess.run``, wrap this in runguard. Return an updates list of parameters for ``subprocess.run``.
201+
# Given an list of arguments to pass as the first parameter of ``subprocess.run``, wrap this in runguard. Return an updated list of parameters for ``subprocess.run``.
201202
def runguard(
202203
# A list of arguments comprising the first parameter of ``subprocess.run``.
203204
args,
204205
# The directory containing the executable to run in runguard.
205206
cwd,
206-
# Kill COMMAND after TIME seconds (float).
207+
# Kill COMMAND after TIME seconds (float). Omitted if this argument is falsey.
207208
time_s=15,
208-
# Set maximum CPU time to TIME seconds (float).
209+
# Set maximum CPU time to TIME seconds (float). Omitted if this argument is falsey.
209210
cputime_s=10,
210-
# Set all (total, stack, etc) memory limits to SIZE kB.
211-
memsize_kb=100,
212-
# Set maximum created filesize to SIZE kB.
211+
# Set all (total, stack, etc) memory limits to SIZE kB. Omitted if this argument is falsey.
212+
memsize_kb=100000,
213+
# Set maximum created filesize to SIZE kB. Omitted if this argument is falsey.
213214
filesize_kb=50,
214-
# Set maximum no. processes to N.
215+
# Set maximum no. processes to N. Omitted if this argument is falsey.
215216
num_processes=1,
216217
# Disable core dumps when True
217218
no_core_dumps=True,
@@ -226,12 +227,12 @@ def runguard(
226227
"/var/www/jobe/runguard/runguard",
227228
f"--user={user}",
228229
"--group=jobe",
229-
f"--time={time_s}",
230-
f"--cputime={cputime_s}",
231-
f"--memsize={memsize_kb}",
232-
f"--filesize={filesize_kb}",
233-
f"--nproc={num_processes}",
234230
]
231+
+ ([f"--time={time_s}"] if time_s else [])
232+
+ ([f"--cputime={cputime_s}"] if cputime_s else [])
233+
+ ([f"--memsize={memsize_kb}"] if memsize_kb else [])
234+
+ ([f"--filesize={filesize_kb}"] if filesize_kb else [])
235+
+ ([f"--nproc={num_processes}"] if num_processes else [])
235236
+ (["--no-core"] if no_core_dumps else [])
236237
+ args
237238
)
@@ -264,9 +265,12 @@ def rust_builder(
264265
out_list = []
265266
report_subprocess(["rustc", "--test", run_file_name], "Compile", cwd, out_list)
266267

267-
# Run.
268+
# Run. Experimentation shows that Rust uses two processes (perhaps one for the test harness?).
268269
return report_subprocess(
269-
runguard(["./" + os.path.splitext(run_file_name)[0]], cwd), "Run", cwd, out_list
270+
runguard(["./" + os.path.splitext(run_file_name)[0]], cwd, num_processes=2),
271+
"Run",
272+
cwd,
273+
out_list,
270274
)
271275

272276

@@ -578,3 +582,57 @@ def armv7_builder(
578582
return out_list, (
579583
100 if correct == 100 and check_sim_out(out_list, verification_code) else 0
580584
)
585+
586+
587+
def verilog_builder(
588+
file_path, cwd, sphinx_base_path, sphinx_source_path, sphinx_out_path, source_path
589+
):
590+
# Build the test code with a random verification code.
591+
out_list = []
592+
verification_code = get_verification_code()
593+
test_file_path = os.path.join(
594+
sphinx_base_path,
595+
sphinx_source_path,
596+
os.path.splitext(source_path)[0] + "-test.v",
597+
)
598+
preproc_path = file_path + ".test.vp"
599+
report_subprocess(
600+
[
601+
"iverilog",
602+
# Only do preprocessing; don't compile the result.
603+
"-E",
604+
# Pass the verification code.
605+
"-DVERIFICATION_CODE=({})".format(verification_code),
606+
"-o",
607+
preproc_path,
608+
test_file_path,
609+
],
610+
"Compile test code",
611+
cwd,
612+
out_list,
613+
)
614+
615+
# Compile the source and test code.
616+
exe_path = file_path + ".exe"
617+
report_subprocess(
618+
[
619+
"iverilog",
620+
"-o",
621+
exe_path,
622+
file_path,
623+
preproc_path,
624+
],
625+
"Compile",
626+
cwd,
627+
out_list,
628+
)
629+
630+
# Run the simulation.
631+
report_subprocess(
632+
runguard([exe_path], cwd, memsize_kb=100000),
633+
"Simulation",
634+
cwd,
635+
out_list,
636+
include_stderr=True,
637+
)
638+
return out_list, (100 if check_sim_out(out_list, verification_code) else 0)

0 commit comments

Comments
 (0)