Skip to content

Instantly share code, notes, and snippets.

@toyowata
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyowata/eb46f8e5ba18ec7bc84e to your computer and use it in GitHub Desktop.
Save toyowata/eb46f8e5ba18ec7bc84e to your computer and use it in GitHub Desktop.
armccのプリプロセスファイルから展開されたシステムインクルードファイルを削除するスクリプト
#!/usr/local/bin/perl
#
# Copyright 2010-2012 ARM Limited. All Rights Reserved.
# <toyomasa.watarai@arm.com>
# shrink_sysinc.pl - tries to remove expanded system include file from preprocessed source code
#
# Usage: shrink_sysinc.pl test.ii > test.cpp
# TODO:
# matching patterns in pre-processed file:
#
# 1 "J:\\RVCT\\4.1\\713\\include\\rw/_defs.h"
# 12 "d:\\SDK\\test\\mneme\\precompiled\\precompiled.h"
#line 123 "C:\\RVCT\\4.1\\995\\include\\inttypes.h"
use File::Basename;
$nested = 0;
$mask = 0;
$inc_name = "";
$inc_line = 0;
$once = 1;
$ARMCCINC = $ENV{'ARMCCINC'};
if ($#ARGV == -1)
{
print " shrink_sysinc.pl - Remove expanded system include file from a preprocessed source code\n";
print " Usage: shrink_sysinc.pl test.ii > test.cpp\n";
exit(0);
}
if ($ARMCCINC eq '')
{
# if ARMCCINC environement variable is not set, you can hard code system include
# path here (forward match and case sensitive)
# e.g. $ARMCCINC = 'C:\RVCT\5.02\28\include';
$ARMCCINC = 'J:\RVCT\5.03\102\include';
}
# change single back-slash to be 4 (for regexp), since precompiled source has 2
$ARMCCINC =~ s/\\/\\\\\\\\/g;
for ($i = 0; $i <= $#ARGV; $i++) {
open(IN, $ARGV[$i]);
while ($buf = <IN>) {
if ($buf =~ /^\#(line)* ([0-9]{1,10}) \"${ARMCCINC}.*\"/ ) {
if ($nested =! 0 && $once == 1) {
$mask = 1;
$once = 0;
$sys_inc = $buf;
$sys_inc =~ s/(^\#(line)* )([0-9]{1,10})( )(\"${ARMCCINC}.*)(\")/$5/g;
chomp($sys_inc);
$result = basename($sys_inc);
print "#include <$result>\n";
}
} else {
if ($buf =~ /^\#(line)* ([0-9]{1,10}) \".*?\"/ ) {
$inc_name = $buf;
$inc_name =~ s/(^\#(line)* )([0-9]{1,10})( )(\".*?\")/$5/g;
$nested += 1;
$inc_line = 1;
print "// $buf";
$once = 1;
}
}
if ( $mask == 1 ) {
if (index ($buf, $inc_name) != -1) {
$nested -= 1;
$mask = 0;
}
}
if ($mask == 0 && $inc_line == 0) {
print $buf;
}
$inc_line = 0;
}
close(IN);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment