Documentation
¶
Index ¶
Constants ¶
const UnknownVariant = ""
UnknownVariant represents the unknown variant case in a select variant statement.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func (*Block) ForAllStatements ¶
type ByTargetTypeThenKind ¶
type ByTargetTypeThenKind []MethodID
func (ByTargetTypeThenKind) Len ¶
func (s ByTargetTypeThenKind) Len() int
func (ByTargetTypeThenKind) Less ¶
func (s ByTargetTypeThenKind) Less(i, j int) bool
func (ByTargetTypeThenKind) Swap ¶
func (s ByTargetTypeThenKind) Swap(i, j int)
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
CodeGenerator represents a code generator which takes a graph of `MeasureTape` and creates all the needed methods to measure their size.
func NewCodeGenerator ¶
func NewCodeGenerator(mt *MeasuringTape) *CodeGenerator
NewCodeGenerator creates a new code generator.
func (*CodeGenerator) Generate ¶
func (cg *CodeGenerator) Generate() map[MethodID]*Method
Generate generates and optimizes the code.
This should be called once, and the result saved for further processing or printing.
type Expression ¶
type Expression interface { // AssertKind asserts that value is one of the `kinds` given. On success, // returns the kind of this value. AssertKind(kinds ...TapeKind) TapeKind // Nullable returns wether this value is nullable. Nullable() bool // Fmt formats the value with the specified formatter. Fmt(ExpressionFormatter) string }
Expression represents an expression. It can be one of:
* N, i.e. a number
- L, i.e. a local variable. It is kinded and can be one of struct, union, table, or unknown which is required for array and vector traversals.
- MEMBER_OF(V, M), i.e. accessing a member of an expression. For instance, this is done differently for a struct member, union member, or table member in the HLCPP bindings.
* FIDL_ALIGN(V), i.e. FIDL aligning an expression.
- LENGTH(V), i.e. the length of an expression. For instance, this is either v.length() or c.size() in the HLCPP bindings depending on the kind of the expression, std::string vs std::vector receiver. Only meaningul on expressions of kind string or vector.
- HAS_MEMBER(V, M), i.e. check if a member of an expression is present. This is meaningful for a nullable struct member, or a table member.
* MULT(V1, V1), i.e. multiplication of two expressions.
type ExpressionFormatter ¶
type ExpressionFormatter interface { CaseNum(num int) string CaseLocal(name string, kind TapeKind) string CaseMemberOf(expr Expression, member string, kind TapeKind, nullable bool) string CaseFidlAlign(expr Expression) string CaseLength(expr Expression) string CaseHasMember(expr Expression, member string) string CaseMult(lhs, rhs Expression) string }
ExpressionFormatter formats an expression.
type LocalWithBlock ¶
type LocalWithBlock struct { Local Expression Body *Block }
type Measurer ¶
type Measurer struct {
// contains filtered or unexported fields
}
func NewMeasurer ¶
func (*Measurer) MeasuringTapeFor ¶
func (m *Measurer) MeasuringTapeFor(targetType string) (*MeasuringTape, error)
func (*Measurer) RootLibraries ¶
func (m *Measurer) RootLibraries() []fidlgen.LibraryName
type MeasuringTape ¶
type MeasuringTape struct {
// contains filtered or unexported fields
}
func (*MeasuringTape) Name ¶
func (mt *MeasuringTape) Name() fidlgen.Name
type Method ¶
type Method struct { ID MethodID Arg Expression Body *Block }
func (*Method) ForAllStatements ¶
ForAllStatements traverses all statements of a method but makes no guarantees as to the order in which the traversal is perfomed.
type MethodID ¶
type MethodID struct { Kind MethodKind TargetType fidlgen.Name }
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
statement describes an operation that needs to be done in order to calculate the size of a FIDL value. Statements are high level operations, describing steps which can be taken within a measuring tape. (Speficially, they are not meant to be general purpose operations like one would find in general purpose programming languages' IR).
A statement can be one of:
* AddNumBytes(E): add E to the num bytes counter.
* AddNumHandles(E): add E to the num handles counter.
- Iterate(L, E, B): iterate over E, and run block B for each element. Each element is referred to by L within block B.
* Invoke(Id, E): invoke method identified as Id with value E.
* Guard(M, B): run block B if member M is present.
- SelectVariant(E, map[variant]B): run block B depending on the selected variant of E. E must be a union.
* MaxOut: max out both bytes and handles counters.
* DeclareMaxOrdinal: declare a local meant to hold the max ordinal value.
* SetMaxOrdinal(E): update the max ordinal local to E.
func (*Statement) Visit ¶
func (stmt *Statement) Visit(formatter StatementFormatter)
type StatementFormatter ¶
type StatementFormatter interface { CaseMaxOut() CaseAddNumBytes(expr Expression) CaseAddNumHandles(expr Expression) CaseInvoke(id MethodID, expr Expression) CaseGuard(cond Expression, body *Block) CaseIterate(local, expr Expression, body *Block) CaseSelectVariant(expr Expression, targetType fidlgen.Name, variants map[string]LocalWithBlock) CaseDeclareMaxOrdinal(local Expression) CaseSetMaxOrdinal(local, ordinal Expression) }