Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions doc/user_guide/user_guide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1687,15 +1687,13 @@ \subsection{Verilog back-end}
back end.
\index{-remove-unused-modules@\te{-remove-unused-modules} (compiler
flag)}
\index{-v95@\te{-v95} (compiler flag)}
\index{-remove-dollar@\te{-remove-dollar} (compiler flag)}
\index{-unspecified-to@\te{-unspecified-to} (compiler flag)}
\index{-Xv@\te{-Xv} (compiler flag)}
\index{-verilog-filter@\te{-verilog-filter} (compiler flag)}
\index{-use-dpi@\te{-use-dpi}}
\begin{centerboxverbatim}
-remove-unused-modules remove unconnected modules from the Verilog
-v95 generate strict Verilog 95 code
-unspecified-to val remaining unspecified values are set to:
'X', '0', '1', 'Z', or 'A'
-remove-dollar remove dollar signs from Verilog identifiers
Expand All @@ -1711,14 +1709,6 @@ \subsection{Verilog back-end}
should be used on modules undergoing synthesis, and not be used for
testbench modules.

The {\bf\tt -v95} flag restricts the Verilog output to pure Verilog-95.
By default, the Verilog output uses features which are not in the
Verilog-95 standard. These features include passing module
parameters by name and use of the {\tt \$signed} system task for formatting
{\tt \$display} output. When the {\tt -v95} flag is turned on, uses
of these features are removed, but comments are left in the Verilog
indicating the parameter names or system tasks which were removed.

The {\bf\tt -unspecified-to val} flag defines the value
which any remaining unspecified values should be tied to. The valid
set of values are: {\tt X}, {\tt 0}, {\tt 1}, {\tt Z}, or {\tt A},
Expand Down
6 changes: 4 additions & 2 deletions src/Libraries/Base1/Fork.bs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import Vector
--@ values to avoid CSE.
--@

-- XXX m == 2*n, but we can't have contexts on foreign.
foreign vfork :: Bit n -> Bit m = "Fork",("i","o")
-- The type variables name the Verilog instance parameters, so they
-- must match Fork.v's parameter names (iw, ow).
-- XXX ow == 2*iw, but we can't have contexts on foreign.
foreign vfork :: Bit iw -> Bit ow = "Fork",("i","o")

--@ Copy a value into two identical values.
--@ \begin{libverbatim}
Expand Down
10 changes: 8 additions & 2 deletions src/comp/AConv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,15 @@ aExpr e@(IAps (ICon i (ICForeign { fName = name, isC = isC, foports = Nothing}))
--let ns = [ n | ITNum n <- ts]
--traceM("AFunCall1: " ++ name)
return $ AFunCall (aTypeConvE e (iGetType e)) i name isC es'
aExpr e@(IAps (ICon i (ICForeign { fName = name, isC = False, foports = (Just ops)})) ts es) = do
aExpr e@(IAps (ICon i (ICForeign { fName = name, isC = False, foports = (Just ops),
fTyVarNames = tvns })) ts es) = do
es' <- mapM aSExpr es
let ns = [ n | ITNum n <- ts ]
let nvals = [ n | ITNum n <- ts ]
ns = if length tvns == length nvals
then zip tvns nvals
else internalError ("AConv.aExpr ANoInlineFunCall: " ++
"parameter names do not pair with values: " ++
ppReadable (name, tvns, nvals))
let t = aTypeConvE e (iGetType e)
-- because Classic allows foreign functions to be declared,
-- we need to check if this is a genwrap generated function
Expand Down
10 changes: 8 additions & 2 deletions src/comp/ASyntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,14 @@ data ANoInlineFun =
ANoInlineFun
-- function nam
String
-- numeric types
[Integer]
-- numeric parameters: the declaration's type variable names
-- paired with the concrete values at this call site. Only
-- Classic foreign functions have these (BSV noinline functions
-- are enforced monomorphic, T0111). They are emitted as NAMED
-- Verilog instance parameters, so the hand-written module must
-- name its parameters after the declaration's type variables
-- (see vDefMpd in AVerilogUtil and Fork.bs/Fork.v).
[(String, Integer)]
-- port list (inputs, outputs); each port is its name and bit size.
-- Inputs are grouped per argument (the inner list is one argument's
-- ports, of which there may be several when the argument splits); the
Expand Down
2 changes: 1 addition & 1 deletion src/comp/AVerilog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ ubInst :: [VId] -> VId -> VMItem
ubInst ids mod = VMInst
{ vi_module_name = mod,
vi_inst_name = pref verilogInstancePrefix mod,
vi_inst_params = Right [],
vi_inst_params = [],
vi_inst_ports = [(i, Just (VEVar i)) | i <- ids]
}

Expand Down
36 changes: 15 additions & 21 deletions src/comp/AVerilogUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Data.Maybe

import FStringCompat(FString, getFString)
import ErrorUtil
import Flags(Flags, readableMux, unSpecTo, v95, systemVerilogTasks, useDPI)
import Flags(Flags, readableMux, unSpecTo, systemVerilogTasks, useDPI)
import PPrint
import IntLit
import Id
Expand Down Expand Up @@ -71,8 +71,6 @@ import SCC(tsort)
-- Define a structure which controls Verilog conversions
data VConvtOpts = VConvtOpts {
vco_unspec :: String,
vco_v95 :: Bool,
vco_v95_tasks :: [String],
vco_readableMux :: Bool,
vco_sv_tasks :: Bool,
vco_use_dpi :: Bool
Expand All @@ -82,8 +80,6 @@ data VConvtOpts = VConvtOpts {
flagsToVco :: Flags -> VConvtOpts
flagsToVco flags = VConvtOpts {
vco_unspec = unSpecTo flags,
vco_v95 = v95 flags,
vco_v95_tasks = ["$signed", "$unsigned"],
vco_readableMux = readableMux flags,
vco_sv_tasks = systemVerilogTasks flags,
vco_use_dpi = useDPI flags
Expand Down Expand Up @@ -215,7 +211,7 @@ vForeignCall vco f@(AForeignCall aid taskid (c:es) ids resets) ffmap =
if aid==idSVA then fcall es
else foldr (Vif . mkNotEqualsReset . vExpr vco) fcall_body resets
where
vtaskid = VId (vCommentTaskName vco taskid) aid Nothing
vtaskid = VId taskid aid Nothing
(ids',es') = let lv = headOrErr "vForeignCall: missing return value" ids
in case isAForeignCallWithRetAsArg vco ffmap f of
(Just ty) -> ([], (ASDef ty lv) : es)
Expand Down Expand Up @@ -538,8 +534,15 @@ vDefMpd vco (ADef i t
[ VMInst {
vi_module_name = mkVId n,
vi_inst_name = VId inst_name i Nothing,
-- these are size params, so default width of 32 is fine
vi_inst_params = Left (map (\x -> (Nothing,VEConst x)) is),
-- Classic foreign functions applied at numeric types
-- (e.g. Fork) pass the values as instance parameters
-- NAMED by the declaration's type variables, which the
-- hand-written module's parameter names must match
-- (Fork.v's iw/ow). BSV noinline functions are
-- enforced monomorphic (T0111): no parameters.
-- (These are size params, so default width of 32 is fine.)
vi_inst_params = [ (mkVId nm, Just (VEConst v))
| (nm, v) <- is ],
vi_inst_ports = iports ++ oports
}
]
Expand Down Expand Up @@ -591,7 +594,7 @@ vDefMpd vco (ADef i_t t_t@(ATBit _) fn@(AFunCall {}) _) ffmap
[ VMDecl $ VVDecl VDReg (vSize t_t) [VVar (vId i_t)]
, VMStmt { vi_translate_off = True, vi_body = body }
]
where name = vCommentTaskName vco (vNameToTask (vco_use_dpi vco) (ae_funname fn))
where name = vNameToTask (vco_use_dpi vco) (ae_funname fn)
vtaskid = VId name (ae_objid fn) Nothing
sensitivityList = nub (concatMap aIds (ae_args fn))
ev = foldr1 VEEOr (map (VEE . VEVar) sensitivityList)
Expand Down Expand Up @@ -765,7 +768,7 @@ vExpr vco (APrim aid t p es) = VEOp (idToVId aid) (vExpr vco (APrim aid t p (ini
-- vExpr vco (AMethCall t i m _) = internalError "AVerilog.vExpr: AMethCall with args"
-- vExpr vco (AMethValue t i m) = VEVar (vMethId i m 1 MethodResult M.Empty)
vExpr vco (AFunCall _ _ n isC es) =
let name = vCommentTaskName vco (if isC then vNameToTask (vco_use_dpi vco) n else n)
let name = if isC then vNameToTask (vco_use_dpi vco) n else n
in VEFctCall (mkVId name) (map (vExpr vco) es)
vExpr vco (ASInt idt (ATBit w) (IntLit _ b i)) = VEWConst (idToVId idt) w b i
vExpr vco (ASReal _ _ r) = VEReal r
Expand Down Expand Up @@ -865,9 +868,7 @@ muxInst vco pri s i es =
++ "Mux_"
++ itos (length es `div` 2)),
vi_inst_name = i,
vi_inst_params = if ( vco_v95 vco )
then Left [(Just $ getVIdString viWidth ,VEConst s)]
else Right [(viWidth, Just (VEConst s))],
vi_inst_params = [(viWidth, Just (VEConst s))],
vi_inst_ports = zip muxInputs (map Just es)
}

Expand Down Expand Up @@ -1092,9 +1093,7 @@ vState flags rewire_map avinst =
vminst = VMInst {
vi_module_name = vIdV (vName vi),
vi_inst_name = vInstId v_inst_name,
vi_inst_params = if ( vco_v95 vco )
then Left (mapFst (Just . getVIdString) paramExprs)
else Right (mapSnd Just paramExprs),
vi_inst_params = mapSnd Just paramExprs,
vi_inst_ports = map (updateArgPosition ifc_position . tildeHack) args
}

Expand Down Expand Up @@ -1203,11 +1202,6 @@ aIds _ = internalError("Unexpected pattern in AVerilog::aIds"

-- ==============================

-- replace non v95 task with their name enclosed in a comment
vCommentTaskName :: VConvtOpts -> String -> String
vCommentTaskName vco s | vco_v95 vco && elem s (vco_v95_tasks vco) = " /*" ++ s ++ "*/ "
| otherwise = s

-- create a Verilog DPI/VPI task name from a foreign function name
-- XXX When using DPI, if any types are poly, use the wrapper name
vNameToTask :: Bool -> String -> String
Expand Down
8 changes: 8 additions & 0 deletions src/comp/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ data ErrMsg =
Position -- ^ previous decl position

| EForeignNotBit String String
| EForeignWidthNotBare String String
| EPartialTypeApp String Integer Integer -- synonym (# expected) (# given)
| ENotStructId String
| ENotStructUpd String
Expand Down Expand Up @@ -1942,6 +1943,13 @@ getErrorText (EMultipleDecl name prevPos) =
getErrorText (EForeignNotBit i t) =
(Type 12, empty, hdr $$ text "Type:" <+> nest 2 (text t))
where hdr = s2par ("Foreign function " ++ ishow i ++ " has a non-Bit argument or result.")
getErrorText (EForeignWidthNotBare i t) =
(Type 159, empty, hdr $$ text "Width:" <+> nest 2 (text t))
where hdr = s2par ("Foreign function " ++ ishow i ++ " has a bit width" ++
" that is not a bare type variable or a literal." ++
" Widths are passed to the module as instance" ++
" parameters named by the type variables, so a" ++
" derived width must be given its own variable.")
getErrorText (EPartialTypeApp i expected given) =
(Type 13, empty,
s2par ("Partially applied type synonym: " ++ ishow i) $$
Expand Down
1 change: 0 additions & 1 deletion src/comp/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ data Flags = Flags {
usePrelude :: Bool,
useProvisoSAT :: Bool,
stdlibNames :: Bool,
v95 :: Bool,
vFlags :: [String],
vdir :: Maybe String,
vPathRaw :: [String],
Expand Down
20 changes: 14 additions & 6 deletions src/comp/FlagsDecode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ defaultFlags bluespecdir = Flags {
usePrelude = True,
useProvisoSAT = True,
stdlibNames = False,
v95 = False,
vFlags = [],
vdir = Nothing,
-- The vPath value will be produced from the raw value,
Expand Down Expand Up @@ -1656,10 +1655,6 @@ externalFlags = [
(Toggle (\f x -> f {stdlibNames=x}) (showIfTrue stdlibNames),
"the source file is from the standard library", Hidden)),

("v95",
(Toggle (\f x -> f {v95=x}) (showIfTrue v95),
"generate strict Verilog 95 code", Visible)),

("vdir",
(Arg "dir" (\f s -> Left (f {vdir = Just s})) (Just (FRTMaybeString vdir)),
"output directory for .v files", Visible)),
Expand All @@ -1676,6 +1671,20 @@ externalFlags = [
("q",
(Alias "quiet", "same as -quiet", Visible)),

-- Removed flag (2026-07): the generated Verilog stopped conforming
-- to Verilog-95 long before the flag was removed, so requests for
-- it fail with a specific message rather than EUnknownFlag.
("v95",
(NoArg (\_ -> Right (cmdPosition,
EObsolete "flag" "-v95"
("The generated Verilog has not conformed to " ++
"Verilog-1995 for some time, so the flag has " ++
"been removed. The output now always uses " ++
"named instance parameters and other " ++
"post-1995 constructs.")))
Nothing,
"removed: bsc no longer generates Verilog-1995 output", Hidden)),

("verilog",
let setFn f = setBackend f Verilog
getFn f = backend f == Just Verilog
Expand Down Expand Up @@ -1942,7 +1951,6 @@ showFlagsRaw flags =
("useNegate", show (useNegate flags)),
("usePrelude", show (usePrelude flags)),
("useProvisoSAT", show (useProvisoSAT flags)),
("v95", show (v95 flags)),
("vFlags", show (vFlags flags)),
("vPath", show (vPath flags)),
("vPathRaw", show (vPathRaw flags)),
Expand Down
14 changes: 7 additions & 7 deletions src/comp/GenABin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import qualified Data.ByteString as B
-- .ba file tag -- change this whenever the .ba format changes
-- See also GenBin.header
header :: [Byte]
header = B.unpack $ TE.encodeUtf8 $ T.pack "bsc-ba-20260712-1"
header = B.unpack $ TE.encodeUtf8 $ T.pack "bsc-ba-20260715-1"

headerBS :: B.ByteString
headerBS = B.pack header
Expand Down Expand Up @@ -560,7 +560,7 @@ instance Bin Flags where
a_090 a_091 a_092 a_093 a_094 a_095 a_096 a_097 a_098 a_099
a_100 a_101 a_102 a_103 a_104 a_105 a_106 a_107 a_108 a_109
a_110 a_111 a_112 a_113 a_114 a_115 a_116 a_117 a_118 a_119
a_120 a_121 a_122 a_123 a_124 a_125 a_126 a_127 a_128 a_129
a_120 a_122 a_123 a_124 a_125 a_126 a_127 a_128 a_129
a_130 a_131 a_132 a_133) =
do wr_chunk0; wr_chunk1; wr_chunk2; wr_chunk3; wr_chunk4;
wr_chunk5; wr_chunk6; wr_chunk7; wr_chunk8
Expand Down Expand Up @@ -610,7 +610,7 @@ instance Bin Flags where
toBin a_115; toBin a_116; toBin a_117; toBin a_118; toBin a_119
{-# NOINLINE wr_chunk8 #-}
wr_chunk8 =
do toBin a_120; toBin a_121; toBin a_122; toBin a_123; toBin a_124;
do toBin a_120; toBin a_122; toBin a_123; toBin a_124;
toBin a_125; toBin a_126; toBin a_127; toBin a_128; toBin a_129;
toBin a_130; toBin a_131; toBin a_132; toBin a_133
readBytes =
Expand All @@ -630,7 +630,7 @@ instance Bin Flags where
a_098, a_099, a_100, a_101, a_102, a_103, a_104) <- rd_chunk6
(a_105, a_106, a_107, a_108, a_109, a_110, a_111, a_112,
a_113, a_114, a_115, a_116, a_117, a_118, a_119) <- rd_chunk7
(a_120, a_121, a_122, a_123, a_124, a_125, a_126, a_127,
(a_120, a_122, a_123, a_124, a_125, a_126, a_127,
a_128, a_129, a_130, a_131, a_132, a_133) <- rd_chunk8
return (Flags
a_000 a_001 a_002 a_003 a_004 a_005 a_006 a_007 a_008 a_009
Expand All @@ -645,7 +645,7 @@ instance Bin Flags where
a_090 a_091 a_092 a_093 a_094 a_095 a_096 a_097 a_098 a_099
a_100 a_101 a_102 a_103 a_104 a_105 a_106 a_107 a_108 a_109
a_110 a_111 a_112 a_113 a_114 a_115 a_116 a_117 a_118 a_119
a_120 a_121 a_122 a_123 a_124 a_125 a_126 a_127 a_128 a_129
a_120 a_122 a_123 a_124 a_125 a_126 a_127 a_128 a_129
a_130 a_131 a_132 a_133)
where
{-# NOINLINE rd_chunk0 #-}
Expand Down Expand Up @@ -706,10 +706,10 @@ instance Bin Flags where
a_113, a_114, a_115, a_116, a_117, a_118, a_119)
{-# NOINLINE rd_chunk8 #-}
rd_chunk8 =
do a_120 <- fromBin; a_121 <- fromBin; a_122 <- fromBin; a_123 <- fromBin; a_124 <- fromBin;
do a_120 <- fromBin; a_122 <- fromBin; a_123 <- fromBin; a_124 <- fromBin;
a_125 <- fromBin; a_126 <- fromBin; a_127 <- fromBin; a_128 <- fromBin; a_129 <- fromBin;
a_130 <- fromBin; a_131 <- fromBin; a_132 <- fromBin; a_133 <- fromBin
return (a_120, a_121, a_122, a_123, a_124, a_125, a_126, a_127,
return (a_120, a_122, a_123, a_124, a_125, a_126, a_127,
a_128, a_129, a_130, a_131, a_132, a_133)

-- ----------
Expand Down
9 changes: 5 additions & 4 deletions src/comp/GenBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ doTrace = elem "-trace-genbin" progArgs
-- .bo file tag -- change this whenever the .bo format changes
-- See also GenABin.header
header :: [Byte]
header = B.unpack $ TE.encodeUtf8 $ T.pack "bsc-bo-20260714-1"
header = B.unpack $ TE.encodeUtf8 $ T.pack "bsc-bo-20260715-1"

headerBS :: B.ByteString
headerBS = B.pack header
Expand Down Expand Up @@ -610,8 +610,8 @@ instance Bin ConTagInfo where
instance Bin (IConInfo a) where
writeBytes (ICDef t _) = do putI 0; toBin t
writeBytes (ICPrim t p) = do putI 1; toBin t; toBin (fromEnum p)
writeBytes (ICForeign t n isC ps Nothing) =
do putI 2; toBin t; toBin n; toBin isC; toBin ps
writeBytes (ICForeign t n isC ps tvns Nothing) =
do putI 2; toBin t; toBin n; toBin isC; toBin ps; toBin tvns
writeBytes (ICForeign { fcallNo = (Just _) }) =
internalError "GenBin.Bin(IConInfo).writeBytes: ICForeign with cookie"
writeBytes (ICCon t cti) = do putI 3; toBin t; toBin cti
Expand Down Expand Up @@ -669,7 +669,8 @@ instance Bin (IConInfo a) where
2 -> do n <- fromBin
isC <- fromBin
ps <- fromBin
return (ICForeign t n isC ps Nothing)
tvns <- fromBin
return (ICForeign t n isC ps tvns Nothing)
3 -> do cti <- fromBin; return (ICCon t cti)
4 -> do cti <- fromBin; return (ICIs t cti)
5 -> do cti <- fromBin; return (ICOut t cti)
Expand Down
Loading
Loading