-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.php
More file actions
76 lines (66 loc) · 1.46 KB
/
gen.php
File metadata and controls
76 lines (66 loc) · 1.46 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
69
70
71
72
73
74
75
<?php
if(count($argv) < 3){
die("Missing command arguments. php gen.php {object_count} {func_count}\n");
}
$ob_c = intval($argv[1]);
$func_c = intval($argv[2]);
$dir = __DIR__ . '/gen';
if(!file_exists($dir))
mkdir($dir);
$ob_ci = 0;
$ofiles = [];
while($ob_ci < $ob_c){
$ob_ci++;
$func_ci = 0;
$content = "";
while($func_ci < $func_c){
$func_ci++;
$fn = 'func_'.$ob_ci . '_'.$func_ci;
$content .= "\nint $fn(int x) {\n";
$content .= " return x + $func_ci;\n";
$content .= "}\n";
}
$cpath = $dir . '/ob_'.$ob_ci . '.c';
$opath = $dir . '/ob_'.$ob_ci . '.o';
file_put_contents($cpath, $content);
exec("cc -O0 -c $cpath -o $opath");
$ofiles[] = $opath;
}
// Main
$cmain = $dir . '/main.c';
$omain = $dir . '/main.o';
$ofiles[] = $omain;
$content = "";
$ob_ci = 0;
while($ob_ci < $ob_c){
$ob_ci++;
$func_ci = 0;
while($func_ci < $func_c){
$func_ci++;
$fn = 'func_'.$ob_ci . '_'.$func_ci;
$content .= "int $fn(int x);\n";
}
}
$content .= "\n\n int main() {\n";
$ob_ci = 0;
while($ob_ci < $ob_c){
$ob_ci++;
$func_ci = 0;
while($func_ci < $func_c){
$func_ci++;
$fn = 'func_'.$ob_ci . '_'.$func_ci;
$content .= "$fn(0);\n";
}
}
$content .= "}\n";
file_put_contents($cmain, $content);
exec("cc -O0 -c $cmain -o $omain");
// Link
echo "# Link\n";
$out = [];
$start = microtime(true);
$cmd = "cc -O0 ".(implode(" ", $ofiles))." -o $dir/out";
echo "# cmd: $cmd\n\n";
system($cmd);
echo "Time: " . (microtime(true) - $start) . "s\n";
echo "\n# Done\n";