mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add -B/--backtrace option to RGBASM and RGBLINK (#1787)
This commit is contained in:
@@ -43,7 +43,8 @@ struct FileStackNode {
|
||||
FileStackNode(FileStackNodeType type_, std::variant<std::vector<uint32_t>, std::string> data_)
|
||||
: type(type_), data(data_) {}
|
||||
|
||||
std::string const &dump(uint32_t curLineNo) const;
|
||||
void printBacktrace(uint32_t curLineNo) const;
|
||||
std::vector<std::pair<std::string, uint32_t>> backtrace(uint32_t curLineNo) const;
|
||||
std::string reptChain() const;
|
||||
};
|
||||
|
||||
@@ -51,7 +52,7 @@ struct MacroArgs;
|
||||
|
||||
void fstk_VerboseOutputConfig();
|
||||
|
||||
bool fstk_DumpCurrent();
|
||||
void fstk_TraceCurrent();
|
||||
std::shared_ptr<FileStackNode> fstk_GetFileStack();
|
||||
std::shared_ptr<std::string> fstk_GetUniqueIDStr();
|
||||
MacroArgs *fstk_GetCurrentMacroArgs();
|
||||
|
||||
@@ -133,7 +133,7 @@ void lexer_ReachELSEBlock();
|
||||
|
||||
void lexer_CheckRecursionDepth();
|
||||
uint32_t lexer_GetLineNo();
|
||||
void lexer_DumpStringExpansions();
|
||||
void lexer_TraceStringExpansions();
|
||||
|
||||
struct Capture {
|
||||
uint32_t lineNo;
|
||||
|
||||
@@ -74,11 +74,10 @@ void fatal(char const *fmt, ...);
|
||||
[[gnu::format(printf, 1, 2)]]
|
||||
void error(char const *fmt, ...);
|
||||
|
||||
// Used for errors that make it impossible to assemble correctly, but don't
|
||||
// affect the following code. The code will fail to assemble but the user will
|
||||
// get a list of all errors at the end, making it easier to fix all of them at
|
||||
// once.
|
||||
void error(std::function<void()> callback);
|
||||
// Used for errors that handle their own backtrace output. The code will fail
|
||||
// to assemble but the user will get a list of all errors at the end, making it
|
||||
// easier to fix all of them at once.
|
||||
void errorNoTrace(std::function<void()> callback);
|
||||
|
||||
void requireZeroErrors();
|
||||
|
||||
|
||||
@@ -53,12 +53,15 @@ struct DiagnosticsState {
|
||||
bool warningsAreErrors = false;
|
||||
};
|
||||
|
||||
static constexpr uint64_t TRACE_COLLAPSE = UINT64_MAX;
|
||||
|
||||
template<typename L, typename W>
|
||||
struct Diagnostics {
|
||||
std::vector<WarningFlag<L>> metaWarnings;
|
||||
std::vector<WarningFlag<L>> warningFlags;
|
||||
std::vector<ParamWarning<W>> paramWarnings;
|
||||
DiagnosticsState<W> state;
|
||||
uint64_t traceDepth;
|
||||
uint64_t nbErrors;
|
||||
|
||||
void incrementErrors() {
|
||||
|
||||
38
include/link/fstack.hpp
Normal file
38
include/link/fstack.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef RGBDS_LINK_FSTACK_HPP
|
||||
#define RGBDS_LINK_FSTACK_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
struct FileStackNode {
|
||||
FileStackNodeType type;
|
||||
std::variant<
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
>
|
||||
data;
|
||||
|
||||
FileStackNode *parent;
|
||||
// Line at which the parent context was exited; meaningless for the root level
|
||||
uint32_t lineNo;
|
||||
|
||||
// REPT iteration counts since last named node, in reverse depth order
|
||||
std::vector<uint32_t> &iters() { return std::get<std::vector<uint32_t>>(data); }
|
||||
std::vector<uint32_t> const &iters() const { return std::get<std::vector<uint32_t>>(data); }
|
||||
// File name for files, file::macro name for macros
|
||||
std::string &name() { return std::get<std::string>(data); }
|
||||
std::string const &name() const { return std::get<std::string>(data); }
|
||||
|
||||
void printBacktrace(uint32_t curLineNo) const;
|
||||
std::vector<std::pair<std::string, uint32_t>> backtrace(uint32_t curLineNo) const;
|
||||
};
|
||||
|
||||
#endif // RGBDS_LINK_FSTACK_HPP
|
||||
@@ -4,13 +4,6 @@
|
||||
#define RGBDS_LINK_MAIN_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
#include "verbosity.hpp"
|
||||
|
||||
struct Options {
|
||||
bool isDmgMode; // -d
|
||||
@@ -32,27 +25,4 @@ struct Options {
|
||||
|
||||
extern Options options;
|
||||
|
||||
struct FileStackNode {
|
||||
FileStackNodeType type;
|
||||
std::variant<
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
>
|
||||
data;
|
||||
|
||||
FileStackNode *parent;
|
||||
// Line at which the parent context was exited; meaningless for the root level
|
||||
uint32_t lineNo;
|
||||
|
||||
// REPT iteration counts since last named node, in reverse depth order
|
||||
std::vector<uint32_t> &iters() { return std::get<std::vector<uint32_t>>(data); }
|
||||
std::vector<uint32_t> const &iters() const { return std::get<std::vector<uint32_t>>(data); }
|
||||
// File name for files, file::macro name for macros
|
||||
std::string &name() { return std::get<std::string>(data); }
|
||||
std::string const &name() const { return std::get<std::string>(data); }
|
||||
|
||||
std::string const &dump(uint32_t curLineNo) const;
|
||||
};
|
||||
|
||||
#endif // RGBDS_LINK_MAIN_HPP
|
||||
|
||||
@@ -44,6 +44,6 @@ void sym_AddSymbol(Symbol &symbol);
|
||||
// Finds a symbol in all the defined symbols.
|
||||
Symbol *sym_GetSymbol(std::string const &name);
|
||||
|
||||
void sym_DumpLocalAliasedSymbols(std::string const &name);
|
||||
void sym_TraceLocalAliasedSymbols(std::string const &name);
|
||||
|
||||
#endif // RGBDS_LINK_SYMBOL_HPP
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
|
||||
#include "diagnostics.hpp"
|
||||
|
||||
#define warningAt(where, ...) warning(where.src, where.lineNo, __VA_ARGS__)
|
||||
#define errorAt(where, ...) error(where.src, where.lineNo, __VA_ARGS__)
|
||||
#define fatalAt(where, ...) fatal(where.src, where.lineNo, __VA_ARGS__)
|
||||
#define warningAt(where, ...) warning((where).src, (where).lineNo, __VA_ARGS__)
|
||||
#define errorAt(where, ...) error((where).src, (where).lineNo, __VA_ARGS__)
|
||||
#define fatalAt(where, ...) fatal((where).src, (where).lineNo, __VA_ARGS__)
|
||||
|
||||
#define fatalTwoAt(where1, where2, ...) \
|
||||
fatalTwo(*(where1).src, (where1).lineNo, *(where2).src, (where2).lineNo, __VA_ARGS__)
|
||||
|
||||
enum WarningLevel {
|
||||
LEVEL_DEFAULT, // Warnings that are enabled by default
|
||||
@@ -46,8 +49,6 @@ void warning(char const *fmt, ...);
|
||||
void error(FileStackNode const *src, uint32_t lineNo, char const *fmt, ...);
|
||||
[[gnu::format(printf, 1, 2)]]
|
||||
void error(char const *fmt, ...);
|
||||
[[gnu::format(printf, 1, 2)]]
|
||||
void errorNoDump(char const *fmt, ...);
|
||||
|
||||
void scriptError(char const *name, uint32_t lineNo, char const *fmt, va_list args);
|
||||
|
||||
@@ -56,6 +57,16 @@ void fatal(FileStackNode const *src, uint32_t lineNo, char const *fmt, ...);
|
||||
[[gnu::format(printf, 1, 2), noreturn]]
|
||||
void fatal(char const *fmt, ...);
|
||||
|
||||
[[gnu::format(printf, 5, 6), noreturn]]
|
||||
void fatalTwo(
|
||||
FileStackNode const &src1,
|
||||
uint32_t lineNo1,
|
||||
FileStackNode const &src2,
|
||||
uint32_t lineNo2,
|
||||
char const *fmt,
|
||||
...
|
||||
);
|
||||
|
||||
void requireZeroErrors();
|
||||
|
||||
#endif // RGBDS_LINK_WARNING_HPP
|
||||
|
||||
Reference in New Issue
Block a user