我目前在实时编程语言的大学课程中学习Ada,并对SPARK有疑问。
我正在开展一个项目,其任务是监控离网电源。这项任务对于机器安全至关重要,因此应该尽可能没有错误,例如SPARK证明。
我得到这个奇怪的错误,我无法找到11:14 tasking in SPARK requires sequential elaboration (SPARK RM 9(2)) violation of pragma SPARK_Mode
原始代码有点长,但我能用最小的例子得到同样的错误。
规范:
pragma Profile (Ravenscar);
pragma SPARK_Mode;
with System;
package simple_monitoring is
function sign (val : in Float) return Float
with Pre => val >= 10.0;
task type myTask is
end myTask;
end simple_monitoring;
实施:
pragma Profile (Ravenscar);
pragma SPARK_Mode;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
package body simple_monitoring is
function sign (val : in Float) return Float is
res : Float;
begin
pragma Assert (val >= 10.0);
res := 100.0 / val;
return res;
end sign;
task body myTask is
TASK_PERIOD : constant Time_Span := Milliseconds (100);
next_time : Time := Clock;
myVar : Float;
begin
loop
Put_Line ("Running task");
myVar := sign (20.0);
next_time := next_time + TASK_PERIOD;
delay until next_time;
end loop;
end myTask;
end simple_monitoring;
感谢任何帮助: - )
答案 0 :(得分:4)
您需要额外的配置编译指示
pragma Partition_Elaboration_Policy (Sequential);
(见ARM H.6)。对于您给出的示例,这只需要放在规范上;但一般来说,它需要是一个程序范围的配置pragma。
您可以通过提供一个文件来安排此操作,例如gnat.adc
,其中包含
pragma Profile (Ravenscar);
pragma Partition_Elaboration_Policy (Sequential);
并在GNAT项目文件中的Builder
包中引用它:
package Builder is
for Global_Configuration_Pragmas use "gnat.adc";
...