Spinorial cohomology and maximally supersymmetric theories