作者jans0204 (jans0204)
看板PLT
标题[实作] J005:AWKcc - awk-to-C transcompiler A
时间Tue Aug 23 05:53:23 2022
J005:AWKcc - awk-to-C transcompiler (PART A)
A. make awkcc.exe
1. 下载原始码 awkcc-main.zip
https://github.com/nokia/awkcc
2. 抽取 awkcc-main.zip\awkcc-main\1988\orig\awkcc\* -> R:\_W_\awkcc\
抽取 awkcc-main.zip\awkcc-main\2011\awkcc20\awkcc\awk.lx.c -> R:\_W_\awkcc\
3. 下载 yacc-1.9.3-1.mingw32.zip
https://sourceforge.net/projects/tiny-cobol/files/misc/yacc-1.9.3-1.mingw32.zip
4. 抽取 yacc-1.9.3-1.mingw32.zip\bin\yacc193.exe -> R:\_W_\awkcc\
5. 备份原档 -> R:\_W_\awkcc\prog\
mv awk.lx.l
mv awkcc.sh.basic
cp funcs.h
mv makefile
cp misc.c
cp type.c
mv y.tab.h
cp 表补钉,
flex 产生档:awk.lx.c 已复制,故 awk.lx.l 没用到,
y.tab.h 呼叫 yacc 会自动产生,token # 与旧档不一致,故备份留存。
6. 编写标头档:stdarg.h -> R:\_W_\awkcc\
/* stdarg.h */
#ifndef _VA_LIST_DEFINED
#define _VA_LIST_DEFINED
typedef char *va_list;
#endif
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
#define va_dcl va_list va_alist;
#define va_start(ap) ap = (va_list)&va_alist
#define va_arg(ap,t) ( *(t*)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
#define va_end(ap) ap = (va_list)0
7.1 PATCH - funcs.h LINE_14
//extern uchar *malloc();
//extern uchar *calloc();
//extern uchar *realloc();
extern void *malloc();
extern void *calloc();
extern void *realloc();
7.2 PATCH - misc.c LINE_15
//#include <varargs.h>
#include "stdarg.h"
7.3 PATCH - type.c
LINE_182
//uchar *malloc();
void *malloc();
LINE_653
//for (tmp=winner->narg[3]; tmp && strcmp(s, tmp->s); tmp=tmp->nnext)
for (tmp=winner->narg[3]; tmp && strcmp((const char*)s, tmp->s);
tmp=tmp->nnext)
7.4 编码 makefile
CC=gcc
CFLAGS=-O
LIBS=-lm
YFLAGS=-d
LFLAGS=-l
TARG=awk.g.o awk.lx.o main.o getopt.o prefuncall.o \
comp.o print.o arrstack.o node.o walk.o write.o \
type.o symtab.o stack.o tempvar.o emitstmt.o \
emitfunc.o emitppmm.o misc.o fix.o printop.o emit.o
awkcc.exe: $(TARG)
$(CC) $(CFLAGS) -o awkcc.exe $(TARG) $(LIBS)
strip awkcc.exe
clean:
rm -f *.o
8.1 产生 awk.g.c y.tab.h
R:\_W_\awkcc>set tmpdir=.
R:\_W_\awkcc>yacc193.exe -d awk.g.y > yacc.log 2>&1
ren y.tab.c awk.g.c
8.2 产生 awkcc.exe
进入 MSYS
$ cd /r/_W_/awkcc
$ make awkcc.exe > mk-exe.log 2>&1
$ make clean
rm -f *.o
8.3 安装:
md r:\awkcc\bin
mv awkcc.exe r:\awkcc\bin
8.4 编写 awk.sh.bat -> r:\awkcc\bin
set HEADERDIR=r:\awkcc\include
set AWKLIB=r:\awkcc\lib\libAWK.a
set MATHLIB=-lm
gcc -O -I%HEADERDIR% -o %2 %1 %AWKLIB% %MATHLIB%
strip %2
del awker.c
9. (To Be Continued)
https://github.com/jans0204/J005-AWKcc---awk-to-C-transcompiler/blob/main/J005:AWKcc - awk-to-C transcompiler (PART A).txt
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 124.218.31.163 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PLT/M.1661205207.A.A5E.html