ironplcc¶
Name¶
ironplcc — IronPLC compiler
Synopsis¶
Description¶
ironplcc is the IronPLC compiler command line interface. It checks
IEC 61131-3 source files for correctness and compiles them into bytecode
container (.iplc) files for execution by the ironplcvm runtime.
Most developers will use ironplcc through the Visual Studio Code extension, but you can also use it directly, for example, to implement a continuous integration pipeline.
When a command accepts multiple files, the files are treated as a single compilation unit (essentially combined for analysis). Directory names can be given to add all files in the given directory.
See also
See Source Formats for all supported source file formats.
Commands¶
Build Commands¶
- ironplcc check [FILES…]
Check source files for syntax and semantic correctness without producing output. On success, the command produces no output.
- ironplcc compile [FILES…]
-oOUTPUT Compile source files into a bytecode container (
.iplc) file. Requires the--output(-o) flag to specify the output file path.Note
The compile command supports Structured Text programs, including functions, function blocks, the standard library, and activated compatibility libraries. A program that uses a feature code generation does not yet support produces a code generation error rather than incorrect bytecode.
Diagnostic Commands¶
- ironplcc echo [
--types] [FILES…] Parse source files and write the parsed representation to standard output. This is primarily useful for diagnostics and understanding the internal structure of the parsed files.
With
--types, the command analyzes the files and writes the analyzed program instead. A comment after each expression gives the type the compiler determined for it:flag := ( big (* LINT *) > total (* DINT -> LINT *) ) (* BOOL *) ;
(* DINT -> LINT *)marks an implicit conversion from the first type to the second.CONSTANTmarks a value the compiler knows, such as a literal:1 (* CONSTANT INT *).?marks an expression whose type the compiler did not determine:(* ? *), or(* ? ANY_INT *)for a literal still of a generic type.
The output is still Structured Text, but it shows the program as the compiler analyzed it rather than as written. Declarations appear in dependency order, named arguments become positional, and the compiler folds constant expressions. The output contains only the declarations from your files, not those of an activated compatibility library.
- ironplcc tokenize [FILES…]
Tokenize source files and verify that all content matches a token. This is primarily useful for diagnostics and understanding the lexer behavior.
Informational Commands¶
- ironplcc dialects
Show available dialects and which features each enables. Use this to discover which
--allow-*flags a dialect includes and which behavior policy alternatives it selects.- ironplcc version
Print the version number of the compiler.
Other Commands¶
- ironplcc lsp
--stdio Run in Language Server Protocol mode to integrate with development tools such as Visual Studio Code. Communication uses standard input/output.
Options¶
-v,--verboseTurn on verbose logging. Repeat the flag to increase verbosity (e.g.,
-vvv).-lFILE,--log-fileFILEWrite log output to the specified file instead of the terminal.
--dialectDIALECTSelect the language dialect. A dialect sets the IEC 61131-3 edition and a default set of extensions. Individual
--allow-*flags can override the dialect’s defaults. Available values:iec61131-3-ed2(default),iec61131-3-ed3,rusty,codesys,twincat. See Enabling Dialects and Features for details.--libraryNAMEActivate a compatibility library by name (for example
--library Tc2_System). Repeat the option to activate several libraries. Applies to thecheckandcompilecommands, and toechowith--types. Libraries referenced by a discovered project file are activated automatically and do not need this option.
--allow-c-style-commentsAllow C-style comments (
//line comments and/* */block comments). These are not part of the IEC 61131-3 standard but are supported by many PLC environments.--allow-missing-semicolonAllow missing semicolons after keyword statements like
END_IFandEND_STRUCT. This is an extension, not part of the IEC 61131-3 standard. It also allows aCASEbranch with no statements at all (a label that falls straight through to the next label,ELSE, orEND_CASE) – strict IEC 61131-3 only allows this via an explicit empty statement (5: ;); this fills in the dropped;.--allow-top-level-var-globalAllow
VAR_GLOBALdeclarations at the top level of a file, outside of aCONFIGURATIONblock. See Variable Scope. This is an extension, not part of the IEC 61131-3 standard.--allow-constant-type-paramsAllow constant references in type parameters such as array bounds and string lengths (e.g.,
ARRAY[1..MY_CONST] OF INTorSTRING[MY_CONST]). See Array Types. This is an extension, not part of the IEC 61131-3 standard.--allow-empty-var-blocksAllow empty variable blocks (
VAR END_VAR,VAR_INPUT END_VAR, etc.). Some PLC environments permit variable blocks with no declarations. This is an extension, not part of the IEC 61131-3 standard.--allow-time-as-function-nameAllow
TIMEto be used as a function name (e.g.,TIME()). Required for OSCAT compatibility whereTIME()reads the PLC system clock. This is an extension, not part of the IEC 61131-3 standard.--allow-long-time-typesAllow the IEC 61131-3:2013 long-time-type keywords LTIME, LDATE, LTIME_OF_DAY (
LTOD), and LDATE_AND_TIME (LDT). Without this flag those words remain available as ordinary identifiers, so Edition 2 code may use them as names.--allow-ref-toAllow
REF_TO,REF(), andNULLsyntax (standardized in IEC 61131-3:2013) without enabling the rest of Edition 3. This is useful when you need references but want to keep Edition 2 keyword handling for the rest of your code. See Reference Types.--allow-reference-toAllow the Beckhoff TwinCAT / CODESYS
REFERENCE TOreference type and theREF=binding operator. This is the TwinCAT/CODESYS-facing alternative to--allow-ref-to: the two describe the same underlying reference but with different surface syntax. The compiler does not restrict flag combinations, so--allow-ref-toand--allow-reference-tomay be set at once. See Reference Types.--allow-pointer-toAllow the Beckhoff TwinCAT / CODESYS
POINTER TOpointer type. APOINTER TOvariable behaves like aREF_TOreference: reading or writing the target requires the explicit dereference operator (^), unlikeREFERENCE TO, which dereferences implicitly. Pointers are bound with theADR()operator (--allow-adr) or theREF()/NULLforms from--allow-ref-to. See Reference Types.--allow-adrAllow the
ADR()address-of operator, which returns a typed pointer to a variable for assignment to aPOINTER TOvariable (--allow-pointer-to). Unlike TwinCAT’s untypedPVOIDresult,ADR(x)in IronPLC has the typePOINTER TOtypeof(x) and is type-checked against the destination pointer’s target type. Addresses of sub-objects (array elements, structure fields) and pointer arithmetic are not supported and are rejected with a diagnostic. See ADR.--allow-persistent-varAllow the
PERSISTENTvariable qualifier, alone or combined withRETAINin either order (RETAIN PERSISTENTorPERSISTENT RETAIN), onVAR,VAR_GLOBAL,VAR_INPUTandVAR_OUTPUTblocks. See Retention. This is an extension, not part of the IEC 61131-3 standard.--allow-ref-arithmeticAllow arithmetic (
+,-) and ordering comparisons (<,>,<=,>=) onREF_TOtypes. By default, only=and<>are permitted on references.--allow-ref-stack-variablesAllow
REF()on stack-allocated variables (VAR_TEMPand functionVAR_INPUT/VAR_OUTPUT). Required for OSCAT patterns where the reference does not escape the call. This is an extension, not part of the IEC 61131-3 standard.--allow-ref-type-punningAllow assigning between
REF_TOtypes of different base types (type punning), such as reinterpreting the bits of aREALthrough aREF_TO DWORD. This is an extension, not part of the IEC 61131-3 standard.--allow-int-to-bool-initializerAllow integer literals
0and1asBOOLvariable initializers (e.g.,debug : BOOL := 0;). The compiler rewrites0toFALSEand1toTRUE. This is a universal extension supported by CoDeSys, TwinCAT, RuSTy, and virtually every PLC runtime.--allow-sizeofAllow the
SIZEOF()operator that returns the size in bytes of a variable or type. This is an extension supported by CODESYS, TwinCAT, and RuSTy. See SIZEOF.--allow-system-uptime-globalExpose
__SYSTEM_UP_TIME(TIME) and__SYSTEM_UP_LTIME(LTIME) as implicitVAR_GLOBALvalues holding the VM’s monotonic uptime. This is an IronPLC runtime convention.--allow-cross-family-wideningAllow implicit widening from a bit-string type to a strictly wider integer type. For example, passing a
BYTEvariable where anINTparameter is expected. This is an extension supported by CODESYS, TwinCAT, and RuSTy.--allow-cross-family-conversionAllow implicit conversion between
UDINTandDWORD, in both directions. The two types share a 32-bit slot, so this converts rather than widens, and it is the one case where an integer converts implicitly to a bit-string. See Type Conversions. This is an extension supported by CODESYS, TwinCAT, and RuSTy.--allow-int-literal-to-bit-stringAllow a bare integer literal where a bit-string type is expected. For example, passing
0where aBYTEparameter is expected. This is an extension supported by CODESYS, TwinCAT, and RuSTy.--allow-bit-string-arithmeticAllow the arithmetic operators
+,-,*and/(andADD,SUB,MULandDIV) on bit-string operands. For example,counter := counter + 1wherecounteris aBYTE. ABYTE,WORD,DWORDorLWORDoperand is treated as the unsigned integer of its width, and the result keeps the bit-string type:BYTE#255 + 1isBYTE#0.BOOLandMODare not included. See Type Conversions. This is an extension supported by CODESYS, TwinCAT, and RuSTy.--allow-partial-access-syntaxAllow IEC 61131-3:2013 partial-access syntax: the bit form
.%Xn(e.g.,myByte.%X3to access bit 3 of aBYTE, equivalent to the short form.n) and the byte, word, double word, and long word forms.%Bn,.%Wn,.%Dn, and.%Ln(e.g.,myDword.%B2to access byte 2 of aDWORD). See Bit Access.--allow-pragmasAllow curly-brace pragmas such as
{attribute 'qualified_only'}and{attribute 'strict'}. These are CODESYS-core syntax (documented by CODESYS itself, and inherited by any IDE built on the CODESYS V3 runtime, including Beckhoff TwinCAT and Schneider Electric Machine Expert). A pragma is parsed and discarded like a comment — its contents are not yet interpreted. Pragmas do not nest; an unclosed{still produces a parse error.--allow-short-circuit-operatorsAllow the
AND_THENandOR_ELSEshort-circuit boolean operators, a Beckhoff/CODESYS extension. Unlike plainANDandOR(which always evaluate both operands),AND_THENonly evaluates its right operand when the left operand isTRUE, andOR_ELSEonly when the left operand isFALSE— commonly used to guard a dereference (ptr <> 0 AND_THEN ptr^ = 99). The spelling is preserved end to end: the operators are not normalized toAND/OR, since the short-circuit behavior is a real, externally-visible difference in TwinCAT/CODESYS. Compiled code branches around the right operand, so the guarded expression above never dereferences a null pointer.Short-circuiting applies to
BOOLoperands.ANDandORare also the bit-string operators, and skipping an operand has no meaning for a bit-string result, soAND_THEN/OR_ELSEon bit-string operands evaluate both operands and produce the same valueANDandORproduce. LikeANDandOR, they accept onlyBOOLand bit-string operands: an integer operand is P4049.--allow-mixed-located-var-declarationsAllow an
AT-located variable (complete address likeAT %IX0.0, or incomplete/wildcard address likeAT %I*) inside an otherwise plainVAR/VAR_INPUT/VAR_OUTPUTblock, instead of requiring located variables to live in their own dedicated block. The IEC 61131-3 standard requires located and plain variables to be declared in separate blocks; real CODESYS/TwinCAT code commonly mixes them. Without this flag, mixing produces problem P4036. A block containing only located variables is unaffected by this flag — it is standard syntax and always allowed.--allow-constant-initializer-expressionsAllow a
VARinitializer or aTYPEdefault to be a constant expression — the name of a declaredCONSTANTvariable (e.g.level : UDINT := DEFAULT_LEVEL;) or arithmetic between literals and such names (e.g.scaled : LREAL := SCALE*4.0;) — rather than only a bare literal. The IEC 61131-3 standard’s initializer grammar permits only literals in this position; this extension folds the expression to a literal at compile time. Using this form without the flag produces P4037; if the expression does not fully reduce to a constant (e.g. it references a non-CONSTANTvariable), it produces P4038; if a named constant’s type is not compatible with the variable’s, it produces P4022.--allow-radix-case-labelsAllow a hex, binary, or octal bit-string literal (e.g.
16#D012,2#1010,8#17) as aCASElabel. The IEC 61131-3 standard grammar for a case label permits only a subrange, a decimalsigned_integer, or an enumerated value; radix-prefixed literals are separate productions the standard does not include here. Real TwinCAT/CODESYS code uses them. The flag also allows them as the bounds of a subrange label (16#01..16#0F:). Without this flag, such a label produces P4041. A plain decimal label (5:) is standard syntax and is always allowed.--allow-paren-string-lengthAllow a string type’s maximum length to be delimited with parentheses (
STRING(255),WSTRING(100)) in addition to the standard square brackets (STRING[255]). The IEC 61131-3 standard grammar declares a string length only with brackets; the parenthesis form is a dialect extension. Without this flag, the parenthesis form produces P4042. The bracket form is standard syntax and is always allowed, and the delimiters must match (STRING[255)is always a syntax error). The renderer normalizes the parenthesis form to brackets. The flag applies in every position a string type can appear, including as an array element type (ARRAY[1..10] OF STRING(255)), a function return type, and aTYPEalias.--allow-radix-subrange-boundsAllow a hex, binary, or octal literal (e.g.
16#FF,2#1010,8#17) as a bound of a subrange type (INT (16#00..16#FF)) or of an array dimension (ARRAY[16#0..16#F] OF INT). The IEC 61131-3 standard grammar defines a subrange’s bounds as decimalsigned_integers. Without this flag, such a bound produces P4096. The bounds of aCASEsubrange label are allowed by--allow-radix-case-labelsinstead.--allow-struct-initializer-expressionsAllow a general (non-constant) expression — such as a pointer dereference plus member access (
pDevice^.Delta) — as the value in a structured or call-style initializer’sname := valuepairs (e.g.tonDelta : TON := (PT := pDevice^.Delta);). The IEC 61131-3 standard grammar for a structured initializer value permits only a constant, enumerated value, array initializer, or nested structure initializer; a value computed at instantiation time is an extension used by TwinCAT/CODESYS. Without this flag, such a value produces P4043. A constant value is standard syntax and is always allowed. ThepDevice^.Deltaexample spells its pointer withREF_TO, which is a separate extension needing--allow-ref-to; not every dialect that enables one enables the other, and some spell the same declarationPOINTER TO FB_Device. ironplcc dialects lists the flags each dialect enables.--allow-fb-inheritanceAllow the IEC 61131-3:2013 object-oriented syntax:
EXTENDS/IMPLEMENTSand qualifiers (ABSTRACT,FINAL,PUBLIC, …) onFUNCTION_BLOCKdeclarations,INTERFACEdeclarations,METHODandPROPERTYdeclarations, andTHIS/SUPER. Support beyond parsing varies by keyword — see Object Oriented Programming for what each one analyzes and executes today; the parts that are parsed but not yet analyzed produce problem P9999 rather than a parse error. A function block qualifier produces P4062 when used without this flag. Enabled by--dialect=iec61131-3-ed3,--dialect=rusty,--dialect=codesys, and--dialect=twincat.--allow-enum-explicit-valuesAllow a member of an enumeration declaration to be given an explicit value (e.g.
(Deutsch := 1, English := 2)). The IEC 61131-3:2003 (Edition 2) grammar lets an enumeration list only bare member names, which take consecutive values starting at zero; explicit values were added in Edition 3. Without this flag, an explicit value produces P4055. A list of bare member names is standard syntax and is always allowed, as is a default value ((RED, GREEN, BLUE) := GREEN), which selects the initial member rather than renumbering one.--allow-enum-base-typeAllow the base-type suffix on an enumeration declaration (e.g.
(A, B) WORD), naming a base type; IronPLC stores every enumeration as aDINTwhatever it names. IEC 61131-3 has no such form — an enumerated specification is a list of member names or another enumerated type’s name, and nothing may follow it — so the suffix is an extension. Unlike--allow-enum-explicit-valuesabove it is not an Edition 3 addition; the two constructs often appear together but are separate questions. Without this flag it produces P4056, and the compiler sizes the type from the members instead.--allow-continueAllow the CONTINUE statement, which goes on with the next iteration of the innermost
FOR,WHILE, orREPEATloop.CONTINUEwas added in Edition 3. Without this flag,CONTINUEis an ordinary identifier, so aCONTINUE;statement is a syntax error and a variable may be namedcontinue.--allow-keywords-as-namesAllow the keywords
ON,STEP,R_EDGEandF_EDGEas names of variables and enumeration members, as inTYPE M : (Off, On); END_TYPEorVAR_INPUT step : DINT; END_VAR. IEC 61131-3 reserves its keywords for their own use, while other toolchains do not reserve these four. Each keyword keeps its keyword role in the same program (RESOURCE r ON PLC, anR_EDGEinput). Without this flag such a name produces P4095.--allow-conditional-returnAllow RETURN(condition), a
RETURNthat happens only when theBOOLcondition isTRUE, as if writtenIF condition THEN RETURN; END_IF;. IEC 61131-3 definesRETURNwith no operand. The condition is never the return value of a function. Without this flag it produces P4098.--allow-pou-header-semicolonAllow a semicolon after the header of a
PROGRAM,FUNCTION,FUNCTION_BLOCKorMETHOD, before its first variable block, as inFUNCTION_BLOCK FB_Motor EXTENDS FB_Base;. The IEC 61131-3 standard grammar puts no terminator after a header. The semicolon has no meaning: the declaration is the same as without it. Without this flag it produces P4100. A semicolon that a variable block does not follow is the standard empty statement at the start of the body and is always allowed.--allow-omitted-call-argumentAllow a call argument with no value (
b :=,for an input,Error=> ,for an output). It is the same as leaving the argument out. The IEC 61131-3 standard grammar gives every argument a value. Without this flag it produces P4102.--allow-trailing-call-commaAllow a comma before the closing parenthesis of a call’s argument list. The IEC 61131-3 standard grammar has no comma after the last argument. Without this flag it produces P4103.
--policy-string-to-num-non-numericALTERNATIVESelect what
STRING_TO_<numeric>treats as convertible when the string has non-numeric characters:reject(the whole string must be a literal; the default),ignore-trailing(convert the leading literal and ignore the rest), orignore-surrounding(skip to the first literal, convert it, ignore the rest). A behavior policy: the dialect selects an alternative and this flag replaces it. See Type Conversions.--policy-string-to-num-failureALTERNATIVESelect what
STRING_TO_<numeric>does when the string is not convertible:trap(halt with V4006; the default) orzero(produce zero and continue). A behavior policy: the dialect selects an alternative and this flag replaces it. See Type Conversions.
Examples¶
Check a source file for correctness:
ironplcc check main.st
Check all files in a directory:
ironplcc check src/
Compile a source file to a bytecode container:
ironplcc compile main.st -o main.iplc
Compile with verbose logging to a file:
ironplcc -vv --log-file build.log compile main.st -o main.iplc
Inspect the parsed representation of a file:
ironplcc echo main.st
Inspect the type the compiler determined for each expression:
ironplcc echo --types main.st
Check a source file using IEC 61131-3:2013 (Edition 3) features:
ironplcc check --dialect iec61131-3-ed3 main.st
Show available dialects and their features:
ironplcc dialects
See Also¶
ironplcvm — IronPLC virtual machine runtime
Overview — Getting started tutorial
Source Formats — Supported source file formats
Problem Codes — Compiler problem code index