libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
writer_executor.hpp
1#pragma once
2
9template <OutputSink Sink>
11{
12 public:
21 Executor(Sink& sink, const uint8_t* codes, const uint8_t* args);
22
32 template <FormatProfile Profile>
33 [[nodiscard]] ErrorCode Run();
34
35 private:
36 // Raw sink and generic field-writing helpers.
37 // 原始输出与通用字段写出辅助函数。
38 [[nodiscard]] ErrorCode WriteRaw(std::string_view text);
39 [[nodiscard]] ErrorCode WritePadding(char fill, size_t count);
40 [[nodiscard]] ErrorCode WriteTextField(std::string_view text, const Spec& spec);
41 [[nodiscard]] ErrorCode WriteIntegerField(char sign_char, std::string_view prefix,
42 std::string_view digits, const Spec& spec);
43 [[nodiscard]] ErrorCode WriteFloatField(char sign_char, std::string_view text,
44 const Spec& spec);
45
46 template <std::signed_integral Int>
47 [[nodiscard]] static char ResolveSignChar(Int value, const Spec& spec);
48
49#if LIBXR_PRINT_ENABLE_FLOAT
50 template <typename T>
51 [[nodiscard]] static char ResolveFloatSignChar(T value, const Spec& spec);
52#endif
53
54 template <std::signed_integral Int>
55 [[nodiscard]] ErrorCode WriteSigned(const Spec& spec, Int value);
56
57 template <FormatType Type, std::unsigned_integral UInt>
58 [[nodiscard]] ErrorCode DispatchUnsigned(const Spec& spec, UInt value);
59
76 template <uint8_t Base, bool UpperCase = false, bool PrependOctalZero = false,
77 std::unsigned_integral UInt>
78 [[nodiscard]] ErrorCode WriteUnsignedDigits(std::string_view prefix, const Spec& spec,
79 UInt value);
80 [[nodiscard]] ErrorCode WritePointer(const Spec& spec, uintptr_t value);
81 [[nodiscard]] ErrorCode WriteCharacter(const Spec& spec, char ch);
82 [[nodiscard]] ErrorCode WriteString(const Spec& spec, std::string_view text);
83
84#if LIBXR_PRINT_ENABLE_FLOAT
85 template <typename T>
86 [[nodiscard]] ErrorCode WriteFloat(FormatType type, const Spec& spec, T value);
87#endif
88
93 [[nodiscard]] ErrorCode WriteU32Dec(uint32_t value);
94
99 [[nodiscard]] ErrorCode WriteI32Dec(int32_t value);
100
105 template <uint8_t Base, bool UpperCase = false>
106 [[nodiscard]] ErrorCode WriteU32Base(uint32_t value);
107
112 [[nodiscard]] ErrorCode WriteU32ZeroPadWidth(uint8_t width, uint32_t value);
113
117 [[nodiscard]] ErrorCode WriteStringRaw(std::string_view text);
118
122 [[nodiscard]] ErrorCode WriteCharacterRaw(char ch);
123
124 // Small bridges that keep GenericField dispatch readable while preserving the
125 // existing "read spec -> read next packed argument -> call concrete writer"
126 // execution order.
127 // 这些小桥接函数只负责让 GenericField 分发更易读,同时保持原有的
128 // “读 spec -> 读下一个已打包参数 -> 调具体 writer” 执行顺序不变。
129 template <std::signed_integral Int>
130 [[nodiscard]] ErrorCode DispatchSignedField();
131
132 template <FormatType Type, std::unsigned_integral UInt>
133 [[nodiscard]] ErrorCode DispatchUnsignedField();
134
135#if LIBXR_PRINT_ENABLE_FLOAT
136 template <FormatType Type, typename Float>
137 [[nodiscard]] ErrorCode DispatchFloatField();
138#endif
139
140 [[nodiscard]] ErrorCode DispatchPointerField();
141
142 [[nodiscard]] ErrorCode DispatchCharacterField();
143
144 [[nodiscard]] ErrorCode DispatchStringField();
145
155 template <FormatProfile Profile>
156 [[nodiscard]] ErrorCode DispatchGenericField(FormatType type);
157
167 template <FormatProfile Profile>
168 [[nodiscard]] ErrorCode DispatchOp(FormatOp op);
169
170 Sink& sink_;
171 CodeReader codes_;
172 ArgumentReader args_;
173};
174
175// These implementation headers form an ordered dependency chain.
176// clang-format off
177#include "writer_executor_field.hpp"
178#include "writer_executor_value.hpp"
179#include "writer_executor_generic.hpp"
180#include "writer_executor_opcode.hpp"
181// clang-format on
运行期参数字节块的顺序读取器 / Sequential reader for the packed runtime argument byte blob
编译后记录流的顺序读取器 / Sequential reader for the compiled record stream
按输出端共享重后端、按调用点 profile 裁剪操作码分发的字节码执行器 / Per-sink bytecode executor with shared heavy backends and per...
ErrorCode WriteI32Dec(int32_t value)
单个原始 int32_t 十进制字段的快路径。 / Fast path for one raw int32_t decimal field.
ErrorCode WriteUnsignedDigits(std::string_view prefix, const Spec &spec, UInt value)
按编译期进制/大小写/八进制备用格式参数复用无符号数字载荷写出逻辑 / Reuse the unsigned-digit payload writer with compile-time radix,...
static char ResolveSignChar(Int value, const Spec &spec)
执行器的具体运行期数值写出函数 / Concrete runtime value writers for the executor
ErrorCode DispatchSignedField()
运行期执行器中 GenericField 的分发桥接函数 / GenericField dispatch bridges for the runtime executor
ErrorCode WriteStringRaw(std::string_view text)
单个原始字符串参数的快路径。 / Fast path for one raw string argument.
ErrorCode Run()
持续执行记录流,直到遇到 FormatOp::End / Run until the compiled record stream reaches FormatOp::End
ErrorCode WriteRaw(std::string_view text)
运行期执行器共享的字段写出原语,供所有操作码路径复用 / Executor-side field-writing primitives shared by all runtime opcodes
ErrorCode WriteU32Base(uint32_t value)
单个原始 uint32_t 非十进制字段的快路径。 / Fast path for one raw uint32_t non-decimal field.
ErrorCode DispatchPointerField()
读取一个指针载荷并走指针字段写出路径 / Read one pointer payload and write it through the pointer field path
ErrorCode DispatchStringField()
读取一个字符串载荷并走字符串字段写出路径 / Read one string payload and write it through the string field path
ErrorCode DispatchOp(FormatOp op)
将一个运行期操作码分发到选中的特化路径 / Dispatch one runtime opcode to the selected specialized path
ErrorCode WritePadding(char fill, size_t count)
向输出端写入重复填充字符 / Write repeated fill characters into the sink
Executor(Sink &sink, const uint8_t *codes, const uint8_t *args)
将一个输出端、一份编译字节块和一份参数字节块绑定起来 / Bind one sink with one compiled byte blob and one packed argument blob
ErrorCode DispatchGenericField(FormatType type)
将一个 GenericField 载荷分发到对应的宽回退路径 / Dispatch one GenericField payload to the corresponding wide fallback
ErrorCode WritePointer(const Spec &spec, uintptr_t value)
按规范指针字段策略写出一个指针值 / Write one pointer value using the canonical pointer field policy
ErrorCode WriteString(const Spec &spec, std::string_view text)
写出一个字符串字段值,并在需要时应用精度截断 / Write one string field value, including precision truncation when present
ErrorCode WriteIntegerField(char sign_char, std::string_view prefix, std::string_view digits, const Spec &spec)
按符号、前缀、精度与填充策略写出一个整数载荷 / Write one integer payload with sign, prefix, precision, and padding policy a...
ErrorCode DispatchUnsigned(const Spec &spec, UInt value)
通过共享整数字段路径写出一个无符号整数语义值 / Write one unsigned integer semantic value through the shared integer-field p...
ErrorCode WriteU32Dec(uint32_t value)
单个原始 uint32_t 十进制字段的快路径。 / Fast path for one raw uint32_t decimal field.
ErrorCode WriteCharacterRaw(char ch)
单个原始字符参数的快路径。 / Fast path for one raw character argument.
ErrorCode WriteCharacter(const Spec &spec, char ch)
写出一个字符字段值 / Write one character field value
ErrorCode DispatchUnsignedField()
读取一个无符号载荷并转发给选定的整数语义写出路径 / Read one unsigned payload and forward it to the selected integer semantic ...
ErrorCode DispatchCharacterField()
读取一个字符载荷并走字符字段写出路径 / Read one character payload and write it through the character field path
ErrorCode WriteSigned(const Spec &spec, Int value)
通过共享整数字段路径写出一个有符号整数值 / Write one signed integer value through the shared integer-field path
ErrorCode WriteTextField(std::string_view text, const Spec &spec)
按宽度与对齐策略写出一个文本字段 / Write one text field with width/alignment policy applied
ErrorCode WriteFloatField(char sign_char, std::string_view text, const Spec &spec)
按符号与字段填充策略写出一个浮点文本载荷 / Write one float text payload with sign and field padding applied
ErrorCode WriteU32ZeroPadWidth(uint8_t width, uint32_t value)
单个零填充 uint32_t 十进制字段的快路径。 / Fast path for one zero-padded uint32_t decimal field.