| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- B A C K E N D _ U T I L S -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2021-2025, 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 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Lib; |
| 27 |
with Opt; use Opt; |
| 28 |
with Switch; use Switch; |
| 29 |
|
| 30 |
package body Backend_Utils is |
| 31 |
|
| 32 |
--------------------------------- |
| 33 |
-- Scan_Common_Back_End_Switch -- |
| 34 |
--------------------------------- |
| 35 |
|
| 36 |
function Scan_Common_Back_End_Switch (Switch_Chars : String) return Boolean |
| 37 |
is |
| 38 |
First : constant Positive := Switch_Chars'First + 1; |
| 39 |
Last : constant Natural := Switch_Last (Switch_Chars); |
| 40 |
begin |
| 41 |
-- Recognize -gxxx switches |
| 42 |
|
| 43 |
if Switch_Chars (First) = 'g' then |
| 44 |
Debugger_Level := 2; |
| 45 |
|
| 46 |
if First < Last then |
| 47 |
case Switch_Chars (First + 1) is |
| 48 |
when '0' => |
| 49 |
Debugger_Level := 0; |
| 50 |
when '1' => |
| 51 |
Debugger_Level := 1; |
| 52 |
when '2' => |
| 53 |
Debugger_Level := 2; |
| 54 |
when '3' => |
| 55 |
Debugger_Level := 3; |
| 56 |
when others => |
| 57 |
null; |
| 58 |
end case; |
| 59 |
end if; |
| 60 |
|
| 61 |
-- Back end switch -fdiagnostics-format=json tells the frontend to |
| 62 |
-- output its error and warning messages in the same format GCC |
| 63 |
-- uses when passed -fdiagnostics-format=json. |
| 64 |
|
| 65 |
elsif Switch_Chars (First .. Last) = "fdiagnostics-format=json" then |
| 66 |
Opt.JSON_Output := True; |
| 67 |
|
| 68 |
-- Back end switch -fdiagnostics-format=sarif-file tells the frontend |
| 69 |
-- to output its error and warning messages in the sarif format. The |
| 70 |
-- messages from gnat are written to a file <source_file>.gnat.sarif. |
| 71 |
|
| 72 |
elsif Switch_Chars (First .. Last) = "fdiagnostics-format=sarif-file" |
| 73 |
then |
| 74 |
Opt.SARIF_File := True; |
| 75 |
|
| 76 |
-- Back end switch -fdiagnostics-format=sarif-stderr tells the frontend |
| 77 |
-- to output its error and warning messages in the sarif format. |
| 78 |
|
| 79 |
elsif Switch_Chars (First .. Last) = "fdiagnostics-format=sarif-stderr" |
| 80 |
then |
| 81 |
Opt.SARIF_Output := True; |
| 82 |
|
| 83 |
-- Back-end switch -fno-inline also sets the front end flags to entirely |
| 84 |
-- inhibit all inlining. So we store it and set the appropriate |
| 85 |
-- flags. |
| 86 |
-- For gcc back ends, -fno-inline disables Inline pragmas only, |
| 87 |
-- not Inline_Always to remain consistent with the always_inline |
| 88 |
-- attribute behavior. |
| 89 |
|
| 90 |
elsif Switch_Chars (First .. Last) = "fno-inline" then |
| 91 |
Opt.Disable_FE_Inline := True; |
| 92 |
|
| 93 |
-- Back end switch -fpreserve-control-flow also sets the front end |
| 94 |
-- flag that inhibits improper control flow transformations. |
| 95 |
|
| 96 |
elsif Switch_Chars (First .. Last) = "fpreserve-control-flow" then |
| 97 |
Opt.Suppress_Control_Flow_Optimizations := True; |
| 98 |
|
| 99 |
elsif Switch_Chars (First .. Last) = "S" then |
| 100 |
Generate_Asm := True; |
| 101 |
|
| 102 |
else |
| 103 |
return False; |
| 104 |
end if; |
| 105 |
|
| 106 |
Lib.Store_Compilation_Switch (Switch_Chars); |
| 107 |
return True; |
| 108 |
end Scan_Common_Back_End_Switch; |
| 109 |
|
| 110 |
end Backend_Utils; |