2009-03-30 22:31:29 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "go.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* architecture-independent object file output
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpobj(void)
|
|
|
|
{
|
|
|
|
bout = Bopen(outfile, OWRITE);
|
2010-04-11 15:52:06 -06:00
|
|
|
if(bout == nil) {
|
|
|
|
flusherrors();
|
|
|
|
print("can't create %s: %r\n", outfile);
|
|
|
|
errorexit();
|
|
|
|
}
|
2009-03-30 22:31:29 -06:00
|
|
|
|
|
|
|
Bprint(bout, "%s\n", thestring);
|
|
|
|
Bprint(bout, " exports automatically generated from\n");
|
2010-01-22 18:06:20 -07:00
|
|
|
Bprint(bout, " %s in package \"%s\"\n", curio.infile, localpkg->name);
|
2009-03-30 22:31:29 -06:00
|
|
|
dumpexport();
|
|
|
|
Bprint(bout, "\n!\n");
|
|
|
|
|
|
|
|
outhist(bout);
|
|
|
|
|
|
|
|
// add nil plist w AEND to catch
|
|
|
|
// auto-generated trampolines, data
|
|
|
|
newplist();
|
|
|
|
|
|
|
|
dumpglobls();
|
2009-07-07 12:03:04 -06:00
|
|
|
dumptypestructs();
|
2009-05-06 14:47:40 -06:00
|
|
|
dumpdata();
|
2009-03-30 22:31:29 -06:00
|
|
|
dumpfuncs();
|
|
|
|
|
|
|
|
Bterm(bout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpglobls(void)
|
|
|
|
{
|
|
|
|
Node *n;
|
2009-08-04 23:59:23 -06:00
|
|
|
NodeList *l;
|
2009-03-30 22:31:29 -06:00
|
|
|
|
|
|
|
// add globals
|
2009-08-04 23:59:23 -06:00
|
|
|
for(l=externdcl; l; l=l->next) {
|
|
|
|
n = l->n;
|
|
|
|
if(n->op != ONAME)
|
2009-03-30 22:31:29 -06:00
|
|
|
continue;
|
|
|
|
|
2009-08-04 23:59:23 -06:00
|
|
|
if(n->type == T)
|
|
|
|
fatal("external %#N nil type\n", n);
|
2009-03-30 22:31:29 -06:00
|
|
|
if(n->class == PFUNC)
|
|
|
|
continue;
|
2010-01-22 18:06:20 -07:00
|
|
|
if(n->sym->pkg != localpkg)
|
2009-08-13 15:41:42 -06:00
|
|
|
continue;
|
2009-03-30 22:31:29 -06:00
|
|
|
dowidth(n->type);
|
2009-08-04 23:59:23 -06:00
|
|
|
|
|
|
|
// TODO(rsc): why is this not s/n->sym->def/n/ ?
|
|
|
|
ggloblnod(n->sym->def, n->type->width);
|
2009-03-30 22:31:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-19 22:34:44 -07:00
|
|
|
Bputname(Biobuf *b, Sym *s)
|
2009-03-30 22:31:29 -06:00
|
|
|
{
|
2010-01-22 18:06:20 -07:00
|
|
|
Bprint(b, "%s", s->pkg->prefix);
|
2010-01-19 22:34:44 -07:00
|
|
|
Bputc(b, '.');
|
|
|
|
Bwrite(b, s->name, strlen(s->name)+1);
|
2009-03-30 22:31:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outhist(Biobuf *b)
|
|
|
|
{
|
|
|
|
Hist *h;
|
|
|
|
char *p, *q, *op;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for(h = hist; h != H; h = h->link) {
|
|
|
|
p = h->name;
|
|
|
|
op = 0;
|
|
|
|
|
|
|
|
if(p && p[0] != '/' && h->offset == 0 && pathname && pathname[0] == '/') {
|
|
|
|
op = p;
|
|
|
|
p = pathname;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(p) {
|
|
|
|
q = utfrune(p, '/');
|
|
|
|
if(q) {
|
|
|
|
n = q-p;
|
|
|
|
if(n == 0)
|
|
|
|
n = 1; // leading "/"
|
|
|
|
q++;
|
|
|
|
} else {
|
|
|
|
n = strlen(p);
|
|
|
|
q = 0;
|
|
|
|
}
|
|
|
|
if(n)
|
|
|
|
zfile(b, p, n);
|
|
|
|
p = q;
|
|
|
|
if(p == 0 && op) {
|
|
|
|
p = op;
|
|
|
|
op = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zhist(b, h->line, h->offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ieeedtod(uint64 *ieee, double native)
|
|
|
|
{
|
|
|
|
double fr, ho, f;
|
|
|
|
int exp;
|
|
|
|
uint32 h, l;
|
2009-11-15 13:57:09 -07:00
|
|
|
uint64 bits;
|
2009-03-30 22:31:29 -06:00
|
|
|
|
|
|
|
if(native < 0) {
|
|
|
|
ieeedtod(ieee, -native);
|
|
|
|
*ieee |= 1ULL<<63;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(native == 0) {
|
|
|
|
*ieee = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fr = frexp(native, &exp);
|
|
|
|
f = 2097152L; /* shouldnt use fp constants here */
|
|
|
|
fr = modf(fr*f, &ho);
|
|
|
|
h = ho;
|
|
|
|
h &= 0xfffffL;
|
|
|
|
f = 65536L;
|
|
|
|
fr = modf(fr*f, &ho);
|
|
|
|
l = ho;
|
|
|
|
l <<= 16;
|
|
|
|
l |= (int32)(fr*f);
|
2009-11-15 13:57:09 -07:00
|
|
|
bits = ((uint64)h<<32) | l;
|
|
|
|
if(exp < -1021) {
|
|
|
|
// gradual underflow
|
|
|
|
bits |= 1LL<<52;
|
|
|
|
bits >>= -1021 - exp;
|
|
|
|
exp = -1022;
|
|
|
|
}
|
|
|
|
bits |= (uint64)(exp+1022L) << 52;
|
|
|
|
*ieee = bits;
|
2009-03-30 22:31:29 -06:00
|
|
|
}
|
|
|
|
|
2009-07-06 23:31:20 -06:00
|
|
|
int
|
|
|
|
duint8(Sym *s, int off, uint8 v)
|
|
|
|
{
|
|
|
|
return duintxx(s, off, v, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
duint16(Sym *s, int off, uint16 v)
|
|
|
|
{
|
|
|
|
return duintxx(s, off, v, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
duint32(Sym *s, int off, uint32 v)
|
|
|
|
{
|
|
|
|
return duintxx(s, off, v, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
duint64(Sym *s, int off, uint64 v)
|
|
|
|
{
|
|
|
|
return duintxx(s, off, v, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
duintptr(Sym *s, int off, uint64 v)
|
|
|
|
{
|
|
|
|
return duintxx(s, off, v, widthptr);
|
|
|
|
}
|