-
Notifications
You must be signed in to change notification settings - Fork 0
/
Symbol.c
43 lines (34 loc) · 970 Bytes
/
Symbol.c
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
#include "Symbol.h"
Esi newEsi(int size) {
Esi esi;
esi.arr = (int*)malloc(size * sizeof(int));
esi.size = size;
return esi;
}
VectorSymbol newVectorSymbol(int size) {
VectorSymbol vs;
vs.symbols = (Symbol **)malloc(sizeof(Symbol*) * size);
vs.size = size;
return vs;
}
void fillData(Symbol* sym, const char *src, int size)
{
if(sym == NULL) return;
if (sym->nbytes != size) {
sym->data = (int*)malloc(size); //int[size/sizeof(int)];
}
memcpy(sym->data, src, size);
}
Symbol* xxor(const Symbol* s1, const Symbol* s2)
{
if (s1 == NULL || s2 == NULL) return NULL;
int i;
if (s1->nbytes != s2->nbytes)
printf("Error! try to xor symbols with unmatched size\n");
Symbol* tmp = (Symbol*)malloc(sizeof(Symbol));
tmp->data = (int*) malloc(s2->nbytes );
for (i=0;i<s1->nbytes/4; i++)
tmp->data[i] = s1->data[i] ^ s2->data[i];
tmp->nbytes = s1->nbytes;
return tmp;
}