Implement unionized sections in RGBASM

This touched a lot more code than initially expected, for two reasons.

First, this broke a big RGBASM assumption: that sections are always being
written to at their end. This plus other problems required touching
basically the entirety of `section.c`.

Second, I tried different solutions to solve the above problem, and along
the way I cleaned up many things around. (I believe that keeping this to
"cleanup" commits yields subpar results, and since it's boring they get
postponed anyways.)

RGBLINK support still needs to be added, but this will come next.
This commit is contained in:
ISSOtm
2020-03-20 21:02:32 +01:00
parent 46a402f7d7
commit cb52ae0f26
13 changed files with 314 additions and 162 deletions

View File

@@ -27,7 +27,6 @@
extern int32_t nLineNo;
extern uint32_t nTotalLines;
extern uint32_t nPC;
extern uint32_t nIFDepth;
extern bool skipElif;
extern uint32_t nUnionDepth;

View File

@@ -31,6 +31,8 @@ extern uint32_t ulNewMacroSize;
extern int32_t nGBGfxID;
extern int32_t nBinaryID;
extern uint32_t curOffset; /* Offset into the current section */
extern struct sOptions DefaultOptions;
extern struct sOptions CurrentOptions;

View File

@@ -19,9 +19,10 @@ extern char *tzObjectname;
extern struct Section *pSectionList, *pCurrentSection;
void out_SetFileName(char *s);
void out_CreatePatch(uint32_t type, struct Expression const *expr);
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);
char const *message, uint32_t ofs);
void out_WriteObject(void);
#endif /* RGBDS_ASM_OUTPUT_H */

View File

@@ -18,7 +18,8 @@ struct Expression;
struct Section {
char *pzName;
enum SectionType nType;
uint32_t nPC;
bool isUnion;
uint32_t size;
uint32_t nOrg;
uint32_t nBank;
uint32_t nAlign;
@@ -28,25 +29,26 @@ struct Section {
};
struct SectionSpec {
int32_t bank;
int32_t alignment;
uint32_t bank;
uint32_t alignment;
};
struct Section *out_FindSectionByName(const char *pzName);
void out_NewSection(char const *pzName, uint32_t secttype, int32_t org,
struct SectionSpec const *attributes);
void out_SetLoadSection(char const *name, uint32_t secttype, int32_t org,
void out_NewSection(char const *pzName, uint32_t secttype, uint32_t org,
struct SectionSpec const *attributes, bool isUnion);
void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,
struct SectionSpec const *attributes);
void out_EndLoadSection(void);
struct Section *sect_GetSymbolSection(void);
uint32_t sect_GetOutputOffset(void);
void out_AbsByte(uint8_t b);
void out_AbsByteGroup(uint8_t const *s, int32_t length);
void out_Skip(int32_t skip);
void out_String(char const *s);
void out_RelByte(struct Expression *expr);
void out_RelBytes(struct Expression *expr, int32_t n);
void out_RelBytes(struct Expression *expr, uint32_t n);
void out_RelWord(struct Expression *expr);
void out_RelLong(struct Expression *expr);
void out_PCRelByte(struct Expression *expr);

View File

@@ -13,6 +13,8 @@
#include <stdint.h>
#include <string.h>
#include "asm/section.h"
#include "types.h"
#define HASHSIZE (1 << 16)
@@ -30,7 +32,6 @@ enum SymbolType {
struct sSymbol {
char tzName[MAXSYMLEN + 1];
enum SymbolType type;
bool isConstant; /* Whether the symbol's value is currently known */
bool isExported; /* Whether the symbol is to be exported */
bool isBuiltin; /* Whether the symbol is a built-in */
bool isReferenced; /* Whether the symbol is referenced in a RPN expr */
@@ -52,7 +53,9 @@ static inline bool sym_IsDefined(struct sSymbol const *sym)
static inline bool sym_IsConstant(struct sSymbol const *sym)
{
return sym->isConstant;
return sym->type == SYM_EQU || sym->type == SYM_SET
|| (sym->type == SYM_LABEL && sym->pSection
&& sym->pSection->nOrg != -1);
}
static inline bool sym_IsNumeric(struct sSymbol const *sym)