From d018906715b395e0fb9624cbd5b7fbf1c0e3f559 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 21 Dec 2024 21:39:02 -0700 Subject: lib9p: idl.gen: Do a better job of organizing the Python into sections --- lib9p/idl.gen | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib9p') diff --git a/lib9p/idl.gen b/lib9p/idl.gen index 47d1102..4f1e8b8 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -17,7 +17,7 @@ import idl # this script, marked with "SPECIAL". -# Generate C ################################################################### +# Utilities #################################################################### idprefix = "lib9p_" @@ -54,6 +54,21 @@ def c_typename(typ: idl.Type) -> str: raise ValueError(f"not a type: {typ.__class__.__name__}") +def c_expr(expr: idl.Expr) -> str: + ret: list[str] = [] + for tok in expr.tokens: + match tok: + case idl.ExprOp(): + ret += [tok.op] + case idl.ExprLit(): + ret += [str(tok.val)] + case idl.ExprSym(name="end"): + ret += ["ctx->net_offset"] + case idl.ExprSym(): + ret += [f"_{tok.name[1:]}_offset"] + return " ".join(ret) + + _ifdef_stack: list[str | None] = [] @@ -96,6 +111,9 @@ def ifdef_pop(n: int) -> str: return ret +# Generate .h ################################################################## + + def gen_h(versions: set[str], typs: list[idl.Type]) -> str: global _ifdef_stack _ifdef_stack = [] @@ -236,19 +254,7 @@ enum {idprefix}version {{ return ret -def c_expr(expr: idl.Expr) -> str: - ret: list[str] = [] - for tok in expr.tokens: - match tok: - case idl.ExprOp(): - ret += [tok.op] - case idl.ExprLit(): - ret += [str(tok.val)] - case idl.ExprSym(name="end"): - ret += ["ctx->net_offset"] - case idl.ExprSym(): - ret += [f"_{tok.name[1:]}_offset"] - return " ".join(ret) +# Generate .c ################################################################## def gen_c(versions: set[str], typs: list[idl.Type]) -> str: @@ -716,7 +722,7 @@ LM_FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_s return ret -################################################################################ +# Main ######################################################################### if __name__ == "__main__": -- cgit v1.2.3-2-g168b