9 LocationCounter::LocationCounter():
13 void LocationCounter::visit(BasicTypeDeclaration &basic)
15 r_count = basic.kind==BasicTypeDeclaration::MATRIX ? basic.size>>16 : 1;
18 void LocationCounter::visit(ImageTypeDeclaration &)
23 void LocationCounter::visit(StructDeclaration &strct)
26 for(NodeList<Statement>::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
35 void LocationCounter::visit(VariableDeclaration &var)
38 if(var.type_declaration)
39 var.type_declaration->visit(*this);
41 if(const Literal *literal = dynamic_cast<const Literal *>(var.array_size.get()))
42 if(literal->value.check_type<int>())
43 r_count *= literal->value.value<int>();
47 void MemoryRequirementsCalculator::visit(BasicTypeDeclaration &basic)
49 if(basic.kind==BasicTypeDeclaration::BOOL)
54 else if(basic.kind==BasicTypeDeclaration::INT || basic.kind==BasicTypeDeclaration::FLOAT)
56 r_size = basic.size/8;
59 else if(basic.kind==BasicTypeDeclaration::VECTOR || basic.kind==BasicTypeDeclaration::MATRIX)
61 basic.base_type->visit(*this);
62 unsigned n_elem = basic.size&0xFFFF;
64 if(basic.kind==BasicTypeDeclaration::VECTOR)
65 r_alignment *= (n_elem==3 ? 4 : n_elem);
67 else if(basic.kind==BasicTypeDeclaration::ARRAY)
68 basic.base_type->visit(*this);
71 void MemoryRequirementsCalculator::visit(StructDeclaration &strct)
74 unsigned max_align = 1;
75 for(NodeList<Statement>::iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
83 total += r_alignment-1;
84 total -= total%r_alignment;
86 max_align = max(max_align, r_alignment);
89 r_alignment = max_align;
92 void MemoryRequirementsCalculator::visit(VariableDeclaration &var)
96 const vector<Layout::Qualifier> qualifiers = var.layout->qualifiers;
97 for(vector<Layout::Qualifier>::const_iterator i=qualifiers.begin(); (r_offset<0 && i!=qualifiers.end()); ++i)
102 if(var.type_declaration)
103 var.type_declaration->visit(*this);
105 if(const Literal *literal = dynamic_cast<const Literal *>(var.array_size.get()))
106 if(literal->value.check_type<int>())
107 r_size += r_alignment*(literal->value.value<int>()-1);
111 set<Node *> DependencyCollector::apply(FunctionDeclaration &func)
117 void DependencyCollector::visit(VariableReference &var)
119 if(var.declaration && !locals.count(var.declaration))
121 dependencies.insert(var.declaration);
122 var.declaration->visit(*this);
126 void DependencyCollector::visit(InterfaceBlockReference &iface)
128 if(iface.declaration)
130 dependencies.insert(iface.declaration);
131 iface.declaration->visit(*this);
135 void DependencyCollector::visit(FunctionCall &call)
138 dependencies.insert(call.declaration);
139 TraversingVisitor::visit(call);
142 void DependencyCollector::visit(VariableDeclaration &var)
145 if(var.type_declaration)
147 dependencies.insert(var.type_declaration);
148 var.type_declaration->visit(*this);
151 TraversingVisitor::visit(var);