~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/5c/swt.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
206
206
                        p->from.offset += nstring - NSNAME;
207
207
                        p->reg = NSNAME;
208
208
                        p->to.type = D_SCONST;
209
 
                        memmove(p->to.sval, string, NSNAME);
 
209
                        memmove(p->to.u.sval, string, NSNAME);
210
210
                        mnstring = 0;
211
211
                }
212
212
                n--;
321
321
                p->from.offset += o+e;
322
322
                p->reg = lw;
323
323
                p->to.type = D_SCONST;
324
 
                memmove(p->to.sval, a->cstring+e, lw);
 
324
                memmove(p->to.u.sval, a->cstring+e, lw);
325
325
        }
326
326
}
327
327
 
351
351
                p->to.type = D_CONST;
352
352
}
353
353
 
354
 
void    zname(Biobuf*, Sym*, int);
355
 
char*   zaddr(char*, Adr*, int);
356
 
void    zwrite(Biobuf*, Prog*, int, int);
357
 
void    outhist(Biobuf*);
358
 
 
359
 
void
360
 
zwrite(Biobuf *b, Prog *p, int sf, int st)
361
 
{
362
 
        char bf[100], *bp;
363
 
 
364
 
        bf[0] = p->as;
365
 
        bf[1] = p->scond;
366
 
        bf[2] = p->reg;
367
 
        bf[3] = p->lineno;
368
 
        bf[4] = p->lineno>>8;
369
 
        bf[5] = p->lineno>>16;
370
 
        bf[6] = p->lineno>>24;
371
 
        bp = zaddr(bf+7, &p->from, sf);
372
 
        bp = zaddr(bp, &p->to, st);
373
 
        Bwrite(b, bf, bp-bf);
374
 
}
375
 
 
376
354
void
377
355
outcode(void)
378
356
{
379
 
        struct { Sym *sym; short type; } h[NSYM];
380
 
        Prog *p;
381
 
        Sym *s;
382
 
        int sf, st, t, sym;
383
 
 
384
 
        if(debug['S']) {
385
 
                for(p = firstp; p != P; p = p->link)
386
 
                        if(p->as != ADATA && p->as != AGLOBL)
387
 
                                pc--;
388
 
                for(p = firstp; p != P; p = p->link) {
389
 
                        print("%P\n", p);
390
 
                        if(p->as != ADATA && p->as != AGLOBL)
391
 
                                pc++;
392
 
                }
393
 
        }
394
 
 
395
 
        Bprint(&outbuf, "go object %s %s %s\n", getgoos(), thestring, getgoversion());
 
357
        Bprint(&outbuf, "go object %s %s %s\n", getgoos(), getgoarch(), getgoversion());
396
358
        if(pragcgobuf.to > pragcgobuf.start) {
397
359
                Bprint(&outbuf, "\n");
398
360
                Bprint(&outbuf, "$$  // exports\n\n");
403
365
        }
404
366
        Bprint(&outbuf, "!\n");
405
367
 
406
 
        outhist(&outbuf);
407
 
        for(sym=0; sym<NSYM; sym++) {
408
 
                h[sym].sym = S;
409
 
                h[sym].type = 0;
410
 
        }
411
 
        sym = 1;
412
 
        for(p = firstp; p != P; p = p->link) {
413
 
        jackpot:
414
 
                sf = 0;
415
 
                s = p->from.sym;
416
 
                while(s != S) {
417
 
                        sf = s->sym;
418
 
                        if(sf < 0 || sf >= NSYM)
419
 
                                sf = 0;
420
 
                        t = p->from.name;
421
 
                        if(h[sf].type == t)
422
 
                        if(h[sf].sym == s)
423
 
                                break;
424
 
                        s->sym = sym;
425
 
                        zname(&outbuf, s, t);
426
 
                        h[sym].sym = s;
427
 
                        h[sym].type = t;
428
 
                        sf = sym;
429
 
                        sym++;
430
 
                        if(sym >= NSYM)
431
 
                                sym = 1;
432
 
                        break;
433
 
                }
434
 
                st = 0;
435
 
                s = p->to.sym;
436
 
                while(s != S) {
437
 
                        st = s->sym;
438
 
                        if(st < 0 || st >= NSYM)
439
 
                                st = 0;
440
 
                        t = p->to.name;
441
 
                        if(h[st].type == t)
442
 
                        if(h[st].sym == s)
443
 
                                break;
444
 
                        s->sym = sym;
445
 
                        zname(&outbuf, s, t);
446
 
                        h[sym].sym = s;
447
 
                        h[sym].type = t;
448
 
                        st = sym;
449
 
                        sym++;
450
 
                        if(sym >= NSYM)
451
 
                                sym = 1;
452
 
                        if(st == sf)
453
 
                                goto jackpot;
454
 
                        break;
455
 
                }
456
 
                zwrite(&outbuf, p, sf, st);
457
 
        }
458
 
        firstp = P;
 
368
        writeobj(ctxt, &outbuf);
459
369
        lastp = P;
460
370
}
461
371
 
462
 
void
463
 
outhist(Biobuf *b)
464
 
{
465
 
        Hist *h;
466
 
        char *p, *q, *op, c;
467
 
        Prog pg;
468
 
        int n;
469
 
        char *tofree;
470
 
        static int first = 1;
471
 
        static char *goroot, *goroot_final;
472
 
 
473
 
        if(first) {
474
 
                // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL.
475
 
                first = 0;
476
 
                goroot = getenv("GOROOT");
477
 
                goroot_final = getenv("GOROOT_FINAL");
478
 
                if(goroot == nil)
479
 
                        goroot = "";
480
 
                if(goroot_final == nil)
481
 
                        goroot_final = goroot;
482
 
                if(strcmp(goroot, goroot_final) == 0) {
483
 
                        goroot = nil;
484
 
                        goroot_final = nil;
485
 
                }
486
 
        }
487
 
 
488
 
        tofree = nil;
489
 
        pg = zprog;
490
 
        pg.as = AHISTORY;
491
 
        c = pathchar();
492
 
        for(h = hist; h != H; h = h->link) {
493
 
                p = h->name;
494
 
                if(p != nil && goroot != nil) {
495
 
                        n = strlen(goroot);
496
 
                        if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') {
497
 
                                tofree = smprint("%s%s", goroot_final, p+n);
498
 
                                p = tofree;
499
 
                        }
500
 
                }
501
 
                op = 0;
502
 
                if(systemtype(Windows) && p && p[1] == ':'){
503
 
                        c = p[2];
504
 
                } else if(p && p[0] != c && h->offset == 0 && pathname){
505
 
                        if(systemtype(Windows) && pathname[1] == ':') {
506
 
                                op = p;
507
 
                                p = pathname;
508
 
                                c = p[2];
509
 
                        } else if(pathname[0] == c){
510
 
                                op = p;
511
 
                                p = pathname;
512
 
                        }
513
 
                }
514
 
                while(p) {
515
 
                        q = utfrune(p, c);
516
 
                        if(q) {
517
 
                                n = q-p;
518
 
                                if(n == 0){
519
 
                                        n = 1;  /* leading "/" */
520
 
                                        *p = '/';       /* don't emit "\" on windows */
521
 
                                }
522
 
                                q++;
523
 
                        } else {
524
 
                                n = strlen(p);
525
 
                                q = 0;
526
 
                        }
527
 
                        if(n) {
528
 
                                BPUTC(b, ANAME);
529
 
                                BPUTC(b, D_FILE);
530
 
                                BPUTC(b, 1);
531
 
                                BPUTC(b, '<');
532
 
                                Bwrite(b, p, n);
533
 
                                BPUTC(b, 0);
534
 
                        }
535
 
                        p = q;
536
 
                        if(p == 0 && op) {
537
 
                                p = op;
538
 
                                op = 0;
539
 
                        }
540
 
                }
541
 
                pg.lineno = h->line;
542
 
                pg.to.type = zprog.to.type;
543
 
                pg.to.offset = h->offset;
544
 
                if(h->offset)
545
 
                        pg.to.type = D_CONST;
546
 
 
547
 
                zwrite(b, &pg, 0, 0);
548
 
 
549
 
                if(tofree) {
550
 
                        free(tofree);
551
 
                        tofree = nil;
552
 
                }
553
 
        }
554
 
}
555
 
 
556
 
void
557
 
zname(Biobuf *b, Sym *s, int t)
558
 
{
559
 
        char *n, bf[7];
560
 
        uint32 sig;
561
 
 
562
 
        n = s->name;
563
 
        if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
564
 
                sig = sign(s);
565
 
                bf[0] = ASIGNAME;
566
 
                bf[1] = sig;
567
 
                bf[2] = sig>>8;
568
 
                bf[3] = sig>>16;
569
 
                bf[4] = sig>>24;
570
 
                bf[5] = t;
571
 
                bf[6] = s->sym;
572
 
                Bwrite(b, bf, 7);
573
 
                s->sig = SIGDONE;
574
 
        }
575
 
        else{
576
 
                bf[0] = ANAME;
577
 
                bf[1] = t;      /* type */
578
 
                bf[2] = s->sym; /* sym */
579
 
                Bwrite(b, bf, 3);
580
 
        }
581
 
        Bwrite(b, n, strlen(n)+1);
582
 
}
583
 
 
584
 
char*
585
 
zaddr(char *bp, Adr *a, int s)
586
 
{
587
 
        int32 l;
588
 
        Ieee e;
589
 
 
590
 
        bp[0] = a->type;
591
 
        bp[1] = a->reg;
592
 
        bp[2] = s;
593
 
        bp[3] = a->name;
594
 
        bp[4] = 0;
595
 
        bp += 5;
596
 
        switch(a->type) {
597
 
        default:
598
 
                diag(Z, "unknown type %d in zaddr", a->type);
599
 
 
600
 
        case D_NONE:
601
 
        case D_REG:
602
 
        case D_FREG:
603
 
        case D_PSR:
604
 
                break;
605
 
 
606
 
        case D_CONST2:
607
 
                l = a->offset2;
608
 
                bp[0] = l;
609
 
                bp[1] = l>>8;
610
 
                bp[2] = l>>16;
611
 
                bp[3] = l>>24;
612
 
                bp += 4;        // fall through
613
 
        case D_OREG:
614
 
        case D_CONST:
615
 
        case D_BRANCH:
616
 
        case D_SHIFT:
617
 
                l = a->offset;
618
 
                bp[0] = l;
619
 
                bp[1] = l>>8;
620
 
                bp[2] = l>>16;
621
 
                bp[3] = l>>24;
622
 
                bp += 4;
623
 
                break;
624
 
 
625
 
        case D_SCONST:
626
 
                memmove(bp, a->sval, NSNAME);
627
 
                bp += NSNAME;
628
 
                break;
629
 
 
630
 
        case D_FCONST:
631
 
                ieeedtod(&e, a->dval);
632
 
                l = e.l;
633
 
                bp[0] = l;
634
 
                bp[1] = l>>8;
635
 
                bp[2] = l>>16;
636
 
                bp[3] = l>>24;
637
 
                bp += 4;
638
 
                l = e.h;
639
 
                bp[0] = l;
640
 
                bp[1] = l>>8;
641
 
                bp[2] = l>>16;
642
 
                bp[3] = l>>24;
643
 
                bp += 4;
644
 
                break;
645
 
        }
646
 
        return bp;
647
 
}
648
 
 
649
372
int32
650
373
align(int32 i, Type *t, int op, int32 *maxalign)
651
374
{