|
| 1 | +with Ada.Text_IO; use Ada.Text_IO; |
| 2 | +with System.Machine_Code; use System.Machine_Code; |
| 3 | + |
| 4 | +procedure Main is |
| 5 | + procedure P is null; |
| 6 | + |
| 7 | + -- Flag because it has clobbers, one output variable that is returned. |
| 8 | + function F1 (Var_In : Integer) return Integer is |
| 9 | + Var_Out : Integer; |
| 10 | + begin |
| 11 | + Asm("addl $42, %1" & ASCII.LF & ASCII.HT & -- FLAG |
| 12 | + "movl %0, %1", |
| 13 | + Outputs => Integer'Asm_Output ("=a", Var_Out), |
| 14 | + Inputs => Integer'Asm_Input ("a", Var_In), |
| 15 | + Clobber => "memory"); |
| 16 | + null; |
| 17 | + P; |
| 18 | + return Var_Out; |
| 19 | + end; |
| 20 | + |
| 21 | + -- Do not flag because it has more than one output. |
| 22 | + function F2 (Var_In : Integer) return Integer is |
| 23 | + Var_Out1, Var_Out2 : Integer; |
| 24 | + begin |
| 25 | + Asm("addl $42, %1" & ASCII.LF & ASCII.HT & -- NOFLAG |
| 26 | + "movl %0, %1", |
| 27 | + Outputs => (Integer'Asm_Output ("=a", Var_Out1), |
| 28 | + Integer'Asm_Output ("=a", Var_Out2)), |
| 29 | + Inputs => Integer'Asm_Input ("a", Var_In), |
| 30 | + Clobber => "memory"); |
| 31 | + return Var_Out1; |
| 32 | + end; |
| 33 | + |
| 34 | + -- Do not flag because it has no clobbers |
| 35 | + function F3 (Var_In : Integer) return Integer is |
| 36 | + Var_Out1, Var_Out2 : Integer; |
| 37 | + begin |
| 38 | + Asm("addl $42, %1" & ASCII.LF & ASCII.HT & -- NOFLAG |
| 39 | + "movl %0, %1", |
| 40 | + Outputs => Integer'Asm_Output ("=a", Var_Out1), |
| 41 | + Inputs => Integer'Asm_Input ("a", Var_In)); |
| 42 | + return Var_Out1; |
| 43 | + end; |
| 44 | + |
| 45 | + -- Do not flag because it doesn't return the sole output variable. |
| 46 | + function F4 (Var_In : Integer) return Integer is |
| 47 | + Var_Out1, Var_Out2 : Integer; |
| 48 | + begin |
| 49 | + Asm("addl $42, %1" & ASCII.LF & ASCII.HT & -- NOFLAG |
| 50 | + "movl %0, %1", |
| 51 | + Outputs => Integer'Asm_Output ("=a", Var_Out1), |
| 52 | + Inputs => Integer'Asm_Input ("a", Var_In)); |
| 53 | + return Var_In; |
| 54 | + end; |
| 55 | + |
| 56 | + -- Flag because it has clobbers, one output variable that is returned. |
| 57 | + function F5 (Var_In : Integer) return Integer is |
| 58 | + Var_Out : Integer; |
| 59 | + begin |
| 60 | + if True |
| 61 | + then |
| 62 | + Asm("addl $42, %1" & ASCII.LF & ASCII.HT & -- FLAG |
| 63 | + "movl %0, %1", |
| 64 | + Outputs => Integer'Asm_Output ("=a", Var_Out), |
| 65 | + Inputs => Integer'Asm_Input ("a", Var_In), |
| 66 | + Clobber => "memory"); |
| 67 | + else |
| 68 | + return 4; |
| 69 | + end if; |
| 70 | + |
| 71 | + return Var_Out; |
| 72 | + end; |
| 73 | +begin |
| 74 | + Put_Line(F1 (1)'Image); |
| 75 | +end; |
0 commit comments