Update v1.0.6
This commit is contained in:
132
public/filemanager/scripts/CodeMirror/mode/verilog/index.html
vendored
Normal file
132
public/filemanager/scripts/CodeMirror/mode/verilog/index.html
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Verilog mode</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="verilog.js"></script>
|
||||
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
<li><a href="../../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="../index.html">Language modes</a>
|
||||
<li><a class=active href="#">Verilog</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Verilog mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
/* Verilog demo code */
|
||||
|
||||
module butterfly
|
||||
#(
|
||||
parameter WIDTH = 32,
|
||||
parameter MWIDTH = 1
|
||||
)
|
||||
(
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
// m_in contains data that passes through this block with no change.
|
||||
input wire [MWIDTH-1:0] m_in,
|
||||
// The twiddle factor.
|
||||
input wire signed [WIDTH-1:0] w,
|
||||
// XA
|
||||
input wire signed [WIDTH-1:0] xa,
|
||||
// XB
|
||||
input wire signed [WIDTH-1:0] xb,
|
||||
// Set to 1 when new data is present on inputs.
|
||||
input wire x_nd,
|
||||
// delayed version of m_in.
|
||||
output reg [MWIDTH-1:0] m_out,
|
||||
// YA = XA + W*XB
|
||||
// YB = XA - W*XB
|
||||
output wire signed [WIDTH-1:0] ya,
|
||||
output wire signed [WIDTH-1:0] yb,
|
||||
output reg y_nd,
|
||||
output reg error
|
||||
);
|
||||
|
||||
// Set wire to the real and imag parts for convenience.
|
||||
wire signed [WIDTH/2-1:0] xa_re;
|
||||
wire signed [WIDTH/2-1:0] xa_im;
|
||||
assign xa_re = xa[WIDTH-1:WIDTH/2];
|
||||
assign xa_im = xa[WIDTH/2-1:0];
|
||||
wire signed [WIDTH/2-1: 0] ya_re;
|
||||
wire signed [WIDTH/2-1: 0] ya_im;
|
||||
assign ya = {ya_re, ya_im};
|
||||
wire signed [WIDTH/2-1: 0] yb_re;
|
||||
wire signed [WIDTH/2-1: 0] yb_im;
|
||||
assign yb = {yb_re, yb_im};
|
||||
|
||||
// Delayed stuff.
|
||||
reg signed [WIDTH/2-1:0] xa_re_z;
|
||||
reg signed [WIDTH/2-1:0] xa_im_z;
|
||||
// Output of multiplier
|
||||
wire signed [WIDTH-1:0] xbw;
|
||||
wire signed [WIDTH/2-1:0] xbw_re;
|
||||
wire signed [WIDTH/2-1:0] xbw_im;
|
||||
assign xbw_re = xbw[WIDTH-1:WIDTH/2];
|
||||
assign xbw_im = xbw[WIDTH/2-1:0];
|
||||
// Do summing
|
||||
// I don't think we should get overflow here because of the
|
||||
// size of the twiddle factors.
|
||||
// If we do testing should catch it.
|
||||
assign ya_re = xa_re_z + xbw_re;
|
||||
assign ya_im = xa_im_z + xbw_im;
|
||||
assign yb_re = xa_re_z - xbw_re;
|
||||
assign yb_im = xa_im_z - xbw_im;
|
||||
|
||||
// Create the multiply module.
|
||||
multiply_complex #(WIDTH) multiply_complex_0
|
||||
(.clk(clk),
|
||||
.rst_n(rst_n),
|
||||
.x(xb),
|
||||
.y(w),
|
||||
.z(xbw)
|
||||
);
|
||||
|
||||
always @ (posedge clk)
|
||||
begin
|
||||
if (!rst_n)
|
||||
begin
|
||||
y_nd <= 1'b0;
|
||||
error <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Set delay for x_nd_old and m.
|
||||
y_nd <= x_nd;
|
||||
m_out <= m_in;
|
||||
if (x_nd)
|
||||
begin
|
||||
xa_re_z <= xa_re/2;
|
||||
xa_im_z <= xa_im/2;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
mode: "text/x-verilog"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple mode that tries to handle Verilog-like languages as well as it
|
||||
can. Takes one configuration parameters: <code>keywords</code>, an
|
||||
object whose property names are the keywords in the language.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-verilog</code> (Verilog code).</p>
|
||||
</article>
|
192
public/filemanager/scripts/CodeMirror/mode/verilog/verilog.js
vendored
Normal file
192
public/filemanager/scripts/CodeMirror/mode/verilog/verilog.js
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("verilog", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit,
|
||||
keywords = parserConfig.keywords || {},
|
||||
blockKeywords = parserConfig.blockKeywords || {},
|
||||
atoms = parserConfig.atoms || {},
|
||||
hooks = parserConfig.hooks || {},
|
||||
multiLineStrings = parserConfig.multiLineStrings;
|
||||
var isOperatorChar = /[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;
|
||||
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (hooks[ch]) {
|
||||
var result = hooks[ch](stream, state);
|
||||
if (result !== false) return result;
|
||||
}
|
||||
if (ch == '"') {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
}
|
||||
if (/[\d']/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.']/);
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var cur = stream.current();
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "keyword";
|
||||
}
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "variable";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = tokenBase;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
var verilogKeywords = "always and assign automatic begin buf bufif0 bufif1 case casex casez cell cmos config " +
|
||||
"deassign default defparam design disable edge else end endcase endconfig endfunction endgenerate endmodule " +
|
||||
"endprimitive endspecify endtable endtask event for force forever fork function generate genvar highz0 " +
|
||||
"highz1 if ifnone incdir include initial inout input instance integer join large liblist library localparam " +
|
||||
"macromodule medium module nand negedge nmos nor noshowcancelled not notif0 notif1 or output parameter pmos " +
|
||||
"posedge primitive pull0 pull1 pulldown pullup pulsestyle_onevent pulsestyle_ondetect rcmos real realtime " +
|
||||
"reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared showcancelled signed small specify specparam " +
|
||||
"strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg " +
|
||||
"unsigned use vectored wait wand weak0 weak1 while wire wor xnor xor";
|
||||
|
||||
var verilogBlockKeywords = "begin bufif0 bufif1 case casex casez config else end endcase endconfig endfunction " +
|
||||
"endgenerate endmodule endprimitive endspecify endtable endtask for forever function generate if ifnone " +
|
||||
"macromodule module primitive repeat specify table task while";
|
||||
|
||||
function metaHook(stream) {
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
return "meta";
|
||||
}
|
||||
|
||||
CodeMirror.defineMIME("text/x-verilog", {
|
||||
name: "verilog",
|
||||
keywords: words(verilogKeywords),
|
||||
blockKeywords: words(verilogBlockKeywords),
|
||||
atoms: words("null"),
|
||||
hooks: {"`": metaHook, "$": metaHook}
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user