summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--8/main.c14
-rw-r--r--parse/infer.c5
-rw-r--r--parse/parse.h4
-rw-r--r--parse/use.c29
-rw-r--r--parse/util.c12
-rw-r--r--util/Makefile2
-rw-r--r--util/muse.c (renamed from util/main.c)6
7 files changed, 63 insertions, 9 deletions
diff --git a/8/main.c b/8/main.c
index 120e9a9..aef28f0 100644
--- a/8/main.c
+++ b/8/main.c
@@ -13,14 +13,18 @@
#include "opt.h"
#include "asm.h"
+/* FIXME: move into one place...? */
Node *file;
-static char *outfile;
int debug;
+char *outfile;
+char **incpaths;
+size_t nincpaths;
static void usage(char *prog)
{
printf("%s [-h] [-o outfile] inputs\n", prog);
printf("\t-h\tPrint this help\n");
+ printf("\t-I path\tAdd 'path' to use search path\n");
printf("\t-d\tPrint debug dumps\n");
printf("\t-o\tOutput to outfile\n");
}
@@ -31,15 +35,21 @@ int main(int argc, char **argv)
int i;
Stab *globls;
- while ((opt = getopt(argc, argv, "dho:")) != -1) {
+ while ((opt = getopt(argc, argv, "dho:I:")) != -1) {
switch (opt) {
case 'o':
outfile = optarg;
break;
case 'h':
+ usage(argv[0]);
+ exit(0);
+ break;
case 'd':
debug++;
break;
+ case 'I':
+ lappend(&incpaths, &nincpaths, optarg);
+ break;
default:
usage(argv[0]);
exit(0);
diff --git a/parse/infer.c b/parse/infer.c
index 05686c3..41afca6 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -87,8 +87,7 @@ static void loaduses(Node *n)
/* uses only allowed at top level. Do we want to keep it this way? */
for (i = 0; i < n->file.nuses; i++)
- fprintf(stderr, "INTERNAL: implement use loading\n");
- /* readuse(n->file.uses[i], n->file.globls); */
+ readuse(n->file.uses[i], n->file.globls);
}
static void settype(Node *n, Type *t)
@@ -143,7 +142,7 @@ static char *ctxstr(Node *n)
char *s;
switch (n->type) {
case Nexpr: s = opstr(exprop(n)); break;
- case Ndecl: s = declstr(n); break;
+ case Ndecl: s = declname(n); break;
case Nname: s = namestr(n); break;
default: s = nodestr(n->type); break;
}
diff --git a/parse/parse.h b/parse/parse.h
index 15dfa5b..9c295ec 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -261,6 +261,7 @@ void *xrealloc(void *p, size_t size);
void die(char *msg, ...);
void fatal(int line, char *fmt, ...);
char *strdupn(char *s, size_t len);
+char *strjoin(char *u, char *v);
void *memdup(void *mem, size_t len);
/* parsing etc */
@@ -374,3 +375,6 @@ void lfree(void *l, size_t *len);
/* Options to control the compilation */
extern int debug;
+extern char *outfile;
+extern char **incpaths;
+extern size_t nincpaths;
diff --git a/parse/use.c b/parse/use.c
index ff2cc4e..e306f6e 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -11,13 +11,38 @@
#include "parse.h"
+int loaduse(FILE *fd, Stab *st)
+{
+ return 1;
+}
+
void readuse(Node *use, Stab *st)
{
- die("Unimplmented use loading");
+ size_t i;
+ FILE *fd;
+ char *p;
+
+ /* local (quoted) uses are always relative to the cwd */
+ fd = NULL;
+ if (use->use.islocal) {
+ fd = fopen(use->use.name, "r");
+ /* nonlocal (barename) uses are always searched on the include path */
+ } else {
+ for (i = 0; i < nincpaths; i++) {
+ p = strjoin(incpaths[i], use->use.name);
+ fd = fopen(p, "r");
+ if (fd) {
+ free(p);
+ break;
+ }
+ }
+ }
+
+ if (loaduse(fd, st))
+ die("Could not load usefile %s", use->use.name);
}
void writeuse(Node *file, FILE *out)
{
- die("Unimplemented use writing");
}
diff --git a/parse/util.c b/parse/util.c
index f3b2983..bc12138 100644
--- a/parse/util.c
+++ b/parse/util.c
@@ -86,6 +86,18 @@ char *strdupn(char *s, size_t len)
return ret;
}
+char *strjoin(char *u, char *v)
+{
+ size_t n;
+ char *s;
+
+ n = strlen(u) + strlen(v) + 1;
+ s = xalloc(n);
+ strcpy(s, u);
+ strcat(s, v);
+ return s;
+}
+
void *memdup(void *mem, size_t len)
{
void *ret;
diff --git a/util/Makefile b/util/Makefile
index d649ecd..0b60228 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,5 +1,5 @@
BIN=muse
-OBJ=main.o
+OBJ=muse.o
DEPS=../parse/libparse.a
diff --git a/util/main.c b/util/muse.c
index 1255b76..325af40 100644
--- a/util/main.c
+++ b/util/muse.c
@@ -11,14 +11,18 @@
#include "parse.h"
+/* FIXME: move into one place...? */
Node *file;
-static char *outfile;
+char *outfile;
int debug;
+char **incpaths;
+size_t nincpaths;
static void usage(char *prog)
{
printf("%s [-h] [-o outfile] inputs\n", prog);
printf("\t-h\tPrint this help\n");
+ printf("\t-I path\tAdd 'path' to use search path\n");
printf("\t-d\tPrint debug dumps\n");
printf("\t-o\tOutput to outfile\n");
}