aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/llvm4-nodebug/llvm-targetmachine.ads
blob: e753acf1dacf8bd7ff11e781e8cceffbe6437a6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--  LLVM binding
--  Copyright (C) 2014 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
--  WARRANTY; without even the implied warranty of MERCHANTABILITY or
--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GHDL; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.
with System;
with LLVM.Core; use LLVM.Core;
with LLVM.Target; use LLVM.Target;

package LLVM.TargetMachine is

   type TargetMachineRef is new System.Address;
   Null_TargetMachineRef : constant TargetMachineRef :=
     TargetMachineRef (System.Null_Address);

   type TargetRef is new System.Address;
   Null_TargetRef : constant TargetRef := TargetRef (System.Null_Address);

   type CodeGenOptLevel is (CodeGenLevelNone,
                            CodeGenLevelLess,
                            CodeGenLevelDefault,
                            CodeGenLevelAggressive);
   pragma Convention (C, CodeGenOptLevel);

   type RelocMode is (RelocDefault,
                      RelocStatic,
                      RelocPIC,
                      RelocDynamicNoPic);
   pragma Convention (C, RelocMode);

   type CodeModel is (CodeModelDefault,
                      CodeModelJITDefault,
                      CodeModelSmall,
                      CodeModelKernel,
                      CodeModelMedium,
                      CodeModelLarge);
   pragma Convention (C, CodeModel);

   type CodeGenFileType is (AssemblyFile,
                            ObjectFile);
   pragma Convention (C, CodeGenFileType);

   --  Returns the first llvm::Target in the registered targets list.
   function GetFirstTarget return TargetRef;
   pragma Import (C, GetFirstTarget, "LLVMGetFirstTarget");

   --  Returns the next llvm::Target given a previous one (or null if there's
   --  none) */
   function GetNextTarget(T : TargetRef) return TargetRef;
   pragma Import (C, GetNextTarget, "LLVMGetNextTarget");

   --  Target

   --  Finds the target corresponding to the given name and stores it in T.
   --  Returns 0 on success.
   function GetTargetFromName (Name : Cstring) return TargetRef;
   pragma Import (C, GetTargetFromName, "LLVMGetTargetFromName");

   --  Finds the target corresponding to the given triple and stores it in T.
   --  Returns 0 on success. Optionally returns any error in ErrorMessage.
   --  Use LLVMDisposeMessage to dispose the message.
   --  Ada: ErrorMessage is the address of a Cstring.
   function GetTargetFromTriple
     (Triple : Cstring; T : access TargetRef; ErrorMessage : access Cstring)
     return Bool;
   pragma Import (C, GetTargetFromTriple, "LLVMGetTargetFromTriple");

   --  Returns the name of a target. See llvm::Target::getName
   function GetTargetName (T: TargetRef) return Cstring;
   pragma Import (C, GetTargetName, "LLVMGetTargetName");

   --  Returns the description  of a target. See llvm::Target::getDescription
   function GetTargetDescription (T : TargetRef) return Cstring;
   pragma Import (C, GetTargetDescription, "LLVMGetTargetDescription");

   --  Target Machine ----------------------------------------------------

   --  Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine

   function CreateTargetMachine(T : TargetRef;
                                Triple : Cstring;
                                CPU : Cstring;
                                Features : Cstring;
                                Level : CodeGenOptLevel;
                                Reloc : RelocMode;
                                CM : CodeModel)
                               return TargetMachineRef;
   pragma Import (C, CreateTargetMachine, "LLVMCreateTargetMachine");

   --  Create a DataLayout based on the targetMachine.
   function CreateTargetDataLayout (T : TargetMachineRef) return TargetDataRef;
   pragma Import (C, CreateTargetDataLayout, "LLVMCreateTargetDataLayout");

   -- Returns the llvm::DataLayout used for this llvm:TargetMachine.
   function GetTargetMachineData(T : TargetMachineRef) return TargetDataRef;
   pragma Import (C, GetTargetMachineData, "LLVMGetTargetMachineData");

   --  Emits an asm or object file for the given module to the filename. This
   --  wraps several c++ only classes (among them a file stream). Returns any
   --  error in ErrorMessage. Use LLVMDisposeMessage to dispose the message.
   function TargetMachineEmitToFile(T : TargetMachineRef;
                                    M : ModuleRef;
                                    Filename : Cstring;
                                    Codegen : CodeGenFileType;
                                    ErrorMessage : access Cstring)
                                   return Bool;
   pragma Import (C, TargetMachineEmitToFile,
                  "LLVMTargetMachineEmitToFile");

   --  Get a triple for the host machine as a string. The result needs to be
   --  disposed with LLVMDisposeMessage.
   function GetDefaultTargetTriple return Cstring;
   pragma Import (C, GetDefaultTargetTriple, "LLVMGetDefaultTargetTriple");
end LLVM.TargetMachine;