Documentation ¶
Index ¶
- Variables
- func CCompileExpression(expr STExpression) string
- func CCompileSequence(sequence []STInstruction) string
- func FindOp(op string) postfixlib.Operator
- func OpTokenIsCombinator(opTok string) bool
- func OpTokenIsComparison(opTok string) bool
- func ParseString(name string, input string) ([]STInstruction, *STParseError)
- func STCompileExpression(expr STExpression) string
- func SetKnownVarNames(varNames []string)
- func VerilogCompileExpression(expr STExpression) string
- func VerilogCompileSequence(sequence []STInstruction) string
- func VhdlCompileExpression(expr STExpression) string
- func VhdlCompileSequence(sequence []STInstruction) string
- type DebugInfo
- type STCase
- type STExpression
- type STExpressionOperator
- type STExpressionValue
- type STForLoop
- type STIfElsIfElse
- type STIfThen
- type STInstruction
- type STParseError
- type STRepeatLoop
- type STSwitchCase
- type STWhileLoop
Constants ¶
This section is empty.
Variables ¶
var ( //ErrInternal means something went wrong and it's the transpiler's fault ErrInternal = errors.New("An internal error occured") //ErrUnexpectedEOF means the document ended unexpectedly ErrUnexpectedEOF = errors.New("Unexpected EOF") //ErrUnexpectedToken is used to indicate a parsed value was not what was expected (i.e. a word instead of a semicolon) ErrUnexpectedToken = errors.New("Unexpected token") //ErrBadExpression is used to indicate something went wrong when parsing a provided ST expression ErrBadExpression = errors.New("A bad ST expression was encountered") //ErrUndefinedEvent is used to indicate that an event was referenced that can't be found (so probably a typo has occured) ErrUndefinedEvent = errors.New("Can't find Event with name") //ErrUnexpectedAssociation is used when an association statement ("with") is used on a data line in an interface inappropriately (i.e. in a compositeFB, or trying to trigger an event) ErrUnexpectedAssociation = errors.New("Unexpected association") //ErrInvalidType is used when the type of an event or data variable is bad ErrInvalidType = errors.New("Invalid or missing data/event type") //ErrInvalidIOMeta is used when metadata for an I/O line is bad ErrInvalidIOMeta = errors.New("Invalid metadata for data/event line") //ErrNameAlreadyInUse is returned whenever something is named but the name is already in use elsewhere ErrNameAlreadyInUse = errors.New("This name is already defined elsewhere") //ErrOnlyInstancesGetParameters is returned when a constant parameter is attempt-assigned to a cfb output ErrOnlyInstancesGetParameters = errors.New("Constant parameters can only be provided to fb instances") )
Functions ¶
func CCompileExpression ¶
func CCompileExpression(expr STExpression) string
CCompileExpression will compile an STExpression to its equivalent C codes using the
c templates stored in cTemplates
func CCompileSequence ¶
func CCompileSequence(sequence []STInstruction) string
CCompileSequence will take a sequence of STInstructions and compile them to their equivalent C codes using the
c templates stored in cTemplates
func FindOp ¶
func FindOp(op string) postfixlib.Operator
FindOp finds a given operator for a given token
func OpTokenIsCombinator ¶
OpTokenIsCombinator takes a given operator token and returns a true if it is of a combination type (e.g. "and", "or")
func OpTokenIsComparison ¶
OpTokenIsComparison takes a given operator token and returns a true if it is of a comparison type (e.g. ">=")
func ParseString ¶
func ParseString(name string, input string) ([]STInstruction, *STParseError)
ParseString takes an input string (i.e. filename) and input and returns all ST instructions in that string
func STCompileExpression ¶
func STCompileExpression(expr STExpression) string
STCompileExpression will compile an STExpression to its equivalent C codes using the
c templates stored in cTemplates
func SetKnownVarNames ¶
func SetKnownVarNames(varNames []string)
SetKnownVarNames sets the names of known variables for the compiler
func VerilogCompileExpression ¶
func VerilogCompileExpression(expr STExpression) string
VerilogCompileExpression will compile an STExpression to its equivalent Verilog codes using the
verlog templates stored in verilogTemplates
func VerilogCompileSequence ¶
func VerilogCompileSequence(sequence []STInstruction) string
VerilogCompileSequence will take a sequence of STInstructions and compile them to their equivalent Verilog codes using the
verilog templates stored in verilogTemplates
verilogTemplate templates make the following assumptions: 1) All variables are VHDL "Variables", not "signals" 2) All variables are integer types 3) Everything completes in a single cycle 4) loops aren't yet supported
func VhdlCompileExpression ¶
func VhdlCompileExpression(expr STExpression) string
VhdlCompileExpression will compile an STExpression to its equivalent VHDL codes using the
vhdl templates stored in vhdlTemplates
vhdlTemplate templates make the following assumptions: 1) All variables are VHDL "Variables", not "signals" 2) All variables are integer types 3) Everything completes in a single cycle 4) loops aren't yet supported
func VhdlCompileSequence ¶
func VhdlCompileSequence(sequence []STInstruction) string
VhdlCompileSequence will take a sequence of STInstructions and compile them to their equivalent VHDL codes using the
vhdl templates stored in vhdlTemplates
vhdlTemplate templates make the following assumptions: 1) All variables are VHDL "Variables", not "signals" 2) All variables are integer types 3) Everything completes in a single cycle 4) loops aren't yet supported
Types ¶
type STCase ¶
type STCase struct { CaseValues []string Sequence []STInstruction }
STCase is used inside STSwitchCase to store the different case options
type STExpression ¶
type STExpression interface { HasValue() string //IsValue reflects that this STExpression is an STExpressionValue, and is just a single variable or value HasOperator() postfixlib.Operator GetArguments() []STExpression IsInstruction() bool }
STExpression is an interface defining an assignments and comparison function tree E.g. A := (2 + y) can be defined using STExpressions
type STExpressionOperator ¶
type STExpressionOperator struct { Operator postfixlib.Operator Arguments []STExpression }
STExpressionOperator is a type of STExpression that is an operator or a function with a list of arguments
func (STExpressionOperator) GetArguments ¶
func (s STExpressionOperator) GetArguments() []STExpression
GetArguments returns the list of arguments
func (STExpressionOperator) HasOperator ¶
func (s STExpressionOperator) HasOperator() postfixlib.Operator
HasOperator returns the internal operator
func (STExpressionOperator) HasValue ¶
func (s STExpressionOperator) HasValue() string
HasValue returns nothing, as STExpressionOperator is not a value
func (STExpressionOperator) IsInstruction ¶
func (s STExpressionOperator) IsInstruction() bool
IsInstruction meets the STInstruction interface
type STExpressionValue ¶
type STExpressionValue struct {
Value string
}
STExpressionValue is a type of STExpression that is just a single variable or value (i.e. an operand)
func (STExpressionValue) GetArguments ¶
func (s STExpressionValue) GetArguments() []STExpression
GetArguments returns the internal value as a single-element slice
func (STExpressionValue) HasOperator ¶
func (s STExpressionValue) HasOperator() postfixlib.Operator
HasOperator returns nothing, as an STExpressionValue is not an operator
func (STExpressionValue) HasValue ¶
func (s STExpressionValue) HasValue() string
HasValue returns the internal value
func (STExpressionValue) IsInstruction ¶
func (s STExpressionValue) IsInstruction() bool
IsInstruction meets the STInstruction interface
type STForLoop ¶
type STForLoop struct { ForAssignment STExpression ToValue STExpression ByIncrement STExpression Sequence []STInstruction }
STForLoop is used for for loops Example:
FOR count := initial_value TO final_value BY increment DO
<statement>;
END_FOR;
func (STForLoop) FindCounterName ¶
FindCounterName will return the variable name assigned to in the ForAssignment, if one can easily be found
func (STForLoop) IsInstruction ¶
IsInstruction meets the STInstruction interface
type STIfElsIfElse ¶
type STIfElsIfElse struct { IfThens []STIfThen ElseSequence []STInstruction }
STIfElsIfElse is used to make up the full if... elsif... elsif.... else... sequence
the ifThens are evaluated in order
example:
IF [boolean expression] THEN <statement>; ELSIF [boolean expression] THEN
<statement>;
ELSE
<statement>;
END_IF ;
A := 0; IF A = 0 THEN
B := 0;
END_IF ;
func (STIfElsIfElse) IsInstruction ¶
func (s STIfElsIfElse) IsInstruction() bool
IsInstruction meets the STInstruction interface
type STIfThen ¶
type STIfThen struct { IfExpression STExpression ThenSequence []STInstruction }
STIfThen is used as part of an STIfElsIfElse
it holds the if [boolean expression] then <statements...>; part
type STInstruction ¶
type STInstruction interface {
IsInstruction() bool
}
STInstruction is the container interface for the sequence instructions we use it to ensure that types passed into STInstruction are types that we can understand (just as a sanity check)
type STParseError ¶
STParseError is used to contain a helpful error message when parsing fails
func (STParseError) Error ¶
func (p STParseError) Error() string
Error makes ParseError fulfill error interface
type STRepeatLoop ¶
type STRepeatLoop struct { UntilExpression STExpression Sequence []STInstruction }
STRepeatLoop is used for Repeat....Until loops Example:
REPEAT
<statement>;
UNTIL [boolean expression] END_REPEAT;
func (STRepeatLoop) IsInstruction ¶
func (s STRepeatLoop) IsInstruction() bool
IsInstruction meets the STInstruction interface
type STSwitchCase ¶
type STSwitchCase struct { SwitchOn STExpression Cases []STCase ElseSequence []STInstruction }
STSwitchCase is used for the switch... case... case... else sequence examples:
CASE [numeric expression] OF
result1, result2: <statement>; resultN[, resultN]: <statemtent>;
ELSE
<statement>;
END_CASE;
CASE StateMachine OF
1: StateMachine := 2; 2: StateMachine := 1;
ELSE
StateMachine := 1;
END_CASE;
func (STSwitchCase) IsInstruction ¶
func (s STSwitchCase) IsInstruction() bool
IsInstruction meets the STInstruction interface
type STWhileLoop ¶
type STWhileLoop struct { WhileExpression STExpression Sequence []STInstruction }
STWhileLoop is used for while loops Example:
WHILE [boolean expression] DO
<statement>;
END_WHILE;
func (STWhileLoop) IsInstruction ¶
func (s STWhileLoop) IsInstruction() bool
IsInstruction meets the STInstruction interface