mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 03:02:06 +00:00
Build everything as C++ (#1176)
This commit is contained in:
4
src/asm/.gitignore
vendored
4
src/asm/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
/parser.c
|
||||
/parser.h
|
||||
/parser.cpp
|
||||
/parser.hpp
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/charmap.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "hashmap.hpp"
|
||||
|
||||
// Charmaps are stored using a structure known as "trie".
|
||||
// Essentially a tree, where each nodes stores a single character's worth of info:
|
||||
@@ -49,12 +49,12 @@ struct CharmapStackEntry *charmapStack;
|
||||
|
||||
static struct Charmap *charmap_Get(char const *name)
|
||||
{
|
||||
return hash_GetElement(charmaps, name);
|
||||
return (struct Charmap *)hash_GetElement(charmaps, name);
|
||||
}
|
||||
|
||||
static void resizeCharmap(struct Charmap **map, size_t capacity)
|
||||
{
|
||||
*map = realloc(*map, sizeof(**map) + sizeof(*(*map)->nodes) * capacity);
|
||||
*map = (struct Charmap *)realloc(*map, sizeof(**map) + sizeof(*(*map)->nodes) * capacity);
|
||||
|
||||
if (!*map)
|
||||
fatalerror("Failed to %s charmap: %s\n",
|
||||
@@ -122,7 +122,7 @@ void charmap_Set(char const *name)
|
||||
|
||||
void charmap_Push(void)
|
||||
{
|
||||
struct CharmapStackEntry *stackEntry = malloc(sizeof(*stackEntry));
|
||||
struct CharmapStackEntry *stackEntry = (struct CharmapStackEntry *)malloc(sizeof(*stackEntry));
|
||||
|
||||
if (stackEntry == NULL)
|
||||
fatalerror("Failed to alloc charmap stack entry: %s\n", strerror(errno));
|
||||
@@ -6,9 +6,9 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
@@ -9,13 +9,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/format.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/format.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
struct FormatSpec fmt_NewSpec(void)
|
||||
{
|
||||
struct FormatSpec fmt = {0};
|
||||
struct FormatSpec fmt = {};
|
||||
|
||||
return fmt;
|
||||
}
|
||||
@@ -8,13 +8,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/macro.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "error.h"
|
||||
#include "platform.h" // S_ISDIR (stat macro)
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/macro.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
#include "error.hpp"
|
||||
#include "platform.hpp" // S_ISDIR (stat macro)
|
||||
|
||||
#define MAXINCPATHS 128
|
||||
|
||||
@@ -114,7 +114,7 @@ void fstk_AddIncludePath(char const *path)
|
||||
}
|
||||
size_t len = strlen(path);
|
||||
size_t allocSize = len + (path[len - 1] != '/') + 1;
|
||||
char *str = malloc(allocSize);
|
||||
char *str = (char *)malloc(allocSize);
|
||||
|
||||
if (!str) {
|
||||
// Attempt to continue without that path
|
||||
@@ -163,7 +163,7 @@ bool fstk_FindFile(char const *path, char **fullPath, size_t *size)
|
||||
{
|
||||
if (!*size) {
|
||||
*size = 64; // This is arbitrary, really
|
||||
*fullPath = realloc(*fullPath, *size);
|
||||
*fullPath = (char *)realloc(*fullPath, *size);
|
||||
if (!*fullPath)
|
||||
error("realloc error during include path search: %s\n",
|
||||
strerror(errno));
|
||||
@@ -183,7 +183,7 @@ bool fstk_FindFile(char const *path, char **fullPath, size_t *size)
|
||||
// Oh how I wish `asnprintf` was standard...
|
||||
if ((size_t)len >= *size) { // `size` includes the terminator, `len` doesn't
|
||||
*size = len + 1;
|
||||
*fullPath = realloc(*fullPath, *size);
|
||||
*fullPath = (char *)realloc(*fullPath, *size);
|
||||
if (!*fullPath) {
|
||||
error("realloc error during include path search: %s\n",
|
||||
strerror(errno));
|
||||
@@ -225,7 +225,7 @@ bool yywrap(void)
|
||||
// If the node is referenced, we can't edit it; duplicate it
|
||||
if (contextStack->fileInfo->referenced) {
|
||||
size_t size = sizeof(*fileInfo) + sizeof(fileInfo->iters[0]) * fileInfo->reptDepth;
|
||||
struct FileStackReptNode *copy = malloc(size);
|
||||
struct FileStackReptNode *copy = (struct FileStackReptNode *)malloc(size);
|
||||
|
||||
if (!copy)
|
||||
fatalerror("Failed to duplicate REPT file node: %s\n", strerror(errno));
|
||||
@@ -295,7 +295,7 @@ static void newContext(struct FileStackNode *fileInfo)
|
||||
// Save the current `\@` value, to be restored when this context ends
|
||||
contextStack->uniqueID = macro_GetUniqueID();
|
||||
|
||||
struct Context *context = malloc(sizeof(*context));
|
||||
struct Context *context = (struct Context *)malloc(sizeof(*context));
|
||||
|
||||
if (!context)
|
||||
fatalerror("Failed to allocate memory for new context: %s\n", strerror(errno));
|
||||
@@ -330,7 +330,8 @@ void fstk_RunInclude(char const *path)
|
||||
return;
|
||||
}
|
||||
|
||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
||||
struct FileStackNamedNode *fileInfo =
|
||||
(struct FileStackNamedNode *)malloc(sizeof(*fileInfo) + size);
|
||||
|
||||
if (!fileInfo) {
|
||||
error("Failed to alloc file info for INCLUDE: %s\n", strerror(errno));
|
||||
@@ -367,7 +368,8 @@ static void runPreIncludeFile(void)
|
||||
return;
|
||||
}
|
||||
|
||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
||||
struct FileStackNamedNode *fileInfo =
|
||||
(struct FileStackNamedNode *)malloc(sizeof(*fileInfo) + size);
|
||||
|
||||
if (!fileInfo) {
|
||||
error("Failed to alloc file info for pre-include: %s\n", strerror(errno));
|
||||
@@ -417,8 +419,8 @@ void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
||||
struct FileStackNamedNode const *baseNode = (struct FileStackNamedNode const *)node;
|
||||
size_t baseLen = strlen(baseNode->name);
|
||||
size_t macroNameLen = strlen(macro->name);
|
||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + baseLen
|
||||
+ reptNameLen + 2 + macroNameLen + 1);
|
||||
struct FileStackNamedNode *fileInfo = (struct FileStackNamedNode *)malloc(sizeof(*fileInfo) +
|
||||
baseLen + reptNameLen + 2 + macroNameLen + 1);
|
||||
|
||||
if (!fileInfo) {
|
||||
error("Failed to alloc file info for \"%s\": %s\n", macro->name, strerror(errno));
|
||||
@@ -461,8 +463,8 @@ static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
||||
uint32_t reptDepth = contextStack->fileInfo->type == NODE_REPT
|
||||
? ((struct FileStackReptNode *)contextStack->fileInfo)->reptDepth
|
||||
: 0;
|
||||
struct FileStackReptNode *fileInfo = malloc(sizeof(*fileInfo)
|
||||
+ (reptDepth + 1) * sizeof(fileInfo->iters[0]));
|
||||
struct FileStackReptNode *fileInfo = (struct FileStackReptNode *)malloc(sizeof(*fileInfo)
|
||||
+ (reptDepth + 1) * sizeof(fileInfo->iters[0]));
|
||||
|
||||
if (!fileInfo) {
|
||||
error("Failed to alloc file info for REPT: %s\n", strerror(errno));
|
||||
@@ -567,8 +569,9 @@ void fstk_Init(char const *mainPath, size_t maxDepth)
|
||||
lexer_SetState(state);
|
||||
char const *fileName = lexer_GetFileName();
|
||||
size_t len = strlen(fileName);
|
||||
struct Context *context = malloc(sizeof(*contextStack));
|
||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + len + 1);
|
||||
struct Context *context = (struct Context *)malloc(sizeof(*contextStack));
|
||||
struct FileStackNamedNode *fileInfo =
|
||||
(struct FileStackNamedNode *)malloc(sizeof(*fileInfo) + len + 1);
|
||||
|
||||
if (!context)
|
||||
fatalerror("Failed to allocate memory for main context: %s\n", strerror(errno));
|
||||
@@ -18,20 +18,20 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h" // For `ssize_t`
|
||||
#include "platform.hpp" // For `ssize_t` and `AT`
|
||||
|
||||
#include "asm/lexer.h"
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/format.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/macro.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/lexer.hpp"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/format.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/macro.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
// Include this last so it gets all type & constant definitions
|
||||
#include "parser.h" // For token definitions, generated from parser.y
|
||||
#include "parser.hpp" // For token definitions, generated from parser.y
|
||||
|
||||
// Neither MSVC nor MinGW provide `mmap`
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
@@ -390,7 +390,7 @@ uint32_t lexer_GetIFDepth(void)
|
||||
|
||||
void lexer_IncIFDepth(void)
|
||||
{
|
||||
struct IfStack *ifStack = malloc(sizeof(*ifStack));
|
||||
struct IfStack *ifStack = (struct IfStack *)malloc(sizeof(*ifStack));
|
||||
|
||||
if (!ifStack)
|
||||
fatalerror("Unable to allocate new IF depth: %s\n", strerror(errno));
|
||||
@@ -437,7 +437,7 @@ void lexer_ReachELSEBlock(void)
|
||||
struct LexerState *lexer_OpenFile(char const *path)
|
||||
{
|
||||
bool isStdin = !strcmp(path, "-");
|
||||
struct LexerState *state = malloc(sizeof(*state));
|
||||
struct LexerState *state = (struct LexerState *)malloc(sizeof(*state));
|
||||
struct stat fileInfo;
|
||||
|
||||
// Give stdin a nicer file name
|
||||
@@ -479,7 +479,7 @@ struct LexerState *lexer_OpenFile(char const *path)
|
||||
|
||||
state->isMmapped = true;
|
||||
state->isReferenced = false; // By default, a state isn't referenced
|
||||
state->ptr = mappingAddr;
|
||||
state->ptr = (char *)mappingAddr;
|
||||
assert(fileInfo.st_size >= 0);
|
||||
state->size = (size_t)fileInfo.st_size;
|
||||
state->offset = 0;
|
||||
@@ -510,7 +510,7 @@ struct LexerState *lexer_OpenFile(char const *path)
|
||||
|
||||
struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size, uint32_t lineNo)
|
||||
{
|
||||
struct LexerState *state = malloc(sizeof(*state));
|
||||
struct LexerState *state = (struct LexerState *)malloc(sizeof(*state));
|
||||
|
||||
if (!state) {
|
||||
error("Failed to allocate memory for lexer state: %s\n", strerror(errno));
|
||||
@@ -567,7 +567,7 @@ struct KeywordDictNode {
|
||||
uint16_t children[0x60 - ' '];
|
||||
struct KeywordMapping const *keyword;
|
||||
// Since the keyword structure is invariant, the min number of nodes is known at compile time
|
||||
} keywordDict[377] = {0}; // Make sure to keep this correct when adding keywords!
|
||||
} keywordDict[377] = {}; // Make sure to keep this correct when adding keywords!
|
||||
|
||||
// Convert a char into its index into the dict
|
||||
static uint8_t dictIndex(char c)
|
||||
@@ -637,7 +637,7 @@ static void reallocCaptureBuf(void)
|
||||
lexerState->captureCapacity = SIZE_MAX;
|
||||
else
|
||||
lexerState->captureCapacity *= 2;
|
||||
lexerState->captureBuf = realloc(lexerState->captureBuf, lexerState->captureCapacity);
|
||||
lexerState->captureBuf = (char *)realloc(lexerState->captureBuf, lexerState->captureCapacity);
|
||||
if (!lexerState->captureBuf)
|
||||
fatalerror("realloc error while resizing capture buffer: %s\n", strerror(errno));
|
||||
}
|
||||
@@ -653,7 +653,7 @@ static void beginExpansion(char const *str, bool owned, char const *name)
|
||||
if (name)
|
||||
lexer_CheckRecursionDepth();
|
||||
|
||||
struct Expansion *exp = malloc(sizeof(*exp));
|
||||
struct Expansion *exp = (struct Expansion *)malloc(sizeof(*exp));
|
||||
|
||||
if (!exp)
|
||||
fatalerror("Unable to allocate new expansion: %s\n", strerror(errno));
|
||||
@@ -2399,11 +2399,11 @@ int yylex(void)
|
||||
nextLine();
|
||||
|
||||
static int (* const lexerModeFuncs[])(void) = {
|
||||
[LEXER_NORMAL] = yylex_NORMAL,
|
||||
[LEXER_RAW] = yylex_RAW,
|
||||
[LEXER_SKIP_TO_ELIF] = yylex_SKIP_TO_ELIF,
|
||||
[LEXER_SKIP_TO_ENDC] = yylex_SKIP_TO_ENDC,
|
||||
[LEXER_SKIP_TO_ENDR] = yylex_SKIP_TO_ENDR,
|
||||
AT(LEXER_NORMAL) yylex_NORMAL,
|
||||
AT(LEXER_RAW) yylex_RAW,
|
||||
AT(LEXER_SKIP_TO_ELIF) yylex_SKIP_TO_ELIF,
|
||||
AT(LEXER_SKIP_TO_ENDC) yylex_SKIP_TO_ENDC,
|
||||
AT(LEXER_SKIP_TO_ENDR) yylex_SKIP_TO_ENDR,
|
||||
};
|
||||
int token = lexerModeFuncs[lexerState->mode]();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/macro.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/macro.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#define MAXMACROARGS 99999
|
||||
|
||||
@@ -26,7 +26,7 @@ struct MacroArgs {
|
||||
};
|
||||
|
||||
#define SIZEOF_ARGS(nbArgs) (sizeof(struct MacroArgs) + \
|
||||
sizeof(((struct MacroArgs){0}).args[0]) * (nbArgs))
|
||||
sizeof(((struct MacroArgs *)0)->args[0]) * (nbArgs))
|
||||
|
||||
static struct MacroArgs *macroArgs = NULL;
|
||||
static uint32_t uniqueID = 0;
|
||||
@@ -44,7 +44,7 @@ struct MacroArgs *macro_GetCurrentArgs(void)
|
||||
|
||||
struct MacroArgs *macro_NewArgs(void)
|
||||
{
|
||||
struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
|
||||
struct MacroArgs *args = (struct MacroArgs *)malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
|
||||
|
||||
if (!args)
|
||||
fatalerror("Unable to register macro arguments: %s\n", strerror(errno));
|
||||
@@ -67,7 +67,7 @@ void macro_AppendArg(struct MacroArgs **argPtr, char *s)
|
||||
// Check that overflow didn't roll us back
|
||||
if (macArgs->capacity <= macArgs->nbArgs)
|
||||
fatalerror("Failed to add new macro argument: capacity overflow\n");
|
||||
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
|
||||
macArgs = (struct MacroArgs *)realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
|
||||
if (!macArgs)
|
||||
fatalerror("Error adding new macro argument: %s\n", strerror(errno));
|
||||
}
|
||||
@@ -110,7 +110,7 @@ char const *macro_GetAllArgs(void)
|
||||
for (uint32_t i = macroArgs->shift; i < macroArgs->nbArgs; i++)
|
||||
len += strlen(macroArgs->args[i]) + 1; // 1 for comma
|
||||
|
||||
char *str = malloc(len + 1); // 1 for '\0'
|
||||
char *str = (char *)malloc(len + 1); // 1 for '\0'
|
||||
char *ptr = str;
|
||||
|
||||
if (!str)
|
||||
@@ -12,24 +12,24 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "asm/charmap.h"
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/format.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/lexer.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/opt.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "parser.h"
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/format.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/lexer.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/opt.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
#include "parser.hpp"
|
||||
|
||||
#include "extern/getopt.h"
|
||||
#include "extern/getopt.hpp"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "error.h"
|
||||
#include "version.h"
|
||||
#include "helpers.hpp"
|
||||
#include "error.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#ifdef __clang__
|
||||
#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
|
||||
@@ -40,7 +40,9 @@
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
// There are known, non-trivial to fix leaks. We would still like to have `make develop'
|
||||
// detect memory corruption, though.
|
||||
extern "C" {
|
||||
char const *__asan_default_options(void) { return "detect_leaks=0"; }
|
||||
}
|
||||
#endif
|
||||
|
||||
// Old Bison versions (confirmed for 2.3) do not forward-declare `yyparse` in the generated header
|
||||
@@ -63,7 +65,7 @@ bool warnings; // True to enable warnings, false to disable them.
|
||||
// Escapes Make-special chars from a string
|
||||
static char *make_escape(char const *str)
|
||||
{
|
||||
char * const escaped_str = malloc(strlen(str) * 2 + 1);
|
||||
char *escaped_str = (char *)malloc(strlen(str) * 2 + 1);
|
||||
char *dest = escaped_str;
|
||||
|
||||
if (escaped_str == NULL)
|
||||
@@ -166,7 +168,7 @@ int main(int argc, char *argv[])
|
||||
warnings = true;
|
||||
sym_SetExportAll(false);
|
||||
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
|
||||
char *dependFileName = NULL;
|
||||
char const *dependFileName = NULL;
|
||||
size_t targetFileNameLen = 0;
|
||||
|
||||
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1;) {
|
||||
@@ -333,7 +335,7 @@ int main(int argc, char *argv[])
|
||||
newTarget = make_escape(newTarget);
|
||||
size_t newTargetLen = strlen(newTarget) + 1; // Plus the space
|
||||
|
||||
targetFileName = realloc(targetFileName,
|
||||
targetFileName = (char *)realloc(targetFileName,
|
||||
targetFileNameLen + newTargetLen + 1);
|
||||
if (targetFileName == NULL)
|
||||
err("Cannot append new file to target file list");
|
||||
@@ -8,12 +8,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/lexer.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/lexer.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
static constexpr size_t numWarningStates = sizeof(warningStates);
|
||||
|
||||
struct OptStackEntry {
|
||||
char binary[2];
|
||||
@@ -26,8 +28,7 @@ struct OptStackEntry {
|
||||
bool warnOnLdOpt;
|
||||
bool warningsAreErrors;
|
||||
size_t maxRecursionDepth;
|
||||
// Don't be confused: we use the size of the **global variable** `warningStates`!
|
||||
enum WarningState warningStates[sizeof(warningStates)];
|
||||
enum WarningState warningStates[numWarningStates];
|
||||
struct OptStackEntry *next;
|
||||
};
|
||||
|
||||
@@ -241,12 +242,12 @@ void opt_Parse(char *s)
|
||||
|
||||
void opt_Push(void)
|
||||
{
|
||||
struct OptStackEntry *entry = malloc(sizeof(*entry));
|
||||
struct OptStackEntry *entry = (struct OptStackEntry *)malloc(sizeof(*entry));
|
||||
|
||||
if (entry == NULL)
|
||||
fatalerror("Failed to alloc option stack entry: %s\n", strerror(errno));
|
||||
|
||||
// Both of these pulled from lexer.h
|
||||
// Both of these pulled from lexer.hpp
|
||||
entry->binary[0] = binDigits[0];
|
||||
entry->binary[1] = binDigits[1];
|
||||
|
||||
@@ -255,19 +256,19 @@ void opt_Push(void)
|
||||
entry->gbgfx[2] = gfxDigits[2];
|
||||
entry->gbgfx[3] = gfxDigits[3];
|
||||
|
||||
entry->fixPrecision = fixPrecision; // Pulled from fixpoint.h
|
||||
entry->fixPrecision = fixPrecision; // Pulled from fixpoint.hpp
|
||||
|
||||
entry->fillByte = fillByte; // Pulled from section.h
|
||||
entry->fillByte = fillByte; // Pulled from section.hpp
|
||||
|
||||
entry->haltNop = haltNop; // Pulled from main.h
|
||||
entry->haltNop = haltNop; // Pulled from main.hpp
|
||||
entry->warnOnHaltNop = warnOnHaltNop;
|
||||
|
||||
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
|
||||
entry->optimizeLoads = optimizeLoads; // Pulled from main.hpp
|
||||
entry->warnOnLdOpt = warnOnLdOpt;
|
||||
|
||||
// Both of these pulled from warning.h
|
||||
// Both of these pulled from warning.hpp
|
||||
entry->warningsAreErrors = warningsAreErrors;
|
||||
memcpy(entry->warningStates, warningStates, sizeof(warningStates));
|
||||
memcpy(entry->warningStates, warningStates, numWarningStates);
|
||||
|
||||
entry->maxRecursionDepth = maxRecursionDepth; // Pulled from fstack.h
|
||||
|
||||
@@ -296,7 +297,7 @@ void opt_Pop(void)
|
||||
|
||||
// opt_W does not apply a whole warning state; it processes one flag string
|
||||
warningsAreErrors = entry->warningsAreErrors;
|
||||
memcpy(warningStates, entry->warningStates, sizeof(warningStates));
|
||||
memcpy(warningStates, entry->warningStates, numWarningStates);
|
||||
|
||||
stack = entry->next;
|
||||
free(entry);
|
||||
@@ -10,18 +10,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/charmap.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "error.h"
|
||||
#include "linkdefs.h"
|
||||
#include "platform.h" // strdup
|
||||
#include "error.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
#include "platform.hpp" // strdup
|
||||
|
||||
struct Patch {
|
||||
struct FileStackNode const *src;
|
||||
@@ -366,14 +366,14 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||
// WARNING: all patches are assumed to eventually be written, so the file stack node is registered
|
||||
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
|
||||
{
|
||||
struct Patch *patch = malloc(sizeof(struct Patch));
|
||||
struct Patch *patch = (struct Patch *)malloc(sizeof(*patch));
|
||||
uint32_t rpnSize = expr->isKnown ? 5 : expr->rpnPatchSize;
|
||||
struct FileStackNode *node = fstk_GetFileStack();
|
||||
|
||||
if (!patch)
|
||||
fatalerror("No memory for patch: %s\n", strerror(errno));
|
||||
|
||||
patch->rpn = malloc(sizeof(*patch->rpn) * rpnSize);
|
||||
patch->rpn = (uint8_t *)malloc(sizeof(*patch->rpn) * rpnSize);
|
||||
if (!patch->rpn)
|
||||
fatalerror("No memory for patch's RPN rpnSize: %s\n", strerror(errno));
|
||||
|
||||
@@ -421,7 +421,7 @@ void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs,
|
||||
bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
|
||||
char const *message, uint32_t ofs)
|
||||
{
|
||||
struct Assertion *assertion = malloc(sizeof(*assertion));
|
||||
struct Assertion *assertion = (struct Assertion *)malloc(sizeof(*assertion));
|
||||
|
||||
if (!assertion)
|
||||
return false;
|
||||
@@ -10,25 +10,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/charmap.h"
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/format.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/lexer.h"
|
||||
#include "asm/macro.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/opt.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/format.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/lexer.hpp"
|
||||
#include "asm/macro.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/opt.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "extern/utf8decoder.h"
|
||||
#include "extern/utf8decoder.hpp"
|
||||
|
||||
#include "linkdefs.h"
|
||||
#include "platform.h" // strncasecmp, strdup
|
||||
#include "linkdefs.hpp"
|
||||
#include "platform.hpp" // strncasecmp, strdup
|
||||
|
||||
static struct CaptureBody captureBody; // Captures a REPT/FOR or MACRO
|
||||
|
||||
@@ -257,7 +257,7 @@ static void initStrFmtArgList(struct StrFmtArgList *args)
|
||||
{
|
||||
args->nbArgs = 0;
|
||||
args->capacity = INITIAL_STRFMT_ARG_SIZE;
|
||||
args->args = malloc(args->capacity * sizeof(*args->args));
|
||||
args->args = (struct StrFmtArg *)malloc(args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("Failed to allocate memory for STRFMT arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -267,7 +267,7 @@ static size_t nextStrFmtArgListIndex(struct StrFmtArgList *args)
|
||||
{
|
||||
if (args->nbArgs == args->capacity) {
|
||||
args->capacity = (args->capacity + 1) * 2;
|
||||
args->args = realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
args->args = (struct StrFmtArg *)realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("realloc error while resizing STRFMT arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -369,7 +369,7 @@ static void initDsArgList(struct DsArgList *args)
|
||||
{
|
||||
args->nbArgs = 0;
|
||||
args->capacity = INITIAL_DS_ARG_SIZE;
|
||||
args->args = malloc(args->capacity * sizeof(*args->args));
|
||||
args->args = (struct Expression *)malloc(args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("Failed to allocate memory for ds arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -379,7 +379,7 @@ static void appendDsArgList(struct DsArgList *args, const struct Expression *exp
|
||||
{
|
||||
if (args->nbArgs == args->capacity) {
|
||||
args->capacity = (args->capacity + 1) * 2;
|
||||
args->args = realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
args->args = (struct Expression *)realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("realloc error while resizing ds arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -396,7 +396,7 @@ static void initPurgeArgList(struct PurgeArgList *args)
|
||||
{
|
||||
args->nbArgs = 0;
|
||||
args->capacity = INITIAL_PURGE_ARG_SIZE;
|
||||
args->args = malloc(args->capacity * sizeof(*args->args));
|
||||
args->args = (char **)malloc(args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("Failed to allocate memory for purge arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -406,7 +406,7 @@ static void appendPurgeArgList(struct PurgeArgList *args, char *arg)
|
||||
{
|
||||
if (args->nbArgs == args->capacity) {
|
||||
args->capacity = (args->capacity + 1) * 2;
|
||||
args->args = realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
args->args = (char **)realloc(args->args, args->capacity * sizeof(*args->args));
|
||||
if (!args->args)
|
||||
fatalerror("realloc error while resizing purge arg list: %s\n",
|
||||
strerror(errno));
|
||||
@@ -966,21 +966,23 @@ assignment : T_LABEL T_POP_EQUAL const {
|
||||
sym_AddVar($1, $3);
|
||||
}
|
||||
| T_LABEL compoundeq const {
|
||||
static const char *compoundEqOperators[] = {
|
||||
[RPN_ADD] = "+=",
|
||||
[RPN_SUB] = "-=",
|
||||
[RPN_MUL] = "*=",
|
||||
[RPN_DIV] = "/=",
|
||||
[RPN_MOD] = "%=",
|
||||
[RPN_XOR] = "^=",
|
||||
[RPN_OR] = "|=",
|
||||
[RPN_AND] = "&=",
|
||||
[RPN_SHL] = "<<=",
|
||||
[RPN_SHR] = ">>=",
|
||||
};
|
||||
const char *compoundEqOperator = NULL;
|
||||
switch ($2) {
|
||||
case RPN_ADD: compoundEqOperator = "+="; break;
|
||||
case RPN_SUB: compoundEqOperator = "-="; break;
|
||||
case RPN_MUL: compoundEqOperator = "*="; break;
|
||||
case RPN_DIV: compoundEqOperator = "/="; break;
|
||||
case RPN_MOD: compoundEqOperator = "%="; break;
|
||||
case RPN_XOR: compoundEqOperator = "^="; break;
|
||||
case RPN_OR: compoundEqOperator = "|="; break;
|
||||
case RPN_AND: compoundEqOperator = "&="; break;
|
||||
case RPN_SHL: compoundEqOperator = "<<="; break;
|
||||
case RPN_SHR: compoundEqOperator = ">>="; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
warning(WARNING_OBSOLETE, "`%s %s` is deprecated; use `DEF %s %s`\n",
|
||||
$1, compoundEqOperators[$2], $1, compoundEqOperators[$2]);
|
||||
$1, compoundEqOperator, $1, compoundEqOperator);
|
||||
compoundAssignment($1, $2, $3);
|
||||
}
|
||||
;
|
||||
@@ -1106,7 +1108,7 @@ shift : T_POP_SHIFT { macro_ShiftCurrentArgs(1); }
|
||||
;
|
||||
|
||||
load : T_POP_LOAD sectmod string T_COMMA sectiontype sectorg sectattrs {
|
||||
sect_SetLoadSection($3, $5, $6, &$7, $2);
|
||||
sect_SetLoadSection($3, (enum SectionType)$5, $6, &$7, $2);
|
||||
}
|
||||
| T_POP_ENDL { sect_EndLoadSection(); }
|
||||
;
|
||||
@@ -1365,7 +1367,7 @@ constlist_8bit_entry : reloc_8bit_no_str {
|
||||
sect_RelByte(&$1, 0);
|
||||
}
|
||||
| string {
|
||||
uint8_t *output = malloc(strlen($1)); // Cannot be larger than that
|
||||
uint8_t *output = (uint8_t *)malloc(strlen($1)); // Cannot be larger than that
|
||||
size_t length = charmap_Convert($1, output);
|
||||
|
||||
sect_AbsByteGroup(output, length);
|
||||
@@ -1381,7 +1383,7 @@ constlist_16bit_entry : reloc_16bit_no_str {
|
||||
sect_RelWord(&$1, 0);
|
||||
}
|
||||
| string {
|
||||
uint8_t *output = malloc(strlen($1)); // Cannot be larger than that
|
||||
uint8_t *output = (uint8_t *)malloc(strlen($1)); // Cannot be larger than that
|
||||
size_t length = charmap_Convert($1, output);
|
||||
|
||||
sect_AbsWordGroup(output, length);
|
||||
@@ -1398,7 +1400,7 @@ constlist_32bit_entry : relocexpr_no_str {
|
||||
}
|
||||
| string {
|
||||
// Charmaps cannot increase the length of a string
|
||||
uint8_t *output = malloc(strlen($1));
|
||||
uint8_t *output = (uint8_t *)malloc(strlen($1));
|
||||
size_t length = charmap_Convert($1, output);
|
||||
|
||||
sect_AbsLongGroup(output, length);
|
||||
@@ -1444,7 +1446,7 @@ reloc_16bit_no_str : relocexpr_no_str {
|
||||
relocexpr : relocexpr_no_str
|
||||
| string {
|
||||
// Charmaps cannot increase the length of a string
|
||||
uint8_t *output = malloc(strlen($1));
|
||||
uint8_t *output = (uint8_t *)malloc(strlen($1));
|
||||
uint32_t length = charmap_Convert($1, output);
|
||||
uint32_t r = str2int2(output, length);
|
||||
|
||||
@@ -1531,8 +1533,12 @@ relocexpr_no_str : scoped_anon_id { rpn_Symbol(&$$, $1); }
|
||||
| T_OP_BANK T_LPAREN string T_RPAREN { rpn_BankSection(&$$, $3); }
|
||||
| T_OP_SIZEOF T_LPAREN string T_RPAREN { rpn_SizeOfSection(&$$, $3); }
|
||||
| T_OP_STARTOF T_LPAREN string T_RPAREN { rpn_StartOfSection(&$$, $3); }
|
||||
| T_OP_SIZEOF T_LPAREN sectiontype T_RPAREN { rpn_SizeOfSectionType(&$$, $3); }
|
||||
| T_OP_STARTOF T_LPAREN sectiontype T_RPAREN { rpn_StartOfSectionType(&$$, $3); }
|
||||
| T_OP_SIZEOF T_LPAREN sectiontype T_RPAREN {
|
||||
rpn_SizeOfSectionType(&$$, (enum SectionType)$3);
|
||||
}
|
||||
| T_OP_STARTOF T_LPAREN sectiontype T_RPAREN {
|
||||
rpn_StartOfSectionType(&$$, (enum SectionType)$3);
|
||||
}
|
||||
| T_OP_DEF {
|
||||
lexer_ToggleStringExpansion(false);
|
||||
} T_LPAREN scoped_anon_id T_RPAREN {
|
||||
@@ -1730,7 +1736,7 @@ strfmt_va_args : %empty {
|
||||
;
|
||||
|
||||
section : T_POP_SECTION sectmod string T_COMMA sectiontype sectorg sectattrs {
|
||||
sect_NewSection($3, $5, $6, &$7, $2);
|
||||
sect_NewSection($3, (enum SectionType)$5, $6, &$7, $2);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -11,26 +11,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/main.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "opmath.h"
|
||||
#include "opmath.hpp"
|
||||
|
||||
// Makes an expression "not known", also setting its error message
|
||||
#define makeUnknown(expr_, ...) do { \
|
||||
struct Expression *_expr = expr_; \
|
||||
_expr->isKnown = false; \
|
||||
/* If we had `asprintf` this would be great, but alas. */ \
|
||||
_expr->reason = malloc(128); /* Use an initial reasonable size */ \
|
||||
_expr->reason = (char *)malloc(128); /* Use an initial reasonable size */ \
|
||||
if (!_expr->reason) \
|
||||
fatalerror("Can't allocate err string: %s\n", strerror(errno)); \
|
||||
int size = snprintf(_expr->reason, 128, __VA_ARGS__); \
|
||||
if (size >= 128) { /* If this wasn't enough, try again */ \
|
||||
_expr->reason = realloc(_expr->reason, size + 1); \
|
||||
_expr->reason = (char *)realloc(_expr->reason, size + 1); \
|
||||
if (!_expr->reason) \
|
||||
fatalerror("Can't allocate err string: %s\n", strerror(errno)); \
|
||||
sprintf(_expr->reason, __VA_ARGS__); \
|
||||
@@ -55,7 +55,7 @@ static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
|
||||
else
|
||||
expr->rpnCapacity *= 2;
|
||||
}
|
||||
expr->rpn = realloc(expr->rpn, expr->rpnCapacity);
|
||||
expr->rpn = (uint8_t *)realloc(expr->rpn, expr->rpnCapacity);
|
||||
|
||||
if (!expr->rpn)
|
||||
fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
|
||||
@@ -550,8 +550,8 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||
// Convert the left-hand expression if it's constant
|
||||
if (src1->isKnown) {
|
||||
uint32_t lval = src1->val;
|
||||
uint8_t bytes[] = {RPN_CONST, lval, lval >> 8,
|
||||
lval >> 16, lval >> 24};
|
||||
uint8_t bytes[] = {RPN_CONST, (uint8_t)lval, (uint8_t)(lval >> 8),
|
||||
(uint8_t)(lval >> 16), (uint8_t)(lval >> 24)};
|
||||
expr->rpnPatchSize = sizeof(bytes);
|
||||
expr->rpn = NULL;
|
||||
expr->rpnCapacity = 0;
|
||||
@@ -579,8 +579,8 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||
|
||||
// If the right expression is constant, merge a shim instead
|
||||
uint32_t rval = src2->val;
|
||||
uint8_t bytes[] = {RPN_CONST, rval, rval >> 8, rval >> 16,
|
||||
rval >> 24};
|
||||
uint8_t bytes[] = {RPN_CONST, (uint8_t)rval, (uint8_t)(rval >> 8),
|
||||
(uint8_t)(rval >> 16), (uint8_t)(rval >> 24)};
|
||||
if (src2->isKnown) {
|
||||
ptr = bytes;
|
||||
len = sizeof(bytes);
|
||||
@@ -8,17 +8,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "error.h"
|
||||
#include "linkdefs.h"
|
||||
#include "platform.h" // strdup
|
||||
#include "error.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
#include "platform.hpp" // strdup
|
||||
|
||||
uint8_t fillByte;
|
||||
|
||||
@@ -265,7 +265,7 @@ static struct Section *createSection(char const *name, enum SectionType type,
|
||||
uint32_t org, uint32_t bank, uint8_t alignment,
|
||||
uint16_t alignOffset, enum SectionModifier mod)
|
||||
{
|
||||
struct Section *sect = malloc(sizeof(*sect));
|
||||
struct Section *sect = (struct Section *)malloc(sizeof(*sect));
|
||||
|
||||
if (sect == NULL)
|
||||
fatalerror("Not enough memory for section: %s\n", strerror(errno));
|
||||
@@ -288,7 +288,7 @@ static struct Section *createSection(char const *name, enum SectionType type,
|
||||
|
||||
// It is only needed to allocate memory for ROM sections.
|
||||
if (sect_HasData(type)) {
|
||||
sect->data = malloc(sectionTypeInfo[type].size);
|
||||
sect->data = (uint8_t *)malloc(sectionTypeInfo[type].size);
|
||||
if (sect->data == NULL)
|
||||
fatalerror("Not enough memory for section: %s\n", strerror(errno));
|
||||
} else {
|
||||
@@ -547,7 +547,7 @@ void sect_StartUnion(void)
|
||||
error("Cannot use UNION inside of ROM0 or ROMX sections\n");
|
||||
return;
|
||||
}
|
||||
struct UnionStackEntry *entry = malloc(sizeof(*entry));
|
||||
struct UnionStackEntry *entry = (struct UnionStackEntry *)malloc(sizeof(*entry));
|
||||
|
||||
if (!entry)
|
||||
fatalerror("Failed to allocate new union stack entry: %s\n", strerror(errno));
|
||||
@@ -933,7 +933,7 @@ cleanup:
|
||||
// Section stack routines
|
||||
void sect_PushSection(void)
|
||||
{
|
||||
struct SectionStackEntry *entry = malloc(sizeof(*entry));
|
||||
struct SectionStackEntry *entry = (struct SectionStackEntry *)malloc(sizeof(*entry));
|
||||
|
||||
if (entry == NULL)
|
||||
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
||||
@@ -11,20 +11,20 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "asm/fixpoint.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/macro.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/output.h"
|
||||
#include "asm/section.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fixpoint.hpp"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/macro.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "error.h"
|
||||
#include "hashmap.h"
|
||||
#include "helpers.h"
|
||||
#include "version.h"
|
||||
#include "error.hpp"
|
||||
#include "hashmap.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
HashMap symbols;
|
||||
|
||||
@@ -49,8 +49,8 @@ struct ForEachArgs {
|
||||
|
||||
static void forEachWrapper(void *_sym, void *_argWrapper)
|
||||
{
|
||||
struct ForEachArgs *argWrapper = _argWrapper;
|
||||
struct Symbol *sym = _sym;
|
||||
struct ForEachArgs *argWrapper = (struct ForEachArgs *)_argWrapper;
|
||||
struct Symbol *sym = (struct Symbol *)_sym;
|
||||
|
||||
argWrapper->func(sym, argWrapper->arg);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ static void updateSymbolFilename(struct Symbol *sym)
|
||||
// Create a new symbol by name
|
||||
static struct Symbol *createsymbol(char const *symName)
|
||||
{
|
||||
struct Symbol *sym = malloc(sizeof(*sym));
|
||||
struct Symbol *sym = (struct Symbol *)malloc(sizeof(*sym));
|
||||
|
||||
if (!sym)
|
||||
fatalerror("Failed to create symbol '%s': %s\n", symName, strerror(errno));
|
||||
@@ -170,7 +170,7 @@ static void assignStringSymbol(struct Symbol *sym, char const *value)
|
||||
|
||||
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||
{
|
||||
return hash_GetElement(symbols, symName);
|
||||
return (struct Symbol *)hash_GetElement(symbols, symName);
|
||||
}
|
||||
|
||||
struct Symbol *sym_FindUnscopedSymbol(char const *symName)
|
||||
@@ -3,11 +3,11 @@
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "asm/main.h"
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "extern/utf8decoder.h"
|
||||
#include "extern/utf8decoder.hpp"
|
||||
|
||||
char const *printChar(int c)
|
||||
{
|
||||
@@ -8,38 +8,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/warning.h"
|
||||
#include "asm/fstack.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "error.h"
|
||||
#include "error.hpp"
|
||||
|
||||
unsigned int nbErrors = 0;
|
||||
|
||||
static const enum WarningState defaultWarnings[ARRAY_SIZE(warningStates)] = {
|
||||
[WARNING_ASSERT] = WARNING_ENABLED,
|
||||
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
|
||||
[WARNING_BUILTIN_ARG] = WARNING_DISABLED,
|
||||
[WARNING_CHARMAP_REDEF] = WARNING_DISABLED,
|
||||
[WARNING_DIV] = WARNING_DISABLED,
|
||||
[WARNING_EMPTY_DATA_DIRECTIVE] = WARNING_DISABLED,
|
||||
[WARNING_EMPTY_MACRO_ARG] = WARNING_DISABLED,
|
||||
[WARNING_EMPTY_STRRPL] = WARNING_DISABLED,
|
||||
[WARNING_LARGE_CONSTANT] = WARNING_DISABLED,
|
||||
[WARNING_LONG_STR] = WARNING_DISABLED,
|
||||
[WARNING_MACRO_SHIFT] = WARNING_DISABLED,
|
||||
[WARNING_NESTED_COMMENT] = WARNING_ENABLED,
|
||||
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
||||
[WARNING_SHIFT] = WARNING_DISABLED,
|
||||
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
|
||||
[WARNING_USER] = WARNING_ENABLED,
|
||||
AT(WARNING_ASSERT) WARNING_ENABLED,
|
||||
AT(WARNING_BACKWARDS_FOR) WARNING_DISABLED,
|
||||
AT(WARNING_BUILTIN_ARG) WARNING_DISABLED,
|
||||
AT(WARNING_CHARMAP_REDEF) WARNING_DISABLED,
|
||||
AT(WARNING_DIV) WARNING_DISABLED,
|
||||
AT(WARNING_EMPTY_DATA_DIRECTIVE) WARNING_DISABLED,
|
||||
AT(WARNING_EMPTY_MACRO_ARG) WARNING_DISABLED,
|
||||
AT(WARNING_EMPTY_STRRPL) WARNING_DISABLED,
|
||||
AT(WARNING_LARGE_CONSTANT) WARNING_DISABLED,
|
||||
AT(WARNING_LONG_STR) WARNING_DISABLED,
|
||||
AT(WARNING_MACRO_SHIFT) WARNING_DISABLED,
|
||||
AT(WARNING_NESTED_COMMENT) WARNING_ENABLED,
|
||||
AT(WARNING_OBSOLETE) WARNING_ENABLED,
|
||||
AT(WARNING_SHIFT) WARNING_DISABLED,
|
||||
AT(WARNING_SHIFT_AMOUNT) WARNING_DISABLED,
|
||||
AT(WARNING_USER) WARNING_ENABLED,
|
||||
|
||||
[WARNING_NUMERIC_STRING_1] = WARNING_ENABLED,
|
||||
[WARNING_NUMERIC_STRING_2] = WARNING_DISABLED,
|
||||
[WARNING_TRUNCATION_1] = WARNING_ENABLED,
|
||||
[WARNING_TRUNCATION_2] = WARNING_DISABLED,
|
||||
[WARNING_UNMAPPED_CHAR_1] = WARNING_ENABLED,
|
||||
[WARNING_UNMAPPED_CHAR_2] = WARNING_DISABLED,
|
||||
AT(WARNING_NUMERIC_STRING_1) WARNING_ENABLED,
|
||||
AT(WARNING_NUMERIC_STRING_2) WARNING_DISABLED,
|
||||
AT(WARNING_TRUNCATION_1) WARNING_ENABLED,
|
||||
AT(WARNING_TRUNCATION_2) WARNING_DISABLED,
|
||||
AT(WARNING_UNMAPPED_CHAR_1) WARNING_ENABLED,
|
||||
AT(WARNING_UNMAPPED_CHAR_2) WARNING_DISABLED,
|
||||
};
|
||||
|
||||
enum WarningState warningStates[ARRAY_SIZE(warningStates)];
|
||||
@@ -139,7 +139,7 @@ static bool tryProcessParamWarning(char const *flag, uint8_t param, enum Warning
|
||||
return true;
|
||||
}
|
||||
|
||||
baseID += maxParam;
|
||||
baseID = (enum WarningID)(baseID + maxParam);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ void processWarningFlag(char *flag)
|
||||
static bool setError = false;
|
||||
|
||||
// First, try to match against a "meta" warning
|
||||
for (enum WarningID id = META_WARNINGS_START; id < NB_WARNINGS; id++) {
|
||||
for (enum WarningID id = META_WARNINGS_START; id < NB_WARNINGS; id = (enum WarningID)(id + 1)) {
|
||||
// TODO: improve the matching performance?
|
||||
if (!strcmp(flag, warningFlags[id])) {
|
||||
// We got a match!
|
||||
@@ -309,7 +309,8 @@ void processWarningFlag(char *flag)
|
||||
}
|
||||
|
||||
// Try to match the flag against a "normal" flag
|
||||
for (enum WarningID id = 0; id < NB_PLAIN_WARNINGS; id++) {
|
||||
for (enum WarningID id = (enum WarningID)0; id < NB_PLAIN_WARNINGS;
|
||||
id = (enum WarningID)(id + 1)) {
|
||||
if (!strcmp(rootFlag, warningFlags[id])) {
|
||||
// We got a match!
|
||||
warningStates[id] = state;
|
||||
@@ -345,7 +346,7 @@ void error(char const *fmt, ...)
|
||||
nbErrors++;
|
||||
}
|
||||
|
||||
_Noreturn void fatalerror(char const *fmt, ...)
|
||||
[[noreturn]] void fatalerror(char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
Reference in New Issue
Block a user