Monday, 16 January 2012

Vim Foo

My most advanced regular expression to date:

0,$ s:\(\d\+\)\s\+\(\w\+\d\+\):set_location_assignment PIN_\u\u\2 -to HdcSig[\1]

This takes a space-separated-value file of signal names and FPGA pin numbers and generates the tickle assignment statements required by the synthesis tool, Quartus.
0    aa1 
1    a4
2    b4
3    c9

set_location_assignment PIN_AA1 -to HdcSig[0]
set_location_assignment PIN_A4 -to HdcSig[1]
set_location_assignment PIN_B4 -to HdcSig[2]
set_location_assignment PIN_C9 -to HdcSig[3]
In Summary it:
  1. Extracts a numeric followed by alpha-numeric field and stores them in \1, \2 variables
  2. Adds a line prefix
  3. Capitalises coordinates
  4. Switches order of signal names vs coordinates
  5. Adds some braces
Result: feeling smug :D

No comments: