diff options
author | Russ Cox <rsc@golang.org> | 2009-08-24 16:15:21 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-08-24 16:15:21 -0700 |
commit | 848e9261c030e32aec6f3f8b13d6aa1a458f2f18 (patch) | |
tree | a65fa19b965ad5b4c2a0bacc21bb06f03a8bdd95 /src/cmd/cc/dpchk.c | |
parent | a04e55452a8b999d380bdfb3ea72603d42fd076e (diff) | |
download | golang-848e9261c030e32aec6f3f8b13d6aa1a458f2f18.tar.gz |
first attempt at real FFI support.
in a .6 file, an export line
//ffi T localfib remotefib remote.so
means the dynamic linker should initialize
localfib, always a pointer, to the address of
remotefib, either text (T) or data (D) after
loading remote.so.
the C compiler will generate an export section
when given the pragmas
#pragma package fib
#pragma ffi T localfib remotefib remote.so
needing #pragma package is a bit of a kludge
and hopefully could go away later.
this is just the 6 tool chain support.
other architectures will happen once 6 settles down.
code using this to do FFI is in a later CL.
R=r
DELTA=161 (141 added, 14 deleted, 6 changed)
OCL=33783
CL=33795
Diffstat (limited to 'src/cmd/cc/dpchk.c')
-rw-r--r-- | src/cmd/cc/dpchk.c | 100 |
1 files changed, 86 insertions, 14 deletions
diff --git a/src/cmd/cc/dpchk.c b/src/cmd/cc/dpchk.c index 9d22e621e..b1e988b87 100644 --- a/src/cmd/cc/dpchk.c +++ b/src/cmd/cc/dpchk.c @@ -200,13 +200,35 @@ arginit(void) flagbits['X'] = flagbits['o']; } +static char* +getquoted(void) +{ + int c; + char *t; + Rune r; + + c = getnsc(); + if(c != '"') + return nil; + t = fmtbuf; + for(;;) { + r = getr(); + if(r == ' ' || r == '\n') + return nil; + if(r == '"') + break; + t += runetochar(t, &r); + } + *t = 0; + return strdup(fmtbuf); +} + void pragvararg(void) { Sym *s; int n, c; char *t; - Rune r; Type *ty; if(!debug['F']) @@ -251,20 +273,9 @@ ckflag: cktype: /*#pragma varargck type O int*/ - c = getnsc(); - if(c != '"') + t = getquoted(); + if(t == nil) goto bad; - t = fmtbuf; - for(;;) { - r = getr(); - if(r == ' ' || r == '\n') - goto bad; - if(r == '"') - break; - t += runetochar(t, &r); - } - *t = 0; - t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; @@ -516,3 +527,64 @@ out: if(debug['f']) print("%s incomplete\n", s->name); } + +void +pragffi(void) +{ + Sym *local, *remote, *type; + char *path; + Ffi *f; + + type = getsym(); + if(type == nil) + goto err; + + local = getsym(); + if(local == nil) + goto err; + + remote = getsym(); + if(remote == nil) + goto err; + + path = getquoted(); + if(path == nil) + goto err; + + if(nffi%32 == 0) + ffi = realloc(ffi, (nffi+32)*sizeof ffi[0]); + f = &ffi[nffi++]; + f->type = type->name[0]; + f->local = local->name; + f->remote = remote->name; + f->path = path; + goto out; + +err: + yyerror("usage: #pragma ffi typechar local remote \"path\""); + +out: + while(getnsc() != '\n') + ; +} + +void +pragpackage(void) +{ + Sym *s; + + s = getsym(); + if(s == nil) + goto err; + + package = s->name; + goto out; + +err: + yyerror("malformed #pragma package"); + +out: + while(getnsc() != '\n') + ; +} + |