Skip to content

Commit

Permalink
thunk_gen: build process simplifications [#146]
Browse files Browse the repository at this point in the history
Get rid of gen_thunks.sh and tg_params.h.
Instead pass params to think_gen via cmdline.
  • Loading branch information
stsp committed Nov 10, 2023
1 parent f1d4076 commit 4e49cb3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
11 changes: 8 additions & 3 deletions fdpp/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TGZ = $(TAR).gz
FD_EXT_H = $(TOP)/include/fdpp
EXT_H = $(FD_EXT_H)/thunks.h $(FD_EXT_H)/bprm.h $(FD_EXT_H)/memtype.h
GEN_EXT = fdpp.pc
TFLAGS = -a 2 -p 2

GIT_REV := $(shell $(srcdir)/git-rev.sh)
GIT_DESCRIBE := $(shell git describe)
Expand Down Expand Up @@ -227,11 +228,15 @@ plt_asmc.h plt_asmp.h: thunk_asms.tmp
$(pars)

thunk_calls.h: thunk_calls.tmp parsers/thunk_gen
parsers/thunk_gen <$< >$@ || ($(RM) $@ ; false)
parsers/thunk_gen $(TFLAGS) <$< >$@ || ($(RM) $@ ; false)

thunk_asms.h: thunk_asms.tmp parsers/thunk_gen $(srcdir)/parsers/thunks.m4
$(srcdir)/parsers/gen_thunks.sh $< $(srcdir)/parsers >$@ || \
($(RM) $@ ; false)
parsers/thunk_gen $(TFLAGS) 1 <$< | sort | uniq | autom4te -l m4sugar $(srcdir)/parsers/thunks.m4 - >$@_ \
|| ($(RM) $@_ ; false)
parsers/thunk_gen $(TFLAGS) 2 <$< >$@__ \
|| ($(RM) $@__ ; false)
cat $@_ $@__ >$@
rm -f $@_ $@__

glob_asmdefs.h: $(SRC)/glob_asm.h
$(srcdir)/parsers/mkasmdefs.sh $< >$@
Expand Down
7 changes: 0 additions & 7 deletions fdpp/parsers/gen_thunks.sh

This file was deleted.

2 changes: 0 additions & 2 deletions fdpp/thunk_gen/tg_params.h

This file was deleted.

21 changes: 14 additions & 7 deletions fdpp/thunk_gen/thunk_gen.y
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include "tg_params.h"

#define YYDEBUG 1

static void yyerror(const char* s);
int yylex(void);

static int thunk_type;
static int ptr_size;
static int align;

static int arg_num;
static int arg_offs;
Expand Down Expand Up @@ -197,7 +198,7 @@ static void fin_arg(int last)
break;
}
if (is_ptr) {
real_arg_size = PTR_SIZE;
real_arg_size = ptr_size;
if (is_far)
real_arg_size *= 2;
} else {
Expand Down Expand Up @@ -242,11 +243,11 @@ static const char *get_flags(void)
}

#define AL(x) (((x) + (align - 1)) & ~(align - 1))
static const char *al_s_type = (align == 2 ? "WORD" : "DWORD");
static const char *al_u_type = (align == 2 ? "UWORD" : "UDWORD");
static const char *al_s_type(void) { return (align == 2 ? "WORD" : "DWORD"); }
static const char *al_u_type(void) { return (align == 2 ? "UWORD" : "UDWORD"); }
#define ATYPE3(s) \
if (al_arg_size > arg_size) \
strcat(atype3, al_##s##_type)
strcat(atype3, al_##s##_type())

%}

Expand Down Expand Up @@ -275,7 +276,7 @@ line: lnum rdecls fname lb args rb attrs SEMIC
if (is_rptr) {
rt = "_RET_PTR";
rv = "_ARG_RPTR";
rlen = PTR_SIZE;
rlen = ptr_size;
if (is_rfar) {
rlen *= 2;
rt = "_RET_PTR_FAR";
Expand Down Expand Up @@ -532,12 +533,18 @@ arg: adecls STRING arr

int main(int argc, char *argv[])
{
const char *optstr = "d";
const char *optstr = "dp:a:";
char c;
yydebug = 0;

while ((c = getopt(argc, argv, optstr)) != -1) {
switch (c) {
case 'a':
align = atoi(optarg);
break;
case 'p':
ptr_size = atoi(optarg);
break;
case 'd':
yydebug = 1;
break;
Expand Down

0 comments on commit 4e49cb3

Please sign in to comment.