Skip to content

Commit 37dea80

Browse files
committed
add support for .NET IL (Intermediate Language) #883
new disambiguation function SKILL_or_DotNetIL(); add test for SKILL
1 parent bf6b7a4 commit 37dea80

7 files changed

+260
-21
lines changed

Unix/cloc

+72-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22
# cloc -- Count Lines of Code {{{1
3-
# Copyright (C) 2006-2024 Al Danial <al.danial@gmail.com>
3+
# Copyright (C) 2006-2025 Al Danial <al.danial@gmail.com>
44
# First release August 2006
55
#
66
# Includes code from:
@@ -45,6 +45,7 @@ use File::Spec;
4545
use IO::File;
4646
use List::Util qw( min max );
4747
use Cwd;
48+
use Encode qw( encode );
4849
use POSIX qw { strftime ceil};
4950

5051
# Digest::MD5 isn't in the standard distribution. Use it only if installed.
@@ -60,8 +61,6 @@ use Digest::MD5;
6061
# Time::HiRes became standard with Perl 5.8
6162
my $HAVE_Time_HiRes = 1;
6263
use Time::HiRes;
63-
#eval "use Time::HiRes;";
64-
#$HAVE_Time_HiRes = 1 if defined $Time::HiRes::VERSION;
6564

6665
my $HAVE_Rexexp_Common = 1;
6766
# Regexp::Common isn't in the standard distribution. It will
@@ -273,6 +272,7 @@ my (
273272
$opt_no_recurse ,
274273
$opt_only_count_files ,
275274
$opt_fmt ,
275+
$opt_encoding ,
276276
);
277277

278278
my $getopt_success = GetOptions( # {{{1
@@ -380,6 +380,7 @@ my $getopt_success = GetOptions( # {{{1
380380
"no_recurse|no-recurse" => \$opt_no_recurse ,
381381
"only_count_files|only-count-files" => \$opt_only_count_files ,
382382
"fmt=i" => \$opt_fmt ,
383+
"encoding=s" => \$opt_encoding , # not production ready #880
383384
);
384385
# 1}}}
385386
$config_file = $opt_config_file if defined $opt_config_file;
@@ -791,6 +792,7 @@ my %Extension_Collision = (
791792
'Verilog-SystemVerilog/Coq' => [ 'v' ] ,
792793
'Visual Basic/TeX/Apex Class' => [ 'cls' ] ,
793794
'Scheme/SaltStack' => [ 'sls' ] ,
795+
'SKILL/.NET IL' => [ 'il' ] ,
794796
);
795797
my @Autogen_to_ignore = no_autogen_files($list_no_autogen);
796798
if ($opt_force_lang_def) {
@@ -6463,16 +6465,19 @@ sub open_file { # {{{1
64636465
$filename, # filename to open
64646466
$use_new_file, # whether to use `new IO::File` or `open` when not using Win32::LongPath
64656467
) = @_;
6466-
if ($ON_WINDOWS and $HAVE_Win32_Long_Path) {
6467-
my $file = undef;
6468-
openL(\$file, $mode, $filename);
6469-
return $file;
6470-
} elsif ($use_new_file) {
6471-
return new IO::File $filename, $mode;
6468+
my $fh = undef;
6469+
if (defined $opt_encoding) {
6470+
open($fh,"<:encoding($opt_encoding)", $filename) or
6471+
die "Failed open('<:encoding($opt_encoding)', $filename): $!";
6472+
} else {
6473+
if ($ON_WINDOWS and $HAVE_Win32_Long_Path) {
6474+
openL(\$fh, $mode, $filename);
6475+
} elsif ($use_new_file) {
6476+
return new IO::File $filename, $mode;
6477+
}
6478+
open($fh, $mode, $filename);
64726479
}
6473-
my $file = undef;
6474-
open($file, $mode, $filename);
6475-
return $file;
6480+
return $fh;
64766481
} # 1}}}
64776482
sub unlink_file { # {{{1
64786483
# portable method to unlink a file. On Windows this uses Win32::LongPath to
@@ -6753,6 +6758,8 @@ sub classify_file { # {{{1
67536758
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Pawn') {
67546759
my $lang_p_or_p = "";
67556760
return Pascal_or_Pawn($full_file, $rh_Err, $raa_errors);
6761+
} elsif ($Language_by_Extension{$extension} eq 'SKILL/.NET IL') {
6762+
return SKILL_or_DotNetIL($full_file, $rh_Err, $raa_errors);
67566763
} elsif ($Language_by_Extension{$extension} eq 'Brainfuck') {
67576764
if (really_is_bf($full_file)) {
67586765
return $Language_by_Extension{$extension};
@@ -8919,7 +8926,7 @@ sub set_constants { # {{{1
89198926
'ipl' => 'IPL' ,
89208927
'pro' => 'IDL/Qt Project/Prolog/ProGuard' ,
89218928
'ig' => 'Modula3' ,
8922-
'il' => 'SKILL' ,
8929+
'il' => 'SKILL/.NET IL' ,
89238930
'ils' => 'SKILL++' ,
89248931
'inc' => 'PHP/Pascal/Fortran/Pawn',
89258932
'ino' => 'Arduino Sketch' ,
@@ -9035,6 +9042,10 @@ sub set_constants { # {{{1
90359042
'mojom' => 'Mojom' ,
90369043
'mojo' => 'Mojo' ,
90379044
'🔥' => 'Mojo' ,
9045+
'mbt' => 'MoonBit' ,
9046+
'mbti' => 'MoonBit' ,
9047+
'mbtx' => 'MoonBit' ,
9048+
'mbty' => 'MoonBit' ,
90389049
'meson.build' => 'Meson' ,
90399050
'metal' => 'Metal' ,
90409051
'mk' => 'make' ,
@@ -10520,6 +10531,7 @@ sub set_constants { # {{{1
1052010531
[ 'call_regexp_common' , 'C' ],
1052110532
[ 'remove_inline' , '#.*$' ],
1052210533
],
10534+
'MoonBit' => [ [ 'remove_matches' , '^\s*//' ], ],
1052310535
'Nemerle' => [
1052410536
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
1052510537
[ 'rm_comments_in_strings', '"', '//', '' ],
@@ -10564,6 +10576,11 @@ sub set_constants { # {{{1
1056410576
'Mustache' => [
1056510577
[ 'remove_between_general', '{{!', '}}' ],
1056610578
],
10579+
'.NET IL' => [
10580+
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
10581+
[ 'rm_comments_in_strings', '"', '//', '' ],
10582+
[ 'call_regexp_common' , 'C++' ],
10583+
],
1056710584
'Nickel' => [
1056810585
[ 'remove_matches' , '^\s*#' ],
1056910586
[ 'remove_inline' , '#.*$' ],
@@ -10909,6 +10926,7 @@ sub set_constants { # {{{1
1090910926
[ 'rm_comments_in_strings', '"', '//', '' ],
1091010927
[ 'call_regexp_common' , 'C++' ],
1091110928
],
10929+
'SKILL/.NET IL' => [ [ 'die' , ], ], # never called
1091210930
'SKILL' => [
1091310931
[ 'call_regexp_common' , 'C' ],
1091410932
[ 'remove_matches' , '^\s*;' ],
@@ -11756,8 +11774,10 @@ sub set_constants { # {{{1
1175611774
'Modelica' => 2.00,
1175711775
'MUMPS' => 4.21,
1175811776
'Mustache' => 1.75,
11777+
'MoonBit' => 2.50,
1175911778
'Nastran' => 1.13,
1176011779
'Nemerle' => 2.50,
11780+
'.NET IL' => 3.00,
1176111781
'NetLogo' => 4.00,
1176211782
'Nickel' => 2.00,
1176311783
'Nim' => 2.00,
@@ -11964,6 +11984,7 @@ sub set_constants { # {{{1
1196411984
'Verilog-SystemVerilog/Coq' => 1.00,
1196511985
'MATLAB/Mathematica/Objective-C/MUMPS/Mercury' => 1.00,
1196611986
'IDL/Qt Project/Prolog/ProGuard' => 1.00,
11987+
'SKILL/.NET IL' => 1.00,
1196711988
);
1196811989
# 1}}}
1196911990
%{$rh_Known_Binary_Archives} = ( # {{{1
@@ -12969,6 +12990,44 @@ sub Pascal_or_Pawn { # {{{1
1296912990
return "Pawn";
1297012991
}
1297112992
} # 1}}}
12993+
sub SKILL_or_DotNetIL { # {{{1
12994+
my ($file , # in
12995+
$rh_Err , # in hash of error codes
12996+
$raa_errors , # out
12997+
) = @_;
12998+
12999+
print "-> SKILL_or_DotNetIL($file)\n" if $opt_v > 2;
13000+
13001+
my $lang = undef;
13002+
my $IN = open_file('<', $file, 1);
13003+
if (!defined $IN) {
13004+
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
13005+
return $lang;
13006+
}
13007+
my $skill = 0;
13008+
my $dnet_il = 0;
13009+
while (<$IN>) {
13010+
next if /^\s*$/;
13011+
if (/^\s*;/) {
13012+
$skill += 50;
13013+
} elsif (/^\.(class|assembly|method|custom|entrypoint)/) {
13014+
$dnet_il += 50;
13015+
last;
13016+
} elsif (/{\s*$/ or /^\s*}/) {
13017+
$dnet_il += 5;
13018+
} elsif (/^\s*(procedure|let|foreach)\b/) {
13019+
$skill += 1;
13020+
}
13021+
}
13022+
$IN->close;
13023+
13024+
print "<- SKILL_or_DotNetIL($file: SKILL=$skill, .NET IL=$dnet_il\n" if $opt_v > 2;
13025+
if ($skill > $dnet_il) {
13026+
return "SKILL";
13027+
} else {
13028+
return ".NET IL";
13029+
}
13030+
} # 1}}}
1297213031
sub html_colored_text { # {{{1
1297313032
# http://www.pagetutor.com/pagetutor/makapage/pics/net216-2.gif
1297413033
my ($color, $text) = @_;

Unix/t/00_C.t

+15-5
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ my @Tests = (
792792
'ref' => '../tests/outputs/drupal.mxml.yaml',
793793
'args' => '../tests/inputs/drupal.mxml',
794794
},
795+
{
796+
'name' => '.NET IL',
797+
'ref' => '../tests/outputs/dotNET_intermediate.il.yaml',
798+
'args' => '../tests/inputs/dotNET_intermediate.il',
799+
},
795800
{
796801
'name' => 'NetLogo',
797802
'ref' => '../tests/outputs/vinos.nlogo.yaml',
@@ -1090,21 +1095,26 @@ my @Tests = (
10901095
'ref' => '../tests/outputs/messages.rb.yaml',
10911096
'args' => '../tests/inputs/messages.rb',
10921097
},
1093-
{
1094-
'name' => 'SCSS',
1095-
'ref' => '../tests/outputs/style.scss.yaml',
1096-
'args' => '../tests/inputs/style.scss',
1097-
},
10981098
{
10991099
'name' => 'SaltStack',
11001100
'ref' => '../tests/outputs/certificates.sls.yaml',
11011101
'args' => '../tests/inputs/certificates.sls',
11021102
},
1103+
{
1104+
'name' => 'SCSS',
1105+
'ref' => '../tests/outputs/style.scss.yaml',
1106+
'args' => '../tests/inputs/style.scss',
1107+
},
11031108
{
11041109
'name' => 'Scheme',
11051110
'ref' => '../tests/outputs/scheme.sls.yaml',
11061111
'args' => '../tests/inputs/scheme.sls',
11071112
},
1113+
{
1114+
'name' => 'SKILL',
1115+
'ref' => '../tests/outputs/ChangeProperties.il.yaml',
1116+
'args' => '../tests/inputs/ChangeProperties.il',
1117+
},
11081118
{
11091119
'name' => 'Starlark',
11101120
'ref' => '../tests/outputs/build.bzl.yaml',

cloc

+52-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22
# cloc -- Count Lines of Code {{{1
3-
# Copyright (C) 2006-2024 Al Danial <al.danial@gmail.com>
3+
# Copyright (C) 2006-2025 Al Danial <al.danial@gmail.com>
44
# First release August 2006
55
#
66
# Includes code from:
@@ -383,7 +383,7 @@ my $getopt_success = GetOptions( # {{{1
383383
"no_recurse|no-recurse" => \$opt_no_recurse ,
384384
"only_count_files|only-count-files" => \$opt_only_count_files ,
385385
"fmt=i" => \$opt_fmt ,
386-
"encoding=s" => \$opt_encoding ,
386+
"encoding=s" => \$opt_encoding , # not production ready #880
387387
);
388388
# 1}}}
389389
$config_file = $opt_config_file if defined $opt_config_file;
@@ -784,6 +784,7 @@ my %Extension_Collision = (
784784
'Verilog-SystemVerilog/Coq' => [ 'v' ] ,
785785
'Visual Basic/TeX/Apex Class' => [ 'cls' ] ,
786786
'Scheme/SaltStack' => [ 'sls' ] ,
787+
'SKILL/.NET IL' => [ 'il' ] ,
787788
);
788789
my @Autogen_to_ignore = no_autogen_files($list_no_autogen);
789790
if ($opt_force_lang_def) {
@@ -6749,6 +6750,8 @@ sub classify_file { # {{{1
67496750
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Pawn') {
67506751
my $lang_p_or_p = "";
67516752
return Pascal_or_Pawn($full_file, $rh_Err, $raa_errors);
6753+
} elsif ($Language_by_Extension{$extension} eq 'SKILL/.NET IL') {
6754+
return SKILL_or_DotNetIL($full_file, $rh_Err, $raa_errors);
67526755
} elsif ($Language_by_Extension{$extension} eq 'Brainfuck') {
67536756
if (really_is_bf($full_file)) {
67546757
return $Language_by_Extension{$extension};
@@ -8915,7 +8918,7 @@ sub set_constants { # {{{1
89158918
'ipl' => 'IPL' ,
89168919
'pro' => 'IDL/Qt Project/Prolog/ProGuard' ,
89178920
'ig' => 'Modula3' ,
8918-
'il' => 'SKILL' ,
8921+
'il' => 'SKILL/.NET IL' ,
89198922
'ils' => 'SKILL++' ,
89208923
'inc' => 'PHP/Pascal/Fortran/Pawn',
89218924
'ino' => 'Arduino Sketch' ,
@@ -10565,6 +10568,11 @@ sub set_constants { # {{{1
1056510568
'Mustache' => [
1056610569
[ 'remove_between_general', '{{!', '}}' ],
1056710570
],
10571+
'.NET IL' => [
10572+
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
10573+
[ 'rm_comments_in_strings', '"', '//', '' ],
10574+
[ 'call_regexp_common' , 'C++' ],
10575+
],
1056810576
'Nickel' => [
1056910577
[ 'remove_matches' , '^\s*#' ],
1057010578
[ 'remove_inline' , '#.*$' ],
@@ -10910,6 +10918,7 @@ sub set_constants { # {{{1
1091010918
[ 'rm_comments_in_strings', '"', '//', '' ],
1091110919
[ 'call_regexp_common' , 'C++' ],
1091210920
],
10921+
'SKILL/.NET IL' => [ [ 'die' , ], ], # never called
1091310922
'SKILL' => [
1091410923
[ 'call_regexp_common' , 'C' ],
1091510924
[ 'remove_matches' , '^\s*;' ],
@@ -11760,6 +11769,7 @@ sub set_constants { # {{{1
1176011769
'MoonBit' => 2.50,
1176111770
'Nastran' => 1.13,
1176211771
'Nemerle' => 2.50,
11772+
'.NET IL' => 3.00,
1176311773
'NetLogo' => 4.00,
1176411774
'Nickel' => 2.00,
1176511775
'Nim' => 2.00,
@@ -11966,6 +11976,7 @@ sub set_constants { # {{{1
1196611976
'Verilog-SystemVerilog/Coq' => 1.00,
1196711977
'MATLAB/Mathematica/Objective-C/MUMPS/Mercury' => 1.00,
1196811978
'IDL/Qt Project/Prolog/ProGuard' => 1.00,
11979+
'SKILL/.NET IL' => 1.00,
1196911980
);
1197011981
# 1}}}
1197111982
%{$rh_Known_Binary_Archives} = ( # {{{1
@@ -12971,6 +12982,44 @@ sub Pascal_or_Pawn { # {{{1
1297112982
return "Pawn";
1297212983
}
1297312984
} # 1}}}
12985+
sub SKILL_or_DotNetIL { # {{{1
12986+
my ($file , # in
12987+
$rh_Err , # in hash of error codes
12988+
$raa_errors , # out
12989+
) = @_;
12990+
12991+
print "-> SKILL_or_DotNetIL($file)\n" if $opt_v > 2;
12992+
12993+
my $lang = undef;
12994+
my $IN = open_file('<', $file, 1);
12995+
if (!defined $IN) {
12996+
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
12997+
return $lang;
12998+
}
12999+
my $skill = 0;
13000+
my $dnet_il = 0;
13001+
while (<$IN>) {
13002+
next if /^\s*$/;
13003+
if (/^\s*;/) {
13004+
$skill += 50;
13005+
} elsif (/^\.(class|assembly|method|custom|entrypoint)/) {
13006+
$dnet_il += 50;
13007+
last;
13008+
} elsif (/{\s*$/ or /^\s*}/) {
13009+
$dnet_il += 5;
13010+
} elsif (/^\s*(procedure|let|foreach)\b/) {
13011+
$skill += 1;
13012+
}
13013+
}
13014+
$IN->close;
13015+
13016+
print "<- SKILL_or_DotNetIL($file: SKILL=$skill, .NET IL=$dnet_il\n" if $opt_v > 2;
13017+
if ($skill > $dnet_il) {
13018+
return "SKILL";
13019+
} else {
13020+
return ".NET IL";
13021+
}
13022+
} # 1}}}
1297413023
sub html_colored_text { # {{{1
1297513024
# http://www.pagetutor.com/pagetutor/makapage/pics/net216-2.gif
1297613025
my ($color, $text) = @_;

tests/inputs/ChangeProperties.il

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;; This is SKILL
2+
;; https://www.mics.ece.vt.edu/ICDesign/Tutorials/Cadence/layout_pg5.html
3+
4+
/*
5+
This procedure will change the bulk node values of nfet3 and pfet3
6+
to be vss! and vdd!, respectively.
7+
*/
8+
9+
procedure(cb(lib cell)
10+
;let will allow you to access the cv and newlabel variables outside
11+
;of this procedure
12+
let((cv newLabel)
13+
;open the cellview as a database object and assign it to cv
14+
cv = dbOpenCellViewByType(lib cell "schematic" "" "a")
15+
;for loop to go through all instances in this cellview
16+
foreach(instancecv~>instances
17+
;open the property window -- this will display the window!
18+
geSelectObjectNoFilter(instance)
19+
schHiObjectProperty()
20+
;check the cellname and change the bulk node (bn) property
21+
if(schObjPropForm->cellName->value == "nfet3"
22+
then
23+
schObjPropForm->bn->value = "vss!"
24+
if(schObjPropForm->cellName->value == "pfet3"
25+
then
26+
schObjPropForm->bn->value = "vdd!"
27+
;close the form
28+
hiFormDone(schObjPropForm)
29+
geDeselectAll()
30+
);end foreach
31+
);end of let
32+
);end procedure

0 commit comments

Comments
 (0)