In this paper, we describe a software architecture supporting code generation from within Ptolemy II. Ptolemy II is a componentbased design tool intended for embedded and real-time system design. The infrastructure described here provides a platform for experimentation with synthesis of embedded software or hardware designs from high-level, Java-based specifications. A specification consists of a set of interconnected actors whose functionality is defined in Java. The provided infrastructure parses the existing Java code for the actors and presents a simple API, using the pattern, for transforming the abstract syntax tree and writing code transformers and back-end code generators. A code transformer is described that performs generic optimizations, such as specialization of polymorphic data types, and domain-specific optimizations, such as static buffer allocation for communication between dataflow actors. The back end resynthesizes the transformed Java code. We describe a simple exam...