Group pointer and size as a ContentSpan struct

This commit is contained in:
Rangi42
2024-03-26 23:47:33 -04:00
committed by Sylvie
parent bf0cabb3ea
commit 78801e324c
7 changed files with 59 additions and 72 deletions

View File

@@ -15,6 +15,8 @@
#include "linkdefs.hpp"
#include "asm/lexer.hpp"
struct FileStackNode {
FileStackNodeType type;
std::variant<
@@ -64,17 +66,14 @@ std::optional<std::string> fstk_FindFile(std::string const &path);
bool yywrap();
void fstk_RunInclude(std::string const &path, bool updateStateNow);
void fstk_RunMacro(std::string const &macroName, std::shared_ptr<MacroArgs> macroArgs);
void fstk_RunRept(
uint32_t count, int32_t reptLineNo, std::shared_ptr<char const[]> body, size_t size
);
void fstk_RunRept(uint32_t count, int32_t reptLineNo, ContentSpan const &span);
void fstk_RunFor(
std::string const &symName,
int32_t start,
int32_t stop,
int32_t step,
int32_t reptLineNo,
std::shared_ptr<char const[]> body,
size_t size
ContentSpan const &span
);
void fstk_StopRept();
bool fstk_Break();

View File

@@ -41,6 +41,11 @@ struct IfStackEntry {
bool reachedElseBlock; // Whether an ELSE block ran already
};
struct ContentSpan {
std::shared_ptr<char[]> ptr;
size_t size;
};
struct BufferedContent {
int fd;
size_t index = 0; // Read index into the buffer
@@ -52,19 +57,17 @@ struct BufferedContent {
};
struct MmappedContent {
std::shared_ptr<char[]> ptr;
size_t size;
ContentSpan span;
size_t offset = 0;
MmappedContent(std::shared_ptr<char[]> ptr_, size_t size_) : ptr(ptr_), size(size_) {}
MmappedContent(std::shared_ptr<char[]> ptr, size_t size) : span({.ptr = ptr, .size = size}) {}
};
struct ViewedContent {
std::shared_ptr<char const[]> ptr;
size_t size;
ContentSpan span;
size_t offset = 0;
ViewedContent(std::shared_ptr<char const[]> ptr_, size_t size_) : ptr(ptr_), size(size_) {}
ViewedContent(ContentSpan const &span_) : span(span_) {}
};
struct LexerState {
@@ -95,9 +98,7 @@ struct LexerState {
void setAsCurrentState();
bool setFileAsNextState(std::string const &filePath, bool updateStateNow);
void setViewAsNextState(
char const *name, std::shared_ptr<char const[]> ptr, size_t size, uint32_t lineNo_
);
void setViewAsNextState(char const *name, ContentSpan const &span, uint32_t lineNo_);
void clear(uint32_t lineNo_);
};
@@ -137,8 +138,7 @@ void lexer_DumpStringExpansions();
struct Capture {
uint32_t lineNo;
std::shared_ptr<char const[]> body;
size_t size;
ContentSpan span;
};
Capture lexer_CaptureRept();

View File

@@ -10,9 +10,9 @@
#include <string>
#include <string_view>
#include <time.h>
#include <utility>
#include <variant>
#include "asm/lexer.hpp"
#include "asm/section.hpp"
enum SymbolType {
@@ -37,10 +37,10 @@ struct Symbol {
uint32_t fileLine; // Line where the symbol was defined
std::variant<
int32_t, // If isNumeric()
int32_t (*)(), // If isNumeric() and has a callback
std::pair<std::shared_ptr<char const[]>, size_t>, // For SYM_MACRO
std::shared_ptr<std::string> // For SYM_EQUS
int32_t, // If isNumeric()
int32_t (*)(), // If isNumeric() and has a callback
ContentSpan, // For SYM_MACRO
std::shared_ptr<std::string> // For SYM_EQUS
>
data;
@@ -62,7 +62,7 @@ struct Symbol {
int32_t getValue() const;
int32_t getOutputValue() const;
std::pair<std::shared_ptr<char const[]>, size_t> getMacro() const;
ContentSpan const &getMacro() const;
std::shared_ptr<std::string> getEqus() const;
uint32_t getConstantValue() const;
};
@@ -89,9 +89,7 @@ Symbol *sym_FindScopedSymbol(std::string const &symName);
// Find a scoped symbol by name; do not return `@` or `_NARG` when they have no value
Symbol *sym_FindScopedValidSymbol(std::string const &symName);
Symbol const *sym_GetPC();
Symbol *sym_AddMacro(
std::string const &symName, int32_t defLineNo, std::shared_ptr<char const[]> body, size_t size
);
Symbol *sym_AddMacro(std::string const &symName, int32_t defLineNo, ContentSpan const &span);
Symbol *sym_Ref(std::string const &symName);
Symbol *sym_AddString(std::string const &symName, std::shared_ptr<std::string> value);
Symbol *sym_RedefString(std::string const &symName, std::shared_ptr<std::string> value);