mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
- FIX: `Label & const` was not actually doing the `& const` masking (fixes #1446) - ADD: `LOW(Label)` can be constant if `Label` is aligned to 8 or more bits (resolves #1444) - ADD: `!expr` can be constant 0 if `expr` has any non-zero bits (resolves #1447) - `LOW()` and `HIGH()` have their own RPN operator values (resolves #1445) The change to RPN values means that the object file version was incremented. This also refactors unary operators and functions, combining their evaluation similarly to binary ones.
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
/* SPDX-License-Identifier: MIT */
|
|
|
|
#ifndef RGBDS_ASM_RPN_HPP
|
|
#define RGBDS_ASM_RPN_HPP
|
|
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
#include "linkdefs.hpp"
|
|
|
|
struct Symbol;
|
|
|
|
struct Expression {
|
|
std::variant<
|
|
int32_t, // If the expression's value is known, it's here
|
|
std::string // Why the expression is not known, if it isn't
|
|
> data = 0;
|
|
bool isSymbol = false; // Whether the expression represents a symbol suitable for const diffing
|
|
std::vector<uint8_t> rpn{}; // Bytes serializing the RPN expression
|
|
uint32_t rpnPatchSize = 0; // Size the expression will take in the object file
|
|
|
|
Expression() = default;
|
|
Expression(Expression &&) = default;
|
|
#ifdef _MSC_VER
|
|
// MSVC and WinFlexBison won't build without this...
|
|
Expression(Expression const &) = default;
|
|
#endif
|
|
|
|
Expression &operator=(Expression &&) = default;
|
|
|
|
bool isKnown() const { return std::holds_alternative<int32_t>(data); }
|
|
int32_t value() const;
|
|
|
|
int32_t getConstVal() const;
|
|
Symbol const *symbolOf() const;
|
|
bool isDiffConstant(Symbol const *symName) const;
|
|
|
|
void makeNumber(uint32_t value);
|
|
void makeSymbol(std::string const &symName);
|
|
void makeBankSymbol(std::string const &symName);
|
|
void makeBankSection(std::string const §Name);
|
|
void makeSizeOfSection(std::string const §Name);
|
|
void makeStartOfSection(std::string const §Name);
|
|
void makeSizeOfSectionType(SectionType type);
|
|
void makeStartOfSectionType(SectionType type);
|
|
void makeUnaryOp(RPNCommand op, Expression &&src);
|
|
void makeBinaryOp(RPNCommand op, Expression &&src1, Expression const &src2);
|
|
|
|
void makeCheckHRAM();
|
|
void makeCheckRST();
|
|
|
|
void checkNBit(uint8_t n) const;
|
|
|
|
private:
|
|
void clear();
|
|
uint8_t *reserveSpace(uint32_t size);
|
|
uint8_t *reserveSpace(uint32_t size, uint32_t patchSize);
|
|
};
|
|
|
|
bool checkNBit(int32_t v, uint8_t n, char const *name);
|
|
|
|
#endif // RGBDS_ASM_RPN_HPP
|