Path: blob/master/runtime/compiler/build/scripts/s390m4check.pl
6004 views
#!/bin/perl12# Copyright (c) 2000, 2019 IBM Corp. and others3#4# This program and the accompanying materials are made available under5# the terms of the Eclipse Public License 2.0 which accompanies this6# distribution and is available at https://www.eclipse.org/legal/epl-2.0/7# or the Apache License, Version 2.0 which accompanies this distribution and8# is available at https://www.apache.org/licenses/LICENSE-2.0.9#10# This Source Code may also be made available under the following11# Secondary Licenses when the conditions for such availability set12# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13# General Public License, version 2 with the GNU Classpath14# Exception [1] and GNU General Public License, version 2 with the15# OpenJDK Assembly Exception [2].16#17# [1] https://www.gnu.org/software/classpath/license.html18# [2] http://openjdk.java.net/legal/assembly-exception.html19#20# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception2122use warnings;23use strict;24use bytes; # avoid using Unicode internally2526die "usage: $0 filename\n" unless @ARGV == 1;27my $inputFile = pop @ARGV;28open FILE, $inputFile or die "unable to open file $inputFile";2930my $MAX_LENGTH = 71;31my $is_m4 = ( $inputFile =~ m/\.m4$/ );32my $is_ascii = 1 if ord('[') == 91;3334while (<FILE>)35{36chomp;37my $line = $_;38my $length = length($line);39die "line longer than $MAX_LENGTH characters ($length) '$line'"40if ( $length > $MAX_LENGTH );4142# check that only valid characters show up in the string43# %goodchars is a hash of characters allowed44my %goodchars = $is_ascii ?45map { $_ => 1 } ( 10, 13, 31 .. 127 ) : # ascii46map { $_ => 1 } ( 13, 21, 64 .. 249 ); # ebcdic47my $newline = $line;48$newline =~ s/(.)/$goodchars{ord($1)} ? $1 : ' '/eg;49die "invalid character(s) '$line'"50if $newline ne $line;5152my $comment_regex =53$is_m4 ? "ZZ" # M454: $is_ascii ? "#" # GAS55: "\\*\\*"; # HLASM5657# skip comment lines58next if $line =~ m/^$comment_regex/;59die "comment lines should not have preceding whitespace '$line'"60if $line =~ m/^\s+$comment_regex/;6162# strip the comments out63$line =~ s/$comment_regex.*$//;6465# the # character is considered a comment everywhere66$line =~ s/\#.*$//;6768die "comma in first column '$line'" if $line =~ m/^,/;69die "whitespace next to comma '$line'" if $line =~ m/\s,|,\s/;70die "whitespace within parentheses '$line'"71if $line =~ m/\(.*\s.*\)/;72die "whitespace before parentheses '$line'"73if $line =~ m/,\s+\(/;74}757677