Remove the one-definition-rule version of extern_weak
[oota-llvm.git] / utils / llvm.grm
1 (*
2
3 polygen grammar for LLVM assembly language.
4
5 This file defines an LLVM assembly language grammar for polygen,
6 which is a tool for generating random text based on a grammar.
7 It is strictly syntax-based, and makes no attempt to generate
8 IR that is semantically valid. Most of the IR produced doesn't
9 pass the Verifier.
10
11 *)
12
13 I ::=   "title:    LLVM assembly language\n"
14       ^ "status:   experimental\n"
15       ^ "audience: LLVM developers\n"
16 ;
17
18 S ::= Module ;
19
20 (*
21 Define rules for non-keyword tokens. This is currently just a bunch
22 of hacks. They don't cover many valid forms of tokens, and they also
23 generate some invalid forms of tokens. The LLVM parser has custom
24 C++ code to lex these; custom C++ code for emitting them would be
25 convenient, but polygen doesn't support that.
26 *)
27 NonZeroDecimalDigit ::=     1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
28 DecimalDigit        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
29 DecimalDigitSeq     ::= DecimalDigit [^ DecimalDigitSeq ];
30 HexDigit            ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
31                       | a | b | c | d | e | f ;
32 HexDigitSeq         ::= HexDigit [^ HexDigitSeq ];
33 StringChar          ::= a | b | c | d | e | f | g | h | i | j | k | l | m
34                       | n | o | p | q | r | s | t | u | v | w | x | y | z ;
35 StringConstantSeq   ::= StringChar [^ StringConstantSeq ];
36 StringConstant      ::= StringChar [^ StringConstantSeq ];
37 EUINT64VAL          ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];
38 ESINT64VAL          ::= [ "-" ] ^ EUINT64VAL ;
39 EUAPINTVAL          ::= EUINT64VAL ;
40 ESAPINTVAL          ::= ESINT64VAL ;
41 LOCALVALID          ::= "%" ^ DecimalDigitSeq ;
42 GLOBALVALID         ::= "@" ^ DecimalDigitSeq ;
43 INTTYPE             ::= "i" ^ EUINT64VAL ;
44 GLOBALVAR           ::= "@" ^ StringConstant ;
45 LOCALVAR            ::= "%" ^ StringConstant ;
46 STRINGCONSTANT      ::= "\"" ^ StringConstant ^ "\"" ;
47 ATSTRINGCONSTANT    ::= "@" ^ STRINGCONSTANT ;
48 PCTSTRINGCONSTANT   ::= "%" ^ STRINGCONSTANT ;
49 LABELSTR            ::= StringConstant ;
50 FPVAL               ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;
51
52 (*
53 The rest of this file is derived directly from llvmAsmParser.y.
54 *)
55
56 ArithmeticOps ::= add | sub | mul | udiv | sdiv | fdiv | urem | srem | frem ;
57 LogicalOps    ::= shl | lshr | ashr | and | or | xor;
58 CastOps       ::= trunc | zext | sext | fptrunc | fpext | bitcast |
59                   uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
60
61 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
62
63 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
64               | ult | ugt | ule | uge | true | false ;
65
66 IntType ::= INTTYPE;
67 FPType  ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
68
69 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
70 OptLocalName ::= LocalName | _ ;
71
72 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
73
74 OptLocalAssign ::= LocalName "=" | _ ;
75
76 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
77
78 OptGlobalAssign ::= GlobalAssign | _ ;
79
80 GlobalAssign ::= GlobalName "=" ;
81
82 GVInternalLinkage
83   ::= + internal
84  | weak
85  | "weak_odr"
86  | linkonce
87  | "linkonce_odr"
88  | appending
89  | dllexport
90  | common
91  | "common_odr"
92  ;
93
94 GVExternalLinkage
95   ::= dllimport
96  | "extern_weak"
97  | + external
98  ;
99
100 GVVisibilityStyle
101   ::= + _
102  | default
103  | hidden
104  | protected
105  ;
106
107 FunctionDeclareLinkage
108   ::= + _
109  | dllimport
110  | "extern_weak"
111  ;
112
113 FunctionDefineLinkage
114   ::= + _
115  | internal
116  | linkonce
117  | "linkonce_odr"
118  | weak
119  | "weak_odr"
120  | dllexport
121  ;
122
123 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
124
125 OptCallingConv ::= + _ |
126                  ccc |
127                  fastcc |
128                  coldcc |
129                  "x86_stdcallcc" |
130                  "x86_fastcallcc" |
131                  cc EUINT64VAL ;
132
133 ParamAttr ::= zeroext
134  | zext
135  | signext
136  | sext
137  | inreg
138  | sret
139  | noalias
140  | nocapture
141  | byval
142  | nest
143  | align EUINT64VAL
144  ;
145
146 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
147
148 RetAttr       ::= inreg
149               | zeroext
150               | signext
151               | noalias
152               ;
153
154 OptRetAttrs  ::= _
155              | OptRetAttrs RetAttr
156              ;
157
158 FuncAttr      ::= noreturn
159  | nounwind
160  | inreg
161  | zeroext
162  | signext
163  | readnone
164  | readonly
165  | noinline
166  | alwaysinline
167  | optsize
168  | ssp
169  | sspreq
170  ;
171
172 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
173
174 OptGC         ::= + _ | gc STRINGCONSTANT ;
175
176 OptAlign      ::= + _ | align EUINT64VAL ;
177 OptCAlign     ::= + _ | ^ "," align EUINT64VAL ;
178
179 SectionString ::= section STRINGCONSTANT ;
180
181 OptSection    ::= + _ | SectionString ;
182
183 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
184 GlobalVarAttribute  ::= SectionString | align EUINT64VAL ;
185
186 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
187           | - label ;
188
189 Types
190   ::= opaque
191  | PrimType
192  | Types OptAddrSpace ^ "*"
193  | SymbolicValueRef
194  | "\\" ^ EUINT64VAL
195  | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
196  | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
197  | "[" ^ EUINT64VAL "x" Types ^ "]"
198  | "<" ^ EUINT64VAL "x" Types ^ ">"
199  | "{" TypeListI "}"
200  | "{" ^ "}"
201  | "<" ^ "{" TypeListI "}" ^ ">"
202  | "<" ^ "{" ^ "}" ^ ">"
203  ;
204
205 ArgType ::= Types OptParamAttrs ;
206
207 ResultTypes ::= Types | void ;
208
209 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
210
211 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
212
213 TypeListI ::= Types | TypeListI ^ "," Types ;
214
215 ConstVal::= Types "[" ^ ConstVector ^ "]"
216  | Types "[" ^ "]"
217  | Types "c" ^ STRINGCONSTANT
218  | Types "<" ^ ConstVector ^ ">"
219  | Types "{" ConstVector "}"
220  | Types "{" ^ "}"
221  | Types "<" ^ "{" ConstVector "}" ^ ">"
222  | Types "<" ^ "{" ^ "}" ^ ">"
223  | Types null
224  | Types undef
225  | Types SymbolicValueRef
226  | Types ConstExpr
227  | Types zeroinitializer
228  | Types ESINT64VAL
229  | Types ESAPINTVAL
230  | Types EUINT64VAL
231  | Types EUAPINTVAL
232  | Types true
233  | Types false
234  | Types FPVAL ;
235
236 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
237  | getelementptr "(" ^ ConstVal IndexList ^ ")"
238  | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
239  | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
240  | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
241  | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
242  | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
243  | vicmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
244  | vfcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
245  | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
246  | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
247  | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
248  | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
249  | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
250
251 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
252
253 GlobalType ::= global | constant ;
254
255 ThreadLocal ::= - "thread_local" | _ ;
256
257 AliaseeRef ::= ResultTypes SymbolicValueRef
258  | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
259
260 Module ::= +++ DefinitionList | --- _ ;
261
262 DefinitionList ::= - Definition | + DefinitionList Definition ;
263
264 Definition
265   ::= ^ ( +++++ define Function
266  | declare FunctionProto
267  | - module asm AsmBlock
268  | OptLocalAssign type Types
269  | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
270    ConstVal GlobalVarAttributes
271  | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
272    GlobalType ConstVal GlobalVarAttributes
273  | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
274    GlobalType Types GlobalVarAttributes
275  | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
276  | target TargetDefinition
277  | deplibs "=" LibrariesDefinition
278  ) ^ "\n";
279
280 AsmBlock ::= STRINGCONSTANT ;
281
282 TargetDefinition ::= triple "=" STRINGCONSTANT
283  | datalayout "=" STRINGCONSTANT ;
284
285 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
286
287 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
288
289 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
290  | Types OptParamAttrs OptLocalName ;
291
292 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
293
294 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
295                   GlobalName ^ "(" ^ ArgList ^ ")"
296                   OptFuncAttrs OptSection OptAlign OptGC ;
297
298 BEGIN ::= ( begin | "{" ) ^ "\n";
299
300 FunctionHeader ::=
301   FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
302
303 END ::= ^ ( end | "}" ) ^ "\n";
304
305 Function ::= BasicBlockList END ;
306
307 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
308
309 OptSideEffect ::= _ | sideeffect ;
310
311 ConstValueRef ::= ESINT64VAL
312  | EUINT64VAL
313  | FPVAL
314  | true
315  | false
316  | null
317  | undef
318  | zeroinitializer
319  | "<" ConstVector ">"
320  | "[" ConstVector "]"
321  | "[" ^ "]"
322  | "c" ^ STRINGCONSTANT
323  | "{" ConstVector "}"
324  | "{" ^ "}"
325  | "<" ^ "{" ConstVector "}" ^ ">"
326  | "<" ^ "{" ^ "}" ^ ">"
327  | ConstExpr
328  | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
329
330 SymbolicValueRef ::= LOCALVALID
331  | GLOBALVALID
332  | LocalName
333  | GlobalName ;
334
335 ValueRef ::= SymbolicValueRef | ConstValueRef;
336
337 ResolvedVal ::= Types ValueRef ;
338
339 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
340
341 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
342
343 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
344
345 InstructionList ::= +++ InstructionList Inst
346  | - _
347  | ^ LABELSTR ^ ":\n" ;
348
349 BBTerminatorInst ::= ^ "  " ^
350  ( ret ReturnedVal
351  | ret void
352  | br label ValueRef
353  | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
354  | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
355  | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
356  | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
357    OptFuncAttrs
358    to label ValueRef unwind label ValueRef
359  | unwind
360  | unreachable ) ^ "\n";
361
362 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
363  | IntType ConstValueRef ^ "," label ValueRef ;
364
365 Inst ::= ^ "  " ^ OptLocalAssign InstVal ^ "\n";
366
367 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
368  | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
369
370 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
371  | label OptParamAttrs ValueRef OptParamAttrs
372  | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
373  | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
374  | - _ ;
375
376 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
377
378 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
379
380 OptTailCall ::= tail call | call ;
381
382 InstVal ::=
383    ArithmeticOps Types ValueRef ^ "," ValueRef
384  | LogicalOps Types ValueRef ^ "," ValueRef
385  | icmp IPredicates Types ValueRef ^ "," ValueRef
386  | fcmp FPredicates Types ValueRef ^ "," ValueRef
387  | vicmp IPredicates Types ValueRef ^ "," ValueRef
388  | vfcmp FPredicates Types ValueRef ^ "," ValueRef
389  | CastOps ResolvedVal to Types
390  | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
391  | "va_arg" ResolvedVal ^ "," Types
392  | extractelement ResolvedVal ^ "," ResolvedVal
393  | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
394  | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
395  | phi PHIList
396  | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
397    OptFuncAttrs
398  | MemoryInst ;
399
400 OptVolatile ::= - volatile | _ ;
401
402 MemoryInst ::= malloc Types OptCAlign
403  | malloc Types ^ "," INTTYPE ValueRef OptCAlign
404  | alloca Types OptCAlign
405  | alloca Types ^ "," INTTYPE ValueRef OptCAlign
406  | free ResolvedVal
407  | OptVolatile load Types ValueRef OptCAlign
408  | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
409  | getresult Types ValueRef ^ "," EUINT64VAL
410  | getelementptr Types ValueRef IndexList
411  | extractvalue Types ValueRef ^ ConstantIndexList 
412  | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;