Commit 5cefbcf0 authored by dbarbera's avatar dbarbera
Browse files

Merge branch 'master' into llvm

parents 54e91fe2 ad11aa98
...@@ -931,8 +931,11 @@ def _bitwise_operators(expr): ...@@ -931,8 +931,11 @@ def _bitwise_operators(expr):
ada_string += u", Length => {left}.Length".format(left=left_str) ada_string += u", Length => {left}.Length".format(left=left_str)
ada_string += u')' ada_string += u')'
else: else:
ada_string = u'({left} {op} {right})'.format( ada_string = u'({left} {op}{short} {right})'.format(
left=left_str, op=expr.operand, right=right_str) left=left_str,
op=expr.operand,
short=expr.shortcircuit,
right=right_str)
code.extend(left_stmts) code.extend(left_stmts)
code.extend(right_stmts) code.extend(right_stmts)
local_decl.extend(left_local) local_decl.extend(left_local)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
   
# Resource object code # Resource object code
# #
# Created: Fri Jun 27 18:30:08 2014 # Created: Wed Jul 2 08:06:50 2014
# by: The Resource Compiler for PySide (Qt v4.8.6) # by: The Resource Compiler for PySide (Qt v4.8.6)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
...@@ -76,14 +76,19 @@ class ExprMinus(Expression): ...@@ -76,14 +76,19 @@ class ExprMinus(Expression):
class ExprOr(Expression): class ExprOr(Expression):
operand = 'or' operand = 'or'
# Indicate that short circuit form is used ("or else")
shortcircuit = ''
class ExprAnd(Expression): class ExprAnd(Expression):
operand = 'and' operand = 'and'
# Indicate that short circuit form is used ("and then")
shortcircuit = ''
class ExprXor(Expression): class ExprXor(Expression):
operand = 'xor' operand = 'xor'
shortcircuit = ''
class ExprEq(Expression): class ExprEq(Expression):
......
...@@ -1282,6 +1282,22 @@ def expression(root, context): ...@@ -1282,6 +1282,22 @@ def expression(root, context):
root.getCharPositionInLine()) root.getCharPositionInLine())
expr.exprType = UNKNOWN_TYPE expr.exprType = UNKNOWN_TYPE
if root.type in (lexer.OR, lexer.AND):
# detect optional THEN in AND/OR expressions, indicating that the
# short-circuit version of the operator is needed, to prevent the
# evaluation of the right part if the left part does not evaluate
# to true.
for idx, val in enumerate(root.children):
if val.type == lexer.THEN:
expr.shortcircuit = ' then'
root.children.pop(idx)
break
elif val.type == lexer.ELSE:
expr.shortcircuit = ' else'
root.children.pop(idx)
break
if root.type in (lexer.PLUS, if root.type in (lexer.PLUS,
lexer.ASTERISK, lexer.ASTERISK,
lexer.DASH, lexer.DASH,
......
...@@ -796,8 +796,8 @@ field_selection ...@@ -796,8 +796,8 @@ field_selection
: (('!'|'.') field_name); : (('!'|'.') field_name);
expression : operand0 ( IMPLIES^ operand0)* ; expression : operand0 ( IMPLIES^ operand0)* ;
operand0 : operand1 (( OR^ | XOR^ ) operand1)*; operand0 : operand1 (( (OR^ ELSE?) | XOR^ ) operand1)*;
operand1 : operand2 ( AND^ operand2)*; operand1 : operand2 ( AND^ THEN? operand2)*;
operand2 : operand3 operand2 : operand3
(( EQ^ | NEQ^ | GT^ | GE^ | LT^ | LE^ | IN^ ) (( EQ^ | NEQ^ | GT^ | GE^ | LT^ | LE^ | IN^ )
operand3)*; operand3)*;
......
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-06-27 18:30:11 # $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-07-02 08:11:12
import sys import sys
from antlr3 import * from antlr3 import *
......
This diff is collapsed.
...@@ -7,6 +7,11 @@ test-ada: ...@@ -7,6 +7,11 @@ test-ada:
../../../opengeode.py --toAda myfunction.pr system_structure.pr ../../../opengeode.py --toAda myfunction.pr system_structure.pr
asn1.exe -Ada dataview-uniq.asn -typePrefix asn1Scc -equal asn1.exe -Ada dataview-uniq.asn -typePrefix asn1Scc -equal
gnatmake -c myfunction.adb gnatmake -c myfunction.adb
gcc -c test.c
gnatbind -n myfunction.ali
gnatlink -o testcase test.o myfunction.ali -lgnat
./testcase
./testcase | diff expected -
test-llvm: test-llvm:
../../../opengeode.py myfunction.pr system_structure.pr --llvm ../../../opengeode.py myfunction.pr system_structure.pr --llvm
......
[C Code] Running test
OK
/* CIF PROCESS (148, 150), (150, 75) */ /* CIF PROCESS (148, 150), (150, 75) */
PROCESS myfunction; PROCESS myfunction;
/* CIF TEXT (-533, -82), (271, 323) */ /* CIF TEXT (0, 17), (271, 323) */
-- Timers defined in the interface view -- Timers defined in the interface view
-- Use SET_TIMER (value, timer name) -- Use SET_TIMER (value, timer name)
-- and RESET_TIMER (timer name) in a -- and RESET_TIMER (timer name) in a
-- PROCEDURE CALL symbol to use them -- PROCEDURE CALL symbol to use them
...@@ -21,66 +21,81 @@ dcl someInt t_uInt8 := 2; ...@@ -21,66 +21,81 @@ dcl someInt t_uInt8 := 2;
-- To test 'op_not' -- To test 'op_not'
dcl opnot T_boolean := not true; dcl opnot T_boolean := not true;
/* CIF ENDTEXT */ /* CIF ENDTEXT */
/* CIF PROCEDURE (358, 391), (91, 35) */ /* CIF PROCEDURE (982, 490), (91, 35) */
PROCEDURE factorial; PROCEDURE factorial;
/* CIF TEXT (29, 42), (215, 48) */ /* CIF TEXT (29, 42), (215, 48) */
fpar in N MyInteger, fpar in N MyInteger,
in/out result MyInteger; in/out result MyInteger;
/* CIF ENDTEXT */ /* CIF ENDTEXT */
/* CIF START (298, 33), (70, 35) */ /* CIF START (298, 33), (70, 35) */
START; START;
/* CIF TASK (284, 83), (97, 35) */ /* CIF TASK (284, 83), (97, 35) */
TASK result := 1; TASK result := 1;
/* CIF TASK (223, 133), (220, 53) */ /* CIF TASK (223, 133), (220, 53) */
TASK for x in range(1, n+1): TASK for x in range(1, n+1):
result := (result * x) mod 255 result := (result * x) mod 255
endfor; endfor;
/* CIF RETURN (315, 201), (35, 35) */ /* CIF RETURN (315, 201), (35, 35) */
RETURN ; RETURN ;
ENDPROCEDURE; ENDPROCEDURE;
/* CIF START (58, -99), (100, 50) */ /* CIF START (591, 0), (100, 50) */
START; START;
/* CIF NEXTSTATE (58, -34), (100, 50) */ /* CIF TASK (586, 65), (110, 35) */
NEXTSTATE Wait; TASK someInt := 0;
/* CIF DECISION (504, 115), (273, 87) */
DECISION someint /=0 and then (10 / someInt > 0)
/* CIF STATE (58, -34), (100, 50) */ or else someint = 0
STATE Wait; /* CIF COMMENT (793, 124), (179, 68) */
/* CIF INPUT (277, 36), (100, 50) */ COMMENT 'Using "and else" is the
INPUT mytimer; short-circuit form. The
/* CIF PROCEDURECALL (259, 101), (135, 50) */ second part should not
CALL writeln be evaluated.';
('timer expired'); /* CIF ANSWER (561, 222), (70, 23) */
/* CIF PROCEDURECALL (247, 166), (160, 35) */ (true):
CALL factorial(3, someint); /* CIF TASK (541, 260), (110, 35) */
/* CIF NEXTSTATE (277, 216), (100, 50) */ TASK someInt := 5;
NEXTSTATE Wait; /* CIF PROCEDURECALL (537, 310), (117, 38) */
/* CIF INPUT (-83, 36), (198, 50) */ CALL writeln('OK');
INPUT start_something (toto); /* CIF ANSWER (664, 222), (70, 23) */
/* CIF OUTPUT (-119, 101), (270, 50) */ (false):
OUTPUT result_data((toto+1) mod 2147483647); ENDDECISION;
/* CIF PROCEDURECALL (-59, 166), (150, 50) */ /* CIF NEXTSTATE (591, 363), (100, 50) */
CALL writeln NEXTSTATE Wait;
/* CIF STATE (591, 363), (100, 50) */
STATE Wait;
/* CIF INPUT (810, 433), (100, 50) */
INPUT mytimer;
/* CIF PROCEDURECALL (769, 498), (182, 50) */
CALL writeln('timer expired');
/* CIF PROCEDURECALL (780, 563), (160, 35) */
CALL factorial(3, someint);
/* CIF NEXTSTATE (810, 613), (100, 50) */
NEXTSTATE Wait;
/* CIF INPUT (450, 433), (198, 50) */
INPUT start_something (toto);
/* CIF OUTPUT (414, 498), (270, 50) */
OUTPUT result_data((toto+1) mod 2147483647);
/* CIF PROCEDURECALL (474, 563), (150, 50) */
CALL writeln
('Hello Toto', toto); ('Hello Toto', toto);
/* CIF PROCEDURECALL (-50, 231), (132, 50) */ /* CIF PROCEDURECALL (451, 628), (196, 50) */
CALL set_timer CALL set_timer(1000, myTimer);
(1000, myTimer); /* CIF TASK (391, 693), (316, 35) */
/* CIF TASK (-142, 296), (316, 35) */ TASK someReal := power(someReal, someInt mod 1);
TASK someReal := power(someReal, someInt mod 1); /* CIF PROCEDURECALL (379, 743), (340, 35) */
/* CIF PROCEDURECALL (-154, 346), (340, 35) */ CALL writeln('1.5 ** 2 == ', someReal, ' (should be 2.25 )');
CALL writeln('1.5 ** 2 == ', someReal, ' (should be 2.25 )'); /* CIF TASK (448, 793), (201, 35) */
/* CIF TASK (-84, 396), (201, 35) */ TASK someReal := float(someInt);
TASK someReal := float(someInt); /* CIF TASK (428, 843), (241, 35) */
/* CIF TASK (-104, 446), (241, 35) */ TASK someInt := fix(someReal) mod 255;
TASK someInt := fix(someReal) mod 255; /* CIF TASK (473, 893), (152, 35) */
/* CIF TASK (-60, 496), (152, 35) */ TASK opnot := not opnot;
TASK opnot := not opnot; /* CIF TASK (470, 943), (157, 35) */
/* CIF TASK (-62, 546), (157, 35) */ TASK someint := -someint;
TASK someint := -someint; /* CIF TASK (467, 993), (164, 35) */
/* CIF TASK (-66, 596), (164, 35) */ TASK someint := (-8) mod 5;
TASK someint := (-8) mod 5; /* CIF NEXTSTATE (498, 1043), (102, 50) */
/* CIF NEXTSTATE (-35, 646), (102, 50) */ NEXTSTATE wait;
NEXTSTATE wait; ENDSTATE;
ENDSTATE;
ENDPROCESS myfunction; ENDPROCESS myfunction;
\ No newline at end of file
#include <math.h>
#include <stdio.h>
extern void adainit();
void myfunction_RI_result_data(long long *val)
{
printf("[C] result_data: %lld\n", *val);
}
void myfunction_RI_set_mytimer(long long *val)
{
printf("[C] SET MyTimer: %lld\n", *val);
}
void myfunction_RI_reset_mytimer()
{
printf("RESET MyTimer\n");
}
int main()
{
printf("[C Code] Running test\n");
adainit();
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment