libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Print::FormatCompiler< Frontend > Class Template Reference

共享编译期后端,把前端事件整理成最终字节流和参数表 / Shared compile-time backend that turns frontend events into the final byte stream plus argument table. More...

#include <format_compile.hpp>

Static Public Member Functions

static consteval auto Compile ()
 把一个前端编译成最终字节流、参数表和 writer 摘要 / Compiles one frontend into the final byte stream, argument table, and writer profile.
 

Detailed Description

template<typename Frontend>
class LibXR::Print::FormatCompiler< Frontend >

共享编译期后端,把前端事件整理成最终字节流和参数表 / Shared compile-time backend that turns frontend events into the final byte stream plus argument table.

前端协议: 前端必须提供如下成员:using ErrorType、static constexpr const char* SourceData()、static constexpr size_t SourceSize()、以及 static consteval ErrorType Walk(visitor)。 Frontend contract: The frontend must provide the members using ErrorType, static constexpr const char* SourceData(), static constexpr size_t SourceSize(), and static consteval ErrorType Walk(visitor).

Walk(visitor) 必须按源串顺序发射两类事件:

  • visitor.Text(offset, text_size)
  • visitor.Field(const FormatField&) Walk(visitor) must emit source-ordered events through:
  • visitor.Text(offset, text_size)
  • visitor.Field(const FormatField&)

这个后端只遍历前端一次。那一遍里会同时收集:

  • 输出字节码
  • 长字面文本存储
  • 运行期参数元信息
  • 运行期执行器摘要

最后再把这些临时缓冲收拢成精确尺寸的最终结果。 The backend only walks the frontend once. During that single walk it collects:

  • output bytecode
  • long literal-text storage
  • runtime argument metadata
  • the runtime executor profile

Then it packs those scratch buffers into the final exact-size result.

Definition at line 51 of file format_compile.hpp.

Member Function Documentation

◆ Compile()

template<typename Frontend >
static consteval auto LibXR::Print::FormatCompiler< Frontend >::Compile ( )
inlinestaticnodiscardconsteval

把一个前端编译成最终字节流、参数表和 writer 摘要 / Compiles one frontend into the final byte stream, argument table, and writer profile.

Returns
返回最终编译结果对象;若失败则返回携带首个编译期错误的失败结果。 Returns the final compiled result object, or a failed result that carries the first compile-time error.

Definition at line 544 of file format_compile.hpp.

545 {
546 constexpr auto scratch = []() consteval
547 {
548 ScratchBuilder builder{};
549 builder.frontend_error = Frontend::Walk(builder);
550 return builder;
551 }();
552
553 if constexpr (scratch.frontend_error != Error::None)
554 {
555 return Failed(scratch.frontend_error);
556 }
557 else
558 {
559 return scratch.template Finish<scratch.FinalCodeBytes(), scratch.FinalBlobBytes(),
560 scratch.arg_count>();
561 }
562 }

The documentation for this class was generated from the following file: