[aarch64] Use op_mode instead of vmode in aarch64_vectorize_vec_perm_const.
[official-gcc.git] / gcc / ada / switch-b.adb
blob10feb23483345d4ce505fa138a459fcf84afaf09
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2022, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Bindgen;
27 with Debug; use Debug;
28 with Osint; use Osint;
29 with Opt; use Opt;
31 with System.OS_Lib; use System.OS_Lib;
32 with System.WCh_Con; use System.WCh_Con;
34 package body Switch.B is
36 --------------------------
37 -- Scan_Binder_Switches --
38 --------------------------
40 procedure Scan_Binder_Switches (Switch_Chars : String) is
41 Max : constant Integer := Switch_Chars'Last;
42 Ptr : Integer := Switch_Chars'First;
43 C : Character := ' ';
45 function Get_Optional_Filename return String_Ptr;
46 -- If current character is '=', return a newly allocated string that
47 -- contains the remainder of the current switch (after the '='), else
48 -- return null.
50 function Get_Stack_Size (S : Character) return Int;
51 -- Used for -d and -D to scan stack size including handling k/m. S is
52 -- set to 'd' or 'D' to indicate the switch being scanned.
54 procedure Scan_Debug_Switches;
55 -- Scan out debug switches
57 ---------------------------
58 -- Get_Optional_Filename --
59 ---------------------------
61 function Get_Optional_Filename return String_Ptr is
62 Result : String_Ptr;
64 begin
65 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
66 if Ptr = Max then
67 Bad_Switch (Switch_Chars);
68 else
69 Result := new String'(Switch_Chars (Ptr + 1 .. Max));
70 Ptr := Max + 1;
71 return Result;
72 end if;
73 end if;
75 return null;
76 end Get_Optional_Filename;
78 --------------------
79 -- Get_Stack_Size --
80 --------------------
82 function Get_Stack_Size (S : Character) return Int is
83 Result : Int;
85 begin
86 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
88 -- In the following code, we enable overflow checking since the
89 -- multiplication by K or M may cause overflow, which is an error.
91 declare
92 pragma Unsuppress (Overflow_Check);
94 begin
95 -- Check for additional character 'k' (for kilobytes) or 'm' (for
96 -- Megabytes), but only if we have not reached the end of the
97 -- switch string. Note that if this appears before the end of the
98 -- string we will get an error when we test to make sure that the
99 -- string is exhausted (at the end of the case).
101 if Ptr <= Max then
102 if Switch_Chars (Ptr) = 'k' then
103 Result := Result * 1024;
104 Ptr := Ptr + 1;
106 elsif Switch_Chars (Ptr) = 'm' then
107 Result := Result * (1024 * 1024);
108 Ptr := Ptr + 1;
109 end if;
110 end if;
112 exception
113 when Constraint_Error =>
114 Osint.Fail ("numeric value out of range for switch: " & S);
115 end;
117 return Result;
118 end Get_Stack_Size;
120 -------------------------
121 -- Scan_Debug_Switches --
122 -------------------------
124 procedure Scan_Debug_Switches is
125 Dot : Boolean := False;
126 Underscore : Boolean := False;
128 begin
129 while Ptr <= Max loop
130 C := Switch_Chars (Ptr);
132 -- Binder debug flags come in the following forms:
134 -- letter
135 -- . letter
136 -- _ letter
138 -- digit
139 -- . digit
140 -- _ digit
142 -- Note that the processing of switch -d aleady takes care of the
143 -- case where the first flag is a digit (default stack size).
145 if C in '1' .. '9' or else
146 C in 'a' .. 'z' or else
147 C in 'A' .. 'Z'
148 then
149 -- . letter
150 -- . digit
152 if Dot then
153 Set_Dotted_Debug_Flag (C);
154 Dot := False;
156 -- _ letter
157 -- _ digit
159 elsif Underscore then
160 Set_Underscored_Debug_Flag (C);
161 if Debug_Flag_Underscore_C then
162 Enable_CUDA_Expansion := True;
163 end if;
164 Underscore := False;
166 -- letter
167 -- digit
169 else
170 Set_Debug_Flag (C);
171 end if;
173 elsif C = '.' then
174 Dot := True;
176 elsif C = '_' then
177 Underscore := True;
179 else
180 Bad_Switch (Switch_Chars);
181 end if;
183 Ptr := Ptr + 1;
184 end loop;
185 end Scan_Debug_Switches;
187 -- Start of processing for Scan_Binder_Switches
189 begin
190 -- Skip past the initial character (must be the switch character)
192 if Ptr = Max then
193 Bad_Switch (Switch_Chars);
194 else
195 Ptr := Ptr + 1;
196 end if;
198 -- A little check, "gnat" at the start of a switch is not allowed except
199 -- for the compiler
201 if Max >= Ptr + 3
202 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
203 then
204 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
205 & " (gnat not needed here)");
206 end if;
208 -- Loop to scan through switches given in switch string
210 Check_Switch : begin
211 C := Switch_Chars (Ptr);
213 case C is
215 -- Processing for a switch
217 when 'a' =>
218 Ptr := Ptr + 1;
219 Use_Pragma_Linker_Constructor := True;
221 -- Processing for A switch
223 when 'A' =>
224 Ptr := Ptr + 1;
225 Output_ALI_List := True;
226 ALI_List_Filename := Get_Optional_Filename;
228 -- Processing for b switch
230 when 'b' =>
231 Ptr := Ptr + 1;
232 Brief_Output := True;
234 -- Processing for c switch
236 when 'c' =>
237 Ptr := Ptr + 1;
238 Check_Only := True;
240 -- Processing for d switch
242 when 'd' =>
243 if Ptr = Max then
244 Bad_Switch (Switch_Chars);
245 end if;
247 Ptr := Ptr + 1;
248 C := Switch_Chars (Ptr);
250 -- Case where character after -d is a digit (default stack size)
252 if C in '0' .. '9' then
254 -- In this case, we process the default primary stack size
256 Default_Stack_Size := Get_Stack_Size ('d');
258 -- Case where character after -d is not digit (debug flags)
260 else
261 Scan_Debug_Switches;
262 end if;
264 -- Processing for D switch
266 when 'D' =>
267 if Ptr = Max then
268 Bad_Switch (Switch_Chars);
269 end if;
271 Ptr := Ptr + 1;
272 Default_Sec_Stack_Size := Get_Stack_Size ('D');
274 -- Processing for e switch
276 when 'e' =>
277 Ptr := Ptr + 1;
278 Elab_Dependency_Output := True;
280 -- Processing for E switch
282 when 'E' =>
284 -- -E is equivalent to -Ea (see below)
286 Exception_Tracebacks := True;
287 Ptr := Ptr + 1;
289 if Ptr <= Max then
290 case Switch_Chars (Ptr) is
292 -- -Ea sets Exception_Tracebacks
294 when 'a' => null;
296 -- -Es sets both Exception_Tracebacks and
297 -- Exception_Tracebacks_Symbolic.
299 when 's' => Exception_Tracebacks_Symbolic := True;
300 when others => Bad_Switch (Switch_Chars);
301 end case;
303 Ptr := Ptr + 1;
304 end if;
306 -- Processing for f switch
308 when 'f' =>
309 if Ptr = Max then
310 Bad_Switch (Switch_Chars);
311 end if;
313 Force_Elab_Order_File :=
314 new String'(Switch_Chars (Ptr + 1 .. Max));
316 Ptr := Max + 1;
318 if not Is_Regular_File (Force_Elab_Order_File.all) then
319 Osint.Fail (Force_Elab_Order_File.all & ": file not found");
320 end if;
322 -- Processing for F switch
324 when 'F' =>
325 Ptr := Ptr + 1;
326 Force_Checking_Of_Elaboration_Flags := True;
328 -- Processing for g switch
330 when 'g' =>
331 Ptr := Ptr + 1;
333 if Ptr <= Max then
334 C := Switch_Chars (Ptr);
336 if C in '0' .. '3' then
337 Debugger_Level :=
338 Character'Pos
339 (Switch_Chars (Ptr)) - Character'Pos ('0');
340 Ptr := Ptr + 1;
341 end if;
343 else
344 Debugger_Level := 2;
345 end if;
347 -- Processing for G switch
349 when 'G' =>
350 Ptr := Ptr + 1;
351 Generate_C_Code := True;
353 -- Processing for h switch
355 when 'h' =>
356 Ptr := Ptr + 1;
357 Usage_Requested := True;
359 -- Processing for H switch
361 when 'H' =>
362 Ptr := Ptr + 1;
363 Legacy_Elaboration_Order := True;
365 -- Processing for i switch
367 when 'i' =>
368 if Ptr = Max then
369 Bad_Switch (Switch_Chars);
370 end if;
372 Ptr := Ptr + 1;
373 C := Switch_Chars (Ptr);
375 if C in '1' .. '5' | '9' | 'p' | '8' | 'f' | 'n' | 'w' then
376 Identifier_Character_Set := C;
377 Ptr := Ptr + 1;
378 else
379 Bad_Switch (Switch_Chars);
380 end if;
382 -- Processing for K switch
384 when 'K' =>
385 Ptr := Ptr + 1;
386 Output_Linker_Option_List := True;
388 -- Processing for l switch
390 when 'l' =>
391 Ptr := Ptr + 1;
392 Elab_Order_Output := True;
394 -- Processing for m switch
396 when 'm' =>
397 if Ptr = Max then
398 Bad_Switch (Switch_Chars);
399 end if;
401 Ptr := Ptr + 1;
402 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
404 -- Processing for n switch
406 when 'n' =>
407 Ptr := Ptr + 1;
408 Bind_Main_Program := False;
410 -- Note: The -L option of the binder also implies -n, so
411 -- any change here must also be reflected in the processing
412 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
414 -- Processing for o switch
416 when 'o' =>
417 Ptr := Ptr + 1;
419 if Output_File_Name_Present then
420 Osint.Fail ("duplicate -o switch");
421 else
422 Output_File_Name_Present := True;
423 end if;
425 -- Processing for O switch
427 when 'O' =>
428 Ptr := Ptr + 1;
429 Output_Object_List := True;
430 Object_List_Filename := Get_Optional_Filename;
432 -- Processing for p switch
434 when 'p' =>
435 Ptr := Ptr + 1;
436 Pessimistic_Elab_Order := True;
438 -- Processing for P switch
440 when 'P' =>
441 Ptr := Ptr + 1;
442 CodePeer_Mode := True;
444 -- Processing for q switch
446 when 'q' =>
447 Ptr := Ptr + 1;
448 Quiet_Output := True;
450 -- Processing for Q switch
452 when 'Q' =>
453 if Ptr = Max then
454 Bad_Switch (Switch_Chars);
455 end if;
457 Ptr := Ptr + 1;
458 Scan_Nat
459 (Switch_Chars, Max, Ptr,
460 Quantity_Of_Default_Size_Sec_Stacks, C);
462 -- Processing for r switch
464 when 'r' =>
465 Ptr := Ptr + 1;
466 List_Restrictions := True;
468 -- Processing for R switch
470 when 'R' =>
471 Ptr := Ptr + 1;
472 List_Closure := True;
474 if Ptr <= Max and then Switch_Chars (Ptr) = 'a' then
475 Ptr := Ptr + 1;
476 List_Closure_All := True;
477 end if;
479 -- Processing for s switch
481 when 's' =>
482 Ptr := Ptr + 1;
483 All_Sources := True;
484 Check_Source_Files := True;
486 -- Processing for t switch
488 when 't' =>
489 Ptr := Ptr + 1;
490 Tolerate_Consistency_Errors := True;
492 -- Processing for T switch
494 when 'T' =>
495 if Ptr = Max then
496 Bad_Switch (Switch_Chars);
497 end if;
499 Ptr := Ptr + 1;
500 Time_Slice_Set := True;
501 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
502 Time_Slice_Value := Time_Slice_Value * 1_000;
504 -- Processing for u switch
506 when 'u' =>
507 if Ptr = Max then
508 Bad_Switch (Switch_Chars);
509 end if;
511 Ptr := Ptr + 1;
512 Dynamic_Stack_Measurement := True;
513 Scan_Nat
514 (Switch_Chars,
515 Max,
516 Ptr,
517 Dynamic_Stack_Measurement_Array_Size,
520 -- Processing for v switch
522 when 'v' =>
523 Ptr := Ptr + 1;
524 Verbose_Mode := True;
526 -- Processing for V switch
528 when 'V' =>
529 declare
530 Eq : Integer;
531 begin
532 Ptr := Ptr + 1;
533 Eq := Ptr;
534 while Eq <= Max and then Switch_Chars (Eq) /= '=' loop
535 Eq := Eq + 1;
536 end loop;
537 if Eq = Ptr or else Eq = Max then
538 Bad_Switch (Switch_Chars);
539 end if;
540 Bindgen.Set_Bind_Env
541 (Key => Switch_Chars (Ptr .. Eq - 1),
542 Value => Switch_Chars (Eq + 1 .. Max));
543 Ptr := Max + 1;
544 end;
546 -- Processing for w switch
548 when 'w' =>
549 if Ptr = Max then
550 Bad_Switch (Switch_Chars);
551 end if;
553 -- For the binder we only allow suppress/error cases
555 Ptr := Ptr + 1;
557 case Switch_Chars (Ptr) is
558 when 'e' =>
559 Warning_Mode := Treat_As_Error;
561 when 'E' =>
562 Warning_Mode := Treat_Run_Time_Warnings_As_Errors;
564 when 's' =>
565 Warning_Mode := Suppress;
567 when others =>
568 Bad_Switch (Switch_Chars);
569 end case;
571 Ptr := Ptr + 1;
573 -- Processing for W switch
575 when 'W' =>
576 Ptr := Ptr + 1;
578 if Ptr > Max then
579 Bad_Switch (Switch_Chars);
580 end if;
582 begin
583 Wide_Character_Encoding_Method :=
584 Get_WC_Encoding_Method (Switch_Chars (Ptr));
585 exception
586 when Constraint_Error =>
587 Bad_Switch (Switch_Chars);
588 end;
590 Wide_Character_Encoding_Method_Specified := True;
592 Upper_Half_Encoding :=
593 Wide_Character_Encoding_Method in WC_Upper_Half_Encoding_Method;
595 Ptr := Ptr + 1;
597 -- Processing for x switch
599 when 'x' =>
600 Ptr := Ptr + 1;
601 All_Sources := False;
602 Check_Source_Files := False;
604 -- Processing for X switch
606 when 'X' =>
607 if Ptr = Max then
608 Bad_Switch (Switch_Chars);
609 end if;
611 Ptr := Ptr + 1;
612 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
614 -- Processing for y switch
616 when 'y' =>
617 Ptr := Ptr + 1;
618 Leap_Seconds_Support := True;
620 -- Processing for z switch
622 when 'z' =>
623 Ptr := Ptr + 1;
624 No_Main_Subprogram := True;
626 -- Processing for Z switch
628 when 'Z' =>
629 Ptr := Ptr + 1;
630 Zero_Formatting := True;
632 -- Processing for --RTS
634 when '-' =>
636 if Ptr + 4 <= Max and then
637 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
638 then
639 Ptr := Ptr + 4;
641 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
642 Osint.Fail ("missing path for --RTS");
644 else
645 -- Valid --RTS switch
647 Opt.No_Stdinc := True;
648 Opt.RTS_Switch := True;
650 declare
651 Src_Path_Name : constant String_Ptr :=
652 Get_RTS_Search_Dir
653 (Switch_Chars (Ptr + 1 .. Max),
654 Include);
655 Lib_Path_Name : constant String_Ptr :=
656 Get_RTS_Search_Dir
657 (Switch_Chars (Ptr + 1 .. Max),
658 Objects);
660 begin
661 if Src_Path_Name /= null and then
662 Lib_Path_Name /= null
663 then
664 -- Set the RTS_*_Path_Name variables, so that the
665 -- correct directories will be set when a subsequent
666 -- call Osint.Add_Default_Search_Dirs is made.
668 RTS_Src_Path_Name := Src_Path_Name;
669 RTS_Lib_Path_Name := Lib_Path_Name;
671 Ptr := Max + 1;
673 elsif Src_Path_Name = null
674 and then Lib_Path_Name = null
675 then
676 Osint.Fail
677 ("RTS path not valid: missing adainclude and "
678 & "adalib directories");
679 elsif Src_Path_Name = null then
680 Osint.Fail
681 ("RTS path not valid: missing adainclude directory");
682 elsif Lib_Path_Name = null then
683 Osint.Fail
684 ("RTS path not valid: missing adalib directory");
685 end if;
686 end;
687 end if;
689 else
690 Bad_Switch (Switch_Chars);
691 end if;
693 -- Anything else is an error (illegal switch character)
695 when others =>
696 Bad_Switch (Switch_Chars);
697 end case;
699 if Ptr <= Max then
700 Bad_Switch (Switch_Chars);
701 end if;
702 end Check_Switch;
703 end Scan_Binder_Switches;
705 end Switch.B;