summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib9p/idl.gen36
1 files changed, 21 insertions, 15 deletions
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__":