# HG changeset patch # User etisserant # Date 1184347226 -7200 # Node ID 8998c8b24b60adad6c9d1996da9dc0350d6bc344 # Parent 873a5b60a7ea4785e9cd1d1a56f729bbf2408703 First working IEC std lib test, actually test from string and to_string functions. diff -r 873a5b60a7ea -r 8998c8b24b60 lib/iec_std_lib.h --- a/lib/iec_std_lib.h Thu Jul 12 11:24:32 2007 +0200 +++ b/lib/iec_std_lib.h Fri Jul 13 19:20:26 2007 +0200 @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -47,6 +48,7 @@ typedef struct timespec TOD; #define __TIME_CMP(t1, t2) (t2.tv_sec == t1.tv_sec ? t2.tv_nsec - t1.tv_nsec : t1.tv_sec - t2.tv_sec) +extern TIME __CURRENT_TIME; #define STR_MAX_LEN 40 typedef int8_t __strlen_t; @@ -57,7 +59,6 @@ #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) - /* TODO typedef struct { __strlen_t len; @@ -65,6 +66,28 @@ } WSTRING; */ +#define __INIT_REAL 0 +#define __INIT_LREAL 0 +#define __INIT_SINT 0 +#define __INIT_INT 0 +#define __INIT_DINT 0 +#define __INIT_LINT 0 +#define __INIT_USINT 0 +#define __INIT_UINT 0 +#define __INIT_UDINT 0 +#define __INIT_ULINT 0 +#define __INIT_TIME (TIME){0,0} +#define __INIT_BOOL 0 +#define __INIT_BYTE 0 +#define __INIT_WORD 0 +#define __INIT_DWORD 0 +#define __INIT_LWORD 0 +#define __INIT_STRING (STRING){0,""} +//#define __INIT_WSTRING +#define __INIT_DATE (DATE){0,0} +#define __INIT_TOD (TOD){0,0} +#define __INIT_DT (DT){0,0} + typedef union __IL_DEFVAR_T { BOOL BOOLvar; @@ -100,7 +123,7 @@ /*****************/ /* function that generates an IEC runtime error */ -void IEC_error(void) { +static inline void IEC_error(void) { /* TODO... */ fprintf(stderr, "IEC 61131-3 runtime error.\n"); /*exit(1);*/ @@ -193,25 +216,25 @@ /***************/ /* Time ops */ /***************/ -inline TIME __date_and_time_to_time_of_day(TIME IN){ +static inline TIME __date_and_time_to_time_of_day(TIME IN){ return (TIME){IN.tv_sec % 86400, IN.tv_nsec}; } -inline TIME __date_and_time_to_date(TIME IN){ +static inline TIME __date_and_time_to_date(TIME IN){ return (TIME){IN.tv_sec - (IN.tv_sec % (24*60*60)), 0}; } -inline TIME __time_add(TIME IN1, TIME IN2){ +static inline TIME __time_add(TIME IN1, TIME IN2){ TIME res ={IN1.tv_sec + IN2.tv_sec, IN1.tv_nsec + IN2.tv_nsec }; __normalize_timespec(&res); return res; } -inline TIME __time_sub(TIME IN1, TIME IN2){ +static inline TIME __time_sub(TIME IN1, TIME IN2){ TIME res ={IN1.tv_sec - IN2.tv_sec, IN1.tv_nsec - IN2.tv_nsec }; __normalize_timespec(&res); return res; } -inline TIME __time_mul(TIME IN1, LREAL IN2){ +static inline TIME __time_mul(TIME IN1, LREAL IN2){ LREAL s_f = IN1.tv_sec * IN2; time_t s = s_f; div_t ns = div((LREAL)IN1.tv_nsec * IN2, 1000000000); @@ -220,7 +243,7 @@ __normalize_timespec(&res); return res; } -inline TIME __time_div(TIME IN1, LREAL IN2){ +static inline TIME __time_div(TIME IN1, LREAL IN2){ LREAL s_f = IN1.tv_sec / IN2; time_t s = s_f; TIME res = {s, @@ -232,36 +255,38 @@ /***************/ /* String ops */ /***************/ -inline UINT __len(STRING IN){ +static inline UINT __len(STRING IN){ return IN.len; } -inline STRING __left(STRING IN, SINT L){ - STRING res = {0,}; - memcpy(&res.body, &IN.body, L < res.len ? L : res.len); - return res; -} -inline STRING __right(STRING IN, SINT L){ - STRING res = {0,}; +static inline STRING __left(STRING IN, SINT L){ + STRING res = __INIT_STRING; L = L < IN.len ? L : IN.len; - memcpy(&res, &IN.body[IN.len - L], L); + memcpy(&res.body, &IN.body, L); res.len = L; return res; } -inline STRING __mid(STRING IN, SINT L, SINT P){ - STRING res = {0,}; +static inline STRING __right(STRING IN, SINT L){ + STRING res = __INIT_STRING; + L = L < IN.len ? L : IN.len; + memcpy(&res.body, &IN.body[IN.len - L], L); + res.len = L; + return res; +} +static inline STRING __mid(STRING IN, SINT L, SINT P){ + STRING res = __INIT_STRING; if(P <= IN.len){ P -= 1; /* now can be used as [index]*/ L = L + P <= IN.len ? L : IN.len - P; - memcpy(&res, &IN.body[P] , L); + memcpy(&res.body, &IN.body[P] , L); res.len = L; } return res; } -inline STRING __concat(SINT param_count, ...){ +static inline STRING __concat(SINT param_count, ...){ va_list ap; UINT i; __strlen_t charcount = 0; - STRING res = {0,}; + STRING res = __INIT_STRING; va_start (ap, param_count); /* Initialize the argument list. */ @@ -279,11 +304,11 @@ va_end (ap); /* Clean up. */ return res; } -inline STRING __insert(STRING IN1, STRING IN2, SINT P){ - STRING res = {0,}; +static inline STRING __insert(STRING IN1, STRING IN2, SINT P){ + STRING res = __INIT_STRING; __strlen_t to_copy; - to_copy = P > IN1.len ? IN1.len : P; + to_copy = P > IN1.len ? IN1.len : P - 1; memcpy(&res.body, &IN1.body , to_copy); P = res.len = to_copy; @@ -297,44 +322,54 @@ return res; } -inline STRING __delete(STRING IN, SINT L_value, SINT P){ - STRING res = {0,}; +static inline STRING __delete(STRING IN, SINT L, SINT P){ + STRING res = __INIT_STRING; __strlen_t to_copy; - to_copy = P > IN.len ? IN.len : P; + to_copy = P > IN.len ? IN.len : P-1; memcpy(&res.body, &IN.body , to_copy); P = res.len = to_copy; - to_copy = IN.len - P; - memcpy(&res.body[res.len], &IN.body[P] , to_copy); - res.len += to_copy; - - return res; -} -inline STRING __replace(STRING IN1, STRING IN2, SINT L, SINT P){ - STRING res = {0,}; + if( IN.len > P + L ){ + to_copy = IN.len - P - L; + memcpy(&res.body[res.len], &IN.body[P + L], to_copy); + res.len += to_copy; + } + + return res; +} +static inline STRING __replace(STRING IN1, STRING IN2, SINT L, SINT P){ + STRING res = __INIT_STRING; __strlen_t to_copy; - to_copy = P > IN1.len ? IN1.len : P; + to_copy = P > IN1.len ? IN1.len : P-1; memcpy(&res.body, &IN1.body , to_copy); P = res.len = to_copy; - to_copy = IN2.len + res.len > STR_MAX_LEN ? STR_MAX_LEN - res.len : IN2.len; + to_copy = IN2.len < L ? IN2.len : L; + + if( to_copy + res.len > STR_MAX_LEN ) + to_copy = STR_MAX_LEN - res.len; + memcpy(&res.body[res.len], &IN2.body , to_copy); res.len += to_copy; - to_copy = res.len < IN1.len ? IN1.len - res.len : 0; - memcpy(&res.body[res.len], &IN1.body[res.len] , to_copy); - res.len += to_copy; - - return res; -} - - - -inline UINT __pfind(STRING* IN1, STRING* IN2){ - UINT count1 = 0; - UINT count2 = 0; + P += L; + if( res.len < STR_MAX_LEN && P < IN1.len) + { + to_copy = IN1.len - P; + memcpy(&res.body[res.len], &IN1.body[P] , to_copy); + res.len += to_copy; + } + + return res; +} + + + +static inline UINT __pfind(STRING* IN1, STRING* IN2){ + UINT count1 = 0; /* offset of first matching char in IN1 */ + UINT count2 = 0; /* count of matching char */ while(count1 + count2 < IN1->len && count2 < IN2->len) { if(IN1->body[count1 + count2] != IN2->body[count2++]){ @@ -342,9 +377,9 @@ count2 = 0; } } - return count2 == IN2->len ? 0 : count1; -} -inline UINT __find(STRING IN1, STRING IN2){ + return count2 == IN2->len -1 ? 0 : count1 + 1; +} +static inline UINT __find(STRING IN1, STRING IN2){ return __pfind(&IN1, &IN2); } @@ -354,32 +389,32 @@ /***************/ /* TO_STRING */ /***************/ -inline STRING __bool_to_string(BOOL IN) +static inline STRING __bool_to_string(BOOL IN) { if(IN) return (STRING){4, "TRUE"}; return (STRING){5,"FALSE"}; } -inline STRING __bit_to_string(LWORD IN){ - STRING res = {0,}; +static inline STRING __bit_to_string(LWORD IN){ + STRING res = __INIT_STRING; res.len = snprintf(res.body, STR_MAX_LEN, "16#%llx", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __real_to_string(LREAL IN){ - STRING res = {0,}; +static inline STRING __real_to_string(LREAL IN){ + STRING res = __INIT_STRING; res.len = snprintf(res.body, STR_MAX_LEN, "%g", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __sint_to_string(LINT IN){ - STRING res = {0,}; +static inline STRING __sint_to_string(LINT IN){ + STRING res = __INIT_STRING; res.len = snprintf(res.body, STR_MAX_LEN, "%lld", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __uint_to_string(ULINT IN){ - STRING res = {0,}; +static inline STRING __uint_to_string(ULINT IN){ + STRING res = __INIT_STRING; res.len = snprintf(res.body, STR_MAX_LEN, "16#%llu", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; @@ -387,11 +422,11 @@ /***************/ /* FROM_STRING */ /***************/ -inline BOOL __string_to_bool(STRING IN){ +static inline BOOL __string_to_bool(STRING IN){ return IN.len == 5 ? !memcmp(&IN.body,"TRUE", IN.len) : 0; } -inline LINT __pstring_to_sint(STRING* IN){ +static inline LINT __pstring_to_sint(STRING* IN){ LINT res = 0; char tmp[STR_MAX_LEN]; char tmp2[STR_MAX_LEN]; @@ -444,22 +479,26 @@ res += ( c - '0') * fac; fac *= 10; shift += 1; - } + }else if( c >= '.' ){ /* reset value */ + res = 0; + fac = 1; + shift = 0; + } } } return res; } -inline LINT __string_to_sint(STRING IN){ +static inline LINT __string_to_sint(STRING IN){ return (LWORD)__pstring_to_sint(&IN); } -inline LWORD __string_to_bit(STRING IN){ +static inline LWORD __string_to_bit(STRING IN){ return (LWORD)__pstring_to_sint(&IN); } -inline ULINT __string_to_uint(STRING IN){ +static inline ULINT __string_to_uint(STRING IN){ return (ULINT)__pstring_to_sint(&IN); } -inline LREAL __string_to_real(STRING IN){ +static inline LREAL __string_to_real(STRING IN){ /* search the dot */ __strlen_t l = IN.len; while(--l > 0 && IN.body[l] != '.'); @@ -473,14 +512,14 @@ /***************/ /* TO_TIME */ /***************/ -inline TIME __int_to_time(LINT IN){ +static inline TIME __int_to_time(LINT IN){ return (TIME){IN, 0}; } -inline TIME __real_to_time(LREAL IN){ +static inline TIME __real_to_time(LREAL IN){ return (TIME){IN, (IN - (LINT)IN) * 1000000000}; } -inline TIME __string_to_time(STRING IN){ +static inline TIME __string_to_time(STRING IN){ /* TODO : * * Duration literals without underlines: T#14ms T#-14ms T#14.7s T#14.7m @@ -516,15 +555,15 @@ /***************/ /* FROM_TIME */ /***************/ -inline LREAL __time_to_real(TIME IN){ +static inline LREAL __time_to_real(TIME IN){ return (LREAL)IN.tv_sec + ((LREAL)IN.tv_nsec/1000000000); } -inline LINT __time_to_int(TIME IN){ +static inline LINT __time_to_int(TIME IN){ return IN.tv_sec; } -inline STRING __time_to_string(TIME IN){ +static inline STRING __time_to_string(TIME IN){ /*t#5d14h12m18s3.5ms*/ - STRING res = {0,}; + STRING res = __INIT_STRING; div_t days = div(IN.tv_sec ,86400); if(!days.rem && IN.tv_nsec == 0){ res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd", days.quot); @@ -548,9 +587,9 @@ if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __date_to_string(DATE IN){ +static inline STRING __date_to_string(DATE IN){ /* D#1984-06-25 */ - STRING res = {0,}; + STRING res = __INIT_STRING; struct tm broken_down_time; time_t seconds = IN.tv_sec; if (NULL == gmtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ @@ -561,9 +600,9 @@ if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __tod_to_string(TOD IN){ +static inline STRING __tod_to_string(TOD IN){ /* TOD#15:36:55.36 */ - STRING res = {0,}; + STRING res = __INIT_STRING; struct tm broken_down_time; time_t seconds = IN.tv_sec; if (NULL == gmtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ @@ -578,7 +617,7 @@ if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } -inline STRING __dt_to_string(DT IN){ +static inline STRING __dt_to_string(DT IN){ /* DT#1984-06-25-15:36:55.36 */ STRING res; struct tm broken_down_time; @@ -608,7 +647,7 @@ return res; } /* BCD */ -inline ULINT __bcd_to_uint(LWORD IN){ +static inline ULINT __bcd_to_uint(LWORD IN){ return IN & 0xf + ((IN >>= 4) & 0xf) * 10 + ((IN >>= 4) & 0xf) * 100 + @@ -626,7 +665,7 @@ ((IN >>= 4) & 0xf) * 100000000000000 + ((IN >>= 4) & 0xf) * 1000000000000000; } -inline LWORD __uint_to_bcd(ULINT IN){ +static inline LWORD __uint_to_bcd(ULINT IN){ return (IN - (IN /= 10))| (IN - (IN /= 10)) << 4 | (IN - (IN /= 10)) << 8 | @@ -649,7 +688,7 @@ /* Binary ops */ /**************/ #define __ror_(TYPENAME)\ -inline TYPENAME __ror_##TYPENAME( TYPENAME IN, USINT N){\ +static inline TYPENAME __ror_##TYPENAME( TYPENAME IN, USINT N){\ N %= 8*sizeof(TYPENAME);\ return (IN >> N) | (IN << 8*sizeof(TYPENAME)-N);\ } @@ -657,7 +696,7 @@ ANY_NBIT(__ror_) #define __rol_(TYPENAME)\ -inline TYPENAME __rol_##TYPENAME( TYPENAME IN, USINT N){\ +static inline TYPENAME __rol_##TYPENAME( TYPENAME IN, USINT N){\ N %= 8*sizeof(TYPENAME);\ return (IN << N) | (IN >> 8*sizeof(TYPENAME)-N);\ } @@ -672,7 +711,7 @@ /**************/ #define __limit_(TYPENAME)\ -inline TYPENAME __limit_##TYPENAME( TYPENAME MN, TYPENAME IN, TYPENAME MX){\ +static inline TYPENAME __limit_##TYPENAME( TYPENAME MN, TYPENAME IN, TYPENAME MX){\ return IN > MN ? IN < MX ? IN : MX : MN;\ } @@ -681,7 +720,7 @@ ANY_NUM(__limit_) #define __limit_time(TYPENAME)\ -inline TIME __limit_##TYPENAME( TYPENAME MN, TYPENAME IN, TYPENAME MX){\ +static inline TIME __limit_##TYPENAME( TYPENAME MN, TYPENAME IN, TYPENAME MX){\ return __TIME_CMP(IN, MN) > 0 ? /* IN>MN ?*/\ __TIME_CMP(IN, MX) < 0 ? /* IN 0 ? __STR_CMP(IN, MX) < 0 ? IN : MX : MN; } @@ -723,7 +762,7 @@ #define VA_ARGS_DT DT #define __extrem_(fname,TYPENAME, COND) \ -inline TYPENAME fname##TYPENAME( UINT param_count, TYPENAME op1, ...){\ +static inline TYPENAME fname##TYPENAME( UINT param_count, TYPENAME op1, ...){\ va_list ap;\ UINT i;\ \ @@ -768,15 +807,16 @@ /* MUX */ /**************/ #define __mux_(TYPENAME) \ -inline TYPENAME __mux_##TYPENAME( UINT param_count, UINT K, TYPENAME op1, ...){\ +static inline TYPENAME __mux_##TYPENAME( UINT param_count, UINT K, ...){\ va_list ap;\ UINT i;\ + TYPENAME tmp = __INIT_##TYPENAME;\ \ - va_start (ap, op1); /* Initialize the argument list. */\ + va_start (ap, K); /* Initialize the argument list. */\ \ for (i = 0; i < param_count; i++){\ if(K == i){\ - TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\ + tmp = va_arg (ap, VA_ARGS_##TYPENAME);\ va_end (ap); /* Clean up. */\ return tmp;\ }else{\ @@ -785,7 +825,7 @@ }\ \ va_end (ap); /* Clean up. */\ - return op1;\ + return tmp;\ } ANY(__mux_) @@ -795,7 +835,7 @@ /**************/ #define __compare_(fname,TYPENAME, COND) \ -inline BOOL fname##TYPENAME( UINT param_count, TYPENAME op1, ...){\ +static inline BOOL fname##TYPENAME( UINT param_count, TYPENAME op1, ...){\ va_list ap;\ UINT i;\ \ diff -r 873a5b60a7ea -r 8998c8b24b60 lib/test_iec_std_lib.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/test_iec_std_lib.c Fri Jul 13 19:20:26 2007 +0200 @@ -0,0 +1,7 @@ + +#include "iec_std_lib.h" + +int main(int argc,char **argv) +{ + return 0; +} diff -r 873a5b60a7ea -r 8998c8b24b60 stage1_2/iec.y --- a/stage1_2/iec.y Thu Jul 12 11:24:32 2007 +0200 +++ b/stage1_2/iec.y Fri Jul 13 19:20:26 2007 +0200 @@ -70,7 +70,7 @@ * Printing of debug info must then be activated by setting * the variable yydebug to 1. */ -#define YYDEBUG 1 +#define YYDEBUG 0 /* file with declaration of absyntax classes... */ diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc.cc --- a/stage4/generate_cc/generate_cc.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc.cc Fri Jul 13 19:20:26 2007 +0200 @@ -1146,19 +1146,19 @@ current_resource_name->accept(*this); s4o.print("\n"); - /* (A.2) POUs inclusion */ - s4o.print("#include \"POUS.c\"\n\n"); - - /* (A.3) Global variables... */ + /* (A.2) Global variables... */ if (current_global_vars != NULL) { vardecl = new generate_cc_vardecl_c(&s4o, - generate_cc_vardecl_c::local_vf, + generate_cc_vardecl_c::localstatic_vf, generate_cc_vardecl_c::global_vt); vardecl->print(current_global_vars); delete vardecl; } s4o.print("\n"); + /* (A.3) POUs inclusion */ + s4o.print("#include \"POUS.c\"\n\n"); + /* (A.4) Resource programs declaration... */ wanted_declaretype = declare_dt; symbol->program_configuration_list->accept(*this); @@ -1382,6 +1382,7 @@ protected: stage4out_c &s4o; stage4out_c pous_s4o; + stage4out_c located_variables_s4o; generate_cc_pous_c generate_cc_pous; symbol_c *current_configuration; @@ -1394,6 +1395,7 @@ generate_cc_c(stage4out_c *s4o_ptr): s4o(*s4o_ptr), pous_s4o("POUS", "c"), + located_variables_s4o("LOCATED_VARIABLES","h"), generate_cc_pous(&pous_s4o) { current_configuration = NULL; } @@ -1404,7 +1406,7 @@ /* B 0 - Programming Model */ /***************************/ void *visit(library_c *symbol) { - generate_location_list_c generate_location_list(&s4o); + generate_location_list_c generate_location_list(&located_variables_s4o); symbol->accept(generate_location_list); for(int i = 0; i < symbol->n; i++) { @@ -1468,16 +1470,18 @@ calculate_common_ticktime_c calculate_common_ticktime; symbol->accept(calculate_common_ticktime); common_ticktime = calculate_common_ticktime.get_ticktime(); - s4o.print("common_ticktime : "); - s4o.print_integer((int)(common_ticktime / 1000000)); - s4o.print("ms\n"); symbol->configuration_name->accept(*this); - stage4out_c config_s4o(current_name, "c"); - generate_cc_config_c generate_cc_config(&config_s4o); - symbol->accept(generate_cc_config); + stage4out_c config_s4o(current_name, "c"); + generate_cc_config_c generate_cc_config(&config_s4o); + symbol->accept(generate_cc_config); + + config_s4o.print("int common_ticktime__ = "); + config_s4o.print_integer((int)(common_ticktime / 1000000)); + config_s4o.print("; /*ms*/\n"); + symbol->resource_declarations->accept(*this); - + current_configuration = NULL; return NULL; diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc_base.cc --- a/stage4/generate_cc/generate_cc_base.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc_base.cc Fri Jul 13 19:20:26 2007 +0200 @@ -194,13 +194,12 @@ } void *print_compare_function(const char *function, - const char *compare_sign, + symbol_c *compare_type, symbol_c *l_exp, symbol_c *r_exp) { s4o.print(function); - s4o.print("("); - s4o.print(compare_sign); - s4o.print(", "); + compare_type->accept(*this); + s4o.print("(2, "); l_exp->accept(*this); s4o.print(", "); r_exp->accept(*this); diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc_il.cc --- a/stage4/generate_cc/generate_cc_il.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc_il.cc Fri Jul 13 19:20:26 2007 +0200 @@ -402,23 +402,15 @@ this->default_variable_name.accept(*this); this->default_variable_name.current_type = backup; - if (search_expression_type->is_time_type(this->default_variable_name.current_type) && - search_expression_type->is_time_type(this->current_operand_type)) { - s4o.print(" = __compare_timespec("); - s4o.print(operation); - s4o.print(", "); - this->default_variable_name.accept(*this); - s4o.print(", "); - o->accept(*this); - s4o.print(")"); - } - else { - s4o.print(" = ("); - this->default_variable_name.accept(*this); - s4o.print(operation); - o->accept(*this); - s4o.print(")"); - } + s4o.print(" = "); + s4o.print(operation); + this->default_variable_name.current_type->accept(*this); + s4o.print("(2, "); + this->default_variable_name.accept(*this); + s4o.print(", "); + o->accept(*this); + s4o.print(")"); + /* the data type resulting from this operation... */ this->default_variable_name.current_type = &(this->bool_type); return NULL; @@ -1215,7 +1207,7 @@ void *visit(ADD_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_time_type(this->current_operand_type)) { - XXX_function("__add_timespec", &(this->default_variable_name), this->current_operand); + XXX_function("__time_add", &(this->default_variable_name), this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; return NULL; @@ -1234,7 +1226,7 @@ void *visit(SUB_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_time_type(this->current_operand_type)) { - XXX_function("__sub_timespec", &(this->default_variable_name), this->current_operand); + XXX_function("__time_sub", &(this->default_variable_name), this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; return NULL; @@ -1253,7 +1245,7 @@ void *visit(MUL_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_integer_type(this->current_operand_type)) { - XXX_function("__mul_timespec", &(this->default_variable_name), this->current_operand); + XXX_function("__time_mul", &(this->default_variable_name), this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; return NULL; @@ -1292,27 +1284,27 @@ } void *visit(GT_operator_c *symbol) { - return CMP_operator(this->current_operand, " > "); + return CMP_operator(this->current_operand, "__gt_"); } void *visit(GE_operator_c *symbol) { - return CMP_operator(this->current_operand, " >= "); + return CMP_operator(this->current_operand, "__ge_"); } void *visit(EQ_operator_c *symbol) { - return CMP_operator(this->current_operand, " == "); + return CMP_operator(this->current_operand, "__eq_"); } void *visit(LT_operator_c *symbol) { - return CMP_operator(this->current_operand, " < "); + return CMP_operator(this->current_operand, "__lt_"); } void *visit(LE_operator_c *symbol) { - return CMP_operator(this->current_operand, " <= "); + return CMP_operator(this->current_operand, "__le_"); } void *visit(NE_operator_c *symbol) { - return CMP_operator(this->current_operand, " != "); + return CMP_operator(this->current_operand, "__ne_"); } diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc_sfc.cc --- a/stage4/generate_cc/generate_cc_sfc.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc_sfc.cc Fri Jul 13 19:20:26 2007 +0200 @@ -783,7 +783,7 @@ s4o.indent_right(); s4o.print(s4o.indent_spaces); print_variable_prefix(); - s4o.print("step_list[i].elapsed_time = __add_timespec("); + s4o.print("step_list[i].elapsed_time = __time_add("); print_variable_prefix(); s4o.print("step_list[i].elapsed_time, PERIOD);\n"); s4o.indent_left(); @@ -808,16 +808,16 @@ s4o.print("action_list[i].reset = 0;\n"); s4o.print(s4o.indent_spaces + "if ("); print_variable_prefix(); - s4o.print("__compare_timespec(>, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); - s4o.indent_right(); - s4o.print(s4o.indent_spaces); - print_variable_prefix(); - s4o.print("action_list[i].set_remaining_time = __sub_timespec("); + s4o.print("__gt_TIME(action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("action_list[i].set_remaining_time = __time_sub("); print_variable_prefix(); s4o.print("action_list[i].set_remaining_time, PERIOD);\n"); s4o.print(s4o.indent_spaces + "if ("); print_variable_prefix(); - s4o.print("__compare_timespec(<=, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); + s4o.print("__le_TIME(action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); s4o.indent_right(); s4o.print(s4o.indent_spaces); print_variable_prefix(); @@ -831,16 +831,16 @@ s4o.print(s4o.indent_spaces + "}\n"); s4o.print(s4o.indent_spaces + "if ("); print_variable_prefix(); - s4o.print("__compare_timespec(>, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); - s4o.indent_right(); - s4o.print(s4o.indent_spaces); - print_variable_prefix(); - s4o.print("action_list[i].reset_remaining_time = __sub_timespec("); + s4o.print("__gt_TIME(action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("action_list[i].reset_remaining_time = __time_sub("); print_variable_prefix(); s4o.print("action_list[i].reset_remaining_time, PERIOD);\n"); s4o.print(s4o.indent_spaces + "if ("); print_variable_prefix(); - s4o.print("__compare_timespec(<=, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); + s4o.print("__le_TIME(action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); s4o.indent_right(); s4o.print(s4o.indent_spaces); print_variable_prefix(); diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc_st.cc --- a/stage4/generate_cc/generate_cc_st.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc_st.cc Fri Jul 13 19:20:26 2007 +0200 @@ -202,7 +202,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", "==", symbol->l_exp, symbol->r_exp); + return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); } @@ -212,7 +212,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", "!=", symbol->l_exp, symbol->r_exp); + return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); } @@ -222,7 +222,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", "<", symbol->l_exp, symbol->r_exp); + return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); } @@ -232,7 +232,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", ">", symbol->l_exp, symbol->r_exp); + return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); } @@ -242,7 +242,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", "<=", symbol->l_exp, symbol->r_exp); + return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); } @@ -252,7 +252,7 @@ if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_time_type(left_type)) - return print_compare_function("__compare_timespec", ">=", symbol->l_exp, symbol->r_exp); + return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp); return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); } @@ -262,7 +262,7 @@ if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) - return print_binary_function("__add_timespec", symbol->l_exp, symbol->r_exp); + return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp); if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) @@ -280,7 +280,7 @@ (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) - return print_binary_function("__sub_timespec", symbol->l_exp, symbol->r_exp); + return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp); if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) @@ -294,7 +294,7 @@ symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) - return print_binary_function("__mul_timespec", symbol->l_exp, symbol->r_exp); + return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp); if (!search_expression_type->is_same_type(left_type, right_type)) ERROR; if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) @@ -386,7 +386,7 @@ case function_add: if (search_expression_type->is_time_type(function_return_type)) { if (current_param == 0) { - s4o.print("__add_timespec("); + s4o.print("__time_add("); param_value->accept(*this); } else if (current_param == 1) { @@ -409,7 +409,7 @@ case function_sub: if (search_expression_type->is_time_type(function_return_type)) { if (current_param == 0) { - s4o.print("__sub_timespec("); + s4o.print("__time_sub("); param_value->accept(*this); } else if (current_param == 1) { @@ -595,7 +595,7 @@ /* now call the function... */ function_block_type_name->accept(*this); s4o.print(FB_FUNCTION_SUFFIX); - s4o.print("("); + s4o.print("(&"); print_variable_prefix(); symbol->fb_name->accept(*this); s4o.print(")"); diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_cc_vardecl.cc --- a/stage4/generate_cc/generate_cc_vardecl.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_cc_vardecl.cc Fri Jul 13 19:20:26 2007 +0200 @@ -200,6 +200,7 @@ */ typedef enum {finterface_vf, local_vf, + localstatic_vf, localinit_vf, init_vf, constructorinit_vf, @@ -327,7 +328,7 @@ s4o.print(nv->get()); this->current_var_type_symbol->accept(*this); s4o.print(FB_INIT_SUFFIX); - s4o.print("("); + s4o.print("(&"); this->print_variable_prefix(); list->elements[i]->accept(*this); s4o.print(");"); @@ -861,7 +862,7 @@ s4o.print(nv->get()); s4o.print("{extern "); this->current_var_type_symbol->accept(*this); - s4o.print(" "); + s4o.print(" *"); symbol->global_var_name->accept(*this); s4o.print("; "); print_variable_prefix(); @@ -962,6 +963,7 @@ /* now to produce the c equivalent... */ switch(wanted_varformat) { case local_vf: + case localstatic_vf: /* NOTE: located variables must be declared static, as the connection to the * MatPLC point must be initialised at program startup, and not whenever * a new function block is instantiated! @@ -972,17 +974,19 @@ */ s4o.print(s4o.indent_spaces); if (symbol->global_var_name != NULL) { - s4o.print("{extern "); + s4o.print("extern "); this->current_var_type_symbol->accept(*this); s4o.print(" "); symbol->location->accept(*this); - s4o.print("; "); + s4o.print(";\n"); + if (wanted_varformat == localstatic_vf) + s4o.print("static "); this->current_var_type_symbol->accept(*this); s4o.print(" *"); symbol->global_var_name->accept(*this); s4o.print(" = &"); symbol->location->accept(*this); - s4o.print(";}\n"); + s4o.print(";\n"); } break; diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/generate_location_list.cc --- a/stage4/generate_cc/generate_location_list.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/generate_location_list.cc Fri Jul 13 19:20:26 2007 +0200 @@ -118,11 +118,12 @@ /********************************************/ void *visit(direct_variable_c *symbol) { + s4o.print("__LOCATED_VAR("); current_var_type_symbol->accept(*generate_cc_base); - s4o.print(" "); + s4o.print(","); /* Do not use print_token() as it will change everything into uppercase */ s4o.printlocation((symbol->value)+1); - s4o.print("\n"); + s4o.print(")\n"); return NULL; } diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/il_code_gen.c --- a/stage4/generate_cc/il_code_gen.c Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/il_code_gen.c Fri Jul 13 19:20:26 2007 +0200 @@ -15019,7 +15019,7 @@ s4o.print_integer(nb_param); s4o.print(","); IN1_param_value->accept(*this); - s4o.print(",&"); + s4o.print(","); IN2_param_value->accept(*this); int base_num = 3; @@ -15040,7 +15040,7 @@ last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; /*Function specific CODE */ - s4o.print(",&"); + s4o.print(","); param_value->accept(*this); } diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/search_var_instance_decl.cc --- a/stage4/generate_cc/search_var_instance_decl.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/search_var_instance_decl.cc Fri Jul 13 19:20:26 2007 +0200 @@ -316,11 +316,11 @@ return NULL; } -/* AT direct_variable */ -//SYM_REF2(location_c, direct_variable, unused) - void *visit(location_c *symbol) { - if (compare_identifiers(symbol->direct_variable, search_name) == 0) { - current_vartype = located_vt; +/* [variable_name] location ':' located_var_spec_init */ +/* variable_name -> may be NULL ! */ +//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) + void *visit(located_var_decl_c *symbol) { + if (symbol->variable_name != NULL && compare_identifiers(symbol->variable_name, search_name) == 0) { return current_type_decl; } else diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/st_code_gen.c --- a/stage4/generate_cc/st_code_gen.c Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/generate_cc/st_code_gen.c Fri Jul 13 19:20:26 2007 +0200 @@ -16703,7 +16703,7 @@ s4o.print_integer(nb_param); s4o.print(","); IN1_param_value->accept(*this); - s4o.print(",&"); + s4o.print(","); IN2_param_value->accept(*this); int base_num = 3; @@ -16724,7 +16724,7 @@ last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; /*Function specific CODE */ - s4o.print(",&"); + s4o.print(","); param_value->accept(*this); } diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/generate_cc/test_iec_std_lib.c --- a/stage4/generate_cc/test_iec_std_lib.c Thu Jul 12 11:24:32 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#include "stdio.h" - -#include "iec_std_lib.h" - -int main(int argc,char **argv) -{ - return 0; -} diff -r 873a5b60a7ea -r 8998c8b24b60 stage4/stage4.cc --- a/stage4/stage4.cc Thu Jul 12 11:24:32 2007 +0200 +++ b/stage4/stage4.cc Fri Jul 13 19:20:26 2007 +0200 @@ -58,6 +58,12 @@ filename += "."; filename += extension; std::fstream *file = new std::fstream(filename.c_str(), std::fstream::out); + if(file->fail()){ + std::cerr << "Cannot open " << filename << " for write access \n"; + exit(EXIT_FAILURE); + }else{ + std::cout << filename << "\n"; + } out = file; m_file = file; this->indent_level = indent_level; diff -r 873a5b60a7ea -r 8998c8b24b60 tests/.cvsignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/.cvsignore Fri Jul 13 19:20:26 2007 +0200 @@ -0,0 +1,6 @@ +STD_TEST.st +STD_RESSOURCE.c +LOCATED_VARIABLES.h +POUS.c +test +STD_CONF.c diff -r 873a5b60a7ea -r 8998c8b24b60 tests/STD_TEST.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/STD_TEST.xml Fri Jul 13 19:20:26 2007 +0200 @@ -0,0 +1,1914 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TESTNR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INTRES + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + IN1 + + + + + + + IN2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + IN2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + The FROM STRING test machine + + + + + + + 1000.0 + + + + + + + 0 + + + + + + + + + + + + + NEXT_TEST + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + 'LEN' + + + + + + + 'STRING_TO_REAL *1000' + + + + + + + 'STRING_TO_INT' + + + + + + + 'FIND' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TEST_NAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + STRRES + + + + + + + TESTNR + + + + + + + IN1 + + + + + + + IN2 + + + + + + + IN3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + L + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + L + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + P + + + + + + + L + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + IN2 + + + + + + + IN3 + + + + + + + IN1 + + + + + + + IN2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + P + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + L + + + + + + + P + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN1 + + + + + + + IN2 + + + + + + + L + + + + + + + P + + + + The TO STRING test machine + + + + + + + + + + + + + NEXT_TEST + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + 'IN1' + + + + + + + 'IN2' + + + + + + + 'IN3' + + + + + + + 'LEFT' + + + + + + + 'RIGHT' + + + + + + + 'MID' + + + + + + + 'CONCAT' + + + + + + + 'INSERT' + + + + + + + 'DELETE' + + + + + + + 'REPLACE' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TEST_NAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + STR1 + + + + + + + '456' + + + + + + + 'abcdefgh' + + + + + + + INT1 + + + + + + + 2 + + + + + + + 3 + + + + + + + + + + + + + RES_STR + + + + + + + + + + + + + RES_INT + + + + + + + TEST_NB + + + + + + + + + + + + + TEST_NB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TO_STR_TEST_NAME + + + + + + + + + + + FROM_STR_TEST_NAME + + + + Unused + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 873a5b60a7ea -r 8998c8b24b60 tests/build.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/build.sh Fri Jul 13 19:20:26 2007 +0200 @@ -0,0 +1,9 @@ +#!/bin/bash + +../iec2cc STD_TEST.st -I ../lib + +gcc -I ../lib -c -g STD_RESSOURCE.c + +gcc -I ../lib -c -g STD_CONF.c + +gcc -I ../lib main.c STD_CONF.o STD_RESSOURCE.o -g -l rt -o test diff -r 873a5b60a7ea -r 8998c8b24b60 tests/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/main.c Fri Jul 13 19:20:26 2007 +0200 @@ -0,0 +1,97 @@ +#include +#include + +#include "iec_std_lib.h" + +/* + * Functions and variables provied by generated C softPLC + **/ +void config_run__(int tick); +void config_init__(void); +extern int common_ticktime__; + +/* + * Functions and variables to export to generated C softPLC + **/ + +TIME __CURRENT_TIME; + +#define __LOCATED_VAR(type, name) type name; +#include "LOCATED_VARIABLES.h" +#undef __LOCATED_VAR + +#define print_BOOL(name) printf(" %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE"); +#define print_SINT(name) printf(" %s = (SINT) %d\n",#name, name); +#define print_INT(name) printf(" %s = (INT) %d\n",#name, name); +#define print_DINT(name) printf(" %s = (DINT) %d\n",#name, name); +#define print_LINT(name) printf(" %s = (LINT) %d\n",#name, name); +#define print_USINT(name) printf(" %s = (USINT) %u\n",#name, name); +#define print_UINT(name) printf(" %s = (UINT) %u\n",#name, name); +#define print_UDINT(name) printf(" %s = (UDINT) %u\n",#name, name); +#define print_ULINT(name) printf(" %s = (ULINT) %lu\n",#name, name); +#define print_REAL(name) printf(" %s = (REAL) %f\n",#name, (double)name); +#define print_LREAL(name) printf(" %s = (LREAL) %f\n",#name, (double)name); +#define print_TIME(name) {tmp STRING = __time_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %s*s\n",#name, tmp.len, &tmp.body);} +#define print_DATE(name) {tmp STRING = __date_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} +#define print_TOD(name) {tmp STRING = __tod_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} +#define print_DT(name) {tmp STRING = __dt_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} +#define print_STRING(name) printf(" %s = (STRING) {%d, \"%*s\"}\n",#name, name.len, name.len, &name.body); +#define print_BYTE(name) printf(" %s = (BYTE) 0x%2.2x\n",#name, name); +#define print_WORD(name) printf(" %s = (WORD) 0x%d4.4\n",#name, name); +#define print_DWORD(name) printf(" %s = (DWORD) 0x%d8.8\n",#name, name); +#define print_LWORD(name) printf(" %s = (LWORD) 0x%d16.16\n",#name, name); + +static int tick = 0; +void timer_notify(sigval_t val) +{ + clock_gettime(CLOCK_REALTIME, &__CURRENT_TIME); + printf("Tick %d\n",tick); + config_run__(tick++); + printf(" Located variables : \n"); +#define __LOCATED_VAR(type, name) print_##type(name); +#include "LOCATED_VARIABLES.h" +#undef __LOCATED_VAR +} + +void catch_signal(int sig) +{ + signal(SIGTERM, catch_signal); + signal(SIGINT, catch_signal); + printf("Got Signal %d\n",sig); +} + +#define maxval(a,b) ((a>b)?a:b) +int main(int argc,char **argv) +{ + timer_t timer; + struct sigevent sigev; + long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000); + time_t tv_sec = common_ticktime__/1000; + struct itimerspec timerValues; + + memset (&sigev, 0, sizeof (struct sigevent)); + memset (&timerValues, 0, sizeof (struct itimerspec)); + sigev.sigev_value.sival_int = 0; + sigev.sigev_notify = SIGEV_THREAD; + sigev.sigev_notify_attributes = NULL; + sigev.sigev_notify_function = timer_notify; + timerValues.it_value.tv_sec = tv_sec; + timerValues.it_value.tv_nsec = tv_nsec; + timerValues.it_interval.tv_sec = tv_sec; + timerValues.it_interval.tv_nsec = tv_nsec; + + config_init__(); + + timer_create (CLOCK_REALTIME, &sigev, &timer); + timer_settime (timer, 0, &timerValues, NULL); + + /* install signal handler for manual break */ + signal(SIGTERM, catch_signal); + signal(SIGINT, catch_signal); + + pause(); + + timer_delete (timer); + + return 0; +}