Skip to content

Commit

Permalink
Merge pull request #6145 from WalterBright/add-dmsc.d
Browse files Browse the repository at this point in the history
convert msc.c to dmsc.d
  • Loading branch information
andralex committed Sep 21, 2016
2 parents cce7909 + f484bf1 commit 93596df
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 193 deletions.
13 changes: 8 additions & 5 deletions src/backend/cdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,15 @@ typedef unsigned short targ_ushort;
typedef int targ_long;
typedef unsigned targ_ulong;

#ifdef __UINT64_TYPE__
typedef __INT64_TYPE__ targ_llong;
typedef __UINT64_TYPE__ targ_ullong;
#if defined(__UINT64_TYPE__)
typedef __INT64_TYPE__ targ_llong;
typedef __UINT64_TYPE__ targ_ullong;
#elif defined(__UINTMAX_TYPE__)
typedef __INTMAX_TYPE__ targ_llong;
typedef __UINTMAX_TYPE__ targ_ullong;
#else
typedef long long targ_llong;
typedef unsigned long long targ_ullong;
typedef long long targ_llong;
typedef unsigned long long targ_ullong;
#endif

typedef float targ_float;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/divcoeff.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Source: https://github.com/dlang/dmd/blob/master/src/backend/divcoeff.c

#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ ullong;
#elif defined(__UINTMAX_TYPE__)
typedef __UINTMAX_TYPE__ ullong;
#else
typedef unsigned long long ullong;
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/backend/global.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ extern __gshared
symtab_t globsym;

// Config config; // precompiled part of configuration
Configv configv; // non-ph part of configuration
// char[SCMAX] sytab;

//volatile int controlc_saw; // a control C was seen
Expand All @@ -93,6 +92,8 @@ extern __gshared
Symbol* tls_get_addr_sym;
}

__gshared Configv configv; // non-ph part of configuration

// iasm.c
Symbol *asm_define_label(const(char)* id);

Expand Down Expand Up @@ -324,6 +325,7 @@ void symtab_free(Symbol **tab);
//#else
//#define symbol_keep(s) (()(s))
//#endif
void symbol_keep(Symbol *s) { }
void symbol_print(Symbol *s);
void symbol_term();
char *symbol_ident(Symbol *s);
Expand Down
4 changes: 3 additions & 1 deletion src/backend/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ void chkunass(elem *);
void chknoabstract(type *);
targ_llong msc_getnum();
targ_size_t alignmember(type *,targ_size_t,targ_size_t);
targ_size_t align(targ_size_t,targ_size_t);
//targ_size_t align(targ_size_t,targ_size_t);
targ_size_t _align(targ_size_t,targ_size_t);
#define align(a, b) _align(a, b)

/* nteh.c */
unsigned char *nteh_context_string();
Expand Down
195 changes: 195 additions & 0 deletions src/dmsc.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (c) 1999-2016 by Digital Mars, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(DMDSRC _dmsc.d)
*/

module ddmd.dmsc;

import core.stdc.stdio;
import core.stdc.string;
import core.stdc.stddef;

extern (C++):

import ddmd.globals;

import ddmd.root.filename;

import ddmd.backend.cc;
import ddmd.backend.cdef;
import ddmd.backend.global;
import ddmd.backend.ty;
import ddmd.backend.type;

/+
#include "mars.h"
#include "cc.h"
#include "global.h"
#include "oper.h"
#include "code.h"
#include "type.h"
#include "dt.h"
#include "cgcv.h"
extern Global global;
+/

__gshared Config config;

void out_config_init(
int model, // 32: 32 bit code
// 64: 64 bit code
// Windows: bit 0 set to generate MS-COFF instead of OMF
bool exe, // true: exe file
// false: dll or shared library (generate PIC code)
bool trace, // add profiling code
bool nofloat, // do not pull in floating point code
bool verbose, // verbose compile
bool optimize, // optimize code
int symdebug, // add symbolic debug information
// 1: D
// 2: fake it with C symbolic debug info
bool alwaysframe, // always create standard function frame
bool stackstomp // add stack stomping code
);

void out_config_debug(
bool debugb,
bool debugc,
bool debugf,
bool debugr,
bool debugw,
bool debugx,
bool debugy
);

/**************************************
* Initialize config variables.
*/

void backend_init()
{
//printf("out_config_init()\n");
Param *params = &global.params;

bool exe;
if (global.params.isWindows)
{
exe = false;
if (params.dll)
{
}
else if (params.run)
exe = true; // EXE file only optimizations
else if (params.link && !global.params.deffile)
exe = true; // EXE file only optimizations
else if (params.exefile) // if writing out EXE file
{ size_t len = strlen(params.exefile);
if (len >= 4 && FileName.compare(params.exefile + len - 3, "exe") == 0)
exe = true;
}
}
else if (global.params.isLinux ||
global.params.isOSX ||
global.params.isFreeBSD ||
global.params.isOpenBSD ||
global.params.isSolaris)
{
exe = params.pic == 0;
}

out_config_init(
(params.is64bit ? 64 : 32) | (params.mscoff ? 1 : 0),
exe,
false, //params.trace,
params.nofloat,
params.verbose,
params.optimize,
params.symdebug,
params.alwaysframe,
params.stackstomp
);

debug
{
out_config_debug(
params.debugb,
params.debugc,
params.debugf,
params.debugr,
false,
params.debugx,
params.debugy
);
}
}


/***********************************
* Return aligned 'offset' if it is of size 'size'.
*/

targ_size_t _align(targ_size_t size, targ_size_t offset)
{
switch (size)
{
case 1:
break;
case 2:
case 4:
case 8:
offset = (offset + size - 1) & ~(size - 1);
break;
default:
if (size >= 16)
offset = (offset + 15) & ~15;
else
offset = (offset + _tysize[TYnptr] - 1) & ~(_tysize[TYnptr] - 1);
break;
}
return offset;
}


/*******************************
* Get size of ty
*/

targ_size_t size(tym_t ty)
{
int sz = (tybasic(ty) == TYvoid) ? 1 : tysize(ty);
debug
{
if (sz == -1)
WRTYxx(ty);
}
assert(sz!= -1);
return sz;
}

/****************************
* Generate symbol of type ty at DATA:offset
*/

Symbol *symboldata(targ_size_t offset,tym_t ty)
{
Symbol *s = symbol_generate(SClocstat, type_fake(ty));
s.Sfl = FLdata;
s.Soffset = offset;
s.Stype.Tmangle = mTYman_d; // writes symbol unmodified in Obj::mangle
symbol_keep(s); // keep around
return s;
}

/**************************************
*/

void backend_term()
{
}

0 comments on commit 93596df

Please sign in to comment.