Skip to content

Commit

Permalink
Convert idgen to D
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed Feb 22, 2015
1 parent d30acc5 commit aa8a7b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
57 changes: 31 additions & 26 deletions src/idgen.c → src/idgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
// id.h
// id.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;

struct Msgtable
{
const char *ident; // name to use in DMD source
const char *name; // name in D executable
const(char)* ident; // name to use in DMD source
const(char)* name; // name in D executable
};

Msgtable msgtable[] =
{
Msgtable[] msgtable =
[
{ "IUnknown" },
{ "Object" },
{ "object" },
Expand Down Expand Up @@ -354,31 +353,34 @@ Msgtable msgtable[] =
{ "basic_ostream" },
{ "basic_iostream" },
{ "char_traits" },
};
];


int main()
{
FILE *fp;
unsigned i;
{
import std.stdio : writeln;
writeln("Generating id.c and id.h");
}

{
fp = fopen("id.h","w");
auto fp = fopen("id.h","w");
if (!fp)
{ printf("can't open id.h\n");
{
printf("can't open id.h\n");
exit(EXIT_FAILURE);
}

fprintf(fp, "// File generated by idgen.c\n");
fprintf(fp, "// File generated by idgen.d\n");
fprintf(fp, "#ifndef DMD_ID_H\n");
fprintf(fp, "#define DMD_ID_H 1\n");
fprintf(fp, "class Identifier;\n");
fprintf(fp, "struct Id\n");
fprintf(fp, "{\n");

for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
{ const char *id = msgtable[i].ident;

foreach(e; msgtable)
{
auto id = e.ident;
fprintf(fp," static Identifier *%s;\n", id);
}

Expand All @@ -390,19 +392,21 @@ int main()
}

{
fp = fopen("id.c","w");
auto fp = fopen("id.c","w");
if (!fp)
{ printf("can't open id.c\n");
{
printf("can't open id.c\n");
exit(EXIT_FAILURE);
}

fprintf(fp, "// File generated by idgen.c\n");
fprintf(fp, "// File generated by idgen.d\n");
fprintf(fp, "#include \"identifier.h\"\n");
fprintf(fp, "#include \"id.h\"\n");

for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
{ const char *id = msgtable[i].ident;
const char *p = msgtable[i].name;
foreach(e; msgtable)
{
auto id = e.ident;
auto p = e.name;

if (!p)
p = id;
Expand All @@ -412,9 +416,10 @@ int main()
fprintf(fp, "void Id::initialize()\n");
fprintf(fp, "{\n");

for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
{ const char *id = msgtable[i].ident;
const char *p = msgtable[i].name;
foreach(e; msgtable)
{
auto id = e.ident;
auto p = e.name;

if (!p)
p = id;
Expand Down
8 changes: 4 additions & 4 deletions src/posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ LDFLAGS=-lm -lstdc++ -lpthread
#endif
CC=$(HOST_CC) $(MODEL_FLAG)
GIT=git
HOST_DC?=dmd

# Compiler Warnings
ifdef ENABLE_WARNINGS
Expand Down Expand Up @@ -182,7 +183,7 @@ else
endif

SRC = win32.mak posix.mak osmodel.mak \
mars.c enum.c struct.c dsymbol.c import.c idgen.c impcnvgen.c \
mars.c enum.c struct.c dsymbol.c import.c idgen.d impcnvgen.c \
identifier.c mtype.c expression.c optimize.c template.h \
template.c lexer.c declaration.c cast.c cond.h cond.c link.c \
aggregate.h parse.c statement.c constfold.c version.h version.c \
Expand Down Expand Up @@ -306,9 +307,8 @@ $(optabgen_output) : optabgen
idgen_output = id.h id.c
$(idgen_output) : idgen

idgen : idgen.c
$(CC) idgen.c -o idgen
./idgen
idgen : idgen.d
$(HOST_DC) -run idgen

######### impcnvgen generates some source

Expand Down
9 changes: 4 additions & 5 deletions src/win32.mak
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ CFLAGS=-I$(INCLUDE) $(OPT) $(CFLAGS) $(DEBUG) -cpp -DTARGET_WINDOS=1 -DDM_TARGET
# Compile flags for modules with backend/toolkit dependencies
MFLAGS=-I$C;$(TK) $(OPT) -DMARS -cpp $(DEBUG) -e -wx -DTARGET_WINDOS=1 -DDM_TARGET_CPU_X86=1 -DDMDV2=1
# Recursive make
DMDMAKE=$(MAKE) -fwin32.mak C=$C TK=$(TK) ROOT=$(ROOT)
DMDMAKE=$(MAKE) -fwin32.mak C=$C TK=$(TK) ROOT=$(ROOT) HOST_DC=$(HOST_DC)

############################### Rule Variables ###############################

Expand Down Expand Up @@ -174,7 +174,7 @@ ROOTOBJS= man.obj port.obj checkedint.obj \
$(GCOBJS)

# D front end
SRCS= mars.c enum.c struct.c dsymbol.c import.c idgen.c impcnvgen.c utf.h \
SRCS= mars.c enum.c struct.c dsymbol.c import.c idgen.d impcnvgen.c utf.h \
utf.c entity.c identifier.c mtype.c expression.c optimize.c \
template.h template.c lexer.c declaration.c cast.c \
cond.h cond.c link.c aggregate.h staticassert.h parse.c statement.c \
Expand Down Expand Up @@ -376,9 +376,8 @@ impcnvtab.c : impcnvgen.c
$(CC) -I$(ROOT) -cpp -DDM_TARGET_CPU_X86=1 impcnvgen
.\impcnvgen.exe

id.h id.c : idgen.c
$(CC) -cpp -DDM_TARGET_CPU_X86=1 idgen
.\idgen.exe
id.h id.c : idgen.d
$(HOST_DC) -run idgen

verstr.h : ..\VERSION
echo "$(..\VERSION)" >verstr.h
Expand Down

0 comments on commit aa8a7b3

Please sign in to comment.