Class: VerilogTools::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/verilog_parser.rb

Overview

The class of the parser.

Constant Summary collapse

FS_TIME =

The table of time conversion.

{
  "s"  => 1_000_000_000_000_000,
  "ms" => 1_000_000_000_000,
  "us" => 1_000_000_000,
  "ns" => 1_000_000,
  "ps" => 1_000,
  "fs" => 1
}
COMMA_TOK =

Definition of the tokens

","
SEMICOLON_TOK =
";"
COLON_TOK =
":"
OPEN_PAR_TOK =
"("
CLOSE_PAR_TOK =
")"
OPEN_BRA_TOK =
"["
CLOSE_BRA_TOK =
"]"
OPEN_CUR_TOK =
"{"
CLOSE_CUR_TOK =
"}"
SHARP_TOK =
"#"
AT_TOK =
"@"
DOT_TOK =
"."
EE_TOK =
"E"
Ee_TOK =
"e"
SLASH_TOK =
"/"
SLASH_SLASH_TOK =
"//"
SLASH_ASTERISK_TOK =
"/*"
ASTERISK_SLASH_TOK =
"*/"
EOL_TOK =
"\n"
MODULE_TOK =
"module"
MACROMODULE_TOK =
"macromodule"
ENDMODULE_TOK =
"endmodule"
PRIMITIVE_TOK =
"primitive"
ENDPRIMITIVE_TOK =
"endprimitive"
TASK_TOK =
"task"
ENDTASK_TOK =
"endtask"
FUNCTION_TOK =
"function"
ENDFUNCTION_TOK =
"endfunction"
TABLE_TOK =
"table"
ENDTABLE_TOK =
"endtable"
SPECIFY_TOK =
"specify"
ENDSPECIFY_TOK =
"endspecify"
INPUT_TOK =
"input"
OUTPUT_TOK =
"output"
INOUT_TOK =
"inout"
INITIAL_TOK =
"initial"
SPECPARAM_TOK =
"specparam"
IF_TOK =
"if"
ELSE_TOK =
"else"
CASE_TOK =
"case"
CASEZ_TOK =
"casez"
CASEX_TOK =
"casex"
ENDCASE_TOK =
"endcase"
FOREVER_TOK =
"forever"
REPEAT_TOK =
"repeat"
WHILE_TOK =
"while"
FOR_TOK =
"for"
WAIT_TOK =
"wait"
RIGHT_ARROW_TOK =
"->"
DISABLE_TOK =
"disable"
ASSIGN_TOK =
"assign"
DEASSIGN_TOK =
"deassign"
FORCE_TOK =
"force"
RELEASE_TOK =
"release"
ALWAYS_TOK =
"always"
DEFAULT_TOK =
"default"
BEGIN_TOK =
"begin"
END_TOK =
"end"
FORK_TOK =
"fork"
JOIN_TOK =
"join"
SIGNED_TOK =
"signed"
REG_TOK =
"reg"
TIME_TOK =
"time"
INTEGER_TOK =
"integer"
REAL_TOK =
"real"
EVENT_TOK =
"event"
DEFPARAM_TOK =
"defparam"
PARAMETER_TOK =
"parameter"
LOCALPARAM_TOK =
"localparam"
SCALARED_TOK =
"scalared"
VECTORED_TOK =
"vectored"
SETUP_TOK =
"$setup"
HOLD_TOK =
"$hold"
PERIOD_TOK =
"$period"
WIDTH_TOK =
"$width"
SKEW_TOK =
"$skew"
RECOVERY_TOK =
"$recovery"
SETUPHOLD_TOK =
"$setuphold"
HYPHEN_TOK =
"-"
ZERO_TOK =
"0"
ONE_TOK =
"1"
Xx_TOK =
"x"
XX_TOK =
"X"
Bb_TOK =
"b"
BB_TOK =
"B"
QUESTION_TOK =
"?"
Rr_TOK =
"r"
RR_TOK =
"R"
Ff_TOK =
"f"
FF_TOK =
"F"
Pp_TOK =
"p"
PP_TOK =
"P"
Nn_TOK =
"n"
NN_TOK =
"N"
ASTERISK_TOK =
"*"
Q_b_TOK =
"'b"
Q_B_TOK =
"'B"
Q_o_TOK =
"'o"
Q_O_TOK =
"'O"
Q_d_TOK =
"'d"
Q_D_TOK =
"'D"
Q_h_TOK =
"'h"
Q_H_TOK =
"'H"
ONE_b_ZERO_TOK =
"1'b0"
ONE_b_ONE_TOK =
"1'b1"
ONE_b_x_TOK =
"1'bx"
ONE_b_X_TOK =
"1'bX"
ONE_B_ZERO_TOK =
"1'B0"
ONE_B_ONE_TOK =
"1'B1"
ONE_B_x_TOK =
"1'Bx"
ONE_B_X_TOK =
"1'BX"
Q_b_ZERO_TOK =
"'b0"
Q_b_ONE_TOK =
"'b1"
Q_B_ZERO_TOK =
"'B0"
Q_B_ONE_TOK =
"'B1"
WIRE_TOK =
"wire"
TRI_TOK =
"tri"
TRI1_TOK =
"tri1"
SUPPLY0_TOK =
"supply0"
WAND_TOK =
"wand"
TRIAND_TOK =
"triand"
TRI0_TOK =
"tri0"
SUPPLY1_TOK =
"supply1"
WOR_TOK =
"wor"
TRIOR_TOK =
"trior"
TRIREG_TOK =
"trireg"
SMALL_TOK =
"small"
MEDIUM_TOK =
"medium"
LARGE_TOK =
"large"
STRONG0_TOK =
"strong0"
PULL0_TOK =
"pull0"
WEAK0_TOK =
"weak0"
HIGHZ0_TOK =
"highz0"
STRONG1_TOK =
"strong1"
PULL1_TOK =
"pull1"
WEAK1_TOK =
"weak1"
HIGHZ1_TOK =
"highz1"
GATE_AND_TOK =
"and"
GATE_NAND_TOK =
"nand"
GATE_OR_TOK =
"or"
GATE_NOR_TOK =
"nor"
GATE_XOR_TOK =
"xor"
GATE_XNOR_TOK =
"xnor"
GATE_BUF_TOK =
"buf"
GATE_BUFIF0_TOK =
"bufif0"
GATE_BUFIF1_TOK =
"bufif1"
GATE_NOT_TOK =
"not"
GATE_NOTIF0_TOK =
"notif0"
GATE_NOTIF1_TOK =
"notif1"
GATE_PULLDOWN_TOK =
"pulldown"
GATE_PULLUP_TOK =
"pullup"
GATE_NMOS_TOK =
"nmos"
GATE_RNMOS_TOK =
"rnmos"
GATE_PMOS_TOK =
"pmos"
GATE_RPMOS_TOK =
"rpmos"
GATE_CMOS_TOK =
"cmos"
GATE_RCMOS_TOK =
"rcmos"
GATE_TRAN_TOK =
"tran"
GATE_RTRAN_TOK =
"rtran"
GATE_TRANIF0_TOK =
"tranif0"
GATE_RTRANIF0_TOK =
"rtranif0"
GATE_TRANIF1_TOK =
"tranif1"
GATE_RTRANIF1_TOK =
"rtranif1"
ZERO_ONE_TOK =
"01"
ONE_ZERO_TOK =
"10"
ZERO_X_TOK =
"0x"
X_ONE_TOK =
"x1"
ONE_X_TOK =
"1x"
X_ZERO_TOK =
"x0"
POSEDGE_TOK =
"posedge"
NEGEDGE_TOK =
"negedge"
EVENT_OR_TOK =
"or"
EQUAL_TOK =
"="
ASSIGN_ARROW_TEX =
"<="
EQUAL_EQUAL_TOK =
"=="
EQUAL_EQUAL_EQUAL_TOK =
"==="
NOT_EQUAL_TOK =
"!="
NOT_EQUAL_EQUAL_TOK =
"!=="
INFERIOR_TOK =
"<"
SUPERIOR_TOK =
">"
INFERIOR_EQUAL_TOK =
"<="
SUPERIOR_EQUAL_TOK =
">="
AND_AND_TOK =
"&&"
OR_OR_TOK =
"||"
NOT_TOK =
"!"
AND_AND_AND_TOK =
"&&&"
ADD_TOK =
"+"
SUB_TOK =
"-"
MUL_TOK =
"*"
DIV_TOK =
"/"
MOD_TOK =
"%"
POWER_TOK =
"**"
AND_TOK =
"&"
OR_TOK =
"|"
XOR_TOK =
"^"
XOR_TILDE_TOK =
"^~"
RIGHT_SHIFT_TOK =
">>"
LEFT_SHIFT_TOK =
"<<"
RIGHT_ASHIFT_TOK =
">>>"
LEFT_ASHIFT_TOK =
"<<<"
TILDE_TOK =
"~"
TILDE_AND_TOK =
"~&"
XOR_OR_TOK =
"^|"
TILDE_XOR_TOK =
"~^"
TILDE_OR_TOK =
"~|"
SHORT_COMMENT_REX =
/[^\n]*/
LONG_COMMENT_REX =
/([^\*]\/|\*[^\/]|[^\/\*])*/
COMMENT_SPACE_REX =

Comments and spaces with capture in one regular expression

/((?:(?:\/\/[^\n]*\n)|(?:\/\*(?:[^\*]\/|\*[^\/]|[^\/\*])*\*\/)|\s)*)/
S =

Shortcut for combining with other regex

COMMENT_SPACE_REX.source
COMMA_REX =
/\G#{S}(,)/
SEMICOLON_REX =
/\G#{S}(;)/
COLON_REX =
/\G#{S}(:)/
OPEN_PAR_REX =
/\G#{S}(\()/
CLOSE_PAR_REX =
/\G#{S}(\))/
OPEN_BRA_REX =
/\G#{S}(\[)/
CLOSE_BRA_REX =
/\G#{S}(\])/
OPEN_CUR_REX =
/\G#{S}(\{)/
CLOSE_CUR_REX =
/\G#{S}(\})/
SHARP_REX =
/\G#{S}(#)/
AT_REX =
/\G#{S}(@)/
DOT_REX =
/\G#{S}(\.)/
EE_REX =
/\G#{S}(E)/
Ee_REX =
/\G#{S}(e)/
SLASH_REX =
/\G#{S}(\/)/
SLASH_SLASH_REX =
/\G#{S}(\/\/)/
SLASH_ASTERISK_REX =
/\G#{S}(\/\*)/
ASTERISK_SLASH_REX =
/\G#{S}(\*\/)/
EOL_REX =
/\G#{S}(\n)/
MODULE_REX =
/\G#{S}(module)/
MACROMODULE_REX =
/\G#{S}(macromodule)/
ENDMODULE_REX =
/\G#{S}(endmodule)/
PRIMITIVE_REX =
/\G#{S}(primitive)/
ENDPRIMITIVE_REX =
/\G#{S}(endprimitive)/
TASK_REX =
/\G#{S}(task)/
ENDTASK_REX =
/\G#{S}(endtask)/
FUNCTION_REX =
/\G#{S}(function)/
ENDFUNCTION_REX =
/\G#{S}(endfunction)/
TABLE_REX =
/\G#{S}(table)/
ENDTABLE_REX =
/\G#{S}(endtable)/
SPECIFY_REX =
/\G#{S}(specify)/
ENDSPECIFY_REX =
/\G#{S}(endspecify)/
INPUT_REX =
/\G#{S}(input)/
OUTPUT_REX =
/\G#{S}(output)/
INOUT_REX =
/\G#{S}(inout)/
INITIAL_REX =
/\G#{S}(initial)/
SPECPARAM_REX =
/\G#{S}(specparam)/
IF_REX =
/\G#{S}(if)/
ELSE_REX =
/\G#{S}(else)/
CASE_REX =
/\G#{S}(case)/
CASEZ_REX =
/\G#{S}(casez)/
CASEX_REX =
/\G#{S}(casex)/
ENDCASE_REX =
/\G#{S}(endcase)/
FOREVER_REX =
/\G#{S}(forever)/
REPEAT_REX =
/\G#{S}(repeat)/
WHILE_REX =
/\G#{S}(while)/
FOR_REX =
/\G#{S}(for)/
WAIT_REX =
/\G#{S}(wait)/
RIGHT_ARROW_REX =
/\G#{S}(->)/
DISABLE_REX =
/\G#{S}(disable)/
ASSIGN_REX =
/\G#{S}(assign)/
DEASSIGN_REX =
/\G#{S}(deassign)/
FORCE_REX =
/\G#{S}(force)/
RELEASE_REX =
/\G#{S}(release)/
ALWAYS_REX =
/\G#{S}(always)/
DEFAULT_REX =
/\G#{S}(default)/
BEGIN_REX =
/\G#{S}(begin)/
END_REX =
/\G#{S}(end)/
FORK_REX =
/\G#{S}(fork)/
JOIN_REX =
/\G#{S}(join)/
SIGNED_REX =
/\G#{S}(signed)/
REG_REX =
/\G#{S}(reg)/
TIME_REX =
/\G#{S}(time)/
INTEGER_REX =
/\G#{S}(integer)/
REAL_REX =
/\G#{S}(real)/
EVENT_REX =
/\G#{S}(event)/
DEFPARAM_REX =
/\G#{S}(defparam)/
PARAMETER_REX =
/\G#{S}(parameter|localparam)/
SCALARED_REX =
/\G#{S}(scalared)/
VECTORED_REX =
/\G#{S}(vectored)/
SETUP_REX =
/\G#{S}($setup)/
HOLD_REX =
/\G#{S}($hold)/
PERIOD_REX =
/\G#{S}($period)/
WIDTH_REX =
/\G#{S}($width)/
SKEW_REX =
/\G#{S}($skew)/
RECOVERY_REX =
/\G#{S}($recovery)/
SETUPHOLD_REX =
/\G#{S}($setuphold)/
HYPHEN_REX =
/\G#{S}(-)/
ZERO_REX =
/\G#{S}(0)/
ONE_REX =
/\G#{S}(1)/
Xx_REX =
/\G#{S}(x)/
XX_REX =
/\G#{S}(X)/
Bb_REX =
/\G#{S}(b)/
BB_REX =
/\G#{S}(B)/
QUESTION_REX =
/\G#{S}(\?)/
Rr_REX =
/\G#{S}(r)/
RR_REX =
/\G#{S}(R)/
Ff_REX =
/\G#{S}(f)/
FF_REX =
/\G#{S}(F)/
Pp_REX =
/\G#{S}(p)/
PP_REX =
/\G#{S}(P)/
Nn_REX =
/\G#{S}(n)/
NN_REX =
/\G#{S}(N)/
ASTERISK_REX =
/\G#{S}(\*)/
Q_b_REX =
/\G#{S}('b)/
Q_B_REX =
/\G#{S}('B)/
Q_o_REX =
/\G#{S}('o)/
Q_O_REX =
/\G#{S}('O)/
Q_d_REX =
/\G#{S}('d)/
Q_D_REX =
/\G#{S}('D)/
Q_h_REX =
/\G#{S}('h)/
Q_H_REX =
/\G#{S}('H)/
ONE_b_ZERO_REX =
/\G#{S}(1'b0)/
ONE_b_ONE_REX =
/\G#{S}(1'b1)/
ONE_b_x_REX =
/\G#{S}(1'bx)/
ONE_b_X_REX =
/\G#{S}(1'bX)/
ONE_B_ZERO_REX =
/\G#{S}(1'B0)/
ONE_B_ONE_REX =
/\G#{S}(1'B1)/
ONE_B_x_REX =
/\G#{S}(1'Bx)/
ONE_B_X_REX =
/\G#{S}(1'BX)/
Q_b_ZERO_REX =
/\G#{S}('b0)/
Q_b_ONE_REX =
/\G#{S}('b1)/
Q_B_ZERO_REX =
/\G#{S}('B0)/
Q_B_ONE_REX =
/\G#{S}('B1)/
WIRE_REX =
/\G#{S}(wire)/
TRI_REX =
/\G#{S}(tri)/
TRI1_REX =
/\G#{S}(tri1)/
SUPPLY0_REX =
/\G#{S}(supply0)/
WAND_REX =
/\G#{S}(wand)/
TRIAND_REX =
/\G#{S}(triand)/
TRI0_REX =
/\G#{S}(tri0)/
SUPPLY1_REX =
/\G#{S}(supply1)/
WOR_REX =
/\G#{S}(wor)/
TRIOR_REX =
/\G#{S}(trior)/
TRIREG_REX =
/\G#{S}(trireg)/
SMALL_REX =
/\G#{S}(small)/
MEDIUM_REX =
/\G#{S}(medium)/
LARGE_REX =
/\G#{S}(large)/
STRONG0_REX =
/\G#{S}(strong0)/
PULL0_REX =
/\G#{S}(pull0)/
WEAK0_REX =
/\G#{S}(weak0)/
HIGHZ0_REX =
/\G#{S}(highz0)/
STRONG1_REX =
/\G#{S}(strong1)/
PULL1_REX =
/\G#{S}(pull1)/
WEAK1_REX =
/\G#{S}(weak1)/
HIGHZ1_REX =
/\G#{S}(highz1)/
GATE_AND_REX =
/\G#{S}(and)/
GATE_NAND_REX =
/\G#{S}(nand)/
GATE_OR_REX =
/\G#{S}(or)/
GATE_NOR_REX =
/\G#{S}(nor)/
GATE_XOR_REX =
/\G#{S}(xor)/
GATE_XNOR_REX =
/\G#{S}(xnor)/
GATE_BUF_REX =
/\G#{S}(buf)/
GATE_NBUF_REX =
/\G#{S}(nbuf)/
GATE_NOT_REX =
/\G#{S}(not)/
GATE_NOTIF0_REX =
/\G#{S}(notif0)/
GATE_NOTIF1_REX =
/\G#{S}(notif1)/
GATE_PULLDOWN_REX =
/\G#{S}(pulldown)/
GATE_PULLUP_REX =
/\G#{S}(pullup)/
GATE_NMOS_REX =
/\G#{S}(nmos)/
GATE_RNMOS_REX =
/\G#{S}(rnmos)/
GATE_PMOS_REX =
/\G#{S}(pmos)/
GATE_RPMOS_REX =
/\G#{S}(rpmos)/
GATE_CMOS_REX =
/\G#{S}(cmos)/
GATE_RCMOS_REX =
/\G#{S}(rcmos)/
GATE_TRAN_REX =
/\G#{S}(tran)/
GATE_RTRAN_REX =
/\G#{S}(rtran)/
GATE_TRANIF0_REX =
/\G#{S}(tranif0)/
GATE_RTRANIF0_REX =
/\G#{S}(rtranif0)/
GATE_TRANIF1_REX =
/\G#{S}(tranif1)/
GATE_RTRANIF1_REX =
/\G#{S}(rtranif1)/
ZERO_ONE_REX =
/\G#{S}(01)/
ONE_ZERO_REX =
/\G#{S}(10)/
ZERO_X_REX =
/\G#{S}(0x)/
X_ONE_REX =
/\G#{S}(x1)/
ONE_X_REX =
/\G#{S}(1x)/
X_ZERO_REX =
/\G#{S}(x0)/
POSEDGE_REX =
/\G#{S}(posedge)/
NEGEDGE_REX =
/\G#{S}(negedge)/
EVENT_OR_REX =
/\G#{S}(or)/
EQUAL_REX =
/\G#{S}(=)/
ASSIGN_ARROW_REX =
/\G#{S}(<=)/
EQUAL_EQUAL_REX =
/\G#{S}(==)/
EQUAL_EQUAL_EQUAL_REX =
/\G#{S}(===)/
NOT_EQUAL_REX =
/\G#{S}(!=)/
NOT_EQUAL_EQUAL_REX =
/\G#{S}(!==)/
INFERIOR_REX =
/\G#{S}(<)/
SUPERIOR_REX =
/\G#{S}(>)/
INFERIOR_EQUAL_REX =
/\G#{S}(<=)/
SUPERIOR_EQUAL_REX =
/\G#{S}(>=)/
AND_AND_REX =
/\G#{S}(&&)/
OR_OR_REX =
/\G#{S}(\|\|)/
NOT_REX =
/\G#{S}(!)/
AND_AND_AND_REX =
/\G#{S}(&&&)/
ADD_REX =
/\G#{S}(\+)/
SUB_REX =
/\G#{S}(-)/
MUL_REX =
/\G#{S}(\*)/
DIV_REX =
/\G#{S}(\/)/
MOD_REX =
/\G#{S}(%)/
POWER_REX =
/\G#{S}(\*\*)/
AND_REX =
/\G#{S}(&)/
OR_REX =
/\G#{S}(\|)/
XOR_REX =
/\G#{S}(\^)/
XOR_TILDE_REX =
/\G#{S}(\^~)/
TILDE_REX =
/\G#{S}(~)/
TILDE_AND_REX =
/\G#{S}(~&)/
XOR_OR_REX =
/\G#{S}(\^|)/
TILDE_XOR_REX =
/\G#{S}(~\^)/
TILDE_OR_REX =
/\G#{S}(~\|)/
IDENTIFIER_REX =
/\G#{S}([_a-zA-Z][_\$0-9a-zA-Z]*)/
SYSTEM_IDENTIFIER_REX =
/\G#{S}(\$[_a-zA-Z][_\$0-9a-zA-Z]*)/
STRING_REX =
/\G#{S}("[^"\n]*")/
MODULE_MACROMODULE_TOKS =

TIME_UNIT_TOKS = [ SECOND_TOK, MILLISECOND_TOK, MICROSECOND_TOK, NANOSECOND_TOK, PICOSECOND_TOK, FENTOSECOND_TOK ] TIME_UNIT_REX = /\G#S(#TIME_UNIT_TOKS.join("|"))/

[ MODULE_TOK, MACROMODULE_TOK ]
MODULE_MACROMODULE_REX =
/\G#{S}(#{MODULE_MACROMODULE_TOKS.join("|")})/
INIT_VAL_TOKS =
[ ONE_b_ZERO_TOK, ONE_b_ONE_TOK,
ONE_b_x_TOK, ONE_b_X_TOK,
ONE_B_ZERO_TOK, ONE_B_ONE_TOK, 
ONE_B_x_TOK, ONE_B_X_TOK,
ONE_TOK, ZERO_TOK ]
INIT_VAL_REX =
/\G#{S}(#{INIT_VAL_TOKS.join("|")})/
OUTPUT_SYMBOL_TOKS =
[ ZERO_TOK, ONE_TOK, Xx_TOK, XX_TOK ]
OUTPUT_SYMBOL_REX =
/\G#{S}(#{OUTPUT_SYMBOL_TOKS.join("|")})/
LEVEL_SYMBOL_TOKS =
[ ZERO_TOK, ONE_TOK, Xx_TOK, XX_TOK, 
"\\" + QUESTION_TOK, Bb_TOK, BB_TOK ]
LEVEL_SYMBOL_REX =
/\G#{S}(#{LEVEL_SYMBOL_TOKS.join("|")})/
EDGE_SYMBOL_TOKS =
[ Rr_TOK, RR_TOK, Ff_TOK, FF_TOK, 
Pp_TOK, PP_TOK, Nn_TOK, NN_TOK, 
"\\" + ASTERISK_TOK ]
EDGE_SYMBOL_REX =
/\G#{S}(#{EDGE_SYMBOL_TOKS.join("|")})/
INTEGER_REAL_TOKS =
[ INTEGER_TOK, REAL_TOK ]
INTEGER_REAL_REX =
/\G#{S}(#{INTEGER_REAL_TOKS.join("|")})/
NETTYPE_TOKS =
[ WIRE_TOK, TRI_TOK, TRI1_TOK, 
SUPPLY0_TOK, WAND_TOK, TRIAND_TOK, TRI0_TOK, 
SUPPLY1_TOK, WOR_TOK, TRIOR_TOK, TRIREG_TOK ]
NETTYPE_REX =
/\G#{S}(#{NETTYPE_TOKS.join("|")})/
INPUTTYPE_TOKS =
[ WIRE_TOK ]
INPUTTYPE_REX =
/\G#{S}(#{INPUTTYPE_TOKS.join("|")})/
OUTPUTTYPE_TOKS =

Note: the only difference between OUTPUTTYPE and NETTYPE is that the first one has reg, and the second trireg.

[ WIRE_TOK, TRI_TOK, TRI1_TOK, 
SUPPLY0_TOK, WAND_TOK, TRIAND_TOK, TRI0_TOK, 
SUPPLY1_TOK, WOR_TOK, TRIOR_TOK, REG_TOK ]
OUTPUTTYPE_REX =
/\G#{S}(#{OUTPUTTYPE_TOKS.join("|")})/
INOUTTYPE_TOKS =
[ WIRE_TOK ]
INOUTTYPE_REX =
/\G#{S}(#{INOUTTYPE_TOKS.join("|")})/
CHARGE_STRENGTH_TOKS =
[ SMALL_TOK, MEDIUM_TOK, LARGE_TOK ]
CHARGE_STRENGTH_REX =
/\G#{S}(#{CHARGE_STRENGTH_TOKS.join("|")})/
STRENGTH0_TOKS =
[ SUPPLY0_TOK, STRONG0_TOK, PULL0_TOK, 
WEAK0_TOK, HIGHZ0_TOK ]
STRENGTH0_REX =
/\G#{S}(#{STRENGTH0_TOKS.join("|")})/
STRENGTH1_TOKS =
[ SUPPLY1_TOK, STRONG1_TOK, PULL1_TOK, 
WEAK1_TOK, HIGHZ1_TOK ]
STRENGTH1_REX =
/\G#{S}(#{STRENGTH1_TOKS.join("|")})/
GATETYPE_TOKS =
[ GATE_AND_TOK, GATE_NAND_TOK, 
GATE_OR_TOK, GATE_NOR_TOK,
GATE_XOR_TOK, GATE_XNOR_TOK, 
GATE_BUF_TOK, GATE_BUFIF0_TOK, GATE_BUFIF1_TOK,
GATE_NOT_TOK, GATE_NOTIF0_TOK, GATE_NOTIF1_TOK,
GATE_PULLDOWN_TOK, GATE_PULLUP_TOK,
GATE_NMOS_TOK, GATE_RNMOS_TOK, 
GATE_PMOS_TOK, GATE_RPMOS_TOK,
GATE_CMOS_TOK, GATE_RCMOS_TOK,
GATE_TRAN_TOK, GATE_RTRAN_TOK, 
GATE_TRANIF0_TOK, GATE_RTRANIF0_TOK, 
GATE_TRANIF1_TOK, GATE_RTRANIF1_TOK ]
GATETYPE_REX =
/\G#{S}(#{GATETYPE_TOKS.join("|")})[^_a-zA-Z0-9]/
COMMA_CLOSE_PAR_TOKS =
[ COMMA_TOK, "\\" + CLOSE_PAR_TOK ]
COMMA_CLOSE_PAR_REX =
/\G#{S}(#{COMMA_CLOSE_PAR_TOKS.join("|")})/
CLOSE_BRA_COLON_TOKS =
[ "\\" + CLOSE_BRA_TOK, COLON_TOK ]
CLOSE_BRA_COLON_REX =
/\G#{S}(#{CLOSE_BRA_COLON_TOKS.join("|")})/
STATEMENT_TOKS =
[ IF_TOK, CASE_TOK, CASEZ_TOK, CASEX_TOK, 
FOREVER_TOK, REPEAT_TOK, WHILE_TOK, FOR_TOK,
WAIT_TOK, RIGHT_ARROW_TOK, DISABLE_TOK,
ASSIGN_TOK, FORCE_TOK, DEASSIGN_TOK, RELEASE_TOK ]
STATEMENT_REX =
/\G#{S}(#{STATEMENT_TOKS.join("|")})/
SYSTEM_TIMING_TOKS =
[ SETUP_TOK, HOLD_TOK, PERIOD_TOK, WIDTH_TOK,
SKEW_TOK, RECOVERY_TOK, SETUPHOLD_TOK ]
SYSTEM_TIMING_REX =
/\G#{S}(#{SYSTEM_TIMING_TOKS.join("|")})/
POSEDGE_NEGEDGE_TOKS =
[ POSEDGE_TOK, NEGEDGE_TOK ]
POSEDGE_NEGEDGE_REX =
/\G#{S}(#{POSEDGE_NEGEDGE_TOKS.join("|")})/
EDGE_DESCRIPTOR_TOKS =
[ ZERO_ONE_TOK, ONE_ZERO_TOK,
ZERO_X_TOK,   X_ONE_TOK,
ONE_X_TOK,    X_ZERO_TOK ]
EDGE_DESCRIPTOR_REX =
/\G#{S}(#{EDGE_DESCRIPTOR_TOKS.join("|")})/
SCALAR_TIMING_CHECK_CONDITION_TOKS =
[ EQUAL_EQUAL_TOK,
EQUAL_EQUAL_EQUAL_TOK,
NOT_EQUAL_TOK,
NOT_EQUAL_EQUAL_TOK ]
SCALAR_TIMING_REX =
/\G#{S}(#{SCALAR_TIMING_CHECK_CONDITION_TOKS.join("|")})/
SCALAR_CONSTANT_TOKS =
[ ONE_b_ZERO_TOK, ONE_b_ONE_TOK,
ONE_B_ZERO_TOK, ONE_B_ONE_TOK,
Q_b_ZERO_TOK,   Q_b_ONE_TOK,
Q_B_ZERO_TOK,   Q_B_ONE_TOK,
ONE_TOK,        ZERO_TOK ]
SCALAR_CONSTANT_REX =
/\G#{S}(#{SCALAR_CONSTANT_TOKS.join("|")})/
POLARITY_OPERATOR_TOKS =
[ "\\" + ADD_TOK, SUB_TOK ]
POLARITY_OPERATOR_REX =
/\G#{S}(#{POLARITY_OPERATOR_TOKS.join("|")})/
EDGE_IDENTIFIER_TOKS =
[ POSEDGE_TOK, NEGEDGE_TOK ]
EDGE_IDENTIFIER_REX =
/\G#{S}(#{EDGE_IDENTIFIER_TOKS.join("|")})/
OR_OPERATOR_TOKS =
[ "\\" + OR_TOK, TILDE_TOK + "\\" + OR_TOK ]
OR_OPERATOR_REX =
/\G#{S}(#{OR_OPERATOR_TOKS.join("|")})[^\|]/
XOR_OPERATOR_TOKS =
[ "\\" + XOR_TOK, TILDE_TOK + "\\" + XOR_TOK ]
XOR_OPERATOR_REX =
/\G#{S}(#{XOR_OPERATOR_TOKS.join("|")})/
AND_OPERATOR_TOKS =
[ AND_TOK, TILDE_AND_TOK ]
AND_OPERATOR_REX =
/\G#{S}(#{AND_OPERATOR_TOKS.join("|")})[^&]/
EQUAL_OPERATOR_TOKS =

BEFORE_AND_OPERATOR_TOKS = [

[ EQUAL_EQUAL_TOK, NOT_EQUAL_TOK,
EQUAL_EQUAL_EQUAL_TOK, NOT_EQUAL_EQUAL_TOK ]
EQUAL_OPERATOR_REX =
/\G#{S}(#{EQUAL_OPERATOR_TOKS.join("|")})/
COMPARISON_OPERATOR_TOKS =
[ INFERIOR_EQUAL_TOK, SUPERIOR_EQUAL_TOK,
INFERIOR_TOK, SUPERIOR_TOK ]
COMPARISON_OPERATOR_REX =
/\G#{S}(#{COMPARISON_OPERATOR_TOKS.join("|")})/
SHIFT_OPERATOR_TOKS =
[ LEFT_SHIFT_TOK,  RIGHT_SHIFT_TOK, 
LEFT_ASHIFT_TOK, RIGHT_ASHIFT_TOK ]
SHIFT_OPERATOR_REX =
/\G#{S}(#{SHIFT_OPERATOR_TOKS.join("|")})/
ADD_OPERATOR_TOKS =
[ "\\" + ADD_TOK, SUB_TOK ]
ADD_OPERATOR_REX =
/\G#{S}(#{ADD_OPERATOR_TOKS.join("|")})/
MUL_OPERATOR_TOKS =
[ "\\" + MUL_TOK, DIV_TOK, MOD_TOK, 
"\\" + MUL_TOK + "\\" + MUL_TOK ]
MUL_OPERATOR_REX =
/\G#{S}(#{MUL_OPERATOR_TOKS.join("|")})/
UNARY_OPERATOR_TOKS =
[ "\\" + ADD_TOK, SUB_TOK, NOT_TOK, TILDE_TOK,
AND_TOK, TILDE_AND_TOK, 
"\\" + OR_TOK, TILDE_TOK + "\\" + OR_TOK, 
"\\" + XOR_TOK  + "\\" + OR_TOK,
"\\" + XOR_TOK, TILDE_TOK + "\\" + XOR_TOK ]
UNARY_OPERATOR_REX =
/\G#{S}(#{UNARY_OPERATOR_TOKS.join("|")})/
BINARY_OPERATOR_TOKS =
[ "\\" + ADD_TOK, SUB_TOK, "\\" + MUL_TOK, 
"\\" + DIV_TOK, MOD_TOK,
EQUAL_EQUAL_TOK, NOT_EQUAL_TOK,
EQUAL_EQUAL_EQUAL_TOK, NOT_EQUAL_EQUAL_TOK,
AND_AND_TOK, "\\" + OR_TOK + "\\" + OR_TOK,
INFERIOR_TOK, INFERIOR_EQUAL_TOK,
SUPERIOR_TOK, SUPERIOR_EQUAL_TOK,
AND_TOK, "\\" + OR_TOK, "\\" + XOR_TOK, 
"\\" + XOR_TILDE_TOK,
RIGHT_SHIFT_TOK, LEFT_SHIFT_TOK ]
BINARY_OPERATOR_REX =
/\G#{S}(#{BINARY_OPERATOR_TOKS.join("|")})/
EVENT_OR_COMMA_TOKS =
[ EVENT_OR_TOK, COMMA_TOK ]
EVENT_OR_COMMA_REX =
/\G#{S}(#{EVENT_OR_COMMA_TOKS.join("|")})/
E_TOKS =
[ EE_TOK, Ee_TOK ]
E_REX =
/\G#{S}(#{E_TOKS.join("|")})/
DECIMAL_NUMBER_REX =
/\G#{S}([+-]?[0-9][_0-9]*)/
UNSIGNED_NUMBER_REX =
/\G#{S}([_0-9][0-9]*)/
NUMBER_REX =
/\G#{S}([0-9a-fA-FzZxX\?][_0-9a-fA-FzZxX\?]*)/
BASE_TOKS =
[ Q_b_TOK, Q_B_TOK, Q_o_TOK, Q_O_TOK,
Q_d_TOK, Q_D_TOK, Q_h_TOK, Q_H_TOK ]
BASE_REX =
/\G#{S}(#{BASE_TOKS.join("|")})/
KEYWORD_SET =

The set of keywords.

RULES =

The parsing rules: obtained directly from the BNF description of Verilog Each rule is paired with a hook (that returns an AST node by default) that can be redefined.

{}
ORIGIN_RULES =

The origin rules (from https://www.verilog.com/VerilogBNF.html) that differs from the ones used in this parser.

{}

Instance Method Summary collapse

Constructor Details

#initializeParser

Create a new parser.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/HDLRuby/verilog_parser.rb', line 128

def initialize
  # Create the parse state.
  # It includes:
  # +compress+: is the compressed version of the AST to generate.
  # +text+: the text to parse
  # +filename+: the origin file name (if any)
  # +lprop+: the properties of each line.
  @state = Struct.new(:compress, 
                      :text, :filename, :path,
                      :lprop,
                      :index, :lpos, :cpos).new(false,"","",[],0,0)
  # Create the list of known module names.
  @module_names = []
  # Create the list of known UDP names.
  @udp_names = []
end

Instance Method Details

#_BASE_hook(tok) ⇒ Object



6722
6723
6724
# File 'lib/HDLRuby/verilog_parser.rb', line 6722

def _BASE_hook(tok)
  return AST[:BASE, tok, self.property_hook]
end

#_BASE_parseObject



6714
6715
6716
6717
6718
6719
6720
# File 'lib/HDLRuby/verilog_parser.rb', line 6714

def _BASE_parse
  tok = self.get_token(BASE_REX)
  if tok then
    return _BASE_hook(tok)
  end
  return nil
end

#_BINARY_OPERATOR_hook(tok) ⇒ Object



6440
6441
6442
# File 'lib/HDLRuby/verilog_parser.rb', line 6440

def _BINARY_OPERATOR_hook(tok)
  return AST[:BINARY_OPERATOR, tok, self.property_hook ]
end

#_BINARY_OPERATOR_parseObject



6432
6433
6434
6435
6436
6437
6438
# File 'lib/HDLRuby/verilog_parser.rb', line 6432

def _BINARY_OPERATOR_parse
  tok = self.get_token(BINARY_OPERATOR_REX)
  if tok then
    return self._BINARY_OPERATOR_hook(tok)
  end
  return nil
end

#_DECIMAL_NUMBER_hook(tok) ⇒ Object



6626
6627
6628
# File 'lib/HDLRuby/verilog_parser.rb', line 6626

def _DECIMAL_NUMBER_hook(tok)
  return AST[:DECIMAL_NUMBER, tok, self.property_hook ]
end

#_DECIMAL_NUMBER_parseObject



6618
6619
6620
6621
6622
6623
6624
# File 'lib/HDLRuby/verilog_parser.rb', line 6618

def _DECIMAL_NUMBER_parse
  tok = self.get_token(DECIMAL_NUMBER_REX)
  if tok then
    return self._DECIMAL_NUMBER_hook(tok)
  end
  return nil
end

#_EDGE_SYMBOL_hook(symbol) ⇒ Object



2352
2353
2354
# File 'lib/HDLRuby/verilog_parser.rb', line 2352

def _EDGE_SYMBOL_hook(symbol)
  return AST[:EDGE_SYMBOL, symbol, self.property_hook ]
end

#_EDGE_SYMBOL_parseObject



2346
2347
2348
2349
2350
# File 'lib/HDLRuby/verilog_parser.rb', line 2346

def _EDGE_SYMBOL_parse
  symbol = self.get_token(EDGE_SYMBOL_REX)
  return nil unless symbol
  return self._EDGE_SYMBOL_hook(symbol)
end

#_GATETYPE_hook(type) ⇒ Object



3363
3364
3365
# File 'lib/HDLRuby/verilog_parser.rb', line 3363

def _GATETYPE_hook(type)
  return AST[:GATETYPE, type, self.property_hook ]
end

#_GATETYPE_parseObject



3355
3356
3357
3358
3359
3360
3361
# File 'lib/HDLRuby/verilog_parser.rb', line 3355

def _GATETYPE_parse
  type = self.get_token(GATETYPE_REX)
  unless type
    return nil
  end
  return _GATETYPE_hook(type)
end

#_IDENTIFIER_hook(tok) ⇒ Object



7067
7068
7069
# File 'lib/HDLRuby/verilog_parser.rb', line 7067

def _IDENTIFIER_hook(tok)
  return AST[:_IDENTIFIER, tok, self.property_hook ]
end

#_IDENTIFIER_parseObject



7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
# File 'lib/HDLRuby/verilog_parser.rb', line 7054

def _IDENTIFIER_parse
  parse_state = self.state
  tok = self.get_token(IDENTIFIER_REX)
  # puts "tok=#{tok}"
  return nil unless tok
  if KEYWORD_SET.include?(tok) then
    # An identifier cannot be a keyword!
    self.state = parse_state
    return nil
  end
  return self._IDENTIFIER_hook(tok)
end

#_LEVEL_SYMBOL_hook(symbol) ⇒ Object



2336
2337
2338
# File 'lib/HDLRuby/verilog_parser.rb', line 2336

def _LEVEL_SYMBOL_hook(symbol)
  return AST[:LEVEL_SYMBOL, symbol, self.property_hook ]
end

#_LEVEL_SYMBOL_parseObject



2330
2331
2332
2333
2334
# File 'lib/HDLRuby/verilog_parser.rb', line 2330

def _LEVEL_SYMBOL_parse
  symbol = self.get_token(LEVEL_SYMBOL_REX)
  return nil unless symbol
  return self._LEVEL_SYMBOL_hook(symbol)
end

#_NETTYPE_hook(type) ⇒ Object



2794
2795
2796
# File 'lib/HDLRuby/verilog_parser.rb', line 2794

def _NETTYPE_hook(type)
  return AST[:NETTYPE, type, self.property_hook ]
end

#_NETTYPE_parseObject



2787
2788
2789
2790
2791
2792
# File 'lib/HDLRuby/verilog_parser.rb', line 2787

def _NETTYPE_parse
  type = self.get_token(NETTYPE_REX)
  return nil unless type
  # self.parse_error("one of [#{NETTYPE_TOKS.join(",")}] expected") unless type
  return self._NETTYPE_hook(type)
end

#_NULL_hookObject

Auth: No parse of NULL, since it is literally nothing.



3804
3805
3806
# File 'lib/HDLRuby/verilog_parser.rb', line 3804

def _NULL_hook
  return AST[:NULL, self.property_hook ]
end

#_NUMBER_hook(tok) ⇒ Object



6704
6705
6706
# File 'lib/HDLRuby/verilog_parser.rb', line 6704

def _NUMBER_hook(tok)
  return AST[:NUMBER, tok, self.property_hook ]
end

#_NUMBER_parse(base) ⇒ Object



6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
# File 'lib/HDLRuby/verilog_parser.rb', line 6673

def _NUMBER_parse(base)
  tok = self.get_token(NUMBER_REX)
  case(base)
  when Q_b_TOK, Q_B_TOK
    # Binary case.
    if tok =~ /^[0-1xXzZ\?][_0-1xXzZ\?]*$/ then
      return self._NUMBER_hook(tok)
    end
    self.parse_error("malformed number")
  when Q_o_TOK, Q_O_TOK
    # Octal case.
    if tok =~ /^[0-7xXzZ\?][_0-7xXzZ\?]*$/ then
      return self._NUMBER_hook(tok)
    end
    self.parse_error("malformed number")
  when Q_d_TOK, Q_D_TOK
    # Decimal case.
    if tok =~ /^[0-9xXzZ\?][_0-9xXzZ\?]*$/ then
      return self._NUMBER_hook(tok)
    end
    self.parse_error("malformed number")
  when Q_h_TOK, Q_H_TOK
    # hexecimal case.
    if tok =~ /^[0-9a-fA-FxXzZ\?][_0-9a-fA-FxXzZ\?]*$/ then
      return self._NUMBER_hook(tok)
    end
    self.parse_error("malformed number")
  end
  raise "Internal error: should not be there!"
end

#_OUTPUT_SYMBOL_hook(symbol) ⇒ Object



2320
2321
2322
# File 'lib/HDLRuby/verilog_parser.rb', line 2320

def _OUTPUT_SYMBOL_hook(symbol)
  return AST[:OUTPUT_SYMBOL, symbol, self.property_hook ]
end

#_OUTPUT_SYMBOL_parseObject



2314
2315
2316
2317
2318
# File 'lib/HDLRuby/verilog_parser.rb', line 2314

def _OUTPUT_SYMBOL_parse
  symbol = self.get_token(OUTPUT_SYMBOL_REX)
  return nil unless symbol
  return self._OUTPUT_SYMBOL_hook(symbol)
end

#_QUESTION_MARK_hook(tok) ⇒ Object



6456
6457
6458
# File 'lib/HDLRuby/verilog_parser.rb', line 6456

def _QUESTION_MARK_hook(tok)
  return AST[:QUESTION_MARK, tok, self.property_hook ]
end

#_QUESTION_MARK_parseObject



6449
6450
6451
6452
6453
6454
# File 'lib/HDLRuby/verilog_parser.rb', line 6449

def _QUESTION_MARK_parse
  if self.get_token(QUESTION_REX) then
    return _QUESTION_MARK_hook(QUESTION_TOK)
  end
  return nil
end

#_STRENGTH0_hook(strength0) ⇒ Object



3242
3243
3244
# File 'lib/HDLRuby/verilog_parser.rb', line 3242

def _STRENGTH0_hook(strength0)
  return AST[:STRENGTH0, strength0, self.property_hook ]
end

#_STRENGTH0_parseObject



3234
3235
3236
3237
3238
3239
3240
# File 'lib/HDLRuby/verilog_parser.rb', line 3234

def _STRENGTH0_parse
  strength0 = self.get_token(STRENGTH0_REX)
  unless strength0
    return nil
  end
  return _STRENGTH0_hook(strength0)
end

#_STRENGTH1_hook(strength1) ⇒ Object



3260
3261
3262
# File 'lib/HDLRuby/verilog_parser.rb', line 3260

def _STRENGTH1_hook(strength1)
  return AST[:STRENGTH1, strength1, self.property_hook ]
end

#_STRENGTH1_parseObject



3252
3253
3254
3255
3256
3257
3258
# File 'lib/HDLRuby/verilog_parser.rb', line 3252

def _STRENGTH1_parse
  strength1 = self.get_token(STRENGTH1_REX)
  unless strength1
    return nil
  end
  return _STRENGTH1_hook(strength1)
end

#_STRING_hook(string) ⇒ Object



6473
6474
6475
# File 'lib/HDLRuby/verilog_parser.rb', line 6473

def _STRING_hook(string)
  return AST[:STRING, string, self.property_hook ]
end

#_STRING_parseObject



6465
6466
6467
6468
6469
6470
6471
# File 'lib/HDLRuby/verilog_parser.rb', line 6465

def _STRING_parse
  string = self.get_token(STRING_REX)
  if string then
    return _STRING_hook(string)
  end
  return nil
end

#_UNARY_OPERATOR_hook(tok) ⇒ Object



6422
6423
6424
# File 'lib/HDLRuby/verilog_parser.rb', line 6422

def _UNARY_OPERATOR_hook(tok)
  return AST[:UNARY_OPERATOR, tok, self.property_hook ]
end

#_UNARY_OPERATOR_parseObject



6414
6415
6416
6417
6418
6419
6420
# File 'lib/HDLRuby/verilog_parser.rb', line 6414

def _UNARY_OPERATOR_parse
  tok = self.get_token(UNARY_OPERATOR_REX)
  if tok then
    return self._UNARY_OPERATOR_hook(tok)
  end
  return nil
end

#_UNSIGNED_NUMBER_hook(tok) ⇒ Object



6645
6646
6647
# File 'lib/HDLRuby/verilog_parser.rb', line 6645

def _UNSIGNED_NUMBER_hook(tok)
  return AST[:UNSIGNED_NUMBER, tok, self.property_hook ]
end

#_UNSIGNED_NUMBER_parseObject



6637
6638
6639
6640
6641
6642
6643
# File 'lib/HDLRuby/verilog_parser.rb', line 6637

def _UNSIGNED_NUMBER_parse
  tok = self.get_token(UNSIGNED_NUMBER_REX)
  if tok then
    return self._UNSIGNED_NUMBER_hook(tok)
  end
  return nil
end

#add_module_name(name) ⇒ Object

Add a known module name.



609
610
611
# File 'lib/HDLRuby/verilog_parser.rb', line 609

def add_module_name(name)
  @module_names << name.to_s
end

#add_term_hook(mul_terms) ⇒ Object



6368
6369
6370
6371
6372
6373
6374
# File 'lib/HDLRuby/verilog_parser.rb', line 6368

def add_term_hook(mul_terms)
  if self.state.compress and mul_terms.size == 1 then
    return mul_terms[0]
  else
    return AST[:and_term, mul_terms, self.property_hook ]
  end
end

#add_term_parseObject



6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
# File 'lib/HDLRuby/verilog_parser.rb', line 6351

def add_term_parse
  # puts "add_term_parse"
  cur_mul_term = self.mul_term_parse
  return nil unless cur_mul_term
  mul_terms = [ cur_mul_term ]
  tok = nil
  loop do
    tok = self.get_token(MUL_OPERATOR_REX)
    break unless tok
    mul_terms << tok
    cur_mul_term = self.mul_term_parse
    self.parse_error("expression expected") unless cur_mul_term
    mul_terms << cur_mul_term
  end
  return add_term_hook(mul_terms)
end

#add_udp_name(name) ⇒ Object

Add a known UDP name.



614
615
616
# File 'lib/HDLRuby/verilog_parser.rb', line 614

def add_udp_name(name)
  @udp_names << name.to_s
end

#always_statement_hook(statement) ⇒ Object



3866
3867
3868
# File 'lib/HDLRuby/verilog_parser.rb', line 3866

def always_statement_hook(statement)
  return AST[:always_statement, statement, self.property_hook ]
end

#always_statement_parseObject



3859
3860
3861
3862
3863
3864
# File 'lib/HDLRuby/verilog_parser.rb', line 3859

def always_statement_parse
  return nil unless self.get_token(ALWAYS_REX)
  statement = self.statement_parse
  self.parse_error("statement expected") unless statement
  return self.always_statement_hook(statement)
end

#assignment_hook(lvalue, expression) ⇒ Object



4078
4079
4080
# File 'lib/HDLRuby/verilog_parser.rb', line 4078

def assignment_hook(lvalue,expression)
  return AST[:assignment, lvalue,expression, self.property_hook ]
end

#assignment_parseObject



4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
# File 'lib/HDLRuby/verilog_parser.rb', line 4062

def assignment_parse
  parse_state = self.state
  lvalue = self.lvalue_parse
  unless lvalue then
    self.state = parse_state
    return nil
  end
  unless self.get_token(EQUAL_REX) then
    self.state = parse_state
    return nil
  end
  expression = self.expression_parse
  self.parse_error("expression expected") unless expression
  return self.assignment_hook(lvalue,expression)
end

#bit_and_term_hook(equal_terms) ⇒ Object



6236
6237
6238
6239
6240
6241
6242
# File 'lib/HDLRuby/verilog_parser.rb', line 6236

def bit_and_term_hook(equal_terms)
  if self.state.compress and equal_terms.size == 1 then
    return equal_terms[0]
  else
    return AST[:bit_and_term, equal_terms, self.property_hook ]
  end
end

#bit_and_term_parseObject



6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
# File 'lib/HDLRuby/verilog_parser.rb', line 6219

def bit_and_term_parse
  # puts "bit_and_term_parse"
  cur_equal_term = self.equal_term_parse
  return nil unless cur_equal_term
  equal_terms = [ cur_equal_term ]
  tok = nil
  loop do
    tok = self.get_token(EQUAL_OPERATOR_REX)
    break unless tok
    equal_terms << tok
    cur_equal_term = self.equal_term_parse
    self.parse_error("expression expected") unless cur_equal_term
    equal_terms << cur_equal_term
  end
  return bit_and_term_hook(equal_terms)
end

#bit_or_term_hook(bit_xor_terms) ⇒ Object



6169
6170
6171
6172
6173
6174
6175
# File 'lib/HDLRuby/verilog_parser.rb', line 6169

def bit_or_term_hook(bit_xor_terms)
  if self.state.compress and bit_xor_terms.size == 1 then
    return bit_xor_terms[0]
  else
    return AST[:bit_or_term, bit_xor_terms, self.property_hook ]
  end
end

#bit_or_term_parseObject



6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
# File 'lib/HDLRuby/verilog_parser.rb', line 6152

def bit_or_term_parse
  # puts "bit_or_term_parse"
  cur_bit_xor_term = self.bit_xor_term_parse
  return nil unless cur_bit_xor_term
  bit_xor_terms = [ cur_bit_xor_term ]
  tok = nil
  loop do
    tok = self.get_token(XOR_OPERATOR_REX)
    break unless tok
    bit_xor_terms << tok
    cur_bit_xor_term = self.bit_xor_term_parse
    self.parse_error("expression expected") unless cur_bit_xor_term
    bit_xor_terms << cur_bit_xor_term
  end
  return bit_or_term_hook(bit_xor_terms)
end

#bit_xor_term_hook(bit_and_terms) ⇒ Object



6203
6204
6205
6206
6207
6208
6209
# File 'lib/HDLRuby/verilog_parser.rb', line 6203

def bit_xor_term_hook(bit_and_terms)
  if self.state.compress and bit_and_terms.size == 1 then
    return bit_and_terms[0]
  else
    return AST[:bit_xor_term, bit_and_terms, self.property_hook ]
  end
end

#bit_xor_term_parseObject



6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
# File 'lib/HDLRuby/verilog_parser.rb', line 6185

def bit_xor_term_parse
  # puts "bit_xor_term_parse"
  parse_state = self.state
  cur_bit_and_term = self.bit_and_term_parse
  return nil unless cur_bit_and_term
  bit_and_terms = [ cur_bit_and_term ]
  tok = nil
  loop do
    tok = self.get_token(AND_OPERATOR_REX)
    break unless tok
    bit_and_terms << tok
    cur_bit_and_term = self.bit_and_term_parse
    self.parse_error("expression expected") unless cur_bit_and_term
    bit_and_terms << cur_bit_and_term
  end
  return bit_xor_term_hook(bit_and_terms)
end

#block_declaration_hook(declaration) ⇒ Object



4379
4380
4381
4382
4383
4384
4385
# File 'lib/HDLRuby/verilog_parser.rb', line 4379

def block_declaration_hook(declaration)
  if self.state.compress then
    return declaration
  else
    return AST[:block_declaration, declaration, self.property_hook ]
  end
end

#block_declaration_parseObject



4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
# File 'lib/HDLRuby/verilog_parser.rb', line 4351

def block_declaration_parse
  parameter_declaration = self.parameter_declaration_parse
  if parameter_declaration then
    return self.block_declaration_hook(parameter_declaration)
  end
  reg_declaration = self.reg_declaration_parse
  if reg_declaration then
    return self.block_declaration_hook(reg_declaration)
  end
  integer_declaration = self.integer_declaration_parse
  if integer_declaration then
    return self.block_declaration_hook(integer_declaration)
  end
  real_declaration = self.real_declaration_parse
  if real_declaration then
    return self.block_declaration_hook(real_declaration)
  end
  time_declaration = self.time_declaration_parse
  if time_declaration then
    return self.block_declaration_hook(time_declaration)
  end
  event_declaration = self.event_declaration_parse
  if event_declaration then
    return self.block_declaration_hook(event_declaration)
  end
  return nil
end

#blocking_assignment_hook(lvalue, delay_or_event_control, expression) ⇒ Object



4107
4108
4109
4110
4111
# File 'lib/HDLRuby/verilog_parser.rb', line 4107

def blocking_assignment_hook(lvalue, delay_or_event_control,
                             expression)
  return AST[:blocking_assignment,
             lvalue,delay_or_event_control,expression, self.property_hook ]
end

#blocking_assignment_parseObject



4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
# File 'lib/HDLRuby/verilog_parser.rb', line 4089

def blocking_assignment_parse
  parse_state = self.state
  lvalue = self.lvalue_parse
  return nil unless lvalue
  unless self.get_token(EQUAL_REX) then
    self.state = parse_state
    return nil
  end
  delay_or_event_control = self.delay_or_event_control_parse
  expression = self.expression_parse
  unless expression then
    self.state = parse_state
    return nil
  end
  return self.blocking_assignment_hook(lvalue,delay_or_event_control,
                                      expression)
end

#case_item_hook(cas, statement_or_null) ⇒ Object



4220
4221
4222
# File 'lib/HDLRuby/verilog_parser.rb', line 4220

def case_item_hook(cas, statement_or_null)
  return AST[:case_item, cas,statement_or_null, self.property_hook ]
end

#case_item_parseObject



4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
# File 'lib/HDLRuby/verilog_parser.rb', line 4187

def case_item_parse
  parse_state = self.state
  if self.get_token(DEFAULT_REX) then
    self.get_token(COLON_REX)
    statement_or_null = self.statement_or_null_parse
    self.parse_error("statement or nothing expected") unless statement_or_null
    return self.case_item_hook(DEFAULT_TOK,statement_or_null)
  end
  cur_expression = self.expression_parse
  # self.parse_error("expression expected") unless cur_expression
  unless cur_expression then
    self.state = parse_state
    return nil
  end
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << cur_expression
  end
  unless self.get_token(COLON_REX) then
    # It was not an item
    self.state = parse_state
    return nil
  end
  statement_or_null = self.statement_or_null_parse
  self.parse_error("statement or nothing expected") unless statement_or_null
  return self.case_item_hook(expressions,statement_or_null)
end

#charge_strength_hook(type) ⇒ Object



3187
3188
3189
# File 'lib/HDLRuby/verilog_parser.rb', line 3187

def charge_strength_hook(type)
  return AST[:char_strength, type, self.property_hook ]
end

#charge_strength_parseObject



3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
# File 'lib/HDLRuby/verilog_parser.rb', line 3171

def charge_strength_parse
  parse_state = self.state
  tok0 = self.get_token(OPEN_PAR_REX)
  tok1 = self.get_token(CHAR_STRENGH_REX)
  tok2 = self.get_token(CLOSE_PAR_REX)
  if !tok0 or !tok2 then
    self.state = parse_state
    return nil
  end
  unless tok1 
    self.state = parse_state
    return nil
  end
  return charget_strength_hook(tok1)
end

#combinational_entry_hook(level_input_list, output_symbol) ⇒ Object



2135
2136
2137
# File 'lib/HDLRuby/verilog_parser.rb', line 2135

def combinational_entry_hook(level_input_list, output_symbol)
  return AST[:combinational_entry, level_input_list,output_symbol, self.property_hook ]
end

#combinational_entry_parseObject



2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
# File 'lib/HDLRuby/verilog_parser.rb', line 2120

def combinational_entry_parse
  parse_state = self.state
  level_input_list = self.level_input_list_parse
  if !level_input_list or !self.get_token(COLON_REX) then
    self.state = parse_state
    return nil
  end
  output_symbol = self._OUTPUT_SYMBOL_parse
  if !output_symbol or !self.get_token(SEMICOLON_REX) then
    self.state = parse_state
    return nil
  end
  return self.combinational_entry_hook(level_input_list,output_symbol)
end

#comment_hook(comment) ⇒ Object



6916
6917
6918
# File 'lib/HDLRuby/verilog_parser.rb', line 6916

def comment_hook(comment)
  return AST[:comment, comment, self.property_hook ]
end

#comment_parseObject



6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
# File 'lib/HDLRuby/verilog_parser.rb', line 6904

def comment_parse
  short_comment = self.short_comment_parse
  if short_comment then
    return self.comment_hook(short_comment)
  end
  long_comment = self.long_comment_parse
  if long_comment then
    return self.comment_hook(long_comment)
  end
  return nil
end

#comment_text_hook(tok) ⇒ Object



7012
7013
7014
# File 'lib/HDLRuby/verilog_parser.rb', line 7012

def comment_text_hook(tok)
  return AST[:comment_text, tok, self.property_hook ]
end

#comparison_term_hook(shift_terms) ⇒ Object



6302
6303
6304
6305
6306
6307
6308
# File 'lib/HDLRuby/verilog_parser.rb', line 6302

def comparison_term_hook(shift_terms)
  if self.state.compress and shift_terms.size == 1 then
    return shift_terms[0]
  else
    return AST[:comparison_term, shift_terms, self.property_hook ]
  end
end

#comparison_term_parseObject



6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
# File 'lib/HDLRuby/verilog_parser.rb', line 6285

def comparison_term_parse
  # puts "comparison_parse"
  cur_shift_term = self.shift_term_parse
  return nil unless cur_shift_term
  shift_terms = [ cur_shift_term ]
  tok = nil
  loop do
    tok = self.get_token(SHIFT_OPERATOR_REX)
    break unless tok
    shift_terms << tok
    cur_shift_term = self.shift_term_parse
    self.parse_error("expression expected") unless cur_shift_term
    shift_terms << cur_shift_term
  end
  return comparison_term_hook(shift_terms)
end

#concatenation_hook(expressions) ⇒ Object



6757
6758
6759
# File 'lib/HDLRuby/verilog_parser.rb', line 6757

def concatenation_hook(expressions)
  return AST[:concatenation, expressions, self.property_hook ]
end

#concatenation_parseObject



6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
# File 'lib/HDLRuby/verilog_parser.rb', line 6732

def concatenation_parse
  parse_state = self.state
  unless self.get_token(OPEN_CUR_REX) then
    self.state = parse_state
    return nil
  end
  cur_expression = self.expression_parse
  self.parse_error("expression expected") unless cur_expression
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << cur_expression
  end
  unless self.get_token(CLOSE_CUR_REX) then
    # Maybe it was a multiple concatenation, rewind and cancel.
    self.state = parse_state
    return nil
  end
  return self.concatenation_hook(expressions)
end

#condition_term_hook(logic_or_terms) ⇒ Object



6072
6073
6074
6075
6076
6077
6078
# File 'lib/HDLRuby/verilog_parser.rb', line 6072

def condition_term_hook(logic_or_terms)
  if self.state.compress and logic_or_terms.size == 1 then
    return logic_or_terms[0]
  else
    return AST[:condition_term, logic_or_terms, self.property_hook ]
  end
end

#condition_term_parseObject



6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
# File 'lib/HDLRuby/verilog_parser.rb', line 6057

def condition_term_parse
  # puts "condition_term_parse"
  cur_logic_or_term = self.logic_or_term_parse
  return nil unless cur_logic_or_term
  logic_or_terms = [ cur_logic_or_term ]
  loop do
    break unless self.get_token(OR_OR_REX)
    logic_or_terms << OR_OR_TOK
    cur_logic_or_term = self.logic_or_term_parse
    self.parse_error("expression expected") unless cur_logic_or_term
    logic_or_terms << cur_logic_or_term
  end
  return condition_term_hook(logic_or_terms)
end

#conditional_port_expression_hook(port_reference__unary_operator, binary_operator, port_reference) ⇒ Object



5598
5599
5600
5601
5602
5603
5604
5605
# File 'lib/HDLRuby/verilog_parser.rb', line 5598

def conditional_port_expression_hook(port_reference__unary_operator,
                                     binary_operator,
                                     port_reference)
  return AST[:conditional_port_expression,
             port_reference__unary_operator,
             binary_operator,
             port_reference, self.property_hook ]
end

#conditional_port_expression_parseObject



5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
# File 'lib/HDLRuby/verilog_parser.rb', line 5574

def conditional_port_expression_parse
  unary_operator = self.unary_operator_parse
  port_reference0 = self.port_reference_parse
  if !port_reference0 then
    self.parse_error("there should be any of [#{UNARY_OPERATOR_TOKS.join(",")}] here") if unary_operator
    return nil
  end
  if unary_operator then
    return self.conditional_port_expression_hook(unary_operator,
                                                 port_reference0,nil)
  end
  binary_operator = self.binary_operator_parse
  if binary_operator then
    port_reference1 = self.port_reference_parse
    self.parse_error("port reference expected here") unless port_reference1
    return self.conditional_port_expression_hook(port_reference0,
                                                 binary_operator,
                                                 port_reference1)
  else
    return self.conditional_port_expression_hook(port_reference0,
                                                 nil,nil)
  end
end

#constant_expression_hook(expression) ⇒ Object



5880
5881
5882
# File 'lib/HDLRuby/verilog_parser.rb', line 5880

def constant_expression_hook(expression)
  return AST[:constant_expression, expression, self.property_hook ]
end

#constant_expression_parseObject



5874
5875
5876
5877
5878
# File 'lib/HDLRuby/verilog_parser.rb', line 5874

def constant_expression_parse
  expression = self.expression_parse
  return nil unless expression
  return self.constant_expression_hook(expression)
end

#continuous_assignment_hook(nettype, drive_strength, expandrange, delay, list_of_assignments) ⇒ Object



2979
2980
2981
2982
2983
2984
# File 'lib/HDLRuby/verilog_parser.rb', line 2979

def continuous_assignment_hook(nettype, drive_strength, expandrange,
                               delay, list_of_assignments)
  return AST[:continuous_assignment, 
             nettype,drive_strength,expandrange,delay,
             list_of_assignments, self.property_hook ]
end

#continuous_assignment_parseObject



2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
# File 'lib/HDLRuby/verilog_parser.rb', line 2956

def continuous_assignment_parse
  if self.get_token(ASSIGN_REX) then
    drive_strength = self.drive_strength_parse
    delay = self.delay_parse
    list_of_assignments = self.list_of_assignments_parse
    self.parse_error("semicolon expected HERE #5") unless self.get_token(SEMICOLON_REX)
    return continuous_assignment_hook(ASSIGN_TOK,
                                      drive_strength,nil,
                                      delay,list_of_assignments)
  else
    nettype = self._NETTYPE_parse
    return nil unless nettype
    drive_strength = self.drive_strength_parse
    expandrange = self.expandrange_parse
    delay = self.delay_parse
    list_of_assignments = self.list_of_assignments_parse
    self.parse_error("semicolon expected HERE #6") unless self.get_token(SEMICOLON_REX)
    return continuous_assignment_hook(nettype,
                                      drive_strength,expandrange,
                                      delay,list_of_assignments)
  end
end

#controlled_timing_check_event_hook(timing_check_event_control, specify_terminal_descriptor, timing_check_condition) ⇒ Object



5259
5260
5261
5262
5263
5264
5265
5266
5267
# File 'lib/HDLRuby/verilog_parser.rb', line 5259

def controlled_timing_check_event_hook(
    timing_check_event_control,
    specify_terminal_descriptor,
    timing_check_condition)
  return AST[:controlled_timing_check_event,
             timing_check_event_control,
             specify_terminal_descriptor,
             timing_check_condition, self.property_hook ]
end

#controlled_timing_check_event_parseObject



5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
# File 'lib/HDLRuby/verilog_parser.rb', line 5236

def controlled_timing_check_event_parse
  parse_state = self.state
  timing_check_event_control = self.timing_check_event_control_parse
  return nil unless timing_check_event_control
  specify_terminal_descriptor = self.specify_terminal_descriptor_parse
  unless specify_terminal_descriptor then
    self.state = parse_state
    return nil
  end
  unless self.get_token(AND_AND_AND_REX) then
    return self.controlled_timing_check_event_hook(
      timing_check_event_control,
      specify_terminal_descriptor,
      nil)
  end
  timing_check_condition = self.timing_check_condition_parse
  self.parse_error("timing check condition expected") unless timing_check_condition
  return self.controlled_timing_check_event_hook(
    timing_check_event_control,
    specify_terminal_descriptor,
    timing_check_condition)
end

#data_source_hook(expression) ⇒ Object



5725
5726
5727
# File 'lib/HDLRuby/verilog_parser.rb', line 5725

def data_source_hook(expression)
  return AST[:data_source, expression, self.property_hook ]
end

#data_source_parseObject



5717
5718
5719
5720
5721
5722
5723
# File 'lib/HDLRuby/verilog_parser.rb', line 5717

def data_source_parse
  # *Auth*: the check are assumed to be done at the AST level.
  #  If required, please redefine data_source_hook
  expression = self.expression_parse
  return nil unless expression
  return self.data_source_hook(expression)
end

#delay_control_hook(number__identifier__mintypmax_expression) ⇒ Object



7152
7153
7154
# File 'lib/HDLRuby/verilog_parser.rb', line 7152

def delay_control_hook(number__identifier__mintypmax_expression)
  return AST[:delay_control, number__identifier__mintypmax_expression, self.property_hook ]
end

#delay_control_parseObject



7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
# File 'lib/HDLRuby/verilog_parser.rb', line 7133

def delay_control_parse
  unless self.get_token(SHARP_REX) then
    return nil
  end
  number = self.number_parse
  if number then
    return self.delay_control_hook(number)
  end
  identifier = self.identifier_parse
  if identifier then
    return self.delay_control_hook(identifier)
  end
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  mintypmax_expression = self.mintypmax_expression_parse
  self.parse_error("min:typical:max expression expected") unless mintypmax_expression
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return self.delay_control_hook(mintypmax_expression)
end

#delay_hook(number__identifier__mintypmax_expression, mintypmax_expression1, mintypmax_expression2) ⇒ Object



3417
3418
3419
3420
3421
# File 'lib/HDLRuby/verilog_parser.rb', line 3417

def delay_hook(mintypmax_expression__number,
               mintypmax_expression1, mintypexpression2)
  return AST[:delay, mintypmax_expression__number,
             mintypmax_expression1,mintypexpression2, self.property_hook ]
end

#delay_or_event_control_hook(base, arg0, arg1) ⇒ Object



4175
4176
4177
# File 'lib/HDLRuby/verilog_parser.rb', line 4175

def delay_or_event_control_hook(base,arg0,arg1)
  return AST[:delay_or_event_control, base,arg0,arg1, self.property_hook ]
end

#delay_or_event_control_parseObject



4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
# File 'lib/HDLRuby/verilog_parser.rb', line 4153

def delay_or_event_control_parse
  if self.get_token(REPEAT_REX) then
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    event_control = self.event_control_parse
    self.parse_error("event control expected") unless event_control
    return self.delay_or_event_control_hook(REPEAT_TOK,
                                       expression,event_control)
  end
  delay_control = self.delay_control_parse
  if delay_control then
    return self.delay_or_event_control_hook(delay_control,nil,nil)
  end
  event_control = self.event_control_parse
  if event_control then
    return self.delay_or_event_control_hook(event_control,nil,nil)
  end
  return nil
end

#delay_parseObject



3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
# File 'lib/HDLRuby/verilog_parser.rb', line 3375

def delay_parse
  unless self.get_token(SHARP_REX) then
    return nil
  end
  if self.get_token(OPEN_PAR_REX) then
    mintypmax_expression0 = self.mintypmax_expression_parse
    self.parse_error("min:typical:max delay expression expected") unless mintypmax_expression0
    tok = self.get_token(COMMA_CLOSE_PAR_REX)
    if tok == COMMA_TOK then
      mintypmax_expression1 = self.mintypmax_expression_parse
      self.parse_error("min:typical:max delay expression expected") unless mintypmax_expression1
      tok = self.get_token(COMMA_CLOSE_PAR_REX)
      if tok == COMMA_TOK then
        mintypmax_expression2 = self.mintypmax_expression_parse
        self.parse_error("min:typical:max delay expression expected") unless mintypmax_expression2
        self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
        return self.delay_hook(mintypmax_expression0,
                               mintypmax_expression1,
                               mintypmax_expression2)
      elsif tok == CLOSE_PAR_TOK then
        return self.delay_hook(mintypmax_expression0,
                               mintypmax_expression1,nil)
      else
        self.parse_error("comma or closing parenthesis expected")
      end
    elsif tok == CLOSE_PAR_TOK then
      return self.delay_hook(mintypmax_expression0,nil,nil)
    else
      self.parse_error("closing parenthesis expected")
    end
  end
  number = self.number_parse
  if number then
    return self.delay_hook(number,nil,nil)
  end
  identifier = self.identifier_parse
  if identifier then
    return self.delay_hook(identifier)
  end
  self.parse_error("identifier expected")
end

#description_hook(elem) ⇒ Object



1434
1435
1436
1437
1438
1439
1440
# File 'lib/HDLRuby/verilog_parser.rb', line 1434

def description_hook(elem)
  if self.state.compress then
    return elem
  else
    return AST[:description, elem, self.property_hook ]
  end
end

#description_parseObject



1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
# File 'lib/HDLRuby/verilog_parser.rb', line 1422

def description_parse
  elem = self.module_parse
  if !elem then
    elem = self.udp_parse
  end
  if !elem then
    return nil if self.eof?
    self.parse_error("this is probably not a Verilog HDL file")
  end
  return self.description_hook(elem)
end

#drive_strength_hook(strengthL, strengthR) ⇒ Object



3224
3225
3226
# File 'lib/HDLRuby/verilog_parser.rb', line 3224

def drive_strength_hook(strengthL, strengthR)
  return AST[:drive_strength, strengthL,strengthR, self.property_hook ]
end

#drive_strength_parseObject



3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
# File 'lib/HDLRuby/verilog_parser.rb', line 3198

def drive_strength_parse
  parse_state = self.state
  unless self.get_token(OPEN_PAR_REX) then
    return nil
  end
  strength0 = self._STRENGTH0_parse
  if !strength0 then
    strength1 = self._STRENGTH1_parse
    unless strength1 then
      self.state = parse_state
      return nil
    end
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    strength0 = self._STRENGTH0_parse
    self.parse_error("one of [#{STRENGTH0_TOKS.join(",")}] expected") unless strength0
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return drive_strength_hook(strength1, strength0)
  else
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    strength1 = self._STRENGTH1_parse
    self.parse_error("one of [#{STRENGTH1_TOKS.join(",")}] expected") unless strength1
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return drive_strength_hook(strength0, strength1)
  end
end

#each_origin_rule(&ruby_block) ⇒ Object

Access each origin rule.



1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'lib/HDLRuby/verilog_parser.rb', line 1375

def each_origin_rule(&ruby_block)
  # No ruby block? Return an enumerator.
  return to_enum(:each_origin_rule) unless ruby_block
  # A ruby block? Apply it on each rule value.
  orig = nil
  RULES.each do |k,v|
    orig = ORIGIN_RULES[k]
    orig ? ruby_block.(orig) : ruby_block.(v)
  end
end

#each_rule(&ruby_block) ⇒ Object

Access each rule.



1367
1368
1369
1370
1371
1372
# File 'lib/HDLRuby/verilog_parser.rb', line 1367

def each_rule(&ruby_block)
  # No ruby block? Return an enumerator.
  return to_enum(:each_rule) unless ruby_block
  # A ruby block? Apply it on each rule value.
  RULES.each_value(&ruby_block)
end

#edge_control_specifier_hook(edge_descriptors) ⇒ Object



5317
5318
5319
# File 'lib/HDLRuby/verilog_parser.rb', line 5317

def edge_control_specifier_hook(edge_descriptors)
  return AST[:edge_control_specifier, edge_descriptors, self.property_hook ]
end

#edge_control_specifier_parseObject



5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
# File 'lib/HDLRuby/verilog_parser.rb', line 5297

def edge_control_specifier_parse
  unless self.get_token(EDGE_REX) then
    return nil
  end
  self.parse_error("opening bracket expected") unless self.get_token(OPEN_BRA_REX)
  cur_edge_descriptor = self.edge_descriptor_parse
  self.parse_error("edge descriptor expected") unless cur_edge_descriptor
  edge_descriptors = [ cur_edge_descriptor ]
  loop do
    if self.get_token(COMMA_REX) then
      break
    end
    cur_edge_descriptor = self.edge_descriptor_parse
    self.parse_error("edge descriptor expected") unless cur_edge_descriptor
    edge_descriptors << cur_edge_descriptor
  end
  self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
  return self.edge_control_specifier_hook(edge_descriptors)
end

#edge_descriptor_hook(tok) ⇒ Object



5340
5341
5342
# File 'lib/HDLRuby/verilog_parser.rb', line 5340

def edge_descriptor_hook(tok)
  return AST[:edge_descriptor, tok, self.property_hook ]
end

#edge_descriptor_parseObject



5332
5333
5334
5335
5336
5337
5338
# File 'lib/HDLRuby/verilog_parser.rb', line 5332

def edge_descriptor_parse
  tok = self.get_token(EDGE_DESCRIPTOR_REX)
  if tok then
    return self.edge_descriptor_hook(tok)
  end
  return nil
end

#edge_hook(edge) ⇒ Object



2268
2269
2270
# File 'lib/HDLRuby/verilog_parser.rb', line 2268

def edge_hook(edge)
  return AST[:edge, edge, self.property_hook ]
end

#edge_identifier_hook(tok) ⇒ Object



5745
5746
5747
# File 'lib/HDLRuby/verilog_parser.rb', line 5745

def edge_identifier_hook(tok)
  return AST[:edge_identifier, tok, self.property_hook ]
end

#edge_identifier_parseObject



5736
5737
5738
5739
5740
5741
5742
5743
# File 'lib/HDLRuby/verilog_parser.rb', line 5736

def edge_identifier_parse
  tok = self.get_token(EDGE_IDENTIFIER_REX)
  if tok then
    return self.edge_identifier_hook(tok)
  else
    return nil
  end
end

#edge_input_list_hook(level_symbols0, edge, level_symbols1) ⇒ Object



2245
2246
2247
# File 'lib/HDLRuby/verilog_parser.rb', line 2245

def edge_input_list_hook(level_symbols0, edge, level_symbols1)
  return AST[:edge_input_list, level_symbols0,edge,level_symbols1, self.property_hook ]
end

#edge_input_list_parseObject



2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
# File 'lib/HDLRuby/verilog_parser.rb', line 2222

def edge_input_list_parse
  parse_state = self.state
  level_symbols0 = []
  cur_level_symbol = nil
  loop do
    cur_level_symbol = self._LEVEL_SYMBOL_parse
    break unless cur_level_symbol
    level_symbols0 << cur_level_symbol
  end
  edge = self.edge_parse
  if !edge then
    self.state = parse_state
    return nil
  end
  level_symbols1 = []
  loop do
    cur_level_symbol = self._LEVEL_SYMBOL_parse
    break unless cur_level_symbol
    level_symbols1 << cur_level_symbol
  end
  return self.edge_input_list_hook(level_symbols0,edge,level_symbols1)
end

#edge_parseObject



2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
# File 'lib/HDLRuby/verilog_parser.rb', line 2256

def edge_parse
  if self.get_token(OPEN_PAR_REX) then
    level_symbol0 = self._LEVEL_SYMBOL_parse
    level_symbol1 = self._LEVEL_SYMBOL_parse
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    edge = [ level_symbol0,level_symbol1 ]
  else
    edge = self._EDGE_SYMBOL_parse
  end
  return self.edge_hook(edge)
end

#edge_sensitive_path_declaration_hook(expression, edge_identifier, specify_input_terminal_descriptor, tok, specify_output_terminal_descriptor__list_of_path_outputs, polarity_operator, data_source_expression, path_delay_value) ⇒ Object



5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
# File 'lib/HDLRuby/verilog_parser.rb', line 5698

def edge_sensitive_path_declaration_hook(
  expression, edge_identifier, specify_input_terminal_descriptor, tok,
  specify_output_terminal_descriptor__list_of_path_outputs,
  polarity_operator, data_source_expression, path_delay_value)
  return AST[:edge_sensitive_path_declaration,
             expression,edge_identifier,
             specify_input_terminal_descriptor,tok,
             spcify_output_terminal_descriptor__list_of_path_outputs,
             polarity_operator,data_source_expression,path_delay_value, self.property_hook ]
end

#edge_sensitive_path_declaration_parseObject



5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
# File 'lib/HDLRuby/verilog_parser.rb', line 5640

def edge_sensitive_path_declaration_parse
  parse_state = self.state
  unless self.get_token(IF_REX) then
    self.state = parse_state
    return nil
  end
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  expression = self.expression_parse
  edge_identifier = self.edge_identifier_parse
  specify_input_terminal_descriptor = 
    self.specify_input_terminal_descriptor_parse
  if !specify_input_terminal_descriptor then
    self.state = parse_state
    return nil
  end
  if self.get_token(SEND_ARROW_REX) then
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    specify_output_terminal_descriptor =
      self.specify_output_terminal_Descriptor_parse
    self.parse_error("output terminal descriptor expected") unless specify_output_terminal_descriptor
    polarity_operator = self.polarity_operator_parse
    self.parse_error("colon expected") unless self.get_token(COLON_REX)
    data_source_expression = self.data_source_expression_parse
    self.parse_error("data source expression expected") unless data_source_expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
    path_delay_value = self.path_delay_value_parse
    self.parse_error("path delay value expected") unless path_delay_value
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.edge_sensitive_path_declaration_hook(
      expression,edge_identifier,specify_input_terminal_descriptor,
      tok,specify_output_terminal_descriptor,polarity_operator,
      data_source_expression,path_delay_value)
  elsif tok == ASTERISK_ARROW_TOK then
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    list_of_path_outputs = self.list_of_path_outputs_parse
    self.parse_error("list of path outputs expected") unless list_of_path_outputs
    polarity_operator = self.polarity_operator_parse
    self.parse_error("colon expected") unless self.get_token(COLON_REX)
    data_source_expression = self.data_source_expression_parse
    self.parse_error("data source expression expected") unless data_source_expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
    path_delay_value = self.path_delay_value_parse
    self.parse_error("path delay value expected") unless path_delay_value
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.edge_sensitive_path_declaration_hook(
      expression,edge_identifier,specify_input_terminal_descriptor,
      tok,list_of_path_outputs,polarity_operator,
      data_source_expression,path_delay_value)
  else
    self.state = parse_state
    return nil
  end
end

#eof?Boolean

Tells if the end of file/string is reached (ignores the spaces and comments for this check)

Returns:

  • (Boolean)


604
605
606
# File 'lib/HDLRuby/verilog_parser.rb', line 604

def eof?
  return (@state.text.match(/\G#{S}\z/,@state.index) != nil)
end

#equal_term_hook(comparison_terms) ⇒ Object



6269
6270
6271
6272
6273
6274
6275
# File 'lib/HDLRuby/verilog_parser.rb', line 6269

def equal_term_hook(comparison_terms)
  if self.state.compress and comparison_terms.size == 1 then
    return comparison_terms[0]
  else
    return AST[:equal_term, comparison_terms, self.property_hook ]
  end
end

#equal_term_parseObject



6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
# File 'lib/HDLRuby/verilog_parser.rb', line 6252

def equal_term_parse
  # puts "equal_term_parse"
  cur_comparison_term = self.comparison_term_parse
  return nil unless cur_comparison_term
  comparison_terms = [ cur_comparison_term ]
  tok = nil
  loop do
    tok = self.get_token(COMPARISON_OPERATOR_REX)
    break unless tok
    comparison_terms << tok
    cur_comparison_term = self.comparison_term_parse
    self.parse_error("expression expected") unless cur_comparison_term
    comparison_terms << cur_comparison_term
  end
  return equal_term_hook(comparison_terms)
end

#event_control_hook(identifier__event_control) ⇒ Object



7178
7179
7180
# File 'lib/HDLRuby/verilog_parser.rb', line 7178

def event_control_hook(identifier__event_control)
  return AST[:event_control, identifier__event_control, self.property_hook ]
end

#event_control_parseObject



7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
# File 'lib/HDLRuby/verilog_parser.rb', line 7163

def event_control_parse
  unless self.get_token(AT_REX) then
    return nil
  end
  identifier = self.identifier_parse
  if identifier then
    return self.event_control_hook(identifier)
  end
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  event_expression = self.event_expression_parse
  self.parse_error("event expression expected") unless event_expression
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return self.event_control_hook(event_expression)
end

#event_declaration_hook(name_of_events) ⇒ Object



2945
2946
2947
# File 'lib/HDLRuby/verilog_parser.rb', line 2945

def event_declaration_hook(name_of_events)
  return AST[:event_declaration, name_of_events, self.property_hook ]
end

#event_declaration_parseObject



2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
# File 'lib/HDLRuby/verilog_parser.rb', line 2927

def event_declaration_parse
  # puts "event_declaration_parse"
  unless self.get_token(EVENT_REX) then
    return nil
  end
  cur_name_of_event = self.name_of_event_parse
  name_of_events = [ cur_name_of_event ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_name_of_event = self.name_of_event_parse
    name_of_events << cur_name_of_event
  end
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return event_declaration_hook(name_of_events)
end

#event_expression_hook(event_primaries) ⇒ Object



7254
7255
7256
# File 'lib/HDLRuby/verilog_parser.rb', line 7254

def event_expression_hook(event_primaries)
  return AST[:event_expression, event_primaries, self.property_hook ]
end

#event_expression_parseObject



7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
# File 'lib/HDLRuby/verilog_parser.rb', line 7241

def event_expression_parse
  cur_event_primary = self.event_primary_parse
  return nil unless cur_event_primary
  event_primaries = [ cur_event_primary ]
  loop do
    break unless self.get_token(EVENT_OR_COMMA_REX)
    cur_event_primary = self.event_primary_parse
    self.parse_error("event expression expected") unless cur_event_primary
    event_primaries << cur_event_primary
  end
  return event_expression_hook(event_primaries)
end

#event_primary_hook(tok__expression, event_expression) ⇒ Object



7284
7285
7286
7287
# File 'lib/HDLRuby/verilog_parser.rb', line 7284

def event_primary_hook(tok__expression, event_expression)
  return AST[:event_primary,
             tok__expression, event_expression, self.property_hook ]
end

#event_primary_parseObject



7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
# File 'lib/HDLRuby/verilog_parser.rb', line 7269

def event_primary_parse
  if self.get_token(MUL_REX) then
    return event_primary_hook(MUL_TOK,nil)
  end
  tok = self.get_token(EDGE_IDENTIFIER_REX)
  if tok then
    scalar_event_expression = self.scalar_event_expression_parse
    self.parse_error("scalar event expression expected") unless scalar_event_expression
    return self.event_primary_hook(tok,scalar_event_expression)
  end
  expression = self.expression_parse
  return nil unless expression
  return self.event_primary_hook(expression,nil)
end

#expandrange_hook(type, range) ⇒ Object



2822
2823
2824
# File 'lib/HDLRuby/verilog_parser.rb', line 2822

def expandrange_hook(type, range)
  return AST[:expandrange, type,range, self.property_hook ]
end

#expandrange_parseObject



2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
# File 'lib/HDLRuby/verilog_parser.rb', line 2806

def expandrange_parse
  if self.get_token(SCALARED_REX) then
    range = self.range_parse
    self.parse_error("range expected") unless range
    return expandrange_hook(SCALARED_TOK.to_sym, range)
  end
  if self.get_token(VECTORED_REX) then
    range = self.range_parse
    self.parse_error("range expected") unless range
    return expandrange_hook(VECTORED_TOK.to_sym, range)
  end
  range = self.range_parse
  return nil unless range
  return expandrange_hook(:"", range)
end

#expression_hook(string__condition_terms) ⇒ Object



6040
6041
6042
6043
6044
6045
6046
6047
# File 'lib/HDLRuby/verilog_parser.rb', line 6040

def expression_hook(string__condition_terms)
  if self.state.compress and string__condition_terms.is_a?(Array) and 
      string__condition_terms.size == 1 then
    return AST[:expression, string__condition_terms[0] ]
  else
    return AST[:expression, string__condition_terms, self.property_hook ]
  end
end

#expression_parseObject



6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
# File 'lib/HDLRuby/verilog_parser.rb', line 6016

def expression_parse
  # puts "expression_parse"
  string = self._STRING_parse
  if string then
    return self.expression_hook(string)
  end
  cur_condition_term = self.condition_term_parse
  return nil unless cur_condition_term
  condition_terms = [ cur_condition_term ]
  loop do
    break unless self.get_token(QUESTION_REX)
    condition_terms << QUESTION_TOK
    cur_condition_term = self.condition_term_parse
    self.parse_error("expression expected") unless cur_condition_term
    condition_terms << cur_condition_term
    self.parse_error("colon expected") unless self.get_token(COLON_REX)
    condition_terms << COLON_TOK
    cur_condition_term = self.condition_term_parse
    self.parse_error("expression expected") unless cur_condition_term
    condition_terms << cur_condition_term
  end
  return expression_hook(condition_terms)
end

#file_error(error, lpos = @state.lpos) ⇒ Object

Generate a file error with origin indicated in +error+

Raises:



629
630
631
# File 'lib/HDLRuby/verilog_parser.rb', line 629

def file_error(error, lpos=@state.lpos)
  raise FileError.new(error,lpos)
end

#function_call_hook(name_of_function__name_of_system_function, expressions) ⇒ Object



6851
6852
6853
6854
6855
6856
# File 'lib/HDLRuby/verilog_parser.rb', line 6851

def function_call_hook(name_of_function__name_of_system_function,
                       expressions)
  return AST[:function_call,
             name_of_function__name_of_system_function,
             expressions, self.property_hook ]
end

#function_call_parseObject



6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
# File 'lib/HDLRuby/verilog_parser.rb', line 6808

def function_call_parse
  parse_state = self.state
  name_of_function = self.name_of_function_parse
  if name_of_function then
    unless self.get_token(OPEN_PAR_REX) then
      self.state = parse_state
      return nil
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions = [ cur_expression ]
    loop do
      unless self.get_token(COMMA_REX) then
        break
      end
      cur_expression = self.expression_parse
      self.parse_error("expression expected") unless cur_expression
      expressions << cur_expression
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return self.function_call_hook(name_of_function,expressions)
  end
  name_of_system_function = self.name_of_system_function_parse
  return nil unless name_of_system_function
  if self.get_token(OPEN_PAR_REX) then
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions = [ cur_expression ]
    loop do
      unless self.get_token(COMMA_REX) then
        break
      end
      cur_expression = self.expression_parse
      self.parse_error("expression expected") unless cur_expression
      expressions << expression
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return self.function_call_hook(name_of_system_function,expressions)
  else
    return self.function_call_hook(name_of_system_function,nil)
  end
end

#function_hook(range_or_type, name_of_function, tf_declarations, statement) ⇒ Object



2436
2437
2438
2439
2440
# File 'lib/HDLRuby/verilog_parser.rb', line 2436

def function_hook(range_or_type, name_of_function,
                  tf_declarations, statement)
  return AST[:function, 
             range_or_type,name_of_function,tf_declarations,statement, self.property_hook ]
end

#function_parseObject



2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
# File 'lib/HDLRuby/verilog_parser.rb', line 2414

def function_parse
  unless self.get_token(FUNCTION_REX) then
    return nil
  else
    range_or_type = self.range_or_type_parse
    name_of_function = self.name_of_function_parse
    self.parse_error("name of function expected") unless self.get_token(SEMICOLON_REX)
    cur_tf_declaration = self.tf_declaration_parse
    self.parse_error("tf declaration expected") unless cur_tf_declaration
    tf_declarations = [ cur_tf_declaration ]
    loop do
      cur_tf_declaration = self.tf_declaration_parse
      break unless cur_tf_declaration
      tf_declarations << cur_tf_declaration
    end
    statement = self.statement_parse
    self.parse_error("'endfunction' expected") unless self.get_token(ENDFUNCTION_REX)
    return self.function_hook(range_or_type,name_of_function,
                              tf_declarations,statement)
  end
end

#gate_declaration_hook(gatetype, drive_strength, delay, gate_instances) ⇒ Object



3342
3343
3344
3345
3346
# File 'lib/HDLRuby/verilog_parser.rb', line 3342

def gate_declaration_hook(gatetype, drive_strength, delay,
                          gate_instances)
  return AST[:gate_declaration,
             gatetype,drive_strength,delay,gate_instances, self.property_hook ]
end

#gate_declaration_parseObject



3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
# File 'lib/HDLRuby/verilog_parser.rb', line 3322

def gate_declaration_parse
  # puts "gate_declaration_parse"
  gatetype = self._GATETYPE_parse
  return nil unless gatetype
  drive_strength = self.drive_strength_parse
  delay = self.delay_parse
  cur_gate_instance = self.gate_instance_parse
  self.parse_error("gate instance expected") unless cur_gate_instance
  gate_instances = [ cur_gate_instance ]
  loop do
    break unless self.get_token(COMMA_REX)
    cur_gate_instance = self.gate_instance_parse
    self.parse_error("gate instance expected") unless cur_gate_instance
    gate_instances << cur_gate_instance
  end
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return gate_declaration_hook(gatetype,drive_strength,delay,
                               gate_instances)
end

#gate_instance_hook(name_of_gate_instance, terminals) ⇒ Object



3451
3452
3453
# File 'lib/HDLRuby/verilog_parser.rb', line 3451

def gate_instance_hook(name_of_gate_instance, terminals)
  return AST[:gate_instance, name_of_gate_instance,terminals, self.property_hook ]
end

#gate_instance_parseObject



3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
# File 'lib/HDLRuby/verilog_parser.rb', line 3429

def gate_instance_parse
  parse_state = self.state
  name_of_gate_instance = self.name_of_gate_instance_parse
  unless self.get_token(OPEN_PAR_REX) then
    self.state = parse_state
    return nil
  end
  cur_terminal = self.terminal_parse
  unless cur_terminal then
    self.parse_error("terminal expected")
  end
  terminals = [ cur_terminal ]
  loop do
    break unless self.get_token(COMMA_REX)
    cur_terminal = self.terminal_parse
    self.parse_error("terminal expected") unless cur_terminal
    terminals << cur_terminal
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return gate_instance_hook(name_of_gate_instance,terminals)
end

#get_token(rex) ⇒ Object

Get the token matching regexp +rex+ if any from current position. NOTE: it is assumed that rex starts with \G so that the maching really starts from current position of the parser and has a single capture for the token. Also assumes spaces are taken into account in the regexp.



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/HDLRuby/verilog_parser.rb', line 575

def get_token(rex)
  # puts "get_token at index=#{@state.index} and lpos=#{@state.lpos} with rex=#{rex} and char is #{@state.text[@state.index]}"
  # puts "text line is #{@state.text[(@[email protected])[email protected]]}"
  begin
    match = @state.text.match(rex,@state.index)
  rescue => error
    self.file_error(error)
  end
  if match then
    # There is a match, get the blanks and the token
    bls = match.captures[0]
    tok = match.captures[1]
    @state.index = match.end(0)
    @state.lpos += bls.scan(/\n/).size
    # spcs = bls.match(/[ \t]*\z/)
    # @state.cpos = spcs.end(0) - spcs.begin(0)+tok.length
    @state.cpos = 0
    while @state.index > @state.cpos and
        !(@state.text[@state.index-@state.cpos] =~ /\n/) do
      @state.cpos += 1
    end
    return tok
  else
    return nil
  end
end

#identifier_hook(identifiers) ⇒ Object



7036
7037
7038
# File 'lib/HDLRuby/verilog_parser.rb', line 7036

def identifier_hook(identifiers)
  return AST[:identifier, *identifiers, self.property_hook ]
end

#identifier_parseObject



7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
# File 'lib/HDLRuby/verilog_parser.rb', line 7023

def identifier_parse
  cur_identifier = self._IDENTIFIER_parse
  return nil unless cur_identifier
  identifiers = [ cur_identifier ]
  loop do
    break unless self.get_token(DOT_REX)
    cur_identifier = self._IDENTIFIER_parse
    self.parse_error("identifier expected") unless cur_identifier
    identifiers << identifier
  end
  return self.identifier_hook(identifiers)
end

#init_val_hook(val) ⇒ Object



2037
2038
2039
# File 'lib/HDLRuby/verilog_parser.rb', line 2037

def init_val_hook(val)
  return AST[:init_val, val, self.property_hook ]
end

#init_val_parseObject



2031
2032
2033
2034
2035
# File 'lib/HDLRuby/verilog_parser.rb', line 2031

def init_val_parse
  val = self.get_token(INIT_VAL_REX)
  self.parse_error("One of [#{INIT_VAL_TOKS.join(",")}] expected") unless val
  return self.init_val_hook(val)
end

#initial_statement_hook(statement) ⇒ Object



3849
3850
3851
# File 'lib/HDLRuby/verilog_parser.rb', line 3849

def initial_statement_hook(statement)
  return AST[:initial_statement, statement, self.property_hook ]
end

#initial_statement_parseObject



3840
3841
3842
3843
3844
3845
3846
3847
# File 'lib/HDLRuby/verilog_parser.rb', line 3840

def initial_statement_parse
  unless self.get_token(INITIAL_REX) then
    return nil
  end
  statement = self.statement_parse
  self.parse_error("statement expected") unless statement
  return self.initial_statement_hook(statement)
end

#inout_declaration_hook(type, sign, range, list_of_variables) ⇒ Object



2684
2685
2686
# File 'lib/HDLRuby/verilog_parser.rb', line 2684

def inout_declaration_hook(type, sign, range, list_of_variables)
  return AST[:inout_declaration, type,sign,range,list_of_variables, self.property_hook ]
end

#inout_declaration_parseObject



2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
# File 'lib/HDLRuby/verilog_parser.rb', line 2671

def inout_declaration_parse
  # puts "inout_declaration_parse"
  unless self.get_token(INOUT_REX) then
    return nil
  end
  type = self.get_token(INOUTTYPE_REX)
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  list_of_variables = self.list_of_variables_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.inout_declaration_hook(type,sign,range,list_of_variables)
end

#inout_port_declaration_hook(type, sign, range, name_of_variable) ⇒ Object



1753
1754
1755
# File 'lib/HDLRuby/verilog_parser.rb', line 1753

def inout_port_declaration_hook(type, sign, range, name_of_variable)
  return AST[:inout_port_declaration, type,sign,range,name_of_variable, self.property_hook ]
end

#inout_port_declaration_parseObject



1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/HDLRuby/verilog_parser.rb', line 1743

def inout_port_declaration_parse
  return nil unless self.get_token(INOUT_REX)
  type = self.get_token(INOUTTYPE_REX)
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  name_of_variable = self.name_of_variable_parse
  self.parse_error("identifier expected") unless name_of_variable
  return inout_port_declaration_hook(type,sign,range,name_of_variable)
end

#input_declaration_hook(type, sign, range, list_of_variables) ⇒ Object



2618
2619
2620
# File 'lib/HDLRuby/verilog_parser.rb', line 2618

def input_declaration_hook(type, sign, range, list_of_variables)
  return AST[:input_declaration, type,sign,range,list_of_variables, self.property_hook ]
end

#input_declaration_parseObject



2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
# File 'lib/HDLRuby/verilog_parser.rb', line 2604

def input_declaration_parse
  # puts "input_declaration_parse"
  unless self.get_token(INPUT_REX) then
    return nil
  end
  type = self.get_token(INPUTTYPE_REX) 
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  list_of_variables = self.list_of_variables_parse
  self.parse_error("identifier expected") unless list_of_variables
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.input_declaration_hook(type,sign,range,list_of_variables)
end

#input_identifier_hook(identifier) ⇒ Object



4875
4876
4877
# File 'lib/HDLRuby/verilog_parser.rb', line 4875

def input_identifier_hook(identifier)
  return AST[:input_identifier, identifier, self.property_hook ]
end

#input_identifier_parseObject



4868
4869
4870
4871
4872
4873
# File 'lib/HDLRuby/verilog_parser.rb', line 4868

def input_identifier_parse
  # *Auth*: it should be checked that the identifier comes from
  # an input module. Left the the AST processing.
  identifier = self._IDENTIFIER_parse
  return self.input_identifier_hook(identifier)
end

#input_list_hook(input_list) ⇒ Object



2186
2187
2188
2189
2190
2191
2192
# File 'lib/HDLRuby/verilog_parser.rb', line 2186

def input_list_hook(input_list)
  if self.state.compress then
    return input_list
  else
    return AST[:input_list, input_list, self.property_hook ]
  end
end

#input_list_parseObject



2177
2178
2179
2180
2181
2182
2183
2184
# File 'lib/HDLRuby/verilog_parser.rb', line 2177

def input_list_parse
  input_list = self.edge_input_list_parse
  if !input_list then
    input_list = self.level_input_list_parse
    return nil unless input_list
  end
  return self.input_list_hook(input_list)
end

#input_port_declaration_hook(type, sign, range, name_of_variable) ⇒ Object



1710
1711
1712
# File 'lib/HDLRuby/verilog_parser.rb', line 1710

def input_port_declaration_hook(type, sign, range, name_of_variable)
  return AST[:input_port_declaration, type,sign,range,name_of_variable, self.property_hook ]
end

#input_port_declaration_parseObject



1700
1701
1702
1703
1704
1705
1706
1707
1708
# File 'lib/HDLRuby/verilog_parser.rb', line 1700

def input_port_declaration_parse
  return nil unless self.get_token(INPUT_REX)
  type = self.get_token(INPUTTYPE_REX)
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  name_of_variable = self.name_of_variable_parse
  self.parse_error("identifier expected") unless name_of_variable
  return input_port_declaration_hook(type,sign,range,name_of_variable)
end

#integer_declaration_hook(list_of_register_variables) ⇒ Object



2897
2898
2899
# File 'lib/HDLRuby/verilog_parser.rb', line 2897

def integer_declaration_hook(list_of_register_variables)
  return AST[:integer_declaration, list_of_register_variables, self.property_hook ]
end

#integer_declaration_parseObject



2887
2888
2889
2890
2891
2892
2893
2894
2895
# File 'lib/HDLRuby/verilog_parser.rb', line 2887

def integer_declaration_parse
  # puts "integer_declaration_parse"
  unless self.get_token(INTEGER_REX) then
    return nil
  end
  list_of_register_variables = self.list_of_register_variables_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return integer_declaration_hook(list_of_register_variables)
end

#level_input_list_hook(level_symbols) ⇒ Object



2212
2213
2214
# File 'lib/HDLRuby/verilog_parser.rb', line 2212

def level_input_list_hook(level_symbols)
  return AST[:level_input_list, level_symbols, self.property_hook ]
end

#level_input_list_parseObject



2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
# File 'lib/HDLRuby/verilog_parser.rb', line 2200

def level_input_list_parse
  cur_level_symbol = self._LEVEL_SYMBOL_parse
  return nil unless cur_level_symbol
  level_symbols = [ cur_level_symbol ]
  loop do
    cur_level_symbol = self._LEVEL_SYMBOL_parse
    break unless cur_level_symbol
    level_symbols << cur_level_symbol
  end
  return self.level_input_list_hook(level_symbols)
end

#level_sensitive_path_declaration_hook(conditional_port_expression, input, polarity_operator, tok, output, path_delay_value) ⇒ Object



5559
5560
5561
5562
5563
5564
# File 'lib/HDLRuby/verilog_parser.rb', line 5559

def level_sensitive_path_declaration_hook(
  conditional_port_expression,
  input, polarity_operator, tok, output, path_delay_value)
  return AST[:level_sensitive_path_declaration,
             input, polarity_operator, tok, output, path_delay_value, self.property_hook ]
end

#level_sensitive_path_declaration_parseObject



5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
# File 'lib/HDLRuby/verilog_parser.rb', line 5510

def level_sensitive_path_declaration_parse
  unless self.get_token(IF_REX) then
    return nil
  end
  self.parse_error("opening parenthesis expected") unless self.get_tokeen(OPEN_PAR_REX)
  conditional_port_expression = self.conditional_port_expression_parse
  self.parse_error("conditional port expression expected") unless conditional_port_expression
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  self.parse_error("openning parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  parse_state = self.state
  specify_input_terminal_descriptor = 
    self.specify_input_terminal_descriptor_parse
  self.parse_error("input terminal descriptor expected") unless specify_input_terminal_descriptor
  polarity_operator = self.polarity_operator_parse
  if self.get_token(SEND_ARROW_REX) then
    # This is the right rule, go no
    specify_output_terminal_descriptor = 
      self.specify_output_terminal_descriptor_parse
    self.parse_error("output terminal descriptor expected") unless specify_output_terminal_descriptor
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
    path_delay_value = self.path_delay_value_parse
    self.parse_error("path delay value expected") unless path_delay_value
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.level_sensitive_path_declaration_hook(
      conditional_port_expression,
      specify_input_terminal_descriptor, polarity_operator, tok,
      specify_output_terminal_descriptor, path_delay_value)
  else
    # This is maybe the other rule, rewind.
    self.state = parse_state
    list_of_path_inputs = self.list_of_path_inputs_parse
    self.parse_error("list of path inputs expected") unless list_of_path_inputs
    polarity_operator = self.polarity_operator_parse
    self.parse_error("'*>' expected") unless self.get_token(ASTERISK_ARROW_REX)
    list_of_path_outputs = self.list_of_path_outputs_parse
    self.parse_error("list of path outputs expected") unless list_of_path_outputs
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("equal expected") unless self.get_token(EQUAL_TOK_REX)
    path_delay_value = self.path_delay_value_parse
    self.parse_error("path delay value expected") unless path_delay_value
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.level_sensitive_path_declaration_hook(
      conditional_port_expression,
      list_of_path_inputs, polarity_operator, tok,
      list_of_path_outputs, path_delay_value)
  end
end

#list_of_assignments_hook(assignments) ⇒ Object



3309
3310
3311
# File 'lib/HDLRuby/verilog_parser.rb', line 3309

def list_of_assignments_hook(assignments)
  return AST[:list_of_assigments, assignments, self.property_hook ]
end

#list_of_assignments_parseObject



3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
# File 'lib/HDLRuby/verilog_parser.rb', line 3294

def list_of_assignments_parse
  cur_assignment = self.assignment_parse
  self.parse_error("assignment expected") unless cur_assignment
  assignments = [ cur_assignment ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_assignment = self.assignment_parse
    self.parse_error("assignment expected") unless cur_assignment
    assignments << cur_assignment
  end
  return list_of_assignments_hook(assignments)
end

#list_of_module_connections_hook(connections) ⇒ Object



3772
3773
3774
# File 'lib/HDLRuby/verilog_parser.rb', line 3772

def list_of_module_connections_hook(connections)
  return AST[:list_of_module_connections, connections, self.property_hook ]
end

#list_of_module_connections_parseObject



3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
# File 'lib/HDLRuby/verilog_parser.rb', line 3743

def list_of_module_connections_parse
  cur_named_port_connection = self.named_port_connection_parse
  if cur_named_port_connection then
    named_port_connections = [ cur_named_port_connection ]
    loop do
      unless self.get_token(COMMA_REX) then
        break
      end
      cur_named_port_connection = self.named_port_connection_parse
      self.parse_error("named port connection expected") unless cur_named_port_connection
      named_port_connections << cur_named_port_connection
    end
    return list_of_module_connections_hook(named_port_connections)
  else
    cur_module_port_connection = self.module_port_connection_parse
    return nil unless cur_module_port_connection
    module_port_connections = [ cur_module_port_connection ]
    loop do
      unless self.get_token(COMMA_REX) then
        break
      end
      cur_module_port_connection = self.module_port_connection_parse
      self.parse_error("module port connection expected") unless cur_module_port_connection
      module_port_connections << cur_module_port_connection
    end
    return list_of_module_connections_hook(module_port_connections)
  end
end

#list_of_param_assignments_hook(param_assignments) ⇒ Object



2568
2569
2570
# File 'lib/HDLRuby/verilog_parser.rb', line 2568

def list_of_param_assignments_hook(param_assignments)
  return AST[:list_of_param_assignments, param_assignments, self.property_hook ]
end

#list_of_param_assignments_parseObject



2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
# File 'lib/HDLRuby/verilog_parser.rb', line 2555

def list_of_param_assignments_parse
  cur_param_assignment = self.param_assignment_parse
  param_assignments = [ cur_param_assignment ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_param_assignment = self.param_assignment_parse
    param_assignments << cur_param_assignment
  end
  return self.list_of_param_assignments_hook(param_assignments)
end

#list_of_path_inputs_hook(specify_input_terminal_descriptors) ⇒ Object



4748
4749
4750
4751
# File 'lib/HDLRuby/verilog_parser.rb', line 4748

def list_of_path_inputs_hook(specify_input_terminal_descriptors)
  return AST[:list_of_path_inputs,
             specify_input_terminal_descriptors, self.property_hook ]
end

#list_of_path_inputs_parseObject



4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
# File 'lib/HDLRuby/verilog_parser.rb', line 4730

def list_of_path_inputs_parse
  cur_specify_input_terminal_descriptor = 
    self.specify_input_terminal_descriptor_parse
  return nil unless cur_specify_input_terminal_descriptor
  specify_input_terminal_descriptors = 
    [ cur_specify_input_terminal_descriptor ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_specify_input_terminal_descriptor = 
      self.specify_input_terminal_descriptor_parse
    self.parse_error("input terminal descriptor expected") unless cur_specify_input_terminal_descriptor
    specify_input_terminal_descriptors << cur_specify_input_terminal_descriptor
  end
  return self.list_of_path_inputs_hook(specify_input_terminal_descriptors)
end

#list_of_path_outputs_hook(specify_output_terminal_descriptors) ⇒ Object



4777
4778
4779
4780
# File 'lib/HDLRuby/verilog_parser.rb', line 4777

def list_of_path_outputs_hook(specify_output_terminal_descriptors)
  return AST[:list_of_path_outputs,
             specify_output_terminal_descriptors, self.property_hook ]
end

#list_of_path_outputs_parseObject



4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
# File 'lib/HDLRuby/verilog_parser.rb', line 4759

def list_of_path_outputs_parse
  cur_specify_output_terminal_descriptor = 
    self.specify_output_terminal_descriptor_parse
  return nil unless cur_specify_output_terminal_descriptor
  specify_output_terminal_descriptors = 
    [ cur_specify_output_terminal_descriptor ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_specify_output_terminal_descriptor = 
      self.specify_output_terminal_descriptor_parse
    self.parse_erro("output terminal descriptor expected") unless cur_specify_output_terminal_descriptor
    specify_output_terminal_descriptors << cur_specify_output_terminal_descriptor
  end
  return self.list_of_path_outputs_hook(specify_output_terminal_descriptors)
end

#list_of_ports_hook(ports) ⇒ Object



1574
1575
1576
# File 'lib/HDLRuby/verilog_parser.rb', line 1574

def list_of_ports_hook(ports)
  return AST[:list_of_ports, ports, self.property_hook ]
end

#list_of_ports_parseObject



1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
# File 'lib/HDLRuby/verilog_parser.rb', line 1551

def list_of_ports_parse
  if self.get_token(OPEN_PAR_REX) then
    cur_port = self.port_parse
    ports = [ cur_port ]
    loop do
      if self.get_token(COMMA_REX) then
        cur_port = self.port_parse
      else
        if self.get_token(CLOSE_PAR_REX) then
          cur_port = nil
        else
          self.parse_error("comma of closing parenthesis expected")
        end
      end
      break unless cur_port
      ports << cur_port
    end
    return list_of_ports_hook(ports)
  else
    return nil
  end
end

#list_of_register_variables_hook(register_variables) ⇒ Object



3063
3064
3065
# File 'lib/HDLRuby/verilog_parser.rb', line 3063

def list_of_register_variables_hook(register_variables)
  return AST[:list_of_register_variables, register_variables, self.property_hook ]
end

#list_of_register_variables_parseObject



3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
# File 'lib/HDLRuby/verilog_parser.rb', line 3050

def list_of_register_variables_parse
  cur_register_variable = self.register_variable_parse
  register_variables = [ cur_register_variable ]
  loop do
    unless self.get_token(COMMA_REX)
      break
    end
    cur_register_variable = self.register_variable_parse
    register_variables << cur_register_variable
  end
  return list_of_register_variables_hook(register_variables)
end

#list_of_variables_hook(name_of_variables) ⇒ Object



3024
3025
3026
# File 'lib/HDLRuby/verilog_parser.rb', line 3024

def list_of_variables_hook(name_of_variables)
  return AST[:list_of_variables, name_of_variables, self.property_hook ]
end

#list_of_variables_parseObject



3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
# File 'lib/HDLRuby/verilog_parser.rb', line 3011

def list_of_variables_parse
  cur_name_of_variable = self.name_of_variable_parse
  name_of_variables = [ cur_name_of_variable ]
  loop do
    unless self.get_token(COMMA_REX)
      break
    end
    cur_name_of_variable = self.name_of_variable_parse
    name_of_variables << cur_name_of_variable
  end
  return list_of_variables_hook(name_of_variables)
end

#logic_and_term_hook(bit_or_terms) ⇒ Object



6136
6137
6138
6139
6140
6141
6142
# File 'lib/HDLRuby/verilog_parser.rb', line 6136

def logic_and_term_hook(bit_or_terms)
  if self.state.compress and bit_or_terms.size == 1 then
    return bit_or_terms[0]
  else
    return AST[:logic_and_term, bit_or_terms, self.property_hook ]
  end
end

#logic_and_term_parseObject



6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
# File 'lib/HDLRuby/verilog_parser.rb', line 6119

def logic_and_term_parse
  # puts "logic_and_term_parse"
  cur_bit_or_term = self.bit_or_term_parse
  return nil unless cur_bit_or_term
  bit_or_terms = [ cur_bit_or_term ]
  tok = nil
  loop do
    tok = self.get_token(OR_OPERATOR_REX)
    break unless tok
    bit_or_terms << tok
    cur_bit_or_term = self.bit_or_term_parse
    self.parse_error("expression expected") unless cur_bit_or_term
    bit_or_terms << cur_bit_or_term
  end
  return logic_and_term_hook(bit_or_terms)
end

#logic_or_term_hook(logic_and_terms) ⇒ Object



6103
6104
6105
6106
6107
6108
6109
# File 'lib/HDLRuby/verilog_parser.rb', line 6103

def logic_or_term_hook(logic_and_terms)
  if self.state.compress and logic_and_terms.size == 1 then
    return logic_and_terms[0]
  else
    return AST[:logic_or_term, logic_and_terms, self.property_hook ]
  end
end

#logic_or_term_parseObject



6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
# File 'lib/HDLRuby/verilog_parser.rb', line 6088

def logic_or_term_parse
  # puts "logic_or_term_parse"
  cur_logic_and_term = self.logic_and_term_parse
  return nil unless cur_logic_and_term
  logic_and_terms = [ cur_logic_and_term ]
  loop do
    break unless self.get_token(AND_AND_REX)
    logic_and_terms << AND_AND_TOK
    cur_logic_and_term = self.logic_and_term_parse
    self.parse_error("expression expected") unless cur_logic_and_term
    logic_and_terms << cur_logic_and_term
  end
  return logic_or_term_hook(logic_and_terms)
end

#long_comment_hook(comment_text) ⇒ Object



6975
6976
6977
# File 'lib/HDLRuby/verilog_parser.rb', line 6975

def long_comment_hook(comment_text)
  return AST[:long_comment, comment_text, self.property_hook ]
end

#long_comment_parseObject



6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
# File 'lib/HDLRuby/verilog_parser.rb', line 6962

def long_comment_parse
  unless self.get_token(SLASH_ASTERISK_REX) then
    return nil
  end
  # comment_text = self.comment_text_parse
  # *Auth*: long and short comment are separated while in the
  # BNF the are the same rule.
  comment_text = self.long_comment_text_parse
  self.parse_error("comment text expected") unless comment_text
  self.parse_error("'*/' expected") unless self.get_token(ASTERISK_SLASH_REX)
  return self.long_comment_hook(comment_text)
end

#long_comment_text_parseObject



7006
7007
7008
7009
7010
# File 'lib/HDLRuby/verilog_parser.rb', line 7006

def long_comment_text_parse
  # *Auth*: long and short comment are separated while in the
  # BNF the are the same rule.
  return comment_text_hook(self.get_token(LONG_COMMENT_TEXT_REX))
end

#lvalue_hook(identifier__concatenation, expression__constant_expression, constant_expression) ⇒ Object



5861
5862
5863
5864
5865
5866
# File 'lib/HDLRuby/verilog_parser.rb', line 5861

def lvalue_hook(identifier__concatenation,
                expression__constant_expression, constant_expression)
  return AST[:lvalue, 
             identifier__concatenation,
             expression__constant_expression,constant_expression, self.property_hook ]
end

#lvalue_parseObject



5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
# File 'lib/HDLRuby/verilog_parser.rb', line 5833

def lvalue_parse
  concatenation = self.concatenation_parse
  if concatenation then
    return self.lvalue_hook(concatenation,nil,nil)
  end
  identifier = self.identifier_parse
  return nil unless identifier
  unless self.get_token(OPEN_BRA_REX) then
    return self.lvalue_hook(identifier,nil,nil)
  end
  parse_state = self.state
  constant_expression0 = self.constant_expression_parse
  if !constant_expression0 or !self.get_token(COLON_REX) then
    # Not constant_expression : constant_expression, rewind.
    self.state = parse_state
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
    return self.lvalue_hook(identifier,expression,nil)
  end
  self.parse_error("constant expression expected") unless constant_expression0
  constant_expression1 = self.constant_expression_parse
  self.parse_error("constant expression expected") unless constant_expression1
  self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
  return self.lvalue_hook(identifier,
                          constant_expression0, constant_expression1)
end

#mintypmax_expression_hook(expression0, expression1, expression2) ⇒ Object



5906
5907
5908
5909
# File 'lib/HDLRuby/verilog_parser.rb', line 5906

def mintypmax_expression_hook(expression0, expression1, expression2)
  return AST[:mintypmax_expression,
             expression0,expression1,expression2, self.property_hook ]
end

#mintypmax_expression_parseObject



5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
# File 'lib/HDLRuby/verilog_parser.rb', line 5891

def mintypmax_expression_parse
  expression0 = self.expression_parse
  return nil unless expression0
  unless self.get_token(COLON_REX) then
    return self.mintypmax_expression_hook(expression0,nil,nil)
  end
  expression1 = self.expression_parse
  self.parse_error("expression expected") unless expression1
  self.parse_error("colon expected") unless self.get_token(COLON_REX)
  expression2 = self.expression_parse
  self.parse_error("expression expected") unless expression2
  return self.mintypmax_expression_hook(expression0,expression1,
                                        expression2)
end

#module_hook(name, pre_parameter_declaration, ports, elems) ⇒ Object

,



1501
1502
1503
1504
1505
# File 'lib/HDLRuby/verilog_parser.rb', line 1501

def module_hook(name, pre_parameter_declaration, ports, elems) #,
                # timescale, celldefine)
  return AST[:module, name,pre_parameter_declaration,ports,elems, self.property_hook ]#,
                      # timescale,celldefine]
end

#module_instance_hook(name_of_instance, list_of_module_connections) ⇒ Object



3714
3715
3716
3717
# File 'lib/HDLRuby/verilog_parser.rb', line 3714

def module_instance_hook(name_of_instance, list_of_module_connections)
  return AST[:module_instance, 
             name_of_instance,list_of_module_connections, self.property_hook ]
end

#module_instance_parseObject



3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
# File 'lib/HDLRuby/verilog_parser.rb', line 3700

def module_instance_parse
  parse_state = self.state
  name_of_instance = self.name_of_instance_parse
  return nil unless name_of_instance
  unless self.get_token(OPEN_PAR_REX) then
    self.state = parse_state
    return nil
  end
  list_of_module_connections = self.list_of_module_connections_parse
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return module_instance_hook(name_of_instance,
                              list_of_module_connections)
end

#module_instantiation_hook(name_of_module, parameter_value_assignment, module_instances) ⇒ Object



3634
3635
3636
3637
3638
3639
3640
# File 'lib/HDLRuby/verilog_parser.rb', line 3634

def module_instantiation_hook(name_of_module,
                              parameter_value_assignment,
                              module_instances)
  return AST[:module_instantiation, 
             name_of_module,parameter_value_assignment,
             module_instances, self.property_hook ]
end

#module_instantiation_parseObject



3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
# File 'lib/HDLRuby/verilog_parser.rb', line 3608

def module_instantiation_parse
  # puts "module_instantiation_parse"
  parse_state = self.state
  name_of_module = self.name_of_module_parse
  return nil unless name_of_module
  parameter_value_assignment = self.parameter_value_assignment_parse
  cur_module_instance = self.module_instance_parse
  unless cur_module_instance then
    self.state = parse_state
    return nil
  end
  module_instances = [ cur_module_instance ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_module_instance = self.module_instance_parse
    self.parse_error("module instance expected") unless cur_module_instance
    module_instances << cur_module_instance
  end
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return module_instantiation_hook(name_of_module,
                                   parameter_value_assignment,
                                   module_instances)
end

#module_item_hook(item) ⇒ Object



1886
1887
1888
1889
1890
1891
1892
# File 'lib/HDLRuby/verilog_parser.rb', line 1886

def module_item_hook(item)
  if self.state.compress then
    return item
  else
    return AST[:module_item, item, self.property_hook ]
  end
end

#module_item_parseObject



1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
# File 'lib/HDLRuby/verilog_parser.rb', line 1842

def module_item_parse
  item = self.parameter_declaration_parse
  return self.module_item_hook(item) if item
  item = self.input_declaration_parse
  return self.module_item_hook(item) if item
  item = self.output_declaration_parse
  return self.module_item_hook(item) if item
  item = self.inout_declaration_parse
  return self.module_item_hook(item) if item
  item = self.net_declaration_parse
  return self.module_item_hook(item) if item
  item = self.reg_declaration_parse
  return self.module_item_hook(item) if item
  item = self.time_declaration_parse
  return self.module_item_hook(item) if item
  item = self.integer_declaration_parse
  return self.module_item_hook(item) if item
  item = self.real_declaration_parse
  return self.module_item_hook(item) if item
  item = self.event_declaration_parse
  return self.module_item_hook(item) if item
  item = self.gate_declaration_parse
  return self.module_item_hook(item) if item
  item = self.module_instantiation_parse
  return self.module_item_hook(item) if item
  item = self.udp_instantiation_parse
  return self.module_item_hook(item) if item
  item = self.parameter_override_parse
  return self.module_item_hook(item) if item
  item = self.continuous_assignment_parse
  return self.module_item_hook(item) if item
  item = self.specify_block_parse
  return self.module_item_hook(item) if item
  item = self.initial_statement_parse
  return self.module_item_hook(item) if item
  item = self.always_statement_parse
  return self.module_item_hook(item) if item
  item = self.task_parse
  return self.module_item_hook(item) if item
  item = self.function_parse
  return self.module_item_hook(item) if item
  return nil
end

#module_name?(name) ⇒ Boolean

Tells if a name is a known module name.

Returns:

  • (Boolean)


619
620
621
# File 'lib/HDLRuby/verilog_parser.rb', line 619

def module_name?(name)
  return @module_names.include?(name)
end

#module_parseObject



1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
# File 'lib/HDLRuby/verilog_parser.rb', line 1470

def module_parse
  if self.get_token(MODULE_MACROMODULE_REX) then
    # # Before parsing the module, get the timescale and celldefine 
    # # properties from current position.
    # timescale = @state.lprop[@state.lpos][:timescale]
    # timescale = nil if timescale == ""
    # celldefine = @state.lprop[@state.lpos][:celldefine]
    # celldefine = nil if celldefine == ""
    # No parse
    name = self.name_of_module_parse
    pre_parameter_declaration = self.pre_parameter_declaration_parse
    ports = self.list_of_ports_parse
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    elems = []
    cur_elem = nil
    loop do
      cur_elem = self.module_item_parse
      break unless cur_elem
      elems << cur_elem
    end
    self.parse_error("'endmodule' expected") unless self.get_token(ENDMODULE_REX)
    # Add a know module name.
    self.add_module_name(name)
    # And return the AST.
    return module_hook(name,pre_parameter_declaration,ports,elems) #,
                       # timescale,celldefine)
  else
    return nil
  end
end

#module_port_connection_hook(expression) ⇒ Object



3792
3793
3794
# File 'lib/HDLRuby/verilog_parser.rb', line 3792

def module_port_connection_hook(expression)
  return AST[:module_port_connection, expression, self.property_hook ]
end

#module_port_connection_parseObject



3783
3784
3785
3786
3787
3788
3789
3790
# File 'lib/HDLRuby/verilog_parser.rb', line 3783

def module_port_connection_parse
  expression = self.expression_parse
  if expression then
    return module_port_connection_hook(expression)
  else
    return module_port_connection_hook(_NULL_hook)
  end
end

#mul_term_hook(unary_terms) ⇒ Object



6400
6401
6402
6403
6404
6405
6406
# File 'lib/HDLRuby/verilog_parser.rb', line 6400

def mul_term_hook(unary_terms)
  if self.state.compress and unary_terms.size == 1 then
    return unary_terms[0]
  else
    return AST[:mul_term, unary_terms, self.property_hook ]
  end
end

#mul_term_parseObject



6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
# File 'lib/HDLRuby/verilog_parser.rb', line 6385

def mul_term_parse
  # puts "mul_term_parse"
  parse_state = self.state
  tok = self.get_token(UNARY_OPERATOR_REX)
  if tok then
    primary = self.primary_parse
    self.parse_error("expression expected") unless primary
    return mul_term_hook([tok,primary])
  else
    primary = self.primary_parse
    return nil unless primary
    return mul_term_hook([primary])
  end
end

#multiple_concatenation_hook(expression, expressions) ⇒ Object



6796
6797
6798
# File 'lib/HDLRuby/verilog_parser.rb', line 6796

def multiple_concatenation_hook(expression, expressions)
  return AST[:multiple_concatenation, expression,expressions, self.property_hook ]
end

#multiple_concatenation_parseObject



6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
# File 'lib/HDLRuby/verilog_parser.rb', line 6767

def multiple_concatenation_parse
  parse_state = self.state
  unless self.get_token(OPEN_CUR_REX) then
    return nil
  end
  expression = self.expression_parse
  self.parse_error("expression expected") unless expression
  unless self.get_token(OPEN_CUR_REX) then
    # It is not a multiple concatenation, maybe it is a simple one.
    # Rewind and cancel.
    self.state = parse_state
    return nil
  end
  cur_expression = self.expression_parse
  self.parse_error("expression expected") unless cur_expression
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << expression
  end
  self.parse_error("closing curly bracket expected") unless self.get_token(CLOSE_CUR_REX)
  self.parse_error("closing curly bracket expected") unless self.get_token(CLOSE_CUR_REX)
  return self.multiple_concatenation_hook(expression,expressions)
end

#name_of_block_hook(identifier) ⇒ Object



4336
4337
4338
# File 'lib/HDLRuby/verilog_parser.rb', line 4336

def name_of_block_hook(identifier)
  return AST[:name_of_block, identifier, self.property_hook ]
end

#name_of_block_parseObject



4330
4331
4332
4333
4334
# File 'lib/HDLRuby/verilog_parser.rb', line 4330

def name_of_block_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return self.name_of_block_hook(identifier)
end

#name_of_event_hook(identifier) ⇒ Object



3159
3160
3161
# File 'lib/HDLRuby/verilog_parser.rb', line 3159

def name_of_event_hook(identifier)
  return AST[:name_of_event, identifier, self.property_hook ]
end

#name_of_event_parseObject



3153
3154
3155
3156
3157
# File 'lib/HDLRuby/verilog_parser.rb', line 3153

def name_of_event_parse
  identifier = self._IDENTIFIER_parse
  return nill unless identifier
  return name_of_event_hook(identifier)
end

#name_of_function_hook(identifier) ⇒ Object



2481
2482
2483
# File 'lib/HDLRuby/verilog_parser.rb', line 2481

def name_of_function_hook(name_of_function)
  return AST[:name_of_function, name_of_function, self.property_hook ]
end

#name_of_function_parseObject



2475
2476
2477
2478
2479
# File 'lib/HDLRuby/verilog_parser.rb', line 2475

def name_of_function_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return self.name_of_function_hook(identifier)
end

#name_of_gate_instance_hook(identifier, range) ⇒ Object



3468
3469
3470
# File 'lib/HDLRuby/verilog_parser.rb', line 3468

def name_of_gate_instance_hook(identifier, range)
  return AST[:name_of_gate_instance, identifier,range, self.property_hook ]
end

#name_of_gate_instance_parseObject



3461
3462
3463
3464
3465
3466
# File 'lib/HDLRuby/verilog_parser.rb', line 3461

def name_of_gate_instance_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  range = self.range_parse
  return name_of_gate_instance_hook(identifier,range)
end

#name_of_instance_hook(identifier, range) ⇒ Object



3732
3733
3734
# File 'lib/HDLRuby/verilog_parser.rb', line 3732

def name_of_instance_hook(identifier, range)
  return AST[:name_of_instance, identifier,range, self.property_hook ]
end

#name_of_instance_parseObject



3725
3726
3727
3728
3729
3730
# File 'lib/HDLRuby/verilog_parser.rb', line 3725

def name_of_instance_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  range = self.range_parse
  return name_of_instance_hook(identifier,range)
end

#name_of_memory_hook(identifier) ⇒ Object



3143
3144
3145
# File 'lib/HDLRuby/verilog_parser.rb', line 3143

def name_of_memory_hook(identifier)
  return AST[:name_of_memory, identifier, self.property_hook ]
end

#name_of_memory_parseObject



3137
3138
3139
3140
3141
# File 'lib/HDLRuby/verilog_parser.rb', line 3137

def name_of_memory_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return name_of_memory_hook(identifier)
end

#name_of_module_hook(identifier) ⇒ Object



1541
1542
1543
# File 'lib/HDLRuby/verilog_parser.rb', line 1541

def name_of_module_hook(name)
  return AST[:name_of_module, name, self.property_hook ]
end

#name_of_module_parseObject



1535
1536
1537
1538
1539
# File 'lib/HDLRuby/verilog_parser.rb', line 1535

def name_of_module_parse
  name = self._IDENTIFIER_parse
  self.parse_error("module name identifier expected") if !name
  return self.name_of_module_hook(name)
end

#name_of_port_hook(name) ⇒ Object



1797
1798
1799
# File 'lib/HDLRuby/verilog_parser.rb', line 1797

def name_of_port_hook(name)
  return AST[:name_of_port, name, self.property_hook ]
end

#name_of_port_parseObject



1791
1792
1793
1794
1795
# File 'lib/HDLRuby/verilog_parser.rb', line 1791

def name_of_port_parse
  name = self._IDENTIFIER_parse
  self.parse_error("port name identifier expected") if !name
  return self.name_of_port_hook(name)
end

#name_of_register_hook(identifier) ⇒ Object



3127
3128
3129
# File 'lib/HDLRuby/verilog_parser.rb', line 3127

def name_of_register_hook(identifier)
  return AST[:name_of_register, identifier, self.property_hook ]
end

#name_of_register_parseObject



3121
3122
3123
3124
3125
# File 'lib/HDLRuby/verilog_parser.rb', line 3121

def name_of_register_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return name_of_register_hook(identifier)
end

#name_of_system_function_hook(identifier) ⇒ Object



6890
6891
6892
# File 'lib/HDLRuby/verilog_parser.rb', line 6890

def name_of_system_function_hook(identifier)
  return AST[:name_of_system_function, identifier, self.property_hook ]
end

#name_of_system_function_parseObject



6881
6882
6883
6884
6885
6886
6887
6888
# File 'lib/HDLRuby/verilog_parser.rb', line 6881

def name_of_system_function_parse
  # *Auth*: the $ is integrated into the system_identifier!!
  tok = self.get_token(SYSTEM_IDENTIFIER_REX)
  if tok then
    return self.name_of_system_function_hook(tok)
  end
  return nil
end

#name_of_system_task_hook(identifier) ⇒ Object



4497
4498
4499
# File 'lib/HDLRuby/verilog_parser.rb', line 4497

def name_of_system_task_hook(identifier)
  return AST[:name_of_system_task, identifier, self.property_hook ]
end

#name_of_system_task_parseObject



4490
4491
4492
4493
4494
4495
# File 'lib/HDLRuby/verilog_parser.rb', line 4490

def name_of_system_task_parse
  # *Auth*: the $ is integrated into the system_identifier!!
  identifier = self.system_identifier_parse
  return nil unless identifier
  return self.name_of_system_task_hook(identifier)
end

#name_of_task_hook(name_of_task) ⇒ Object



2401
2402
2403
# File 'lib/HDLRuby/verilog_parser.rb', line 2401

def name_of_task_hook(name_of_task)
  return AST[:name_of_task, name_of_task, self.property_hook ]
end

#name_of_task_parseObject



2395
2396
2397
2398
2399
# File 'lib/HDLRuby/verilog_parser.rb', line 2395

def name_of_task_parse
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return self.name_of_task_hook(identifier)
end

#name_of_udp_hook(identifier) ⇒ Object



1967
1968
1969
# File 'lib/HDLRuby/verilog_parser.rb', line 1967

def name_of_udp_hook(name)
  return AST[:name_of_UDP, name, self.property_hook ]
end

#name_of_udp_instance_hook(identifier, range) ⇒ Object



3573
3574
3575
# File 'lib/HDLRuby/verilog_parser.rb', line 3573

def name_of_udp_instance_hook(identifier,range)
  return AST[:name_of_UDP_instance, identifier,range, self.property_hook ]
end

#name_of_udp_instance_parseObject



3566
3567
3568
3569
3570
3571
# File 'lib/HDLRuby/verilog_parser.rb', line 3566

def name_of_udp_instance_parse
  identifier = self.identifier_parse
  return nil unless identifier
  range = self.range_parse
  return name_of_udp_instance_hook(identifier,range)
end

#name_of_udp_parseObject



1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
# File 'lib/HDLRuby/verilog_parser.rb', line 1955

def name_of_udp_parse
  name = self._IDENTIFIER_parse
  # self.parse_error("name of UDP identifier expected") if !name
  return nil unless name
  if self.module_name?(identifier) then
    # This is a module name, not an UDP one.
    self.state = parse_state
    return nil
  end
  return name_of_udp_hook(name)
end

#name_of_variable_hook(identifier) ⇒ Object



1813
1814
1815
# File 'lib/HDLRuby/verilog_parser.rb', line 1813

def name_of_variable_hook(name)
  return AST[:name_of_variable, name, self.property_hook ]
end

#name_of_variable_parseObject



1807
1808
1809
1810
1811
# File 'lib/HDLRuby/verilog_parser.rb', line 1807

def name_of_variable_parse
  name = self._IDENTIFIER_parse
  self.parse_error("variable name identifier expected") if !name
  return self.name_of_variable_hook(name)
end

#named_port_connection_hook(identifier, expression) ⇒ Object



3827
3828
3829
# File 'lib/HDLRuby/verilog_parser.rb', line 3827

def named_port_connection_hook(identifier, expression)
  return AST[:named_port_connection, identifier,expression, self.property_hook ]
end

#named_port_connection_parseObject



3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
# File 'lib/HDLRuby/verilog_parser.rb', line 3814

def named_port_connection_parse
  unless self.get_token(DOT_REX) then
    return nil
  end
  identifier = self._IDENTIFIER_parse
  self.parse_error("identifier expected") unless identifier
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  expression = self.expression_parse
  self.parse_error("expression expected") unless expression
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return named_port_connection_hook(identifier,expression)
end

#net_declaration_hook(nettype_or_charge_strength, sign, expandrange, delay, list_of_variables_or_list_of_assignments) ⇒ Object



2742
2743
2744
2745
2746
2747
2748
# File 'lib/HDLRuby/verilog_parser.rb', line 2742

def net_declaration_hook(nettype_or_charge_strength, 
                         sign, expandrange, delay,
                         list_of_variables_or_list_of_assignments)
  return AST[:net_declaration, 
             nettype_or_charge_strength,sign,expandrange,delay,
             list_of_variables_or_list_of_assignments, self.property_hook ]
end

#net_declaration_parseObject



2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
# File 'lib/HDLRuby/verilog_parser.rb', line 2705

def net_declaration_parse
  # puts "net_declaration_parse"
  nettype = self._NETTYPE_parse
  if nettype then
    drive_strength = self.drive_strength_parse
    if !drive_strength then
      sign = self.get_token(SIGNED_REX)
      expandrange = self.expandrange_parse
      delay = self.delay_parse
      list_of_variables = self.list_of_variables_parse
      self.parse_error("semicolon expected HERE #1") unless self.get_token(SEMICOLON_REX)
      return net_declaration_hook(nettype,sign,expandrange,delay,
                                  list_of_variables)
    else
      sign = self.get_token(SIGNED_REX)
      expandrange = self.expandrange_parse
      delay = self.delay_parse
      list_of_assignments = self.list_of_assignments_parse
      self.parse_error("semicolon expected HERE #2") unless self.get_token(SEMICOLON_REX)
      return net_declaration_hook(nettype,sign,expandrange,delay,
                                  list_of_assignments)
    end
  else
    unless self.get_token(TRIREG_REX) then
      return nil
    end
    charge_strength = self.charge_strength_parse
    sign = self.get_token(SIGNED_REX)
    expandrange = self.expandrange_parse
    delay = self.delay_parse
    list_of_variables = self.list_of_variables_parse
    self.parse_error("semicolon expected HERE #3") unless self.get_token(SEMICOLON_REX)
    return net_declaration_hook(charge_strength,sign,expandrange,delay,
                                list_of_variables)
  end
end

#next_state_hook(symbol) ⇒ Object



2304
2305
2306
# File 'lib/HDLRuby/verilog_parser.rb', line 2304

def next_state_hook(symbol)
  return AST[:next_state, symbol, self.property_hook ]
end

#next_state_parseObject



2295
2296
2297
2298
2299
2300
2301
2302
# File 'lib/HDLRuby/verilog_parser.rb', line 2295

def next_state_parse
  if self.get_token(HYPHEN_REX) then
    return next_state_hook(HYPHEN_TOK)
  else
    output_symbol = self._OUTPUT_SYMBOL_parse
    return self.next_state_hook(output_symbol)
  end
end

#non_blocking_assignment_hook(lvalue, delay_or_event_control, expression) ⇒ Object



4139
4140
4141
4142
4143
# File 'lib/HDLRuby/verilog_parser.rb', line 4139

def non_blocking_assignment_hook(lvalue, delay_or_event_control,
                             expression)
  return AST[:non_blocking_assignment,
             lvalue,delay_or_event_control,expression, self.property_hook ]
end

#non_blocking_assignment_parseObject



4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
# File 'lib/HDLRuby/verilog_parser.rb', line 4120

def non_blocking_assignment_parse
  parse_state = self.state
  lvalue = self.lvalue_parse
  return nil unless lvalue
  unless self.get_token(ASSIGN_ARROW_REX) then
    self.state = parse_state
    return nil
  end
  delay_or_event_control = self.delay_or_event_control_parse
  expression = self.expression_parse
  unless expression then
    self.state = parse_state
    return nil
  end
  return self.non_blocking_assignment_hook(lvalue,
                                           delay_or_event_control,
                                           expression)
end

#notify_register_hook(identifier) ⇒ Object



5493
5494
5495
# File 'lib/HDLRuby/verilog_parser.rb', line 5493

def notify_register_hook(identifier)
  return AST[:notify_register, identifier, self.property_hook ]
end

#notify_register_parseObject



5487
5488
5489
5490
5491
# File 'lib/HDLRuby/verilog_parser.rb', line 5487

def notify_register_parse
  identifier = self.identifier_parse
  return nil unless identifier
  return self.notify_register_hook(identifier)
end

#number_hook(unsigned_number__decimal_number, base__unsigned_number, decimal_number) ⇒ Object



6602
6603
6604
6605
6606
6607
6608
6609
# File 'lib/HDLRuby/verilog_parser.rb', line 6602

def number_hook(unsigned_number__decimal_number,
                base__unsigned_number,
                decimal_number)
  return AST[:number,
             unsigned_number__decimal_number,
             base__unsigned_number,
             decimal_number, self.property_hook ]
end

#number_parseObject



6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
# File 'lib/HDLRuby/verilog_parser.rb', line 6575

def number_parse
  parse_state = self.state
  unsigned_number = self._UNSIGNED_NUMBER_parse
  base = self._BASE_parse
  if base then
    number = self._NUMBER_parse(base[0])
    self.parse_error("number expected") unless number
    return self.number_hook(unsigned_number,base,number)
  end
  # Not a based number, rewind.
  self.state = parse_state
  decimal_number0 = self._DECIMAL_NUMBER_parse
  return nil unless decimal_number0
  if self.get_token(DOT_REX) then
    unsigned_number = self._UNSIGNED_NUMBER_parse
    if self.get_token(E_REX) then
      decimal_number1 = self._DECIMAL_NUMBER_parse
      self.parse_error("decimal number expected") unless decimal_number1
      return self.number_hook(decimal_number0,unsigned_number,
                              decimal_number1)
    end
    self.parse_error("unsigned number expected") unless unsigned_number
    return self.number_hook(decimal_number0,unsigned_number,nil)
  end
  return self.number_hook(decimal_number0,nil,nil)
end

#origin_rule(name) ⇒ Object

Get an origin rule by +name+.



1359
1360
1361
1362
1363
1364
# File 'lib/HDLRuby/verilog_parser.rb', line 1359

def origin_rule(name)
  name = name.to_sym
  res = ORIGIN_RULES[name]
  res = RULES[name] unless res
  return res
end

#output_declaration_hook(type, sign, range, list_of_variables) ⇒ Object



2652
2653
2654
# File 'lib/HDLRuby/verilog_parser.rb', line 2652

def output_declaration_hook(type, sign, range, list_of_variables)
  return AST[:output_declaration, type,sign,range,list_of_variables, self.property_hook ]
end

#output_declaration_parseObject



2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
# File 'lib/HDLRuby/verilog_parser.rb', line 2637

def output_declaration_parse
  # puts "output_declaration_parse"
  unless self.get_token(OUTPUT_REX) then
    return nil
  end
  type = self.get_token(OUTPUTTYPE_REX)
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  list_of_variables = self.list_of_register_variables_parse
  # list_of_variables = self.list_of_output_variables_parse
  # # Auth: semicolon included in list_of_output_variables!
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.output_declaration_hook(type,sign,range,list_of_variables)
end

#output_identifier_hook(identifier) ⇒ Object



4892
4893
4894
# File 'lib/HDLRuby/verilog_parser.rb', line 4892

def output_identifier_hook(identifier)
  return AST[:output_identifier, identifier, self.property_hook ]
end

#output_identifier_parseObject



4885
4886
4887
4888
4889
4890
# File 'lib/HDLRuby/verilog_parser.rb', line 4885

def output_identifier_parse
  # *Auth*: it should be checked that the identifier comes from
  # an output module. Left the the AST processing.
  identifier = self.identifier_parse
  return self.output_identifier_hook(identifier)
end

#output_port_declaration_hook(type, sign, range, name_of_variable) ⇒ Object



1731
1732
1733
# File 'lib/HDLRuby/verilog_parser.rb', line 1731

def output_port_declaration_hook(type, sign, range, name_of_variable)
  return AST[:output_port_declaration, type,sign,range,name_of_variable, self.property_hook ]
end

#output_port_declaration_parseObject



1721
1722
1723
1724
1725
1726
1727
1728
1729
# File 'lib/HDLRuby/verilog_parser.rb', line 1721

def output_port_declaration_parse
  return nil unless self.get_token(OUTPUT_REX)
  type = self.get_token(OUTPUTTYPE_REX)
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  name_of_variable = self.name_of_variable_parse
  self.parse_error("identifier expected") unless name_of_variable
  return output_port_declaration_hook(type,sign,range,name_of_variable)
end

#output_terminal_name_hook(name_of_variable) ⇒ Object



2053
2054
2055
2056
2057
2058
2059
# File 'lib/HDLRuby/verilog_parser.rb', line 2053

def output_terminal_name_hook(name_of_variable)
  if self.state.compress then
    return name_of_variable
  else
    return AST[:output_terminal_name, name_of_variable, self.property_hook]
  end
end

#output_terminal_name_parseObject



2047
2048
2049
2050
2051
# File 'lib/HDLRuby/verilog_parser.rb', line 2047

def output_terminal_name_parse
  name_of_variable = self.name_of_variable_parse
  return nil unless name_of_variable
  return self.output_terminal_name_hook(name_of_variable)
end

#par_block_hook(statements__name_of_block, block_declarations, statements) ⇒ Object



4318
4319
4320
4321
4322
# File 'lib/HDLRuby/verilog_parser.rb', line 4318

def par_block_hook(statements__name_of_block,
                   block_declarations, statements)
  return AST[:name_of_block, statements__name_of_block,
             block_declarations,statements, self.property_hook ]
end

#par_block_parseObject



4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
# File 'lib/HDLRuby/verilog_parser.rb', line 4281

def par_block_parse
  unless self.get_token(FORK_REX) then
    return nil
  end
  if self.get_token(COLON_REX) then
    name_of_block = self.name_of_block_parse
    self.parse_error("block name expected") unless name_of_block
    block_declarations = [ ]
    cur_block_declaration = nil
    loop do
      cur_block_declaration = self.block_declaration_parse
      break unless cur_block_declaration
      block_declarations << cur_block_declaration
    end
    statements = []
    cur_statement = nil
    loop do
      cur_statement = self.statement_parse
      break unless cur_statement
      statements << cur_statement
    end
    self.parse_error("'join' expected") unless self.get_token(JOIN_REX)
    return self.par_block_hook(name_of_block,block_declarations,
                               statements)
  else
    statements = []
    cur_statement = nil
    loop do
      cur_statement = self.statement_parse
      break unless cur_statement
      statements << cur_statement
    end
    self.parse_error("'join' expected") unless self.get_token(JOIN_REX)
    return self.par_block_hook(statements,nil,nil)
  end
end

#param_assignment_hook(identifier, constant_expression) ⇒ Object



2585
2586
2587
# File 'lib/HDLRuby/verilog_parser.rb', line 2585

def param_assignment_hook(identifier, constant_expression)
  return AST[:param_assignment, identifier,constant_expression, self.property_hook ]
end

#param_assignment_parseObject



2578
2579
2580
2581
2582
2583
# File 'lib/HDLRuby/verilog_parser.rb', line 2578

def param_assignment_parse
  identifier = self.identifier_parse
  self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
  constant_expression = self.constant_expression_parse
  return self.param_assignment_hook(identifier,constant_expression)
end

#parameter_declaration_hook(list_of_param_assignments) ⇒ Object



2545
2546
2547
# File 'lib/HDLRuby/verilog_parser.rb', line 2545

def parameter_declaration_hook(list_of_param_assignments)
  return AST[:parameter_declaration, list_of_param_assignments, self.property_hook ]
end

#parameter_declaration_parseObject



2535
2536
2537
2538
2539
2540
2541
2542
2543
# File 'lib/HDLRuby/verilog_parser.rb', line 2535

def parameter_declaration_parse
  # puts "parameter_declaration_parse"
  unless self.get_token(PARAMETER_REX) then
    return nil
  end
  list_of_param_assignments = self.list_of_param_assignments_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.parameter_declaration_hook(list_of_param_assignments)
end

#parameter_override_hook(list_of_param_assignments) ⇒ Object



3001
3002
3003
# File 'lib/HDLRuby/verilog_parser.rb', line 3001

def parameter_override_hook(list_of_param_assignments)
  return AST[:parameter_override, list_of_param_assignments, self.property_hook ]
end

#parameter_override_parseObject



2992
2993
2994
2995
2996
2997
2998
2999
# File 'lib/HDLRuby/verilog_parser.rb', line 2992

def parameter_override_parse
  unless self.get_token(DEFPARAM_REX) then
    return nil
  end
  list_of_param_assignments = self.list_of_param_assignments_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return parameter_override_hook(list_of_param_assignments)
end

#parameter_value_assignment_hook(expressions) ⇒ Object



3690
3691
3692
# File 'lib/HDLRuby/verilog_parser.rb', line 3690

def parameter_value_assignment_hook(expressions)
  return AST[:parameter_value_assignment, expressions, self.property_hook ]
end

#parameter_value_assignment_parseObject



3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
# File 'lib/HDLRuby/verilog_parser.rb', line 3670

def parameter_value_assignment_parse
  unless self.get_token(SHARP_REX) then
    return nil
  end
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  cur_expression = self.expression_parse
  self.parse_error("expression expected") unless cur_expression
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << cur_expression
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return parameter_value_assignment_hook(expressions)
end

#parseObject

Parse the Verilog HDL text. NOTE: does not support compiler directives, they must be preprocessed first using preprocess method.



537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/HDLRuby/verilog_parser.rb', line 537

def parse
  # Initialize the state.
  @state.index = 0
  @state.lpos = 1
  @state.cpos = 1
  # Initialize the list of known module names.
  @module_names = []
  # Initialize the list of known UDP names.
  @udp_names = []
  # Execute the parsing.
  return self.source_text_parse
end

#parse_error(msg, line_txt = nil, lpos = @state.lpos, cpos = @state.cpos, filename = ) ⇒ Object

Generate a parse error with message indicated by +msg+ and possible line text +line_text+, line number +lpos+, column +cpos+ and origin file name +filename+.

Raises:



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/HDLRuby/verilog_parser.rb', line 636

def parse_error(msg, line_txt=nil, lpos=@state.lpos, cpos=@state.cpos,
                filename=@state.lprop[lpos][:filename])
  # Maybe it was the main file.
  filename = @state.filename unless filename
  # Get the line where the error was.
  # First locate the position of the begining and the end of the line.
  # puts "lpos=#{lpos} line_txt=#{line_txt.class}"
  unless line_txt then
    blpos = @state.index-@state.cpos
    elpos = @state.index + 
      @state.text.match(/[^\n]*/,@state.index).to_s.size
    # Address the case of invalid end of line (e.g., semicolon missing)
    if elpos == blpos then
      count = 1
      while(@state.text[@state.index-count] =~ /[^\n]/) do
        count += 1
      end
      cpos = count-1
      blpos = elpos-count+1
    end
    # The get the line.
    line_txt = @state.text[blpos...elpos]
  end
  # Raise an exception containing an error message made of msg,
  # the adjusted line number, its number, and the column where error
  # happended.
  raise ParseError.new(msg,line_txt,@state.lprop[lpos][:lpos],cpos,
                      filename)
end

#path_declaration_hook(path_description, path_delay_value) ⇒ Object



4676
4677
4678
# File 'lib/HDLRuby/verilog_parser.rb', line 4676

def path_declaration_hook(path_description, path_delay_value)
  return AST[:path_declaration, path_description,path_delay_value, self.property_hook ]
end

#path_declaration_parseObject



4666
4667
4668
4669
4670
4671
4672
4673
4674
# File 'lib/HDLRuby/verilog_parser.rb', line 4666

def path_declaration_parse
  path_description = self.path_description_parse
  return nil unless path_description
  self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
  path_delay_value = self.path_delay_value_parse
  self.parse_error("path delay value expected") unless path_delay_value
  self.parse_error("semicolon expected") unless self.get_toekn == SEMICOLON_TOK
  return self.path_declaration_hook(path_description,path_delay_value)
end

#path_delay_expression_hook(mintypmax_expression) ⇒ Object



4984
4985
4986
4987
4988
4989
4990
# File 'lib/HDLRuby/verilog_parser.rb', line 4984

def path_delay_expression_hook(mintypmax_expression)
  if self.state.compress then
    return mintypmax_expression
  else
    return AST[:path_delay_expression, mintypmax_expression, self.property_hook ]
  end
end

#path_delay_expression_parseObject



4978
4979
4980
4981
4982
# File 'lib/HDLRuby/verilog_parser.rb', line 4978

def path_delay_expression_parse
  mintypmax_expression = self.mintypmax_expression_parse
  return nil unless mintypmax_expression
  return path_delay_expression_hook(mintypmax_expression)
end

#path_delay_value_hook(path_delay_expression0, path_delay_expression1, path_delay_expression2, path_delay_expression3, path_delay_expression4, path_delay_expression5, path_delay_expression6, path_delay_expression7, path_delay_expression8, path_delay_expression9, path_delay_expression10, path_delay_expression11) ⇒ Object



4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
# File 'lib/HDLRuby/verilog_parser.rb', line 4945

def path_delay_value_hook(path_delay_expression0,
                          path_delay_expression1,
                          path_delay_expression2,
                          path_delay_expression3,
                          path_delay_expression4,
                          path_delay_expression5,
                          path_delay_expression6,
                          path_delay_expression7,
                          path_delay_expression8,
                          path_delay_expression9,
                          path_delay_expression10,
                          path_delay_expression11)
  return AST[:path_delay_value, 
             path_delay_expression0,
             path_delay_expression1,
             path_delay_expression2,
             path_delay_expression3,
             path_delay_expression4,
             path_delay_expression5,
             path_delay_expression6,
             path_delay_expression7,
             path_delay_expression8,
             path_delay_expression9,
             path_delay_expression10,
             path_delay_expression11, self.property_hook ]
end

#path_delay_value_parseObject



4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
# File 'lib/HDLRuby/verilog_parser.rb', line 4914

def path_delay_value_parse
  parse_state = self.state
  if self.get_token(OPEN_PAR_REX) then
    cur_path_delay_expression = self.path_delay_expression_parse
    unless cur_path_delay_expression then
      self.state = parse_state
      return nil
    end
    path_delay_expressions = [ cur_path_delay_expression ]
    tok = nil
    11.times do
      break unless self.get_token(COMMA_REX)
      cur_path_delay_expression = self.path_delay_expression_parse
      self.parse_error("path delay expression expected") unless cur_path_delay_expression
      path_delay_expressions << cur_path_delay_expression
    end
    self.parse_error("closing parenthesis expected") unless tok == CLOSE_PAR_TOK
    # Ensure there are 12 elements in the path_delay_expressions
    if path_delay_expressions.size < 12 then
      path_delay_expressions[11] = nil
    end
    return self.path_delay_value_hook(*path_delay_expressions)
  else
    path_delay_expression = self.path_delay_expression_parse
    return nil unless path_delay_expression
    return self.path_delay_value_hook(path_delay_expression,
                                     nil,nil,nil,nil,nil,nil,
                                     nil,nil,nil,nil,nil)
  end
end

#path_description_hook(type, input, output) ⇒ Object



4720
4721
4722
# File 'lib/HDLRuby/verilog_parser.rb', line 4720

def path_description_hook(type, input, output)
  return AST[:path_description, type,input,output, self.property_hook ]
end

#path_description_parseObject



4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
# File 'lib/HDLRuby/verilog_parser.rb', line 4687

def path_description_parse
  parse_state = self.state
  unless self.get_token(OPEN_PAR_REX) then
    self.state = parse_state
    return nil
  end
  specify_input_terminal_descriptor =
    self.specify_input_terminal_descriptor_parse
  if self.get_token(SEND_ARROW_REX) and 
      specify_input_terminal_descriptor then
    specify_output_terminal_descriptor =
      self.specify_output_terminal_descriptor_parse
    self.parse_error("output terminal descriptor expected") unless specify_output_terminal_descriptor
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return self.path_description_hook(SEND_ARROW_TOK,
                                 specify_input_terminal_descriptor,
                                 specify_output_terminal_descriptor)
  end
  list_of_path_inputs = self.list_of_path_inputs_parse
  unless list_of_path_inputs then
    self.state = parse_state
    return nil
  end
  unless self.get_token(ASTERISK_ARROW_REX) then
    self.state = parse_state
  end
  list_of_path_outputs = self.list_of_path_outputs_parse
  self.parse_error("list of path outputs expected") unless list_of_path_outputs
  return self.path_description_hook(ASTERIS_ARROW_TOK,
                                    list_of_path_inputs,
                                    list_of_path_outputs)
end

#peek_token(rex) ⇒ Object

Check the token matching regexp +rex+ from current position. Returns the match in case of success and nil otherwise but do not change the state of the parser.



566
567
568
# File 'lib/HDLRuby/verilog_parser.rb', line 566

def peek_token(rex)
  return @state.text.match(rex,@state.index)
end

#polarity_operator_hook(tok) ⇒ Object



5623
5624
5625
# File 'lib/HDLRuby/verilog_parser.rb', line 5623

def polarity_operator_hook(tok)
  return AST[:polarity_operator, tok, self.property_hook ]
end

#polarity_operator_parseObject



5614
5615
5616
5617
5618
5619
5620
5621
# File 'lib/HDLRuby/verilog_parser.rb', line 5614

def polarity_operator_parse
  tok = self.get_token(POLARITY_OPERATOR_REX)
  if tok then
    return polarity_operator_hook(tok)
  else
    return nil
  end
end

#port_expression_hook(port_declaration__port_refs) ⇒ Object



1688
1689
1690
# File 'lib/HDLRuby/verilog_parser.rb', line 1688

def port_expression_hook(port_declaration__port_refs)
  return AST[:port_expression, port_declaration__port_refs, self.property_hook ]
end

#port_expression_parseObject



1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
# File 'lib/HDLRuby/verilog_parser.rb', line 1642

def port_expression_parse
  input_port_declaration = self.input_port_declaration_parse
  if input_port_declaration then
    return port_expression_hook(input_port_declaration)
  end
  output_port_declaration = self.output_port_declaration_parse
  if output_port_declaration then
    return port_expression_hook(output_port_declaration)
  end
  inout_port_declaration = self.inout_port_declaration_parse
  if inout_port_declaration then
    return port_expression_hook(inout_port_declaration)
  end

  parse_state = self.state
  port_refs = [ ]
  cur_port_ref = self.port_reference_parse
  if cur_port_ref then
    port_refs << cur_port_ref
  else
    unless self.get_token(OPEN_CUR_REX) then
      self.state = parse_state
      return nil
    end
    port_refs << cur_port_ref
    cur_port_ref = self.port_reference_parse
    if !cur_port_ref then
      self.state = parse_state
      return nil
    end
    loop do
      if self.get_token(COMMMA_REX) then
        cur_port_ref = self.port_reference_parse
      end
      if self.get_token(CLOSE_CUR_REX) then
        cur_port_ref = nil
      else
        self.parse_error("comma or closing parenthesis expected")
      end
      break unless cur_port_ref
      port_refs << cur_port_ref
    end
  end
  return self.port_expression_hook(port_refs)
end

#port_hook(port_expression__name_of_port, port_expression) ⇒ Object



1602
1603
1604
# File 'lib/HDLRuby/verilog_parser.rb', line 1602

def port_hook(port_expression__name_of_port, port_expression)
  return AST[:port, port_expression__name_of_port,port_expression, self.property_hook ]
end

#port_parseObject



1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
# File 'lib/HDLRuby/verilog_parser.rb', line 1585

def port_parse
  port_expression = self.port_expression_parse
  if port_expression then
    return self.port_hook(port_expression,nil)
  end
  unless self.get_token(DOT_REX) then
    return nil
  end
  name_of_port = self.name_of_port_parse
  self.parse_error("name of port expected") unless name_of_port
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  port_expression = self.port_expression_parse
  self.parse_error("port expression expected") unless port_expression
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return self.port_hook(name_of_port,port_expression)
end

#port_reference_hook(name, const0, const1) ⇒ Object



1781
1782
1783
# File 'lib/HDLRuby/verilog_parser.rb', line 1781

def port_reference_hook(name,const0,const1)
  return AST[:port_reference, name,const0,const1, self.property_hook ]
end

#port_reference_parseObject



1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
# File 'lib/HDLRuby/verilog_parser.rb', line 1766

def port_reference_parse
  name = self.name_of_variable_parse
  const0, const1 = nil, nil
  if self.get_token(OPEN_BRA_REX) then
    const0 = self.constant_expression_parse
    self.parse_error("constant expression expected") unless const0
    if self.get_token(COLON_REX) then
      const1 = self.constant_expression_parse
      self.parse_error("constant expression expected") unless const1
    end
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
  end
  return self.port_reference_hook(name,const0,const1)
end

#pre_parameter_declaration_hook(list_of_param_assignments) ⇒ Object



1524
1525
1526
# File 'lib/HDLRuby/verilog_parser.rb', line 1524

def pre_parameter_declaration_hook(list_of_param_assignments)
  return AST[:pre_parameter_declaration, list_of_param_assignments, self.property_hook ]
end

#pre_parameter_declaration_parseObject



1514
1515
1516
1517
1518
1519
1520
1521
1522
# File 'lib/HDLRuby/verilog_parser.rb', line 1514

def pre_parameter_declaration_parse
  return nil unless self.get_token(SHARP_REX)
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  self.parse_error("parameter expected") unless self.get_token(PARAMETER_REX)
  list_of_param_assignments = self.list_of_param_assignments_parse
  self.parse_error("parameter assignment expected") unless list_of_param_assignments
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return pre_parameter_declaration_hook(list_of_param_assignments)
end

#preprocessObject

Preprocess the Verilog HDL text with directives.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/HDLRuby/verilog_parser.rb', line 213

def preprocess
  # Initialize the preprocessing variables.
  macro_cons = {}    # The set of macro constants.
  macro_func = {}    # The set of macro functions.
  lpos = 1           # Current line number in text.
  cur_timescale = "" # The Current time scale
  # The initial text becomes the text to preprocesses whereas
  # the text to parse is cleared.
  pre_text = @state.text
  @state.text = ""
  # Initialize the line jump (1 if no line merge).
  ljump = 1
  # Initialize the lines properties.
  # @state.lprop = [ { lpos: 0, timescale: "", celldefine: "" }]
  @state.lprop = [ { lpos: 0 }]
  # Initialize the line skip mode for handling the `ifdef and `ifndef
  # directives.
  skip_mode = [ [:start, false] ]
  # Preprocessing is grammatically straight foward, so use
  # a StringScanner.
  scanner = StringScanner.new(pre_text)
  while(!scanner.eos?) do
    # Set the default propery of the line if none.
    if !@state.lprop[lpos] then
      @state.lprop[lpos] = @state.lprop[lpos-1].clone
      # But not the freeze state.
      @state.lprop[lpos].delete(:lfreeze)
      @state.lprop[lpos][:lpos] = @state.lprop[lpos-1][:lpos] + 1
    else
      # Still need to update the timescale and celldefine properties.
      @state.lprop[lpos][:timescale] = @state.lprop[lpos-1][:timescale]
      @state.lprop[lpos][:celldefine] = @state.lprop[lpos-1][:celldefine]
    end
    # Set the default filename if none.
    unless @state.lprop[lpos][:filename] then
      @state.lprop[lpos][:filename] = @state.filename
    end
    # puts "lpos=#{lpos} @state.lprop[lpos]=#{@state.lprop[lpos]}"
    # Is it a directive line?
    begin
      line = scanner.scan(/[ \t]*`[^\n]*\n/)
    rescue => error
      # Problem in the text, so fix it first.
      estr = scanner.string.scrub("\uFFFD")
      # And locate the error.
      elpos = 1
      ecpos = nil
      eline = nil
      estr.lines do |line|
        elpos = elpos + 1
        unless @state.lprop[elpos] then
          if elpos > 1 then
            @state.lprop[elpos] = @state.lprop[elpos-1]
          else
            @state.lprop[elpos] = { :lpos => 1, 
                                    :filename => @state.filename }
          end
          @state.lprop[elpos][:lpos] += 1
        end
        eline = line
        ecpos = line.index("\uFFFD")
        break if ecpos
      end
      if ecpos then
        # It was an invalid, non-UTF8, character.
        self.parse_error("non UTF-8 character",
                         eline.chomp,elpos,ecpos)
      else
        # It was another kind of error.
        self.file_error(error,@state.lprop[lpos][:lpos])
      end
    end
    if line then
      # Yes, process it.
      # But, first, are there any line merge?
      line,jump = self.process_merge_line(line,scanner,lpos)
      # Get the kind of macro and its arguments.
      type,code = line.scan(/^\s*`[a-zA-Z]+|[^`]*$/)
      type.gsub!(/\s/,"")
      # Add the skip mode: X at the end if skipped.
      type += "X" if skip_mode[-1][1]
      # Depending of the kind of macro.
      case type
      when "`timescaleX" # Skip
      when "`timescale"
        # Process and check to code.
        code = code.gsub(/\s/,"")
        mcode = code.match(/^([0-9]+)(s|ms|us|ns|ps|fs)\/([0-9]+)(s|ms|us|ns|ps|fs)/)
        # Compute the position of the code, used in case of error.
        cpos = line.scan(/\s*`timescale\s*/)[0].size
        unless mcode then
          self.parse_error("invalid timescale format",
                           line.chomp,lpos,cpos)
        end
        unit = mcode.captures[0].to_i * FS_TIME[mcode.captures[1]]
        prec = mcode.captures[2].to_i * FS_TIME[mcode.captures[3]]
        unless unit > prec then
          self.parse_error(
            "in timescale, unit shoud be greater than precision",
                           line.chomp,lpos,cpos)
        end
        # puts "unit=#{unit} precision=#{prec}"
        # @state.lprop[lpos][:timescale] = AST[:timescale, unit, prec ]
        @state.lprop[lpos][:timescale] = [ unit, prec ]
      when "`celldefineX" # Skip
      when "`celldefine"
        # @state.lprop[lpos][:celldefine] = AST[:celldefine]
        @state.lprop[lpos][:celldefine] = true
      when "`endcelldefineX" # Skip
      when "`endcelldefine"
        @state.lprop[lpos][:celldefine] = false
      when "`defineX" # Skip
      when "`define"
        # Get the macro name, arguments and replacement.
        name,args,replace = 
          code.scan(/^\s*[_a-zA-Z][_a-zA-Z0-9]*|\(.*\)|.*$/)
        # Process the name.
        unless name =~ /^\s*[_a-zA-Z][_a-zA-Z0-9]*/ then
          cpos = line.scan(/\s*`define\s*/)[0].size
          self.parse_error("invalid macro name",line.chomp,lpos,cpos)
        end
        name.gsub!(/\s/,"")
        # Process the arguments if any.
        if args[0] == "(" then
          # There are indeed arguments, it is a macro function.
          args = args.split(/[\(\),]/).reject { |arg| arg.empty? }
          # Process the arguments.
          cpos = line.index("(")
          args.map! do |arg|
            cpos += 1
            unless arg =~ /^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*$/ then
              self.parse_error("invalid macro argument",
                               line.chomp,lpos,cpos)
            end
            cpos += arg.size
            /#{arg.gsub(/\s/,"")}(?=[^_a-zA-Z0-9])/
          end
          # Add the macro function.
          macro_func[name] = [ /`#{name}\([^\(]*\)/, args, replace ]
          # Remove the macro constant if any to avoid conflict.
          macro_cons.delete(name)
        else
          # There are no arguments, it is a macro constant.
          macro_cons[name] = [ /`#{name}(?=[^_a-zA-Z0-9])/, args ]
          # Remove the macro function if any to avoid conflict.
          macro_func.delete(name)
        end
      when "`undefX" # Skip
      when "`undef"
        # Get the macro name, arguments and replacement.
        name = code.scan(/^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*$/)[0]
        # Process the name.
        name.gsub!(/\s/,"")
        # Remove the macro.
        macro_cons.delete(name)
        macro_func.delete(name)
      when "`ifdefX" # Skip
      when "`ifdef"
        # Get the macro name, arguments and replacement.
        name = code.scan(/^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*$/)[0]
        unless name =~ /^\s*[_a-zA-Z][_a-zA-Z0-9]*/ then
          cpos = line.scan(/\s*`ifdef\s*/)[0].size
          self.parse_error("invalid macro name",line.chomp,lpos,cpos)
        end
        # Process the name.
        name.gsub!(/\s/,"")
        # Set the the skip mode on if there is no such macro.
        if macro_cons.key?(name) or macro_func.key?(name)
          skip_mode << [ :ifdef, false ]
        else
          skip_mode << [ :ifdef, true ]
        end
      when "`ifndefX" # Skip
      when "`ifndef"
        # Get the macro name, arguments and replacement.
        name = code.scan(/^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*$/)[0]
        unless name =~ /^\s*[_a-zA-Z][_a-zA-Z0-9]*/ then
          cpos = line.scan(/\s*`ifndef\s*/)[0].size
          self.parse_error("invalid macro name",line.chomp,lpos,cpos)
        end
        # Process the name.
        name.gsub!(/\s/,"")
        # Set the the skip mode on if there is such macro.
        if macro_cons.key?(name) or macro_func.key?(name)
          skip_mode << [ :ifndef, true ]
        else
          skip_mode << [ :ifndef, false ]
        end
      when "`else", "`elseX"
        # Invert the last skip mode if any, otherwise, error.
        if skip_mode.size < 2 then
          self.parse_error("misplaced `else directive",
                               line.chomp,lpos,0)
        end
        skip_mode[-1] = [:else, !skip_mode[-1][1] ]
      when "`elsif", "`elsifX"
        # Get the macro name, arguments and replacement.
        name = code.scan(/^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*$/)[0]
        unless name =~ /^\s*[_a-zA-Z][_a-zA-Z0-9]*/ then
          cpos = line.scan(/\s*`elsifX?\s*/)[0].size
          self.parse_error("invalid macro name",line.chomp,lpos,cpos)
        end
        # Process the name.
        name.gsub!(/\s/,"")
        # Depending of the skip mode.
        if (skip_mode[-1][0]==:ifdef or skip_mode[-1][0]==:ifndef) and
            skip_mode[-1][1] then
          # Set the the skip mode on if there is such macro.
          if macro_cons.key?(name) or macro_func.key?(name)
            # This is an elsif so replace the last skip mode.
            skip_mode[-1] = [ :ifdef, false ]
          else
            # This is an elsif so replace the last skip mode.
            skip_mode[-1] [ :ifdef, true ]
          end
        else
          self.parse_error("misplaced `elsif directive",
                               line.chomp,lpos,0)
        end
      when "`endif", "`endifX"
        # Remove the last skip mode if any, otherwise, error.
        if skip_mode.size < 2 then
          self.parse_error("misplaced `endif directive",
                               line.chomp,lpos,0)
        end
        skip_mode.pop
      when "`includeX"
      when "`include"
        # Get the file name to include.
        filename = code.scan(/^\s*"[^\\"]*"\s*$/)[0]
        filename.gsub!(/^\s*/,"")
        filename.gsub!(/"\s*$/,"\"")
        filename = filename[1..-2]
        # Reads the file.
        included_text = ""
        begin
          included_text = File.read(@state.path + filename)
        rescue => error
          self.file_error(error,lpos+ljump)
        end
        # Insert it in pre_text and not in final text so that it
        # is processed again, and setup again the scanner.
        new_pos = scanner.pos-line.size+1
        pre_text = pre_text[0...new_pos] + 
                   included_text + 
                   pre_text[scanner.pos..-1]
        scanner = StringScanner.new(pre_text)
        scanner.pos = new_pos
        # Also update the line numbering and file reference.
        included_jump = included_text.lines.count
        # puts "included_jump=#{included_jump} ljump=#{ljump}"
        idx = 0
        included_jump.times do |i|
          idx = lpos+i+ljump-1
          @state.lprop[idx] = @state.lprop[idx-1].clone
          # i-1 to compenstate the later line increase.
          @state.lprop[idx][:lpos] = i-1
          @state.lprop[idx][:filename] = @state.path + filename
        end
        # puts "lpos=#{lpos} @state.lprop[lpos]=#{@state.lprop[lpos]}"
        next_lpos = lpos+included_jump
        @state.lprop[next_lpos] = @state.lprop[lpos-1].clone
        @state.lprop[next_lpos][:lpos] += ljump
        @state.lprop[next_lpos][:lfreeze] = true
      when "`resetallX" # Skip
      when "`resetall"
        # Clears the macro.
        # Auth: that what it should do right?
        macro_cons.clear
        macro_func.clear
      else
        cpos = line.index("`")
        self.parse_error("unknown directive",line.chomp,lpos,cpos)
      end
      # And add an empty line instead to the final text.
      @state.text << "\n"
    else
      # No, get it as a normal line.
      line = scanner.scan(/[^\n]*\n/)
      # But, first, are there any line merge?
      line,ljump = self.process_merge_line(line,scanner,lpos)
      # Shall we skip?
      if skip_mode[-1][1] then
        # Yes, the line is empty.
        line = "\n"
      else
        # Also, this time, there will be some line position adjustment.
        # And apply the known macros.
        macro_cons.each_value do |rex,replace|
          line.gsub!(rex,replace)
        end
        macro_func.each_value do |rex,formal_args,replace|
          # Extract all the macro function call
          macro_calls = line.scan(rex)
          # Process them to replacements.
          macro_calls.each do |mc|
            real_args = mc.split(/[\(\),]/)[1..-1]
            # puts "real_args=#{real_args} formal_args=#{formal_args}"
            formal_args.each_with_index do |formal_arg,i|
              replace = replace.gsub(formal_arg,real_args[i])
            end
            line.sub!(mc,replace)
          end
        end
      end
      # Write the line to the final text.
      @state.text << line
    end
    # Next line.
    lpos += ljump
  end
  # Are all the `ifdef and `ifndef directive closed?
  if skip_mode.size > 1 then
    # No, error.
    self.parse_error("`endif directive missing",line.chomp,lpos,0)
  end
  # puts "Result: #{@state.text}"
  # puts "lprops=#{@state.lprop.join("\n")}"
end

#primary_hook(base, expression__constant_expression, constant_expression) ⇒ Object



6537
6538
6539
6540
6541
6542
6543
# File 'lib/HDLRuby/verilog_parser.rb', line 6537

def primary_hook(base,
                 expression__constant_expression,
                 constant_expression)
  return AST[:primary,
             base, expression__constant_expression,
             constant_expression, self.property_hook ]
end

#primary_parseObject



6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
# File 'lib/HDLRuby/verilog_parser.rb', line 6490

def primary_parse
  number = self.number_parse
  if number then
    return self.primary_hook(number,nil,nil)
  end
  multiple_concatenation = self.multiple_concatenation_parse
  if multiple_concatenation then
    return self.primary_hook(multiple_concatenation,nil,nil)
  end
  concatenation = self.concatenation_parse
  if concatenation then
    return self.primary_hook(concatenation,nil,nil)
  end
  function_call = self.function_call_parse
  if function_call then
    return self.primary_hook(function_call,nil,nil)
  end
  if self.get_token(OPEN_PAR_REX) then
    mintypmax_expression = self.mintypmax_expression_parse
    if !mintypmax_expression then
      return nil
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    return self.primary_hook(mintypmax_expression,nil,nil)
  end
  identifier = self.identifier_parse
  return nil unless identifier
  unless self.get_token(OPEN_BRA_REX) then
    return self.primary_hook(identifier,nil,nil)
  end
  parse_state = self.state
  constant_expression0 = self.constant_expression_parse
  if !constant_expression0 or !self.get_token(COLON_REX) then
    # Not constant_expression : constant_expression, rewind
    self.state = parse_state
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
    return self.primary_hook(identifier,expression,nil)
  end
  constant_expression1 = self.constant_expression_parse
  self.parse_error("constant expression expected") unless constant_expression1
  self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
  return self.primary_hook(identifier,
                           constant_expression0,constant_expression1)
end

#property_hookObject

Hook for the properties of the current line. (No syntax rule required).



1389
1390
1391
# File 'lib/HDLRuby/verilog_parser.rb', line 1389

def property_hook
  return AST[:property, @state.lprop[@state.lpos].select {|k,v| v} ]
end

#range_hook(constant_expression0, constant_expression1) ⇒ Object



3284
3285
3286
# File 'lib/HDLRuby/verilog_parser.rb', line 3284

def range_hook(constant_expression0, constant_expression1)
  return AST[:range, constant_expression0,constant_expression1, self.property_hook ]
end

#range_or_type_hook(range_or_type) ⇒ Object



2461
2462
2463
2464
2465
2466
2467
# File 'lib/HDLRuby/verilog_parser.rb', line 2461

def range_or_type_hook(range_or_type)
  if self.state.compress then
    return range_or_type
  else
    return AST[:range_or_type, range_or_type, self.property_hook ]
  end
end

#range_or_type_parseObject



2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
# File 'lib/HDLRuby/verilog_parser.rb', line 2450

def range_or_type_parse
  tok = self.get_token(INTEGER_REAL_REX)
  if tok then
    return self.range_or_type_hook(tok)
  else
    range = self.range_parse
    return nil unless range
    return self.range_or_type_hook(range)
  end
end

#range_parseObject



3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
# File 'lib/HDLRuby/verilog_parser.rb', line 3270

def range_parse
  parse_state = self.state
  return nil unless self.get_token(OPEN_BRA_REX)
  constant_expression0 = self.constant_expression_parse
  if !constant_expression0 or !self.get_token(COLON_REX) then
    self.state = parse_state
    return nil
  end
  constant_expression1 = self.constant_expression_parse
  self.parse_error("constant expression expected") unless constant_expression1
  self.parse_error unless self.get_token(CLOSE_BRA_REX)
  return range_hook(constant_expression0,constant_expression1)
end

#real_declaration_hook(list_of_register_variables) ⇒ Object



2917
2918
2919
# File 'lib/HDLRuby/verilog_parser.rb', line 2917

def real_declaration_hook(list_of_register_variables)
  return AST[:real_declaration, list_of_register_variables, self.property_hook ]
end

#real_declaration_parseObject



2907
2908
2909
2910
2911
2912
2913
2914
2915
# File 'lib/HDLRuby/verilog_parser.rb', line 2907

def real_declaration_parse
  # puts "real_declaration_parse"
  unless self.get_token(REAL_REX) then
    return nil
  end
  list_of_register_variables = self.list_of_register_variables_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return real_declaration_hook(list_of_register_variables)
end

#reg_declaration_hook(sign, range, list_of_register_variables) ⇒ Object



2852
2853
2854
# File 'lib/HDLRuby/verilog_parser.rb', line 2852

def reg_declaration_hook(sign, range, list_of_register_variables)
  return AST[:reg_declaration, sign,range,list_of_register_variables, self.property_hook ]
end

#reg_declaration_parseObject



2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
# File 'lib/HDLRuby/verilog_parser.rb', line 2840

def reg_declaration_parse
  # puts "reg_declaration_parse"
  unless self.get_token(REG_REX) then
    return nil
  end
  sign = self.get_token(SIGNED_REX)
  range = self.range_parse
  list_of_register_variables = self.list_of_register_variables_parse
  self.parse_error("semicolon exptected HERE #4") unless self.get_token(SEMICOLON_REX)
  return reg_declaration_hook(sign,range,list_of_register_variables)
end

#register_variable_hook(name, constant_expression1, constant_expression2) ⇒ Object



3108
3109
3110
3111
3112
3113
# File 'lib/HDLRuby/verilog_parser.rb', line 3108

def register_variable_hook(name, 
                           constant_expression1,
                           constant_expression2)
  return AST[:register_variable, 
             name, constant_expression1, constant_expression2, self.property_hook ]
end

#register_variable_parseObject



3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
# File 'lib/HDLRuby/verilog_parser.rb', line 3081

def register_variable_parse
  parse_state = self.state
  name_of_memory = self.name_of_memory_parse
  if self.get_token(OPEN_BRA_REX) then
    constant_expression1 = self.constant_expression_parse
    self.parse_error("constant expression expected") unless constant_expression1
    self.parse_error("colon expected") unless self.get_token(COLON_REX)
    constant_expression2  = self.constant_expression_parse
    self.parse_error("constant expression expected") unless constant_expression2
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
    return register_variable_hook(name_of_memory,
                                  constant_expression1, 
                                  constant_expression2)
  else
    self.state = parse_state
    name_of_register = self.name_of_register_parse
    # Handle the initialization if any.
    if self.get_token(EQUAL_REX) then
      expression = self.expression_parse
      self.parse_error("expression expected") unless expression
    else
      expression = nil
    end
    return register_variable_hook(name_of_register,expression,nil)
  end
end

#rule(name) ⇒ Object

Get a rule by +name+.



1354
1355
1356
# File 'lib/HDLRuby/verilog_parser.rb', line 1354

def rule(name)
  return RULES[name.to_sym]
end

#run(text: nil, filename: "", compress: false) ⇒ Object

Runs the full preprocesser and parser for text to parse +text+ and/or origin file named +filename+. If +compress+ is true the compressed version of the AST will be generated.



150
151
152
153
154
# File 'lib/HDLRuby/verilog_parser.rb', line 150

def run(text: nil, filename: "", compress: false)
  self.setup(text: text, filename: filename, compress: compress)
  self.preprocess
  self.parse
end

#scalar_constant_hook(tok) ⇒ Object



5477
5478
5479
# File 'lib/HDLRuby/verilog_parser.rb', line 5477

def scalar_constant_hook(tok)
  return AST[:scalar_constant, tok, self.property_hook ]
end

#scalar_constant_parseObject



5469
5470
5471
5472
5473
5474
5475
# File 'lib/HDLRuby/verilog_parser.rb', line 5469

def scalar_constant_parse
  tok = self.get_token(SCALAR_CONSTANT_REX)
  unless tok then
    return nil
  end
  return self.scalar_constant_hook(tok)
end

#scalar_event_expression_hook(scalar_event_expression) ⇒ Object



7304
7305
7306
# File 'lib/HDLRuby/verilog_parser.rb', line 7304

def scalar_event_expression_hook(scalar_event_expression)
  return AST[:scalar_event_expression, scalar_event_expression, self.property_hook ]
end

#scalar_event_expression_parseObject



7296
7297
7298
7299
7300
7301
7302
# File 'lib/HDLRuby/verilog_parser.rb', line 7296

def scalar_event_expression_parse
  # *Auth*: we use a simple expression here. The check is left to
  # the AST.
  expression = self.expression_parse
  return nil unless expression 
  return self.scalar_event_expression_hook(expression)
end

#scalar_expression_hook(expression) ⇒ Object



5434
5435
5436
# File 'lib/HDLRuby/verilog_parser.rb', line 5434

def scalar_expression_hook(expression)
  return AST[:scalar_expression, expression, self.property_hook ]
end

#scalar_expression_parseObject



5424
5425
5426
5427
5428
5429
5430
5431
5432
# File 'lib/HDLRuby/verilog_parser.rb', line 5424

def scalar_expression_parse
  # *Auth*: assume to be a plain expression: actually it should be
  # one-bit.
  # This is assumed to be checked at the AST level, for example
  # by redefinition the hook method.
  expression = self.expression_parse
  return nil unless expression
  return self.scalar_expression_hook(expression)
end

#scalar_timing_check_condition_hook(scalar_expression__tok, scalar_expression, scalar_constant) ⇒ Object



5410
5411
5412
5413
5414
5415
5416
# File 'lib/HDLRuby/verilog_parser.rb', line 5410

def scalar_timing_check_condition_hook(scalar_expression__tok,
                                       scalar_expression,
                                       scalar_constant)
  return AST[:scalar_timing_check_condition,
             scalar_expression__tok,
             scalar_expression,scalar_constant, self.property_hook ]
end

#scalar_timing_check_condition_parseObject



5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
# File 'lib/HDLRuby/verilog_parser.rb', line 5388

def scalar_timing_check_condition_parse
  if self.get_token(TILDE_REX) then
    scalar_expression = self.scalar_expression_parse
    self.parse_error("scalar expression expected") unless scalar_expression
    return self.scalar_timing_check_condition_hook(TILDE_TOK,
                                                   scalar_expression,
                                                   nil)
  end
  scalar_expression = self.scalar_expression_parse
  return nil unless scalar_expression
  tok = self.get_token(SCALAR_TIMING_CHECK_CONDITION_REX)
  if tok then
    scalar_constant = self.scalar_constant_parse
    self.parse_error("scalar constant expected") unless scalar_constant
    return self.scalar_timing_check_condition(tok,
                                              scalar_expression,
                                              scalar_constant)
  end
  return self.scalar_timing_check_condition_hook(scalar_expression,
                                                 nil,nil)
end

#sdpd_conditional_expression_hook(unary_operator__expression, expression__binary_operator, expression) ⇒ Object



5812
5813
5814
5815
5816
5817
5818
5819
# File 'lib/HDLRuby/verilog_parser.rb', line 5812

def sdpd_conditional_expression_hook(unary_operator__expression,
                                     expression__binary_operator,
                                     expression)
  return AST[:sdpd_conditionla_expression,
             unary_operator__expression,
             expression__binary_operator,
             expression, self.property_hook ]
end

#sdpd_conditional_expression_parseObject



5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
# File 'lib/HDLRuby/verilog_parser.rb', line 5792

def sdpd_conditional_expression_parse
  unary_operator = self._UNARY_OPERATOR_parse
  if unary_operator then
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    return self.sdpd_conditional_expression_hook(unary_operator,
                                                 expression,nil)
  else
    expression0 = self.expression_parse
    return nil unless expression0
    binary_operator = self._BINARY_OPERATOR_parse
    self.parse_error("one of [#{BINARY_OPERATOR_TOKS.join(",")}] expected") unless binary_operator
    expression1 = self.expression_parse
    self.parse_error("expression expected") unless expression1
    return self.sdpd_conditional_expression_hook(expression0,
                                                 binary_operator,
                                                 expression1)
  end
end

#sdpd_hook(sdpd_conditional_expression, path_description, path_delay_value) ⇒ Object



5778
5779
5780
5781
5782
5783
# File 'lib/HDLRuby/verilog_parser.rb', line 5778

def sdpd_hook(sdpd_conditional_expression, path_description,
              path_delay_value)
  return AST[:sdpd, 
             sdpd_conditional_expression,path_description,
             path_delay_value, self.property_hook ]
end

#sdpd_parseObject



5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
# File 'lib/HDLRuby/verilog_parser.rb', line 5755

def sdpd_parse
  parse_state = self.state
  unless self.get_token(IF_REX) then
    self.state = parse_state
    return nil
  end
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  sdpd_conditional_expression = self.sdpd_conditional_expression_parse
  if !sdpd_conditional_expression then
    self.state = parse_state
    return nil
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  path_description = self.path_description_parse
  self.parse_error("path description expected") unless path_description
  self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
  path_delay_value = self.path_delay_value_parse
  self.parse_error("path delay value expected") unless path_delay_value
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return sdpd_hook(sdpd_conditional_expression,path_description,
                   path_delay_value)
end

#seq_block_hook(name_of_block, block_declarations, statements) ⇒ Object



4268
4269
4270
4271
4272
# File 'lib/HDLRuby/verilog_parser.rb', line 4268

def seq_block_hook(name_of_block,
                   block_declarations, statements)
  return AST[:seq_block, name_of_block,
             block_declarations,statements, self.property_hook ]
end

#seq_block_parseObject



4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
# File 'lib/HDLRuby/verilog_parser.rb', line 4231

def seq_block_parse
  unless self.get_token(BEGIN_REX) then
    return nil
  end
  if self.get_token(COLON_REX) then
    name_of_block = self.name_of_block_parse
    self.parse_error("block name expected") unless name_of_block
    block_declarations = [ ]
    cur_block_declaration = nil
    loop do
      cur_block_declaration = self.block_declaration_parse
      break unless cur_block_declaration
      block_declarations << cur_block_declaration
    end
    statements = []
    cur_statement = nil
    loop do
      cur_statement = self.statement_parse
      break unless cur_statement
      statements << cur_statement
    end
    self.parse_error("'end' expected") unless self.get_token(END_REX)
    return self.seq_block_hook(name_of_block,block_declarations,
                               statements)
  else
    statements = []
    cur_statement = nil
    loop do
      cur_statement = self.statement_parse
      break unless cur_statement
      statements << cur_statement
    end
    self.parse_error("'end' expected") unless self.get_token(END_REX)
    return self.seq_block_hook(nil,nil,statements)
  end
end

#sequential_entry_hook(input_list, _state, next_state) ⇒ Object



2166
2167
2168
# File 'lib/HDLRuby/verilog_parser.rb', line 2166

def sequential_entry_hook(input_list, _state, next_state)
  return AST[:sequential_entry, input_list,_state,next_state, self.property_hook ]
end

#sequential_entry_parseObject



2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
# File 'lib/HDLRuby/verilog_parser.rb', line 2145

def sequential_entry_parse
  parse_state = self.state
  input_list = self.input_list_parse
  if !input_list or !self.get_token(COLON_REX) then
    self.state = parse_state
    return nil
  end
  parse_state = self.state
  _state = self.state_parse
  if !_state or !self.get_token(COLON_REX) then
    self.state = parse_state
    return nil
  end
  next_state = self.next_state_parse
  if !next_state or !self.get_token(SEMICOLON_REX) then
    self.state = parse_state
    return nil
  end
  return self.sequential_entry_hook(input_list,_state,next_state)
end

#setup(text: nil, filename: "", compress: false) ⇒ Object

Set up the parser with text to parse +text+ and/or origin file named +filename+



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/HDLRuby/verilog_parser.rb', line 159

def setup(text: nil, filename: "", compress: false)
  # Shall we load the file?
  if text then
    # The text is provided, so do not load it.
    @state.text = text.to_s
    @state.filename = filename.to_s
  else
    # Yes, load from filename.
    @state.filename = filename.to_s
    @state.text = File.read(@state.filename)
  end
  # Set the path the the files.
  @state.path = File.dirname(@state.filename) + "/"
  # Set the compress mode.
  @state.compress = compress ? true : false
end

#shift_term_hook(add_terms) ⇒ Object



6335
6336
6337
6338
6339
6340
6341
# File 'lib/HDLRuby/verilog_parser.rb', line 6335

def shift_term_hook(add_terms)
  if self.state.compress and add_terms.size == 1 then
    return add_terms[0]
  else
    return AST[:shift_term, add_terms, self.property_hook ]
  end
end

#shift_term_parseObject



6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
# File 'lib/HDLRuby/verilog_parser.rb', line 6318

def shift_term_parse
  # puts "shift_term_parse"
  cur_add_term = self.add_term_parse
  return nil unless cur_add_term
  add_terms = [ cur_add_term ]
  tok = nil
  loop do
    tok = self.get_token(ADD_OPERATOR_REX)
    break unless tok
    add_terms << tok
    cur_add_term = self.add_term_parse
    self.parse_error("expression expected") unless cur_add_term
    add_terms << cur_add_term
  end
  return shift_term_hook(add_terms)
end

#short_comment_hook(comment_text) ⇒ Object



6945
6946
6947
# File 'lib/HDLRuby/verilog_parser.rb', line 6945

def short_comment_hook(comment_text)
  return AST[:short_comment, comment_text, self.property_hook ]
end

#short_comment_parseObject



6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
# File 'lib/HDLRuby/verilog_parser.rb', line 6933

def short_comment_parse
  unless self.get_token(SLASH_SLASH_REX) then
    return nil
  end
  # *Auth*: long and short comment are separated while in the
  # BNF the are the same rule.
  comment_text = self.short_comment_text_parse
  self.parse_error("comment text expected") unless comment_text
  self.parse_error("end of line expected") unless self.get_token(EOL_REX)
  return self.short_comment_hook(comment_text)
end

#short_comment_text_parseObject



6993
6994
6995
6996
6997
# File 'lib/HDLRuby/verilog_parser.rb', line 6993

def short_comment_text_parse
  # *Auth*: long and short comment are separated while in the
  # BNF the are the same rule.
  return comment_text_hook(self.get_token(SHORT_COMMENT_TEXT_REX))
end

#source_text_hook(elems) ⇒ Object



1411
1412
1413
# File 'lib/HDLRuby/verilog_parser.rb', line 1411

def source_text_hook(elems)
  return AST[:source_text, elems, self.property_hook ]
end

#source_text_parseObject



1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
# File 'lib/HDLRuby/verilog_parser.rb', line 1400

def source_text_parse
  elems = []
  cur_elem = nil
  loop do
    cur_elem = self.description_parse
    break unless cur_elem
    elems << cur_elem
  end
  return self.source_text_hook(elems)
end

#specify_block_hook(specify_items) ⇒ Object



4544
4545
4546
# File 'lib/HDLRuby/verilog_parser.rb', line 4544

def specify_block_hook(specify_items)
  return AST[:specify_block, specify_items, self.property_hook ]
end

#specify_block_parseObject



4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
# File 'lib/HDLRuby/verilog_parser.rb', line 4529

def specify_block_parse
  unless self.get_token(SPECIFY_REX) then
    return nil
  end
  specify_items = []
  cur_specify_item = nil
  loop do
    cur_specify_item = self.specify_item_parse
    break unless cur_specify_item
    specify_items << cur_specify_item
  end
  self.parse_error("'endspecify expected'") unless self.get_token(ENDSPECIFY_REX)
  return self.specify_block_hook(specify_items)
end

#specify_input_terminal_descriptor_hook(input_identifier, constant_expression, constant_expression2) ⇒ Object



4814
4815
4816
4817
4818
4819
4820
# File 'lib/HDLRuby/verilog_parser.rb', line 4814

def specify_input_terminal_descriptor_hook(input_identifier,
                                           constant_expression,
                                           constant_expression2)
  return AST[:specify_input_terminal_descriptor,
             input_identifier,
             constant_expression,constant_expression2, self.property_hook ]
end

#specify_input_terminal_descriptor_parseObject



4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
# File 'lib/HDLRuby/verilog_parser.rb', line 4790

def specify_input_terminal_descriptor_parse
  input_identifier = self.input_identifier_parse
  return nil unless input_identifier
  unless self.get_token(OPEN_BRA_REX) then
    return self.specify_input_terminal_descriptor_hook(
      input_identifier,nil,nil)
  end
  constant_expression = self.constant_expression_parse
  self.parse_error("constant expression expected") unless constant_expression
  tok = self.get_token(CLOSE_BRA_COLON_REX)
  if tok == CLOSE_BRA_TOK then
    return self.specify_input_terminal_descriptor_hook(
      input_identifier,constant_expression,nil)
  elsif tok == COLON_TOK then
    constant_expression2 = self.constant_expression_parse
    self.parse_error("constant expression expected") unless constant_expression
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
    return self.specify_input_terminal_descriptor_hook(
      input_identifier,constant_expression,constant_expression2)
  else
    self.parse_error("invalid input terminal descriptor")
  end
end

#specify_item_hook(declaration) ⇒ Object



4589
4590
4591
4592
4593
4594
4595
# File 'lib/HDLRuby/verilog_parser.rb', line 4589

def specify_item_hook(declaration)
  if self.state.compress then
    return declaration
  else
    return AST[:specify_item, declaration, self.property_hook ]
  end
end

#specify_item_parseObject



4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
# File 'lib/HDLRuby/verilog_parser.rb', line 4559

def specify_item_parse
  specparam_declaration = self.specparam_declaration_parse
  if specparam_declaration then
    return self.specify_item_hook(specparam_declaration)
  end
  path_declaration = self.path_declaration_parse
  if path_declaration then
    return self.specify_item_hook(path_declaration)
  end
  level_sensitive_path_declaration = 
    self.level_sensitive_path_declaration_parse
  if level_sensitive_path_declaration then
    return self.specify_item_hook(level_sensitive_path_declaration)
  end
  edge_sensitive_path_declaration =
    self.edge_sensitive_path_declaration_parse
  if edge_sensitive_path_declaration then
    return self.specify_item_hook(edge_sensitive_path_declaration)
  end
  system_timing_check = self.system_timing_check_parse
  if system_timing_check then
    return self.specify_item_hook(system_timing_check)
  end
  sdpd = self.sdpd_parse
  if sdpd then
    return self.specify_item_hook(sdpd)
  end
  return nil
end

#specify_output_terminal_descriptor_hook(output_identifier, constant_expression, constant_expression2) ⇒ Object



4854
4855
4856
4857
4858
4859
4860
# File 'lib/HDLRuby/verilog_parser.rb', line 4854

def specify_output_terminal_descriptor_hook(output_identifier,
                                           constant_expression,
                                           constant_expression2)
  return AST[:specify_output_terminal_descriptor,
             output_identifier,
             constant_expression,constant_expression2, self.property_hook ]
end

#specify_output_terminal_descriptor_parseObject



4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
# File 'lib/HDLRuby/verilog_parser.rb', line 4830

def specify_output_terminal_descriptor_parse
  output_identifier = self.output_identifier_parse
  return nil unless output_identifier
  unless self.get_token(OPEN_BRA_REX) then
    return self.specify_output_terminal_descriptor_hook(
      output_identifier,nil,nil)
  end
  constant_expression = self.constant_expression_parse
  self.parse_error("constant expression expected") unless constant_expression
  tok = self.get_token(CLOSE_BRA_COLON_REX)
  if tok == CLOSE_BRA_TOK then
    return self.specify_output_terminal_descriptor_hook(
      output_identifier,constant_expression,nil)
  elsif tok == COLON_TOK then
    constant_expression2 = self.constant_expression_parse
    self.parse_error("constant expression expected") unless constant_expression
    self.parse_error("closing bracket expected") unless self.get_token(CLOSE_BRA_REX)
    return self.specify_output_terminal_descriptor_hook(
      output_identifier,constant_expression,constant_expression2)
  else
    self.parse_error("invalid output terminal descriptor")
  end
end

#specify_terminal_descriptor_hook(specify_terminal_descriptor) ⇒ Object



5221
5222
5223
5224
5225
5226
5227
# File 'lib/HDLRuby/verilog_parser.rb', line 5221

def specify_terminal_descriptor_hook(specify_terminal_descriptor)
  if self.state.compress then
    return specify_terminal_descriptor
  else
    return AST[:specify_terminal_descriptor, specify_terminal_descriptor, self.property_hook ]
  end
end

#specify_terminal_descriptor_parseObject



5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
# File 'lib/HDLRuby/verilog_parser.rb', line 5205

def specify_terminal_descriptor_parse
  specify_input_terminal_descriptor = 
    self.specify_input_terminal_descriptor_parse
  if specify_input_terminal_descriptor then
    return self.specify_terminal_descriptor(
      specify_input_terminal_descriptor)
  end
  specify_output_terminal_descriptor = 
    self.specify_output_terminal_descriptor_parse
  unless specify_output_terminal_descriptor then
    return nil
  end
  return self.specify_terminal_descriptor_hook(
    specify_output_terminal_descriptor)
end

#specparam_declaration_hook(list_of_param_assignments) ⇒ Object



4613
4614
4615
# File 'lib/HDLRuby/verilog_parser.rb', line 4613

def specparam_declaration_hook(list_of_param_assignments)
  return AST[:specparam_declaration, list_of_param_assignments, self.property_hook ]
end

#specparam_declaration_parseObject



4603
4604
4605
4606
4607
4608
4609
4610
4611
# File 'lib/HDLRuby/verilog_parser.rb', line 4603

def specparam_declaration_parse
  unless self.get_token(SPECPARAM_REX) then
    return nil
  end
  list_of_param_assignments = self.list_of_param_assignments_parse
  self.parse_error("list of parameter assignments expected") unless list_of_param_assignments
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.specparam_declaration_hook(list_of_param_assignments)
end

#stateObject

Get a copy of the current state.



551
552
553
# File 'lib/HDLRuby/verilog_parser.rb', line 551

def state
  return @state.clone
end

#state=(state) ⇒ Object

Sets the current state.



556
557
558
559
560
561
# File 'lib/HDLRuby/verilog_parser.rb', line 556

def state=(state)
  # @state.index = state.index
  # @state.lpos = state.lpos
  # @state.cpos = state.cpos
  @state = state
end

#state_hook(level_symbol) ⇒ Object



2284
2285
2286
# File 'lib/HDLRuby/verilog_parser.rb', line 2284

def state_hook(level_symbol)
  return AST[:state, level_symbol, self.property_hook ]
end

#state_parseObject



2278
2279
2280
2281
2282
# File 'lib/HDLRuby/verilog_parser.rb', line 2278

def state_parse
  level_symbol = self._LEVEL_SYMBOL_parse
  return nil unless level_symbol
  return self.state_hook(level_symbol)
end

#statement_hook(base, arg0, arg1, arg2, arg3) ⇒ Object



4052
4053
4054
# File 'lib/HDLRuby/verilog_parser.rb', line 4052

def statement_hook(base,arg0,arg1,arg2,arg3)
  return AST[:statement, base,arg0,arg1,arg2,arg3, self.property_hook ]
end

#statement_or_null_hook(statement) ⇒ Object



3886
3887
3888
# File 'lib/HDLRuby/verilog_parser.rb', line 3886

def statement_or_null_hook(statement)
  return AST[:statement_or_null, statement, self.property_hook ]
end

#statement_or_null_parseObject



3877
3878
3879
3880
3881
3882
3883
3884
# File 'lib/HDLRuby/verilog_parser.rb', line 3877

def statement_or_null_parse
  if self.get_token(SEMICOLON_REX) then
    return statement_or_null_hook(self._NULL_hook)
  end
  statement = self.statement_parse
  return nil unless statement
  return statement_or_null_hook(statement)
end

#statement_parseObject



3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
# File 'lib/HDLRuby/verilog_parser.rb', line 3919

def statement_parse
  tok = self.get_token(STATEMENT_REX)
  case(tok)
  when IF_TOK
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    statement_or_null = self.statement_or_null_parse
    self.parse_error("statement or nothing expected") unless statement_or_null
    if self.get_token(ELSE_REX) then
      statement_or_null2 = self.statement_or_null_parse
      self.parse_error("statement or nothing expected") unless statement_or_null2
      return statement_hook(IF_TOK,expression,statement_or_null,
                            statement_or_null2,nil)
    else
      return statement_hook(tok,expression,statement_or_null,nil,nil)
    end
  when CASE_TOK, CASEZ_TOK, CASEX_TOK
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    cur_case_item = self.case_item_parse
    self.parse_error("closing parenthesis expected") unless cur_case_item
    case_items = [ cur_case_item ]
    loop do
      cur_case_item = self.case_item_parse
      break unless cur_case_item
      case_items << cur_case_item
    end
    self.parse_error("'endcase' expected") unless self.get_token(ENDCASE_REX)
    return self.statement_hook(tok,expression,case_items,nil,nil)
  when FOREVER_TOK
    statement = self.statement_parse
    self.parse_error("statement expected") unless statement
    return self.statement_hook(tok,statement,nil,nil,nil)
  when REPEAT_TOK, WHILE_TOK
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    statement = self.statement_parse
    self.parse_error("statement expression expected") unless statement
    return self.statement_hook(tok,expression,statement,nil,nil)
  when FOR_TOK
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    assignment = self.assignment_parse
    self.parse_error("assignment expected") unless assignment
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    assignment2 = self.assignment_parse
    self.parse_error("assignment expected") unless assignment2
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    statement = self.statement_parse
    self.parse_error("statement expected") unless statement
    return self.statement_hook(tok,assignment,expression,assignment2,
                              statement)
  when WAIT_TOK
    self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
    expression = self.expression_parse
    self.parse_error("expression expected") unless expression
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    statement_or_null = self.statement_or_null_parse
    self.parse_error("statement or nothing expected") unless statement_or_null
    return self.statement_hook(tok,expression,statement_or_null,
                               nil,nil)
  when RIGHT_ARROW_TOK
    name_of_event = self.parse_name_of_event
    self.parse_error("event name expected") unless name_of_event
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.statement_hook(tok,name_of_event,nil,nil,nil)
  when DISABLE_TOK
    name_of_task = self.name_of_task_parse
    if name_of_task then
      self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
      return self.statement_hook(tok,name_of_task,nil,nil,nil)
    end
    name_of_block = self.name_of_block_parse
    if name_of_block then
      self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
      return self.statement_hook(tok,name_of_block,nil,nil,nil)
    end
    self.parse_error("invalid disable")
  when ASSIGN_TOK, FORCE_TOK
    assignment = self.assignment_parse
    self.parse_error("assignment expected") unless assignment
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.statement_hook(tok,assignment,nil,nil,nil)
  when DEASSIGN_TOK, RELEASE_TOK
    lvalue = self.lvalue_parse
    self.parse_error("left value expected") unless lvalue
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.statement_hook(tok,lvalue,nil,nil,nil)
  end
  delay_or_event_control = self.delay_or_event_control_parse
  if delay_or_event_control then
    statement_or_null = self.statement_or_null_parse
    self.parse_error("statement or nothing expected") unless statement_or_null
    return self.statement_hook(delay_or_event_control,
                               statement_or_null,nil,nil,nil)
  end
  seq_block = self.seq_block_parse
  if seq_block then
    return self.statement_hook(seq_block,nil,nil,nil,nil)
  end
  par_block = self.par_block_parse
  if par_block then
    return self.statement_hook(par_block,nil,nil,nil,nil)
  end
  task_enable = self.task_enable_parse
  if task_enable then
    return self.statement_hook(task_enable,nil,nil,nil,nil)
  end
  system_task_enable = self.system_task_enable_parse
  if system_task_enable then
    return self.statement_hook(system_task_enable,nil,nil,nil,nil)
  end
  blocking_assignment = self.blocking_assignment_parse
  if blocking_assignment then
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.statement_hook(blocking_assignment,nil,nil,nil,nil)
  end
  non_blocking_assignment = self.non_blocking_assignment_parse
  if non_blocking_assignment then
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.statement_hook(non_blocking_assignment,nil,nil,nil,nil)
  end
  return nil
end

#system_identifier_hook(tok) ⇒ Object



4516
4517
4518
# File 'lib/HDLRuby/verilog_parser.rb', line 4516

def system_identifier_hook(tok)
  AST[:system_identifier, tok, self.property_hook ]
end

#system_identifier_parseObject



4507
4508
4509
4510
4511
4512
4513
4514
# File 'lib/HDLRuby/verilog_parser.rb', line 4507

def system_identifier_parse
  tok = self.get_token(SYSTEM_IDENTIFIER_REX)
  if tok then
    return self.system_identifier_hook(tok)
  end
  return nil
  # self.parse_error("dollar-starting identifier expected")
end

#system_task_enable_hook(name_of_system_task, expressions) ⇒ Object



4480
4481
4482
# File 'lib/HDLRuby/verilog_parser.rb', line 4480

def system_task_enable_hook(name_of_system_task,expressions)
  return AST[:system_task_enable, name_of_system_task,expressions, self.property_hook ]
end

#system_task_enable_parseObject



4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
# File 'lib/HDLRuby/verilog_parser.rb', line 4445

def system_task_enable_parse
  parse_state = self.state
  name_of_system_task = self.name_of_system_task_parse
  return nil unless name_of_system_task
  unless self.get_token(OPEN_PAR_REX) then
    if self.get_token(SEMICOLON_REX) then
      return self.system_task_enable_hook(name_of_system_task,nil)
    else
      self.state = parse_state
      return nil
    end
  end
  cur_expression = self.expression_parse
  # self.parse_error("expression expected") unless cur_expression
  if !cur_expression then
    # No arguments, check for closing parenthsis and semicolon 
    # then return.
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_task_enable_hook(name_of_system_task,[])
  end
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << cur_expression
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.system_task_enable_hook(name_of_system_task,expressions)
end

#system_timing_check_hook(tok, arg0, arg1, arg2, arg3, arg4) ⇒ Object



5158
5159
5160
5161
# File 'lib/HDLRuby/verilog_parser.rb', line 5158

def system_timing_check_hook(tok,arg0,arg1,arg2,arg3,arg4)
  return AST[:system_timing_check,
             tok,arg0,arg1,arg2,arg3,arg4, self.property_hook ]
end

#system_timing_check_parseObject



5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
# File 'lib/HDLRuby/verilog_parser.rb', line 5015

def system_timing_check_parse
  tok = self.get_token(SYSTEM_TIMING_REX)
  case(tok)
  when SETUP_TOK, HOLD_TOK
    timing_check_event0 = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event0
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_event1 = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event1
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit
    notify_register = nil
    if self.get_token(COMMA_REX) then
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless cur_notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                         timing_check_event0,
                                         timing_check_event1,
                                         timing_check_limit,
                                         notify_register,
                                         nil)
  when PERIOD_TOK
    controlled_timing_check_event = 
      self.controlled_timing_check_event_parse
    self.parse_error("controlled timing check expected") unless controlled_timing_check_event
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit
    notify_register = nil
    if self.get_token(COMMA_REX) then
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless cur_notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                        controlled_timing_check_event,
                                        timing_check_limit,
                                        notify_register,
                                        nil,nil)
  when WIDTH_TOK
    controlled_timing_check_event = 
      self.controlled_timing_check_event_parse
    self.parse_error("controlled timing check event expected") unless controlled_timing_check_event
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit
    constant_expression = nil
    notify_register = nil
    if self.get_token(COMMA_REX) then
      constant_expression = self.constant_expression_parse
      self.parse_error("constant expression expected") unless constant_expression
      self.parse_error("comma expected") unless self.get_token(COMMA_REX)
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                        controlled_timing_check_event,
                                        timing_check_limit,
                                        constant_expression,
                                        notify_register,
                                        nil)
  when SKEW_TOK
    timing_check_event0 = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event0
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_event1 = self.timing_check_event1
    self.parse_error("timing check event expected") unless timing_check_event1
    timing_check_limit = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit
    notify_register = nil
    if self.get_token(COMMA_REX) then
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless cur_notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                         timing_check_event0.
                                         timing_check_event1,
                                         timing_check_limit,
                                         notify_register,
                                         nil)
  when RECOVERY_TOK
    controlled_timing_check_event = 
      self.controlled_timing_check_event_parse
    self.parse_error("controlled timing check event expected") unless controlled_timing_check_event
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_event = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit = self.timing_check_limit_parse
    self.parse_error("timing check event expected") unless timing_check_limit
    notify_register = nil
    if self.get_token(COMMA_REX) then
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless cur_notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                        controlled_timing_check_event,
                                        timing_check_event,
                                        timing_check_limit,
                                        notify_register,
                                        nil)
  when SETUPHOLD_TOK
    timing_check_event0 = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event0
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_event1 = self.timing_check_event_parse
    self.parse_error("timing check event expected") unless timing_check_event1
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit0 = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit0
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    timing_check_limit1 = self.timing_check_limit_parse
    self.parse_error("timing check limit expected") unless timing_check_limit1
    self.parse_error("comma expected") unless self.get_token(COMMA_REX)
    notify_register = nil
    if self.get_token(COMMA_REX) then
      notify_register = self.notify_register_parse
      self.parse_error("identifier expected") unless cur_notify_register
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    return self.system_timing_check_hook(tok,
                                         timing_check_event0,
                                         timing_check_event1,
                                         timing_check_limit0,
                                         timing_check_limit1,
                                         notify_register)
  else
    return nil
  end
end

#table_definition_hook(table_entries) ⇒ Object



2076
2077
2078
# File 'lib/HDLRuby/verilog_parser.rb', line 2076

def table_definition_hook(table_entries)
  return AST[:table_definition, table_entries, self.property_hook ]
end

#table_definition_parseObject



2067
2068
2069
2070
2071
2072
2073
2074
# File 'lib/HDLRuby/verilog_parser.rb', line 2067

def table_definition_parse
  unless self.get_token(TABLE_REX) then
    return nil
  end
  table_entries = self.table_entries_parse
  self.parse_error("'endtable' expected") unless self.get_token(ENDTABLE_REX)
  return self.table_definition_hook(table_entries)
end

#table_entries_hook(entries) ⇒ Object



2110
2111
2112
# File 'lib/HDLRuby/verilog_parser.rb', line 2110

def table_entries_hook(entries)
  return AST[:table_entries, entries, self.property_hook ]
end

#table_entries_parseObject



2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
# File 'lib/HDLRuby/verilog_parser.rb', line 2087

def table_entries_parse
  cur_combinational_entry = self.combinational_entry_parse
  if cur_combinational_entry then
    combinational_entries = [ cur_combinational_entry ]
    loop do
      cur_combinational_entry = self.combinational_entry_parse
      break unless cur_combinational_entry
      combinational_entries << cur_combinational_entry
    end
    return table_entries_hook(combinational_entries)
  else
    cur_sequential_entry = self.sequential_entry_parse
    self.parse_error("sequential entry expected") unless cur_sequential_entry
    sequential_entries = [ cur_sequential_entry ]
    loop do
      cur_sequential_entry = self.sequential_entry_parse
      break unless cur_sequential_entry
      sequential_entries << cur_sequential_entry
    end
    return self.table_entries_hook(sequential_entries)
  end
end

#task_enable_hook(name_of_task, expressions) ⇒ Object



4434
4435
4436
# File 'lib/HDLRuby/verilog_parser.rb', line 4434

def task_enable_hook(name_of_task,expressions)
  return AST[:task_enable, name_of_task,expressions, self.property_hook ]
end

#task_enable_parseObject



4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
# File 'lib/HDLRuby/verilog_parser.rb', line 4406

def task_enable_parse
  parse_state = self.state
  name_of_task = self.name_of_task_parse
  return nil unless name_of_task
  unless self.get_token(OPEN_PAR_REX) then
    if self.get_token(SEMICOLON_REX) then
      return self.task_enable_hook(name_of_task,nil)
    else
      self.state = parse_state
      return nil
    end
  end
  cur_expression = self.expression_parse
  self.parse_error("expression expected") unless cur_expression
  expressions = [ cur_expression ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_expression = self.expression_parse
    self.parse_error("expression expected") unless cur_expression
    expressions << cur_expression
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.task_enable_hook(name_of_task,expressions)
end

#task_hook(name_of_task, tf_declaration, statement_or_null) ⇒ Object



2385
2386
2387
# File 'lib/HDLRuby/verilog_parser.rb', line 2385

def task_hook(name_of_task, tf_declaration, statement_or_null)
  return AST[:task, name_of_task,tf_declaration,statement_or_null, self.property_hook ]
end

#task_parseObject



2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
# File 'lib/HDLRuby/verilog_parser.rb', line 2365

def task_parse
  unless self.get_token(TASK_REX) then
    return nil
  else
    name_of_task = self.name_of_task_parse
    self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
    tf_declarations = []
    cur_tf_declaration = nil
    loop do
      cur_tf_declaration = self.tf_declaration_parse
      break unless cur_tf_declaration
      tf_declarations << cur_tf_declaration
    end
    statement_or_null = self.statement_or_null_parse
    self.parse_error("statement or nothing expected") unless statement_or_null
    self.parse_error("'endtask' expected") unless self.get_token(ENDTASK_REX)
    return self.task_hook(name_of_task,tf_declarations,statement_or_null)
  end
end

#terminal_hook(terminal) ⇒ Object



3594
3595
3596
# File 'lib/HDLRuby/verilog_parser.rb', line 3594

def terminal_hook(terminal)
  return AST[:terminal, terminal, self.property_hook ]
end

#terminal_parseObject



3584
3585
3586
3587
3588
3589
3590
3591
3592
# File 'lib/HDLRuby/verilog_parser.rb', line 3584

def terminal_parse
  expression = self.expression_parse
  if expression then
    return self.terminal_hook(expression)
  end
  identifier = self._IDENTIFIER_parse
  return nil unless identifier
  return self.terminal_hook(identifier)
end

#tf_declaration_hook(declaration) ⇒ Object



2518
2519
2520
2521
2522
2523
2524
# File 'lib/HDLRuby/verilog_parser.rb', line 2518

def tf_declaration_hook(declaration)
  if self.state.compress then
    return declaration
  else
    return AST[:tf_declaration, declaration, self.property_hook ]
  end
end

#tf_declaration_parseObject



2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
# File 'lib/HDLRuby/verilog_parser.rb', line 2498

def tf_declaration_parse
  declaration = self.parameter_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.input_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.output_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.inout_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.reg_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.time_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.integer_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  declaration = self.real_declaration_parse
  return self.tf_declaration_hook(declaration) if declaration
  return nil
end

#time_declaration_hook(list_of_register_variables) ⇒ Object



2877
2878
2879
# File 'lib/HDLRuby/verilog_parser.rb', line 2877

def time_declaration_hook(list_of_register_variables)
  return AST[:time_declaration, list_of_register_variables, self.property_hook ]
end

#time_declaration_parseObject



2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
# File 'lib/HDLRuby/verilog_parser.rb', line 2862

def time_declaration_parse
  # puts "time_declaration_parse"
  parse_state = self.state
  unless self.get_token(TIME_REX) then
    return nil
  end
  list_of_register_variables = self.list_of_register_variables_parse
  # self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  unless self.get_token(SEMICOLON_REX) then
    self.state = parse_state
    return nil
  end
  return time_declaration_hook(list_of_register_variables)
end

#timing_check_condition_hook(scalar_timing_check_condition) ⇒ Object



5368
5369
5370
5371
5372
5373
5374
5375
# File 'lib/HDLRuby/verilog_parser.rb', line 5368

def timing_check_condition_hook(scalar_timing_check_condition)
  if self.state.compress then
    return scalar_timing_check_condition
  else
    return AST[:timing_check_condition,
               scalar_timing_check_condition, self.property_hook ]
  end
end

#timing_check_condition_parseObject



5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
# File 'lib/HDLRuby/verilog_parser.rb', line 5351

def timing_check_condition_parse
  scalar_timing_check_condition = nil
  if self.get_token(OPEN_PAR_REX) then
    scalar_timing_check_condition = 
      self.scalar_timig_check_condition_parse
    unless scalar_timing_check_condition then
      return nil
    end
    self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  else
    scalar_timing_check_condition = 
      self.scalar_timig_check_condition_parse
    return nil unless scalar_timing_check_condition
  end
  return self.timing_check_condition_hook(scalar_timing_check_condition)
end

#timing_check_event_control_hook(tok__edge_control_specifier) ⇒ Object



5287
5288
5289
# File 'lib/HDLRuby/verilog_parser.rb', line 5287

def timing_check_event_control_hook(tok__edge_control_specifier)
  return AST[:timing_check_event_control, tok__event_control_specifier, self.property_hook ]
end

#timing_check_event_control_parseObject



5277
5278
5279
5280
5281
5282
5283
5284
5285
# File 'lib/HDLRuby/verilog_parser.rb', line 5277

def timing_check_event_control_parse
  tok = self.get_token(POSEDGE_NEGEDGE_REX)
  if tok then
    return self.timing_check_event_control_hook(tok)
  end
  edge_control_specifier = self.edge_control_specifier_parse
  return nil unless edge_control_specifier
  return self.timing_check_event_control_hook(edge_control_specifier)
end

#timing_check_event_hook(timing_check_event_control, specify_terminal_descriptor, timing_check_condition) ⇒ Object



5190
5191
5192
5193
5194
5195
5196
# File 'lib/HDLRuby/verilog_parser.rb', line 5190

def timing_check_event_hook(timing_check_event_control,
                            specify_terminal_descriptor,
                            timing_check_condition)
  return AST[:timing_check_event, timing_check_event_control,
             specify_terminal_descriptor,
             timing_check_condition, self.property_hook ]
end

#timing_check_event_parseObject



5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
# File 'lib/HDLRuby/verilog_parser.rb', line 5170

def timing_check_event_parse
  parse_state = self.state
  timing_check_event_control = self.timing_check_event_control_parse
  specify_terminal_descriptor = self.specify_terminal_descriptor_parse
  unless specify_terminal_descriptor then
    self.state = parse_state
    return nil
  end
  unless self.get_token(AND_AND_AND_REX) then
    return self.timing_check_event_hook(timing_check_event_control,
                                        specify_terminal_descriptor,
                                        nil)
  end
  timing_check_condition = self.timing_check_condition_parse
  self.parse_error("timing check condition expected") unless timing_check_condition
  return self.timing_check_event_hook(timing_check_event_control,
                                      specify_terminal_descriptor,
                                      timing_check_condition)
end

#timing_check_list_hook(expression) ⇒ Object



5450
5451
5452
# File 'lib/HDLRuby/verilog_parser.rb', line 5450

def timing_check_list_hook(expression)
  return AST[:timing_check_list, expression, self.property_hook ]
end

#timing_check_list_parseObject



5444
5445
5446
5447
5448
# File 'lib/HDLRuby/verilog_parser.rb', line 5444

def timing_check_list_parse
  expression = self.expression_parse
  return nil unless expression
  return self.timing_check_list_hook(expression)
end

#udp_declaration_hook(declaration) ⇒ Object



1989
1990
1991
1992
1993
1994
1995
# File 'lib/HDLRuby/verilog_parser.rb', line 1989

def udp_declaration_hook(declaration)
  if self.state.compress then
    return declaration
  else
    return AST[:UDP_declaration, declaration, self.property_hook ]
  end
end

#udp_declaration_parseObject



1979
1980
1981
1982
1983
1984
1985
1986
1987
# File 'lib/HDLRuby/verilog_parser.rb', line 1979

def udp_declaration_parse
  declaration = self.output_declaration_parse
  return self.udp_declaration_hook(declaration) if declaration
  declaration = self.reg_declaration_parse
  return self.udp_declaration_hook(declaration) if declaration
  declaration = self.input_declaration_parse
  return self.udp_declaration_hook(declaration) if declaration
  return nil
end

#udp_hook(name, name_of_variables, udp_declarations, udp_initial_statement, table_definition) ⇒ Object



1942
1943
1944
1945
1946
1947
# File 'lib/HDLRuby/verilog_parser.rb', line 1942

def udp_hook(name, name_of_variables, udp_declarations,
             udp_initial_statement, table_definition)
  return AST[:UDP, 
             name,name_of_variables,udp_declarations,
             udp_initial_statement,table_definition, self.property_hook ]
end

#udp_initial_statement_hook(output_terminal_name, init_val) ⇒ Object



2012
2013
2014
# File 'lib/HDLRuby/verilog_parser.rb', line 2012

def udp_initial_statement_hook(output_terminal_name,init_val)
  return AST[:UDP_initial_statement, output_terminal_name,init_val, self.property_hook ]
end

#udp_initial_statement_parseObject



2003
2004
2005
2006
2007
2008
2009
2010
# File 'lib/HDLRuby/verilog_parser.rb', line 2003

def udp_initial_statement_parse
  return nil unless self.get_token(INITIAL_REX)
  output_terminal_name = self.output_terminal_name_parse
  self.parse_error("equal expected") unless self.get_token(EQUAL_REX)
  init_val = self.init_val_parse
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  return self.udp_initial_statement_hook(output_terminal_name,init_val)
end

#udp_instance_hook(name_of_udp_instance, terminals) ⇒ Object



3556
3557
3558
# File 'lib/HDLRuby/verilog_parser.rb', line 3556

def udp_instance_hook(name_of_udp_instance, terminals)
  return AST[:UDP_instance, name_of_udp_instance,terminals, self.property_hook ]
end

#udp_instance_parseObject



3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
# File 'lib/HDLRuby/verilog_parser.rb', line 3531

def udp_instance_parse
  parse_state = self.state
  name_of_udp_instance = self.name_of_udp_instance_parse
  unless self.get_token(OPEN_PAR_REX) then
    self.state = parse_state
    return nil
  end
  cur_terminal = self.terminal_parse
  unless cur_terminal then
    self.state = parse_state
    return nil
  end
  terminals = [ cur_terminal ]
  loop do
    unless self.get_token(COMMA_REX) then
      break
    end
    cur_terminal = self.terminal_parse
    self.parse_error("terminal expected") unless cur_terminal
    terminals << cur_terminal
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  return udp_instance_hook(name_of_udp_instance,terminals)
end

#udp_instantiation_hook(name_of_udp, drive_strength, delay, udp_instances) ⇒ Object



3503
3504
3505
3506
3507
# File 'lib/HDLRuby/verilog_parser.rb', line 3503

def udp_instantiation_hook(name_of_udp, drive_strength, delay,
                           udp_instances)
  return AST[:udp_instantiation,
             name_of_udp,drive_strength,delay,udp_instances, self.property_hook ]
end

#udp_instantiation_parseObject



3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
# File 'lib/HDLRuby/verilog_parser.rb', line 3479

def udp_instantiation_parse
  # puts "udp_instantiation_parse"
  parse_state = self.state
  name_of_udp = self.name_of_udp_parse
  return nil unless name_of_udp
  drive_strength = self.drive_strength_parse
  delay = self.delay_parse
  cur_udp_instance = self.udp_instance_parse
  unless cur_udp_instance then
    self.state = parse_state
    return nil
  end
  udp_instances = [ cur_udp_instance ]
  loop do
    break unless self.get_token(COMMA_REX)
    cur_udp_instance = self.udp_instance_parse
    self.parse_error("UDP instance expected") unless cur_udp_instance
    udp_instances << cur_udp_instance
  end
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON)
  return udp_instantiation_hook(name_of_udp,drive_strength,delay,
                                udp_instances)
end

#udp_name?(name) ⇒ Boolean

Tells if a name is a known UDP name.

Returns:

  • (Boolean)


624
625
626
# File 'lib/HDLRuby/verilog_parser.rb', line 624

def udp_name?(name)
  return @udp_names.include?(name)
end

#udp_parseObject



1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
# File 'lib/HDLRuby/verilog_parser.rb', line 1905

def udp_parse
  unless self.get_token(PRIMITIVE_REX) then
    return nil
  end
  name = self.name_of_udp_parse
  self.parse_error("name of UDP expected") unless name
  self.parse_error("opening parenthesis expected") unless self.get_token(OPEN_PAR_REX)
  cur_name_of_variable = self.name_of_variable_parse
  self.parse_error("variable name expected") unless cur_name_of_variable
  name_of_variables = [ cur_name_of_variable ]
  loop do
    break unless self.get_token(COMMA_REX)
    cur_name_of_variable = self.name_of_variable_parse
    self.parse_error("identifier expected") unless cur_name_of_variable
    name_of_variables << cur_name_of_variable
  end
  self.parse_error("closing parenthesis expected") unless self.get_token(CLOSE_PAR_REX)
  self.parse_error("semicolon expected") unless self.get_token(SEMICOLON_REX)
  udp_declarations = []
  cur_udp_declaration = nil
  loop do
    cur_udp_declaration = self.udp_declaration_parse
    break unless cur_udp_declaration
    udp_declarations << cur_udp_declaration
  end
  self.parse_error("empty UDP declaration") if udp_declarations.empty? # udp_declaration+ rule
  udp_initial_statement = self.udp_initial_statement_parse
  table_definition = self.table_definition_parse
  self.parse_error("'endprimitive' expected") unless self.get_token(ENDPRIMITIVE_REX)

  # Add a know udp name.
  self.add_udp_name(name)
  # And return the corresponding AST
  return self.udp_hook(name,name_of_variables,udp_declarations,
                       udp_initial_statement, table_definition)
end