Skip to content

Commit

Permalink
Also verify that submodule writes are only to inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Nov 9, 2023
1 parent 758b3d6 commit 52ec912
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use num::bigint::BigUint;

use crate::{tokenizer::{TokenTypeIdx, get_token_type_name}, linker::{NamedUUID, FileUUID}, flattening::{FlattenedModule, WireIDMarker, WireID, OutsideWireID}, arena_alloc::ListAllocator, typing::Type};
use core::ops::Range;
use std::{ops::Deref, fmt::Display};
use std::fmt::Display;

// Token span. Indices are INCLUSIVE
#[derive(Clone,Copy,Debug,PartialEq,Eq)]
Expand Down
19 changes: 14 additions & 5 deletions src/flattening.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{ops::Deref, iter::zip};

use crate::{
ast::{Span, Value, Module, Expression, SpanExpression, LocalOrGlobal, Operator, AssignableExpression, SpanAssignableExpression, Statement, CodeBlock, AssignableExpressionWithModifiers, TypeExpression},
ast::{Span, Value, Module, Expression, SpanExpression, LocalOrGlobal, Operator, AssignableExpression, SpanAssignableExpression, Statement, CodeBlock, AssignableExpressionWithModifiers, IdentifierType},
linker::{Linker, Named, Linkable, get_builtin_uuid},
errors::{ErrorCollector, error_info}, arena_alloc::{ListAllocator, UUID}, tokenizer::kw, typing::{Type, get_unary_operator_types, get_binary_operator_types}
};
Expand Down Expand Up @@ -105,15 +105,24 @@ impl<'l, 'm, 'e> FlatteningContext<'l, 'm, 'e> {
Some(arr_content_type.clone())
},
ConnectionWrite::StructField(struct_field_box) => {
let (struct_or_instance, OutsideWireID(outside_field)) = struct_field_box.deref();
let ((struct_or_instance, struct_or_instance_span), OutsideWireID(outside_field)) = struct_field_box.deref();

let ConnectionWrite::Local(id) = struct_or_instance.0 else {todo!()};
let ConnectionWrite::Local(id) = struct_or_instance else {todo!()};

let Instantiation::Instantiation{typ : Type::Named(instantiation), typ_span} = &self.instantiations[id] else {todo!()};
let Instantiation::Instantiation{typ : Type::Named(instantiation), typ_span} = &self.instantiations[*id] else {todo!()};

let Named::Module(found) = &self.linker.links[*instantiation] else {panic!("Instantiation must be module!")};

let found_type = found.declarations[*outside_field].typ.0.map_to_type(&found.link_info.global_references);
let field_decl = &found.declarations[*outside_field];

if field_decl.identifier_type != IdentifierType::Input {
assert!(field_decl.identifier_type == IdentifierType::Output);
let field_decl_info = error_info(field_decl.span, found.link_info.file, "Output Defined Here");
self.errors.error_with_info(*struct_or_instance_span, "Cannot write to output of submodule!", vec![field_decl_info]);
return None;
}

let found_type = field_decl.typ.0.map_to_type(&found.link_info.global_references);

Some(found_type)
},
Expand Down

0 comments on commit 52ec912

Please sign in to comment.