code_generator.py¶
- class fabric_generator.code_generator.codeGenerator¶
The base class for all code generators.
- abstract addAssignScalar(left, right, delay=0, indentLevel=0)¶
Add a scalar assign statement. Delay is provided by currently not being used by any of the code generator. If right is a list, it will be concatenated. Verilog will be concatenated with comma ‘,’. VHDL will be concatenated with ampersand ‘&’.
- Examples :
- Verilog: assign left = right;VHDL: left <= right after delay ps;
- abstract addAssignVector(left, right, widthL, widthR, indentLevel=0)¶
Add a vector assign statement.
- Examples :
- Verilog: assign left = right [widthL:widthR];VHDL: left <= right ( widthL downto widthR );
- Parameters
left – The left hand side of the assign statement.
right – The right hand side of the assign statement.
widthL – The start index of the vector. Can be a string.
widthR – The end index of the vector. Can be a string.
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addComment(comment: str, onNewLine=False, end='', indentLevel=0) None ¶
Add a comment to the code.
- Examples :
- Verilog: // commentVHDL : – comment
- abstract addComponentDeclarationForFile(fileName: str)¶
Add a component declaration for a file. Only useful with VHDL. Will copy the entity of the file, and replacing the entity with component for VHDL to work.
- Parameters
fileName (str) – name of the VHDL file
- abstract addConnectionScalar(name: str, indentLevel=0)¶
Add a scalar connection.
- Examples :
- Verilog: wire name;VHDL: signal name : STD_LOGIC;
- abstract addConnectionVector(name: str, startIndex, endIndex=0, indentLevel=0)¶
Add a vector connection.
- Examples :
- Verilog: wire [startIndex:end] name;VHDL: signal name : STD_LOGIC_VECTOR( startIndex downto endIndex );
- abstract addConstant(name: str, value, indentLevel=0)¶
Add a constant.
- Examples :
- Verilog: parameter name = value;VHDL: constant name : STD_LOGIC := value;
- abstract addDesignDescriptionEnd(indentLevel=0)¶
Add end of design description.
- Examples :
- Verilog: endmoduleVHDL: end architecture Behavioral
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addDesignDescriptionStart(name: str, indentLevel=0)¶
Add start of design description. Only useful with VHDL.
- Examples :
- Verilog:VHDL: architecture Behavioral of name is
- abstract addHeader(name: str, package='', indentLevel=0)¶
Add a header to the code.
- Examples :
- Verilog: module nameVHDL: library IEEE;use IEEE.std_logic_1164.all;use IEEE.NUMERIC_STD.ALLpackageentity name is
- abstract addHeaderEnd(name: str, indentLevel=0)¶
Add end to header. Only useful with VHDL.
- Examples :
- Verilog:VHDL: end entity name;
- abstract addInstantiation(compName: str, compInsName: str, portsPairs: List[Tuple[str, str]], paramPairs: List[Tuple[str, str]] = [], emulateParamPairs: List[Tuple[str, str]] = [], indentLevel=0)¶
Add an instantiation. This will line up the ports and signals. So ports[0] will have signals[0] and so on. This is also the same case for paramPorts and paramSignals.
- Examples :
- Verilog: compName compInsName # (. paramPorts[0] (paramSignals[0]),. paramPorts[1] (paramSignals[1]),…. paramPorts[n] (paramSignals[n])) (. compPorts[0] (signals[0]),. compPorts[1] (signals[1]),…. compPorts[n] (signals[n]));VHDL: compInsName : compNamegeneric map (paramPorts[0] => paramSignals[0],paramPorts[1] => paramSignals[1],…paramPorts[i] => paramSignals[i]);Port map (compPorts[i] => signals[i],compPorts[i] => signals[i],compPorts[i] => signals[i]);
- Parameters
compName (str) – name of the component
compInsName (str) – name of the component instance
compPorts (List[str]) – list of ports of the component
signals (List[str]) – list of signals of the component
paramPorts (List[str], optional) – list of parameter ports of the component. Defaults to [].
paramSignals (List[str], optional) – list of parameter signals of the component. Defaults to [].
emulateParamPairs (List[str], optional) – list of parameter signals of the component in emulation mode only. Defaults to [].
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- Raises
ValueError – If the number of compPorts and signals are not equal.
ValueError – If the number of paramPorts and paramSignals are not equal.
- abstract addLogicEnd(indentLevel=0)¶
Add end of logic. Only useful with VHDL.
- Examples :
- Verilog:VHDL: end
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addLogicStart(indentLevel=0)¶
Add start of logic. Only useful with VHDL.
- Examples :
- Verilog:VHDL: begin
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addParameter(name: str, type, value, indentLevel=0)¶
Add a parameter.
- Examples :
- Verilog: parameter name = valueVHDL: name : type := value;
- abstract addParameterEnd(indentLevel=0)¶
Add end of parameters.
- Examples :
- Verilog: )VHDL: );
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addParameterStart(indentLevel=0)¶
Add start of parameters.
- Examples :
- Verilog: #(VHDL: Generic(
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addPortEnd(indentLevel=0)¶
Add end of ports.
- Examples :
- Verilog: );VHDL: );
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addPortScalar(name: str, io: fabric_generator.fabric.IO, indentLevel=0)¶
Add a scalar port.
- Examples :
- Verilog: io nameVHDL: name : io STD_LOGIC;
- abstract addPortStart(indentLevel=0)¶
Add start of ports.
- Examples :
- Verilog: (VHDL: port (
- Parameters
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addPortVector(name: str, io: fabric_generator.fabric.IO, msbIndex, indentLevel=0)¶
Add a vector port.
- Examples :
- Verilog: io [msbIndex:0] nameVHDL: name : io STD_LOGIC_VECTOR( msbIndex downto 0 );
- abstract addPreprocElse(indentLevel=0)¶
Add a preprocessor “else”
- Examples :
- Verilog: `elseVHDL: unsupported
- Parameters
macro – The macro to check for
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addPreprocEndif(indentLevel=0)¶
Add a preprocessor “endif”
- Examples :
- Verilog: `endifVHDL: unsupported
- Parameters
macro – The macro to check for
indentLevel (int, optional) – The indentation Level. Defaults to 0.
- abstract addPreprocIfDef(macro, indentLevel=0)¶
Add a preprocessor “ifdef”
- Examples :
- Verilog: `ifdef macroVHDL: unsupported
- Parameters
macro – The macro to check for
indentLevel (int, optional) – The indentation Level. Defaults to 0.