Cross-Stage Logic and Architectural Synthesis: with Applications to Specialized Circuits and Programmable Processors