Testcases and executable rename

This commit is contained in:
Erki 2021-02-24 17:45:27 +02:00
parent 7849afc4dd
commit e30d779c30
7 changed files with 253 additions and 4 deletions

View File

@ -17,18 +17,21 @@ endif ()
llvm_map_components_to_libnames(llvm_libs support option core)
add_executable(llvm_proto main.cpp OperationFinder.cpp)
add_executable(op-finder
main.cpp
OperationFinder.cpp
)
target_include_directories(llvm_proto
target_include_directories(op-finder
PRIVATE ${LLVM_INCLUDE_DIRS}
)
target_compile_definitions(llvm_proto
target_compile_definitions(op-finder
PRIVATE
${LLVM_DEFINITIONS}
)
target_link_libraries(llvm_proto
target_link_libraries(op-finder
PRIVATE
${llvm_libs}
clangTooling

24
testcases/assignment.c Normal file
View File

@ -0,0 +1,24 @@
#define A (unsigned long)4
#define STUFF int c = a + b
#warning butts
#include "stuff.h"
void g()
{
int a = 4;
int b = 6;
int c = a + b;
(void)c;
}
int main()
{
short a = A;
char b = 3;
STUFF;
int c2 = a + A;
}

3
testcases/dump-ast Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
clang -Xclang -ast-dump -fsyntax-only $1

46
testcases/fir.c Normal file
View File

@ -0,0 +1,46 @@
/*******************************************************************************
*
* Name : FIR Filter
* Purpose : Benchmark an FIR filter. The input values for the filter
* is an array of 51 16-bit values. The order of the filter is
* 17.
*
*******************************************************************************/
#ifdef MSP430
#include "msp430x14x.h"
#endif
#include <math.h>
#define FIR_LENGTH 17
const float COEFF[FIR_LENGTH] =
{
-0.000091552734, 0.000305175781, 0.004608154297, 0.003356933594, -0.025939941406,
-0.044006347656, 0.063079833984, 0.290313720703, 0.416748046875, 0.290313720703,
0.063079833984, -0.044006347656, -0.025939941406, 0.003356933594, 0.004608154297,
0.000305175781, -0.000091552734};
/* The following array simulates input A/D converted values */
const unsigned int INPUT[] =
{
0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x0000, 0x0000, 0x0000,
0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000,
0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000, 0x0C00, 0x0800,
0x0400, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00,
0x2000, 0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000, 0x0C00,
0x0800, 0x0400, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800,
0x1C00, 0x2000, 0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000,
0x0C00, 0x0800, 0x0400};
void main(void)
{
int i, y; /* Loop counters */
volatile float OUTPUT[36],sum;
for(y = 0; y < 36; y++)
{
sum=0;
for(i = 0; i < FIR_LENGTH/2; i++)
{
sum = sum+COEFF[i] * ( INPUT[y + 16 - i] + INPUT[y + i] );
}
OUTPUT[y] = sum + (INPUT[y + FIR_LENGTH/2] * COEFF[FIR_LENGTH/2] );
}
return;
}

123
testcases/gauss_blur.c Normal file
View File

@ -0,0 +1,123 @@
#include <stdlib.h>
int gauss_blur(){
char Gauss[] = {99, 68, 35, 10};
int g_acc;
int tot = 0;
int i, k = 0, l, x, y;
unsigned char** g_tmp_image;
unsigned char * gauss_image;
unsigned char * outputImage;
unsigned char * inputImage;
int pictureHight = 50;
int pictureWidth = 50;
const int GB = 1;
const int NB = 1;
char maxdiff, val;
gauss_image = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char));
outputImage = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char));
g_tmp_image = (unsigned char **) malloc(pictureWidth * sizeof (unsigned char*));
inputImage = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char));
for (i = 0; i < pictureHight * pictureWidth; i++) {
inputImage[i] = k;
k++;
if (k == 256) {
k = 0;
}
}
//Perform Gauss operations on image
for (i = 0; i < pictureWidth; i++) {
*(g_tmp_image + i) = (unsigned char*) malloc(pictureHight * sizeof (unsigned char));
}
for (k = -GB; k <= GB; k++) {
tot += Gauss[abs(k)];
}
/*
Horizontal Gauss blur*/
for (x = 0; x < pictureWidth; x++) {
for (y = 0; y < pictureHight; y++) {
*(*(g_tmp_image + x) + y) = 0;
}
}
for (x = GB; x < pictureWidth - GB; x++) {
for (y = GB; y < pictureHight - GB; y++) {
g_acc = 0;
for (k = -GB; k <= GB; k++) {
g_acc += inputImage[x + k + pictureWidth * y] * Gauss[abs(k)];
}
*(*(g_tmp_image + x) + y) = g_acc / tot;
}
}
//Vertival Gauss blur
for (i = 0; i < pictureWidth * pictureHight; i++) {
gauss_image[i] = 0;
}
for (x = GB; x < pictureWidth - GB; x++) {
for (y = GB; y < pictureHight - GB; y++) {
g_acc = 0;
for (k = -GB; k < GB; k++) {
g_acc += (*(*(g_tmp_image + x) + y + k)) * Gauss[abs(k)];
}
gauss_image[x + y * pictureWidth] = g_acc / tot;
}
}
for (i = 0; i < pictureWidth * pictureHight; i++) {
outputImage[i] = 0;
}
for (x = NB; x < pictureWidth - NB; x++) {
for (y = NB; y < pictureHight - NB; y++) {
maxdiff = 0;
for (k = -NB; k <= NB; k++) {
for (l = -NB; l <= NB; l++) {
if (k != 0 || l != 0) {
val = abs(((int) gauss_image[x + k + pictureWidth * (y + 1)] -
gauss_image[x + pictureWidth * y]));
if (val > maxdiff) {
maxdiff = val;
}
}
}
}
outputImage[x + pictureWidth * y] = maxdiff;
}
}
/*Memory deallocation*/
free(gauss_image);
free(outputImage);
free(inputImage);
for (i = 0; i < pictureWidth; i++) {
free(*(g_tmp_image + i));
}
free(g_tmp_image);
return 0;
}

33
testcases/matrix.c Normal file
View File

@ -0,0 +1,33 @@
typedef unsigned short UInt16;
const UInt16 m1[3][4] = {
{0x01, 0x02, 0x03, 0x04},
{0x05, 0x06, 0x07, 0x08},
{0x09, 0x0A, 0x0B, 0x0C}
};
const UInt16 m2[4][5] = {
{0x01, 0x02, 0x03, 0x04, 0x05},
{0x06, 0x07, 0x08, 0x09, 0x0A},
{0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
{0x10, 0x11, 0x12, 0x13, 0x14}
};
int main(void)
{
int m, n, p;
volatile UInt16 m3[3][5];
for(m = 0; m < 3; m++)
{
for(p = 0; p < 5; p++)
{
m3[m][p] = 0;
for(n = 0; n < 4; n++)
{
m3[m][p] += m1[m][n] * m2[n][p];
}
}
}
return 0;
}

17
testcases/stuff.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by erki on 23.02.21.
//
#ifndef C_ANALYZER_STUFF_H
#define C_ANALYZER_STUFF_H
void f()
{
int a = 4;
int b = 6;
int c = a + b;
(void)c;
}
#endif //C_ANALYZER_STUFF_H