Of course, as noted by Yuval Filmus, one should not expect a general
solution to such problems. But as is usually the case, solutions can be
found for interesting subsets of the general case.
I am in no way expert, or even significantly knowledgeable in this
area, by I happen to know of some work of the kind. It concerns
automatic average complexity analysis, and the work was done by
Philippe Flajolet and his colleagues.
From what I understood when it was explained to me, the authors
designed a small language (nothing Turing complete as you might
expect, but significant enough) so that any algorithm written within
the constraint of that language could have its average complexity
analyzed automatically.The system was called at the time Lambda-Upsilon-Omega, i.e. $\lambda\acute\upsilon\omega$ (I unbind).
One paper I found on the web is a 1990 paper: Automatic average-case
analysis of algorithms by Philippe Flajolet, Paul Zimmermann, and Bruno
I would expect that later papers have extended this work, but I do not
really know. The work was quite heavily cited, and searching the web
for it should yield more recent work on the same topic.
Now, I am afraid that the work of Flajolet and his colleagues was very mathematical, and I would not expect much easy reading.