[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

inline expressions for decodetree !function syntax

From: Peter Maydell
Subject: inline expressions for decodetree !function syntax
Date: Thu, 15 Jul 2021 10:33:28 +0100

I have found myself wondering whether it would be a good idea for
decodetree to support some minimal syntax for defining constant-modifying
functions inline in the decode file, so that instead of writing

   %imm4_16_p1 16:4 !function=plus_1

and then having to define a "plus_1" function somewhere in a .c file,
you could write something like

   %imm4_16_p1 16:4 !function="x + 1"

and decodetree would just wrap the quoted string in
 "static inline int fnname(DisasContext *s, int x) {return %s;}"
(autogenerating a unique function name for it).

Obviously the error messages if you put some complete rubbish inside the
quoted string could be a bit opaque, but a full-on expression parser seems
like overkill. The existing mechanism would be retained for more
complicated functions, but this sort of shorthand seems like it is more
readable than the current situation where we are gradually accumulating
various "plus_1", "times_2", "negate", etc functions and trying to come
up with function names that remind us of the trivial expressions they
are wrapping. (target/arm actually has three separate implementations of
the "add 1" function right now :-))

What do you think?

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]