Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/build/scripts/s390m4check.pl
6004 views
1
#!/bin/perl
2
3
# Copyright (c) 2000, 2019 IBM Corp. and others
4
#
5
# This program and the accompanying materials are made available under
6
# the terms of the Eclipse Public License 2.0 which accompanies this
7
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
# or the Apache License, Version 2.0 which accompanies this distribution and
9
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10
#
11
# This Source Code may also be made available under the following
12
# Secondary Licenses when the conditions for such availability set
13
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
# General Public License, version 2 with the GNU Classpath
15
# Exception [1] and GNU General Public License, version 2 with the
16
# OpenJDK Assembly Exception [2].
17
#
18
# [1] https://www.gnu.org/software/classpath/license.html
19
# [2] http://openjdk.java.net/legal/assembly-exception.html
20
#
21
# 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-exception
22
23
use warnings;
24
use strict;
25
use bytes; # avoid using Unicode internally
26
27
die "usage: $0 filename\n" unless @ARGV == 1;
28
my $inputFile = pop @ARGV;
29
open FILE, $inputFile or die "unable to open file $inputFile";
30
31
my $MAX_LENGTH = 71;
32
my $is_m4 = ( $inputFile =~ m/\.m4$/ );
33
my $is_ascii = 1 if ord('[') == 91;
34
35
while (<FILE>)
36
{
37
chomp;
38
my $line = $_;
39
my $length = length($line);
40
die "line longer than $MAX_LENGTH characters ($length) '$line'"
41
if ( $length > $MAX_LENGTH );
42
43
# check that only valid characters show up in the string
44
# %goodchars is a hash of characters allowed
45
my %goodchars = $is_ascii ?
46
map { $_ => 1 } ( 10, 13, 31 .. 127 ) : # ascii
47
map { $_ => 1 } ( 13, 21, 64 .. 249 ); # ebcdic
48
my $newline = $line;
49
$newline =~ s/(.)/$goodchars{ord($1)} ? $1 : ' '/eg;
50
die "invalid character(s) '$line'"
51
if $newline ne $line;
52
53
my $comment_regex =
54
$is_m4 ? "ZZ" # M4
55
: $is_ascii ? "#" # GAS
56
: "\\*\\*"; # HLASM
57
58
# skip comment lines
59
next if $line =~ m/^$comment_regex/;
60
die "comment lines should not have preceding whitespace '$line'"
61
if $line =~ m/^\s+$comment_regex/;
62
63
# strip the comments out
64
$line =~ s/$comment_regex.*$//;
65
66
# the # character is considered a comment everywhere
67
$line =~ s/\#.*$//;
68
69
die "comma in first column '$line'" if $line =~ m/^,/;
70
die "whitespace next to comma '$line'" if $line =~ m/\s,|,\s/;
71
die "whitespace within parentheses '$line'"
72
if $line =~ m/\(.*\s.*\)/;
73
die "whitespace before parentheses '$line'"
74
if $line =~ m/,\s+\(/;
75
}
76
77