~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to Puma/src/aspects/ExtGnu.ah

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-06-15 10:17:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090615101702-qsr30iptwbxylmo2
Tags: 1.0pre4~svn.20090615-1
* New upstream release.
* don't ignore errors in the postrm script
* avoid spurious creation of empty dir ./usr/sbin/
* improve short descriptions of libpuma-doc and libpuma-dev
* bump Standards-Version to 3.8.1
* bump debhelper compat level to level 7 (latest in stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// This file is part of PUMA.
2
2
// Copyright (C) 1999-2003  The PUMA developer team.
3
 
//                                                                
4
 
// This program is free software;  you can redistribute it and/or 
5
 
// modify it under the terms of the GNU General Public License as 
6
 
// published by the Free Software Foundation; either version 2 of 
7
 
// the License, or (at your option) any later version.            
8
 
//                                                                
 
3
//
 
4
// This program is free software;  you can redistribute it and/or
 
5
// modify it under the terms of the GNU General Public License as
 
6
// published by the Free Software Foundation; either version 2 of
 
7
// the License, or (at your option) any later version.
 
8
//
9
9
// This program is distributed in the hope that it will be useful,
10
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
11
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
12
 
// GNU General Public License for more details.                   
13
 
//                                                                
14
 
// You should have received a copy of the GNU General Public      
15
 
// License along with this program; if not, write to the Free     
16
 
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
17
 
// MA  02111-1307  USA                                            
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
//
 
14
// You should have received a copy of the GNU General Public
 
15
// License along with this program; if not, write to the Free
 
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
17
// MA  02111-1307  USA
18
18
 
19
19
#ifndef __ext_gnu_h__
20
20
#define __ext_gnu_h__
25
25
#include "Puma/CStructure.h"
26
26
#include "Puma/CSemVisitor.h"
27
27
#include "Puma/CSemDeclSpecs.h"
 
28
#include "Puma/PreMacro.h"
 
29
#include "Puma/PreMacroManager.h"
28
30
#include "Puma/Config.h"
29
31
 
30
32
#include "ExtGnuCSemDeclSpecs.ah"
49
51
}
50
52
 
51
53
aspect ExtGnu {
52
 
 
53
54
  // flags to enable/disable certain Gnu features
54
55
  bool extended_asm;
55
56
  bool extended_cv_qual;
58
59
  bool typeof_keyword;
59
60
  bool statement_exprs;
60
61
  bool labels_as_values;
 
62
  bool thread_local_storage_class;
 
63
  bool friend_injection;
 
64
  bool extern_inline;
61
65
 
62
66
  // pointcut definitions
63
67
  pointcut node ()          = "Puma::CT_AsmDef";
68
72
  pointcut csemdeclspecs () = "Puma::CSemDeclSpecs";
69
73
 
70
74
  // ----------------------------------------------------
71
 
  // the Gnu ASM syntax
 
75
  // the GNU ASM syntax
72
76
  // ----------------------------------------------------
73
77
 
74
78
  // structural extensions
94
98
      result = ((JoinPoint::That*)syn)->gnu_asm_spec ();
95
99
  }
96
100
 
97
 
//   // asm declaration specifiers
98
 
//   advice within (derived (syntax ())) &&
99
 
//          execution ("% Puma::%::init_simple_type_spec()") : after () {
100
 
//     if (extended_asm)
101
 
//       tjp->that ()->_simple_type_spec_1.set (Puma::TOK_ASM);
102
 
//   }
103
 
//   advice execution ("% Puma::CSyntax::rule_simple_type_spec()") : after () {
104
 
//     Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
105
 
//     if (extended_asm && !result && tjp->that ()->look_ahead (Puma::TOK_ASM) &&
106
 
//         tjp->that ()->parse (&JoinPoint::That::gnu_asm_spec))
107
 
//       result = tjp->that ()->builder ().gnu_asm_spec ();
108
 
//   }
109
 
//   advice execution ("% Puma::CCSyntax::rule_simple_type_spec()") : after () {
110
 
//     Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
111
 
//     if (extended_asm && !result && tjp->that ()->look_ahead (Puma::TOK_ASM) &&
112
 
//         tjp->that ()->parse (&JoinPoint::That::gnu_asm_spec))
113
 
//       result = tjp->that ()->semantic ().simple_type_spec ();
114
 
//   }
115
 
//   // make the analysis function aware of 'asm(...)'
116
 
//   advice execution("bool Puma::%::analyze(...)") && within (csemdeclspecs ()) &&
117
 
//          args (spec): after (Puma::CTree *spec) {
118
 
//     bool &result = *tjp->result ();
119
 
//     if (!result && spec->NodeName () == Puma::CT_GnuAsmSpec::NodeId ())
120
 
//       result = true;
121
 
//   }
 
101
  // ----------------------------------------------------
 
102
  // redefinition of 'extern inline' functions
 
103
  // ----------------------------------------------------
 
104
 
 
105
  advice execution ("% Puma::CSemantic::isRedefinedFunction(...)") : around () {
 
106
    // if previous function definition is declared 'extern inline'
 
107
    // then it is no error to redefine it
 
108
    Puma::CObjectInfo* fct = *tjp->arg<0>();
 
109
    if (extern_inline && fct->isExtern () && fct->isInline ())
 
110
      *(tjp->result ()) = false;
 
111
    else
 
112
      tjp->proceed ();
 
113
  }
122
114
 
123
115
  // ----------------------------------------------------
124
116
  // the 'restrict' keyword
131
123
  }
132
124
 
133
125
  // -------------------------
134
 
  // Gnu statement expressions 
 
126
  // GNU statement expressions
135
127
  // -------------------------
136
128
 
137
129
  // pointcut definitions
162
154
  }
163
155
 
164
156
  // ----------------------------------------
165
 
  // support for "labels as values" extension 
 
157
  // support for "labels as values" extension
166
158
  // ----------------------------------------
167
159
 
168
160
  // extended goto syntax
169
161
  advice within (derived (syntax ())) &&
170
162
    execution ("% ...::jump_stmt()") : around () {
171
163
    JoinPoint::That *syntax = tjp->that ();
172
 
    if (labels_as_values && 
 
164
    if (labels_as_values &&
173
165
        syntax->look_ahead (Puma::TOK_GOTO) &&
174
166
        syntax->look_ahead (Puma::TOK_MUL, 2)) {
175
167
      syntax->consume (); // skip the 'goto' keyword
183
175
  }
184
176
 
185
177
  // the address of a label
186
 
    advice within (derived (syntax ())) &&
187
 
      execution ("% ...::unary_expr()") : around () {
188
 
      JoinPoint::That *syntax = tjp->that ();
189
 
      if (labels_as_values && 
190
 
          syntax->look_ahead (Puma::TOK_AND_AND)) {
191
 
        syntax->consume (); // consume the '&&' token, already checked
192
 
        Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
193
 
        result = syntax->identifier () ? syntax->builder().unary_expr () : 0;
194
 
      }
195
 
      else
196
 
        tjp->proceed ();
 
178
  advice within (derived (syntax ())) &&
 
179
    execution ("% ...::unary_expr()") : around () {
 
180
    JoinPoint::That *syntax = tjp->that ();
 
181
    if (labels_as_values &&
 
182
        syntax->look_ahead (Puma::TOK_AND_AND)) {
 
183
      syntax->consume (); // consume the '&&' token, already checked
 
184
      Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
185
      result = syntax->identifier () ? syntax->builder().unary_expr () : 0;
197
186
    }
 
187
    else
 
188
      tjp->proceed ();
 
189
  }
198
190
 
199
191
  // extended semantic analysis
200
192
  advice within ("Puma::%CSemVisitor") &&
224
216
        tjp->proceed ();
225
217
  }
226
218
 
 
219
  // ----------------------------------------
 
220
  // Thread-local storage class (TLS) support
 
221
  // ----------------------------------------
 
222
 
 
223
  // extend storage class specifiers
 
224
  advice within (derived (syntax ())) &&
 
225
         execution ("% Puma::%::init_storage_class_spec()") : after () {
 
226
    if (thread_local_storage_class)
 
227
      tjp->that ()->_storage_class_spec_1.set (Puma::TOK_THREAD);
 
228
  }
 
229
 
227
230
  // ----------------------
228
231
  // TYPEOF keyword support
229
232
  // ----------------------
268
271
         that (csd) && args (spec): after (Puma::CSemDeclSpecs &csd, Puma::CTree *spec) {
269
272
    bool &result = *tjp->result ();
270
273
    if (!result && spec->NodeName () == Puma::CT_GnuTypeof::NodeId ()) {
271
 
      csd._typeofs++;      
 
274
      csd._typeofs++;
272
275
      csd._typeof_node = (Puma::CT_GnuTypeof*)spec;
273
276
      result = true;
274
277
    }
275
278
  }
276
 
  
 
279
 
277
280
  // make the check functions aware of 'typeof'
278
281
  advice execution("bool Puma::%::check_complex_decl_specs(...)") &&
279
282
         within (csemdeclspecs ()) && that (csd) && args (have_type):
284
287
      result    = true;
285
288
    }
286
289
  }
287
 
  
 
290
 
288
291
  advice execution("bool Puma::%::check_signed_unsigned()") &&
289
292
         within (csemdeclspecs ()) && that (csd) : after (Puma::CSemDeclSpecs &csd) {
290
293
    bool &result = *tjp->result ();
291
294
    if (result) {
292
 
      if ((csd._prim_map[Puma::CT_PrimDeclSpec::PDS_SIGNED] || 
 
295
      if ((csd._prim_map[Puma::CT_PrimDeclSpec::PDS_SIGNED] ||
293
296
           csd._prim_map[Puma::CT_PrimDeclSpec::PDS_UNSIGNED]) &&
294
297
          csd._typeofs) {
295
 
        *csd._err << Puma::sev_error << csd._dss->token ()->location () 
 
298
        *csd._err << Puma::sev_error << csd._dss->token ()->location ()
296
299
                  << "`signed' or `unsigned' invalid for 'typeof'"
297
300
                  << Puma::endMessage;
298
301
        result = false;
304
307
         within (csemdeclspecs ()) && that (csd) : after (Puma::CSemDeclSpecs &csd) {
305
308
    bool &result = *tjp->result ();
306
309
    if (result && csd._typeofs > 0) {
307
 
      *csd._err << Puma::sev_error << csd._dss->token ()->location () 
 
310
      *csd._err << Puma::sev_error << csd._dss->token ()->location ()
308
311
                << "invalid type specified in declaration"
309
312
                << Puma::endMessage;
310
313
      result = false;
322
325
      }
323
326
    }
324
327
  }
325
 
  
 
328
 
326
329
  // ----------------------
327
 
  // Gnu builtin functions
 
330
  // GNU builtin functions
328
331
  // ----------------------
329
332
 
330
333
  // structural extensions
340
343
  // std hack: if a lookup in 'std' fails, look into '::'
341
344
  // ----------------------------------------------------
342
345
 
343
 
  advice execution ("% Puma::CCNameLookup::lookup(%::CStructure *,bool,bool)") : 
 
346
  advice execution ("% Puma::CCNameLookup::lookup(%::CStructure *,bool,bool)") :
344
347
  before () {
345
348
    if (std_hack) {
346
349
      Puma::CStructure *&scope = *(Puma::CStructure**)tjp->arg (0);
350
353
        nested = true;
351
354
    }
352
355
  }
353
 
  
 
356
 
 
357
  // ----------------------------------------------------
 
358
  // friend injection of GCC before version 4.1
 
359
  // ----------------------------------------------------
 
360
 
 
361
  advice execution ("% Puma::CCNameLookup::invisibleFriend(...)") : around () {
 
362
    if (friend_injection)
 
363
      *tjp->result () = false;  // friends are always visible
 
364
    else
 
365
      tjp->proceed ();
 
366
  }
 
367
 
 
368
  // ----------------------------------------------------
354
369
  // get the configuration and check whether the GNU mode is enabled
355
 
  advice args (config) && within (derived ("Puma::Syntax")) && 
 
370
  // ----------------------------------------------------
 
371
 
 
372
  bool get_gnu_version (const Puma::Config &config,
 
373
    int &major, int &minor, int &patchlevel) {
 
374
    const Puma::ConfOption *gnu_option = config.Option ("--gnu");
 
375
    if (!gnu_option)
 
376
      return false;
 
377
    major = -1;
 
378
    minor = -1;
 
379
    patchlevel = -1;
 
380
    const char *gnu_version_str =
 
381
      (gnu_option->Arguments() == 1) ? gnu_option->Argument (0) : 0;
 
382
    if (gnu_version_str) {
 
383
      char sep;
 
384
      istringstream in (gnu_version_str);
 
385
      if (in.good()) in >> major;
 
386
      if (in.good()) in >> sep >> minor;
 
387
      if (in.good()) in >> sep >> patchlevel;
 
388
    }
 
389
    return true;
 
390
  }
 
391
 
 
392
  advice args (config) &&
 
393
         execution("void Puma::CScanner::configure (...)"):
 
394
  after (const Puma::Config &config) {
 
395
    int gnu_major, gnu_minor, gnu_patchlevel;
 
396
    // call get_gnu_version to check whether --gnu was given
 
397
    if (get_gnu_version (config, gnu_major, gnu_minor, gnu_patchlevel)) {
 
398
      if (gnu_major == -1 || (gnu_major >= 4 && gnu_minor >= 3)) {
 
399
        // set the builtin type traits option (implemented by g++ >= 4.3)
 
400
        tjp->that()->allow_type_traits (true);
 
401
      }
 
402
    }
 
403
  }
 
404
 
 
405
  advice args (config) && within (derived ("Puma::Syntax")) &&
356
406
         execution ("void Puma::%::configure(...)"): before (Puma::Config &config) {
357
 
    if (config.Option ("--gnu") || config.Option ("--gnu-2.95")) {
 
407
    int gnu_major, gnu_minor, gnu_patchlevel;
 
408
    // call get_gnu_version to check whether --gnu was given
 
409
    if (get_gnu_version (config, gnu_major, gnu_minor, gnu_patchlevel)) {
 
410
      // settings for all gcc dialects
358
411
      extended_asm     = true;
359
412
      extended_cv_qual = true;
360
413
      gnu_builtins     = true;
361
414
      typeof_keyword   = true;
362
415
      statement_exprs  = true;
363
416
      labels_as_values = true;
 
417
      extern_inline    = true;
 
418
      thread_local_storage_class = true;
 
419
 
 
420
      if (gnu_major >= 0 && gnu_major < 3) {
 
421
        std_hack         = true;
 
422
        friend_injection = true;
 
423
      }
364
424
    }
 
425
    // these options can be explicitely set even without --gnu
365
426
    if (config.Option ("--gnu-extended-asm"))
366
427
      extended_asm = true;
367
 
    if (config.Option ("--gnu-2.95") || config.Option ("--gnu-std-hack"))
 
428
    if (config.Option ("--gnu-std-hack"))
368
429
      std_hack = true;
 
430
    if (config.Option ("--gnu-friend-injection"))
 
431
      friend_injection = true;
369
432
  }
370
433
 
371
434
  // --------------------------------------------------
372
435
  // support for unnamed struct/union members
373
436
  // --------------------------------------------------
374
 
  
 
437
 
375
438
  advice execution ("% Puma::CSyntax::member_decl()") : around () {
376
439
    // 2: type_spec_seq                          ;
377
440
    // 3: type_spec_seq  member_declarator_list  ;
378
441
    Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
379
 
    if (! (tjp->that ()->parse (&JoinPoint::That::type_spec_seq) && 
380
 
           tjp->that ()->opt(tjp->that ()->parse (&JoinPoint::That::member_declarator_list)) && 
 
442
    if (! (tjp->that ()->parse (&JoinPoint::That::type_spec_seq) &&
 
443
           tjp->that ()->opt(tjp->that ()->parse (&JoinPoint::That::member_declarator_list)) &&
381
444
           tjp->that ()->parse (Puma::TOK_SEMI_COLON))) {
382
445
      result = (Puma::CTree*)0;
383
446
    } else {
384
447
      tjp->that ()->semantic ().finish_decl ();
385
 
      result = tjp->that ()->builder ().member_decl (); 
 
448
      result = tjp->that ()->builder ().member_decl ();
 
449
    }
 
450
  }
 
451
 
 
452
  // --------------------------------------------------
 
453
  // GNU defined macros
 
454
  // --------------------------------------------------
 
455
 
 
456
  advice execution ("void Puma::PreprocessorParser::defineGNUMacros()") : after () {
 
457
    // GNU defines
 
458
    tjp->that ()->defUndefinedMacro ("__GNUC__", "2");
 
459
    tjp->that ()->defUndefinedMacro ("__GNUC_MINOR__", "8");
 
460
    tjp->that ()->defUndefinedMacro ("_GLIBCPP_EXTERN_TEMPLATE", "0");
 
461
    tjp->that ()->defUndefinedMacro ("__null", "0");
 
462
    tjp->that ()->defUndefinedMacro ("__extension__", " ");
 
463
    tjp->that ()->defUndefinedMacro ("_WCHAR_T_", " ");
 
464
    // attributes
 
465
    if (! tjp->that ()->_macroManager->getMacro ("__attribute__")) {
 
466
      Puma::PreMacro::MacroArgs *args = new Puma::PreMacro::MacroArgs ();
 
467
      args->append ("par1");
 
468
      tjp->that ()->_macroManager->addMacro (new Puma::PreMacro ("__attribute__", args, " "));
 
469
    }
 
470
    if (! tjp->that ()->_macroManager->getMacro ("__attribute")) {
 
471
      Puma::PreMacro::MacroArgs *args = new Puma::PreMacro::MacroArgs ();
 
472
      args->append ("par1");
 
473
      tjp->that ()->_macroManager->addMacro (new Puma::PreMacro ("__attribute", args, " "));
 
474
    }
 
475
    // variable argument list access
 
476
    if (! tjp->that ()->_macroManager->getMacro ("__builtin_va_arg")) {
 
477
      Puma::PreMacro::MacroArgs *args = new Puma::PreMacro::MacroArgs ();
 
478
      args->append ("par1");
 
479
      args->append ("par2");
 
480
      tjp->that ()->_macroManager->addMacro (new Puma::PreMacro ("__builtin_va_arg", args,
 
481
        "((par2)__builtin_va_arg_helper(par1))"));
 
482
    }
 
483
 
 
484
    // atomic memory access built-in functions
 
485
 
 
486
    // #define __sync_...(arg,...) *(typeof(arg))__generic_sync_...(arg, ## __VA_ARGS__)
 
487
    #define __puma_defSyncMacro(opname) \
 
488
    if (! tjp->that ()->_macroManager->getMacro ("__sync_" opname)) { \
 
489
      Puma::PreMacro::MacroArgs *args = new Puma::PreMacro::MacroArgs (2); \
 
490
      args->append ("par1"); \
 
491
      args->append ("__VA_ARGS__"); \
 
492
      tjp->that ()->_macroManager->addMacro (new Puma::PreMacro ("__sync_" opname, args, \
 
493
        "*(typeof(par1))__generic_sync_" opname "(par1, ## __VA_ARGS__)", Puma::PreMacro::VAR_ARG_MACRO)); \
 
494
    }
 
495
    __puma_defSyncMacro("fetch_and_add");
 
496
    __puma_defSyncMacro("fetch_and_add");
 
497
    __puma_defSyncMacro("fetch_and_sub");
 
498
    __puma_defSyncMacro("fetch_and_or");
 
499
    __puma_defSyncMacro("fetch_and_and");
 
500
    __puma_defSyncMacro("fetch_and_xor");
 
501
    __puma_defSyncMacro("fetch_and_nand");
 
502
    __puma_defSyncMacro("add_and_fetch");
 
503
    __puma_defSyncMacro("sub_and_fetch");
 
504
    __puma_defSyncMacro("or_and_fetch");
 
505
    __puma_defSyncMacro("and_and_fetch");
 
506
    __puma_defSyncMacro("xor_and_fetch");
 
507
    __puma_defSyncMacro("nand_and_fetch");
 
508
    __puma_defSyncMacro("val_compare_and_swap");
 
509
    __puma_defSyncMacro("lock_test_and_set");
 
510
 
 
511
    // built-in versions of the ISO C99 floating point comparison macros
 
512
    // map to its originals
 
513
    tjp->that ()->defUndefinedMacro ("__builtin_isgreater", "isgreater");
 
514
    tjp->that ()->defUndefinedMacro ("__builtin_isgreaterequal", "isgreaterequal");
 
515
    tjp->that ()->defUndefinedMacro ("__builtin_isless", "isless");
 
516
    tjp->that ()->defUndefinedMacro ("__builtin_islessequal", "islessequal");
 
517
    tjp->that ()->defUndefinedMacro ("__builtin_islessgreater", "islessgreater");
 
518
    tjp->that ()->defUndefinedMacro ("__builtin_isunordered", "isunordered");
 
519
 
 
520
    // implementation of ?: without side effects in not chosen alternative
 
521
    // type __builtin_choose_expr (const_exp, exp1, exp2)
 
522
    if (! tjp->that ()->_macroManager->getMacro ("__builtin_choose_expr")) {
 
523
      Puma::PreMacro::MacroArgs *args = new Puma::PreMacro::MacroArgs ();
 
524
      args->append ("const_exp");
 
525
      args->append ("exp1");
 
526
      args->append ("exp2");
 
527
      tjp->that ()->_macroManager->addMacro (new Puma::PreMacro ("__builtin_choose_expr", args, "(exp1)"));
386
528
    }
387
529
  }
388
530
 
389
531
protected:
390
 
  ExtGnu () : extended_asm (false), extended_cv_qual (false),
391
 
    gnu_builtins (false), std_hack (false), typeof_keyword (false),
392
 
    statement_exprs (false)
 
532
  ExtGnu () :
 
533
    extended_asm (false),
 
534
    extended_cv_qual (false),
 
535
    gnu_builtins (false),
 
536
    std_hack (false),
 
537
    typeof_keyword (false),
 
538
    statement_exprs (false),
 
539
    labels_as_values (false),
 
540
    thread_local_storage_class (false),
 
541
    friend_injection (false),
 
542
    extern_inline (false)
393
543
  {}
394
544
};
395
545
 
404
554
  Puma::CTree * gnu_asm_spec ();
405
555
  Puma::CTree * gnu_asm_def ();
406
556
  Puma::CTree * gnu_asm_operands ();
 
557
  Puma::CTree * gnu_asm_empty_operands ();
407
558
  Puma::CTree * gnu_asm_operand ();
408
559
  Puma::CTree * gnu_asm_clobbers ();
409
560
};
419
570
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_def () {
420
571
  return (parse (Puma::TOK_ASM) && opt (cv_qual ()) &&
421
572
          parse (Puma::TOK_OPEN_ROUND) && cmpd_str () &&
422
 
          opt (parse (&Puma::CSyntax::gnu_asm_operands) &&
 
573
          opt ((look_ahead (Puma::TOK_COLON_COLON) ?
 
574
                 parse (&Puma::CSyntax::gnu_asm_empty_operands) &&
 
575
                 parse (&Puma::CSyntax::gnu_asm_operands) :
423
576
               parse (&Puma::CSyntax::gnu_asm_operands) &&
 
577
               look_ahead (Puma::TOK_COLON_COLON) ?
 
578
                 parse (&Puma::CSyntax::gnu_asm_empty_operands) :
 
579
                 parse (&Puma::CSyntax::gnu_asm_operands)) &&
424
580
               parse (&Puma::CSyntax::gnu_asm_clobbers)) &&
425
581
          parse (Puma::TOK_CLOSE_ROUND) && parse (Puma::TOK_SEMI_COLON)) ?
426
582
    builder ().gnu_asm_def () : (Puma::CTree*)0;
427
583
}
428
584
 
429
585
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operands () {
430
 
  return (parse (Puma::TOK_COLON) &&
 
586
  return ((parse (Puma::TOK_COLON) || parse (Puma::TOK_COLON_COLON)) &&
431
587
          opt (list (&Puma::CSyntax::gnu_asm_operand, Puma::TOK_COMMA))) ?
432
588
    builder ().gnu_asm_operands () : (Puma::CTree*)0;
433
589
}
434
590
 
 
591
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_empty_operands () {
 
592
  return builder ().gnu_asm_empty_operands ();
 
593
}
 
594
 
435
595
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operand () {
436
596
  return (cmpd_str () && parse (Puma::TOK_OPEN_ROUND) &&
437
597
          parse (&Puma::CSyntax::expr) && parse (Puma::TOK_CLOSE_ROUND)) ?
439
599
}
440
600
 
441
601
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_clobbers () {
442
 
  return (parse (Puma::TOK_COLON) && list (&Puma::CSyntax::cmpd_str, Puma::TOK_COMMA)) ?
 
602
  return ((parse (Puma::TOK_COLON) || parse (Puma::TOK_COLON_COLON)) &&
 
603
           opt (list (&Puma::CSyntax::cmpd_str, Puma::TOK_COMMA))) ?
443
604
    builder ().gnu_asm_clobbers () : (Puma::CTree*)0;
444
605
}
445
606
 
449
610
  Puma::CTree * gnu_asm_spec ();
450
611
  Puma::CTree * gnu_asm_def ();
451
612
  Puma::CTree * gnu_asm_operands ();
 
613
  Puma::CTree * gnu_asm_empty_operands ();
452
614
  Puma::CTree * gnu_asm_operand ();
453
615
  Puma::CTree * gnu_asm_clobbers ();
454
616
};
476
638
  return list (new Puma::CT_GnuAsmOperands);
477
639
}
478
640
 
 
641
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_empty_operands () {
 
642
  return new Puma::CT_GnuAsmOperands;
 
643
}
 
644
 
479
645
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_operand () {
480
646
  return new Puma::CT_GnuAsmOperand (get_node (0), get_node (1), get_node (2),
481
647
                               get_node (3));
482
648
}
483
 
        
 
649
 
484
650
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_clobbers () {
485
651
  return list (new Puma::CT_GnuAsmClobbers);
486
652
}
487
653
 
488
654
// -------------------------
489
 
// Gnu statement expressions 
 
655
// Gnu statement expressions
490
656
// -------------------------
491
657
 
492
658
// C Builder extension
511
677
  Puma::CT_GnuStatementExpr *node, Puma::CTree *) {
512
678
 
513
679
  Puma::CTypeInfo *result = &Puma::CTYPE_UNDEFINED;
514
 
  
 
680
 
515
681
  if (! current_scope->LocalScope ()) {
516
682
    SEM_ERROR (node,
517
683
               "braced-group within expression allowed only inside a function");
551
717
  Puma::CT_GnuStatementExpr *node, Puma::CTree *) {
552
718
 
553
719
  Puma::CTypeInfo *result = &Puma::CTYPE_UNDEFINED;
554
 
  
 
720
 
555
721
  if (! current_scope->LocalScope ()) {
556
722
    SEM_ERROR (node,
557
723
               "braced-group within expression allowed only inside a function");
673
839
};
674
840
 
675
841
slice void Puma::ExtGnuBuiltinsSemantic::define_gnu_builtins () {
676
 
  // declare gnu-specific builtin functions
 
842
  // declare GNU built-ins
677
843
 
678
844
  Puma::CFunctionInfo *info;
679
845
  Puma::CTypeInfo *type;
680
846
  Puma::CTypeList *args;
681
847
 
682
 
  // mem... functions
683
 
  
684
 
  // void *__builtin_memcpy(void *dest, const void *src, size_t n)
685
 
  args = new Puma::CTypeList (3);
686
 
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID); // void*
687
 
  args->AddEntry (type);
688
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_VOID, true, false, false);
689
 
  type = new Puma::CTypePointer (type);
690
 
  args->AddEntry (type); // const void*
691
 
  args->AddEntry (Puma::CTypeInfo::CTYPE_SIZE_T);
692
 
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID); // void*
693
 
  type = new Puma::CTypeFunction (type, args, true);
694
 
  info = createFunction ("__builtin_memcpy", current_scope, type);
695
 
  createParameter (info, args->Entry (0));
696
 
  createParameter (info, args->Entry (1));
697
 
  createParameter (info, args->Entry (2));
698
 
 
699
 
  // string functions
700
 
 
701
 
  // char *__builtin_strchr(const char *s, int c);
702
 
  args = new Puma::CTypeList (2);
703
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
704
 
  type = new Puma::CTypePointer (type);
705
 
  args->AddEntry (type); // const char*
706
 
  args->AddEntry (&Puma::CTYPE_INT); // int
707
 
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
708
 
  type = new Puma::CTypeFunction (type, args, true);
709
 
  info = createFunction ("__builtin_strchr", current_scope, type);
710
 
  createParameter (info, args->Entry (0));
711
 
  createParameter (info, args->Entry (1));
712
 
 
713
 
  // char *__builtin_strrchr(const char *s, int c);
714
 
  args = new Puma::CTypeList (2);
715
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
716
 
  type = new Puma::CTypePointer (type);
717
 
  args->AddEntry (type); // const char*
718
 
  args->AddEntry (&Puma::CTYPE_INT); // int
719
 
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
720
 
  type = new Puma::CTypeFunction (type, args, true);
721
 
  info = createFunction ("__builtin_strrchr", current_scope, type);
722
 
  createParameter (info, args->Entry (0));
723
 
  createParameter (info, args->Entry (1));
724
 
 
725
 
  // char *__builtin_strpbrk(const char *s, const char *accept);
726
 
  args = new Puma::CTypeList (2);
727
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
728
 
  type = new Puma::CTypePointer (type);
729
 
  args->AddEntry (type); // const char*
730
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
731
 
  type = new Puma::CTypePointer (type);
732
 
  args->AddEntry (type); // const char*
733
 
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
734
 
  type = new Puma::CTypeFunction (type, args, true);
735
 
  info = createFunction ("__builtin_strpbrk", current_scope, type);
736
 
  createParameter (info, args->Entry (0));
737
 
  createParameter (info, args->Entry (1));
738
 
 
739
 
  // char *__builtin_strstr(const char *haystack, const char *needle);
740
 
  args = new Puma::CTypeList (2);
741
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
742
 
  type = new Puma::CTypePointer (type);
743
 
  args->AddEntry (type); // const char*
744
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
745
 
  type = new Puma::CTypePointer (type);
746
 
  args->AddEntry (type); // const char*
747
 
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
748
 
  type = new Puma::CTypeFunction (type, args, true);
749
 
  info = createFunction ("__builtin_strstr", current_scope, type);
750
 
  createParameter (info, args->Entry (0));
751
 
  createParameter (info, args->Entry (1));
752
 
 
753
 
  // math functions
754
 
  
755
 
  // double __builtin_fabs(double x)
756
 
  args = new Puma::CTypeList (1);
757
 
  args->AddEntry (&Puma::CTYPE_DOUBLE); // double
758
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
759
 
  info = createFunction ("__builtin_fabs", current_scope, type);
760
 
  createParameter (info, args->Entry (0));
761
 
 
762
 
  // float __builtin_fabsf(float x)
763
 
  args = new Puma::CTypeList (1);
764
 
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
765
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
766
 
  info = createFunction ("__builtin_fabsf", current_scope, type);
767
 
  createParameter (info, args->Entry (0));
768
 
 
769
 
  // long double __builtin_fabsl(long double x)
770
 
  args = new Puma::CTypeList (1);
771
 
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
772
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
773
 
  info = createFunction ("__builtin_fabsl", current_scope, type);
774
 
  createParameter (info, args->Entry (0));
775
 
 
776
 
  // float __builtin_cosf(float x)
777
 
  args = new Puma::CTypeList (1);
778
 
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
779
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
780
 
  info = createFunction ("__builtin_cosf", current_scope, type);
781
 
  createParameter (info, args->Entry (0));
782
 
 
783
 
  // long double __builtin_cosl(long double x)
784
 
  args = new Puma::CTypeList (1);
785
 
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
786
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
787
 
  info = createFunction ("__builtin_cosl", current_scope, type);
788
 
  createParameter (info, args->Entry (0));
789
 
 
790
 
  // float __builtin_sinf(float x)
791
 
  args = new Puma::CTypeList (1);
792
 
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
793
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
794
 
  info = createFunction ("__builtin_sinf", current_scope, type);
795
 
  createParameter (info, args->Entry (0));
796
 
 
797
 
  // long double __builtin_sinl(long double x)
798
 
  args = new Puma::CTypeList (1);
799
 
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
800
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
801
 
  info = createFunction ("__builtin_sinl", current_scope, type);
802
 
  createParameter (info, args->Entry (0));
803
 
 
804
 
  // float __builtin_sqrtf(float x)
805
 
  args = new Puma::CTypeList (1);
806
 
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
807
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
808
 
  info = createFunction ("__builtin_sqrtf", current_scope, type);
809
 
  createParameter (info, args->Entry (0));
810
 
 
811
 
  // long double __builtin_sqrtl(long double x)
812
 
  args = new Puma::CTypeList (1);
813
 
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
814
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
815
 
  info = createFunction ("__builtin_sqrtl", current_scope, type);
816
 
  createParameter (info, args->Entry (0));
 
848
 
 
849
  // function name constants
 
850
 
 
851
  Puma::CAttributeInfo *attr;
 
852
 
 
853
  // static const char __func__[] = "function-name";
 
854
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
855
  type = new Puma::CTypeArray (type);
 
856
  type->TypeArray ()->Dimension (1);
 
857
  attr = createAttribute ("__func__", current_scope, type, true);
 
858
 
 
859
  // static const char __FUNCTION__[] = "function-name";
 
860
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
861
  type = new Puma::CTypeArray (type);
 
862
  type->TypeArray ()->Dimension (1);
 
863
  attr = createAttribute ("__FUNCTION__", current_scope, type, true);
 
864
 
 
865
  // static const char __PRETTY_FUNCTION__[] = "function-name";
 
866
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
867
  type = new Puma::CTypeArray (type);
 
868
  type->TypeArray ()->Dimension (1);
 
869
  attr = createAttribute ("__PRETTY_FUNCTION__", current_scope, type, true);
 
870
 
 
871
 
 
872
  // variable arguments access
 
873
 
 
874
  // void __builtin_stdarg_start(...)
 
875
  args = new Puma::CTypeList (1);
 
876
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
877
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
878
  info = createFunction ("__builtin_stdarg_start", current_scope, type);
 
879
  createParameter (info, args->Entry (0));
 
880
 
 
881
  // void __builtin_va_start(...)
 
882
  args = new Puma::CTypeList (1);
 
883
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
884
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
885
  info = createFunction ("__builtin_va_start", current_scope, type);
 
886
  createParameter (info, args->Entry (0));
 
887
 
 
888
  // hm, __builtin_va_arg is a problem as it has a variable result type
 
889
  // I use int __builtin_va_start_helper(...)
 
890
  args = new Puma::CTypeList (1);
 
891
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
892
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
893
  info = createFunction ("__builtin_va_arg_helper", current_scope, type);
 
894
  createParameter (info, args->Entry (0));
 
895
 
 
896
  // void __builtin_va_end(...)
 
897
  args = new Puma::CTypeList (1);
 
898
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
899
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
900
  info = createFunction ("__builtin_va_end", current_scope, type);
 
901
  createParameter (info, args->Entry (0));
 
902
 
 
903
  // typedef void *__builtin_va_list
 
904
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
905
  createTypedef ("__builtin_va_list", current_scope, type);
817
906
 
818
907
 
819
908
  // debug/frame access functions
921
1010
  info = createFunction ("__builtin_nansl", current_scope, type);
922
1011
  createParameter (info, args->Entry (0));
923
1012
 
924
 
  
925
 
  // allocation functions
926
 
 
927
 
  // void *__builtin_alloca(size_t size);
928
 
  args = new Puma::CTypeList (1);
929
 
  args->AddEntry (Puma::CTypeInfo::CTYPE_SIZE_T);
930
 
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
931
 
  type = new Puma::CTypeFunction (type, args, true);
932
 
  info = createFunction ("__builtin_alloca", current_scope, type);
933
 
  createParameter (info, args->Entry (0));
934
 
  
935
 
 
936
 
  // variable arguments access functions
937
 
 
938
 
  // void __builtin_stdarg_start(...)
939
 
  args = new Puma::CTypeList (1);
940
 
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
941
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
942
 
  info = createFunction ("__builtin_stdarg_start", current_scope, type);
943
 
  createParameter (info, args->Entry (0));
944
 
 
945
 
  // void __builtin_va_start(...)
946
 
  args = new Puma::CTypeList (1);
947
 
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
948
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
949
 
  info = createFunction ("__builtin_va_start", current_scope, type);
950
 
  createParameter (info, args->Entry (0));
951
 
 
952
 
  // hm, __builtin_va_arg is a problem as it has a variable result type
953
 
  // I use void __builtin_va_start_helper(...)
954
 
  args = new Puma::CTypeList (1);
955
 
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
956
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
957
 
  info = createFunction ("__builtin_va_arg_helper", current_scope, type);
958
 
  createParameter (info, args->Entry (0));
959
 
  
960
 
  // void __builtin_va_end(...)
961
 
  args = new Puma::CTypeList (1);
962
 
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
963
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
964
 
  info = createFunction ("__builtin_va_end", current_scope, type);
965
 
  createParameter (info, args->Entry (0));
966
 
 
967
1013
 
968
1014
  // compiler optimization
969
 
  
 
1015
 
 
1016
  // int __builtin_constant_p (...)
 
1017
  args = new Puma::CTypeList (1);
 
1018
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1019
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1020
  info = createFunction ("__builtin_constant_p", current_scope, type);
 
1021
  createParameter (info, args->Entry (0));
 
1022
 
 
1023
  // int __builtin_types_compatible_p (...)
 
1024
  args = new Puma::CTypeList (1);
 
1025
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1026
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1027
  info = createFunction ("__builtin_types_compatible_p", current_scope, type);
 
1028
  createParameter (info, args->Entry (0));
 
1029
 
970
1030
  // long __builtin_expect (long exp, long c)
971
1031
  args = new Puma::CTypeList (2);
972
1032
  args->AddEntry (&Puma::CTYPE_LONG); // long
975
1035
  info = createFunction ("__builtin_expect", current_scope, type);
976
1036
  createParameter (info, args->Entry (0));
977
1037
  createParameter (info, args->Entry (1));
978
 
  
979
 
  // int __builtin_constant_p (...)
980
 
  args = new Puma::CTypeList (1);
981
 
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
982
 
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
983
 
  info = createFunction ("__builtin_constant_p", current_scope, type);
984
 
  createParameter (info, args->Entry (0));
985
 
  
986
 
  
987
 
  // builtin typedefs (shouldn't be here!)
988
 
  
989
 
  // typedef void *__builtin_va_list
990
 
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
991
 
  createTypedef ("__builtin_va_list", current_scope, type);
992
 
 
993
 
 
994
 
  // builtin attributes
995
 
  Puma::CAttributeInfo *attr;
996
 
 
997
 
  // static const char *__func__;
998
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
999
 
  type = new Puma::CTypePointer (type);
1000
 
  attr = createAttribute ("__func__", current_scope, type, true);
1001
 
 
1002
 
  // static const char *__FUNCTION__;
1003
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
1004
 
  type = new Puma::CTypePointer (type);
1005
 
  attr = createAttribute ("__FUNCTION__", current_scope, type, true);
1006
 
 
1007
 
  // static const char *__PRETTY_FUNCTION__;
1008
 
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
1009
 
  type = new Puma::CTypePointer (type);
1010
 
  attr = createAttribute ("__PRETTY_FUNCTION__", current_scope, type, true);
1011
 
 
 
1038
 
 
1039
  // void __builtin_prefetch (const void *addr, ...)
 
1040
  args = new Puma::CTypeList (2);
 
1041
  type = new Puma::CTypeQualified (&Puma::CTYPE_VOID, true, false, false);
 
1042
  args->AddEntry (new Puma::CTypePointer (type)); // const void*
 
1043
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1044
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
1045
  info = createFunction ("__builtin_prefetch", current_scope, type);
 
1046
  createParameter (info, args->Entry (0));
 
1047
  createParameter (info, args->Entry (1));
 
1048
 
 
1049
 
 
1050
  // bit operations
 
1051
 
 
1052
  // int __builtin_ffs (unsigned int x)
 
1053
  args = new Puma::CTypeList (1);
 
1054
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT);
 
1055
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1056
  info = createFunction ("__builtin_ffs", current_scope, type);
 
1057
  createParameter (info, args->Entry (0));
 
1058
 
 
1059
  // int __builtin_clz (unsigned int x)
 
1060
  args = new Puma::CTypeList (1);
 
1061
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT);
 
1062
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1063
  info = createFunction ("__builtin_clz", current_scope, type);
 
1064
  createParameter (info, args->Entry (0));
 
1065
 
 
1066
  // int __builtin_ctz (unsigned int x)
 
1067
  args = new Puma::CTypeList (1);
 
1068
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT);
 
1069
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1070
  info = createFunction ("__builtin_ctz", current_scope, type);
 
1071
  createParameter (info, args->Entry (0));
 
1072
 
 
1073
  // int __builtin_popcount (unsigned int x)
 
1074
  args = new Puma::CTypeList (1);
 
1075
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT);
 
1076
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1077
  info = createFunction ("__builtin_popcount", current_scope, type);
 
1078
  createParameter (info, args->Entry (0));
 
1079
 
 
1080
  // int __builtin_parity (unsigned int x)
 
1081
  args = new Puma::CTypeList (1);
 
1082
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT);
 
1083
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1084
  info = createFunction ("__builtin_parity", current_scope, type);
 
1085
  createParameter (info, args->Entry (0));
 
1086
 
 
1087
  // int __builtin_ffsl (unsigned long)
 
1088
  args = new Puma::CTypeList (1);
 
1089
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG);
 
1090
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1091
  info = createFunction ("__builtin_ffsl", current_scope, type);
 
1092
  createParameter (info, args->Entry (0));
 
1093
 
 
1094
  // int __builtin_clzl (unsigned long)
 
1095
  args = new Puma::CTypeList (1);
 
1096
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG);
 
1097
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1098
  info = createFunction ("__builtin_clzl", current_scope, type);
 
1099
  createParameter (info, args->Entry (0));
 
1100
 
 
1101
  // int __builtin_ctzl (unsigned long)
 
1102
  args = new Puma::CTypeList (1);
 
1103
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG);
 
1104
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1105
  info = createFunction ("__builtin_ctzl", current_scope, type);
 
1106
  createParameter (info, args->Entry (0));
 
1107
 
 
1108
  // int __builtin_popcountl (unsigned long)
 
1109
  args = new Puma::CTypeList (1);
 
1110
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG);
 
1111
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1112
  info = createFunction ("__builtin_popcountl", current_scope, type);
 
1113
  createParameter (info, args->Entry (0));
 
1114
 
 
1115
  // int __builtin_parityl (unsigned long)
 
1116
  args = new Puma::CTypeList (1);
 
1117
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG);
 
1118
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1119
  info = createFunction ("__builtin_parityl", current_scope, type);
 
1120
  createParameter (info, args->Entry (0));
 
1121
 
 
1122
  // int __builtin_ffsll (unsigned long long)
 
1123
  args = new Puma::CTypeList (1);
 
1124
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG_LONG);
 
1125
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1126
  info = createFunction ("__builtin_ffsll", current_scope, type);
 
1127
  createParameter (info, args->Entry (0));
 
1128
 
 
1129
  // int __builtin_clzll (unsigned long long)
 
1130
  args = new Puma::CTypeList (1);
 
1131
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG_LONG);
 
1132
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1133
  info = createFunction ("__builtin_clzll", current_scope, type);
 
1134
  createParameter (info, args->Entry (0));
 
1135
 
 
1136
  // int __builtin_ctzll (unsigned long long)
 
1137
  args = new Puma::CTypeList (1);
 
1138
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG_LONG);
 
1139
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1140
  info = createFunction ("__builtin_ctzll", current_scope, type);
 
1141
  createParameter (info, args->Entry (0));
 
1142
 
 
1143
  // int __builtin_popcountll (unsigned long long)
 
1144
  args = new Puma::CTypeList (1);
 
1145
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG_LONG);
 
1146
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1147
  info = createFunction ("__builtin_popcountll", current_scope, type);
 
1148
  createParameter (info, args->Entry (0));
 
1149
 
 
1150
  // int __builtin_parityll (unsigned long long)
 
1151
  args = new Puma::CTypeList (1);
 
1152
  args->AddEntry (&Puma::CTYPE_UNSIGNED_LONG_LONG);
 
1153
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
 
1154
  info = createFunction ("__builtin_parityll", current_scope, type);
 
1155
  createParameter (info, args->Entry (0));
 
1156
 
 
1157
 
 
1158
  // power calculation
 
1159
 
 
1160
  // double __builtin_powi (double, int)
 
1161
  args = new Puma::CTypeList (2);
 
1162
  args->AddEntry (&Puma::CTYPE_DOUBLE); // double
 
1163
  args->AddEntry (&Puma::CTYPE_INT); // int
 
1164
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
 
1165
  info = createFunction ("__builtin_powi", current_scope, type);
 
1166
  createParameter (info, args->Entry (0));
 
1167
  createParameter (info, args->Entry (1));
 
1168
 
 
1169
  // float __builtin_powif (float, int)
 
1170
  args = new Puma::CTypeList (2);
 
1171
  args->AddEntry (&Puma::CTYPE_FLOAT); // float
 
1172
  args->AddEntry (&Puma::CTYPE_INT); // int
 
1173
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
 
1174
  info = createFunction ("__builtin_powif", current_scope, type);
 
1175
  createParameter (info, args->Entry (0));
 
1176
  createParameter (info, args->Entry (1));
 
1177
 
 
1178
  // long double __builtin_powil (long double, int)
 
1179
  args = new Puma::CTypeList (2);
 
1180
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // long double
 
1181
  args->AddEntry (&Puma::CTYPE_INT); // int
 
1182
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
 
1183
  info = createFunction ("__builtin_powil", current_scope, type);
 
1184
  createParameter (info, args->Entry (0));
 
1185
  createParameter (info, args->Entry (1));
 
1186
 
 
1187
 
 
1188
  // atomic memory access
 
1189
 
 
1190
  // void __sync_synchronize (...)
 
1191
  args = new Puma::CTypeList (1);
 
1192
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1193
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
1194
  info = createFunction ("__sync_synchronize", current_scope, type);
 
1195
  createParameter (info, args->Entry (0));
 
1196
 
 
1197
  // void __sync_lock_release (type *ptr, ...)
 
1198
  args = new Puma::CTypeList (1);
 
1199
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1200
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
1201
  info = createFunction ("__sync_lock_release", current_scope, type);
 
1202
  createParameter (info, args->Entry (0));
 
1203
 
 
1204
  // bool __sync_bool_compare_and_swap (type *ptr, type oldval, type newval, ...)
 
1205
  args = new Puma::CTypeList (1);
 
1206
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1207
  type = new Puma::CTypeFunction (&Puma::CTYPE_BOOL, args, true);
 
1208
  info = createFunction ("__sync_bool_compare_and_swap", current_scope, type);
 
1209
  createParameter (info, args->Entry (0));
 
1210
 
 
1211
  // type __sync_fetch_and_add (type *ptr, type value, ...)
 
1212
  args = new Puma::CTypeList (1);
 
1213
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1214
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1215
  type = new Puma::CTypeFunction (type, args, true);
 
1216
  info = createFunction ("__generic_sync_fetch_and_add", current_scope, type);
 
1217
  createParameter (info, args->Entry (0));
 
1218
 
 
1219
  // type __sync_fetch_and_sub (type *ptr, type value, ...)
 
1220
  args = new Puma::CTypeList (1);
 
1221
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1222
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1223
  type = new Puma::CTypeFunction (type, args, true);
 
1224
  info = createFunction ("__generic_sync_fetch_and_sub", current_scope, type);
 
1225
  createParameter (info, args->Entry (0));
 
1226
 
 
1227
  // type __sync_fetch_and_or (type *ptr, type value, ...)
 
1228
  args = new Puma::CTypeList (1);
 
1229
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1230
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1231
  type = new Puma::CTypeFunction (type, args, true);
 
1232
  info = createFunction ("__generic_sync_fetch_and_or", current_scope, type);
 
1233
  createParameter (info, args->Entry (0));
 
1234
 
 
1235
  // type __sync_fetch_and_and (type *ptr, type value, ...)
 
1236
  args = new Puma::CTypeList (1);
 
1237
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1238
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1239
  type = new Puma::CTypeFunction (type, args, true);
 
1240
  info = createFunction ("__generic_sync_fetch_and_and", current_scope, type);
 
1241
  createParameter (info, args->Entry (0));
 
1242
 
 
1243
  // type __sync_fetch_and_xor (type *ptr, type value, ...)
 
1244
  args = new Puma::CTypeList (1);
 
1245
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1246
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1247
  type = new Puma::CTypeFunction (type, args, true);
 
1248
  info = createFunction ("__generic_sync_fetch_and_xor", current_scope, type);
 
1249
  createParameter (info, args->Entry (0));
 
1250
 
 
1251
  // type __sync_fetch_and_nand (type *ptr, type value, ...)
 
1252
  args = new Puma::CTypeList (1);
 
1253
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1254
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1255
  type = new Puma::CTypeFunction (type, args, true);
 
1256
  info = createFunction ("__generic_sync_fetch_and_nand", current_scope, type);
 
1257
  createParameter (info, args->Entry (0));
 
1258
 
 
1259
  // type __sync_add_and_fetch (type *ptr, type value, ...)
 
1260
  args = new Puma::CTypeList (1);
 
1261
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1262
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1263
  type = new Puma::CTypeFunction (type, args, true);
 
1264
  info = createFunction ("__generic_sync_add_and_fetch", current_scope, type);
 
1265
  createParameter (info, args->Entry (0));
 
1266
 
 
1267
  // type __sync_sub_and_fetch (type *ptr, type value, ...)
 
1268
  args = new Puma::CTypeList (1);
 
1269
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1270
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1271
  type = new Puma::CTypeFunction (type, args, true);
 
1272
  info = createFunction ("__generic_sync_sub_and_fetch", current_scope, type);
 
1273
  createParameter (info, args->Entry (0));
 
1274
 
 
1275
  // type __sync_or_and_fetch (type *ptr, type value, ...)
 
1276
  args = new Puma::CTypeList (1);
 
1277
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1278
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1279
  type = new Puma::CTypeFunction (type, args, true);
 
1280
  info = createFunction ("__generic_sync_or_and_fetch", current_scope, type);
 
1281
  createParameter (info, args->Entry (0));
 
1282
 
 
1283
  // type __sync_and_and_fetch (type *ptr, type value, ...)
 
1284
  args = new Puma::CTypeList (1);
 
1285
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1286
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1287
  type = new Puma::CTypeFunction (type, args, true);
 
1288
  info = createFunction ("__generic_sync_and_and_fetch", current_scope, type);
 
1289
  createParameter (info, args->Entry (0));
 
1290
 
 
1291
  // type __sync_xor_and_fetch (type *ptr, type value, ...)
 
1292
  args = new Puma::CTypeList (1);
 
1293
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1294
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1295
  type = new Puma::CTypeFunction (type, args, true);
 
1296
  info = createFunction ("__generic_sync_xor_and_fetch", current_scope, type);
 
1297
  createParameter (info, args->Entry (0));
 
1298
 
 
1299
  // type __sync_nand_and_fetch (type *ptr, type value, ...)
 
1300
  args = new Puma::CTypeList (1);
 
1301
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1302
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1303
  type = new Puma::CTypeFunction (type, args, true);
 
1304
  info = createFunction ("__generic_sync_nand_and_fetch", current_scope, type);
 
1305
  createParameter (info, args->Entry (0));
 
1306
 
 
1307
  // type __sync_val_compare_and_swap (type *ptr, type oldval, type newval, ...)
 
1308
  args = new Puma::CTypeList (1);
 
1309
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1310
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1311
  type = new Puma::CTypeFunction (type, args, true);
 
1312
  info = createFunction ("__generic_sync_val_compare_and_swap", current_scope, type);
 
1313
  createParameter (info, args->Entry (0));
 
1314
 
 
1315
  // type __sync_lock_test_and_set (type *ptr, type value, ...)
 
1316
  args = new Puma::CTypeList (1);
 
1317
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
1318
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1319
  type = new Puma::CTypeFunction (type, args, true);
 
1320
  info = createFunction ("__generic_sync_lock_test_and_set", current_scope, type);
 
1321
  createParameter (info, args->Entry (0));
 
1322
 
 
1323
 
 
1324
  // constructing function calls
 
1325
 
 
1326
  // void * __builtin_apply_args()
 
1327
  args = new Puma::CTypeList (0);
 
1328
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1329
  type = new Puma::CTypeFunction (type, args, true);
 
1330
  info = createFunction ("__builtin_apply_args", current_scope, type);
 
1331
 
 
1332
  // void * __builtin_apply(void (*function)(), void *arguments, size_t size)
 
1333
  args = new Puma::CTypeList (3);
 
1334
  args->AddEntry (new Puma::CTypePointer (new Puma::CTypeFunction (&Puma::CTYPE_VOID, new Puma::CTypeList (0), true)));
 
1335
  args->AddEntry (new Puma::CTypePointer (&Puma::CTYPE_VOID));
 
1336
  args->AddEntry (Puma::CTypeInfo::CTYPE_SIZE_T);
 
1337
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
1338
  type = new Puma::CTypeFunction (type, args, true);
 
1339
  info = createFunction ("__builtin_apply", current_scope, type);
 
1340
  createParameter (info, args->Entry (0));
 
1341
  createParameter (info, args->Entry (1));
 
1342
  createParameter (info, args->Entry (2));
 
1343
 
 
1344
  // void __builtin_return(void *result)
 
1345
  args = new Puma::CTypeList (1);
 
1346
  args->AddEntry (new Puma::CTypePointer (&Puma::CTYPE_VOID));
 
1347
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
 
1348
  info = createFunction ("__builtin_return", current_scope, type);
 
1349
  createParameter (info, args->Entry (0));
1012
1350
}
1013
1351
 
1014
1352