First of all, ensure yourself that you have KB2844240 installed and configured. Then verify configuration of the compiler - you may want to decrease compiler level (especially if it’s set to Level 4) and to disable update of cross-references.
Then review your hardware - you should easily see whether you’re out of RAM or whether your processor runs constantly at 100%. The problem may be also in slow disks. Even without measurement, add more RAM. 4 GB is very little, especially if you have database server on the same machine.
Also look at Joris’s blog post about Dynamics AX 2012 Compile Times.