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

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

parent 2e8e630e
CC = gcc
#CC = cc
DEST = $(PREFIX)/usr
BINDIR = $(DEST)/bin
MANDIR = $(DEST)/man/man1
EXECS = datadec
#EXECS = datadec m2datadec
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
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)
install -m 755 datadec $(PREFIX)/usr/local/bin/datadec
install -m 644 $(PREFIX)/usr/man/man1/datadec.1
arch: $(EXECS)
cp -p $(EXECS) ../../$(ARCH)
cd ../../$(ARCH); chmod a+rx,ug+w $(EXECS)
install: $(EXECS)
install -m 755 $(EXECS) $(BINDIR)
install -m 644 $(MANDIR)/datadec.1
/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)
$(CC) -g -o datadec $(datadec_objs)
datadec.o: datadec.c struct.h lexer.h parser.h decs.h optimize.h
decs.o: decs.c struct.h decs.h
lexer.o: lexer.c struct.h lexer.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
datadec.o: struct.h lexer.h parser.h decs.h optimize.h
decs.o: struct.h decs.h
lexer.o: struct.h lexer.h
optimize.o: optimize.h struct.h
parser.o: struct.h lexer.h parser.h
struct.o: struct.h
......@@ -21,7 +21,6 @@ illist = nil
idtree = leaf( string id, illist l )
| node( idtree left, idtree right )
What does this mean?
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
which might (for example) contain:
IntList = Null or Cons( int first, IntList next );
ILList = Null or Cons( IntList first, ILList next );
IdTree = Leaf( string id )
or Node( IdTree left, IdTree right );
intlist = nil or cons( int first, intlist next );
illist = nil or cons( intlist first, illist next );
idtree = leaf( string id )
or node( idtree left, idtree right );
To generate C code implementing these types, invoke:
......@@ -100,7 +100,7 @@ Similarly, the contents of the
.I "global"
section are placed in the C file,
again with `@@' being used to split the global section into "top of file" and
"bottom at file" pieces.
"bottom of file" pieces.
Similarly, the contents of the
......@@ -149,7 +149,9 @@ Each type name is simply an identifier.
also generates routines to write each type to an open FILE *.
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,
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.
If a print rule is given, each print element
......@@ -162,26 +164,24 @@ whereas a number (eg. 4) means that the
For example, we could augment the
.I "IdTree"
.I "idtree"
type from the example given above with print rules:
IdTree = Leaf( string id ) "leaf(" 1 ")"
or Node( IdTree left, IdTree right ) "node(" 1 ",\\n" 2 ")";
idtree = leaf( string id ) "leaf(" 1 ")"
or node( idtree left, idtree right ) "node( l=" 1 ", r=" 2 " )";
Now, an IdTree constructed as
Now, an idtree constructed as
Node( Leaf( "hello" ), Node( Leaf( "there" ) ) )
node( leaf( "hello" ), node( leaf( "there" ), leaf( "how are you" ) ) )
would print as:
node( l=leaf("hello"), r=node(l=leaf("there"),r=leaf("how are you")))
......@@ -189,14 +189,19 @@ node(leaf("there")))
LALR, REX, Miranda Language Definition.
I must implement the missing free_TYPE functions sometime.
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.
Some single letter typenames (eg. "f" or "p") could clash with internal
parameter names in the print routines, leading to syntax errors when you
compile the files generated by datadec.
Someday I'll get it to free up the types too!
And, finally, one day I'll have to write the C++ and Java versions :-)
Duncan C. White,
Duncan C. White,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "struct.h"
#include "decs.h"
......@@ -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 );
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 );
......@@ -154,7 +165,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
line( "/* Remaining contents of EXPORT section */" );
line( exportptr );
literalline( exportptr );
......@@ -182,7 +193,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
line( " * Automatically Generated by DataDec" );
line( " */\n" );
line( "#include <stdio.h>" );
line( "#include <malloc.h>" );
line( "#include <stdlib.h>" );
line( "#include \"%s.h\"\n\n", base );
......@@ -213,7 +224,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
line( "/* Remaining contents of GLOBAL section */" );
line( globalptr );
literalline( globalptr );
......@@ -868,6 +879,10 @@ static void print_all_params( d, s ) declnlist d; shapelist s;
for( p = s->params; p != NULL; p = p->next )
print_param( s, p, d->Union );
if( p->next != NULL )
line( "fputc( ',', f );" );
if( s->params )
......@@ -140,7 +140,6 @@ static BOOL tail_optimize( d ) decln d;
shapelist s;
printlist pl;
param p;
int n;
for( s = d->shapes; s != NULL; s = s->next )
......@@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include "struct.h"
#include "lexer.h"
#include "parser.h"
#INC = /vol/lab/include
AUTOCRAP = mtest.* mx.* ctest.* cx.?
AUTOCRAP = ctest.* cx.[och]
......@@ -11,21 +10,6 @@ clean:
cx.c cx.h: ../datadec
../datadec cx
cx.o: cx.c cx.h
ctest.o: ctest.c cx.h
ctest: ctest.o cx.o
$(CC) -o ctest ctest.o cx.o
mx.def mx.mod: ../src/m2datadec
../src/m2datadec mx
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
cx.o: cx.h
ctest.o: cx.h
Supports Markdown
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