Created
November 6, 2017 08:08
-
-
Save haotian-liu/210aef0040a52e7896f35e7057a98b50 to your computer and use it in GitHub Desktop.
Simple PHP script to convert UCF constraints to XDC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Convert UCF to XDC</h3> | |
<?php | |
$handle = isset($_POST['handle']) && !empty($_POST['handle']) ? $_POST['handle'] : null; | |
if ($handle === null) { | |
echo ' | |
<form method="POST"> | |
<textarea name="handle" rows="20" style="width:90%; max-width: 640px"></textarea> | |
<br> | |
<input type="submit" value="Convert"> | |
</form> | |
'; | |
exit(); | |
} | |
$buffer = $handle; | |
$buffer = preg_replace("/#([^\n]*)/", "", $buffer); | |
$buffer = preg_replace("/;([^\n]*)/", "", $buffer); | |
$buffer = str_replace(["LOC", "PULLUP"], ["PACKAGE_PIN", "PULLUP = true"], $buffer); | |
preg_match_all("/NET \"([^\"]*)\"([^\n]*)/", $buffer, $matches); | |
for ($i = 0; $i < count ($matches[0]); $i++) { | |
$drive = trim($matches[1][$i]); | |
if (strstr($drive, "[")) $drive = "{{$drive}}"; | |
$device = $matches[2][$i]; | |
$devices = explode('|', $device); | |
$buffer = "set_property -dict {"; | |
foreach ($devices as $each) { | |
$each = trim($each); | |
$each = str_replace("\"", "", $each); | |
preg_match("/([A-Z_]*) = ([A-Za-z0-9]*)/", $each, $match); | |
if (count($match) == 0) { continue; } | |
$buffer .= "{$match[1]} {$match[2]} "; | |
} | |
$buffer = trim($buffer); | |
$buffer .= "} [get_ports {$drive}]"; | |
echo $buffer; | |
echo "<br>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment