-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_function
More file actions
executable file
·68 lines (60 loc) · 1.5 KB
/
insert_function
File metadata and controls
executable file
·68 lines (60 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env perl
# USAGE:
# $ insert_function INFILE FUNCTION...
# This script will look in the INFILE for the function dx_sethi, and locate
# the else statement in the if-else chain contained in it. It then parses
# each FUNCTION file for functions generated by llvm2opal (with the -o
# option, so there is an opcode) and insert them into dx_sethi as an
# else if statemnt.
open (my $in, "<", $ARGV[0]) || die ("Failed to open input file: $!");
my $step = 0;
while (<$in>)
{
# Locat dx_set.
if ($step == 0 && $_ =~ /dx_sethi/)
{
$step = 1;
}
# Locate last else statement.
elsif ($step == 1 && $_ =~ /else {/)
{
$step = 2;
$save = $_;
for ($i = 1; $i <= $#ARGV; $i++)
{
ins_file ($ARGV[$i]);
}
print $save;
}
print $_;
}
sub ins_file {
my $file = shift;
open (my $src, "<", $file) || die ("Failed to open input file: $!");
$first_func = 1;
while (<$src>)
{
if ($_ =~ /OPCODE /)
{
# Print a closing bracket for previous function, if needed.
if ($first_func)
{
$first_func = 0;
}
else
{
print " }\n";
}
$_ =~ s/OPCODE (.*)\n/$1/g;
print " else if (op==$_)\n";
print " {\n";
}
elsif ($_ !~ /^\n/)
{
$_ =~ s/^\s*/ /g;
print $_;
}
}
# Print last closing bracket.
print " }\n";
}