mirror of
https://github.com/golang/go
synced 2024-11-22 01:04:40 -07:00
parent
978c3e96d1
commit
31645cc0bb
@ -171,6 +171,8 @@ class CL(object):
|
|||||||
f = open(path+'!', "w")
|
f = open(path+'!', "w")
|
||||||
f.write(self.DiskText())
|
f.write(self.DiskText())
|
||||||
f.close()
|
f.close()
|
||||||
|
if sys.platform == "win32" and os.path.isfile(path):
|
||||||
|
os.remove(path)
|
||||||
os.rename(path+'!', path)
|
os.rename(path+'!', path)
|
||||||
if self.web and not self.original_author:
|
if self.web and not self.original_author:
|
||||||
EditDesc(self.name, desc=self.desc,
|
EditDesc(self.name, desc=self.desc,
|
||||||
|
@ -85,6 +85,7 @@ struct Lang
|
|||||||
char *constend;
|
char *constend;
|
||||||
|
|
||||||
char *typdef;
|
char *typdef;
|
||||||
|
char *typdefend;
|
||||||
|
|
||||||
char *structbegin;
|
char *structbegin;
|
||||||
char *unionbegin;
|
char *unionbegin;
|
||||||
|
@ -82,6 +82,34 @@
|
|||||||
|
|
||||||
#include "a.h"
|
#include "a.h"
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
int
|
||||||
|
spawn(char *prog, char **argv)
|
||||||
|
{
|
||||||
|
return _spawnvp(P_NOWAIT, prog, (const char**)argv);
|
||||||
|
}
|
||||||
|
#undef waitfor
|
||||||
|
void
|
||||||
|
waitfor(int pid)
|
||||||
|
{
|
||||||
|
_cwait(0, pid, 0);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int
|
||||||
|
spawn(char *prog, char **argv)
|
||||||
|
{
|
||||||
|
int pid = fork();
|
||||||
|
if(pid < 0)
|
||||||
|
sysfatal("fork: %r");
|
||||||
|
if(pid == 0) {
|
||||||
|
exec(argv[0], argv);
|
||||||
|
fprint(2, "exec gcc: %r\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@ -101,6 +129,7 @@ Lang go =
|
|||||||
")\n",
|
")\n",
|
||||||
|
|
||||||
"type",
|
"type",
|
||||||
|
"\n",
|
||||||
|
|
||||||
"type %s struct {\n",
|
"type %s struct {\n",
|
||||||
"type %s struct {\n",
|
"type %s struct {\n",
|
||||||
@ -117,6 +146,7 @@ Lang c =
|
|||||||
"};\n",
|
"};\n",
|
||||||
|
|
||||||
"typedef",
|
"typedef",
|
||||||
|
";\n",
|
||||||
|
|
||||||
"typedef struct %s %s;\nstruct %s {\n",
|
"typedef struct %s %s;\nstruct %s {\n",
|
||||||
"typedef union %s %s;\nunion %s {\n",
|
"typedef union %s %s;\nunion %s {\n",
|
||||||
@ -153,6 +183,7 @@ main(int argc, char **argv)
|
|||||||
Biobuf *bin, *bout;
|
Biobuf *bin, *bout;
|
||||||
Type *t;
|
Type *t;
|
||||||
Field *f;
|
Field *f;
|
||||||
|
int orig_output_fd;
|
||||||
|
|
||||||
quotefmtinstall();
|
quotefmtinstall();
|
||||||
|
|
||||||
@ -191,76 +222,57 @@ main(int argc, char **argv)
|
|||||||
av[n++] = argv[0];
|
av[n++] = argv[0];
|
||||||
av[n] = nil;
|
av[n] = nil;
|
||||||
|
|
||||||
// Run gcc writing assembly and stabs debugging to p[1].
|
orig_output_fd = dup(1, -1);
|
||||||
if(pipe(p) < 0)
|
for(i=0; i==0 || i < argc; i++) {
|
||||||
sysfatal("pipe: %r");
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if(pid < 0)
|
|
||||||
sysfatal("fork: %r");
|
|
||||||
if(pid == 0) {
|
|
||||||
close(p[0]);
|
|
||||||
dup(p[1], 1);
|
|
||||||
if(argc == 0) {
|
|
||||||
exec(av[0], av);
|
|
||||||
fprint(2, "exec gcc: %r\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
// Some versions of gcc do not accept -S with multiple files.
|
// Some versions of gcc do not accept -S with multiple files.
|
||||||
// Run gcc once for each file.
|
// Run gcc once for each file.
|
||||||
close(0);
|
// Write assembly and stabs debugging to p[1].
|
||||||
open("/dev/null", OREAD);
|
if(pipe(p) < 0)
|
||||||
for(i=0; i<argc; i++) {
|
sysfatal("pipe: %r");
|
||||||
pid = fork();
|
dup(p[1], 1);
|
||||||
if(pid < 0)
|
close(p[1]);
|
||||||
sysfatal("fork: %r");
|
if (argc)
|
||||||
if(pid == 0) {
|
av[n-1] = argv[i];
|
||||||
av[n-1] = argv[i];
|
pid = spawn(av[0], av);
|
||||||
exec(av[0], av);
|
dup(orig_output_fd, 1);
|
||||||
fprint(2, "exec gcc: %r\n");
|
|
||||||
exit(1);
|
// Read assembly, pulling out .stabs lines.
|
||||||
|
bin = Bfdopen(p[0], OREAD);
|
||||||
|
while((q = Brdstr(bin, '\n', 1)) != nil) {
|
||||||
|
// .stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
|
||||||
|
tofree = q;
|
||||||
|
while(*q == ' ' || *q == '\t')
|
||||||
|
q++;
|
||||||
|
if(strncmp(q, ".stabs", 6) != 0)
|
||||||
|
goto Continue;
|
||||||
|
q += 6;
|
||||||
|
while(*q == ' ' || *q == '\t')
|
||||||
|
q++;
|
||||||
|
if(*q++ != '\"') {
|
||||||
|
Bad:
|
||||||
|
sysfatal("cannot parse .stabs line:\n%s", tofree);
|
||||||
}
|
}
|
||||||
waitpid();
|
|
||||||
|
r = strchr(q, '\"');
|
||||||
|
if(r == nil)
|
||||||
|
goto Bad;
|
||||||
|
*r++ = '\0';
|
||||||
|
if(*r++ != ',')
|
||||||
|
goto Bad;
|
||||||
|
if(*r < '0' || *r > '9')
|
||||||
|
goto Bad;
|
||||||
|
if(atoi(r) != 128) // stabs kind = local symbol
|
||||||
|
goto Continue;
|
||||||
|
|
||||||
|
parsestabtype(q);
|
||||||
|
|
||||||
|
Continue:
|
||||||
|
free(tofree);
|
||||||
}
|
}
|
||||||
exit(0);
|
Bterm(bin);
|
||||||
|
waitfor(pid);
|
||||||
}
|
}
|
||||||
close(p[1]);
|
close(orig_output_fd);
|
||||||
|
|
||||||
// Read assembly, pulling out .stabs lines.
|
|
||||||
bin = Bfdopen(p[0], OREAD);
|
|
||||||
while((q = Brdstr(bin, '\n', 1)) != nil) {
|
|
||||||
// .stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
|
|
||||||
tofree = q;
|
|
||||||
while(*q == ' ' || *q == '\t')
|
|
||||||
q++;
|
|
||||||
if(strncmp(q, ".stabs", 6) != 0)
|
|
||||||
goto Continue;
|
|
||||||
q += 6;
|
|
||||||
while(*q == ' ' || *q == '\t')
|
|
||||||
q++;
|
|
||||||
if(*q++ != '\"') {
|
|
||||||
Bad:
|
|
||||||
sysfatal("cannot parse .stabs line:\n%s", tofree);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = strchr(q, '\"');
|
|
||||||
if(r == nil)
|
|
||||||
goto Bad;
|
|
||||||
*r++ = '\0';
|
|
||||||
if(*r++ != ',')
|
|
||||||
goto Bad;
|
|
||||||
if(*r < '0' || *r > '9')
|
|
||||||
goto Bad;
|
|
||||||
if(atoi(r) != 128) // stabs kind = local symbol
|
|
||||||
goto Continue;
|
|
||||||
|
|
||||||
parsestabtype(q);
|
|
||||||
|
|
||||||
Continue:
|
|
||||||
free(tofree);
|
|
||||||
}
|
|
||||||
Bterm(bin);
|
|
||||||
waitpid();
|
|
||||||
|
|
||||||
// Write defs to standard output.
|
// Write defs to standard output.
|
||||||
bout = Bfdopen(1, OWRITE);
|
bout = Bfdopen(1, OWRITE);
|
||||||
@ -283,7 +295,7 @@ main(int argc, char **argv)
|
|||||||
if(ncon > 0) {
|
if(ncon > 0) {
|
||||||
Bprint(bout, lang->constbegin);
|
Bprint(bout, lang->constbegin);
|
||||||
for(i=0; i<ncon; i++)
|
for(i=0; i<ncon; i++)
|
||||||
Bprint(bout, lang->constfmt, con[i].name, con[i].value);
|
Bprint(bout, lang->constfmt, con[i].name, con[i].value & 0xFFFFFFFF);
|
||||||
Bprint(bout, lang->constend);
|
Bprint(bout, lang->constend);
|
||||||
}
|
}
|
||||||
Bprint(bout, "\n");
|
Bprint(bout, "\n");
|
||||||
@ -340,7 +352,7 @@ main(int argc, char **argv)
|
|||||||
default: // numeric, array, or pointer
|
default: // numeric, array, or pointer
|
||||||
case Array:
|
case Array:
|
||||||
case Ptr:
|
case Ptr:
|
||||||
Bprint(bout, "%s %lT\n", lang->typdef, name, t);
|
Bprint(bout, "%s %lT%s", lang->typdef, name, t, lang->typdefend);
|
||||||
break;
|
break;
|
||||||
case Union:
|
case Union:
|
||||||
// In Go, print union as struct with only first element,
|
// In Go, print union as struct with only first element,
|
||||||
|
Loading…
Reference in New Issue
Block a user