A computer-implemented method comprising: converting source code into an automaton comprising states and transitions between the states, the source code including one or more regular expressions, wherein the states in the automaton include a general purpose state that corresponds to a general purpose hardware element of a target hardware device and a special purpose state that corresponds to a special purpose hardware element of the target hardware device, wherein the general purpose hardware element including one or more inputs and one or more outputs, and is arranged to determine the one or more outputs based on the one or more inputs, and wherein special purpose hardware elements of the target hardware device are each arranged to implement a function that requires use of a larger number of general purpose hardware elements of the target hardware device than when implemented by the special purpose hardware element; wherein the special purpose hardware element of the target hardware device can be used to implement a more narrow range of functions than the general purpose hardware element; converting the automaton into a netlist, wherein converting the automaton into a netlist maps the states of the automaton to instances of a hardware element, wherein the netlist includes a plurality of instances, each instance corresponding to a hardware element of the target hardware device; and placing and routing the netlist to provide machine code for configuring the target hardware device, wherein the target hardware device is configured from the machine code to implement a finite state machine, wherein the finite state machine is mapped to the states in the automaton including the general purpose state and the special purpose state; wherein the method further comprises optimizing of the automaton, wherein optimizing includes splitting a particular state of the automaton into multiple states when an estimated in-degree of the particular state is greater than a constraint of the target hardware device, wherein splitting the particular state comprises distributing driving states of the particular state to the multiple states so that an in-degree of each of the multiple states meets the constraint. wherein the states in the automaton include a general purpose state that corresponds to a general purpose hardware element of a target hardware device and a special purpose state that corresponds to a special purpose hardware element of the target hardware device, wherein the general purpose hardware element including one or more inputs and one or more outputs, and is arranged to determine the one or more outputs based on the one or more inputs, and wherein special purpose hardware elements of the target hardware device are each arranged to implement a function that requires use of a larger number of general purpose hardware elements of the target hardware device than when implemented by the special purpose hardware element; wherein the special purpose hardware element of the target hardware device can be used to implement a more narrow range of functions than the general purpose hardware element; converting the automaton into a netlist, wherein converting the automaton into a netlist maps the states of the automaton to instances of a hardware element, wherein the netlist includes a plurality of instances, each instance corresponding to a hardware element of the target hardware device; and placing and routing the netlist to provide machine code for configuring the target hardware device, wherein the target hardware device is configured from the machine code to implement a finite state machine, wherein the finite state machine is mapped to the states in the automaton including the general purpose state and the special purpose state; wherein the method further comprises optimizing of the automaton, wherein optimizing includes splitting a particular state of the automaton into multiple states when an estimated in-degree of the particular state is greater than a constraint of the target hardware device, wherein splitting the particular state comprises distributing driving states of the particular state to the multiple states so that an in-degree of each of the multiple states meets the constraint.