Skip to content

Commit

Permalink
Merge pull request #6435 from The-OpenROAD-Project-staging/odb-rm-def…
Browse files Browse the repository at this point in the history
…ines

odb: rm some #defines from lef/def parser
  • Loading branch information
maliberty authored Dec 26, 2024
2 parents 526f8b6 + 0600294 commit ee94598
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 348 deletions.
2 changes: 1 addition & 1 deletion src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "geom.h"
#include "odb.h"

#define ADS_MAX_CORNER 10
constexpr int ADS_MAX_CORNER = 10;

namespace utl {
class Logger;
Expand Down
335 changes: 169 additions & 166 deletions src/odb/src/def/def/def.y

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/odb/src/def/def/def_keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ int defrData::defGetKeyword(const char* name, int* result)

if (search != settings->Keyword_set.end()) {
*result = search->second;
return TRUE;
return true;
}

return FALSE;
return false;
}

int defrData::defGetAlias(const std::string& name, std::string& result)
Expand All @@ -75,10 +75,10 @@ int defrData::defGetAlias(const std::string& name, std::string& result)

if (search != def_alias_set.end()) {
result = search->second;
return TRUE;
return true;
}

return FALSE;
return false;
}

int defrData::defGetDefine(const std::string& name, std::string& result)
Expand All @@ -88,10 +88,10 @@ int defrData::defGetDefine(const std::string& name, std::string& result)

if (search != def_defines_set.end()) {
result = search->second;
return TRUE;
return true;
}

return FALSE;
return false;
}

// lex.cpph starts here
Expand Down Expand Up @@ -200,7 +200,7 @@ int defrData::DefGetTokenFromStack(char* s)
else if (*ch == '\n') {
*s++ = *ch;
*s = 0;
return TRUE;
return true;
} else { /* we found something */
for (;; ch++) {
if (*ch == ' ' || *ch == '\t' || *ch == '\n' || *ch == 0) {
Expand All @@ -213,7 +213,7 @@ int defrData::DefGetTokenFromStack(char* s)
*s++ = '\0';
stack[input_level] = ch;

return TRUE;
return true;
}
/* 10/10/2000 - Wanda da Rosa, pcr 341032
** Save the location of the previous s
Expand All @@ -223,7 +223,7 @@ int defrData::DefGetTokenFromStack(char* s)
}
}
}
return FALSE; /* if we get here, we ran out of input levels */
return false; /* if we get here, we ran out of input levels */
}

void defrData::print_lines(long long lines)
Expand Down Expand Up @@ -281,7 +281,7 @@ int defrData::DefGetToken(char** buf, int* bufferSize)

if (input_level >= 0) { /* if we are expanding an alias */
if (DefGetTokenFromStack(s)) /* try to get a token from it */
return TRUE; /* if we get one, return it */
return true; /* if we get one, return it */
} /* but if not, continue */

/* skip blanks and count lines */
Expand All @@ -294,14 +294,14 @@ int defrData::DefGetToken(char** buf, int* bufferSize)
}

if (ch == EOF)
return FALSE;
return false;

if (ch == '\n') {
*s = ch;
IncCurPos(&s, buf, bufferSize);

*s = '\0';
return TRUE;
return true;
}

/* now get the token */
Expand All @@ -328,7 +328,7 @@ int defrData::DefGetToken(char** buf, int* bufferSize)
ch = GETC();
if ((ch == '\n') || (ch == EOF)) { /* senaty check */
*s = '\0';
return FALSE;
return false;
}
}
}
Expand All @@ -340,12 +340,12 @@ int defrData::DefGetToken(char** buf, int* bufferSize)

if (ch == EOF) {
*s = '\0';
return FALSE;
return false;
}
} while (ch != '"');

*s = '\0';
return TRUE;
return true;
}

if (names_case_sensitive) {
Expand Down Expand Up @@ -386,7 +386,7 @@ int defrData::DefGetToken(char** buf, int* bufferSize)
*s = '\0';
if (ch != EOF) /* shouldn't ungetc an EOF */
UNGETC((char) ch);
return TRUE;
return true;
}

/* creates an upper case copy of an array */
Expand Down
60 changes: 10 additions & 50 deletions src/odb/src/def/def/defiDefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,69 +41,40 @@ BEGIN_LEFDEF_PARSER_NAMESPACE

/*=================== General Types and Definitions =================*/

#ifndef TRUE
#define TRUE (1)
#endif

#ifndef FALSE
#define FALSE (0)
#endif

#ifndef NULL
#define NULL (0)
#endif

typedef struct defpoint defPOINT;

struct defpoint
struct defPOINT
{
int x;
int y;
};

typedef struct defrect defRECT;

struct defrect
struct defRECT
{
defPOINT ll, ur;
};

typedef struct deftoken defTOKEN;

struct deftoken
struct defTOKEN
{
defTOKEN* next;
int what;
int data;
defPOINT pt;
};

#define START_LIST 10001
#define POINT_SPEC 10002
#define VIA_SPEC 10003
#define WIDTH_SPEC 10004
#define LAYER_SPEC 10005
#define SHAPE_SPEC 10006

#define ROUND(x) ((x) >= 0 ? (int) ((x) + 0.5) : (int) ((x) -0.5))

// defTOKEN *TokenFromRect();

/*=================== Enumerated Types ============================*/
typedef int defiBoolean;
using defiBoolean = int;

/* Every type of object has a unique identifier, and each object
* which is created knows its type, by storing the defiObjectType_e
* as the first member in the structure.
*
*/
typedef enum
enum defiObjectType_e
{
/* decrease likelihood of accidentally correct values by starting
at an unusual number */
defiInvalidObject = 41713,
defiUnknownObject /* void * */
} defiObjectType_e;
};

/* The memory policy controls how an object which refers to or is composed of
* other objects manages those sub-objects, particularly when the parent
Expand Down Expand Up @@ -139,7 +110,7 @@ typedef enum
* made of a child sub-object, the memory policy of the child controls
* whether deep or shallow copies are made of the grandchildren.
*/
typedef enum
enum defiMemoryPolicy_e
{
/* decrease likelihood of accidentally correct values by starting
at an unusual number */
Expand All @@ -148,26 +119,15 @@ typedef enum
defiReferencedSubObjects, // shallow copy, no delete
defiOrphanSubObjects, // deep copy, no delete
defiAdoptedSubObjects // shallow copy + delete
} defiMemoryPolicy_e;
};

/* An opaque pointer for passing user data through from one API
* function to another.
* A handle which a user can set to point to their own data
* on a per-callback basis. (See the comment in defwWriter.h)
*/
#define defiUserData void*
#define defiUserDataHandle void**

/* On SunOs 4.1.3 with acc, this is in libansi.a, but isn't properly
* declared anywhere in the header files supplied with the compiler.
*/
#ifdef __SunOS_4_1_3
extern int strcasecmp(const char*, const char*);
#endif

#ifdef WIN32
#define strdup _strdup
#endif
using defiUserData = void*;
using defiUserDataHandle = void**;

END_LEFDEF_PARSER_NAMESPACE

Expand Down
4 changes: 2 additions & 2 deletions src/odb/src/def/def/defrData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defrData::defrData(const defrCallbacks* pCallbacks,
names_case_sensitive(1),
needNPCbk(0),
needSNPCbk(0),
nl_token(FALSE),
nl_token(false),
no_num(0),
nonDefaultWarnings(0),
nondef_is_keyword(0),
Expand Down Expand Up @@ -169,7 +169,7 @@ defrData::defrData(const defrCallbacks* pCallbacks,
xStep(0),
yStep(0),
NeedPathData(0),
shield(FALSE),
shield(false),
shiftBuf(nullptr),
shiftBufLength(0),
virtual_is_keyword(0),
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/def/def/defrData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ typedef union
int integer;
char* string;
int keyword; // really just a nop
struct defpoint pt;
defPOINT pt;
defTOKEN* tk;
} YYSTYPE;

Expand Down
4 changes: 2 additions & 2 deletions src/odb/src/def/def/defrReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2153,13 +2153,13 @@ void defrAddAlias(std::string_view key, std::string_view value, int marked)
void defrSetOpenLogFileAppend()
{
DEF_INIT;
defContext.settings->LogFileAppend = TRUE;
defContext.settings->LogFileAppend = true;
}

void defrUnsetOpenLogFileAppend()
{
DEF_INIT;
defContext.settings->LogFileAppend = FALSE;
defContext.settings->LogFileAppend = false;
}

void defrSetReadFunction(DEFI_READ_FUNCTION f)
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/def/def/defwWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "defwWriter.hpp"

#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
Expand Down Expand Up @@ -416,7 +417,7 @@ int defwInit(FILE* f,
case 10000:
case 16000:
case 20000:
fprintf(defwFile, "UNITS DISTANCE MICRONS %d ;\n", ROUND(units));
fprintf(defwFile, "UNITS DISTANCE MICRONS %ld ;\n", std::lround(units));
defwLines++;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/lef/clef/lefrReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "lefiTypedefs.h"

#define MAX_LEF_MSGS 4701
constexpr int MAX_LEF_MSGS = 4701;

/* The reader initialization. Must be called before lefrRead(). */
EXTERN int lefrInit();
Expand Down
20 changes: 10 additions & 10 deletions src/odb/src/lef/lef/lef.y
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ rule: version | busbitchars | case_sensitivity | units_section
case_sensitivity: K_NAMESCASESENSITIVE K_ON ';'
{
if (lefData->versionNum < 5.6) {
lefData->namesCaseSensitive = TRUE;
lefData->namesCaseSensitive = true;
if (lefCallbacks->CaseSensitiveCbk)
CALLBACK(lefCallbacks->CaseSensitiveCbk,
lefrCaseSensitiveCbkType,
Expand All @@ -500,7 +500,7 @@ case_sensitivity: K_NAMESCASESENSITIVE K_ON ';'
| K_NAMESCASESENSITIVE K_OFF ';'
{
if (lefData->versionNum < 5.6) {
lefData->namesCaseSensitive = FALSE;
lefData->namesCaseSensitive = false;
if (lefCallbacks->CaseSensitiveCbk)
CALLBACK(lefCallbacks->CaseSensitiveCbk, lefrCaseSensitiveCbkType,
lefData->namesCaseSensitive);
Expand Down Expand Up @@ -6511,15 +6511,15 @@ one_cap: K_MINPINS int_number K_WIRECAP int_number ';'
{ if (lefCallbacks->ArrayCbk) lefData->lefrArray.addDefaultCap((int)$2, $4); }

msg_statement:
K_MESSAGE {lefData->lefDumbMode=1;lefData->lefNlToken=TRUE;} T_STRING '=' s_expr dtrm
K_MESSAGE {lefData->lefDumbMode=1;lefData->lefNlToken=true;} T_STRING '=' s_expr dtrm
{ }

create_file_statement:
K_CREATEFILE {lefData->lefDumbMode=1;lefData->lefNlToken=TRUE;} T_STRING '=' s_expr dtrm
K_CREATEFILE {lefData->lefDumbMode=1;lefData->lefNlToken=true;} T_STRING '=' s_expr dtrm
{ }

def_statement:
K_DEFINE {lefData->lefDumbMode=1;lefData->lefNlToken=TRUE;} T_STRING '=' expression dtrm
K_DEFINE {lefData->lefDumbMode=1;lefData->lefNlToken=true;} T_STRING '=' expression dtrm
{
if (lefData->versionNum < 5.6)
lefAddNumDefine($3, $5);
Expand All @@ -6528,7 +6528,7 @@ def_statement:
if (lefData->arrayWarnings++ < lefSettings->ArrayWarnings)
lefWarning(2067, "DEFINE statement is obsolete in version 5.6 and later.\nThe LEF parser will ignore this statement.\nTo avoid this warning in the future, remove this statement from the LEF file with version 5.6 or later.");
}
| K_DEFINES {lefData->lefDumbMode=1;lefData->lefNlToken=TRUE;} T_STRING '=' s_expr dtrm
| K_DEFINES {lefData->lefDumbMode=1;lefData->lefNlToken=true;} T_STRING '=' s_expr dtrm
{
if (lefData->versionNum < 5.6)
lefAddStringDefine($3, $5);
Expand All @@ -6537,7 +6537,7 @@ def_statement:
if (lefData->arrayWarnings++ < lefSettings->ArrayWarnings)
lefWarning(2068, "DEFINES statement is obsolete in version 5.6 and later.\nThe LEF parser will ignore this statement.\nTo avoid this warning in the future, remove this statement from the LEF file with version 5.6 or later.");
}
| K_DEFINEB {lefData->lefDumbMode=1;lefData->lefNlToken=TRUE;} T_STRING '=' b_expr dtrm
| K_DEFINEB {lefData->lefDumbMode=1;lefData->lefNlToken=true;} T_STRING '=' b_expr dtrm
{
if (lefData->versionNum < 5.6)
lefAddBooleanDefine($3, $5);
Expand All @@ -6549,8 +6549,8 @@ def_statement:

// terminator for &defines. Can be semicolon or newline
dtrm:
| ';' {lefData->lefNlToken = FALSE;}
| '\n' {lefData->lefNlToken = FALSE;}
| ';' {lefData->lefNlToken = false;}
| '\n' {lefData->lefNlToken = false;}

then:
K_THEN
Expand Down Expand Up @@ -6602,7 +6602,7 @@ s_expr:
{ $$ = $2; }
| K_IF b_expr then s_expr else s_expr %prec IF
{
lefData->lefDefIf = TRUE;
lefData->lefDefIf = true;
if ($2 != 0) {
$$ = $4;
} else {
Expand Down
Loading

0 comments on commit ee94598

Please sign in to comment.