1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 */
6 module llvm_hiwrap.value.constant;
7 
8 import llvm_hiwrap.types;
9 
10 struct ConstantValue {
11     import llvm;
12 
13     LxConstantValue value;
14     alias value this;
15 
16     /**
17      * This section contains APIs for interacting with LLVMValueRef that
18      * correspond to llvm::Constant instances.
19      *
20      * These functions will work for any LLVMValueRef in the llvm::Constant
21      * class hierarchy.
22      *
23      * @{
24      */
25 
26     /**
27      * Obtain a constant value referring to the null instance of a type.
28      *
29      * @see llvm::Constant::getNullValue()
30      */
31     //LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
32 
33     /**
34      * Obtain a constant value referring to the instance of a type
35      * consisting of all ones.
36      *
37      * This is only valid for integer types.
38      *
39      * @see llvm::Constant::getAllOnesValue()
40      */
41     //LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
42 
43     /**
44      * Obtain a constant value referring to an undefined value of a type.
45      *
46      * @see llvm::UndefValue::get()
47      */
48     //LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
49 
50     /**
51      * Determine whether a value instance is null.
52      *
53      * @see llvm::Constant::isNullValue()
54      */
55     //LLVMBool LLVMIsNull(LLVMValueRef Val);
56 
57     /**
58      * Obtain a constant that is a constant pointer pointing to NULL for a
59      * specified type.
60      */
61     //LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
62 }
63 
64 struct ScalarConstantValue {
65     import llvm;
66 
67     LxScalarConstantValue value;
68     alias value this;
69 
70     /**
71      * @defgroup LLVMCCoreValueConstantScalar Scalar constants
72      *
73      * Functions in this group model LLVMValueRef instances that correspond
74      * to constants referring to scalar types.
75      *
76      * For integer types, the LLVMTypeRef parameter should correspond to a
77      * llvm::IntegerType instance and the returned LLVMValueRef will
78      * correspond to a llvm::ConstantInt.
79      *
80      * For floating point types, the LLVMTypeRef returned corresponds to a
81      * llvm::ConstantFP.
82      *
83      * @{
84      */
85 
86     /**
87      * Obtain a constant value for an integer type.
88      *
89      * The returned value corresponds to a llvm::ConstantInt.
90      *
91      * @see llvm::ConstantInt::get()
92      *
93      * @param IntTy Integer type to obtain value of.
94      * @param N The value the returned instance should refer to.
95      * @param SignExtend Whether to sign extend the produced value.
96      */
97     //LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
98     //LLVMBool SignExtend);
99 
100     /**
101      * Obtain a constant value for an integer of arbitrary precision.
102      *
103      * @see llvm::ConstantInt::get()
104      */
105     //LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
106     //unsigned NumWords,
107     //const uint64_t Words[]);
108 
109     /**
110      * Obtain a constant value for an integer parsed from a string.
111      *
112      * A similar API, LLVMConstIntOfStringAndSize is also available. If the
113      * string's length is available, it is preferred to call that function
114      * instead.
115      *
116      * @see llvm::ConstantInt::get()
117      */
118     //LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
119     //                                  uint8_t Radix);
120 
121     /**
122      * Obtain a constant value for an integer parsed from a string with
123      * specified length.
124      *
125      * @see llvm::ConstantInt::get()
126      */
127     //LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
128     //unsigned SLen, uint8_t Radix);
129 
130     /**
131      * Obtain a constant value referring to a double floating point value.
132      */
133     //LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
134 
135     /**
136      * Obtain a constant for a floating point value parsed from a string.
137      *
138      * A similar API, LLVMConstRealOfStringAndSize is also available. It
139      * should be used if the input string's length is known.
140      */
141     //LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
142 
143     /**
144      * Obtain a constant for a floating point value parsed from a string.
145      */
146     //LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
147     //unsigned SLen);
148 
149     /**
150      * Obtain the zero extended value for an integer constant value.
151      *
152      * @see llvm::ConstantInt::getZExtValue()
153      */
154     //unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
155 
156     /**
157      * Obtain the sign extended value for an integer constant value.
158      *
159      * @see llvm::ConstantInt::getSExtValue()
160      */
161     //long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
162 
163     /**
164      * Obtain the double value for an floating point constant value.
165      * losesInfo indicates if some precision was lost in the conversion.
166      *
167      * @see llvm::ConstantFP::getDoubleValue
168      */
169     //double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
170 }
171 
172 struct CompositeConstantValue {
173     LxCompositeConstantValue value;
174     alias value this;
175 
176     /**
177      * @defgroup LLVMCCoreValueConstantComposite Composite Constants
178      *
179      * Functions in this group operate on composite constants.
180      *
181      * @{
182      */
183 
184     /**
185      * Create a ConstantDataSequential and initialize it with a string.
186      *
187      * @see llvm::ConstantDataArray::getString()
188      */
189     //LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
190     //                                      unsigned Length, LLVMBool DontNullTerminate);
191 
192     /**
193      * Create a ConstantDataSequential with string content in the global context.
194      *
195      * This is the same as LLVMConstStringInContext except it operates on the
196      * global context.
197      *
198      * @see LLVMConstStringInContext()
199      * @see llvm::ConstantDataArray::getString()
200      */
201     //LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
202     //                             LLVMBool DontNullTerminate);
203 
204     /**
205      * Returns true if the specified constant is an array of i8.
206      *
207      * @see ConstantDataSequential::getAsString()
208      */
209     //LLVMBool LLVMIsConstantString(LLVMValueRef c);
210 
211     /**
212      * Get the given constant data sequential as a string.
213      *
214      * @see ConstantDataSequential::getAsString()
215      */
216     //const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
217 
218     /**
219      * Create an anonymous ConstantStruct with the specified values.
220      *
221      * @see llvm::ConstantStruct::getAnon()
222      */
223     //LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
224     //                                      LLVMValueRef *ConstantVals,
225     //                                      unsigned Count, LLVMBool Packed);
226 
227     /**
228      * Create a ConstantStruct in the global Context.
229      *
230      * This is the same as LLVMConstStructInContext except it operates on the
231      * global Context.
232      *
233      * @see LLVMConstStructInContext()
234      */
235     //LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
236     //                             LLVMBool Packed);
237 
238     /**
239      * Create a ConstantArray from values.
240      *
241      * @see llvm::ConstantArray::get()
242      */
243     //LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
244     //                            LLVMValueRef *ConstantVals, unsigned Length);
245 
246     /**
247      * Create a non-anonymous ConstantStruct from values.
248      *
249      * @see llvm::ConstantStruct::get()
250      */
251     //LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
252     //                                  LLVMValueRef *ConstantVals,
253     //                                  unsigned Count);
254 
255     /**
256      * Get an element at specified index as a constant.
257      *
258      * @see ConstantDataSequential::getElementAsConstant()
259      */
260     //LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
261 
262     /**
263      * Create a ConstantVector from values.
264      *
265      * @see llvm::ConstantVector::get()
266      */
267     //LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
268 }
269 
270 struct LxConstantExpressionValue {
271     /**
272      * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
273      *
274      * Functions in this group correspond to APIs on llvm::ConstantExpr.
275      *
276      * @see llvm::ConstantExpr.
277      *
278      * @{
279      */
280     //LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
281     //LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
282     //LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
283     //LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
284     //LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
285     //LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
286     //LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
287     //LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
288     //LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
289     //LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
290     //LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
291     //LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
292     //LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
293     //LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
294     //LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
295     //LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
296     //LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
297     //LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
298     //LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
299     //LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
300     //LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
301     //LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
302     //LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
303     //LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
304     //LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
305     //LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
306     //LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
307     //LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
308     //LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
309     //LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
310     //LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
311     //LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
312     //                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
313     //LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
314     //                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
315     //LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
316     //LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
317     //LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
318     //LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
319     //                          LLVMValueRef *ConstantIndices, unsigned NumIndices);
320     //LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
321     //                                  LLVMValueRef *ConstantIndices,
322     //                                  unsigned NumIndices);
323     //LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
324     //LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
325     //LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
326     //LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
327     //LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
328     //LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
329     //LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
330     //LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
331     //LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
332     //LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
333     //LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
334     //LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
335     //LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
336     //LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
337     //                                    LLVMTypeRef ToType);
338     //LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
339     //                                    LLVMTypeRef ToType);
340     //LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
341     //                                     LLVMTypeRef ToType);
342     //LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
343     //                                  LLVMTypeRef ToType);
344     //LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
345     //                              LLVMBool isSigned);
346     //LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
347     //LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
348     //                             LLVMValueRef ConstantIfTrue,
349     //                             LLVMValueRef ConstantIfFalse);
350     //LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
351     //                                     LLVMValueRef IndexConstant);
352     //LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
353     //                                    LLVMValueRef ElementValueConstant,
354     //                                    LLVMValueRef IndexConstant);
355     //LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
356     //                                    LLVMValueRef VectorBConstant,
357     //                                    LLVMValueRef MaskConstant);
358     //LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
359     //                                   unsigned NumIdx);
360     //LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
361     //                                  LLVMValueRef ElementValueConstant,
362     //                                  unsigned *IdxList, unsigned NumIdx);
363     //LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
364     //                                const char *AsmString, const char *Constraints,
365     //                                LLVMBool HasSideEffects, LLVMBool IsAlignStack);
366     //LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
367 }