Commit 69792c72 authored by Duncan White's avatar Duncan White

removed some traces of m2datadec, imported in a couple of bug fixes from c-tools datadec

parent 2e8e630e
CC = gcc CC = gcc
#CC = cc #CC = cc
CFLAGS = -g -UDEBUGGING DEST = $(PREFIX)/usr
LINTFLAGS = -UDEBUGGING BINDIR = $(DEST)/bin
MANDIR = $(DEST)/man/man1
CFLAGS = -g -UDEBUGGING -Wall
LDLIBS =
EXECS = datadec EXECS = datadec
#EXECS = datadec m2datadec
datadec_srcs = datadec.c parser.c lexer.c struct.c decs.c optimize.c datadec_srcs = datadec.c parser.c lexer.c struct.c decs.c optimize.c
datadec_objs = datadec.o parser.o lexer.o struct.o decs.o optimize.o datadec_objs = datadec.o parser.o lexer.o struct.o decs.o optimize.o
m2datadec_srcs = datadec.c parser.c lexer.c struct.c m2decs.c optimize.c
m2datadec_objs = datadec.o parser.o lexer.o struct.o m2decs.o optimize.o
all: $(EXECS) all: $(EXECS)
install: install: $(EXECS)
install -m 755 datadec $(PREFIX)/usr/local/bin/datadec install -m 755 $(EXECS) $(BINDIR)
install -m 644 c-datadec.man $(PREFIX)/usr/man/man1/datadec.1 install -m 644 c-datadec.man $(MANDIR)/datadec.1
arch: $(EXECS)
cp -p $(EXECS) ../../$(ARCH)
cd ../../$(ARCH); chmod a+rx,ug+w $(EXECS)
clean: clean:
/bin/rm -f *.o a.out core $(EXECS) /bin/rm -f *.o a.out core $(EXECS)
lint: lint_datadec lint_m2datadec
lint_datadec: $(datadec_srcs)
lint $(LINTFLAGS) $(datadec_srcs) >lint_datadec 2>&1
lint_m2datadec: $(m2datadec_srcs)
lint $(LINTFLAGS) $(m2datadec_srcs) >lint_m2datadec 2>&1
m2datadec: $(m2datadec_objs)
$(CC) -g -o m2datadec $(m2datadec_objs)
datadec: $(datadec_objs) datadec: $(datadec_objs)
$(CC) -g -o datadec $(datadec_objs) $(CC) -g -o datadec $(datadec_objs)
datadec.o: datadec.c struct.h lexer.h parser.h decs.h optimize.h datadec.o: struct.h lexer.h parser.h decs.h optimize.h
decs.o: struct.h decs.h
decs.o: decs.c struct.h decs.h lexer.o: struct.h lexer.h
optimize.o: optimize.h struct.h
lexer.o: lexer.c struct.h lexer.h parser.o: struct.h lexer.h parser.h
struct.o: struct.h
m2decs.o: m2decs.c struct.h decs.h
optimize.o: optimize.h struct.h optimize.c
parser.o: parser.c struct.h lexer.h parser.h
struct.o: struct.c struct.h
...@@ -21,7 +21,6 @@ illist = nil ...@@ -21,7 +21,6 @@ illist = nil
idtree = leaf( string id, illist l ) idtree = leaf( string id, illist l )
| node( idtree left, idtree right ) | node( idtree left, idtree right )
; ;
</pre>
What does this mean? What does this mean?
The first rule declares that an intlist can take two basic "shapes" - The first rule declares that an intlist can take two basic "shapes" -
......
...@@ -43,10 +43,10 @@ The simplest use is to prepare an input file, such as ...@@ -43,10 +43,10 @@ The simplest use is to prepare an input file, such as
which might (for example) contain: which might (for example) contain:
.nf .nf
TYPE { TYPE {
IntList = Null or Cons( int first, IntList next ); intlist = nil or cons( int first, intlist next );
ILList = Null or Cons( IntList first, ILList next ); illist = nil or cons( intlist first, illist next );
IdTree = Leaf( string id ) idtree = leaf( string id )
or Node( IdTree left, IdTree right ); or node( idtree left, idtree right );
} }
.fi .fi
To generate C code implementing these types, invoke: To generate C code implementing these types, invoke:
...@@ -100,7 +100,7 @@ Similarly, the contents of the ...@@ -100,7 +100,7 @@ Similarly, the contents of the
.I "global" .I "global"
section are placed in the C file, section are placed in the C file,
again with `@@' being used to split the global section into "top of file" and again with `@@' being used to split the global section into "top of file" and
"bottom at file" pieces. "bottom of file" pieces.
.PP .PP
Similarly, the contents of the Similarly, the contents of the
...@@ -149,7 +149,9 @@ Each type name is simply an identifier. ...@@ -149,7 +149,9 @@ Each type name is simply an identifier.
also generates routines to write each type to an open FILE *. also generates routines to write each type to an open FILE *.
The method of printing each shape is governed by the presence or absence The method of printing each shape is governed by the presence or absence
of a print rule. If no print rule is given, the constructor name is printed, of a print rule. If no print rule is given, the constructor name is printed,
and then each parameter is written out using the appropriate print routine. then an open bracket,
then each parameter is written out using the appropriate print routine,
with commas separating the parameters, then a close bracket.
.PP .PP
If a print rule is given, each print element If a print rule is given, each print element
...@@ -162,26 +164,24 @@ whereas a number (eg. 4) means that the ...@@ -162,26 +164,24 @@ whereas a number (eg. 4) means that the
.PP .PP
For example, we could augment the For example, we could augment the
.I "IdTree" .I "idtree"
type from the example given above with print rules: type from the example given above with print rules:
.nf .nf
TYPE { TYPE {
IdTree = Leaf( string id ) "leaf(" 1 ")" idtree = leaf( string id ) "leaf(" 1 ")"
or Node( IdTree left, IdTree right ) "node(" 1 ",\\n" 2 ")"; or node( idtree left, idtree right ) "node( l=" 1 ", r=" 2 " )";
} }
.fi .fi
.PP .PP
Now, an IdTree constructed as Now, an idtree constructed as
.nf .nf
Node( Leaf( "hello" ), Node( Leaf( "there" ) ) ) node( leaf( "hello" ), node( leaf( "there" ), leaf( "how are you" ) ) )
.fi .fi
would print as: would print as:
.nf .nf
node(leaf("hello"), node( l=leaf("hello"), r=node(l=leaf("there"),r=leaf("how are you")))
.br
node(leaf("there")))
.fi .fi
.SH SEE ALSO .SH SEE ALSO
...@@ -189,14 +189,19 @@ node(leaf("there"))) ...@@ -189,14 +189,19 @@ node(leaf("there")))
LALR, REX, Miranda Language Definition. LALR, REX, Miranda Language Definition.
.fi .fi
.SH MISSING FEATURES
I must implement the missing free_TYPE functions sometime.
.PP
A cool extra would be a sprint_TYPE function to print into a string.
This should be a trivial modification on the code that prints to a file,
of course we don't know how long the generated string will need to be.
.SH BUGS .SH BUGS
Some single letter typenames (eg. "f" or "p") could clash with internal Some single letter typenames (eg. "f" or "p") could clash with internal
parameter names in the print routines, leading to syntax errors when you parameter names in the print routines, leading to syntax errors when you
compile the files generated by datadec. compile the files generated by datadec.
.PP .PP
Someday I'll get it to free up the types too!
.PP
And, finally, one day I'll have to write the C++ and Java versions :-) And, finally, one day I'll have to write the C++ and Java versions :-)
.SH "AUTHOR" .SH "AUTHOR"
Duncan C. White, D.White@surrey.ac.uk. Duncan C. White, D.White@imperial.ac.uk.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "struct.h" #include "struct.h"
#include "decs.h" #include "decs.h"
...@@ -85,6 +86,16 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d; ...@@ -85,6 +86,16 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
} }
static void literalline( mesg ) char *mesg;
{
int i;
for( i=numtabs; i; i-- ) fputc( '\t', outfile );
fputs( mesg, outfile );
nl();
}
void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base; void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base;
{ {
printf( "datadec: Making data declarations in %s.[ch]\n", base ); printf( "datadec: Making data declarations in %s.[ch]\n", base );
...@@ -154,7 +165,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; ...@@ -154,7 +165,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
{ {
nl(); nl();
line( "/* Remaining contents of EXPORT section */" ); line( "/* Remaining contents of EXPORT section */" );
line( exportptr ); literalline( exportptr );
nl(); nl();
} }
...@@ -182,7 +193,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de ...@@ -182,7 +193,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
line( " * Automatically Generated by DataDec" ); line( " * Automatically Generated by DataDec" );
line( " */\n" ); line( " */\n" );
line( "#include <stdio.h>" ); line( "#include <stdio.h>" );
line( "#include <malloc.h>" ); line( "#include <stdlib.h>" );
line( "#include \"%s.h\"\n\n", base ); line( "#include \"%s.h\"\n\n", base );
globalptr=globals; globalptr=globals;
...@@ -213,7 +224,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de ...@@ -213,7 +224,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
nl(); nl();
nl(); nl();
line( "/* Remaining contents of GLOBAL section */" ); line( "/* Remaining contents of GLOBAL section */" );
line( globalptr ); literalline( globalptr );
nl(); nl();
} }
...@@ -868,6 +879,10 @@ static void print_all_params( d, s ) declnlist d; shapelist s; ...@@ -868,6 +879,10 @@ static void print_all_params( d, s ) declnlist d; shapelist s;
for( p = s->params; p != NULL; p = p->next ) for( p = s->params; p != NULL; p = p->next )
{ {
print_param( s, p, d->Union ); print_param( s, p, d->Union );
if( p->next != NULL )
{
line( "fputc( ',', f );" );
}
} }
if( s->params ) if( s->params )
{ {
......
...@@ -140,7 +140,6 @@ static BOOL tail_optimize( d ) decln d; ...@@ -140,7 +140,6 @@ static BOOL tail_optimize( d ) decln d;
shapelist s; shapelist s;
printlist pl; printlist pl;
param p; param p;
int n;
for( s = d->shapes; s != NULL; s = s->next ) for( s = d->shapes; s != NULL; s = s->next )
{ {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <malloc.h> #include <stdlib.h>
#include "struct.h" #include "struct.h"
#include "lexer.h" #include "lexer.h"
#include "parser.h" #include "parser.h"
......
#INC = /vol/lab/include
CFLAGS = -g -UDEBUGGING CFLAGS = -g -UDEBUGGING
TESTEXECS = ctest TESTEXECS = ctest
AUTOCRAP = mtest.* mx.* ctest.* cx.? AUTOCRAP = ctest.* cx.[och]
all: $(TESTEXECS) all: $(TESTEXECS)
...@@ -11,21 +10,6 @@ clean: ...@@ -11,21 +10,6 @@ clean:
cx.c cx.h: cdata.in ../datadec cx.c cx.h: cdata.in ../datadec
../datadec cx cdata.in ../datadec cx cdata.in
cx.o: cx.c cx.h
ctest.o: ctest.c cx.h
ctest: ctest.o cx.o ctest: ctest.o cx.o
$(CC) -o ctest ctest.o cx.o cx.o: cx.h
ctest.o: cx.h
mx.def mx.mod: m2data.in ../src/m2datadec
../src/m2datadec mx m2data.in
mx.sym: mx.def
mx.o: mx.mod mx.sym
mtest.o: mtest.mod mx.sym
mtest: mtest.o mx.o
m2c $(M2FLAGS) $(M2LINKFLAGS) -o mtest -e mtest
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment