Compare commits

..

43 Commits

Author SHA1 Message Date
Nikolay Puzanov
3aee2d2f38 Fix help message 2024-04-14 16:16:45 +03:00
Nikolay Puzanov
b84ec9a1c5 Remove clock from testbench input 2024-04-14 16:08:20 +03:00
Nikolay Puzanov
1e0bfb58cf Add support for verilator 5.018+ 2023-11-07 14:27:08 +03:00
Nikolay Puzanov
e67558de14 Enable dump in iverilog testbench template 2023-06-02 11:08:51 +03:00
Nikolay Puzanov
54f7e2be54 Enable trace of structs 2022-12-13 11:49:15 +03:00
Nikolay Puzanov
cc605cce85 Top module for all simulators must have an input clock signal 2022-12-09 10:21:40 +03:00
Nikolay Puzanov
2f9f5b6dd1 Disable Save hotkey (to prevent thoughtless use) 2022-12-09 10:13:03 +03:00
Nikolay Puzanov
cb8bc37dfe Disable ligatures 2022-12-09 09:23:07 +03:00
Nikolay Puzanov
1e12d5d3e2 Don't save unmodified code 2022-12-09 09:20:53 +03:00
Nikolay Puzanov
1bc6ec544d Save code only by Save button. Save always to new location 2022-12-09 09:07:13 +03:00
Nikolay Puzanov
d04282e1c7 Add simple scroll of long waveform 2022-12-08 19:06:08 +03:00
Nikolay Puzanov
664b7b1f5c Buttons can move to new line 2022-12-07 18:07:00 +03:00
Nikolay Puzanov
37b7a54d3b Visual improvements 2022-12-07 17:55:21 +03:00
Nikolay Puzanov
01c982fada Fix parsing canvas width 2022-12-07 17:54:50 +03:00
Nikolay Puzanov
931f4d8aa4 Fix signals sorting (put clock on the top) 2022-12-07 17:53:50 +03:00
Nikolay Puzanov
90905544d4 Upcase signal values 2022-12-07 17:53:17 +03:00
Nikolay Puzanov
ab5db7f6e8 Add waveforms 2022-12-07 17:00:51 +03:00
Nikolay Puzanov
e8ba09ecab Add VCD to SVG conversion functions 2022-12-06 20:06:26 +03:00
Nikolay Puzanov
daa744f8b2 Replace 'when not' to 'unless' 2022-12-05 20:26:04 +03:00
Nikolay Puzanov
c91003e34b Replace string-trim (left only trim) by string-trim-both 2022-12-04 19:53:56 +03:00
Nikolay Puzanov
53412381fb Optionally enable timestamp in save snippet uri 2022-12-04 12:09:32 +03:00
Nikolay Puzanov
536bde92df Allow to disable code sanitization 2022-12-04 11:29:25 +03:00
Nikolay Puzanov
b9cd29ad87 Fix Crtl-S hotkey 2022-12-04 11:29:10 +03:00
Nikolay Puzanov
c6c6744b22 Show execution time of compilation and simulation 2022-12-04 10:20:53 +03:00
Nikolay Puzanov
42f22147ea Limit dump file size for Icarus Verilog 2022-12-03 23:53:03 +03:00
Nikolay Puzanov
b4507004b8 Add latest Icarus Verilog and Verilator to Docker image 2022-12-03 19:31:39 +03:00
Nikolay Puzanov
74e76d8131 Add verilator build jobs option 2022-12-03 19:30:58 +03:00
Nikolay Puzanov
058191de55 Add Verilator support 2022-12-03 18:36:50 +03:00
Nikolay Puzanov
f61bb7b980 Prepare to add Verilator 2022-12-03 13:52:43 +03:00
Nikolay Puzanov
9939a226c8 Add help button 2022-12-03 13:32:09 +03:00
Nikolay Puzanov
185dcb350d Fix content type of binary response. Add favicon 2022-12-02 18:46:42 +03:00
Nikolay Puzanov
28d86fb98d Disable side-by-side layout on mobile phones 2022-12-02 16:13:39 +03:00
Nikolay Puzanov
680e9f3aa5 Add 'Save as new' button 2022-12-02 14:53:43 +03:00
Nikolay Puzanov
ec02787747 Change page design. Make page mobile friendly 2022-12-02 14:33:31 +03:00
Nikolay Puzanov
b87a7e0c97 Flush stdout after log string printing 2022-12-01 22:15:59 +03:00
Nikolay Puzanov
6a9959f98d Add docker related files 2022-12-01 22:05:28 +03:00
Nikolay Puzanov
61a16ad2cd Add charset meta to html page 2022-12-01 22:05:01 +03:00
Nikolay Puzanov
9f4fbe2499 Rename file 2022-12-01 22:04:50 +03:00
Nikolay Puzanov
347dfa0af6 CTRL-C as $finish 2022-12-01 19:33:53 +03:00
Nikolay Puzanov
5a23aa8e0f Place log level initialization after args checking 2022-12-01 17:14:10 +03:00
Nikolay Puzanov
171b821dbb Show "Please wait..." when waiting for simulation complete 2022-12-01 16:51:37 +03:00
Nikolay Puzanov
0e4d5a2df3 Add optionsfor work dir, storage dir and logging level. Split GET and POST requests. Some other changes. 2022-12-01 16:50:01 +03:00
Nikolay Puzanov
43a2e51137 Move sources to server folder 2022-12-01 13:26:06 +03:00
15 changed files with 1471 additions and 608 deletions

View File

@@ -10,4 +10,11 @@ module testbench;
initial begin initial begin
$finish; $finish;
end end
`ifdef DUMP
initial begin
$dumpfile("testbench.fst");
$dumpvars(0, testbench);
end
`endif
endmodule endmodule

52
_web_server/Dockerfile Normal file
View File

@@ -0,0 +1,52 @@
# syntax=docker/dockerfile:1
FROM ubuntu:22.10
LABEL description="Verilog playground"
# Prepare OS
RUN sed -i 's/^# *deb-src/deb-src/g' /etc/apt/sources.list
RUN apt-get -y update \
&& apt-get -y install guile-3.0 locales git
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
&& locale-gen
RUN apt-get build-dep -y iverilog verilator
# Build latest Icarus Veriolog
WORKDIR /build
RUN git clone --depth 1 https://github.com/steveicarus/iverilog.git
WORKDIR /build/iverilog
RUN sh ./autoconf.sh && ./configure --prefix=/usr && make -j2 && make install
# Build latest Verilator
WORKDIR /build
RUN git clone --depth 1 https://github.com/verilator/verilator.git
WORKDIR /build/verilator
RUN autoconf && ./configure --prefix=/usr && make -j2 && make install
# Environment
ENV GIT_SSL_NO_VERIFY=1
ENV GUILE_LOAD_PATH=/server/embddr-scheme-library
ENV LANG=en_US.UTF-8
ENV DONOTUSEFIREJAIL=1
# Copy server files
WORKDIR /server
COPY server/* ./
RUN git clone https://git.embddr.com/np/embddr-scheme-library.git
RUN mkdir play-work /verilog-playground-store
EXPOSE 8080
VOLUME /verilog-playground-store
CMD [ "guile", "-e", "main", \
"./playground-server.scm", \
"--port=8080", \
"--addr=0.0.0.0", \
"--host=https://play.embddr.com", \
"--iverilog-wrap=./restrict", \
"--vvp-wrap=./restrict", \
"--verilator-sim-wrap=./restrict", \
"--verilator-build-jobs=2", \
"--max-len=10000", \
"--work-base=play-work", \
"--stor-base=/verilog-playground-store", \
"--log-level=2" ]

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
docker build -t playground .

45
_web_server/container-run.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
if [ 0 -eq "$#" ]; then
echo "Usage $0 start/stop/status"
exit -1
fi
action=$1
container=playground
case $action in
"start")
cid=$(docker container ls -q -a -f name=$container)
if [ -z "$cid" ]; then
docker run -d --name $container \
-p 127.0.0.1:8089:8080 \
-v /srv/playground/storage:/verilog-playground-store \
--cpus=1 --memory=16g --memory-swap=16g \
$container
else
docker start $container
fi
;;
"stop")
# Press twice CRTL-C
docker kill -s SIGINT $container
docker kill -s SIGINT $container
;;
"status")
cid=$(docker container ls -q -f name=$container)
if [ -z "$cid" ]; then
echo "Stopped"
else
echo "Started"
fi
;;
"*")
echo "Unknown action $action. Actions start, stop and status are allowed"
;;
esac

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env bash
exe=$(basename $0)
exec firejail --noprofile --quiet \
--rlimit-cpu=1 \
--rlimit-as=100m \
--rlimit-fsize=1m \
"$exe" "$@"

View File

@@ -1,106 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Verilog Playground</title>
<style type="text/css" media="screen">
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap');
.container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 5px;
box-sizing: border-box;
background: white;
font-family: 'JetBrains Mono', monospace;
font-size: 14px;
}
.panel {
float: left;
position: relative;
height: 100%;
padding: 4px;
border: 1px solid #008899;
box-sizing: border-box;
}
.ctrl-panel { width: 10%; }
.editor { width: 45%; }
.log-panel { width: 45%; }
#log {
width: 100%;
height: 100%;
border: 0px;
font-size: inherit;
}
</style>
</head>
<body>
<div class="container">
<div class="panel ctrl-panel">
<button style="width:100%" onclick="save_code()">Save (ctrl+s)</button>
<button style="width:100%" onclick="send_to_icarus()">Run Icarus Verilog</button>
</div>
<div class="panel editor" id="editor">@CODE@</div>
<div class="panel log-panel">
<textarea id="log" readonly="readonly"></textarea>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var editor = ace.edit('editor');
editor.setTheme('ace/theme/chrome');
editor.session.setMode('ace/mode/verilog');
editor.setOptions({
tabSize : 2,
fontSize : 14,
fontFamily : 'JetBrains Mono, monospace',
enableBasicAutocompletion : true,
enableLiveAutocompletion : true
});
const log_area = document.getElementById('log');
function send_to_icarus() {
fetch('%IVERILOGPOSTURI%',
{
method: 'POST',
headers: {
'Accept': 'text/plain',
'Content-Type': 'text/plain'
},
body: editor.getValue()
})
.then((response) => response.text())
.then((text) => { log_area.value = text; });
};
function save_code() {
fetch('%SAVECODEURI%',
{
method: 'POST',
headers: {
'Accept': 'text/plain',
'Content-Type': 'text/plain'
},
body: editor.getValue()
})
.then((response) => response.text())
.then((text) => { window.location.href = text; });
};
document.addEventListener('keydown', (e) => {
if (e.key.toLowerCase() === 's' && e.ctrlKey) {
e.preventDefault();
save_code();
}
});
</script>
</body>
</html>

View File

@@ -1 +0,0 @@
./firejailed.sh

View File

@@ -1,491 +0,0 @@
#!/usr/bin/env -S guile -e "main" -s
!#
;; -*- geiser-scheme-implementation: guile -*-
(import (srfi srfi-1)
(srfi srfi-11)
(srfi srfi-26)
(srfi srfi-28)
(rnrs bytevectors)
(web server)
(web request)
(web response)
(web uri)
(sxml simple)
(ice-9 regex)
(ice-9 binary-ports)
(ice-9 textual-ports)
(ice-9 popen))
(import (embddr common)
(embddr optargs))
(define INDEX-FILE "index.html")
(define LOGGING #t)
(define DELETE-WORK-DIR #t)
(define DEFAULT-CODE
(string-append
"`timescale 10ps/10ps\n\n"
"module test;\n"
" initial begin\n"
" $display(\"Hello world!\");\n"
" $finish();\n"
" end\n"
"endmodule\n"))
(define (multistring . strings)
(apply string-append
(insert-between strings "\n")))
(define (not-found request)
(values (build-response #:code 404)
(string-append "Resource not found: "
(uri->string (request-uri request)))))
(define* (make-response str #:key (type 'text/html))
(values (build-response
#:headers `((content-type . (,type (charset . "utf-8"))))
#:code 200)
str))
(define* (file-reader file-name #:key (max-read-length 512))
(lambda (port)
(with-input-from-file file-name
(lambda ()
(let loop ()
(let ((data (get-bytevector-n (current-input-port)
max-read-length)))
(when (not (eof-object? data))
(put-bytevector port data)
(loop))))))))
(define* (file-response file #:key (type 'text/html))
(make-response (file-reader file) #:type type))
(define-syntax guard
(syntax-rules ()
((_ default code...)
(with-exception-handler (lambda (e) default)
(lambda () code...)
#:unwind? #t))))
(define (print . args)
(display (apply format args)))
(define (println . args)
(display (apply format args))
(newline))
(define (printlog . args)
(when LOGGING
(display (apply format args))
(newline)))
;;;
;;; Return directory list
;;;
(define (list-dir path)
(if (file-exists? path)
(let ((dir (opendir path)))
(let loop ((ls '()))
(let ((item (readdir dir)))
(if (eof-object? item)
(begin
(closedir dir)
ls)
(if (or (string=? item ".")
(string=? item ".."))
(loop ls)
(loop (cons (string-append path "/" item) ls)))))))
'()))
;;;
;;; Recursive delete directory
;;;
(define (delete-recursive path)
(let ((path (canonicalize-path path)))
(if (eq? 'directory (stat:type (stat path)))
(begin
(for-each delete-recursive (list-dir path))
(rmdir path))
(delete-file path))))
;;;
;;; Trim list
;;;
(define (list-trim l pred)
(cond
((null? l) '())
((pred (car l)) (list-trim (cdr l) pred))
(else
(let ((lr (reverse l)))
(if (pred (car lr))
(reverse (list-trim (cdr lr) pred))
l)))))
;;;
;;; Read template to string
;;;
(define (read-template-text file subst)
(let ((lines (read-template file "%~a%" subst)))
(apply string-append
(append-map (cut list <> "\n") lines))))
;;;
;;; Execute system command and capture stdout and stderr to string list
;;;
(define* (system-to-string cmd #:key (pwd #f))
(let* ((cmd (string-append cmd " 2>&1"))
(cmd (if pwd (format "cd ~a; ~a" pwd cmd) cmd))
(p (open-input-pipe cmd))
(out (get-string-all p)))
(values (close-pipe p) out)))
;;;
;;; Unused
;;;
;; (define* (system-to-string-list cmd #:key (pwd #f))
;; (let-values (((status out)
;; (system-to-string cmd #:pwd pwd)))
;; (values
;; status
;; (list-trim (string-split out #\newline) string-null?))))
;;;
;;; Make pretty log from executable output
;;;
(define (exe-log-pretty cmdline status out)
(string-append
(format "$ ~a\n" cmdline)
(format "Return code: ~a\n" status)
(if (string-null? out)
"\n"
(format "--\n~a\n" out))))
;;;
;;; Trivial sanitize verilog code
;;;
(define (sanitize-verilog code)
(let* (;; $f* functions but not $finish
(code (regexp-substitute/global #f "\\$f[a-hj-z][a-z]+" code 'pre "$error" 'post))
;; $scanf
(code (regexp-substitute/global #f "\\$.?scanf" code 'pre "$error" 'post))
;; $readmem
(code (regexp-substitute/global #f "\\$readmem[bh]" code 'pre "$error" 'post))
;; $dump*
(code (regexp-substitute/global #f "\\$dump[a-z]*" code 'pre "$error" 'post)))
code))
;;;
;;; Get module name
;;;
(define (module-name code)
(let ((rx (make-regexp
"(^|\\s)module\\s*(\\s|(#\\(.*\\)\\s*))[a-zA-Z0-9_]+")))
(let loop ((pos 0)
(modname #f))
(let ((m (regexp-exec rx code pos)))
(if m
(loop (match:end m) (match:substring m))
(if modname
(match:substring (string-match "[a-zA-Z0-9_]+$" modname))
#f))))))
;;;
;;; Create dump module
;;;
(define (create-dump-module path modname top)
(define (* . fmt) (display (apply format fmt)) (newline))
(let ((filename (format "~a/~a.v" path modname)))
(with-output-to-file filename
(lambda ()
(* "`timescale 1ps/1ps")
(* "module ~a();" modname)
(* " initial begin")
(* " $dumpfile(\"~a/~a.vcd\");" path modname)
(* " $dumpvars(0, ~a);" top)
(* " end")
(* "endmodule")))
filename))
;;;
;;; Make workdir with sources and command file
;;; Returns work directory path string
;;;
(define (make-sim-workdir simulator code top)
(let* ((work-dir (mkdtemp (format "work-~a-XXXXXX" (current-time))))
(verilog-file (format "~a/testbench.sv" work-dir))
(command-file (format "~a/testbench.vc" work-dir))
(dump-file (create-dump-module work-dir "dump" top)))
(with-output-to-file verilog-file (cut display code))
(with-output-to-file command-file
(lambda ()
(cond
((eq? simulator 'iverilog)
(println "~a" verilog-file)
(println "~a" dump-file)
(println "+define+TESTBENCH")
(println "+timescale+1ps/1ps")))))
work-dir))
;;;
;;; Compile sources and execute simulation with Icarus Verilog
;;; Returns (values status log)
;;;
(define (exec-sim-iverilog work-dir vvp-exe iverilog-exe)
;; Compile
(let ((cmdline (format "~a -g2012 -o ~a/testbench.vvp -c~a/testbench.vc"
iverilog-exe work-dir work-dir)))
(let-values (((status out)
(system-to-string cmdline)))
(let ((compile-log
(exe-log-pretty cmdline status out)))
(if (not (zero? status))
(values status compile-log)
;; Execute
(let ((cmdline (format "~a ~a/testbench.vvp" vvp-exe work-dir)))
(let-values (((status out)
(system-to-string cmdline)))
(let ((execution-log
(exe-log-pretty cmdline status out)))
(values status (string-append compile-log execution-log))))))))))
;;;
;;; Execute simulation
;;;
(define* (exec-sim simulator code
#:key
(vvp-exe "vvp")
(iverilog-exe "iverilog"))
(let ((top (module-name code)))
(if (not top)
"Error: No module declaration\n"
(let ((work-dir (make-sim-workdir simulator code top)))
(let-values
(((status log)
(cond
((eq? simulator 'iverilog)
(exec-sim-iverilog work-dir vvp-exe iverilog-exe))
(else
(values -1 "No simulator found!\n")))))
;; Delete work dir
(when DELETE-WORK-DIR
(delete-recursive work-dir))
;; Return log
(string-append
log
(format "-----------------\nSimulation complete~a\n"
(if (zero? status)
" succesfully"
" with errors"))))))))
;;;
;;; Get storage path from URI
;;;
(define (get-storage-path uri root-path)
(string-trim
(substring (uri-path uri)
(string-length root-path))
#\/))
;;;
;;; Check storage path validity
;;;
(define (valid-storage-path path)
(if (or (< (string-length path) 1)
(> (string-length path) 32))
#f
(string-fold
(lambda (c valid)
(if (or (char-alphabetic? c)
(char-numeric? c)
(char=? c #\-))
valid #f))
#t path)))
;;;
;;; Check storage exists
;;;
(define (storage-exists path)
(let ((dir-stat (stat path #f))
(file-stat (stat (format "~a/code.v" path) #f)))
(and dir-stat file-stat
(eq? (stat:type dir-stat) 'directory)
(eq? (stat:type file-stat) 'regular)
(not (zero? (logand #o444 (stat:perms file-stat))))
(not (zero? (logand #o222 (stat:perms file-stat)))))))
;;;
;;; Save code to storage
;;;
(define (save-to-storage path code)
(with-output-to-file (format "~a/code.v" path)
(cut display code)))
;;;
;;; Read from storage
;;;
(define (read-from-storage path)
(call-with-input-file (format "~a/code.v" path)
get-string-all))
;;;
;;; Web page handler
;;;
(define (make-page-handler host root index-file
max-code-size
vvp-exe iverilog-exe)
(let* ((root-path (split-and-decode-uri-path root))
(root (encode-and-join-uri-path root-path))
(iverilog-path (append root-path '("iverilog")))
(savecode-path (append root-path '("save")))
(iverilog-post-uri (string-append host "/" (encode-and-join-uri-path iverilog-path)))
(savecode-post-uri (string-append host "/" (encode-and-join-uri-path savecode-path)))
(index-html (read-template-text index-file `(("IVERILOGPOSTURI" ,iverilog-post-uri)
("SAVECODEURI" ,savecode-post-uri)))))
(lambda (request request-body)
(let* ((path (split-and-decode-uri-path
(uri-path
(request-uri request))))
(ref (assoc 'referer (request-headers request)))
(ref-stor (if ref (get-storage-path (cdr ref) root) ""))
(ref-stor (if (and (valid-storage-path ref-stor)
(storage-exists ref-stor))
ref-stor #f))
(code (if request-body (utf8->string request-body) ""))
(code (if (or (zero? max-code-size)
(<= (string-length code) max-code-size))
code
(substring code 0 max-code-size))))
(printlog "-- path: ~a" path)
(printlog "-- ref-stor: ~a" ref-stor)
(printlog "-- length: ~a/~a"
(request-content-length request)
(string-length code))
(cond
;; Iverilog
((equal? path iverilog-path)
(printlog "-- Request simulate")
(when ref-stor
(save-to-storage ref-stor code))
(make-response
(exec-sim 'iverilog
(sanitize-verilog code)
#:vvp-exe vvp-exe
#:iverilog-exe iverilog-exe)
#:type 'text/plain))
;; Save code
((equal? path savecode-path)
(printlog "-- Request save code")
(let ((storage (or ref-stor
(mkdtemp (format "~a-XXXXXX" (current-time))))))
(save-to-storage storage code)
(make-response
(encode-and-join-uri-path
(append root-path `(,storage))))))
;; Index page
((equal? path root-path)
(printlog "-- Request index page")
(make-response
(substitute index-html "@~a@" `((CODE ,DEFAULT-CODE)))))
;; Storage
((and (> (length path)
(length root-path))
(every equal? path root-path))
(let ((storage (if (null? path) "" (last path))))
(printlog "-- Request code from storage ~a" storage)
(if (and (valid-storage-path storage)
(storage-exists storage))
(let ((code (read-from-storage storage)))
(make-response
(substitute index-html "@~a@" `((CODE ,code)))))
(make-response
(substitute index-html "@~a@" `((CODE ,DEFAULT-CODE)))))))
;; Wrong request
(else
(printlog "-- Request wrong path")
(not-found request)))))))
;;;
;;; ----------------------------------------------------------------------
;;; ------------------------------- MAIN ---------------------------------
;;; ----------------------------------------------------------------------
;;;
(define (print-help app-name)
(define (-> . args)
(display (apply format args) (current-error-port))
(newline (current-error-port)))
(let ((app-name (basename app-name)))
(with-output-to-port (current-error-port)
(lambda ()
(-> "Usage: ~a [OPTION]..." app-name)
(-> "Start Verilog playground WEB server")
(-> "")
(-> "Options:")
(-> " -a, --addr ADDR Listen on ADDR address. Default: 127.0.0.1")
(-> " -p, --port PORT Listen on PORT port. Default: 8080")
(-> " -s, --host URL Run on URL hostname. Default: http://127.0.0.1:8080")
(-> " -r, --root URN Service location root. Default: ''")
(-> " --ivverilog-exe PATH Set Icarus Verilog compiler executable. Default: iverilog")
(-> " --vvp-exe PATH Set Icarus Verilog interpreter executable. Default: vvp")
(-> " --max-len LEN Set maximum code size in symbols. Default: 0 (infinite)")
(-> " -h, --help Print this message and exit")
(-> "")
(-> "Source code and issue tracker: <https://github.com/punzik/>")))))
(define (main args)
(debug-disable 'backtrace)
(let-values
(((opts rest err)
(parse-opts (cdr args)
'(("addr" #\a) required)
'(("port" #\p) required)
'(("host" #\s) required)
'(("root" #\r) required)
'(("vvp-exe") required)
'(("iverilog-exe") required)
'(("max-len") required)
'(("help" #\h) none))))
(let ((addr (string-trim (or (option-get opts "addr") "127.0.0.1")))
(port (string->number (string-trim (or (option-get opts "port") "8080"))))
(host (string-trim (or (option-get opts "host") "http://127.0.0.1:8080")))
(root (string-trim (or (option-get opts "root") "")))
(vvp (string-trim (or (option-get opts "vvp-exe") "vvp")))
(iverilog (string-trim (or (option-get opts "iverilog-exe") "iverilog")))
(max-code-size (string->number (string-trim (or (option-get opts "max-len") "0")))))
(cond
(err
(display (format "Unknown option '~a'\n" err))
(print-help (car args))
(exit -1))
((option-get opts "help")
(print-help (car args))
(exit -1))
(else
(printlog "Listen on '~a' port '~a'" addr port)
(printlog "Server URL: '~a/~a'" host root)
(printlog "Max code size: ~a" max-code-size)
(run-server
(make-page-handler host root INDEX-FILE max-code-size vvp iverilog)
'http `(#:host ,addr #:port ,port)))))))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,197 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Verilog Playground</title>
<style type="text/css" media="screen">
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-variant-ligatures: none;
}
body {
padding: 3px;
font-family: 'JetBrains Mono', monospace;
font-size: 10pt;
}
pre {
font-family: 'JetBrains Mono', monospace;
font-size: 10pt;
}
#buttons {
color: white;
background-color: #2d3d40;
width: 100%;
padding: 3px;
font-size: inherit;
}
#logdiv, #editor, #buttons {
border-width: 1px;
border-style: solid;
border-color: #505050;
}
button {
color: black;
background-color: #dbdbdb;
margin-left: 1px;
margin-right: 1px;
margin-top: 2px;
margin-bottom: 2px;
height: 25px;
}
button span.text { padding: 4px; }
#editor {
height: 75vh;
width: 100%;
}
#logdiv {
height: 100%;
width: 100%;
}
#logdiv {
position: relative;
overflow: scroll;
}
svg {
fill: none;
stroke: white;
stroke-width: 0;
shape-rendering: crispEdges;
}
svg text {
font-family: 'JetBrains Mono', monospace;
font-size: 10pt;
fill: white;
}
svg #wave-signals {
stroke: #00fcff;
stroke-width: 1;
}
svg #wave-clock {
stroke: #fffe9a;
font-size: 8pt;
stroke-width: 1;
}
svg #wave-signals text { font-size: 8pt; }
svg #wave-clock text { font-size: 8pt; }
svg #wave-delim {
stroke: #d0d0d0;
stroke-width: 2;
}
svg #wave-background { fill: #1e2426; }
@media (orientation: landscape) and (not (pointer: coarse)) {
body {
display: flex;
flex-flow: column;
height: 100vh;
}
#text { flex-grow: 1; }
#editor {
float: left;
width: 50%;
height: 100%;
}
#logdiv {
float: left;
width: 50%;
height: 100%;
}
#logdiv pre {
position: absolute;
height: 100%;
}
}
</style>
</head>
<body>
<div id="buttons">
<button onclick="show_help()"><span class="text">?</span></button>
<button onclick="save_code('%SAVECODEURI%')"><span class="text">Save</span></button>
Sim:
<button onclick="send_to_sim('%IVERILOGPOSTURI%')"><span class="text">Icarus</span></button>
<button onclick="send_to_sim('%VERILATORPOSTURI%')"><span class="text">Verilator</span></button>
</div>
<div id="text">
<div id="editor">@CODE@</div>
<div id="logdiv"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var editor = ace.edit('editor');
editor.setTheme('ace/theme/chrome');
editor.session.setMode('ace/mode/verilog');
editor.setOptions({
tabSize : 2,
fontSize : 14,
fontFamily : 'JetBrains Mono, monospace',
enableBasicAutocompletion : true,
enableLiveAutocompletion : true
});
const log_area = document.getElementById('logdiv');
function send_to_sim(uri) {
query = uri + "?width=" + log_area.clientWidth;
log_area.innerHTML = "Please wait...";
fetch(query,
{
method: 'POST',
headers: {
'Accept': 'text/plain',
'Content-Type': 'text/plain'
},
body: editor.getValue()
})
.then((response) => response.text())
.then((text) => { log_area.innerHTML = text; });
};
function save_code(uri) {
fetch(uri,
{
method: 'POST',
headers: {
'Accept': 'text/plain',
'Content-Type': 'text/plain'
},
body: editor.getValue()
})
.then((response) => response.text())
.then((text) => { window.location.href = text; });
};
function show_help() {
alert("%HELPSTRING%");
};
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

12
_web_server/server/restrict Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
if [ -z "$DONOTUSEFIREJAIL" ]; then
exec firejail \
--quiet --noprofile \
--rlimit-cpu=5 \
--rlimit-as=250m \
--rlimit-fsize=250k \
"$@"
else
exec timeout -v -s KILL 5 "$@"
fi

View File

@@ -0,0 +1,11 @@
`timescale 1ps/1ps
module __@TOPMODULE@__;
@TOPMODULE@ @TOPMODULE@ ();
initial begin
$dumpfile("@WORKDIR@/@TOPMODULE@.vcd");
$dumpvars(1, @TOPMODULE@);
$dumplimit(100000);
end
endmodule

View File

@@ -0,0 +1,43 @@
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "V@TOPMODULE@.h"
#define DUMPFILE "@WORKDIR@/@TOPMODULE@.vcd"
int main(int argc, char** argv, char**) {
// Setup context, defaults, and parse command line
Verilated::debug(0);
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
contextp->traceEverOn(true);
contextp->commandArgs(argc, argv);
// Construct the Verilated model, from Vtop.h generated from Verilating
const std::unique_ptr<V@TOPMODULE@> topp{new V@TOPMODULE@{contextp.get()}};
VerilatedVcdC *vcd = new VerilatedVcdC;
topp->trace(vcd, 99);
vcd->open(DUMPFILE);
// Simulate until $finish
while (!contextp->gotFinish()) {
// Evaluate model
topp->eval();
vcd->dump(contextp->time());
// Advance time
if (!topp->eventsPending()) break;
contextp->time(topp->nextTimeSlot());
}
if (!contextp->gotFinish()) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););
}
// Execute 'final' processes
topp->final();
// Print statistical summary report
contextp->statsPrintSummary();
vcd->close();
return 0;
}

View File

@@ -1 +0,0 @@
./firejailed.sh