Update skeleton

This commit is contained in:
Jeehoon Kang
2020-04-29 23:10:15 +09:00
parent 61b2162408
commit 3bef06455e
14 changed files with 3699 additions and 237 deletions

35
examples/c/float.c Normal file
View File

@@ -0,0 +1,35 @@
double custom_abs(double a) {
return a < 0 ? -a : a;
}
double custom_max(double a, double b) {
return a > b ? a : b;
}
int is_close(double a, double b, double rel_tol, double abs_tol) {
return custom_abs(a - b) <= custom_max(rel_tol * custom_max(custom_abs(a), custom_abs(b)), abs_tol);
}
double average(int len, int a[10]) {
int sum = 0;
int i;
for(i = 0; i < len; i++) {
sum += a[i];
}
return (double) sum / len;
}
int main() {
int a[10];
int len = 10;
for (int i = 0; i < len; i++) {
a[i] = i;
}
float avg = average(len, a);
return is_close(avg, 4.5, 1e-09, 0.1);
}

3205
examples/c/float2.c Normal file

File diff suppressed because it is too large Load Diff

59
examples/c/float2_gen.py Normal file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env python3
"""Make c program which uses floating point variables
To make c program, execute `python3 float_gen.py > file_name.c`
"""
import random
def random_operator():
ops = ["+", "-", "*", "/"]
return ops[random.randint(0, len(ops) - 1)]
def random_dtype():
dtypes = ["float", "double"]
return dtypes[random.randint(0, len(dtypes) - 1)]
def random_suffix():
suffixes = ["f", ""]
return suffixes[random.randint(0, len(suffixes) - 1)]
def make_expr(vars):
if len(vars) == 1:
return vars[0]
else:
var = vars.pop()
return "(" + var + " " + random_operator() + " " + make_expr(vars) + ")"
def make_func(i):
"""Make a function that contains a conditional expression
"""
func_signature = random_dtype() + " func_" + str(i) + "()"
variables = "abcdefghijklmnopqrstuvwxyzA"
func_inner = []
val_bitmap = []
# Variable initializiation
for var in variables:
val = random.gauss(0, 1)
val_bitmap.append(val)
decl = "\t" + random_dtype() + " " + var + " = " + str(val) + random_suffix() + ";"
func_inner.append(decl)
func_inner.append("\treturn " + make_expr(list(variables)) + ";")
return "\n".join([func_signature, "{"] + func_inner + ["}"])
if __name__ == "__main__":
src = ""
return_stmt = "\treturn (int)("
NUM_FUNC = 100
for i in range(NUM_FUNC):
src += make_func(i)
src += "\n\n"
return_stmt += "func_" + str(i) + "()"
return_stmt += " " + random_operator() + " " if i != (NUM_FUNC - 1) else ");"
src += "int main()\n{\n" + return_stmt + "\n}\n"
print(src)

View File

@@ -1,22 +1,23 @@
struct color { int number; char name; };
int f(int i, int const a[i]) {
int main() {
int temp = 0;
const float temp2 = 0.f, temp3 = 0.f;
temp = sizeof(unsigned char);
temp = _Alignof(unsigned char);
temp += sizeof(unsigned char);
temp += _Alignof(unsigned char);
struct color c;
c.name;
struct color c = {1, 2};
temp += c.name;
struct color *cp = &c;
cp->name;
temp += cp->name;
for(int i = 0, j = 0; i < 10; ++i) {
break;
if ( i == 2 && j == 0) break;
temp += i;
}
switch(temp) {
case 1: {
temp = 0;
break;
}
default: {