├── .gitignore
├── .settings
└── org.eclipse.cdt.core.prefs
├── AnnexF
├── average_st.txt
├── cmd_monitor_il.txt
├── cmd_monitor_st.txt
├── delay_st.txt
├── derivative_st.txt
├── diffeq_st.txt
├── fwd_rev_mon_il.txt
├── fwd_rev_mon_st.txt
├── gravel_st.txt
├── hysteresis_st.txt
├── integral_st.txt
├── lag1_st.txt
├── pid_st.txt
├── ramp_st.txt
├── readme
├── stack_int_il.txt
├── stack_int_st.txt
├── transfer_st.txt
├── weigh_il.txt
└── weigh_st.txt
├── COPYING
├── Makefile.am
├── README.build
├── absyntax
├── Makefile.am
├── absyntax.cc
├── absyntax.def
├── absyntax.hh
├── visitor.cc
└── visitor.hh
├── absyntax_utils
├── Makefile.am
├── absyntax_utils.cc
├── absyntax_utils.hh
├── add_en_eno_param_decl.cc
├── add_en_eno_param_decl.hh
├── array_dimension_iterator.cc
├── array_dimension_iterator.hh
├── case_element_iterator.cc
├── case_element_iterator.hh
├── debug_ast.cc
├── debug_ast.hh
├── decompose_var_instance_name.cc
├── decompose_var_instance_name.hh
├── function_call_iterator.cc
├── function_call_iterator.hh
├── function_call_param_iterator.cc
├── function_call_param_iterator.hh
├── function_param_iterator.cc
├── function_param_iterator.hh
├── get_datatype_info.cc
├── get_datatype_info.hh
├── get_sizeof_datatype.cc
├── get_sizeof_datatype.hh
├── get_var_name.cc
├── get_var_name.hh
├── search_base_type.cc
├── search_base_type.hh
├── search_fb_instance_decl.cc
├── search_fb_instance_decl.hh
├── search_fb_typedecl.cc
├── search_fb_typedecl.hh
├── search_il_label.cc
├── search_il_label.hh
├── search_var_instance_decl.cc
├── search_var_instance_decl.hh
├── search_varfb_instance_type.cc
├── search_varfb_instance_type.hh
├── spec_init_separator.cc
├── spec_init_separator.hh
├── type_initial_value.cc
└── type_initial_value.hh
├── common.mk
├── config
├── INSTALL
├── aclocal.m4
├── depcomp
├── install-sh
├── libtool.m4
├── ltmain.sh
├── ltoptions.m4
├── ltsugar.m4
├── ltversion.m4
├── lt~obsolete.m4
├── missing
└── ylwrap
├── configure.ac
├── debian
├── README.Debian
├── changelog
├── compat
├── control
├── copyright
├── dirs
├── postinst
├── postrm
└── rules
├── lib
├── C
│ ├── accessor.h
│ ├── iec_std_FB.h
│ ├── iec_std_FB_no_ENENO.h
│ ├── iec_std_functions.h
│ ├── iec_std_lib.h
│ ├── iec_types.h
│ └── iec_types_all.h
├── COPYING.LESSER
├── bistable.txt
├── counter.txt
├── create_standard_function_txt.sh
├── derivative_st.txt
├── edge_detection.txt
├── hysteresis_st.txt
├── ieclib.txt
├── integral_st.txt
├── pid_st.txt
├── ramp_st.txt
├── rtc.txt
├── sema.txt
├── standard_FB.txt
├── standard_functions.txt
├── test_iec_std_lib.c
└── timer.txt
├── main.cc
├── main.hh
├── readme
├── stage1_2
├── .cvsignore
├── Makefile.am
├── create_enumtype_conversion_functions.cc
├── create_enumtype_conversion_functions.hh
├── iec_bison.yy
├── iec_flex.ll
├── stage1_2.cc
├── stage1_2.hh
├── stage1_2_priv.hh
└── standard_function_names.c
├── stage3
├── Makefile.am
├── TODO
├── array_range_check.cc
├── array_range_check.hh
├── case_elements_check.cc
├── case_elements_check.hh
├── constant_folding.cc
├── constant_folding.hh
├── datatype_functions.cc
├── datatype_functions.hh
├── declaration_check.cc
├── declaration_check.hh
├── enum_declaration_check.cc
├── enum_declaration_check.hh
├── fill_candidate_datatypes.cc
├── fill_candidate_datatypes.hh
├── flow_control_analysis.cc
├── flow_control_analysis.hh
├── forced_narrow_candidate_datatypes.cc
├── forced_narrow_candidate_datatypes.hh
├── lvalue_check.cc
├── lvalue_check.hh
├── narrow_candidate_datatypes.cc
├── narrow_candidate_datatypes.hh
├── print_datatypes_error.cc
├── print_datatypes_error.hh
├── remove_forward_dependencies.cc
├── remove_forward_dependencies.hh
├── stage3.cc
└── stage3.hh
├── stage4
├── Makefile.am
├── generate_c
│ ├── .cvsignore
│ ├── Makefile.am
│ ├── generate_c.cc
│ ├── generate_c.hh
│ ├── generate_c_base.cc
│ ├── generate_c_configbody.cc
│ ├── generate_c_il.cc
│ ├── generate_c_inlinefcall.cc
│ ├── generate_c_sfc.cc
│ ├── generate_c_sfcdecl.cc
│ ├── generate_c_st.cc
│ ├── generate_c_typedecl.cc
│ ├── generate_c_vardecl.cc
│ ├── generate_location_list.cc
│ ├── generate_var_list.cc
│ ├── plc.h
│ └── types.h
├── generate_cc
│ └── .cvsignore
├── generate_iec
│ ├── .cvsignore
│ ├── Makefile.am
│ ├── generate_iec.cc
│ └── generate_iec.hh
├── stage4.cc
└── stage4.hh
├── tests
├── .cvsignore
├── LD_TEST.xml
├── SFC_TEST.xml
├── STD_TEST.xml
├── build.sh
├── build_win32.sh
├── main.c
├── plc.c
└── syntax
│ ├── configuration
│ └── configuration.txt
│ ├── enumeration
│ └── enumerationvalue.txt
│ ├── identifier
│ ├── Makefile
│ ├── basic_code.test
│ ├── identifier.txt
│ ├── identifier_as_configuration.test
│ ├── identifier_as_datatype.test
│ ├── identifier_as_enumerationvalue.test
│ ├── identifier_as_function1.test
│ ├── identifier_as_function2.test
│ ├── identifier_as_functionblock.test
│ ├── identifier_as_label.test
│ ├── identifier_as_program.test
│ ├── identifier_as_variable1.test
│ ├── identifier_as_variable2.test
│ ├── identifier_in_sfc.test
│ └── runtests
│ └── sfc
│ └── sfc.txt
└── util
├── dsymtable.cc
├── dsymtable.hh
├── strdup.hh
├── symtable.cc
└── symtable.hh
/.gitignore:
--------------------------------------------------------------------------------
1 | # Desktop enviroment #
2 | ######################
3 | *.directory
4 |
5 | # IDE files, etc #
6 | ##################
7 | *~
8 | *.orig
9 | *.dep
10 | *.depend
11 | *.Po
12 |
13 | # Compiled Object files #
14 | #########################
15 | *.slo
16 | *.lo
17 | *.o
18 | *.obj
19 |
20 | # Precompiled Headers #
21 | #######################
22 | *.gch
23 | *.pch
24 |
25 | # Compiled Dynamic libraries #
26 | ##############################
27 | *.so
28 | *.dylib
29 | *.dll
30 |
31 | # Fortran module files #
32 | ########################
33 | *.mod
34 |
35 | # Compiled Static libraries #
36 | #############################
37 | *.lai
38 | *.la
39 | *.a
40 | *.lib
41 |
42 | # Executables #
43 | ###############
44 | *.exe
45 | *.out
46 | *.app
47 |
48 | # Automake, etc #
49 | #################
50 | autom4te.cache
51 | Makefile
52 | Makefile.in
53 | config.log
54 | stamp-h1
55 | config.status
56 | configure
57 | aclocal.m4
58 |
59 | # Specific files #
60 | ##################
61 |
62 | iec2c
63 | iec2iec
64 |
65 | stage1_2/iec_bison.cc
66 | stage1_2/iec_bison.h*
67 | stage1_2/iec_flex.cc
68 | config/config.h*
69 | test/**
70 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.cdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jan 31 15:26:34 CET 2007
2 | eclipse.preferences.version=1
3 | indexerId=org.eclipse.cdt.core.fastIndexer
4 |
--------------------------------------------------------------------------------
/AnnexF/average_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK AVERAGE
2 | VAR_INPUT
3 | RUN : BOOL ; (* 1 = run, 0 = reset *)
4 | XIN : REAL ; (* Input variable *)
5 | N : INT ; (* 0 <= N < 128 or manufacturer- *)
6 | END_VAR (* specified maximum value *)
7 | VAR_OUTPUT XOUT : REAL ; END_VAR (* Averaged output *)
8 | VAR SUM : REAL := 0.0; (* Running sum *)
9 | FIFO : DELAY ; (* N-Element FIFO *)
10 | END_VAR
11 | SUM := SUM - FIFO.XOUT ;
12 | FIFO (RUN := RUN , XIN := XIN, N := N) ;
13 | SUM := SUM + FIFO.XOUT ;
14 | IF RUN THEN XOUT := SUM/N ;
15 | ELSE SUM := N*XIN ; XOUT := XIN ;
16 | END_IF ;
17 | END_FUNCTION_BLOCK
18 |
19 |
--------------------------------------------------------------------------------
/AnnexF/cmd_monitor_il.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK CMD_MONITOR
2 | VAR_INPUT AUTO_CMD : BOOL ; (* Automated command *)
3 | AUTO_MODE : BOOL ; (* AUTO_CMD enable *)
4 | MAN_CMD : BOOL ; (* Manual Command *)
5 | MAN_CMD_CHK : BOOL ; (* Negated MAN_CMD to debounce *)
6 | T_CMD_MAX : TIME ; (* Max time from CMD to FDBK *)
7 | FDBK : BOOL ; (* Confirmation of CMD completion
8 | by operative unit *)
9 | ACK : BOOL ; (* Acknowledge/cancel ALRM *)
10 | END_VAR
11 | VAR_OUTPUT CMD : BOOL ; (* Command to operative unit *)
12 | ALRM : BOOL ; (* T_CMD_MAX expired without FDBK *)
13 | END_VAR
14 | VAR CMD_TMR : TON ; (* CMD-to-FDBK timer *)
15 | ALRM_FF : SR ; (* Note over-riding S input: *)
16 | END_VAR (* Command must be cancelled before
17 | "ACK" can cancel alarm *)
18 | (* Function Block Body *)
19 | LD T_CMD_MAX
20 | ST CMD_TMR.PT (* Store an input to the TON FB *)
21 | LD AUTO_CMD
22 | AND AUTO_MODE
23 | OR( MAN_CMD
24 | ANDN AUTO_MODE
25 | ANDN MAN_CMD_CHK
26 | )
27 | ST CMD
28 | IN CMD_TMR (* Invoke the TON FB *)
29 | LD CMD_TMR.Q
30 | ANDN FDBK
31 | ST ALRM_FF.S1 (* Store an input to the SR FB *)
32 | LD ACK
33 | R ALRM_FF (* Invoke the SR FB *)
34 | LD ALRM_FF.Q1
35 | ST ALRM
36 |
37 | END_FUNCTION_BLOCK
38 |
--------------------------------------------------------------------------------
/AnnexF/cmd_monitor_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK CMD_MONITOR
2 | VAR_INPUT AUTO_CMD : BOOL ; (* Automated command *)
3 | AUTO_MODE : BOOL ; (* AUTO_CMD enable *)
4 | MAN_CMD : BOOL ; (* Manual Command *)
5 | MAN_CMD_CHK : BOOL ; (* Negated MAN_CMD to debounce *)
6 | T_CMD_MAX : TIME ; (* Max time from CMD to FDBK *)
7 | FDBK : BOOL ; (* Confirmation of CMD completion
8 | by operative unit *)
9 | ACK : BOOL ; (* Acknowledge/cancel ALRM *)
10 | END_VAR
11 | VAR_OUTPUT CMD : BOOL ; (* Command to operative unit *)
12 | ALRM : BOOL ; (* T_CMD_MAX expired without FDBK *)
13 | END_VAR
14 | VAR CMD_TMR : TON ; (* CMD-to-FDBK timer *)
15 | ALRM_FF : SR ; (* Note over-riding S input: *)
16 | END_VAR (* Command must be cancelled before
17 | "ACK" can cancel alarm *)
18 | (* Function Block Body *)
19 | CMD := AUTO_CMD & AUTO_MODE
20 | OR MAN_CMD & NOT MAN_CMD_CHK & NOT AUTO_MODE ;
21 | CMD_TMR (IN := CMD, PT := T_CMD_MAX);
22 | ALRM_FF (S1 := CMD_TMR.Q & NOT FDBK, R := ACK);
23 | ALRM := ALRM_FF.Q1;
24 |
25 | END_FUNCTION_BLOCK
26 |
--------------------------------------------------------------------------------
/AnnexF/delay_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK DELAY (* N-sample delay *)
2 | VAR_INPUT
3 | RUN : BOOL ; (* 1 = run, 0 = reset *)
4 | XIN : REAL ;
5 | N : INT (* 0 <= N < 128 or manufacturer- *)
6 | END_VAR (* specified maximum value *)
7 | VAR_OUTPUT XOUT : REAL; END_VAR (* Delayed output *)
8 | VAR X : ARRAY [0..127] (* N-Element queue *)
9 | OF REAL; (* with FIFO discipline *)
10 | I, IXIN, IXOUT : INT := 0;
11 | END_VAR
12 | IF RUN THEN IXIN := MOD(IXIN + 1, 128) ; X[IXIN] := XIN ;
13 | IXOUT := MOD(IXOUT + 1, 128) ; XOUT := X[IXOUT];
14 | ELSE XOUT := XIN ; IXIN := N ; IXOUT := 0;
15 | FOR I := 0 TO N DO X[I] := XIN; END_FOR;
16 | END_IF ;
17 | END_FUNCTION_BLOCK
18 |
19 |
--------------------------------------------------------------------------------
/AnnexF/derivative_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK DERIVATIVE
2 | VAR_INPUT
3 | RUN : BOOL ; (* 0 = reset *)
4 | XIN : REAL ; (* Input to be differentiated *)
5 | CYCLE : TIME ; (* Sampling period *)
6 | END_VAR
7 | VAR_OUTPUT
8 | XOUT : REAL ; (* Differentiated output *)
9 | END_VAR
10 | VAR X1, X2, X3 : REAL ; END_VAR
11 | IF RUN THEN
12 | XOUT := (3.0 * (XIN - X3) + X1 - X2)
13 | / (10.0 * TIME_TO_REAL(CYCLE)) ;
14 | X3 := X2 ; X2 := X1 ; X1 := XIN ;
15 | ELSE XOUT := 0.0; X1 := XIN ; X2 := XIN ; X3 := XIN ;
16 | END_IF ;
17 | END_FUNCTION_BLOCK
18 |
19 |
--------------------------------------------------------------------------------
/AnnexF/diffeq_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK DIFFEQ
2 | VAR_INPUT
3 | RUN : BOOL ; (* 1 = run, 0 = reset *)
4 | XIN : REAL ;
5 | A : ARRAY[1..] OF REAL ; (* Input coefficients *)
6 | M : INT ; (* Length of input history *)
7 | B : ARRAY[0..] OF REAL ; (* Output coefficients *)
8 | N : INT ; (* Length of output history *)
9 | END_VAR
10 | VAR_OUTPUT XOUT : REAL := 0.0 ; END_VAR
11 | VAR (* NOTE : Manufacturer may specify other array sizes *)
12 | XI : ARRAY [0..128] OF REAL ; (* Input history *)
13 | XO : ARRAY [0..128] OF REAL ; (* Output history *)
14 | I : INT ;
15 | END_VAR
16 | XO[0] := XOUT ; XI[0] := XIN ;
17 | XOUT := B[0] * XIN ;
18 | IF RUN THEN
19 | FOR I := M TO 1 BY -1 DO
20 | XOUT := XOUT + A[I] * XO[I] ; XO[I] := XO[I-1];
21 | END_FOR;
22 | FOR I := N TO 1 BY -1 DO
23 | XOUT := XOUT + B[I] * XI[I] ; XI[I] := XI[I-1];
24 | END_FOR;
25 | ELSE
26 | FOR I := 1 TO M DO XO[I] := 0.0; END_FOR;
27 | FOR I := 1 TO N DO XI[I] := 0.0; END_FOR;
28 | END_IF ;
29 | END_FUNCTION_BLOCK
30 |
31 |
--------------------------------------------------------------------------------
/AnnexF/fwd_rev_mon_il.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK FWD_REV_MON
2 | VAR_INPUT AUTO : BOOL ;(* Enable automated commands *)
3 | ACK : BOOL ; (* Acknowledge/cancel all alarms *)
4 | AUTO_FWD : BOOL ; (* Automated forward command *)
5 | MAN_FWD : BOOL ; (* Manual forward command *)
6 | MAN_FWD_CHK : BOOL ; (* Negated MAN_FWD for debouncing *)
7 | T_FWD_MAX : TIME ; (* Maximum time from FWD_CMD to FWD_FDBK *)
8 | FWD_FDBK : BOOL ; (* Confirmation of FWD_CMD completion *)
9 | (* by operative unit *)
10 | AUTO_REV : BOOL ; (* Automated reverse command *)
11 | MAN_REV : BOOL ; (* Manual reverse command *)
12 | MAN_REV_CHK : BOOL ; (* Negated MAN_REV for debouncing *)
13 | T_REV_MAX : TIME ; (* Maximum time from REV_CMD to REV_FDBK *)
14 | REV_FDBK : BOOL ; (* Confirmation of REV_CMD completion *)
15 | END_VAR (* by operative unit *)
16 | VAR_OUTPUT KLAXON : BOOL ; (* Any alarm active *)
17 | FWD_REV_ALRM : BOOL; (* Forward/reverse command conflict *)
18 | FWD_CMD : BOOL ; (* "Forward" command to operative unit *)
19 | FWD_ALRM : BOOL ; (* T_FWD_MAX expired without FWD_FDBK *)
20 | REV_CMD : BOOL ; (* "Reverse" command to operative unit *)
21 | REV_ALRM : BOOL ; (* T_REV_MAX expired without REV_FDBK *)
22 | END_VAR
23 | VAR FWD_MON : CMD_MONITOR; (* "Forward" command monitor *)
24 | REV_MON : CMD_MONITOR; (* "Reverse" command monitor *)
25 | FWD_REV_FF : SR ; (* Forward/Reverse contention latch *)
26 | END_VAR
27 | (* Function Block body *)
28 | LD AUTO (* Load common inputs *)
29 | ST FWD_MON.AUTO_MODE
30 | ST REV_MON.AUTO_MODE
31 | LD ACK
32 | ST FWD_MON.ACK
33 | ST REV_MON.ACK
34 | ST FWD_REV_FF.R
35 | LD AUTO_FWD (* Load inputs to FWD_MON *)
36 | ST FWD_MON.AUTO_CMD
37 | LD MAN_FWD
38 | ST FWD_MON.MAN_CMD
39 | LD MAN_FWD_CHK
40 | ST FWD_MON.MAN_CMD_CHK
41 | LD T_FWD_MAX
42 | ST FWD_MON.T_CMD_MAX
43 | LD FWD_FDBK
44 | ST FWD_MON.FDBK
45 | CAL FWD_MON (* Activate FWD_MON *)
46 | LD AUTO_REV (* Load inputs to REV_MON *)
47 | ST REV_MON.AUTO_CMD
48 | LD MAN_REV
49 | ST REV_MON.MAN_CMD
50 | LD MAN_REV_CHK
51 | ST REV_MON.MAN_CMD_CHK
52 | LD T_REV_MAX
53 | ST REV_MON.T_CMD_MAX
54 | LD REV_FDBK
55 | ST REV_MON.FDBK
56 | CAL REV_MON (* Activate REV_MON *)
57 | LD FWD_MON.CMD (* Check for contention *)
58 | AND REV_MON.CMD
59 | S1 FWD_REV_FF (* Latch contention condition *)
60 | LD FWD_REV_FF.Q
61 | ST FWD_REV_ALRM (* Contention alarm *)
62 | LD FWD_MON.CMD (* "Forward" command and alarm *)
63 | ANDN FWD_REV_ALRM
64 | ST FWD_CMD
65 | LD FWD_MON.ALRM
66 | ST FWD_ALRM
67 | LD REV_MON.CMD (* "Reverse" command and alarm *)
68 | ANDN FWD_REV_ALRM
69 | ST REV_CMD
70 | LD REV_MON.ALRM
71 | ST REV_ALRM
72 | OR FWD_ALRM (* OR all alarms *)
73 | OR FWD_REV_ALRM
74 | ST KLAXON
75 |
76 | END_FUNCTION_BLOCK
77 |
78 |
--------------------------------------------------------------------------------
/AnnexF/fwd_rev_mon_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK FWD_REV_MON
2 | VAR_INPUT AUTO : BOOL ;(* Enable automated commands *)
3 | ACK : BOOL ; (* Acknowledge/cancel all alarms *)
4 | AUTO_FWD : BOOL ; (* Automated forward command *)
5 | MAN_FWD : BOOL ; (* Manual forward command *)
6 | MAN_FWD_CHK : BOOL ; (* Negated MAN_FWD for debouncing *)
7 | T_FWD_MAX : TIME ; (* Maximum time from FWD_CMD to FWD_FDBK *)
8 | FWD_FDBK : BOOL ; (* Confirmation of FWD_CMD completion *)
9 | (* by operative unit *)
10 | AUTO_REV : BOOL ; (* Automated reverse command *)
11 | MAN_REV : BOOL ; (* Manual reverse command *)
12 | MAN_REV_CHK : BOOL ; (* Negated MAN_REV for debouncing *)
13 | T_REV_MAX : TIME ; (* Maximum time from REV_CMD to REV_FDBK *)
14 | REV_FDBK : BOOL ; (* Confirmation of REV_CMD completion *)
15 | END_VAR (* by operative unit *)
16 | VAR_OUTPUT KLAXON : BOOL ; (* Any alarm active *)
17 | FWD_REV_ALRM : BOOL; (* Forward/reverse command conflict *)
18 | FWD_CMD : BOOL ; (* "Forward" command to operative unit *)
19 | FWD_ALRM : BOOL ; (* T_FWD_MAX expired without FWD_FDBK *)
20 | REV_CMD : BOOL ; (* "Reverse" command to operative unit *)
21 | REV_ALRM : BOOL ; (* T_REV_MAX expired without REV_FDBK *)
22 | END_VAR
23 | VAR FWD_MON : CMD_MONITOR; (* "Forward" command monitor *)
24 | REV_MON : CMD_MONITOR; (* "Reverse" command monitor *)
25 | FWD_REV_FF : SR ; (* Forward/Reverse contention latch *)
26 | END_VAR
27 | (* Function Block body *)
28 | (* Evaluate internal function blocks *)
29 | FWD_MON (AUTO_MODE := AUTO,
30 | ACK := ACK,
31 | AUTO_CMD := AUTO_FWD,
32 | MAN_CMD := MAN_FWD,
33 | MAN_CMD_CHK := MAN_FWD_CHK,
34 | T_CMD_MAX := T_FWD_MAX,
35 | FDBK := FWD_FDBK);
36 | REV_MON (AUTO_MODE := AUTO,
37 | ACK := ACK,
38 | AUTO_CMD := AUTO_REV,
39 | MAN_CMD := MAN_REV,
40 | MAN_CMD_CHK := MAN_REV_CHK,
41 | T_CMD_MAX := T_REV_MAX,
42 | FDBK := REV_FDBK);
43 | FWD_REV_FF (S1 := FWD_MON.CMD & REV_MON.CMD, R := ACK);
44 | (* Transfer data to outputs *)
45 | FWD_REV_ALRM := FWD_REV_FF.Q1;
46 | FWD_CMD := FWD_MON.CMD & NOT FWD_REV_ALRM;
47 | FWD_ALRM := FWD_MON.ALRM;
48 | REV_CMD := REV_MON.CMD & NOT FWD_REV_ALRM;
49 | REV_ALRM := REV_MON.ALRM;
50 | KLAXON := FWD_ALRM OR REV_ALRM OR FWD_REV_ALRM;
51 |
52 | END_FUNCTION_BLOCK
53 |
54 |
--------------------------------------------------------------------------------
/AnnexF/gravel_st.txt:
--------------------------------------------------------------------------------
1 | PROGRAM GRAVEL (* Gravel measurement and loading system *)
2 | VAR_INPUT
3 | OFF_PB : BOOL ;
4 | ON_PB : BOOL ;
5 | FILL_PB : BOOL ;
6 | SIREN_ACK : BOOL ;
7 | LOAD_PB : BOOL ; (* Load truck from bin *)
8 | JOG_PB : BOOL ;
9 | LAMP_TEST : BOOL ;
10 | TRUCK_ON_RAMP : BOOL ; (* Optical sensor *)
11 | SILO_EMPTY_LS : BOOL ;
12 | BIN_EMPTY_LS : BOOL ;
13 | SETPOINT : BYTE ; (* 2-digit BCD *)
14 | END_VAR
15 | VAR_OUTPUT
16 | CONTROL_LAMP : BOOL ;
17 | TRUCK_LAMP : BOOL ;
18 | SILO_EMPTY_LAMP : BOOL ;
19 | CONVEYOR_LAMP : BOOL ;
20 | CONVEYOR_MOTOR : BOOL ;
21 | SILO_VALVE : BOOL ;
22 | BIN_VALVE : BOOL ;
23 | SIREN : BOOL ;
24 | BIN_LEVEL : BYTE ;
25 | END_VAR
26 | VAR
27 | BLINK_TIME : TIME; (* BLINK ON/OFF time *)
28 | PULSE_TIME : TIME; (* LEVEL_CTR increment interval *)
29 | RUNOUT_TIME: TIME; (* Conveyor running time after loading *)
30 | RUN_IN_TIME: TIME; (* Conveyor running time before loading *)
31 | SILENT_TIME: TIME; (* Siren silent time after SIREN_ACK *)
32 | OK_TO_RUN : BOOL; (* 1 = Conveyor is allowed to run *)
33 | (* Function Blocks *)
34 | BLINK: TON; (* Blinker OFF period timer / ON output *)
35 | BLANK: TON; (* Blinker ON period timer / blanking pulse *)
36 | PULSE: TON; (* LEVEL_CTR pulse interval timer *)
37 | SIREN_FF: RS;
38 | SILENCE_TMR: TP; (* Siren silent period timer *)
39 | END_VAR
40 | VAR RETAIN LEVEL_CTR : CTU ; END_VAR
41 | (* Program body *)
42 | (* Major operating states *)
43 | INITIAL_STEP START : END_STEP
44 | TRANSITION FROM START TO FILL_BIN
45 | := FILL_PB & CONTROL.X ; END_TRANSITION
46 | STEP FILL_BIN: SILO_VALVE(N); END_STEP
47 | TRANSITION FROM FILL_BIN TO START
48 | := NOT FILL_PB OR NOT CONTROL.X ; END_TRANSITION
49 | TRANSITION FROM FILL_BIN TO LOAD_WAIT := LEVEL_CTR.Q ;
50 | END_TRANSITION
51 | STEP LOAD_WAIT : END_STEP
52 | TRANSITION FROM LOAD_WAIT TO RUN_IN
53 | := LOAD_PB & OK_TO_RUN ; END_TRANSITION
54 | STEP RUN_IN : END_STEP
55 | TRANSITION FROM RUN_IN TO LOAD_WAIT := NOT OK_TO_RUN ;
56 | END_TRANSITION
57 | TRANSITION FROM RUN_IN TO DUMP_BIN
58 | := RUN_IN.T > RUN_IN_TIME;
59 | END_TRANSITION
60 | STEP DUMP_BIN: BIN_VALVE(N); END_STEP
61 | TRANSITION FROM DUMP_BIN TO LOAD_WAIT := NOT OK_TO_RUN ;
62 | END_TRANSITION
63 | TRANSITION FROM DUMP_BIN TO RUNOUT := BIN_EMPTY_LS ;
64 | END_TRANSITION
65 | STEP RUNOUT : END_STEP
66 | TRANSITION FROM RUNOUT TO LOAD_WAIT := NOT OK_TO_RUN ;
67 | END_TRANSITION
68 | TRANSITION FROM RUNOUT TO START
69 | := RUNOUT.T >= RUNOUT_TIME ; END_TRANSITION
70 | (* Control state sequencing *)
71 | INITIAL_STEP CONTROL_OFF: END_STEP
72 | TRANSITION FROM CONTROL_OFF TO CONTROL
73 | := ON_PB & NOT OFF_PB ; END_TRANSITION
74 | STEP CONTROL: CONTROL_ACTION(N); END_STEP
75 | ACTION CONTROL_ACTION:
76 | BLINK(EN:=CONTROL.X & NOT BLANK.Q, PT := BLINK_TIME) ;
77 | BLANK(EN:=BLINK.Q, PT := BLINK_TIME) ;
78 | OK_TO_RUN := CONTROL.X & TRUCK_ON_RAMP ;
79 | CONVEYOR_MOTOR :=
80 | OK_TO_RUN & OR(JOG_PB, RUN_IN.X, DUMP_BIN.X, RUNOUT.X);
81 | END_ACTION
82 | TRANSITION FROM CONTROL TO CONTROL_OFF := OFF_PB ;
83 | END_TRANSITION
84 | (* Monitor Logic *)
85 | INITIAL_STEP MONITOR: MONITOR_ACTION(N); END_STEP
86 | ACTION MONITOR_ACTION:
87 | CONVEYOR_LAMP := CONVEYOR_MOTOR & BLINK.Q ;
88 | CONTROL_LAMP := CONTROL.X OR LAMP_TEST ;
89 | TRUCK_LAMP := TRUCK_ON_RAMP OR LAMP_TEST ;
90 | SILO_EMPTY_LAMP := BLINK.Q & SILO_EMPTY_LS OR LAMP_TEST ;
91 | SILENCE_TMR(IN:=SIREN_ACK, PT:=SILENT_TIME) ;
92 | SIREN_FF(S:=SILO_EMPTY_LS, R1:=SILENCE_TMR.Q) ;
93 | SIREN := SIREN_FF.Q1 ;
94 | PULSE(IN:=FILL_BIN.X & NOT PULSE.Q, PT:=PULSE_TIME) ;
95 | LEVEL_CTR(R := BIN_EMPTY_LS, CU := PULSE.Q,
96 | PV := BCD_TO_INT(SETPOINT)) ;
97 | BIN_LEVEL := INT_TO_BCD(LEVEL_CTR.CV) ;
98 | END_ACTION
99 |
100 | END_PROGRAM
101 |
102 | CONFIGURATION GRAVEL_CONTROL
103 | RESOURCE PROC1 ON PROC_TYPE_Y
104 | PROGRAM G : GRAVEL
105 | (* Inputs *)
106 | (OFF_PB := %I0.0 ,
107 | ON_PB := %I0.1 ,
108 | FILL_PB := %I0.2 ,
109 | SIREN_ACK := %I0.3 ,
110 | LOAD_PB := %I0.4 ,
111 | JOG_PB := %I0.5 ,
112 | LAMP_TEST := %I0.7 ,
113 | TRUCK_ON_RAMP := %I1.4 ,
114 | SILO_EMPTY_LS := %I1.5 ,
115 | BIN_EMPTY_LS := %I1.6 ,
116 | SETPOINT := %IB2 ,
117 | (* Outputs *)
118 | CONTROL_LAMP => %Q4.0,
119 | TRUCK_LAMP => %Q4.2,
120 | SILO_EMPTY_LAMP => %Q4.3,
121 | CONVEYOR_LAMP => %Q5.3,
122 | CONVEYOR_MOTOR => %Q5.4,
123 | SILO_VALVE => %Q5.5,
124 | BIN_VALVE => %Q5.6,
125 | SIREN => %Q5.7,
126 | BIN_LEVEL => %B6) ;
127 | END_RESOURCE
128 | END_CONFIGURATION
129 |
130 |
--------------------------------------------------------------------------------
/AnnexF/hysteresis_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK HYSTERESIS
2 | (* Boolean hysteresis on difference *)
3 | (* of REAL inputs, XIN1 - XIN2 *)
4 | VAR_INPUT XIN1, XIN2, EPS : REAL; END_VAR
5 | VAR_OUTPUT Q : BOOL := 0; END_VAR
6 | IF Q THEN IF XIN1 < (XIN2 - EPS) THEN Q := 0; END_IF ;
7 | ELSIF XIN1 > (XIN2 + EPS) THEN Q := 1 ;
8 | END_IF ;
9 | END_FUNCTION_BLOCK
10 |
11 |
--------------------------------------------------------------------------------
/AnnexF/integral_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK INTEGRAL
2 | VAR_INPUT
3 | RUN : BOOL ; (* 1 = integrate, 0 = hold *)
4 | R1 : BOOL ; (* Overriding reset *)
5 | XIN : REAL ; (* Input variable *)
6 | X0 : REAL ; (* Initial value *)
7 | CYCLE : TIME ; (* Sampling period *)
8 | END_VAR
9 | VAR_OUTPUT
10 | Q : BOOL ; (* NOT R1 *)
11 | XOUT : REAL ; (* Integrated output *)
12 | END_VAR
13 | Q := NOT R1 ;
14 | IF R1 THEN XOUT := X0 ;
15 | ELSIF RUN THEN XOUT := XOUT + XIN * TIME_TO_REAL(CYCLE);
16 | END_IF ;
17 | END_FUNCTION_BLOCK
18 |
19 |
--------------------------------------------------------------------------------
/AnnexF/lag1_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK LAG1
2 | VAR_INPUT
3 | RUN : BOOL ; (* 1 = run, 0 = reset *)
4 | XIN : REAL ; (* Input variable *)
5 | TAU : TIME ; (* Filter time constant *)
6 | CYCLE : TIME ; (* Sampling time interval *)
7 | END_VAR
8 | VAR_OUTPUT XOUT : REAL ; END_VAR (* Filtered output *)
9 | VAR K : REAL ; (* Smoothing constant, 0.0<=K<1.0 *)
10 | END_VAR
11 | IF RUN THEN XOUT := XOUT + K * (XIN - XOUT) ;
12 | ELSE XOUT := XIN ;
13 | K := TIME_TO_REAL(CYCLE) / TIME_TO_REAL(CYCLE + TAU) ;
14 | END_IF ;
15 | END_FUNCTION_BLOCK
16 |
17 |
--------------------------------------------------------------------------------
/AnnexF/pid_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK PID
2 | VAR_INPUT
3 | AUTO : BOOL ; (* 0 - manual , 1 - automatic *)
4 | PV : REAL ; (* Process variable *)
5 | SP : REAL ; (* Set point *)
6 | X0 : REAL ; (* Manual output adjustment - *)
7 | (* Typically from transfer station *)
8 | KP : REAL ; (* Proportionality constant *)
9 | TR : REAL ; (* Reset time *)
10 | TD : REAL ; (* Derivative time constant *)
11 | CYCLE : TIME ; (* Sampling period *)
12 | END_VAR
13 | VAR_OUTPUT XOUT : REAL; END_VAR
14 | VAR ERROR : REAL ; (* PV - SP *)
15 | ITERM : INTEGRAL ; (* FB for integral term *)
16 | DTERM : DERIVATIVE ; (* FB for derivative term *)
17 | END_VAR
18 | ERROR := PV - SP ;
19 | (*** Adjust ITERM so that XOUT := X0 when AUTO = 0 ***)
20 | ITERM (RUN := AUTO, R1 := NOT AUTO, XIN := ERROR,
21 | X0 := TR * (X0 - ERROR), CYCLE := CYCLE) ;
22 | DTERM (RUN := AUTO, XIN := ERROR, CYCLE := CYCLE) ;
23 | XOUT := KP * (ERROR + ITERM.XOUT/TR + DTERM.XOUT*TD) ;
24 | END_FUNCTION_BLOCK
25 |
26 |
--------------------------------------------------------------------------------
/AnnexF/ramp_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK RAMP
2 | VAR_INPUT
3 | RUN : BOOL ; (* 0 - track X0, 1 - ramp to/track X1 *)
4 | X0,X1 : REAL ;
5 | TR : TIME ; (* Ramp duration *)
6 | CYCLE : TIME ; (* Sampling period *)
7 | END_VAR
8 | VAR_OUTPUT
9 | BUSY : BOOL ; (* BUSY = 1 during ramping period *)
10 | XOUT : REAL := 0.0 ;
11 | END_VAR
12 | VAR XI : REAL ; (* Initial value *)
13 | T : TIME := T#0s; (* Elapsed time of ramp *)
14 | END_VAR
15 | BUSY := RUN ;
16 | IF RUN THEN
17 | IF T >= TR THEN BUSY := 0 ; XOUT := X1 ;
18 | ELSE XOUT := XI + (X1-XI) * TIME_TO_REAL(T)
19 | / TIME_TO_REAL(TR) ;
20 | T := T + CYCLE ;
21 | END_IF ;
22 | ELSE XOUT := X0 ; XI := X0 ; T := t#0s ;
23 | END_IF ;
24 | END_FUNCTION_BLOCK
25 |
26 |
--------------------------------------------------------------------------------
/AnnexF/readme:
--------------------------------------------------------------------------------
1 | IEC 61131-3 Annex F Examples (informative)
2 |
3 | This directory contains example code take from:
4 |
5 | Annex F of Draft 2nd edition of the IEC 61131-3 standard (1998)
6 | "PROGRAMMABLE CONTROLLERS - PROGRAMMING LANGUAGES"
7 |
--------------------------------------------------------------------------------
/AnnexF/stack_int_il.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK STACK_INT
2 | VAR_INPUT PUSH, POP: BOOL R_EDGE; (* Basic stack operations *)
3 | R1 : BOOL ; (* Over-riding reset *)
4 | IN : INT ; (* Input to be pushed *)
5 | N : INT ; (* Maximum depth after reset *)
6 | END_VAR
7 | VAR_OUTPUT EMPTY : BOOL := 1 ; (* Stack empty *)
8 | OFLO : BOOL := 0 ; (* Stack overflow *)
9 | OUT : INT := 0 ; (* Top of stack data *)
10 | END_VAR
11 | VAR STK : ARRAY[0..127] OF INT; (* Internal stack *)
12 | NI : INT :=128 ; (* Storage for N upon reset *)
13 | PTR : INT := -1 ; (* Stack pointer *)
14 | END_VAR
15 | (* Function Block body *)
16 | LD R1 (* Dispatch on operations *)
17 | JMPC RESET
18 | LD POP
19 | ANDN EMPTY (* Don't pop empty stack *)
20 | JMPC POP_STK
21 | LD PUSH
22 | ANDN OFLO (* Don't push overflowed stack *)
23 | JMPC PUSH_STK
24 | RET (* Return if no operations active *)
25 | RESET: LD 0 (* Stack reset operations *)
26 | ST OFLO
27 | LD 1
28 | ST EMPTY
29 | LD -1
30 | ST PTR
31 | CAL LIMIT(MN:=1,IN:=N,MX:=128)
32 | ST NI
33 | JMP ZRO_OUT
34 | POP_STK: LD 0
35 | ST OFLO (* Popped stack is not overflowing *)
36 | LD PTR
37 | SUB 1
38 | ST PTR
39 | LT 0 (* Empty when PTR < 0 *)
40 | ST EMPTY
41 | JMPC ZRO_OUT
42 | LD STK[PTR]
43 | JMP SET_OUT
44 | PUSH_STK: LD 0
45 | ST EMPTY (* Pushed stack is not empty *)
46 | LD PTR
47 | ADD 1
48 | ST PTR
49 | EQ NI (* Overflow when PTR = NI *)
50 | ST OFLO
51 | JMPC ZRO_OUT
52 | LD IN
53 | ST STK[PTR] (* Push IN onto STK *)
54 | JMP SET_OUT
55 | ZRO_OUT: LD 0 (* OUT=0 for EMPTY or OFLO *)
56 | SET_OUT: ST OUT
57 |
58 | END_FUNCTION_BLOCK
59 |
--------------------------------------------------------------------------------
/AnnexF/stack_int_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK STACK_INT
2 | VAR_INPUT PUSH, POP: BOOL R_EDGE; (* Basic stack operations *)
3 | R1 : BOOL ; (* Over-riding reset *)
4 | IN : INT ; (* Input to be pushed *)
5 | N : INT ; (* Maximum depth after reset *)
6 | END_VAR
7 | VAR_OUTPUT EMPTY : BOOL := 1 ; (* Stack empty *)
8 | OFLO : BOOL := 0 ; (* Stack overflow *)
9 | OUT : INT := 0 ; (* Top of stack data *)
10 | END_VAR
11 | VAR STK : ARRAY[0..127] OF INT; (* Internal stack *)
12 | NI : INT :=128 ; (* Storage for N upon reset *)
13 | PTR : INT := -1 ; (* Stack pointer *)
14 | END_VAR
15 | (* Function Block body *)
16 | IF R1 THEN
17 | OFLO := 0; EMPTY := 1; PTR := -1;
18 | NI := LIMIT (MN:=1,IN:=N,MX:=128); OUT := 0;
19 | ELSIF POP & NOT EMPTY THEN
20 | OFLO := 0; PTR := PTR-1; EMPTY := PTR < 0;
21 | IF EMPTY THEN OUT := 0;
22 | ELSE OUT := STK[PTR];
23 | END_IF ;
24 | ELSIF PUSH & NOT OFLO THEN
25 | EMPTY := 0; PTR := PTR+1; OFLO := (PTR = NI);
26 | IF NOT OFLO THEN OUT := IN ; STK[PTR] := IN;
27 | ELSE OUT := 0;
28 | END_IF ;
29 | END_IF ;
30 |
31 | END_FUNCTION_BLOCK
32 |
--------------------------------------------------------------------------------
/AnnexF/transfer_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION_BLOCK TRANSFER
2 | VAR_INPUT
3 | AUTO : BOOL ; (* 1 - track X0, 0 - ramp or hold *)
4 | XIN : REAL ; (* Typically from PID Function Block *)
5 | FAST_RATE, SLOW_RATE : REAL ; (* Up/down ramp slopes *)
6 | FAST_UP, SLOW_UP, (* Typically pushbuttons *)
7 | FAST_DOWN, SLOW_DOWN : BOOL;
8 | CYCLE : TIME ; (* Sampling period *)
9 | END_VAR
10 | VAR_OUTPUT XOUT : REAL ; END_VAR
11 | VAR XFER_RAMP : INTEGRAL ;
12 | RAMP_RATE : REAL ;
13 | END_VAR
14 | RAMP_RATE := 0.0 ;
15 | IF NOT AUTO THEN
16 | IF FAST_UP THEN RAMP_RATE := FAST_RATE; END_IF;
17 | IF SLOW_UP THEN RAMP_RATE := RAMP_RATE + SLOW_RATE; END_IF;
18 | IF FAST_DOWN THEN RAMP_RATE := RAMP_RATE - FAST_RATE; END_IF;
19 | IF SLOW_DOWN THEN RAMP_RATE := RAMP_RATE - SLOW_RATE; END_IF;
20 | END_IF ;
21 | XFER_RAMP (RUN := 1, CYCLE := CYCLE, R1 := AUTO,
22 | XIN := RAMP_RATE, X0 := XIN) ;
23 | XOUT := XFER_RAMP.XOUT;
24 | END_FUNCTION_BLOCK
25 |
26 |
--------------------------------------------------------------------------------
/AnnexF/weigh_il.txt:
--------------------------------------------------------------------------------
1 | FUNCTION WEIGH : WORD (* BCD encoded *)
2 | VAR_INPUT (* "EN" input is used to indicate "scale ready" *)
3 | weigh_command : BOOL;
4 | gross_weight : WORD ; (* BCD encoded *)
5 | tare_weight : INT ;
6 | END_VAR
7 | (* Function Body *)
8 | LD weigh_command
9 | JMPC WEIGH_NOW
10 | ST ENO (* No weighing, 0 to "ENO" *)
11 | RET
12 | WEIGH_NOW: LD gross_weight
13 | BCD_TO_INT
14 | SUB tare_weight
15 | INT_TO_BCD (* Return evaluated weight *)
16 | ST WEIGH
17 |
18 | END_FUNCTION (* Implicit "ENO" *)
19 |
--------------------------------------------------------------------------------
/AnnexF/weigh_st.txt:
--------------------------------------------------------------------------------
1 | FUNCTION WEIGH : WORD (* BCD encoded *)
2 | VAR_INPUT (* "EN" input is used to indicate "scale ready" *)
3 | weigh_command : BOOL;
4 | gross_weight : WORD ; (* BCD encoded *)
5 | tare_weight : INT ;
6 | END_VAR
7 | (* Function Body *)
8 | IF weigh_command THEN
9 | WEIGH := INT_TO_BCD (BCD_TO_INT(gross_weight) - tare_weight);
10 | END_IF ;
11 |
12 | END_FUNCTION (* Implicit "ENO" *)
13 |
--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | include common.mk
2 |
3 | bin_PROGRAMS = iec2c iec2iec
4 |
5 | SUBDIRS = absyntax absyntax_utils stage1_2 stage3 stage4
6 |
7 | ACLOCAL_AMFLAGS=-I config
8 |
9 | HGVERSION= $(shell hg -R $(top_srcdir) parents --template '{node|short}' 2> /dev/null || grep node $(top_srcdir)/.hg_archival.txt 2> /dev/null || true )
10 | AM_CXXFLAGS += -DHGVERSION="\"${HGVERSION}\""
11 |
12 | iec2c_LDADD = stage1_2/libstage1_2.a \
13 | stage3/libstage3.a \
14 | stage4/generate_c/libstage4_c.a \
15 | absyntax/libabsyntax.a \
16 | absyntax_utils/libabsyntax_utils.a
17 |
18 | iec2iec_LDADD = stage1_2/libstage1_2.a \
19 | stage3/libstage3.a \
20 | stage4/generate_iec/libstage4_iec.a \
21 | absyntax/libabsyntax.a \
22 | absyntax_utils/libabsyntax_utils.a
23 |
24 | iec2c_SOURCES = main.cc
25 |
26 | iec2iec_SOURCES = main.cc
27 |
28 |
--------------------------------------------------------------------------------
/README.build:
--------------------------------------------------------------------------------
1 |
2 | Compile/Build
3 | =============
4 |
5 | 1) Compiling under Linux
6 | ------------------------
7 | $ autoreconf -i
8 | $ ./configure
9 | $ make
10 |
11 |
12 | 2) Cross-Compiling under Linux, for Windows
13 | -------------------------------------------
14 | $ ./configure --host=i586-pc-mingw32
15 | (or, to use static linking, which does not require installing any mingw dll's on windows)
16 | $ ./configure --host=i586-pc-mingw32 LDFLAGS="-static"
17 | $ make
18 |
19 |
20 |
21 |
22 |
23 | Maintaining the Build Environment
24 | =================================
25 | -> Add new files to Makefile.am or add a new makefile
26 | $ autoreconf
27 |
28 |
29 | -> Prepare clean project
30 | $ make distclean
31 |
32 |
33 |
34 | -> Remember to add these files to your .hgignore
35 | Makefile
36 | config.*
37 | *.a
38 | .deps
39 |
40 |
41 | -> Send me TODO list to complete build system.
42 | matteo.facchinetti@sirius-es.it
43 |
44 |
--------------------------------------------------------------------------------
/absyntax/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../common.mk
2 |
3 | lib_LIBRARIES = libabsyntax.a
4 |
5 | libabsyntax_a_SOURCES = \
6 | absyntax.cc \
7 | visitor.cc
8 |
9 |
--------------------------------------------------------------------------------
/absyntax_utils/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../common.mk
2 |
3 | lib_LIBRARIES = libabsyntax_utils.a
4 |
5 | libabsyntax_utils_a_SOURCES = \
6 | absyntax_utils.cc \
7 | add_en_eno_param_decl.cc \
8 | decompose_var_instance_name.cc \
9 | array_dimension_iterator.cc \
10 | case_element_iterator.cc \
11 | function_call_iterator.cc \
12 | function_call_param_iterator.cc \
13 | function_param_iterator.cc \
14 | get_sizeof_datatype.cc \
15 | get_var_name.cc \
16 | search_il_label.cc \
17 | search_base_type.cc \
18 | search_fb_instance_decl.cc \
19 | search_fb_typedecl.cc \
20 | search_varfb_instance_type.cc \
21 | search_var_instance_decl.cc \
22 | spec_init_separator.cc \
23 | type_initial_value.cc \
24 | search_varfb_instance_type.cc \
25 | search_var_instance_decl.cc \
26 | spec_init_separator.cc \
27 | type_initial_value.cc \
28 | debug_ast.cc \
29 | get_datatype_info.cc
30 |
--------------------------------------------------------------------------------
/absyntax_utils/absyntax_utils.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * This is the main stage 3a file.
36 | *
37 | * In stage 3a some helpful symbol tables are instanciated and populated.
38 | * These symbol tables wll then be used by stage3b and atage4 code generators.
39 | */
40 |
41 |
42 |
43 |
44 | #ifndef _SEARCH_UTILS_HH
45 | #define _SEARCH_UTILS_HH
46 |
47 | // #include /* required for NULL */
48 | #include "../util/symtable.hh"
49 | #include "../util/dsymtable.hh"
50 | #include "../absyntax/absyntax.hh"
51 | #include "../absyntax/visitor.hh"
52 |
53 |
54 |
55 | /* returns 0 if the names are equal!! Case is ignored. */
56 | int compare_identifiers(symbol_c *ident1, symbol_c *ident2);
57 |
58 | /* A symbol table with all globally declared functions... */
59 | typedef dsymtable_c function_symtable_t;
60 | extern function_symtable_t function_symtable;
61 |
62 | /* A symbol table with all globally declared functions block types... */
63 | typedef symtable_c function_block_type_symtable_t;
64 | extern function_block_type_symtable_t function_block_type_symtable;
65 |
66 | /* A symbol table with all globally declared program types... */
67 | typedef symtable_c program_type_symtable_t;
68 | extern program_type_symtable_t program_type_symtable;
69 |
70 | /* A symbol table with all user declared type definitions... */
71 | /* Note that function block types and program types have their
72 | * own symbol tables, so do not get placed in this symbol table!
73 | *
74 | * The symbol_c * associated to the value will point to the data type declaration.
75 | */
76 | typedef symtable_c type_symtable_t;
77 | extern type_symtable_t type_symtable;
78 |
79 |
80 | /***********************************************************************/
81 | /***********************************************************************/
82 | /***********************************************************************/
83 | /***********************************************************************/
84 |
85 | #include "spec_init_separator.hh"
86 | #include "array_dimension_iterator.hh"
87 | #include "case_element_iterator.hh"
88 | #include "function_param_iterator.hh"
89 | #include "function_call_iterator.hh"
90 | #include "function_call_param_iterator.hh"
91 | #include "type_initial_value.hh"
92 | #include "search_fb_instance_decl.hh"
93 | #include "search_fb_typedecl.hh"
94 | #include "search_base_type.hh"
95 | #include "search_var_instance_decl.hh"
96 | #include "decompose_var_instance_name.hh"
97 | #include "search_varfb_instance_type.hh"
98 | #include "add_en_eno_param_decl.hh"
99 | #include "get_sizeof_datatype.hh"
100 | #include "search_il_label.hh"
101 | #include "get_var_name.hh"
102 | #include "get_datatype_info.hh"
103 | #include "debug_ast.hh"
104 |
105 | /***********************************************************************/
106 | /***********************************************************************/
107 | /***********************************************************************/
108 | /***********************************************************************/
109 | /***********************************************************************/
110 |
111 |
112 |
113 |
114 | void absyntax_utils_init(symbol_c *tree_root);
115 |
116 |
117 | #endif /* _SEARCH_UTILS_HH */
118 |
--------------------------------------------------------------------------------
/absyntax_utils/add_en_eno_param_decl.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Iterate through all declared functions and Function Blocks,
36 | * and, for each function/FB, add a declaration of the EN and ENO
37 | * parameters, if they have not already been explicitly declared.
38 | *
39 | * EN and ENO parameters declared explicitly (by the user in the source code)
40 | * and implicitly (by the comnpiler, i.e. by this visitor class) may be
41 | * distinguished later on by the 'method' flag in the en_param_declaration_c
42 | * and eno_param_declaration_c objects.
43 | */
44 |
45 | #ifndef _ADD_EN_ENO_PARAM_DECL_HH
46 | #define _ADD_EN_ENO_PARAM_DECL_HH
47 |
48 | #include "../absyntax/visitor.hh"
49 |
50 |
51 | class add_en_eno_param_decl_c : public null_visitor_c {
52 | public:
53 | static symbol_c *add_to(symbol_c *tree_root);
54 | ~add_en_eno_param_decl_c(void);
55 |
56 | private:
57 | /* this class is a singleton. So we need a pointer to the single instance... */
58 | static add_en_eno_param_decl_c *singleton;
59 |
60 | /* flags to remember whether the EN and/or ENO parameters have already
61 | * been explicitly declared by the user in the IEC 61131-3 source code we are parsing...
62 | */
63 | bool en_declared;
64 | bool eno_declared;
65 |
66 | private:
67 | void* iterate_list(list_c *list);
68 | input_declarations_c *build_en_param (void);
69 | output_declarations_c *build_eno_param(void);
70 |
71 | private:
72 | /***************************/
73 | /* B 0 - Programming Model */
74 | /***************************/
75 | void *visit(library_c *symbol);
76 |
77 | /***********************/
78 | /* B 1.5.1 - Functions */
79 | /***********************/
80 | void *visit(function_declaration_c *symbol);
81 | /* intermediate helper symbol for function_declaration */
82 | void *visit(var_declarations_list_c *symbol);
83 |
84 | /******************************************/
85 | /* B 1.4.3 - Declaration & Initialisation */
86 | /******************************************/
87 | void *visit(input_declarations_c *symbol);
88 | void *visit(input_declaration_list_c *symbol);
89 | void *visit(en_param_declaration_c *symbol);
90 | void *visit(eno_param_declaration_c *symbol);
91 | void *visit(output_declarations_c *symbol);
92 | void *visit(var_init_decl_list_c *symbol);
93 |
94 | /*****************************/
95 | /* B 1.5.2 - Function Blocks */
96 | /*****************************/
97 | /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
98 | void *visit(function_block_declaration_c *symbol);
99 |
100 | }; // function_param_iterator_c
101 |
102 | #endif /* _ADD_EN_ENO_PARAM_DECL_HH */
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/absyntax_utils/array_dimension_iterator.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Array dimension iterator.
36 | * Iterate through the dimensions of array specification.
37 | *
38 | * This is part of the 4th stage that generates
39 | * a c++ source program equivalent to the IL and ST
40 | * code.
41 | */
42 |
43 | /* Given a array_specification_c, iterate through
44 | * each subrange, returning the symbol of each subrange
45 | * ...array_dimension_iterator_c
46 | */
47 |
48 |
49 |
50 |
51 | #include "array_dimension_iterator.hh"
52 | #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
53 |
54 |
55 | //#define DEBUG
56 | #ifdef DEBUG
57 | #define TRACE(classname) printf("\n____%s____\n",classname);
58 | #else
59 | #define TRACE(classname)
60 | #endif
61 |
62 |
63 |
64 | void* array_dimension_iterator_c::iterate_list(list_c *list) {
65 | void *res;
66 | for (int i = 0; i < list->n; i++) {
67 | res = list->get_element(i)->accept(*this);
68 | if (res != NULL)
69 | return res;
70 | }
71 | return NULL;
72 | }
73 |
74 | /* start off at the first case element once again... */
75 | void array_dimension_iterator_c::reset(void) {
76 | current_array_dimension = NULL;
77 | }
78 |
79 |
80 | /* initialize the iterator object.
81 | * We must be given a reference to a array_specification_c that will be analyzed...
82 | */
83 | array_dimension_iterator_c::array_dimension_iterator_c(symbol_c *symbol) {
84 | /* do some consistency check... */
85 | /* NOTE: We comment out the consistency check so the compiler does not bork when it encounters buggy source code.
86 | * e.g. Code that handles a non array variable as an array!
87 | * VAR v1, v2: int; END_VAR
88 | * v1 := v2[33, 45];
89 | * The above error will be caught by the datatype checking algorithms!
90 | */
91 | array_spec_init_c * array_spec_init = dynamic_cast(symbol);
92 | if (NULL != array_spec_init) symbol = array_spec_init->array_specification;
93 | array_specification_c* array_spec = dynamic_cast(symbol);
94 | // if (NULL == array_spec) ERROR;
95 |
96 | /* OK. Now initialize this object... */
97 | this->array_specification = array_spec; // Set to array_spec and not symbol => will be NULL if not an array_specification_c* !!
98 | reset();
99 | }
100 |
101 |
102 |
103 | /* Skip to the next subrange. After object creation,
104 | * the object references on subrange _before_ the first, so
105 | * this function must be called once to get the object to
106 | * reference the first subrange...
107 | *
108 | * Returns the subrange symbol!
109 | */
110 | subrange_c *array_dimension_iterator_c::next(void) {
111 | if (NULL == array_specification) return NULL; /* The source code probably has a bug which will be caught somewhere else! */
112 | void *res = array_specification->accept(*this);
113 | if (NULL == res) return NULL;
114 |
115 | return current_array_dimension;
116 | }
117 |
118 | /********************************/
119 | /* B 1.3.3 - Derived data types */
120 | /********************************/
121 | /* signed_integer DOTDOT signed_integer */
122 | void *array_dimension_iterator_c::visit(subrange_c *symbol) {
123 | if (current_array_dimension == symbol) {
124 | current_array_dimension = NULL;
125 | }
126 | else if (current_array_dimension == NULL) {
127 | current_array_dimension = symbol;
128 | return symbol;
129 | }
130 |
131 | /* Not found! */
132 | return NULL;
133 | }
134 |
135 | /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
136 | void *array_dimension_iterator_c::visit(array_specification_c *symbol) {
137 | return symbol->array_subrange_list->accept(*this);
138 | }
139 |
140 | /* array_subrange_list ',' subrange */
141 | void *array_dimension_iterator_c::visit(array_subrange_list_c *symbol) {
142 | return iterate_list(symbol);
143 | }
144 |
145 |
--------------------------------------------------------------------------------
/absyntax_utils/array_dimension_iterator.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Array dimension iterator.
36 | * Iterate through the dimensions of array specification.
37 | *
38 | * This is part of the 4th stage that generates
39 | * a c++ source program equivalent to the IL and ST
40 | * code.
41 | */
42 |
43 | /* Given a array_specification_c, iterate through
44 | * each subrange, returning the symbol of each subrange
45 | * ...array_dimension_iterator_c
46 | */
47 |
48 |
49 | #include "../absyntax/visitor.hh"
50 |
51 |
52 | class array_dimension_iterator_c : public null_visitor_c {
53 | private:
54 | /* a pointer to the array_specification_c currently being analyzed */
55 | symbol_c *array_specification;
56 | /* used when called to iterate() for a parameter */
57 | subrange_c *current_array_dimension;
58 |
59 | private:
60 | void* iterate_list(list_c *list);
61 |
62 | public:
63 | /* start off at the first dimension once again... */
64 | void reset(void);
65 |
66 | /* initialize the iterator object.
67 | * We must be given a reference to a array_specification_c that will be analyzed...
68 | */
69 | array_dimension_iterator_c(symbol_c *symbol);
70 |
71 | /* Skip to the next subrange. After object creation,
72 | * the object references on subrange _before_ the first, so
73 | * this function must be called once to get the object to
74 | * reference the first subrange...
75 | *
76 | * Returns the subrange symbol!
77 | */
78 | subrange_c *next(void);
79 |
80 |
81 | private:
82 |
83 | /********************************/
84 | /* B 1.3.3 - Derived data types */
85 | /********************************/
86 | /* signed_integer DOTDOT signed_integer */
87 | void *visit(subrange_c *symbol);
88 |
89 | /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
90 | void *visit(array_specification_c *symbol);
91 |
92 | /* array_subrange_list ',' subrange */
93 | void *visit(array_subrange_list_c *symbol);
94 |
95 | }; // function_param_iterator_c
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/absyntax_utils/case_element_iterator.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Case element iterator.
36 | * Iterate through the elements of a case list.
37 | *
38 | * This is part of the 4th stage that generates
39 | * a c++ source program equivalent to the IL and ST
40 | * code.
41 | */
42 |
43 | /* Given a case_list_c and a type of element, iterate through
44 | * each element, returning the symbol of each element if from
45 | * the good type...case_element_iterator_c
46 | */
47 |
48 |
49 | #include "../absyntax/visitor.hh"
50 |
51 |
52 | class case_element_iterator_c : public null_visitor_c {
53 | public:
54 | /* A type to specify the type of element.
55 | */
56 | typedef enum {
57 | element_single,
58 | element_subrange
59 | } case_element_t ;
60 |
61 |
62 | private:
63 | /* a pointer to the case_list_c currently being analyzed */
64 | symbol_c *case_list;
65 | /* used when called to iterate() for a parameter */
66 | symbol_c *current_case_element;
67 |
68 | /* used to indicate the type of case element on which iterate */
69 | case_element_t wanted_element_type;
70 |
71 | private:
72 | void* handle_case_element(symbol_c *case_element);
73 |
74 | void* iterate_list(list_c *list);
75 |
76 | public:
77 | /* start off at the first case element once again... */
78 | void reset(void);
79 |
80 | /* initialize the iterator object.
81 | * We must be given a reference to a case_list_c that will be analyzed...
82 | */
83 | case_element_iterator_c(symbol_c *list, case_element_t element_type);
84 |
85 | /* Skip to the next case element of type chosen. After object creation,
86 | * the object references on case element _before_ the first, so
87 | * this function must be called once to get the object to
88 | * reference the first element...
89 | *
90 | * Returns the case element's symbol!
91 | */
92 | symbol_c *next(void);
93 |
94 | private:
95 |
96 | /******************************/
97 | /* B 1.2.1 - Numeric Literals */
98 | /******************************/
99 | void *visit(integer_c *symbol);
100 | void *visit(neg_integer_c *symbol);
101 |
102 | /********************************/
103 | /* B 1.3.3 - Derived data types */
104 | /********************************/
105 | /* signed_integer DOTDOT signed_integer */
106 | void *visit(subrange_c *symbol);
107 |
108 | /* enumerated_type_name '#' identifier */
109 | void *visit(enumerated_value_c *symbol);
110 |
111 | /********************************/
112 | /* B 3.2.3 Selection Statements */
113 | /********************************/
114 | void *visit(case_list_c *symbol);
115 |
116 |
117 |
118 | }; // function_param_iterator_c
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/absyntax_utils/debug_ast.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
4 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 |
33 | /*
34 | * Some classes to help with debuging.
35 | *
36 | * These classes will print out the current state of a symbol or a portion of the Abstract Syntax Tree.
37 | */
38 |
39 |
40 |
41 |
42 |
43 |
44 | #include "../absyntax/absyntax.hh"
45 |
46 |
47 | class debug_c {
48 | public:
49 | static void print(const_value_c cvalue);
50 | static void print(symbol_c *symbol);
51 | static void print(const char *str);
52 |
53 | /* print the AST from this point downwards */
54 | static void print_ast(symbol_c *root_symbol);
55 | };
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/absyntax_utils/function_call_iterator.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Function call parameter iterator.
36 | *
37 | * This is part of the 4th stage that generates
38 | * a c++ source program equivalent to the IL and ST
39 | * code.
40 | */
41 |
42 | /* given a function_body_c, iterate through each
43 | * function/FB call in that code.
44 | */
45 |
46 |
47 | #include "function_call_iterator.hh"
48 | #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
49 |
50 |
51 | //#define DEBUG
52 | #ifdef DEBUG
53 | #define TRACE(classname) printf("\n____%s____\n",classname);
54 | #else
55 | #define TRACE(classname)
56 | #endif
57 |
58 |
59 |
60 |
61 |
62 | /* initialise the iterator object.
63 | * We must be given a reference to the function declaration
64 | * that will be analysed...
65 | */
66 | function_call_iterator_c::function_call_iterator_c(symbol_c *symbol) {
67 | this->start_symbol = symbol;
68 | next_fcall = fcall_count = 0;
69 | current_finvocation = NULL;
70 | current_fcall_name = NULL;
71 | }
72 |
73 | /* Skip to the next function call. After object creation,
74 | * the object references _before_ the first, so
75 | * this function must be called once to get the object to
76 | * reference the first function call...
77 | *
78 | * Returns the function_invocation_c!
79 | */
80 | //function_invocation_c *next(void) {TRACE("function_call_iterator_c::next(): called ");
81 | symbol_c *function_call_iterator_c::next(void) {TRACE("function_call_iterator_c::next(): called ");
82 | fcall_count = 0;
83 | next_fcall++;
84 | current_finvocation = NULL;
85 | current_fcall_name = NULL;
86 |
87 | start_symbol->accept(*this);
88 | return current_finvocation;
89 | }
90 |
91 | /* Returns the name of the currently referenced function invocation */
92 | token_c *function_call_iterator_c::fname(void) {
93 | token_c *fname_sym = dynamic_cast(current_fcall_name);
94 | if (fname_sym == NULL) ERROR;
95 | return fname_sym;
96 | }
97 |
98 |
99 | /***************************************/
100 | /* B.3 - Language ST (Structured Text) */
101 | /***************************************/
102 | /***********************/
103 | /* B 3.1 - Expressions */
104 | /***********************/
105 | void *function_call_iterator_c::visit(function_invocation_c *symbol) {
106 | fcall_count++;
107 | if (next_fcall == fcall_count) {
108 | current_finvocation = symbol;
109 | current_fcall_name = symbol->function_name;
110 | }
111 | return NULL;
112 | }
113 |
114 |
115 |
116 | /****************************************/
117 | /* B.2 - Language IL (Instruction List) */
118 | /****************************************/
119 | /***********************************/
120 | /* B 2.1 Instructions and Operands */
121 | /***********************************/
122 |
123 | /* | function_name [il_operand_list] */
124 | // SYM_REF2(il_function_call_c, function_name, il_operand_list)
125 | void *function_call_iterator_c::visit(il_function_call_c *symbol) {
126 | fcall_count++;
127 | if (next_fcall == fcall_count) {
128 | current_finvocation = symbol;
129 | current_fcall_name = symbol->function_name;
130 | }
131 | return NULL;
132 | }
133 |
134 |
135 |
136 | /* | function_name '(' eol_list [il_param_list] ')' */
137 | // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
138 | void *function_call_iterator_c::visit(il_formal_funct_call_c *symbol) {
139 | fcall_count++;
140 | if (next_fcall == fcall_count) {
141 | current_finvocation = symbol;
142 | current_fcall_name = symbol->function_name;
143 | }
144 | return NULL;
145 | }
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/absyntax_utils/function_call_iterator.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Function call parameter iterator.
36 | *
37 | * This is part of the 4th stage that generates
38 | * a c++ source program equivalent to the IL and ST
39 | * code.
40 | */
41 |
42 |
43 | #include "../absyntax/visitor.hh"
44 |
45 |
46 |
47 | /* given a function_body_c, iterate through each
48 | * function/FB call in that code.
49 | */
50 |
51 | class function_call_iterator_c : public iterator_visitor_c {
52 |
53 | private:
54 | symbol_c *start_symbol;
55 | int next_fcall, fcall_count;
56 | symbol_c *current_fcall_name;
57 | symbol_c *current_finvocation;
58 |
59 | public:
60 | /* initialise the iterator object.
61 | * We must be given a reference to the function declaration
62 | * that will be analysed...
63 | */
64 | function_call_iterator_c(symbol_c *symbol);
65 |
66 | /* Skip to the next function call. After object creation,
67 | * the object references _before_ the first, so
68 | * this function must be called once to get the object to
69 | * reference the first function call...
70 | *
71 | * Returns the function_invocation_c!
72 | */
73 | symbol_c *next(void);
74 |
75 | /* Returns the name of the currently referenced function invocation */
76 | token_c *fname(void);
77 |
78 | private:
79 | /***************************************/
80 | /* B.3 - Language ST (Structured Text) */
81 | /***************************************/
82 | /***********************/
83 | /* B 3.1 - Expressions */
84 | /***********************/
85 | void *visit(function_invocation_c *symbol);
86 |
87 | /****************************************/
88 | /* B.2 - Language IL (Instruction List) */
89 | /****************************************/
90 | /***********************************/
91 | /* B 2.1 Instructions and Operands */
92 | /***********************************/
93 |
94 | /* | function_name [il_operand_list] */
95 | // SYM_REF2(il_function_call_c, function_name, il_operand_list)
96 | void *visit(il_function_call_c *symbol);
97 |
98 | /* | function_name '(' eol_list [il_param_list] ')' */
99 | // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
100 | void *visit(il_formal_funct_call_c *symbol);
101 |
102 | }; // class function_call_iterator_c
103 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/absyntax_utils/get_var_name.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 | /*
33 | * A small helper visitor class, that will
34 | * return the name (tokn_c *) of a variable, as it will
35 | * appear in the variable declaration.
36 | */
37 |
38 |
39 |
40 | #include "absyntax_utils.hh"
41 |
42 |
43 |
44 |
45 |
46 |
47 | get_var_name_c *get_var_name_c::singleton_instance_ = NULL;
48 |
49 |
50 |
51 | /* For ex.:
52 | * VAR
53 | * A : int;
54 | * B : ARRAY [1..9] of int;
55 | * C : some_struct_t;
56 | * END_VAR
57 | *
58 | * A := 56;
59 | * B[8] := 99;
60 | * C.e := 77;
61 | *
62 | * Calling this method with symbolic_variable_c instance referencing 'A' in
63 | * the line 'A := 56', will return the string "A".
64 | *
65 | * Calling this method with array_variable_c instance referencing 'B[8]' in
66 | * the line 'B[8] := 99', will return the string "B".
67 | *
68 | * Calling this method with array_variable_c instance referencing 'C.e' in
69 | * the line 'C.e := 77', will return the string "C".
70 | */
71 |
72 | token_c *get_var_name_c::get_name(symbol_c *symbol) {
73 | if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c();
74 | if (NULL == singleton_instance_) ERROR;
75 |
76 | return (token_c *)(symbol->accept(*singleton_instance_));
77 | }
78 |
79 |
80 | /* Return the last field of a structured variable...
81 | *
82 | * A := 56; --> returns A
83 | * B[8] := 99; --> returns B
84 | * C.e := 77; --> returns e !!!
85 | */
86 | symbol_c *get_var_name_c::get_last_field(symbol_c *symbol) {
87 | if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c();
88 | if (NULL == singleton_instance_) ERROR;
89 |
90 | singleton_instance_->last_field = NULL;
91 | symbol_c *res = (symbol_c*)(symbol->accept(*singleton_instance_));
92 | return (NULL != singleton_instance_->last_field)? singleton_instance_->last_field : res;
93 | }
94 |
95 |
96 |
97 |
98 | /*************************/
99 | /* B.1 - Common elements */
100 | /*************************/
101 | /*******************************************/
102 | /* B 1.1 - Letters, digits and identifiers */
103 | /*******************************************/
104 | // SYM_TOKEN(identifier_c)
105 | void *get_var_name_c::visit(identifier_c *symbol) {return (void *)symbol;}
106 |
107 | /*********************/
108 | /* B 1.4 - Variables */
109 | /*********************/
110 | // SYM_REF2(symbolic_variable_c, var_name, unused)
111 | void *get_var_name_c::visit(symbolic_variable_c *symbol) {return symbol->var_name->accept(*this);}
112 |
113 | /********************************************/
114 | /* B.1.4.1 Directly Represented Variables */
115 | /********************************************/
116 | // SYM_TOKEN(direct_variable_c)
117 |
118 | /*************************************/
119 | /* B.1.4.2 Multi-element Variables */
120 | /*************************************/
121 | /* subscripted_variable '[' subscript_list ']' */
122 | // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
123 | void *get_var_name_c::visit(array_variable_c *symbol) {return symbol->subscripted_variable->accept(*this);}
124 |
125 | /* subscript_list ',' subscript */
126 | // SYM_LIST(subscript_list_c)
127 |
128 | /* record_variable '.' field_selector */
129 | /* WARNING: input and/or output variables of function blocks
130 | * may be accessed as fields of a tructured variable!
131 | * Code handling a structured_variable_c must take
132 | * this into account!
133 | */
134 | // SYM_REF2(structured_variable_c, record_variable, field_selector)
135 | void *get_var_name_c::visit(structured_variable_c *symbol) {
136 | void *res = symbol->record_variable->accept(*this);
137 | last_field = symbol->field_selector;
138 | return res;
139 | }
140 |
141 |
142 |
143 |
--------------------------------------------------------------------------------
/absyntax_utils/get_var_name.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 | /*
33 | * A small helper visitor class, that will
34 | * return the name (tokn_c *) of a variable, as it will
35 | * appear in the variable declaration.
36 | */
37 |
38 | /* For ex.:
39 | * VAR
40 | * A : int;
41 | * B : ARRAY [1..9] of int;
42 | * C : some_struct_t;
43 | * END_VAR
44 | *
45 | * A := 56;
46 | * B[8] := 99;
47 | * C.e := 77;
48 | *
49 | * Calling this visitor class with symbolic_variable_c instance referencing 'A' in
50 | * the line 'A := 56', will return the string "A".
51 | *
52 | * Calling this visitor class with array_variable_c instance referencing 'B[8]' in
53 | * the line 'B[8] := 99', will return the string "B".
54 | *
55 | * Calling this visitor class with array_variable_c instance referencing 'C.e' in
56 | * the line 'C.e := 77', will return the string "C".
57 | */
58 |
59 |
60 |
61 |
62 | class get_var_name_c : public search_visitor_c {
63 | public:
64 | get_var_name_c(void) {};
65 | ~get_var_name_c(void) {};
66 | static token_c *get_name(symbol_c *symbol);
67 | static symbol_c *get_last_field(symbol_c *symbol);
68 |
69 | private:
70 | static get_var_name_c *singleton_instance_;
71 | symbol_c *last_field;
72 |
73 | private:
74 | /*************************/
75 | /* B.1 - Common elements */
76 | /*************************/
77 | /*******************************************/
78 | /* B 1.1 - Letters, digits and identifiers */
79 | /*******************************************/
80 | // SYM_TOKEN(identifier_c)
81 | void *visit(identifier_c *symbol);
82 |
83 | /*********************/
84 | /* B 1.4 - Variables */
85 | /*********************/
86 | // SYM_REF2(symbolic_variable_c, var_name, unused)
87 | void *visit(symbolic_variable_c *symbol);
88 |
89 | /********************************************/
90 | /* B.1.4.1 Directly Represented Variables */
91 | /********************************************/
92 | // SYM_TOKEN(direct_variable_c)
93 | // void *visit(direct_variable_c *symbol);
94 |
95 | /*************************************/
96 | /* B.1.4.2 Multi-element Variables */
97 | /*************************************/
98 | /* subscripted_variable '[' subscript_list ']' */
99 | // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
100 | void *visit(array_variable_c *symbol);
101 |
102 | /* subscript_list ',' subscript */
103 | // SYM_LIST(subscript_list_c)
104 | // void *visit(subscript_list_c *symbol);
105 |
106 | /* record_variable '.' field_selector */
107 | /* WARNING: input and/or output variables of function blocks
108 | * may be accessed as fields of a tructured variable!
109 | * Code handling a structured_variable_c must take
110 | * this into account!
111 | */
112 | // SYM_REF2(structured_variable_c, record_variable, field_selector)
113 | void *visit(structured_variable_c *symbol);
114 | };
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/absyntax_utils/search_fb_instance_decl.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 |
35 | /* Returns the function block type declaration
36 | * of a specific function block instance.
37 | */
38 |
39 |
40 |
41 | /* Returns the type name of a specific function block
42 | * instance. This class will search the variable
43 | * declarations inside the scope given to it
44 | * searching for the declaration of the function
45 | * block instance.
46 | *
47 | * The class constructor must be given the search scope
48 | * (function, function block or program within which
49 | * the function block instance was declared).
50 | *
51 | * This class will search the tree from the root given to the
52 | * constructor. Another option would be to build a symbol table,
53 | * and search that instead. Building the symbol table would be done
54 | * while visiting the variable declaration objects in the parse
55 | * tree. Unfortuantely, generate_c_c does not visit these
56 | * objects, delegating it to another class. This means that
57 | * we would need another specialised class just to build the
58 | * symbol table. We might just as well have a specialised class
59 | * that searches the tree itself for the relevant info. This
60 | * class is exactly that...!
61 | */
62 |
63 |
64 | class search_fb_instance_decl_c: public search_visitor_c {
65 |
66 | private:
67 | symbol_c *search_scope;
68 |
69 | symbol_c *search_name;
70 | symbol_c *current_fb_type_name;
71 |
72 | public:
73 | search_fb_instance_decl_c(symbol_c *search_scope);
74 | symbol_c *get_type_name(symbol_c *fb_instance_name);
75 |
76 | public:
77 | /***************************/
78 | /* B 0 - Programming Model */
79 | /***************************/
80 | void *visit(library_c *symbol);
81 |
82 | /******************************************/
83 | /* B 1.4.3 - Declaration & Initialisation */
84 | /******************************************/
85 |
86 | /* name_list ':' function_block_type_name ASSIGN structure_initialization */
87 | /* structure_initialization -> may be NULL ! */
88 | void *visit(fb_name_decl_c *symbol);
89 | /* name_list ',' fb_name */
90 | void *visit(fb_name_list_c *symbol);
91 | /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */
92 | void *visit(external_declaration_c *symbol);
93 |
94 |
95 | /**************************************/
96 | /* B.1.5 - Program organization units */
97 | /**************************************/
98 | /***********************/
99 | /* B 1.5.1 - Functions */
100 | /***********************/
101 | void *visit(function_declaration_c *symbol);
102 |
103 | /*****************************/
104 | /* B 1.5.2 - Function Blocks */
105 | /*****************************/
106 | void *visit(function_block_declaration_c *symbol);
107 |
108 | /**********************/
109 | /* B 1.5.3 - Programs */
110 | /**********************/
111 | void *visit(program_declaration_c *symbol);
112 | }; // search_fb_instance_decl_c
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/absyntax_utils/search_fb_typedecl.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 | /* Returns the function block declaration symbol
34 | * of a specific function block type.
35 | */
36 |
37 | #include "absyntax_utils.hh"
38 |
39 |
40 | search_fb_typedecl_c::search_fb_typedecl_c(symbol_c *search_scope) {
41 | this->search_scope = search_scope;
42 | }
43 |
44 | symbol_c *search_fb_typedecl_c::get_decl(symbol_c *fb_type_name) {
45 | this->search_name = fb_type_name;
46 | return (symbol_c *)search_scope->accept(*this);
47 | }
48 | /**************************************/
49 | /* B.1.5 - Program organization units */
50 | /**************************************/
51 |
52 | /*****************************/
53 | /* B 1.5.2 - Function Blocks */
54 | /*****************************/
55 | void *search_fb_typedecl_c::visit(function_block_declaration_c *symbol) {
56 | if (compare_identifiers(symbol->fblock_name, search_name) == 0)
57 | return symbol;
58 | return NULL;
59 | }
60 |
61 | /**********************/
62 | /* B 1.5.3 - Programs */
63 | /**********************/
64 | void *search_fb_typedecl_c::visit(program_declaration_c *symbol) {
65 | if (compare_identifiers(symbol->program_type_name, search_name) == 0)
66 | return symbol;
67 | return NULL;
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/absyntax_utils/search_fb_typedecl.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /* Returns the function block declaration symbol
35 | * of a specific function block type.
36 | */
37 |
38 | class search_fb_typedecl_c: public search_visitor_c {
39 |
40 | private:
41 | symbol_c *search_scope;
42 |
43 | symbol_c *search_name;
44 |
45 | public:
46 | search_fb_typedecl_c(symbol_c *search_scope);
47 | symbol_c *get_decl(symbol_c *fb_type_name);
48 |
49 | private:
50 | /**************************************/
51 | /* B.1.5 - Program organization units */
52 | /**************************************/
53 |
54 | /*****************************/
55 | /* B 1.5.2 - Function Blocks */
56 | /*****************************/
57 | void *visit(function_block_declaration_c *symbol);
58 |
59 | /**********************/
60 | /* B 1.5.3 - Programs */
61 | /**********************/
62 | void *visit(program_declaration_c *symbol);
63 | }; // search_fb_typedecl_c
64 |
--------------------------------------------------------------------------------
/absyntax_utils/search_il_label.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 |
33 | /*
34 | * Search for a specific label in an IL list.
35 | *
36 | * when instantiated, must be given a pointer to one of the following
37 | * - function_declaration_c
38 | * - function_block_declaration_c
39 | * - program_declaration_c
40 | * - instruction_list_c
41 | *
42 | * which is where all calls to search for a specific label will look for said label.
43 | */
44 |
45 |
46 |
47 | #include "absyntax_utils.hh"
48 |
49 |
50 |
51 | /* set to 1 to see debug info during execution */
52 | static int debug = 0;
53 |
54 | search_il_label_c::search_il_label_c(symbol_c *search_scope) {
55 | this->search_scope = search_scope;
56 | this->search_label = NULL;
57 | }
58 |
59 | search_il_label_c::~search_il_label_c(void) {
60 | }
61 |
62 |
63 | il_instruction_c *search_il_label_c::find_label(const char *label) {
64 | return find_label(new identifier_c(label));
65 | }
66 |
67 |
68 | il_instruction_c *search_il_label_c::find_label(symbol_c *label) {
69 | search_label = label;
70 | il_instruction_c *res = (il_instruction_c *)search_scope->accept(*this);
71 | search_label = NULL;
72 | return res;
73 | }
74 |
75 |
76 | /****************************************/
77 | /* B.2 - Language IL (Instruction List) */
78 | /****************************************/
79 | /***********************************/
80 | /* B 2.1 Instructions and Operands */
81 | /***********************************/
82 |
83 | /* | label ':' [il_incomplete_instruction] eol_list */
84 | // SYM_REF2(il_instruction_c, label, il_instruction)
85 | // void *visit(instruction_list_c *symbol);
86 | void *search_il_label_c::visit(il_instruction_c *symbol) {
87 | // printf("search_il_label_c::visit(il_instruction_c *symbol): searching for %s\n", ((identifier_c *)search_label)->value);
88 | if (NULL != symbol->label)
89 | if (compare_identifiers(search_label, symbol->label) == 0)
90 | return symbol;
91 |
92 | return NULL;
93 | }
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/absyntax_utils/search_il_label.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Search for a specific label in an IL list.
36 | *
37 | * when instantiated, must be given a pointer to one of the following
38 | * - function_declaration_c
39 | * - function_block_declaration_c
40 | * - program_declaration_c
41 | * - instruction_list_c
42 | *
43 | * which is where all calls to search for a specific label will look for said label.
44 | */
45 |
46 |
47 |
48 | #include "../absyntax_utils/absyntax_utils.hh"
49 |
50 |
51 | class search_il_label_c: public search_visitor_c {
52 |
53 | private:
54 | search_varfb_instance_type_c *search_varfb_instance_type;
55 | symbol_c *search_scope;
56 | symbol_c *search_label;
57 |
58 | public:
59 | search_il_label_c(symbol_c *search_scope);
60 | virtual ~search_il_label_c(void);
61 |
62 | il_instruction_c *find_label(const char *label);
63 | il_instruction_c *find_label(symbol_c *label);
64 |
65 |
66 | /****************************************/
67 | /* B.2 - Language IL (Instruction List) */
68 | /****************************************/
69 | /***********************************/
70 | /* B 2.1 Instructions and Operands */
71 | /***********************************/
72 | // void *visit(instruction_list_c *symbol);
73 | void *visit(il_instruction_c *symbol);
74 | // void *visit(il_simple_operation_c *symbol);
75 | // void *visit(il_function_call_c *symbol);
76 | // void *visit(il_expression_c *symbol);
77 | // void *visit(il_fb_call_c *symbol);
78 | // void *visit(il_formal_funct_call_c *symbol);
79 | // void *visit(il_operand_list_c *symbol);
80 | // void *visit(simple_instr_list_c *symbol);
81 | // void *visit(il_simple_instruction_c*symbol);
82 | // void *visit(il_param_list_c *symbol);
83 | // void *visit(il_param_assignment_c *symbol);
84 | // void *visit(il_param_out_assignment_c *symbol);
85 |
86 |
87 | }; // search_il_label_c
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/absyntax_utils/spec_init_separator.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Separation of type specification and default value constructs
36 | * (for e.g. simple_spec_init_c), into a type specificiation part,
37 | * and a default value part.
38 | */
39 |
40 | #include "../absyntax/absyntax.hh"
41 | #include "../absyntax/visitor.hh"
42 |
43 | class spec_init_sperator_c: public null_visitor_c {
44 |
45 | private:
46 | /* this is a singleton class... */
47 | static spec_init_sperator_c *class_instance;
48 | static spec_init_sperator_c *get_class_instance(void);
49 |
50 | private:
51 | typedef enum {search_spec, search_init} search_what_t;
52 | static search_what_t search_what;
53 |
54 | public:
55 | /* the only two public functions... */
56 | static symbol_c *get_spec(symbol_c *spec_init);
57 |
58 | static symbol_c *get_init(symbol_c *spec_init);
59 |
60 |
61 | private:
62 |
63 |
64 | /*******************************************/
65 | /* B 1.1 - Letters, digits and identifiers */
66 | /*******************************************/
67 | // SYM_TOKEN(identifier_c)
68 | void *visit( identifier_c *symbol);
69 | void *visit(derived_datatype_identifier_c *symbol);
70 | void *visit( poutype_identifier_c *symbol);
71 |
72 |
73 | /********************************/
74 | /* B 1.3.3 - Derived data types */
75 | /********************************/
76 |
77 | /* simple_specification ASSIGN constant */
78 | void *visit(simple_spec_init_c *symbol);
79 |
80 | /* subrange_specification ASSIGN signed_integer */
81 | void *visit(subrange_spec_init_c *symbol);
82 |
83 | /* integer_type_name '(' subrange')' */
84 | void *visit(subrange_specification_c *symbol);
85 |
86 | /* array_specification [ASSIGN array_initialization} */
87 | /* array_initialization may be NULL ! */
88 | void *visit(array_spec_init_c *symbol);
89 |
90 | /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
91 | void *visit(array_specification_c *symbol);
92 |
93 | /* enumerated_specification ASSIGN enumerated_value */
94 | void *visit(enumerated_spec_init_c *symbol);
95 |
96 | /* structure_type_name ASSIGN structure_initialization */
97 | /* structure_initialization may be NULL ! */
98 | //SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
99 | void *visit(initialized_structure_c *symbol);
100 |
101 | /* function_block_type_name ASSIGN structure_initialization */
102 | /* structure_initialization -> may be NULL ! */
103 | //SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
104 | void *visit(fb_spec_init_c *symbol);
105 |
106 | /* REF_TO (non_generic_type_name | function_block_type_name) */
107 | // SYM_REF1(ref_spec_c, type_name)
108 | void *visit(ref_spec_c *symbol);
109 |
110 | /* ref_spec [ ASSIGN ref_initialization ] */
111 | /* NOTE: ref_initialization may be NULL!! */
112 | // SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization)
113 | void *visit(ref_spec_init_c *symbol);
114 |
115 | /******************************************/
116 | /* B 1.4.3 - Declaration & Initialisation */
117 | /******************************************/
118 |
119 | /* STRING '[' integer ']'
120 | * STRING ASSIGN single_byte_character_string
121 | * STRING '[' integer ']' ASSIGN single_byte_character_string
122 | */
123 | void *visit(single_byte_string_spec_c *symbol);
124 |
125 | /* WSTRING '[' integer ']'
126 | * WSTRING ASSIGN double_byte_character_string
127 | * WSTRING '[' integer ']' ASSIGN double_byte_character_string
128 | */
129 | void *visit(double_byte_string_spec_c *symbol);
130 |
131 | }; /* class spec_init_sperator_c */
132 |
--------------------------------------------------------------------------------
/common.mk:
--------------------------------------------------------------------------------
1 | AM_CXXFLAGS = -g -Wall -Wpointer-arith -Wwrite-strings -Wno-unused
2 |
3 |
4 |
--------------------------------------------------------------------------------
/config/ltsugar.m4:
--------------------------------------------------------------------------------
1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*-
2 | #
3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4 | # Written by Gary V. Vaughan, 2004
5 | #
6 | # This file is free software; the Free Software Foundation gives
7 | # unlimited permission to copy and/or distribute it, with or without
8 | # modifications, as long as this notice is preserved.
9 |
10 | # serial 6 ltsugar.m4
11 |
12 | # This is to help aclocal find these macros, as it can't see m4_define.
13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
14 |
15 |
16 | # lt_join(SEP, ARG1, [ARG2...])
17 | # -----------------------------
18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
19 | # associated separator.
20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
21 | # versions in m4sugar had bugs.
22 | m4_define([lt_join],
23 | [m4_if([$#], [1], [],
24 | [$#], [2], [[$2]],
25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
26 | m4_define([_lt_join],
27 | [m4_if([$#$2], [2], [],
28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
29 |
30 |
31 | # lt_car(LIST)
32 | # lt_cdr(LIST)
33 | # ------------
34 | # Manipulate m4 lists.
35 | # These macros are necessary as long as will still need to support
36 | # Autoconf-2.59 which quotes differently.
37 | m4_define([lt_car], [[$1]])
38 | m4_define([lt_cdr],
39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
40 | [$#], 1, [],
41 | [m4_dquote(m4_shift($@))])])
42 | m4_define([lt_unquote], $1)
43 |
44 |
45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR])
46 | # ------------------------------------------
47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended
49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different
51 | # than defined and empty).
52 | #
53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier
54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
55 | m4_define([lt_append],
56 | [m4_define([$1],
57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
58 |
59 |
60 |
61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
62 | # ----------------------------------------------------------
63 | # Produce a SEP delimited list of all paired combinations of elements of
64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list
65 | # has the form PREFIXmINFIXSUFFIXn.
66 | # Needed until we can rely on m4_combine added in Autoconf 2.62.
67 | m4_define([lt_combine],
68 | [m4_if(m4_eval([$# > 3]), [1],
69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
70 | [[m4_foreach([_Lt_prefix], [$2],
71 | [m4_foreach([_Lt_suffix],
72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
74 |
75 |
76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
77 | # -----------------------------------------------------------------------
78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
80 | m4_define([lt_if_append_uniq],
81 | [m4_ifdef([$1],
82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
83 | [lt_append([$1], [$2], [$3])$4],
84 | [$5])],
85 | [lt_append([$1], [$2], [$3])$4])])
86 |
87 |
88 | # lt_dict_add(DICT, KEY, VALUE)
89 | # -----------------------------
90 | m4_define([lt_dict_add],
91 | [m4_define([$1($2)], [$3])])
92 |
93 |
94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
95 | # --------------------------------------------
96 | m4_define([lt_dict_add_subkey],
97 | [m4_define([$1($2:$3)], [$4])])
98 |
99 |
100 | # lt_dict_fetch(DICT, KEY, [SUBKEY])
101 | # ----------------------------------
102 | m4_define([lt_dict_fetch],
103 | [m4_ifval([$3],
104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
106 |
107 |
108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
109 | # -----------------------------------------------------------------
110 | m4_define([lt_if_dict_fetch],
111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
112 | [$5],
113 | [$6])])
114 |
115 |
116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
117 | # --------------------------------------------------------------
118 | m4_define([lt_dict_filter],
119 | [m4_if([$5], [], [],
120 | [lt_join(m4_quote(m4_default([$4], [[, ]])),
121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
123 | ])
124 |
--------------------------------------------------------------------------------
/config/ltversion.m4:
--------------------------------------------------------------------------------
1 | # ltversion.m4 -- version numbers -*- Autoconf -*-
2 | #
3 | # Copyright (C) 2004 Free Software Foundation, Inc.
4 | # Written by Scott James Remnant, 2004
5 | #
6 | # This file is free software; the Free Software Foundation gives
7 | # unlimited permission to copy and/or distribute it, with or without
8 | # modifications, as long as this notice is preserved.
9 |
10 | # Generated from ltversion.in.
11 |
12 | # serial 3017 ltversion.m4
13 | # This file is part of GNU Libtool
14 |
15 | m4_define([LT_PACKAGE_VERSION], [2.2.6b])
16 | m4_define([LT_PACKAGE_REVISION], [1.3017])
17 |
18 | AC_DEFUN([LTVERSION_VERSION],
19 | [macro_version='2.2.6b'
20 | macro_revision='1.3017'
21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
22 | _LT_DECL(, macro_revision, 0)
23 | ])
24 |
--------------------------------------------------------------------------------
/configure.ac:
--------------------------------------------------------------------------------
1 | # -*- Autoconf -*-
2 | # Process this file with autoconf to produce a configure script.
3 |
4 | AC_PREREQ([2.61])
5 | AC_INIT([matiec], [0.1], [msousa@fe.up.pt, beremiz-devel@lists.sourceforge.net])
6 | AC_CONFIG_HEADERS([config/config.h])
7 | AC_CONFIG_AUX_DIR(config)
8 |
9 | AM_INIT_AUTOMAKE([foreign])
10 |
11 | # Before checking for CXX and CC, set CFLAGS and CXXFLAGS because they
12 | # are otherwise initialized to contain -g -O2
13 | if test "x$CFLAGS" = "x"; then
14 | CFLAGS=
15 | fi
16 | if test "x$CXXFLAGS" = "x"; then
17 | CXXFLAGS=
18 | fi
19 |
20 | # Checks for programs.
21 | AC_PROG_YACC
22 | AC_PROG_LEX
23 | AC_PROG_CXX
24 | AC_PROG_INSTALL
25 | AC_PROG_LN_S
26 | AC_PROG_MAKE_SET
27 | AC_PROG_RANLIB
28 | AC_PROG_AWK
29 |
30 | # Check bison version, we need a version great or equal than 2.4 to build matiec.
31 | version_bison="$(bison --version | sed q | cut -d' ' -f4)"
32 | version_bison=${version_bison:0:3}
33 |
34 | AS_IF([awk -v ver="$version_bison" 'BEGIN { if (ver < 2.4) exit 1; }'],
35 | [have_bison_correct=yes], [have_bison_correct=no])
36 |
37 |
38 | if test "x${have_bison_correct}" = xno; then
39 | echo "------------------------------------------"
40 | echo " Wrong bison version: $version_bison < 2.4 "
41 | echo "------------------------------------------"
42 | (exit 1); exit 1;
43 | fi
44 |
45 | if test "x$LEX" == "x:"; then
46 | AC_MSG_ERROR("flex/lex is missing")
47 | fi
48 |
49 | # Checks for header files.
50 | AC_CHECK_HEADERS([float.h limits.h stdint.h stdlib.h string.h strings.h sys/timeb.h unistd.h])
51 |
52 | # Checks for typedefs, structures, and compiler characteristics.
53 | AC_HEADER_STDBOOL
54 | AC_C_INLINE
55 | AC_TYPE_INT16_T
56 | AC_TYPE_INT32_T
57 | AC_TYPE_INT64_T
58 | AC_TYPE_INT8_T
59 | AC_TYPE_UINT16_T
60 | AC_TYPE_UINT32_T
61 | AC_TYPE_UINT64_T
62 | AC_TYPE_UINT8_T
63 |
64 | # Checks for library functions.
65 | AC_FUNC_MALLOC
66 | AC_FUNC_MKTIME
67 | AC_FUNC_REALLOC
68 | AC_CHECK_FUNCS([clock_gettime memset pow strcasecmp strdup strtoul strtoull])
69 |
70 |
71 | AC_CONFIG_MACRO_DIR([config])
72 |
73 | AC_CONFIG_FILES([Makefile \
74 | absyntax/Makefile \
75 | absyntax_utils/Makefile \
76 | stage1_2/Makefile \
77 | stage3/Makefile \
78 | stage4/Makefile \
79 | stage4/generate_c/Makefile \
80 | stage4/generate_iec/Makefile])
81 | AC_OUTPUT
82 |
83 |
84 |
--------------------------------------------------------------------------------
/debian/README.Debian:
--------------------------------------------------------------------------------
1 | matiec for Debian
2 | -----------------
3 |
4 |
5 |
6 | -- edouard Wed, 21 Nov 2007 17:01:50 +0100
7 |
--------------------------------------------------------------------------------
/debian/changelog:
--------------------------------------------------------------------------------
1 | matiec (2009.0-%DATEVERSION%) unstable; urgency=low
2 |
3 | * Initial release (Closes: #nnnn)
4 |
5 | -- edouard Wed, 21 Nov 2007 17:01:50 +0100
6 |
7 |
--------------------------------------------------------------------------------
/debian/compat:
--------------------------------------------------------------------------------
1 | 5
2 |
--------------------------------------------------------------------------------
/debian/control:
--------------------------------------------------------------------------------
1 | Source: matiec
2 | Section: devel
3 | Priority: standard
4 | Maintainer: edouard
5 | Build-Depends: debhelper (>= 5), bison, flex
6 | Standards-Version: 3.7.2
7 |
8 | Package: matiec
9 | Architecture: any
10 | Depends: ${shlibs:Depends}, ${misc:Depends}
11 | Description: The IEC to ANSI-C compiler
12 | Compiles ST/IL/SFC code into ANSI-C code
13 |
--------------------------------------------------------------------------------
/debian/copyright:
--------------------------------------------------------------------------------
1 | This package was debianized by edouard > on
2 | Wed, 21 Nov 2007 17:01:50 +0100.
3 |
4 | It was downloaded from
5 |
6 | Upstream Author:
7 |
8 | Copyright:
10 |
11 | License:
12 |
13 | This package is free software; you can redistribute it and/or modify
14 | it under the terms of the GNU General Public License as published by
15 | the Free Software Foundation; either version 2 of the License, or
16 | (at your option) any later version.
17 |
18 | This package is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | GNU General Public License for more details.
22 |
23 | You should have received a copy of the GNU General Public License
24 | along with this package; if not, write to the Free Software
25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 |
27 | On Debian systems, the complete text of the GNU General
28 | Public License can be found in `/usr/share/common-licenses/GPL'.
29 |
30 | The Debian packaging is (C) 2007, edouard and
31 | is licensed under the GPL, see above.
32 |
33 |
34 | # Please also look if there are files or directories which have a
35 | # different copyright/license attached and list them here.
36 |
--------------------------------------------------------------------------------
/debian/dirs:
--------------------------------------------------------------------------------
1 | usr/bin
2 |
--------------------------------------------------------------------------------
/debian/postinst:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # postinst script for canfestival
3 | #
4 | # see: dh_installdeb(1)
5 |
6 | set -e
7 |
8 | # summary of how this script can be called:
9 | # * `configure'
10 | # * `abort-upgrade'
11 | # * `abort-remove' `in-favour'
12 | #
13 | # * `abort-remove'
14 | # * `abort-deconfigure' `in-favour'
15 | # `removing'
16 | #
17 | # for details, see http://www.debian.org/doc/debian-policy/ or
18 | # the debian-policy package
19 |
20 |
21 | case "$1" in
22 | configure)
23 | ln -sf /usr/share/matiec/iec2c /usr/bin/iec2c
24 | chmod 755 /usr/share/matiec/iec2c
25 | ;;
26 |
27 | abort-upgrade|abort-remove|abort-deconfigure)
28 | ;;
29 |
30 | *)
31 | echo "postinst called with unknown argument \`$1'" >&2
32 | exit 1
33 | ;;
34 | esac
35 |
36 | # dh_installdeb will replace this with shell code automatically
37 | # generated by other debhelper scripts.
38 |
39 | #DEBHELPER#
40 |
41 | exit 0
42 |
43 |
44 |
--------------------------------------------------------------------------------
/debian/postrm:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # postrm script for canfestival-objdictedit
3 | #
4 | # see: dh_installdeb(1)
5 |
6 | set -e
7 |
8 | MATIEC=/usr/bin/iec2c
9 |
10 | case "$1" in
11 | purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
12 |
13 | if [ -f "$MATIEC" ]; then
14 | rm $MATIEC
15 | fi
16 | ;;
17 |
18 | *)
19 | echo "postrm called with unknown argument \`$1'" >&2
20 | exit 1
21 | ;;
22 | esac
23 |
24 | # dh_installdeb will replace this with shell code automatically
25 | # generated by other debhelper scripts.
26 |
27 | #DEBHELPER#
28 |
29 | exit 0
30 |
31 |
32 |
--------------------------------------------------------------------------------
/debian/rules:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 | # -*- makefile -*-
3 | # Sample debian/rules that uses debhelper.
4 | # This file was originally written by Joey Hess and Craig Small.
5 | # As a special exception, when this file is copied by dh-make into a
6 | # dh-make output file, you may use that output file without restriction.
7 | # This special exception was added by Craig Small in version 0.37 of dh-make.
8 |
9 | # Uncomment this to turn on verbose mode.
10 | export DH_VERBOSE=1
11 |
12 | CFLAGS = -Wall -g
13 |
14 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
15 | CFLAGS += -O0
16 | else
17 | CFLAGS += -O2
18 | endif
19 |
20 | build: build-stamp
21 |
22 | build-stamp:
23 | dh_testdir
24 | # Add here commands to compile the package.
25 | $(MAKE)
26 | touch $@
27 |
28 | clean:
29 | dh_testdir
30 | dh_testroot
31 | rm -f build-stamp
32 |
33 | # Add here commands to clean up after the build process.
34 | -$(MAKE) clean
35 |
36 | dh_clean
37 |
38 | install: build
39 | dh_testdir
40 | dh_testroot
41 | dh_clean -k
42 | dh_installdirs
43 |
44 | # Add here commands to install the package into debian/matiec.
45 | #$(MAKE) INSTALL_PREDIR=$(CURDIR)/debian/matiec/usr INSTALL_BINDIR=/bin IECLIBDIR=/lib install
46 |
47 | # Add here commands to install the package into debian/beremiz.
48 | mkdir -p $(CURDIR)/debian/matiec/usr/share/matiec
49 |
50 | cp -a lib $(CURDIR)/debian/matiec/usr/share/matiec
51 | cp iec2c $(CURDIR)/debian/matiec/usr/share/matiec
52 |
53 | # Build architecture-independent files here.
54 | binary-indep: build install
55 | # We have nothing to do by default.
56 |
57 | # Build architecture-dependent files here.
58 | binary-arch: build install
59 | dh_testdir
60 | dh_testroot
61 | # dh_installchangelogs
62 | # dh_installdocs
63 | # dh_installexamples
64 | # dh_install
65 | # dh_installmenu
66 | # dh_installdebconf
67 | # dh_installlogrotate
68 | # dh_installemacsen
69 | # dh_installpam
70 | # dh_installmime
71 | # dh_python
72 | # dh_installinit
73 | # dh_installcron
74 | # dh_installinfo
75 | # dh_installman
76 | dh_link
77 | dh_strip
78 | dh_compress
79 | dh_fixperms
80 | # dh_perl
81 | # dh_makeshlibs
82 | dh_installdeb
83 | dh_shlibdeps
84 | dh_gencontrol
85 | dh_md5sums
86 | dh_builddeb
87 |
88 | binary: binary-indep binary-arch
89 | .PHONY: build clean binary-indep binary-arch binary install
90 |
--------------------------------------------------------------------------------
/lib/C/iec_types.h:
--------------------------------------------------------------------------------
1 | #ifndef IEC_TYPES_H
2 | #define IEC_TYPES_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | /*********************/
9 | /* IEC Types defs */
10 | /*********************/
11 |
12 | typedef uint8_t IEC_BOOL;
13 |
14 | typedef int8_t IEC_SINT;
15 | typedef int16_t IEC_INT;
16 | typedef int32_t IEC_DINT;
17 | typedef int64_t IEC_LINT;
18 |
19 | typedef uint8_t IEC_USINT;
20 | typedef uint16_t IEC_UINT;
21 | typedef uint32_t IEC_UDINT;
22 | typedef uint64_t IEC_ULINT;
23 |
24 | typedef uint8_t IEC_BYTE;
25 | typedef uint16_t IEC_WORD;
26 | typedef uint32_t IEC_DWORD;
27 | typedef uint64_t IEC_LWORD;
28 |
29 | typedef float IEC_REAL;
30 | typedef double IEC_LREAL;
31 |
32 | /* WARNING: When editing the definition of IEC_TIMESPEC, take note that
33 | * if the order of the two elements 'tv_sec' and 'tv_nsec' is changed, then the macros
34 | * __time_to_timespec() and __tod_to_timespec() will need to be changed accordingly.
35 | * (these macros may be found in iec_std_lib.h)
36 | */
37 | typedef struct {
38 | long int tv_sec; /* Seconds. */
39 | long int tv_nsec; /* Nanoseconds. */
40 | } /* __attribute__((packed)) */ IEC_TIMESPEC; /* packed is gcc specific! */
41 |
42 | typedef IEC_TIMESPEC IEC_TIME;
43 | typedef IEC_TIMESPEC IEC_DATE;
44 | typedef IEC_TIMESPEC IEC_DT;
45 | typedef IEC_TIMESPEC IEC_TOD;
46 |
47 | #ifndef STR_MAX_LEN
48 | #define STR_MAX_LEN 126
49 | #endif
50 |
51 | #ifndef STR_LEN_TYPE
52 | #define STR_LEN_TYPE int8_t
53 | #endif
54 |
55 | #define __INIT_REAL 0
56 | #define __INIT_LREAL 0
57 | #define __INIT_SINT 0
58 | #define __INIT_INT 0
59 | #define __INIT_DINT 0
60 | #define __INIT_LINT 0
61 | #define __INIT_USINT 0
62 | #define __INIT_UINT 0
63 | #define __INIT_UDINT 0
64 | #define __INIT_ULINT 0
65 | #define __INIT_TIME (TIME){0,0}
66 | #define __INIT_BOOL 0
67 | #define __INIT_BYTE 0
68 | #define __INIT_WORD 0
69 | #define __INIT_DWORD 0
70 | #define __INIT_LWORD 0
71 | #define __INIT_STRING (STRING){0,""}
72 | //#define __INIT_WSTRING
73 | #define __INIT_DATE (DATE){0,0}
74 | #define __INIT_TOD (TOD){0,0}
75 | #define __INIT_DT (DT){0,0}
76 |
77 | typedef STR_LEN_TYPE __strlen_t;
78 | typedef struct {
79 | __strlen_t len;
80 | uint8_t body[STR_MAX_LEN];
81 | } /* __attribute__((packed)) */ IEC_STRING; /* packed is gcc specific! */
82 |
83 | #endif /*IEC_TYPES_H*/
84 |
--------------------------------------------------------------------------------
/lib/bistable.txt:
--------------------------------------------------------------------------------
1 | (*
2 | * This file is part of matiec - a compiler for the programming
3 | * languages defined in IEC 61131-3
4 | *
5 | * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt)
6 | *
7 | * See COPYING and COPYING.LESSER files for copyright details.
8 | * This library is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 3 of the License, or (at your option) any later version.
12 | *
13 | * This library is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with this library; if not, write to the Free Software
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 | * USA
22 | *
23 | * This code is made available on the understanding that it will not be
24 | * used in safety-critical situations without a full and competent review.
25 | *)
26 |
27 |
28 |
29 | (*
30 | * An IEC 61131-3 compiler.
31 | *
32 | * Based on the
33 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
34 | *
35 | *)
36 |
37 |
38 | (*
39 | * This is part of the library conatining the functions
40 | * and function blocks defined in the standard.
41 | *
42 | * SR and RS function blocks
43 | * -------------------------
44 | *)
45 |
46 | (* The standard defines the SR FB thus:
47 |
48 | +-----+
49 | S1----------------| >=1 |---Q1
50 | +---+ | |
51 | R------O| & |----| |
52 | Q1------| | | |
53 | +---+ +-----+
54 | *)
55 |
56 | FUNCTION_BLOCK SR
57 | VAR_INPUT
58 | S1, R : BOOL;
59 | END_VAR
60 | VAR_OUTPUT
61 | Q1 : BOOL;
62 | END_VAR
63 | Q1 := S1 OR ((NOT R) AND Q1);
64 | END_FUNCTION_BLOCK
65 |
66 |
67 | (* The standard defines the RS FB thus:
68 | +---+
69 | R1----------------O| & |---Q1
70 | +-----+ | |
71 | S-------| >=1 |----| |
72 | Q1------| | | |
73 | +-----+ +---+
74 | *)
75 |
76 | FUNCTION_BLOCK RS
77 | VAR_INPUT
78 | S, R1 : BOOL;
79 | END_VAR
80 | VAR_OUTPUT
81 | Q1 : BOOL;
82 | END_VAR
83 | Q1 := (NOT R1) AND (S OR Q1);
84 | END_FUNCTION_BLOCK
85 |
--------------------------------------------------------------------------------
/lib/derivative_st.txt:
--------------------------------------------------------------------------------
1 |
2 | (* Following taken directly from the IEC 61131.3 draft standard *)
3 |
4 | (*
5 | * An IEC 61131-3 IL and ST compiler.
6 | *
7 | * Based on the
8 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
9 | *
10 | *)
11 |
12 |
13 | FUNCTION_BLOCK DERIVATIVE
14 | VAR_INPUT
15 | RUN : BOOL ; (* 0 = reset *)
16 | XIN : REAL ; (* Input to be differentiated *)
17 | CYCLE : TIME ; (* Sampling period *)
18 | END_VAR
19 | VAR_OUTPUT
20 | XOUT : REAL ; (* Differentiated output *)
21 | END_VAR
22 | VAR X1, X2, X3 : REAL ; END_VAR
23 | IF RUN THEN
24 | XOUT := (3.0 * (XIN - X3) + X1 - X2)
25 | / (10.0 * TIME_TO_REAL(CYCLE)) ;
26 | X3 := X2 ; X2 := X1 ; X1 := XIN ;
27 | ELSE XOUT := 0.0; X1 := XIN ; X2 := XIN ; X3 := XIN ;
28 | END_IF ;
29 | END_FUNCTION_BLOCK
30 |
31 |
--------------------------------------------------------------------------------
/lib/edge_detection.txt:
--------------------------------------------------------------------------------
1 | (* Following taken directly from the IEC 61131.3 draft standard *)
2 |
3 | (*
4 | * An IEC 61131-3 IL and ST compiler.
5 | *
6 | * Based on the
7 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8 | *
9 | *)
10 |
11 |
12 | (*
13 | * This is part of the library conatining the functions
14 | * and function blocks defined in the standard.
15 | *
16 | * Edge detection function blocks
17 | * ------------------------------
18 | *)
19 |
20 | FUNCTION_BLOCK R_TRIG
21 | VAR_INPUT CLK: BOOL; END_VAR
22 | VAR_OUTPUT Q: BOOL; END_VAR
23 | VAR RETAIN M: BOOL; END_VAR
24 | Q := CLK AND NOT M;
25 | M := CLK;
26 | END_FUNCTION_BLOCK
27 |
28 | FUNCTION_BLOCK F_TRIG
29 | VAR_INPUT CLK: BOOL; END_VAR
30 | VAR_OUTPUT Q: BOOL; END_VAR
31 | VAR RETAIN M: BOOL; END_VAR
32 | Q := NOT CLK AND NOT M;
33 | M := NOT CLK;
34 | END_FUNCTION_BLOCK
35 |
36 |
--------------------------------------------------------------------------------
/lib/hysteresis_st.txt:
--------------------------------------------------------------------------------
1 | (* Following taken directly from the IEC 61131.3 draft standard *)
2 |
3 | (*
4 | * An IEC 61131-3 IL and ST compiler.
5 | *
6 | * Based on the
7 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8 | *
9 | *)
10 |
11 |
12 | FUNCTION_BLOCK HYSTERESIS
13 | (* Boolean hysteresis on difference *)
14 | (* of REAL inputs, XIN1 - XIN2 *)
15 | VAR_INPUT XIN1, XIN2, EPS : REAL; END_VAR
16 | VAR_OUTPUT Q : BOOL := 0; END_VAR
17 | IF Q THEN IF XIN1 < (XIN2 - EPS) THEN Q := 0; END_IF ;
18 | ELSIF XIN1 > (XIN2 + EPS) THEN Q := 1 ;
19 | END_IF ;
20 | END_FUNCTION_BLOCK
21 |
22 |
--------------------------------------------------------------------------------
/lib/ieclib.txt:
--------------------------------------------------------------------------------
1 | (*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | *)
23 |
24 | (* This is the library containing the standard function blocks defined in the standard. *)
25 |
26 | (* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) *)
27 |
28 | (* The standard functions *)
29 | {#include "standard_functions.txt" }
30 |
31 | (* The standard functions *)
32 | {#include "standard_FB.txt" }
33 |
--------------------------------------------------------------------------------
/lib/integral_st.txt:
--------------------------------------------------------------------------------
1 | (* Following taken directly from the IEC 61131.3 draft standard *)
2 |
3 | (*
4 | * An IEC 61131-3 IL and ST compiler.
5 | *
6 | * Based on the
7 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8 | *
9 | *)
10 |
11 | FUNCTION_BLOCK INTEGRAL
12 | VAR_INPUT
13 | RUN : BOOL ; (* 1 = integrate, 0 = hold *)
14 | R1 : BOOL ; (* Overriding reset *)
15 | XIN : REAL ; (* Input variable *)
16 | X0 : REAL ; (* Initial value *)
17 | CYCLE : TIME ; (* Sampling period *)
18 | END_VAR
19 | VAR_OUTPUT
20 | Q : BOOL ; (* NOT R1 *)
21 | XOUT : REAL ; (* Integrated output *)
22 | END_VAR
23 | Q := NOT R1 ;
24 | IF R1 THEN XOUT := X0 ;
25 | ELSIF RUN THEN XOUT := XOUT + XIN * TIME_TO_REAL(CYCLE);
26 | END_IF ;
27 | END_FUNCTION_BLOCK
28 |
29 |
--------------------------------------------------------------------------------
/lib/pid_st.txt:
--------------------------------------------------------------------------------
1 | (* Following taken directly from the IEC 61131.3 draft standard *)
2 |
3 | (*
4 | * An IEC 61131-3 IL and ST compiler.
5 | *
6 | * Based on the
7 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8 | *
9 | *)
10 |
11 | FUNCTION_BLOCK PID
12 | VAR_INPUT
13 | AUTO : BOOL ; (* 0 - manual , 1 - automatic *)
14 | PV : REAL ; (* Process variable *)
15 | SP : REAL ; (* Set point *)
16 | X0 : REAL ; (* Manual output adjustment - *)
17 | (* Typically from transfer station *)
18 | KP : REAL ; (* Proportionality constant *)
19 | TR : REAL ; (* Reset time *)
20 | TD : REAL ; (* Derivative time constant *)
21 | CYCLE : TIME ; (* Sampling period *)
22 | END_VAR
23 | VAR_OUTPUT XOUT : REAL; END_VAR
24 | VAR ERROR : REAL ; (* PV - SP *)
25 | ITERM : INTEGRAL ; (* FB for integral term *)
26 | DTERM : DERIVATIVE ; (* FB for derivative term *)
27 | END_VAR
28 | ERROR := PV - SP ;
29 | (*** Adjust ITERM so that XOUT := X0 when AUTO = 0 ***)
30 | ITERM (RUN := AUTO, R1 := NOT AUTO, XIN := ERROR,
31 | X0 := TR * (X0 - ERROR), CYCLE := CYCLE) ;
32 | DTERM (RUN := AUTO, XIN := ERROR, CYCLE := CYCLE) ;
33 | XOUT := KP * (ERROR + ITERM.XOUT/TR + DTERM.XOUT*TD) ;
34 | END_FUNCTION_BLOCK
35 |
36 |
--------------------------------------------------------------------------------
/lib/ramp_st.txt:
--------------------------------------------------------------------------------
1 | (* Following taken directly from the IEC 61131.3 draft standard *)
2 |
3 | (*
4 | * An IEC 61131-3 IL and ST compiler.
5 | *
6 | * Based on the
7 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8 | *
9 | *)
10 |
11 | FUNCTION_BLOCK RAMP
12 | VAR_INPUT
13 | RUN : BOOL ; (* 0 - track X0, 1 - ramp to/track X1 *)
14 | X0,X1 : REAL ;
15 | TR : TIME ; (* Ramp duration *)
16 | CYCLE : TIME ; (* Sampling period *)
17 | END_VAR
18 | VAR_OUTPUT
19 | BUSY : BOOL ; (* BUSY = 1 during ramping period *)
20 | XOUT : REAL := 0.0 ;
21 | END_VAR
22 | VAR XI : REAL ; (* Initial value *)
23 | T : TIME := T#0s; (* Elapsed time of ramp *)
24 | END_VAR
25 | BUSY := RUN ;
26 | IF RUN THEN
27 | IF T >= TR THEN BUSY := 0 ; XOUT := X1 ;
28 | ELSE XOUT := XI + (X1-XI) * TIME_TO_REAL(T)
29 | / TIME_TO_REAL(TR) ;
30 | T := T + CYCLE ;
31 | END_IF ;
32 | ELSE XOUT := X0 ; XI := X0 ; T := t#0s ;
33 | END_IF ;
34 | END_FUNCTION_BLOCK
35 |
36 |
--------------------------------------------------------------------------------
/lib/rtc.txt:
--------------------------------------------------------------------------------
1 | (****************************************************************
2 |
3 | RTC - Real-time clock
4 |
5 | Q is a copy of IN.
6 |
7 | When IN = FALSE, CDT is the current date and time as set by the
8 | PLC driver.
9 |
10 | When IN changes from FALSE to TRUE, PDT is stored. As long as IN is
11 | TRUE, CDT is equal to PDT + the amount of time since PDT was loaded.
12 |
13 | ****************************************************************)
14 |
15 | FUNCTION_BLOCK RTC
16 | VAR_INPUT
17 | IN : BOOL; (* 0 - current time, 1 - load time from
18 | PDT *)
19 | PDT : DT; (* Preset datetime *)
20 | END_VAR
21 | VAR_OUTPUT
22 | Q : BOOL := FALSE; (* Copy of IN *)
23 | CDT : DT; (* Datetime, current or relative to PDT *)
24 | END_VAR
25 |
26 | VAR
27 | PREV_IN : BOOL := FALSE;
28 | OFFSET : TIME;
29 | CURRENT_TIME : DT;
30 | END_VAR
31 |
32 | {__SET_VAR(data__->,CURRENT_TIME,,__CURRENT_TIME)}
33 |
34 | IF IN
35 | THEN
36 | IF NOT PREV_IN
37 | THEN
38 | OFFSET := PDT - CURRENT_TIME;
39 | END_IF;
40 |
41 | (* PDT + time since PDT was loaded *)
42 | CDT := CURRENT_TIME + OFFSET;
43 | ELSE
44 | CDT := CURRENT_TIME;
45 | END_IF;
46 |
47 | Q := IN;
48 | PREV_IN := IN;
49 |
50 | END_FUNCTION_BLOCK
51 |
52 |
--------------------------------------------------------------------------------
/lib/sema.txt:
--------------------------------------------------------------------------------
1 | (*
2 | * (c) 2011 Edouard Tisserant
3 | *
4 | * Fake semaphore support, for non preemptive implementation.
5 | *
6 | *)
7 |
8 |
9 | FUNCTION_BLOCK SEMA
10 | VAR_INPUT
11 | CLAIM : BOOL;
12 | RELEASE : BOOL;
13 | END_VAR
14 | VAR_OUTPUT
15 | BUSY : BOOL;
16 | END_VAR
17 | VAR
18 | Q_INTERNAL : BOOL;
19 | END_VAR
20 |
21 | Q_INTERNAL := CLAIM OR ( Q_INTERNAL AND (NOT RELEASE));
22 | BUSY := Q_INTERNAL;
23 |
24 | END_FUNCTION_BLOCK
25 |
26 |
--------------------------------------------------------------------------------
/lib/standard_FB.txt:
--------------------------------------------------------------------------------
1 | (*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | *)
23 |
24 | (* This is the library containing the standard function blocks defined in the standard. *)
25 |
26 | (* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) *)
27 |
28 |
29 | {disable code generation}
30 |
31 |
32 | (* The standard function blocks *)
33 | {#include "edge_detection.txt" }
34 | {#include "bistable.txt" }
35 | {#include "counter.txt" }
36 | {#include "timer.txt" }
37 | {#include "derivative_st.txt" }
38 | {#include "hysteresis_st.txt" }
39 | {#include "integral_st.txt" }
40 | {#include "pid_st.txt" }
41 | {#include "ramp_st.txt" }
42 | {#include "rtc.txt" }
43 |
44 | (* Not in the standard, but useful nonetheless. *)
45 | {#include "sema.txt" }
46 |
47 |
48 | {enable code generation}
49 |
--------------------------------------------------------------------------------
/lib/test_iec_std_lib.c:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | *
24 | * Test bed for C implementation of standard IEC functions.
25 | *
26 | */
27 |
28 | #include "iec_std_lib.h"
29 |
30 | int main(int argc,char **argv)
31 | {
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/stage1_2/.cvsignore:
--------------------------------------------------------------------------------
1 | iec.flex.c
2 | iec.y.output
3 | iec.y.cc
4 | iec.y.hh
5 | Makefile.depend
6 |
--------------------------------------------------------------------------------
/stage1_2/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../common.mk
2 |
3 | ## Flags for yacc syntax parser generator (bison)
4 | AM_YFLAGS = -d
5 | ## Flags for lex lexer generator (flex)
6 | AM_LFLAGS = --warn -o$(LEX_OUTPUT_ROOT).c
7 |
8 | # Make sure this header file is generated first (by bison), as it is included
9 | # by other C++ code that will also be compiled.
10 | BUILT_SOURCES = iec_bison.hh
11 |
12 | %.hh: %.h
13 | cp $< $@
14 |
15 | CLEANFILES = \
16 | iec_flex.cc \
17 | iec_bison.cc \
18 | iec_bison.hh
19 |
20 | lib_LIBRARIES = libstage1_2.a
21 | libstage1_2_a_SOURCES = \
22 | iec_flex.ll \
23 | iec_bison.yy \
24 | create_enumtype_conversion_functions.cc \
25 | stage1_2.cc
26 |
27 | libstage1_2_a_CPPFLAGS = -DDEFAULT_LIBDIR='"lib"' -I../../absyntax -DYY_BUF_SIZE=65536 -fpermissive
28 |
29 |
--------------------------------------------------------------------------------
/stage1_2/create_enumtype_conversion_functions.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
6 | *
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | *
21 | *
22 | * This code is made available on the understanding that it will not be
23 | * used in safety-critical situations without a full and competent review.
24 | */
25 |
26 | /*
27 | * An IEC 61131-3 compiler.
28 | *
29 | * Based on the
30 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
31 | *
32 | */
33 |
34 | /*
35 | * create_enumtype_conversion_functions_c generates ST conversion functions source code for
36 | * enumerate user defined data types.
37 | *
38 | */
39 |
40 | #ifndef _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH
41 | #define _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH
42 |
43 | #include
44 | #include
45 |
46 | #include "../absyntax_utils/absyntax_utils.hh"
47 |
48 |
49 | class create_enumtype_conversion_functions_c: public iterator_visitor_c {
50 | private:
51 | static create_enumtype_conversion_functions_c *singleton;
52 |
53 | public:
54 | explicit create_enumtype_conversion_functions_c(symbol_c *ignore);
55 | virtual ~create_enumtype_conversion_functions_c(void);
56 | static std::string &get_declaration(symbol_c *symbol);
57 |
58 | void *visit( identifier_c *symbol);
59 | void *visit( poutype_identifier_c *symbol);
60 | void *visit(derived_datatype_identifier_c *symbol);
61 |
62 | /**********************/
63 | /* B 1.3 - Data types */
64 | /**********************/
65 | /********************************/
66 | /* B 1.3.3 - Derived data types */
67 | /********************************/
68 | void *visit(enumerated_type_declaration_c *symbol);
69 | void *visit(enumerated_value_list_c *symbol);
70 |
71 | private:
72 | std::string text;
73 | std::string currentToken;
74 | std::list currentTokenList;
75 | std::string getIntegerName(bool isSigned, size_t size);
76 | void printStringToEnum (std::string &enumerateName, std::list &enumerateValues);
77 | void printEnumToString (std::string &enumerateName, std::list &enumerateValues);
78 | void printIntegerToEnum (std::string &enumerateName, std::list &enumerateValues, bool isSigned, size_t size);
79 | void printEnumToInteger (std::string &enumerateName, std::list &enumerateValues, bool isSigned, size_t size);
80 | };
81 |
82 | #endif /* _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH */
83 |
--------------------------------------------------------------------------------
/stage1_2/stage1_2.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * The public interface to stage1_2.cc
36 | */
37 |
38 |
39 |
40 | #ifndef _STAGE1_2_HH
41 | #define _STAGE1_2_HH
42 |
43 |
44 |
45 | /* This file includes the interface through which the main function accesses the stage1_2 services */
46 |
47 |
48 | int stage1_2(const char *filename, symbol_c **tree_root);
49 |
50 |
51 |
52 |
53 |
54 | #endif /* _STAGE1_2_HH */
55 |
--------------------------------------------------------------------------------
/stage3/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../common.mk
2 |
3 | lib_LIBRARIES = libstage3.a
4 |
5 | libstage3_a_SOURCES = \
6 | stage3.cc \
7 | flow_control_analysis.cc \
8 | fill_candidate_datatypes.cc \
9 | narrow_candidate_datatypes.cc \
10 | forced_narrow_candidate_datatypes.cc \
11 | print_datatypes_error.cc \
12 | datatype_functions.cc \
13 | lvalue_check.cc \
14 | array_range_check.cc \
15 | case_elements_check.cc \
16 | constant_folding.cc \
17 | declaration_check.cc \
18 | enum_declaration_check.cc \
19 | remove_forward_dependencies.cc
20 |
21 |
--------------------------------------------------------------------------------
/stage3/TODO:
--------------------------------------------------------------------------------
1 |
2 |
3 | Things that we must still check for in stage 3:
4 |
5 |
6 | 1) Handling of CONSTANTs:
7 |
8 | 1.a) "Any program organization unit attempts to modify the value of a variable that has been declared with the CONSTANT qualifier;"
9 | 1.b) From table 16.a "The CONSTANT qualifier shall not be used in the declaration of function block instances as described in 2.5.2.1."
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/stage3/array_range_check.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
6 | *
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | *
21 | *
22 | * This code is made available on the understanding that it will not be
23 | * used in safety-critical situations without a full and competent review.
24 | */
25 |
26 | /*
27 | * An IEC 61131-3 compiler.
28 | *
29 | * Based on the
30 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
31 | *
32 | */
33 |
34 | // #include
35 | #include "../absyntax_utils/absyntax_utils.hh"
36 | // #include "datatype_functions.hh"
37 |
38 |
39 |
40 | class array_range_check_c: public iterator_visitor_c {
41 |
42 | private:
43 | search_varfb_instance_type_c *search_varfb_instance_type;
44 | int error_count;
45 | int current_display_error_level;
46 |
47 | void check_dimension_count(array_variable_c *symbol);
48 | void check_bounds(array_variable_c *symbol);
49 |
50 | public:
51 | array_range_check_c(symbol_c *ignore);
52 | virtual ~array_range_check_c(void);
53 | int get_error_count();
54 |
55 | /*************************/
56 | /* B.1 - Common elements */
57 | /*************************/
58 | /**********************/
59 | /* B.1.3 - Data types */
60 | /**********************/
61 | /********************************/
62 | /* B 1.3.3 - Derived data types */
63 | /********************************/
64 | /* NOTE: we may later want to move the following 2 methods to a visitor that will focus on analysing the data type declarations! */
65 | void *visit(subrange_c *symbol);
66 | void *visit(array_initial_elements_c *symbol);
67 |
68 | /*********************/
69 | /* B 1.4 - Variables */
70 | /*********************/
71 | /*************************************/
72 | /* B 1.4.2 - Multi-element variables */
73 | /*************************************/
74 | void *visit(array_variable_c *symbol);
75 |
76 | /**************************************/
77 | /* B 1.5 - Program organisation units */
78 | /**************************************/
79 | /***********************/
80 | /* B 1.5.1 - Functions */
81 | /***********************/
82 | void *visit(function_declaration_c *symbol);
83 |
84 | /*****************************/
85 | /* B 1.5.2 - Function blocks */
86 | /*****************************/
87 | void *visit(function_block_declaration_c *symbol);
88 |
89 | /**********************/
90 | /* B 1.5.3 - Programs */
91 | /**********************/
92 | void *visit(program_declaration_c *symbol);
93 |
94 | }; /* array_range_check_c */
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/stage3/case_elements_check.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2015 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Case Options Checking:
36 | * - Check whether the options in a case statement are repeated, either directly, or in a range.
37 | * For example:
38 | * case var of
39 | * 1: ... <- OK
40 | * 2: ... <- OK
41 | * 1: ... <- OK (not an error), but produce a warning!
42 | * 0..8: ...<- OK (not an error), but produce a warning!
43 | */
44 |
45 | #include "../absyntax_utils/absyntax_utils.hh"
46 |
47 |
48 |
49 | class case_elements_check_c: public iterator_visitor_c {
50 |
51 | private:
52 | bool warning_found;
53 | int error_count;
54 | int current_display_error_level;
55 |
56 | std::vector case_elements_list;
57 | void check_subr_subr(symbol_c *s1, symbol_c *s2);
58 | void check_subr_symb(symbol_c *s1, symbol_c *s2);
59 | void check_symb_symb(symbol_c *s1, symbol_c *s2);
60 |
61 |
62 | public:
63 | case_elements_check_c(symbol_c *ignore);
64 | virtual ~case_elements_check_c(void);
65 | int get_error_count();
66 |
67 | /***************************************/
68 | /* B.3 - Language ST (Structured Text) */
69 | /***************************************/
70 | /********************/
71 | /* B 3.2 Statements */
72 | /********************/
73 | /********************************/
74 | /* B 3.2.3 Selection Statements */
75 | /********************************/
76 | void *visit(case_statement_c *symbol);
77 | void *visit(case_list_c *symbol);
78 | }; /* case_elements_check_c */
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/stage3/datatype_functions.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | #ifndef _HELPER_FUNCTIONS_HH_
26 | #define _HELPER_FUNCTIONS_HH_
27 |
28 | #include "../absyntax/visitor.hh"
29 | #include
30 |
31 |
32 |
33 |
34 |
35 | typedef struct {
36 | symbol_c *function_name;
37 | symbol_c *nonformal_operand_list;
38 | symbol_c * formal_operand_list;
39 |
40 | enum {POU_FB, POU_function} POU_type;
41 | //symbol_c &*datatype;
42 | //std::vector &candidate_datatypes;
43 | std::vector &candidate_functions;
44 | symbol_c *&called_function_declaration;
45 | int &extensible_param_count;
46 | } generic_function_call_t;
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | /* Widening Primitive Conversion */
56 | struct widen_entry {
57 | symbol_c *left;
58 | symbol_c *right;
59 | symbol_c *result;
60 | enum {ok, deprecated} status;
61 | };
62 | /*
63 | * 2.5.1.5.6 Functions of time data types
64 | * Table 30 - page 64
65 | */
66 | extern const struct widen_entry widen_ADD_table[];
67 | extern const struct widen_entry widen_SUB_table[];
68 | extern const struct widen_entry widen_MUL_table[];
69 | extern const struct widen_entry widen_DIV_table[];
70 | extern const struct widen_entry widen_MOD_table[];
71 | extern const struct widen_entry widen_EXPT_table[];
72 | extern const struct widen_entry widen_AND_table[];
73 | extern const struct widen_entry widen_OR_table[];
74 | extern const struct widen_entry widen_XOR_table[];
75 | extern const struct widen_entry widen_CMP_table[];
76 |
77 | /* Search for a datatype inside a candidate_datatypes list.
78 | * Returns: position of datatype in the list, or -1 if not found.
79 | */
80 | int search_in_candidate_datatype_list(symbol_c *datatype, const std::vector &candidate_datatypes);
81 |
82 | /* Remove a datatype inside a candidate_datatypes list.
83 | * Returns: If successful it returns true, false otherwise.
84 | */
85 | bool remove_from_candidate_datatype_list(symbol_c *datatype, std::vector &candidate_datatypes);
86 |
87 | /* Intersect two candidate_datatype_lists.
88 | * Remove from list1 (origin, dest.) all elements that are not found in list2 (with).
89 | * In essence, list1 will contain the result of the intersection of list1 with list2.
90 | * In other words, modify list1 so it only contains the elelements that are simultaneously in list1 and list2!
91 | */
92 | void intersect_candidate_datatype_list(symbol_c *list1 /*origin, dest.*/, symbol_c *list2 /*with*/);
93 |
94 | /* intersect the candidate_datatype lists of all prev_il_intructions, and set the local candidate_datatype list to the result! */
95 | void intersect_prev_candidate_datatype_lists(il_instruction_c *symbol);
96 |
97 |
98 |
99 |
100 |
101 | #endif /* _HELPER_FUNCTIONS_HH_ */
102 |
--------------------------------------------------------------------------------
/stage3/declaration_check.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2012 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 | #include
34 |
35 | #include "../absyntax_utils/absyntax_utils.hh"
36 |
37 |
38 | class declaration_check_c : public iterator_visitor_c {
39 | int error_count;
40 | int current_display_error_level;
41 | symbol_c *current_pou_decl;
42 | symbol_c *current_resource_decl;
43 |
44 | public:
45 | declaration_check_c(symbol_c *ignore);
46 | virtual ~declaration_check_c(void);
47 | int get_error_count();
48 |
49 | /*****************************/
50 | /* B 1.5.2 - Function Blocks */
51 | /*****************************/
52 | void *visit(function_block_declaration_c *symbol);
53 |
54 | /******************************************/
55 | /* B 1.5.3 - Declaration & Initialisation */
56 | /******************************************/
57 | void *visit(program_declaration_c *symbol);
58 |
59 | /********************************/
60 | /* B 1.7 Configuration elements */
61 | /********************************/
62 | void *visit(configuration_declaration_c *symbol);
63 | void *visit(resource_declaration_c *symbol);
64 | void *visit(program_configuration_c *symbol);
65 | };
66 |
--------------------------------------------------------------------------------
/stage3/enum_declaration_check.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 |
33 | #include "../absyntax_utils/absyntax_utils.hh"
34 |
35 | class populate_enumvalue_symtable_c;
36 |
37 | class enum_declaration_check_c : public iterator_visitor_c {
38 | private:
39 | int error_count;
40 | int current_display_error_level;
41 | populate_enumvalue_symtable_c *populate_enumvalue_symtable;
42 | symbol_c::enumvalue_symtable_t *global_enumvalue_symtable;
43 |
44 | public:
45 | enum_declaration_check_c(symbol_c *ignore);
46 | ~enum_declaration_check_c(void);
47 | int get_error_count();
48 |
49 |
50 | /***************************/
51 | /* B 0 - Programming Model */
52 | /***************************/
53 | void *visit(library_c *symbol);
54 |
55 | /**********************/
56 | /* B.1.3 - Data types */
57 | /**********************/
58 | void *visit(data_type_declaration_c *symbol);
59 |
60 | /***********************/
61 | /* B 1.5.1 - Functions */
62 | /***********************/
63 | void *visit(function_declaration_c *symbol);
64 |
65 | /*****************************/
66 | /* B 1.5.2 - Function Blocks */
67 | /*****************************/
68 | void *visit(function_block_declaration_c *symbol);
69 |
70 | /******************************************/
71 | /* B 1.5.3 - Declaration & Initialisation */
72 | /******************************************/
73 | void *visit(program_declaration_c *symbol);
74 |
75 | /********************************/
76 | /* B 1.7 Configuration elements */
77 | /********************************/
78 | void *visit(configuration_declaration_c *symbol);
79 | void *visit(resource_declaration_c *symbol);
80 | void *visit(single_resource_declaration_c *symbol);
81 | };
82 |
--------------------------------------------------------------------------------
/stage3/forced_narrow_candidate_datatypes.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * forced_narrow_candidate_datatypes_c
36 | *
37 | */
38 |
39 |
40 |
41 | #include "../absyntax_utils/absyntax_utils.hh"
42 | #include "narrow_candidate_datatypes.hh"
43 |
44 |
45 |
46 | class forced_narrow_candidate_datatypes_c: public narrow_candidate_datatypes_c {
47 |
48 | private:
49 | void forced_narrow_il_instruction(symbol_c *symbol, std::vector &next_il_instruction);
50 |
51 | protected:
52 | virtual void set_datatype_in_prev_il_instructions(symbol_c *datatype, il_instruction_c *symbol);
53 |
54 | public:
55 | forced_narrow_candidate_datatypes_c(symbol_c *ignore);
56 | virtual ~forced_narrow_candidate_datatypes_c(void);
57 |
58 | /****************************************/
59 | /* B.2 - Language IL (Instruction List) */
60 | /****************************************/
61 | /***********************************/
62 | /* B 2.1 Instructions and Operands */
63 | /***********************************/
64 | void *visit(instruction_list_c *symbol);
65 | void *visit(il_instruction_c *symbol);
66 | // void *visit(il_simple_operation_c *symbol);
67 | // void *visit(il_function_call_c *symbol);
68 | // void *visit(il_expression_c *symbol);
69 | // void *visit(il_jump_operation_c *symbol);
70 | // void *visit(il_fb_call_c *symbol);
71 | // void *visit(il_formal_funct_call_c *symbol);
72 | // void *visit(il_operand_list_c *symbol);
73 | // void *visit(simple_instr_list_c *symbol);
74 | void *visit(il_simple_instruction_c*symbol);
75 | // void *visit(il_param_list_c *symbol);
76 | // void *visit(il_param_assignment_c *symbol);
77 | // void *visit(il_param_out_assignment_c *symbol);
78 | // void *visit(il_assign_operator_c *symbol);
79 | // void *visit(il_assign_operator_c *symbol);
80 |
81 | /***************************************/
82 | /* B.3 - Language ST (Structured Text) */
83 | /***************************************/
84 | void *visit(statement_list_c *symbol);
85 | }; // forced_narrow_candidate_datatypes_c
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/stage3/remove_forward_dependencies.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2014 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 | /*
25 | * An IEC 61131-3 compiler.
26 | *
27 | * Based on the
28 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
29 | *
30 | */
31 |
32 |
33 | /*
34 | * Re-oder the POUs in te library so that no forward references occur.
35 | *
36 | * Since stage1_2 now suppport POUs that contain references to POUS that are only declared later,
37 | * (e.g. a variable of FB1_t is declared, before the FB1_T function block is itself declared!)
38 | * we may need to re-order all the POUs in the library so that these forward references do not occur.
39 | *
40 | * This utility class will do just that. However, it does not destroy the original abstract syntax
41 | * tree (AST). It instead creates a new re-ordered AST, by instantiating a new library_c object.
42 | * This new library_c object will however point to the *same* objects of the original AST, just in
43 | * a new order.
44 | * This means that the new and original AST share all the object instances, and only use a distinct
45 | * library_c object!
46 | */
47 |
48 | #include "../absyntax/absyntax.hh"
49 | #include "../absyntax/visitor.hh"
50 | #include "../util/symtable.hh"
51 | #include
52 |
53 |
54 | class find_forward_dependencies_c;
55 | typedef symtable_c identifiers_symbtable_t;
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | class remove_forward_dependencies_c: public search_visitor_c {
64 |
65 | private:
66 | /* The level of detail that the user wants us to display error messages. */
67 | #define error_level_default (1)
68 | #define error_level_nagging (4)
69 | unsigned int current_display_error_level;
70 | int error_count;
71 | bool warning_found;
72 | library_c *new_tree;
73 | int cycle_count; // main algorithm runs in a loop. The nuber of the current cycle...
74 | // NOTE: we need two lists in order to correctly handle overloaded functions
75 | identifiers_symbtable_t declared_identifiers; // list of identifiers already declared by the symbols in the new tree
76 | std::set inserted_symbols; // list of symbols already inserted in the new tree
77 | symbol_c *current_code_generation_pragma; // points to any currently 'active' enable_code_generation_pragma_c
78 | find_forward_dependencies_c *find_forward_dependencies;
79 |
80 | public:
81 | remove_forward_dependencies_c(void);
82 | ~remove_forward_dependencies_c(void);
83 | library_c *create_new_tree(symbol_c *old_tree); // create a new tree with POUs ordered so it does not contain forward dependencies...
84 | int get_error_count(void);
85 |
86 | private:
87 | void *handle_library_symbol(symbol_c *symbol, symbol_c *name, symbol_c *search1, symbol_c *search2 = NULL, symbol_c *search3 = NULL);
88 | void print_circ_error(library_c *symbol);
89 |
90 | /***************************/
91 | /* B 0 - Programming Model */
92 | /***************************/
93 | void *visit(library_c *symbol);
94 | /**************************************/
95 | /* B.1.5 - Program organization units */
96 | /**************************************/
97 | void *visit(function_declaration_c *symbol);
98 | void *visit(function_block_declaration_c *symbol);
99 | void *visit(program_declaration_c *symbol);
100 | /********************************/
101 | /* B 1.7 Configuration elements */
102 | /********************************/
103 | void *visit(configuration_declaration_c *symbol);
104 | /********************/
105 | /* 2.1.6 - Pragmas */
106 | /********************/
107 | void *visit(disable_code_generation_pragma_c *symbol);
108 | void *visit(enable_code_generation_pragma_c *symbol);
109 | void *visit(pragma_c *symbol);
110 |
111 | }; /* class remove_forward_dependencies_c */
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/stage3/stage3.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 | #ifndef _STAGE3_HH
34 | #define _STAGE3_HH
35 |
36 | #include "../util/symtable.hh"
37 |
38 |
39 | int stage3(symbol_c *tree_root, symbol_c **ordered_tree_root);
40 |
41 | #endif /* _STAGE3_HH */
42 |
--------------------------------------------------------------------------------
/stage4/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../common.mk
2 |
3 | SUBDIRS = generate_c generate_iec
4 |
5 | CLEANFILES = stage4.o
6 |
7 |
--------------------------------------------------------------------------------
/stage4/generate_c/.cvsignore:
--------------------------------------------------------------------------------
1 | Makefile.depend
2 | test_iec_std_lib
3 |
--------------------------------------------------------------------------------
/stage4/generate_c/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../../common.mk
2 |
3 | lib_LIBRARIES = libstage4_c.a
4 |
5 | libstage4_c_a_SOURCES = generate_c.cc
6 |
7 | libstage4_c_a_LIBADD = ../stage4.o
8 |
9 | libstage4_c_a_CPPFLAGS = -I../../../absyntax
10 |
11 |
--------------------------------------------------------------------------------
/stage4/generate_c/generate_c.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * This is one of the versions available for the 4th stage.
36 | *
37 | * This 4th stage generates a c source program equivalent
38 | * to the IL, ST and SFC code.
39 | */
40 |
41 |
42 | /*
43 | * generate_c.HH
44 | */
45 |
46 |
47 | #ifndef _generate_c_HH
48 | #define _generate_c_HH
49 |
50 |
51 |
52 | #include
53 | #include "../../absyntax/absyntax.hh"
54 | #include "../../absyntax/visitor.hh"
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | #endif /* _generate_c_H */
64 |
65 |
--------------------------------------------------------------------------------
/stage4/generate_c/plc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * (c) 2000 Jiri Baum
3 | * Mario de Sousa
4 | *
5 | * Offered to the public under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; either version 2 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 | * Public License for more details.
13 | *
14 | * This code is made available on the understanding that it will not be
15 | * used in safety-critical situations without a full and competent review.
16 | */
17 |
18 |
19 | #ifndef __PLC_H
20 | #define __PLC_H
21 |
22 | #include /* required for declaration of FILE */
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 |
29 | #include "types.h"
30 | #include "log/log.h"
31 | #include "conffile/conffile.h"
32 | #include "cmm/cmm.h"
33 | #include "gmm/gmm.h"
34 | #include "synch/synch.h"
35 | #include "period/period.h"
36 | #include "state/state.h"
37 | #include "rt/rt.h"
38 |
39 |
40 | #define PLC_PT_NAME_MAX_LEN CMM_NAME_MAX_LEN
41 |
42 | /*** GENERAL ***/
43 | int plc_init(char const *module_name, int argc, char **argv);
44 | int plc_done(void);
45 |
46 | /*** SYNCHING ***/
47 | int plc_scan_beg(void);
48 | int plc_scan_end(void);
49 |
50 | /* memory must be de-allocated with free() */
51 | const char *plc_module_name(void);
52 |
53 | /*
54 | * UTIL functions;
55 | */
56 | int plc_print_usage(FILE *output);
57 | /* prints the command line arguments the plc_init() function accepts */
58 |
59 | /* not to be used by general plc modules. This function is used by the
60 | * plc_shutdown() function.
61 | */
62 | int plc_init_try(char const *module_name, int argc, char **argv);
63 |
64 |
65 | /* plc command line options leader */
66 | #define CLO_LEADER "--PLC"
67 |
68 | /* plc command line options */
69 | #define CLO_plc_id CLO_LEADER "plc_id="
70 | #define CLO_loc_local CLO_LEADER "local"
71 | #define CLO_loc_isolate CLO_LEADER "isolate"
72 | #define CLO_loc_shared CLO_LEADER "shared"
73 | #define CLO_privmap_key CLO_LEADER "local_map_key="
74 | #define CLO_log_level CLO_LEADER "debug="
75 | #define CLO_log_file CLO_LEADER "logfile="
76 | #define CLO_config_file CLO_LEADER "conf="
77 | #define CLO_module_name CLO_LEADER "module="
78 | #define CLO_force_init CLO_LEADER "force-init"
79 |
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif /* __PLC_H */
86 |
--------------------------------------------------------------------------------
/stage4/generate_c/types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * (c) 2000 Jiri Baum
3 | * Mario de Sousa
4 | *
5 | * Offered to the public under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; either version 2 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 | * Public License for more details.
13 | *
14 | * This code is made available on the understanding that it will not be
15 | * used in safety-critical situations without a full and competent review.
16 | */
17 |
18 |
19 | #ifndef __PLC_TYPES_H
20 | #define __PLC_TYPES_H
21 |
22 | #include
23 | #include /* some limits related to floats are located here (?) */
24 |
25 |
26 | /*
27 | * This will need to be conditional on the arquitecture or something.
28 | * Anyone know where we can snarf the relevant magic easily?
29 | */
30 | typedef double f64; /* 64-bit floating point */
31 | typedef float f32; /* 32-bit floating point */
32 |
33 | typedef unsigned long long int u64; /* 64-bit unsigned integer */
34 | typedef long long int i64; /* 64-bit signed integer */
35 | typedef unsigned int u32; /* 32-bit unsigned integer */
36 | typedef int i32; /* 32-bit signed integer */
37 | typedef unsigned short int u16; /* 16-bit unsigned integer */
38 | typedef short int i16; /* 16-bit signed integer */
39 | typedef unsigned char u8; /* 8-bit unsigned integer */
40 | typedef signed char i8; /* 8-bit signed integer */
41 |
42 | /* some platforms seem to be missing with the definition of FLT_MAX */
43 | #ifndef FLT_MAX
44 | /* this is the minimum value guaranteed by ANSI C++ */
45 | /* does anybody know the minimum value guaranteed for ANSI C ? */
46 | #define FLT_MAX 1E+37
47 | #endif
48 | #ifndef FLT_MIN
49 | /* this is the minimum value guaranteed by ANSI C++ */
50 | /* does anybody know the minimum value guaranteed for ANSI C ? */
51 | #define FLT_MIN 1E-37
52 | #endif
53 |
54 | #define f32_MAX FLT_MAX
55 | #define f32_MIN FLT_MIN
56 |
57 | #define u32_MAX UINT_MAX
58 | #define u32_MIN 0
59 | #define i32_MAX INT_MAX
60 | #define i32_MIN INT_MIN
61 |
62 | #define u16_MAX USHRT_MAX
63 | #define u16_MIN 0
64 | #define i16_MAX SHRT_MAX
65 | #define i16_MIN SHRT_MIN
66 |
67 | #define u8_MAX UCHAR_MAX
68 | #define u8_MIN 0
69 | #define i8_MAX SCHAR_MAX
70 | #define i8_MIN SCHAR_MIN
71 |
72 | #endif /* __PLC_TYPES_H */
73 |
74 |
--------------------------------------------------------------------------------
/stage4/generate_cc/.cvsignore:
--------------------------------------------------------------------------------
1 | *.depend
2 |
--------------------------------------------------------------------------------
/stage4/generate_iec/.cvsignore:
--------------------------------------------------------------------------------
1 | Makefile.depend
2 |
--------------------------------------------------------------------------------
/stage4/generate_iec/Makefile.am:
--------------------------------------------------------------------------------
1 | include ../../common.mk
2 |
3 | lib_LIBRARIES = libstage4_iec.a
4 |
5 | libstage4_iec_a_SOURCES = generate_iec.cc
6 |
7 | libstage4_iec_a_LIBADD = ../stage4.o
8 |
9 | libstage4_iec_a_CPPFLAGS = -I../../../absyntax
10 |
11 |
--------------------------------------------------------------------------------
/stage4/generate_iec/generate_iec.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * Code to be included into the code generated by the 4th stage.
36 | *
37 | * This is part of the 4th stage that generates
38 | * a ST and IL source program equivalent to the IL and ST
39 | * code.
40 | * This is expected to be used mainly in debuging the syntax
41 | * and lexical parser, and as a starting point for other
42 | * 4th stages.
43 | */
44 |
45 |
46 |
47 | /*
48 | * GENERATE_IEC.HH
49 | */
50 |
51 |
52 | #ifndef _GENERATE_IEC_HH
53 | #define _GENERATE_IEC_HH
54 |
55 |
56 |
57 | #include
58 | #include "../../absyntax/visitor.hh"
59 |
60 |
61 |
62 |
63 | #endif /* _GENERATE_IEC_HH */
64 |
--------------------------------------------------------------------------------
/stage4/stage4.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * An IEC 61131-3 compiler.
27 | *
28 | * Based on the
29 | * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
30 | *
31 | */
32 |
33 |
34 | /*
35 | * This file contains the code that stores the output generated
36 | * by each specific version of the 4th stage.
37 | */
38 |
39 | #ifndef _STAGE4_HH
40 | #define _STAGE4_HH
41 |
42 | #include "../absyntax/absyntax.hh"
43 |
44 |
45 | void stage4err(const char *stage4_generator_id, symbol_c *symbol1, symbol_c *symbol2, const char *errmsg, ...);
46 |
47 |
48 | class stage4out_c {
49 | public:
50 | std::string indent_level;
51 | std::string indent_spaces;
52 |
53 | public:
54 | stage4out_c(std::string indent_level = " ");
55 | stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level = " ");
56 | ~stage4out_c(void);
57 |
58 | void flush(void);
59 |
60 | void enable_output(void);
61 | void disable_output(void);
62 |
63 | void indent_right(void);
64 | void indent_left(void);
65 |
66 | void *print( std::string value);
67 | void *print( const char *value);
68 | //void *print( int64_t value); // not required, since we have long long int, or similar
69 | //void *print( uint64_t value); // not required, since we have long long int, or similar
70 | void *print( real64_t value);
71 | void *print( int value);
72 | void *print( long int value);
73 | void *print( long long int value);
74 | void *print(unsigned int value);
75 | void *print(unsigned long int value);
76 | void *print(unsigned long long int value);
77 |
78 | void *print_long_integer(unsigned long l_integer, bool suffix=true);
79 | void *print_long_long_integer(unsigned long long ll_integer, bool suffix=true);
80 |
81 |
82 | void *printupper(const char *str);
83 | void *printupper(std::string str);
84 |
85 | void *printlocation(const char *str);
86 | void *printlocation(std::string str);
87 |
88 | void *printlocation_comasep(const char *str);
89 |
90 | protected:
91 | std::ostream *out;
92 | std::fstream *m_file;
93 |
94 | /* A flag to tell whether to really print to the file, or to ignore any request to print to the file */
95 | /* This is used to implement the no_code_generation pragmas, that lets the user tell the compiler
96 | * when to switch on and off the code generation, without stoping the lexical, syntatical, and
97 | * semantic analysers from analysing the code.
98 | */
99 | bool allow_output;
100 |
101 | };
102 |
103 |
104 |
105 | int stage4(symbol_c *tree_root, const char *builddir);
106 |
107 | /* Functions to be implemented by each generate_XX version of stage 4 */
108 | int stage4_parse_options(char *options);
109 | void stage4_print_options(void);
110 |
111 | #endif /* _STAGE4_HH */
112 |
--------------------------------------------------------------------------------
/tests/.cvsignore:
--------------------------------------------------------------------------------
1 | STD_TEST.st
2 | STD_RESSOURCE.c
3 | LOCATED_VARIABLES.h
4 | POUS.c
5 | test
6 | STD_CONF.c
7 | SFC_TEST.st
8 | test.exe
9 | plc.st
10 | POUS.h
11 | VARIABLES.csv
12 |
--------------------------------------------------------------------------------
/tests/LD_TEST.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/tests/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # matiec - a compiler for the programming languages defined in IEC 61131-3
3 | #
4 | # Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | # Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 | # Shell script to build test for unix likes
21 |
22 | STFILE=$1
23 |
24 | shift
25 |
26 | CFLAGS=$*
27 |
28 |
29 | CC=gcc
30 | #CC=i686-mingw32-gcc
31 |
32 | ../iec2c $STFILE -I ../lib
33 | #2>/dev/null
34 |
35 | $CC -I ../lib -c STD_RESSOURCE.c $CFLAGS
36 |
37 | $CC -I ../lib -c STD_CONF.c $CFLAGS
38 |
39 | $CC -I ../lib -c plc.c $CFLAGS
40 |
41 | $CC -I ../lib main.c STD_CONF.o STD_RESSOURCE.o plc.o $CFLAGS -l rt -o test
42 |
--------------------------------------------------------------------------------
/tests/build_win32.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # matiec - a compiler for the programming languages defined in IEC 61131-3
3 | #
4 | # Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | # Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 | # Shell script to build test for windows
21 |
22 | STFILE=$1
23 |
24 | shift
25 |
26 | CFLAGS=$*
27 |
28 |
29 | #CC=gcc
30 | CC=i686-mingw32-gcc
31 |
32 | ../iec2c $STFILE -I ../lib
33 | #2>/dev/null
34 |
35 | $CC -I ../lib -c STD_RESSOURCE.c $CFLAGS
36 |
37 | $CC -I ../lib -c STD_CONF.c $CFLAGS
38 |
39 | $CC -I ../lib -c plc.c $CFLAGS
40 |
41 | $CC -I ../lib main.c STD_CONF.o STD_RESSOURCE.o plc.o $CFLAGS -o test.exe
42 |
--------------------------------------------------------------------------------
/tests/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | *
24 | *
25 | * Minimal standaloen C runtime, for test purpose.
26 | * TODO : UPDATE
27 | *
28 | */
29 |
30 | #ifdef __WIN32__
31 | #include
32 | #include
33 | #include
34 | #include
35 | #else
36 | #include
37 | #include
38 | #include
39 | #include
40 | #endif
41 |
42 | #include "iec_types.h"
43 |
44 | /*
45 | * Functions and variables provied by generated C softPLC
46 | **/
47 | extern int common_ticktime__;
48 |
49 | IEC_BOOL __DEBUG;
50 |
51 | /*
52 | * Functions and variables provied by plc.c
53 | **/
54 | void run(long int tv_sec, long int tv_nsec);
55 |
56 | #define maxval(a,b) ((a>b)?a:b)
57 |
58 | #ifdef __WIN32__
59 | void timer_notify()
60 | {
61 | struct _timeb timebuffer;
62 |
63 | _ftime( &timebuffer );
64 | run(timebuffer.time, timebuffer.millitm * 1000000);
65 | }
66 |
67 | int main(int argc,char **argv)
68 | {
69 | HANDLE hTimer = NULL;
70 | LARGE_INTEGER liDueTime;
71 |
72 | liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);;
73 |
74 | // Create a waitable timer.
75 | hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
76 | if (NULL == hTimer)
77 | {
78 | printf("CreateWaitableTimer failed (%d)\n", GetLastError());
79 | return 1;
80 | }
81 |
82 | config_init__();
83 |
84 | // Set a timer to wait for 10 seconds.
85 | if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
86 | {
87 | printf("SetWaitableTimer failed (%d)\n", GetLastError());
88 | return 2;
89 | }
90 |
91 | while(1){
92 | // Wait for the timer.
93 | if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
94 | {
95 | printf("WaitForSingleObject failed (%d)\n", GetLastError());
96 | break;
97 | }
98 | timer_notify();
99 | }
100 | return 0;
101 | }
102 | #else
103 | void timer_notify(sigval_t val)
104 | {
105 | struct timespec CURRENT_TIME;
106 | clock_gettime(CLOCK_REALTIME, &CURRENT_TIME);
107 | run(CURRENT_TIME.tv_sec, CURRENT_TIME.tv_nsec);
108 | }
109 |
110 | void catch_signal(int sig)
111 | {
112 | signal(SIGTERM, catch_signal);
113 | signal(SIGINT, catch_signal);
114 | printf("Got Signal %d\n",sig);
115 | }
116 |
117 | int main(int argc,char **argv)
118 | {
119 | timer_t timer;
120 | struct sigevent sigev;
121 | long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000);
122 | time_t tv_sec = common_ticktime__/1000;
123 | struct itimerspec timerValues;
124 |
125 | memset (&sigev, 0, sizeof (struct sigevent));
126 | memset (&timerValues, 0, sizeof (struct itimerspec));
127 | sigev.sigev_value.sival_int = 0;
128 | sigev.sigev_notify = SIGEV_THREAD;
129 | sigev.sigev_notify_attributes = NULL;
130 | sigev.sigev_notify_function = timer_notify;
131 | timerValues.it_value.tv_sec = tv_sec;
132 | timerValues.it_value.tv_nsec = tv_nsec;
133 | timerValues.it_interval.tv_sec = tv_sec;
134 | timerValues.it_interval.tv_nsec = tv_nsec;
135 |
136 | config_init__();
137 |
138 | timer_create (CLOCK_REALTIME, &sigev, &timer);
139 | timer_settime (timer, 0, &timerValues, NULL);
140 |
141 | /* install signal handler for manual break */
142 | signal(SIGTERM, catch_signal);
143 | signal(SIGINT, catch_signal);
144 |
145 | pause();
146 |
147 | timer_delete (timer);
148 |
149 | return 0;
150 | }
151 | #endif
152 |
--------------------------------------------------------------------------------
/tests/plc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | *
24 | *
25 | * Simple PLC run cycle test implementation - prints every located at each cycle
26 | *
27 | */
28 |
29 | #include "iec_std_lib.h"
30 | #include
31 |
32 | #define __print_BOOL(name) printf(" %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE");
33 | #define __print_SINT(name) printf(" %s = (SINT) %d\n",#name, name);
34 | #define __print_INT(name) printf(" %s = (INT) %d\n",#name, name);
35 | #define __print_DINT(name) printf(" %s = (DINT) %d\n",#name, name);
36 | #define __print_LINT(name) printf(" %s = (LINT) %d\n",#name, name);
37 | #define __print_USINT(name) printf(" %s = (USINT) %u\n",#name, name);
38 | #define __print_UINT(name) printf(" %s = (UINT) %u\n",#name, name);
39 | #define __print_UDINT(name) printf(" %s = (UDINT) %u\n",#name, name);
40 | #define __print_ULINT(name) printf(" %s = (ULINT) %lu\n",#name, name);
41 | #define __print_REAL(name) printf(" %s = (REAL) %f\n",#name, (double)name);
42 | #define __print_LREAL(name) printf(" %s = (LREAL) %f\n",#name, (double)name);
43 | #define __print_TIME(name) {STRING __tmp = __time_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, __tmp.len, &__tmp.body);}
44 | #define __print_DATE(name) {STRING __tmp = __date_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (DATE) %*s\n",#name, __tmp.len, &__tmp.body);}
45 | #define __print_TOD(name) {STRING __tmp = __tod_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (TOD) %*s\n",#name, __tmp.len, &__tmp.body);}
46 | #define __print_DT(name) {STRING __tmp = __dt_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (DT) %*s\n",#name, __tmp.len, &__tmp.body);}
47 | #define __print_STRING(name) printf(" %s = (STRING) {%d, \"%*s\"}\n",#name, name->len, name->len, &name->body);
48 | #define __print_BYTE(name) printf(" %s = (BYTE) 0x%2.2x\n",#name, name);
49 | #define __print_WORD(name) printf(" %s = (WORD) 0x%4.4x\n",#name, name);
50 | #define __print_DWORD(name) printf(" %s = (DWORD) 0x%8.8x\n",#name, name);
51 | #define __print_LWORD(name) printf(" %s = (LWORD) 0x%16.16lx\n",#name, name);
52 | /*
53 | * Functions and variables provied by generated C softPLC
54 | **/
55 | void config_run__(int tick);
56 | void config_init__(void);
57 |
58 | /*
59 | * Functions and variables to export to generated C softPLC
60 | **/
61 |
62 | TIME __CURRENT_TIME;
63 |
64 | #define __LOCATED_VAR(type, name, ...) type __##name;
65 | #include "LOCATED_VARIABLES.h"
66 | #undef __LOCATED_VAR
67 | #define __LOCATED_VAR(type, name, ...) type* name = &__##name;
68 | #include "LOCATED_VARIABLES.h"
69 | #undef __LOCATED_VAR
70 |
71 | static int tick = 0;
72 |
73 | void run()
74 | {
75 | printf("Tick %d\n",tick);
76 | config_run__(tick++);
77 | printf(" Located variables : \n");
78 | #define __LOCATED_VAR(type, name,...) __print_##type(name);
79 | #include "LOCATED_VARIABLES.h"
80 | #undef __LOCATED_VAR
81 | }
82 |
83 |
--------------------------------------------------------------------------------
/tests/syntax/configuration/configuration.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PROGRAM foo
5 | VAR_INPUT
6 | single, interval, priority : BOOL;
7 | END_VAR
8 | LD single
9 | LD interval
10 | LD priority
11 | END_PROGRAM
12 |
13 |
14 | PROGRAM priority
15 | VAR_INPUT
16 | bar : BOOL;
17 | END_VAR
18 | LD bar
19 | END_PROGRAM
20 |
21 |
22 | PROGRAM single
23 | VAR_INPUT
24 | bar : BOOL;
25 | END_VAR
26 | LD bar
27 | END_PROGRAM
28 |
29 |
30 | PROGRAM interval
31 | VAR_INPUT
32 | bar : BOOL;
33 | END_VAR
34 | LD bar
35 | END_PROGRAM
36 |
37 |
38 |
39 |
40 |
41 | CONFIGURATION config1
42 | TASK fast(PRIORITY := 4);
43 | PROGRAM P1 WITH fast:
44 | FOO(single := TRUE, interval := TRUE, priority := TRUE);
45 | END_CONFIGURATION
46 |
47 |
48 | CONFIGURATION config2
49 | TASK fast(SINGLE := 3, PRIORITY := 4);
50 | PROGRAM P1 WITH fast:
51 | FOO(single := TRUE, interval := TRUE, priority := TRUE);
52 | END_CONFIGURATION
53 |
54 |
55 | CONFIGURATION config3
56 | TASK fast(INTERVAL := T#1s, PRIORITY := 4);
57 | PROGRAM P1 WITH fast:
58 | FOO(single := TRUE, interval := TRUE, priority := TRUE);
59 | END_CONFIGURATION
60 |
61 |
62 | CONFIGURATION config4
63 | TASK fast(SINGLE := 3, INTERVAL := T#1s, PRIORITY := 4);
64 | PROGRAM P1 WITH fast:
65 | FOO(single := TRUE, interval := TRUE, priority := TRUE);
66 | END_CONFIGURATION
67 |
68 |
--------------------------------------------------------------------------------
/tests/syntax/enumeration/enumerationvalue.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TYPE
5 | enum_type00 : (enum_v1, XXXX, enum_v2) := XXXX;
6 | END_TYPE
7 |
8 | TYPE
9 | enum_type01 : (XXXX, enum_v2) := XXXX;
10 | END_TYPE
11 |
12 | TYPE
13 | enum_type02 : (enum_v1, XXXX) := XXXX;
14 | END_TYPE
15 |
16 | TYPE
17 | enum_type03 : (XXXX) := XXXX;
18 | END_TYPE
19 |
20 |
21 |
22 |
23 | function foo : int
24 | var_input
25 | a_1, b_1: int;
26 | end_var
27 | var
28 | c_1, d_1: enum_type00;
29 | (*
30 | enum_v1 : enum_type00;
31 | *)
32 | end_var
33 | c_1 := enum_type00#XXXX;
34 | c_1 := XXXX;
35 | c_1 := enum_v1;
36 | (*
37 | enum_v1 := enum_v1;
38 | *)
39 | end_function
40 |
41 |
42 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/Makefile:
--------------------------------------------------------------------------------
1 | # matiec - a compiler for the programming languages defined in IEC 61131-3
2 | #
3 | # Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
4 | # Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 |
19 |
20 | default: runtests
21 |
22 |
23 | runtests:
24 | ./runtests
25 |
26 |
27 | clean:
28 | rm -f *.iec
29 | rm -f *.err
30 | rm -f *.err2
31 | rm -f *.out
32 | rm -f *.out2
33 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier.txt:
--------------------------------------------------------------------------------
1 | ################
2 | # IL operators #
3 | ################
4 | # which are not simultaneously
5 | # - keywords (AND, OR, NOT, MOD, XOR),
6 | # - or standard funtion name (which by implication are also keywords)
7 | # (AND, OR, NOT, MOD, XOR, as well as, GE, GT, LE, LT, EQ, NE, SUB, ADD, MUL, DIV)
8 | # - or standard function block name (which by implication are also keywords)
9 | # - invalid identifier name (&, &N)
10 | ANDN
11 | CAL
12 | CALC
13 | CALCN
14 | CD
15 | CLK
16 | CU
17 | IN
18 | JMP
19 | JMPC
20 | JMPCN
21 | LD
22 | LDN
23 | ORN
24 | PT
25 | PV
26 | R
27 | R1
28 | RET
29 | RETC
30 | RETCN
31 | S
32 | S1
33 | ST
34 | STN
35 | XORN
36 |
37 |
38 | ##################
39 | # SFC qualifiers #
40 | ##################
41 | D
42 | DS
43 | L
44 | N
45 | P
46 | #R -> also an IL operator
47 | #S -> also an IL operator
48 | SD
49 | SL
50 |
51 |
52 | #####################
53 | # Task initialisers #
54 | #####################
55 | PRIORITY
56 | SINGLE
57 | INTERVAL
58 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_configuration.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * CONFIGURATION identifier
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (*
15 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
16 | #SFC_qualifiers D DS L N P #R #S SD SL
17 | NOTE: R and S are identical to IL operators!!
18 | #Task_initialisers PRIORITY SINGLE INTERVAL
19 | *)
20 |
21 |
22 |
23 | (* a helper program *)
24 | PROGRAM bar000
25 | VAR_INPUT
26 | a_1 : BOOL;
27 | END_VAR
28 | VAR_OUTPUT
29 | b_1 : BOOL;
30 | END_VAR
31 | a_1 := TRUE;
32 | END_PROGRAM
33 |
34 |
35 | (* using in program parameter *)
36 | CONFIGURATION XXXX
37 | TASK fast(PRIORITY := 4);
38 | PROGRAM foo WITH fast:
39 | bar000(a_1 := TRUE);
40 | END_CONFIGURATION
41 |
42 |
43 |
44 | (* Checking whether the use of XXXX will confuse any other
45 | * normal and correct IL or ST code.
46 | *)
47 | {#include "basic_code.test" }
48 |
49 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_datatype.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * derived data type identifier
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (*
15 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
16 | #SFC_qualifiers D DS L N P #R #S SD SL
17 | NOTE: R and S are identical to IL operators!!
18 | #Task_initialisers PRIORITY SINGLE INTERVAL
19 | *)
20 |
21 |
22 |
23 |
24 | TYPE
25 | XXXX : real := 50;
26 | END_TYPE
27 |
28 |
29 |
30 | function foo : int
31 | var_input
32 | a_1, b_1: XXXX;
33 | end_var
34 | var
35 | c_1, d_1: int;
36 | end_var
37 | c_1 := 0;
38 | end_function
39 |
40 |
41 |
42 | (* Checking whether the use of XXXX will confuse any other
43 | * normal and correct IL or ST code.
44 | *)
45 | {#include "basic_code.test" }
46 |
47 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_enumerationvalue.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * enumeration value
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (*
15 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
16 | #SFC_qualifiers D DS L N P #R #S SD SL
17 | NOTE: R and S are identical to IL operators!!
18 | #Task_initialisers PRIORITY SINGLE INTERVAL
19 | *)
20 |
21 |
22 |
23 |
24 | TYPE
25 | enum_type00 : (enum_v1, XXXX, enum_v2) := XXXX;
26 | END_TYPE
27 |
28 | TYPE
29 | enum_type01 : (XXXX, enum_v2) := XXXX;
30 | END_TYPE
31 |
32 | TYPE
33 | enum_type02 : (enum_v1, XXXX) := XXXX;
34 | END_TYPE
35 |
36 | TYPE
37 | enum_type03 : (XXXX) := XXXX;
38 | END_TYPE
39 |
40 |
41 |
42 |
43 | function foo : int
44 | var_input
45 | a_1, b_1: int;
46 | end_var
47 | var
48 | c_1, d_1: enum_type00;
49 | end_var
50 | c_1 := enum_type00#XXXX;
51 | c_1 := XXXX;
52 | end_function
53 |
54 |
55 |
56 | (* Checking whether the use of XXXX will confuse any other
57 | * normal and correct IL or ST code.
58 | *)
59 | {#include "basic_code.test" }
60 |
61 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_function1.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * FUNCTION declaration
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (* This file is specific for identifiers identical to IL operators.
15 | * See the note following the identifier list
16 | *)
17 | (*
18 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
19 | #SFC_qualifiers #D #DS #L #N #P #R #S #SD #SL
20 | #Task_initialisers #PRIORITY #SINGLE #INTERVAL
21 | *)
22 |
23 | (* NOTE: The identifier as a function test has some special cases.
24 | * Namely, when using IL operators as function names.
25 | * For example, if a function LD has been previoulsy defined,
26 | * The following IL code may be interpreted as either a
27 | * function call or an IL operation
28 | * LD 10
29 | * Due to undefined situations as the above, our
30 | * IEC compiler currently will always interpret IL operator identifiers.
31 | * inside IL code as an IL operator.
32 | * This means that calling, from IL code, of functions whose names
33 | * coincide with an IL operator is not possible.
34 | *
35 | * The following test code must therefore consider two possibilities:
36 | * - if the identifier under test is an IL operator
37 | * - if the identifier under test is not an IL operator
38 | *)
39 |
40 |
41 |
42 |
43 |
44 | (* The FUNCTION declaration *)
45 |
46 | function XXXX : int
47 | var_input
48 | a_1, b_1: int;
49 | end_var
50 | XXXX := a_1 + b_1;
51 | end_function
52 |
53 |
54 |
55 | (* Calling of the function from within ST code *)
56 | function foo : int
57 | var
58 | c_1, d_1 : int;
59 | e_1, f_1 : int;
60 | end_var
61 | d_1 := XXXX(c_1, d_1);
62 | d_1 := XXXX(10, 20);
63 | c_1 := XXXX(20, 22);
64 | c_1 := XXXX(b_1 := e_1, a_1 := f_1);
65 | c_1 := XXXX (a_1 := e_1, b_1 := f_1);
66 | end_function
67 |
68 |
69 |
70 |
71 | (* Calling of the function from within IL code *)
72 | (* NOTE: some legal identifiers, for ex. IL operators,
73 | * will not actually be interpreted as a reference to
74 | * the function, but rather as an IL operator.
75 | * However, no error should occur, as the compiler is written
76 | * to give priority to interpreting it as an IL operator.
77 | *)
78 |
79 | (*
80 | function bar000 : int
81 | var
82 | e_1, f_1 : int;
83 | end_var
84 | XXXX 10
85 | LD 20
86 | XXXX 30
87 | XXXX 10, 20
88 | XXXX (
89 | b_1 := 10,
90 | a_1 := 20
91 | )
92 | XXXX(
93 | b_1 := 10,
94 | a_1 := 20
95 | )
96 | XXXX (
97 | b_1 := 10
98 | )
99 | XXXX(
100 | b_1 := 10
101 | )
102 | end_function
103 | *)
104 |
105 |
106 |
107 |
108 | (* Checking whether the use of XXXX will confuse the logic
109 | * used to determine if a POU body is in IL or ST language.
110 | *)
111 |
112 | (*
113 | function bar001 : int
114 | var
115 | e_1, f_1 : int;
116 | end_var
117 | XXXX 10
118 | end_function
119 |
120 |
121 | function bar002 : int
122 | var
123 | e_1, f_1 : int;
124 | end_var
125 | XXXX 10, 20
126 | end_function
127 |
128 |
129 | function bar003 : int
130 | var
131 | e_1, f_1 : int;
132 | end_var
133 | XXXX(
134 | b_1 := 10,
135 | a_1 := 20
136 | )
137 | end_function
138 |
139 |
140 | function bar004 : int
141 | var
142 | e_1, f_1 : int;
143 | end_var
144 | XXXX (
145 | b_1 := 10,
146 | a_1 := 20
147 | )
148 | end_function
149 | *)
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | (* Checking whether the use of XXXX will confuse any other
160 | * normal and correct IL or ST code.
161 | *)
162 | {#include "basic_code.test"}
163 |
164 |
165 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_function2.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * FUNCTION declaration
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (* This file is specific for identifiers NOT identical to IL operators.
15 | * See the note following the identifier list
16 | *)
17 | (*
18 | #IL_operators #ANDN #CAL #CALC #CALCN #CD #CLK #CU #IN #JMP #JMPC #JMPCN #LD #LDN #ORN
19 | #IL_operators #PT #PV #R #R1 #RET #RETC #RETCN #S #S1 #ST #STN #XORN
20 | NOTE: R and S are identical to IL operators!!
21 | #SFC_qualifiers D DS L N P #R #S SD SL
22 | #Task_initialisers PRIORITY SINGLE INTERVAL
23 | *)
24 |
25 | (* NOTE: The identifier as a function test has some special cases.
26 | * Namely, when using IL operators as function names.
27 | * For example, if a function LD has been previoulsy defined,
28 | * The following IL code may be interpreted as either a
29 | * function call or an IL operation
30 | * LD 10
31 | * Due to undefined situations as the above, our
32 | * IEC compiler currently will always interpret IL operator identifiers.
33 | * inside IL code as an IL operator.
34 | * This means that calling, from IL code, of functions whose names
35 | * coincide with an IL operator is not possible.
36 | *
37 | * The following test code must therefore consider two possibilities:
38 | * - if the identifier under test is an IL operator
39 | * - if the identifier under test is not an IL operator
40 | *)
41 |
42 |
43 |
44 | (* The FUNCTION declaration *)
45 |
46 | function XXXX : int
47 | var_input
48 | a_1, b_1: int;
49 | end_var
50 | XXXX := a_1 + b_1;
51 | end_function
52 |
53 |
54 |
55 | (* Calling of the function from within ST code *)
56 | function foo : int
57 | var
58 | c_1, d_1 : int;
59 | e_1, f_1 : int;
60 | end_var
61 | d_1 := XXXX(c_1, d_1);
62 | d_1 := XXXX(10, 20);
63 | c_1 := XXXX(20, 22);
64 | c_1 := XXXX(b_1 := e_1, a_1 := f_1);
65 | c_1 := XXXX (a_1 := e_1, b_1 := f_1);
66 | end_function
67 |
68 |
69 |
70 | (* Calling of the function from within IL code *)
71 |
72 | function bar000 : int
73 | var
74 | e_1, f_1 : int;
75 | end_var
76 | XXXX 10
77 | LD 20
78 | XXXX 30
79 | XXXX 10, 20
80 | XXXX (
81 | b_1 := 10,
82 | a_1 := 20
83 | )
84 | XXXX(
85 | b_1 := 10,
86 | a_1 := 20
87 | )
88 | XXXX (
89 | b_1 := 10
90 | )
91 | XXXX(
92 | b_1 := 10
93 | )
94 | end_function
95 |
96 |
97 |
98 | (* Checking whether the use of XXXX will confuse the logic
99 | * used to determine if a POU body is in IL or ST language.
100 | *)
101 |
102 | function bar001 : int
103 | var
104 | e_1, f_1 : int;
105 | end_var
106 | XXXX 10
107 | end_function
108 |
109 |
110 | function bar002 : int
111 | var
112 | e_1, f_1 : int;
113 | end_var
114 | XXXX 10, 20
115 | end_function
116 |
117 |
118 | function bar003 : int
119 | var
120 | e_1, f_1 : int;
121 | end_var
122 | XXXX(
123 | b_1 := 10,
124 | a_1 := 20
125 | )
126 | end_function
127 |
128 |
129 | function bar004 : int
130 | var
131 | e_1, f_1 : int;
132 | end_var
133 | XXXX (
134 | b_1 := 10,
135 | a_1 := 20
136 | )
137 | end_function
138 |
139 |
140 |
141 |
142 |
143 |
144 | (* Checking whether the use of XXXX will confuse any other
145 | * normal and correct IL or ST code.
146 | *)
147 | {#include "basic_code.test" }
148 |
149 |
150 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_functionblock.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * FUNCTION_BLOCK declaration
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (*
15 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN
16 | #IL_operators PT PV R R1 RET RETC RETCN S S1 ST STN XORN
17 | NOTE: R and S are identical to IL operators!!
18 | #SFC_qualifiers D DS L N P #R #S SD SL
19 | #Task_initialisers PRIORITY SINGLE INTERVAL
20 | *)
21 |
22 |
23 |
24 |
25 |
26 | (* The FUNCTION BLOCK declaration *)
27 | function_block XXXX
28 | var_input
29 | a_1, b_1: int;
30 | end_var
31 | var_output
32 | c_1, d_1: int;
33 | end_var
34 | c_1 := 10 + b_1;
35 | end_function_block
36 |
37 |
38 | (* Calling of the function block from within ST code *)
39 |
40 | function_block foo
41 | var
42 | e_1, f_1 : int;
43 | fb : XXXX;
44 | end_var
45 | fb(10, 20);
46 | fb (10, 20, e_1, f_1);
47 | fb (a_1 := 10, b_1:=20, c_1=>e_1, d_1=>f_1);
48 | fb(a_1 := 10, b_1:=20, c_1=>e_1, d_1=>f_1);
49 | fb (c_1=>e_1, a_1:=20, d_1=>f_1);
50 | f_1 := fb.c_1;
51 | fb.a_1 := e_1;
52 | end_function_block
53 |
54 |
55 |
56 | (* Calling of the function block from within IL code *)
57 | function_block bar
58 | var
59 | e_1, f_1 : int;
60 | fb : XXXX;
61 | end_var
62 | CAL fb
63 | LD fb.a_1
64 | ST fb.b_1
65 | CAL fb (10)
66 | CAL fb(30, 20, e_1, f_1)
67 | CAL fb (
68 | a_1 := 10,
69 | c_1 => f_1
70 | )
71 | CAL fb(
72 | a_1 := 10,
73 | c_1 => f_1
74 | )
75 | end_function_block
76 |
77 |
78 |
79 | (* Checking whether the use of XXXX will confuse any other
80 | * normal and correct IL or ST code.
81 | *)
82 | {#include "basic_code.test" }
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | (*
93 |
94 | CONFIGURATION
95 | ......
96 | using these XXXX identifiers within a configuration
97 |
98 | especially a task initialisation, as Priority, single and interval may clash here.
99 | (they shouldn't, but if the parser has an error, they will....)
100 |
101 | END_CONFIGURATION
102 |
103 | *)
104 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_label.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * IL label name/identifier
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (*
15 | #IL_operators #ANDN #CAL #CALC #CALCN #CD #CLK #CU #IN #JMP #JMPC #JMPCN
16 | #IL_operators #LD #LDN #ORN #PT #PV #R #R1 #RET #RETC #RETCN #S #S1 #ST #STN #XORN
17 | #SFC_qualifiers D DS L N P #R #S SD SL
18 | NOTE: R and S are identical to IL operators!!
19 | #Task_initialisers PRIORITY SINGLE INTERVAL
20 | *)
21 |
22 | (* NOTE: Currently the matiec compiler does not yet support
23 | * the use of identifiers identical to IL operators
24 | * in IL code. In ther words, in IL code we cannot use
25 | * identifiers identical to IL operators to identify variables,
26 | * functions, etc...
27 | * Identifiers identical to IL operators are therefore
28 | * commented out.
29 | *)
30 |
31 |
32 |
33 |
34 |
35 | function foo : int
36 | var
37 | e, f : bool;
38 | end_var
39 |
40 | XXXX: R e
41 | JMP XXXX
42 | end_function
43 |
44 |
45 |
46 | function bar : int
47 | var
48 | e, f : bool;
49 | end_var
50 |
51 | JMP XXXX
52 | XXXX: R e
53 | end_function
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | (* Checking whether the use of XXXX will confuse any other
62 | * normal and correct IL or ST code.
63 | *)
64 | {#include "basic_code.test" }
65 |
66 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/identifier_as_program.test:
--------------------------------------------------------------------------------
1 | (* Test whether the keyword XXXX may be used as an identifier for:
2 | * Program identifier
3 | *
4 | * The XXXX names in the following code are merely a placeholder.
5 | * They will be replaced by several identifiers before actual testing
6 | * of the compiler.
7 | *)
8 |
9 | (* The identifiers that will replace the XXXX
10 | * must be placed on a line starting with #
11 | * All identifiers preceded by # are ignored!
12 | * The identifier list must be placed inside an IEC 61131-3 comment.
13 | *)
14 | (* This file is specific for identifiers identical to IL operators.
15 | * See the note following the identifier list
16 | *)
17 | (*
18 | #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
19 | #SFC_qualifiers D DS L N P #R #S SD SL
20 | NOTE: R and S are identical to IL operators!!
21 | #Task_initialisers PRIORITY SINGLE INTERVAL
22 | *)
23 |
24 | (* NOTE: The identifier as a variable test has some special cases.
25 | * Namely, when using IL operators as variable names.
26 | * Even though the syntax of the IL language would not result
27 | * in ambiguities in the above case, our parser does not currently
28 | * allow the use of variables (with names identical to IL
29 | * operators) within IL code.
30 | *
31 | * The following test code must therefore consider two possibilities:
32 | * - if the identifier under test is an IL operator
33 | * - if the identifier under test is not an IL operator
34 | *)
35 |
36 |
37 |
38 |
39 |
40 |
41 | PROGRAM XXXX
42 | VAR_INPUT
43 | a_1 : BOOL;
44 | END_VAR
45 | LD a_1
46 | END_PROGRAM
47 |
48 |
49 |
50 |
51 |
52 | CONFIGURATION config1
53 | TASK fast(PRIORITY := 4);
54 | PROGRAM P1 WITH fast:
55 | XXXX(a_1 := TRUE);
56 | END_CONFIGURATION
57 |
58 |
59 |
60 |
61 | (* Checking whether the use of XXXX will confuse any other
62 | * normal and correct IL or ST code.
63 | *)
64 | {#include "basic_code.test" }
65 |
66 |
67 |
--------------------------------------------------------------------------------
/tests/syntax/identifier/runtests:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # assume no error to start with...
4 | error=0
5 |
6 | for ff in `ls *.test`
7 | do
8 | for id in `cat $ff | grep "^#" | sed "s/#[^ ]*//g"`
9 | do
10 | sed s/XXXX/$id/g $ff > $ff"_"$id.iec
11 | if `../../../iec2iec $ff"_"$id.iec -I ../../../lib > $ff"_"$id.out 2>$ff"_"$id.err`
12 | #if `../../../iec2c $ff"_"$id.iec -I ../../../lib > $ff"_"$id.out 2>$ff"_"$id.err`
13 | # TODO before deciding test is success [OK]
14 | # - test whether xxx.out has size <> 0
15 | # - test whether xxx.err has size == 0
16 | # - (?) test whether xxx.out2 is identical to xxx.out
17 | # - (?) test whether xxx.err2 has size == 0
18 | # - perhaps produce a [WARN] instead of [ERROR] in cases of (?)
19 | then echo "[ O K ] " $ff "->" $id
20 | else echo "[ERROR] " $ff "->" $id; error=1
21 | fi
22 | # ../../../iec2iec $ff"_"$id.out -I ../../../lib > $ff"_"$id.out2 2>$ff"_"$id.err2
23 | done
24 | done
25 |
26 | echo
27 | if `test $error = 1`
28 | then echo "FAILURE -> At least one of the tests failed!"
29 | else echo "SUCCESS -> All tests passed!"
30 | fi
31 |
--------------------------------------------------------------------------------
/tests/syntax/sfc/sfc.txt:
--------------------------------------------------------------------------------
1 | PROGRAM MAIN_TEST
2 | VAR
3 | QX1 AT %QX1 : BOOL := 1;
4 | QX2 AT %QX2 : BOOL := 0;
5 | QX3 AT %QX3 : BOOL;
6 | IX1 AT %IX1 : BOOL;
7 | IX2 AT %IX2 : BOOL;
8 | IX3 AT %IX3 : BOOL;
9 | END_VAR
10 |
11 | INITIAL_STEP GO:
12 | END_STEP
13 |
14 | TRANSITION FROM GO TO STEP1
15 | := IX1 = FALSE;
16 | END_TRANSITION
17 |
18 | STEP STEP1:
19 | ONSTEP1(N);
20 | END_STEP
21 |
22 | ACTION ONSTEP1:
23 | QX1 := TRUE;
24 | QX2 := TRUE;
25 | END_ACTION
26 |
27 | TRANSITION FROM STEP1 TO STEP2
28 | := IX2 = TRUE;
29 | END_TRANSITION
30 |
31 | STEP STEP2:
32 | INLINE1(P);
33 | END_STEP
34 |
35 | ACTION INLINE1:
36 | QX1 := QX2 XOR QX1; QX2 := NOT QX2;
37 | END_ACTION
38 |
39 | TRANSITION FROM STEP2 TO A1
40 | := QX1 = FALSE AND QX2 = FALSE;
41 | END_TRANSITION
42 |
43 | STEP A1:
44 | INLINE2(N);
45 | END_STEP
46 |
47 | ACTION INLINE2:
48 | IX1 := TRUE;
49 | END_ACTION
50 |
51 | TRANSITION FROM A1 TO STEP2
52 | := IX1 = TRUE;
53 | END_TRANSITION
54 |
55 | TRANSITION FROM STEP2 TO (D1, D2, D3)
56 | := QX1 = TRUE AND QX2 = TRUE;
57 | END_TRANSITION
58 |
59 | STEP D1:
60 | INLINE5(N);
61 | END_STEP
62 |
63 | ACTION INLINE5:
64 | QX1 := FALSE;
65 | END_ACTION
66 |
67 | TRANSITION FROM D1 TO E1
68 | := NOT ( QX1 OR QX2 OR QX3 );
69 | END_TRANSITION
70 |
71 | STEP E1:
72 | INLINE8(N);
73 | END_STEP
74 |
75 | ACTION INLINE8:
76 | QX1 := TRUE;
77 | END_ACTION
78 |
79 | TRANSITION FROM (E1, E2, E3) TO GO
80 | := QX1 AND QX2 AND QX3;
81 | END_TRANSITION
82 |
83 | STEP D2:
84 | INLINE6(N);
85 | END_STEP
86 |
87 | ACTION INLINE6:
88 | QX2 := FALSE;
89 | END_ACTION
90 |
91 | TRANSITION FROM D2 TO E2
92 | := NOT ( QX1 OR QX2 OR QX3 );
93 | END_TRANSITION
94 |
95 | STEP E2:
96 | INLINE9(N);
97 | END_STEP
98 |
99 | ACTION INLINE9:
100 | QX2 := TRUE;
101 | END_ACTION
102 |
103 | STEP D3:
104 | INLINE7(N);
105 | END_STEP
106 |
107 | ACTION INLINE7:
108 | QX2 := FALSE;
109 | END_ACTION
110 |
111 | TRANSITION FROM D3 TO E3
112 | := NOT ( QX1 OR QX2 OR QX3 );
113 | END_TRANSITION
114 |
115 | STEP E3:
116 | INLINE10(N);
117 | END_STEP
118 |
119 | ACTION INLINE10:
120 | QX3 := TRUE;
121 | END_ACTION
122 |
123 | TRANSITION FROM STEP2 TO A3
124 | := QX1 = TRUE AND QX2 = FALSE;
125 | END_TRANSITION
126 |
127 | STEP A3:
128 | INLINE4(N);
129 | END_STEP
130 |
131 | ACTION INLINE4:
132 | IX1 := TRUE;
133 | END_ACTION
134 |
135 | TRANSITION FROM A3 TO STEP2
136 | := IX1 = TRUE;
137 | END_TRANSITION
138 |
139 | TRANSITION FROM STEP2 TO A2
140 | := QX1 = FALSE AND QX2 = TRUE;
141 | END_TRANSITION
142 |
143 | STEP A2:
144 | INLINE3(N);
145 | END_STEP
146 |
147 | ACTION INLINE3:
148 | IX1 := FALSE;
149 | END_ACTION
150 |
151 | TRANSITION FROM A2 TO STEP2
152 | := IX1 = FALSE;
153 | END_TRANSITION
154 |
155 | END_PROGRAM
156 |
157 |
158 | CONFIGURATION STD_CONF
159 |
160 | RESOURCE STD_RESSOURCE ON BEREMIZ
161 | TASK STD_TASK(INTERVAL := t#100ms,PRIORITY := 0);
162 | PROGRAM MAIN_INSTANCE : MAIN_TEST;
163 | END_RESOURCE
164 | END_CONFIGURATION
165 |
--------------------------------------------------------------------------------
/util/dsymtable.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt)
5 | * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | *
20 | *
21 | * This code is made available on the understanding that it will not be
22 | * used in safety-critical situations without a full and competent review.
23 | */
24 |
25 | /*
26 | * A generic symbol table that allows duplicate values.
27 | *
28 | * This is used to create a symbol table of previously defined
29 | * functions. Duplicate are allowed since the standard permits function\
30 | * overloading in the standard library.
31 | */
32 |
33 |
34 | #include
35 | #include "symtable.hh"
36 | #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
37 |
38 |
39 |
40 | /* clear all entries... */
41 | template
42 | void dsymtable_c::reset(void) {
43 | _base.clear();
44 | }
45 |
46 |
47 | template
48 | void dsymtable_c::insert(const char *identifier_str, value_t new_value) {
49 | // std::cout << "store_identifier(" << identifier_str << "): \n";
50 | std::pair new_element(identifier_str, new_value);
51 | /* iterator res = */ _base.insert(new_element);
52 | }
53 |
54 |
55 | template
56 | void dsymtable_c::insert(const symbol_c *symbol, value_t new_value) {
57 | const token_c *name = dynamic_cast(symbol);
58 | if (name == NULL)
59 | ERROR;
60 | insert(name->value, new_value);
61 | }
62 |
63 |
64 | #if 0
65 | template
66 | void dsymtable_c::insert_noduplicate(const char *identifier_str, value_t new_value) {
67 | if (find_value(identifier_str) != null_value)
68 | /* already present in the set! */
69 | ERROR;
70 |
71 | // std::cout << "store_identifier(" << identifier_str << "): \n";
72 | std::pair new_element(identifier_str, new_value);
73 | /* iterator res = */ _base.insert(new_element);
74 | }
75 |
76 |
77 | template
78 | void dsymtable_c::insert_noduplicate(const symbol_c *symbol, value_t new_value) {
79 | const token_c *name = dynamic_cast(symbol);
80 | if (name == NULL)
81 | ERROR;
82 | insert_noduplicate(name->value, new_value);
83 | }
84 | #endif
85 |
86 |
87 |
88 |
89 | template
90 | const char * dsymtable_c::symbol_to_string(const symbol_c *symbol) {
91 | const token_c *name = dynamic_cast(symbol);
92 | if (name == NULL)
93 | ERROR;
94 | return name->value;
95 | }
96 |
97 |
98 | /* debuging function... */
99 | template
100 | void dsymtable_c::print(void) {
101 | for(iterator i = _base.begin();
102 | i != _base.end();
103 | i++)
104 | std::cout << i->second << ":" << i->first << "\n";
105 | std::cout << "=====================\n";
106 | }
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/util/strdup.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * matiec - a compiler for the programming languages defined in IEC 61131-3
3 | *
4 | * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt)
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | *
19 | *
20 | * This code is made available on the understanding that it will not be
21 | * used in safety-critical situations without a full and competent review.
22 | */
23 |
24 |
25 | /*******************************************/
26 | /* String Duplication Utility Functions... */
27 | /*******************************************/
28 |
29 |
30 |
31 | #ifndef STRDUP__H
32 | #define STRDUP__H
33 |
34 | #include /* required for malloc() */
35 | #include /* required for strcat() & strlen() */
36 |
37 | /*
38 | * Join two strings together. Allocate space with malloc(3).
39 | */
40 | static char *strdup2(const char *a, const char *b) {
41 | char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
42 |
43 | if (res == NULL) return NULL;
44 | return strcat(strcpy(res, a), b);
45 | }
46 |
47 | /*
48 | * Join three strings together. Allocate space with malloc(3).
49 | */
50 | static char *strdup3(const char *a, const char *b, const char *c) {
51 | char *res = (char *)malloc(strlen(a) + strlen(b) + strlen(c) + 1);
52 |
53 | if (res == NULL) return NULL;
54 | return strcat(strcat(strcpy(res, a), b), c);
55 | }
56 |
57 |
58 | #endif /* STRDUP__H */
59 |
--------------------------------------------------------------------------------