|
@@ -258,6 +258,67 @@ my %PARSE_RULES = (
|
|
|
'connect' => sub {
|
|
|
my $connect_line = shift;
|
|
|
$connect_line = trim($connect_line);
|
|
|
+ if ( $connect_line =~ m/([A-Z]{1}[A-Za-z0-9]{1,})\.([A-Za-z0-9]{1,})\ ([A-Z]{1}[A-Za-z0-9]{1,})\.([A-Za-z0-9]{1,})/ ) {
|
|
|
+ my $output_mod = $1;
|
|
|
+ my $output_mod_port = $2;
|
|
|
+ my $input_mod = $3;
|
|
|
+ my $input_mod_dst = $4;
|
|
|
+
|
|
|
+ # Check we have modules defined
|
|
|
+ if ( ! defined $AST{'Modules'} ) {
|
|
|
+ die "Parse error: Encountered connection but no modules are imported: $connect_line"
|
|
|
+ } else {
|
|
|
+ # Check that connect references imported modules and get module refs
|
|
|
+ my $output_mod_ref;
|
|
|
+ my $input_mod_ref;
|
|
|
+ foreach my $mod_ref ( @{$AST{'Modules'}} ) {
|
|
|
+ if ( $$mod_ref{'Module'} eq $output_mod ) {
|
|
|
+ $output_mod_ref = $mod_ref;
|
|
|
+ } elsif ( $$mod_ref{'Module'} eq $input_mod ) {
|
|
|
+ $input_mod_ref = $mod_ref;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ # If we reach the end of the loop and input/output refs are not set
|
|
|
+ # we didn't find the module, and it's a parse error
|
|
|
+ if ( ! defined $output_mod_ref ||
|
|
|
+ $output_mod_ref eq "" ||
|
|
|
+ ! defined $input_mod_ref ||
|
|
|
+ $input_mod_ref eq "" ) {
|
|
|
+ die "Parse error, couldn't find $output_mod or $input_mod in AST"
|
|
|
+ }
|
|
|
+
|
|
|
+ # Check src/dst ports
|
|
|
+ if ( ! defined $$output_mod_ref{'Outputs'}->{$output_mod_port} ) {
|
|
|
+ die "Parse error: $output_mod_port is not defined in module $output_mod"
|
|
|
+ } elsif ( ! defined $$input_mod_ref{'Inputs'}->{$input_mod_dst} ) {
|
|
|
+ die "Parse error: $input_mod_dst is not defined in module $input_mod"
|
|
|
+ }
|
|
|
+
|
|
|
+ # Everything looks good, make connection
|
|
|
+ my $get_conn_id = sub {
|
|
|
+ if ( ! defined $AST{'Connections'} ) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ my $c = 0;
|
|
|
+ foreach my $conn_id ( @{$AST{'Connections'}} ) {
|
|
|
+ $c++;
|
|
|
+ }
|
|
|
+ return $c;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ my $conn_id = $get_conn_id->();
|
|
|
+ my %conn_map = (
|
|
|
+ 'Output_Module' => $output_mod,
|
|
|
+ 'Output_Port' => $output_mod_port,
|
|
|
+ 'Input_Module' => $input_mod,
|
|
|
+ 'Input_Mod_Dst' => $input_mod_dst,
|
|
|
+ );
|
|
|
+ $AST{'Connections'}->{$conn_id} = \%conn_map;
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ die "Parse error at $connect_line";
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
);
|
|
@@ -287,6 +348,7 @@ sub line_parse($) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+# MAIN - split the input and parse it
|
|
|
foreach my $line ( split("\n", $src_content) ) {
|
|
|
chomp $line;
|
|
|
if ( $line eq "" ) {
|
|
@@ -295,5 +357,5 @@ foreach my $line ( split("\n", $src_content) ) {
|
|
|
line_parse($line);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ # Dump the AST for now. This is where we'd render the output
|
|
|
print Dumper %AST;
|