generate_IEC_std.py
changeset 58 39cd981ff242
parent 43 4a7e80513edd
child 59 af079a11837b
equal deleted inserted replaced
57:9bf197698af0 58:39cd981ff242
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
       
     5 #based on the plcopen standard. 
       
     6 #
       
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 #
       
     9 #See COPYING file for copyrights details.
       
    10 #
       
    11 #This library is free software; you can redistribute it and/or
       
    12 #modify it under the terms of the GNU General Public
       
    13 #License as published by the Free Software Foundation; either
       
    14 #version 2.1 of the License, or (at your option) any later version.
       
    15 #
       
    16 #This library is distributed in the hope that it will be useful,
       
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    19 #General Public License for more details.
       
    20 #
       
    21 #You should have received a copy of the GNU General Public
       
    22 #License along with this library; if not, write to the Free Software
       
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    24 
     1 """
    25 """
     2 
    26 
     3  THIS CODE GENARATES C++ CODE FOR IEC2CC COMPILER
    27  THIS CODE GENARATES C++ CODE FOR IEC2CC COMPILER
     4  GENERATED CODE IS :
    28  GENERATED CODE IS :
     5  
    29  
    17 # Get definitions
    41 # Get definitions
    18 from plcopen.structures import *
    42 from plcopen.structures import *
    19 
    43 
    20 #import pprint
    44 #import pprint
    21 #pp = pprint.PrettyPrinter(indent=4)
    45 #pp = pprint.PrettyPrinter(indent=4)
       
    46 
       
    47 matiec_header = """/*
       
    48  * (c) 2003 Mario de Sousa
       
    49  *
       
    50  * Offered to the public under the terms of the GNU General Public License
       
    51  * as published by the Free Software Foundation; either version 2 of the
       
    52  * License, or (at your option) any later version.
       
    53  *
       
    54  * This program is distributed in the hope that it will be useful, but
       
    55  * WITHOUT ANY WARRANTY; without even the implied warranty of
       
    56  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
       
    57  * Public License for more details.
       
    58  *
       
    59  * This code is made available on the understanding that it will not be
       
    60  * used in safety-critical situations without a full and competent review.
       
    61  */
       
    62 
       
    63 /*
       
    64  * An IEC 61131-3 IL and ST compiler.
       
    65  *
       
    66  * Based on the
       
    67  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    68  *
       
    69  */
       
    70  
       
    71  """
    22 
    72 
    23 def ANY_to_compiler_test_type_GEN(typename, paramname):
    73 def ANY_to_compiler_test_type_GEN(typename, paramname):
    24     """
    74     """
    25     Convert ANY_XXX IEC type declaration into IEC2CC's generated type test.
    75     Convert ANY_XXX IEC type declaration into IEC2CC's generated type test.
    26     This tests are defined in search_expression_type.cc 
    76     This tests are defined in search_expression_type.cc 
   199 ###################################################################
   249 ###################################################################
   200 
   250 
   201 """
   251 """
   202 Generate the long enumeration of std function types
   252 Generate the long enumeration of std function types
   203 """
   253 """
   204 function_type_decl =  """
   254 function_type_decl =  matiec_header + """
   205 /****
   255 /****
   206  * IEC 61131-3 standard function lib
   256  * IEC 61131-3 standard function lib
   207  * generated code, do not edit by hand
   257  * generated code, do not edit by hand
   208  */
   258  */
   209 typedef enum {
   259 typedef enum {
   216 """
   266 """
   217 ###################################################################
   267 ###################################################################
   218 """
   268 """
   219 Generate the funct that return enumerated according function name
   269 Generate the funct that return enumerated according function name
   220 """
   270 """
   221 get_function_type_decl = """
   271 get_function_type_decl = matiec_header + """
   222 /****
   272 /****
   223  * IEC 61131-3 standard function lib
   273  * IEC 61131-3 standard function lib
   224  * generated code, do not edit by hand
   274  * generated code, do not edit by hand
   225  */
   275  */
   226 function_type_t get_function_type(identifier_c *function_name) {
   276 function_type_t get_function_type(identifier_c *function_name) {
   239 ###################################################################
   289 ###################################################################
   240 """
   290 """
   241 Generate the part of generate_cc_st_c::visit(function_invocation)
   291 Generate the part of generate_cc_st_c::visit(function_invocation)
   242 that is responsible to generate C code for std lib calls.
   292 that is responsible to generate C code for std lib calls.
   243 """
   293 """
   244 st_code_gen = """
   294 st_code_gen = matiec_header + """
   245 /****
   295 /****
   246  * IEC 61131-3 standard function lib
   296  * IEC 61131-3 standard function lib
   247  * generated code, do not edit by hand
   297  * generated code, do not edit by hand
   248  */
   298  */
   249 switch(current_function_type){
   299 switch(current_function_type){
   276 ###################################################################
   326 ###################################################################
   277 """
   327 """
   278 Generate the part of generate_cc_il_c::visit(il_function_call)
   328 Generate the part of generate_cc_il_c::visit(il_function_call)
   279 that is responsible to generate C code for std lib calls.
   329 that is responsible to generate C code for std lib calls.
   280 """
   330 """
   281 il_code_gen = """
   331 il_code_gen = matiec_header + """
   282 /****
   332 /****
   283  * IEC 61131-3 standard function lib
   333  * IEC 61131-3 standard function lib
   284  * generated code, do not edit by hand
   334  * generated code, do not edit by hand
   285  */
   335  */
   286 switch(current_function_type){
   336 switch(current_function_type){
   313 ###################################################################
   363 ###################################################################
   314 """
   364 """
   315 Generate the part of search_expression_type_c::visit(function_invocation)
   365 Generate the part of search_expression_type_c::visit(function_invocation)
   316 that is responsible of returning type symbol for function invocation.
   366 that is responsible of returning type symbol for function invocation.
   317 """
   367 """
   318 search_type_code =  """
   368 search_type_code =  matiec_header + """
   319 /****
   369 /****
   320  * IEC 61131-3 standard function lib
   370  * IEC 61131-3 standard function lib
   321  * generated code, do not edit by hand
   371  * generated code, do not edit by hand
   322  */
   372  */
   323 
   373 
   415 ###################################################################
   465 ###################################################################
   416 ###################################################################
   466 ###################################################################
   417 """
   467 """
   418 Generate the C implementation of the IEC standard function library.
   468 Generate the C implementation of the IEC standard function library.
   419 """
   469 """
   420 iec_std_lib_generated =  """
   470 iec_std_lib_generated = matiec_header + """
   421 /****
   471 /****
   422  * IEC 61131-3 standard function lib
   472  * IEC 61131-3 standard function lib
   423  * generated code, do not edit by hand
   473  * generated code, do not edit by hand
   424  */
   474  */
   425 
   475