repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
pedromig/COMP-Project
tests/meta4/input/more_tests.c
int cc; void f(void) { cc = 'Y'; } int error_in_C_problem(void) { char a, b; int c; a = 10; b = -5; c = 0; putchar(027 * 01365 + 'A'); putchar((!a || !b || !c)); putchar(!a); putchar(!b); putchar((!b || !a)); putchar((!a || !b || !c) && -2); putchar((!a || !b || !c) && -2 && (!b || !a)); putchar(!((!a || !b || !c) && -2 && (!b || !a))); putchar(!((!a || !b || !c) && -2 && (!b || !a)) + 'A'); putchar((a && (b = b + 1) && c || (b = b + 4) && (a = a - 5) || 1 || (c = -1)) + 'A'); putchar(a + 'A'); return 0; } int error_in_D_problem(void) { int a = 5; putchar(a); int b = 3; putchar(b); a = a + 1; putchar(a); a = 2 * a; putchar(a); int c = (b = b + 1, a = a + b, b = 2 * b) - 5; putchar(a); putchar(b); putchar(c); return 0; } char nand(char x, char y) { return !(x && y); } char nor(char x, char y) { return !(x || y); } int random_tests(void) { cc = 'F'; double x = 1.2; double y = 1.5; double z = 1.5 / 1.2; int g = 0 & 12; int zz = 65; int c = +(+zz); int d = -(-zz); int e = 4 | 1 * 2; putchar(g); int a = 67; if (f(), a = 65, 1) { putchar(a); putchar('X'); putchar(cc); } else { putchar(a); if ((1, 2, 31)) { putchar('B'); } } putchar(a); return 0; } int lol(void) { char a, b; int c; a = 10; b = -5; putchar(!a); putchar(!b); c = (!b || !a); putchar(c); c = !b && !a; putchar(c); putchar((!b || !a)); if (!b || !a) putchar('t'); else putchar('f'); return 0; } int main(void) { lol(); error_in_C_problem(); putchar('\n'); error_in_D_problem(); putchar('\n'); // error in E problem; nand('A', 'B'); nor('A', 'B'); // Other random_tests(); return 0; }
pedromig/COMP-Project
tests/meta4/input/expressions.c
// Arithmetic, relational and logical expressions int main(void) { putchar((5 && 3) + 'A'); putchar((0 || 0) + 'A'); putchar(130 % 85); putchar(82 & 81); putchar(110 ^ 85); putchar(82 | 81); putchar((2 != 3) + 'A'); putchar((2 == 3) + 'A'); putchar((2 < 3) + 'A'); putchar((2 > 3) + 'A'); putchar((2 <= 3) + 'A'); putchar((2 <= 2) + 'A'); putchar((2 >= 3) + 'A'); putchar((2 >= 2) + 'A'); putchar((+(-2)) + 'A'); putchar((-(-2)) + 'A'); putchar(!0 + 'A'); putchar(5 + 2 + 'A'); 5.2 + 1.3; 5 + 1.3; 5.2 + 1; putchar(5 - 1 + 'A'); 5.2 - 1.3; 5 - 1.3; 5.2 - 1; putchar(5 * 3 + 'A'); 5.2 * 1.3; 5 * 1.3; 5.2 * 1; putchar(15 / 5 + 'A'); 5.2 / 1.3; 5 / 1.3; 5.2 / 1; char a = 'Z'; }
pedromig/COMP-Project
tests/meta4/input/control_flow.c
void print_number(int n) { int u = 1; while (n / u) u = u * 10; while (u > 1) { putchar('0' + n / (u / 10) - n / u * 10); u = u / 10; } } int main(void) { int gang = 'a'; if (gang > 'a') { putchar('l'); putchar('o'); putchar('l'); putchar('\n'); return 0; } print_number(13920498); putchar('\n'); if (gang == 'b') { gang = (123 * 2, 132 / 4, 213 * 6, 231 * 4, 312 - 2, 321 - (-(-(0)))); } else { gang = 1, 2, 3; print_number(gang); putchar('\n'); print_number((12, 34, 56, 78)); putchar('\n'); } gang = 10; while (gang) { print_number(gang); putchar('\n'); gang = 0, gang - 1; } putchar('e'); putchar('n'); putchar('d'); putchar('\n'); }
pedromig/COMP-Project
src/utils.h
/** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #ifndef UTILS_H #define UTILS_H #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "structures.h" // Error not specified in the project document but that is useful // Description: int f(int,int) { return 1; } according to gcc -> error: parameter name omitted #define parameter_name_omitted(line, column) \ printf("Line %d, col %d: Parameter name omitted\n", line, column); const char *decapitalize(const char *string); const char *select_operator(const char *string); bool has_parameters_omitted(ast_node_t *parameter_list); bool invalid_assign(type_t lhs, type_t rhs); const char *implicit_conversion(type_t left_operand, type_t right_operand); bool is_unary_operator(const char *operator); bool is_arithmetic_operator(const char *operator); bool is_relational_operator(const char *operator); bool is_bitwise_operator(const char *operator); bool is_logical_operator(const char *operator); bool is_statement_id(const char *operator); // LLVM Utils int ord(const char *str); const char *type_to_llvm(const char *type); int insert_default_return(const char *llvm_type, bool has_return_keyword); int intlit_to_int(const char *str); #endif //UTILS_H
pedromig/COMP-Project
tests/meta4/input/octal.c
int main(void) { char a, b; int c; a = 10; b = -5; c = 0; putchar(027 * 01365 + 'A'); putchar(a + 'A'); putchar(c + 'A'); putchar(!2 + '0'); putchar(!0 + '0'); putchar(!((!a || !b || !c) && -2 && (!b || !a)) + 'A'); putchar((a && (b = b + 1) && c || (b = b + 4) && (a = a - 5) || 1 || (c = -1)) + 'A'); putchar(a + '0'); putchar(a + 'A'); int d = 8; putchar((d = d - 5) + '0'); putchar(d + '0'); }
pedromig/COMP-Project
tests/meta3/input/testesV2.c
void f1(void, int a){ //algo } void f2(void, void){ //algo } int f3(char a); int f3(int a);
pedromig/COMP-Project
tests/meta4/input/doubles.c
<reponame>pedromig/COMP-Project<filename>tests/meta4/input/doubles.c<gh_stars>1-10 void print_equality(double a, double b) { if (a == b) { putchar('y'); putchar('e'); putchar('s'); } else { putchar('n'); putchar('o'); } putchar('\n'); } int main(void) { double a = 1.2, b = 1.3, c = 1.4, d = 1.2; double e = 1.7976931348623157e+2; double f, g, h; f = e * 12; g = a * b; h = 52; double i = h / g; double j = (5 * e / 5) + (23) - 5 * (98 - 4) / (6 * g - 42); double k = ((((2)) + b)) * ((5)); double l = (d) + (17 * 2 - 30) * (5) + 2 - (8 / f) * 4; double m = (67 + 2 * 3 - 67 + 2 / 1 - 7); double n = 2 * 3 * 4 / 8 - 5 / 2 * 4 + 6 + 0 / 3 / 7 & 2; double o = 5.0005 + 0.0095; double p = 5.0005 + 0.0095; double q = ((2 + 3) * (1 + 2)) * 4 & 2, r = ((2 + 3) * (1 + 2)) * 4 & -2; double s = (a) + (c * e - g) * (i) + k - (m / o) * q; double t = (a) + (c * e - g) * (i) + k - (m / o) * q; double u = (b) + l + (23 & 1 | 42) - (n / p) * s; putchar('a'); putchar(' '); print_equality(a, 1.200000); putchar('b'); putchar(' '); print_equality(b, 1.300000); putchar('c'); putchar(' '); print_equality(c, 1.400000); putchar('d'); putchar(' '); print_equality(d, 1.200000); putchar('f'); putchar(' '); print_equality(f, 2157.231762); putchar('g'); putchar(' '); print_equality(g, 1.560000); putchar('h'); putchar(' '); print_equality(h, 52.000000); putchar('i'); putchar(' '); print_equality(i, 33.333333); putchar('j'); putchar(' '); print_equality(j, 217.168823); putchar('k'); putchar(' '); print_equality(k, 16.500000); putchar('l'); putchar(' '); print_equality(l, 23.185166); putchar('m'); putchar(' '); print_equality(m, 1.000000); putchar('n'); putchar(' '); print_equality(n, 0.000000); putchar('o'); putchar(' '); print_equality(o, 5.010000); putchar('p'); putchar(' '); print_equality(p, 5.010000); putchar('q'); putchar(' '); print_equality(q, 0.000000); putchar('r'); putchar(' '); print_equality(r, 60.000000); putchar('s'); putchar(' '); print_equality(s, 8354.934629); putchar('t'); putchar(' '); print_equality(t, 8354.934629); putchar('u'); putchar(' '); print_equality(u, 67.485166); // putchar('\n'); // putchar('D'); // putchar('\n'); // d = a + b; // d = c - d; // d = e / f; // d = g * h; // d = i + j + k; // d = l - m - n; // d = o / c / d; // d = r * a * b; // d = u - a + b; // d = c + d - e; // d = f * g / h; // d = i / j * k; }
pedromig/COMP-Project
src/y.tab.h
/* A Bison parser, made by GNU Bison 3.5.1. */ /* Bison interface for Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* Undocumented macros, especially those whose name start with YY_, are private implementation details. Do not rely on them. */ #ifndef YY_YY_Y_TAB_H_INCLUDED # define YY_YY_Y_TAB_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif #if YYDEBUG extern int yydebug; #endif /* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { INTLIT = 258, CHRLIT = 259, REALLIT = 260, IF = 261, ELSE = 262, WHILE = 263, RETURN = 264, RESERVED = 265, CHAR = 266, INT = 267, SHORT = 268, DOUBLE = 269, VOID = 270, PLUS = 271, MINUS = 272, MUL = 273, DIV = 274, MOD = 275, EQ = 276, NE = 277, GE = 278, GT = 279, LE = 280, LT = 281, AND = 282, OR = 283, NOT = 284, BITWISEAND = 285, BITWISEOR = 286, BITWISEXOR = 287, ASSIGN = 288, COMMA = 289, LBRACE = 290, LPAR = 291, RBRACE = 292, RPAR = 293, SEMI = 294, ID = 295, NO_ELSE = 296, UNARY_OPERATOR = 297 }; #endif /* Tokens. */ #define INTLIT 258 #define CHRLIT 259 #define REALLIT 260 #define IF 261 #define ELSE 262 #define WHILE 263 #define RETURN 264 #define RESERVED 265 #define CHAR 266 #define INT 267 #define SHORT 268 #define DOUBLE 269 #define VOID 270 #define PLUS 271 #define MINUS 272 #define MUL 273 #define DIV 274 #define MOD 275 #define EQ 276 #define NE 277 #define GE 278 #define GT 279 #define LE 280 #define LT 281 #define AND 282 #define OR 283 #define NOT 284 #define BITWISEAND 285 #define BITWISEOR 286 #define BITWISEXOR 287 #define ASSIGN 288 #define COMMA 289 #define LBRACE 290 #define LPAR 291 #define RBRACE 292 #define RPAR 293 #define SEMI 294 #define ID 295 #define NO_ELSE 296 #define UNARY_OPERATOR 297 /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED union YYSTYPE { #line 48 "uccompiler.y" token_t token; ast_node_t *node; #line 146 "y.tab.h" }; typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif extern YYSTYPE yylval; int yyparse (void); #endif /* !YY_YY_Y_TAB_H_INCLUDED */
pedromig/COMP-Project
tests/meta4/input/testFile.c
int d; int declaredOnly(int,int x); double globalDouble = 2.0; int func(int a, double c){ a=3; return a*3; } void notTest(void){ int a; a=!a; double c; c=!a; } void declarationTests(void){ int x; double b=x; double c = 2; double anotherD = 'a'; int a = 'a'; double k2=2.2; double k3=1+2.2; double k4 =2.2+1; k3=9 + 9.9; k3=6 + 6.6; } void uselessFunction(int a, int b){} void arithmeticTests(void){ double a=90; int b = 50; double c; c= 2.0+1; uselessFunction(3+4,5+3); c=1*2+3*4; c= a+7*b; c=1*7+b*3*4+2+(3*4)+2; a = 1*2+3*4; int AAAAAAAA = b; int z= 2*2; double k9 = 2.2*c+1; k9=c=a; } void errorTestingLogicalOps(void){ double d; int a; //a = a&d; //a = a&&d; //a = a|d; //a = a||d; //a = a^d; //a = !d; } void relationalOperationsTest(void){ int a=1; int b=0; //prints: bdfgik if(a == b){ // -> false putchar('a'); } if(a == a){ // -> true putchar('b'); } if(b != b){ // -> false putchar('c'); } if(a != b){ // -> true putchar('d'); } if(a < a){ // false putchar('e'); } if(b < a){ // true putchar('f'); } if(a <= a){ // true putchar('g'); } if(b > a){ // false putchar('h'); } if(a > b){ // true putchar('i'); } if(b >= a){ // false putchar('j'); } if(a >= a){ // true putchar('k'); } putchar('\n'); } void whileAndIfChains(void){ //prints: ABC int a=5; int b; while(a <= 10){ b = 1; if(b==2){ } else { if(a == 7){ putchar('\n'); putchar('A'); putchar('B'); putchar('C'); putchar('\n'); } } a=a+1; } } void intAndDouble(int a, double b){} int scopeLimitTesting(void){ int a=1; if(a){ if(a){ } return 3; } while(a){ if(a){} a=a-1; //int a = 3; //erro } return 0; } void moreIntToDoubleConversionTests(void){ double d = (3,3); d = (1,1); } void andOrTesting(void){ int a = 1; int b = 0; //prints: bde putchar('\n'); if(a && b){ // 1 && 0 -> false putchar('a'); } if(a && a){ // 1 && 1 -> true putchar('b'); } if(b && b){ // 0 && 0 -> false putchar('c'); } if(a || b){ // 1 || 0 -> true putchar('d'); } if(a || a){ // 1 || 1 -> true putchar('e'); } if(b || b){ // 0 || 0 -> false putchar('f'); } putchar('\n'); } int main(void){ whileAndIfChains(); relationalOperationsTest(); andOrTesting(); intAndDouble(1, 1); errorTestingLogicalOps(); d=98; /* char c = '\n'; int a=5; while(a){ putchar('a'); putchar(d); a=a-1; } int c=d; */ func(97, 0.0); }
pedromig/COMP-Project
src/ast.h
/** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #include <assert.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef __AST_H #define __AST_H #include "structures.h" #include "symbol_table.h" // Helper define to assist in line/column assigns of nodes that should // have a null token value making impossible to use ast_node() without // unwanted side effects in the AST #define ASSIGN_TOKEN_LC(NODE, TOKEN) \ NODE->token.line = TOKEN.line; \ NODE->token.column = TOKEN.column #define ASSIGN_NODE_LC(NODE1, NODE2) \ NODE1->token.line = NODE2->token.line; \ NODE1->token.column = NODE2->token.column #define NULL_TOKEN \ (token_t) { .value = NULL, .line = -1, .column = -1 } #define IS_NULL_TOKEN(TOKEN) (TOKEN.value == NULL) && (TOKEN.line == -1) && (TOKEN.column == -1) token_t token(char *value, int line, int column, int type); ast_node_t *ast_node(const char *id, token_t token); void add_children(ast_node_t *parent, int argc, ...); void add_siblings(ast_node_t *parent, int argc, ...); void free_ast(ast_node_t *head); void print_ast(ast_node_t *root); void add_typespec(ast_node_t *type, ast_node_t *give_me_type); ast_node_t *statement_list(ast_node_t *stat_list); ast_node_t *null_check(); #endif // __AST_H
pedromig/COMP-Project
tests/meta4/input/comma_exprs.c
<gh_stars>1-10 int return1(void) { return 1; } int main(void) { int a; a = 0, 1, 2, 3; putchar('a' + a); a = (0, 1, 2, 3); putchar('a' + a); putchar('a' + ((1, 2, 3), (1, 2))); putchar('a' + (3, 2, return1())); putchar('a' + (3, 2, return1(), 0)); putchar('a' + ((a = return1()), a)); }
pedromig/COMP-Project
tests/meta4/input/logical_stuff.c
void and (void) { putchar('0' + (0 && 0)); putchar('0' + (0 && 1)); putchar('0' + (1 && 0)); putchar('0' + (1 && 1)); putchar('0' + (0 && 0)); putchar('0' + (0 && 100)); putchar('0' + (100 && 0)); putchar('0' + (100 && 100)); } void nand(void) { putchar('0' + !(0 && 0)); putchar('0' + !(0 && 1)); putchar('0' + !(1 && 0)); putchar('0' + !(1 && 1)); putchar('0' + !(0 && 0)); putchar('0' + !(0 && 100)); putchar('0' + !(100 && 0)); putchar('0' + !(100 && 100)); } void or (void) { putchar('0' + (0 || 0)); putchar('0' + (0 || 1)); putchar('0' + (1 || 0)); putchar('0' + (1 || 1)); putchar('0' + (0 || 0)); putchar('0' + (0 || 100)); putchar('0' + (100 || 0)); putchar('0' + (100 || 100)); } void nor(void) { putchar('0' + !(0 || 0)); putchar('0' + !(0 || 1)); putchar('0' + !(1 || 0)); putchar('0' + !(1 || 1)); putchar('0' + !(0 || 0)); putchar('0' + !(0 || 100)); putchar('0' + !(100 || 0)); putchar('0' + !(100 || 100)); } void n_or_and_or(void) { putchar('0' + !(0 || 0 && 0)); putchar('0' + !(0 || 1 && 0)); putchar('0' + !(1 || 0 && 0)); putchar('0' + !(1 || 1 && 0)); putchar('0' + !(0 || 0 && 1)); putchar('0' + !(0 || 1 && 1)); putchar('0' + !(1 || 0 && 1)); putchar('0' + !(1 || 1 && 1)); putchar('0' + !(0 || 0 && 0 || 0)); putchar('0' + !(0 || 1 && 0 || 0)); putchar('0' + !(1 || 0 && 0 || 0)); putchar('0' + !(1 || 1 && 0 || 0)); putchar('0' + !(0 || 0 && 1 || 0)); putchar('0' + !(0 || 1 && 1 || 0)); putchar('0' + !(1 || 0 && 1 || 0)); putchar('0' + !(1 || 1 && 1 || 0)); putchar('0' + !(0 || 0 && 0 || 1)); putchar('0' + !(0 || 1 && 0 || 1)); putchar('0' + !(1 || 0 && 0 || 1)); putchar('0' + !(1 || 1 && 0 || 1)); putchar('0' + !(0 || 0 && 1 || 1)); putchar('0' + !(0 || 1 && 1 || 1)); putchar('0' + !(1 || 0 && 1 || 1)); putchar('0' + !(1 || 1 && 1 || 1)); putchar('0' + !(0 || 0)); putchar('0' + !(0 || 100)); putchar('0' + !(100 || 0)); putchar('0' + !(100 || 100)); } void test_continue_end(void) { int a = 'w'; 0 && (a = 'w'); putchar(a); 1 && (a = 'o'); putchar(a); 0 || (a = 'r'); putchar(a); a = 'k'; 1 || (a = 'r'); putchar(a); 0 || 1 && (a = 's'); putchar(a); } int main(void) { putchar('t'); putchar('a'); putchar('b'); putchar('e'); putchar('l'); putchar('a'); putchar(' '); putchar('d'); putchar('e'); putchar(' '); putchar('v'); putchar('e'); putchar('r'); putchar('d'); putchar('a'); putchar('d'); putchar('e'); putchar(':'); putchar('\n'); and(); putchar('\n'); or (); putchar('\n'); nand(); putchar('\n'); nor(); putchar('\n'); n_or_and_or(); putchar('\n'); test_continue_end(); putchar('\n'); }
pedromig/COMP-Project
tests/meta3/input/TestesEv2.c
<reponame>pedromig/COMP-Project<filename>tests/meta3/input/TestesEv2.c //Joao void fA(int a); void fA(int a, int b); void fB(int a, int b); void fB(int a); void fC(void); void fC(int a); void fD(void, void); void fD(int c); int a=3; //Rui void f1(int a, double b); int f1(int a, double b); int f1(int a, double b){ return a; } int f2(int a, double b); int f2(int a, double b){ return b; } void f3(void){ //algo } void f4(int a, char b, short c, double d){ //algo } void f4(int a, char b, short c, double d){ //algo } void f5(int a, void, double b); int f6(void,void,void); int main(void){ fC(a); void erro; int a; char b; short c; double d; int a; double b; if(!a){ } if(!b){ } if(!c){ } if(!d){ } if(!e){ } if(h){ } if(b = b){ } if(a){ } if(b){ } if(c){ } if(d){ } int coiso; coiso = f3(); f4(a,a,a,a); f4(b,b,b,b); f4(c,c,c,c); f4(d,d,d,d); if(a || a){ } if(a || b){ } if(a || c){ } if(a || d){ } if(a || h){ } 1.5 = b; if(a + a){ } if(a + b){ } if(a + c){ } if(a + d){ } if(a,a){ } if(a,b){ } if(a,c){ } if(a,d){ } if(a/a){ } if(a/b){ } if(a/c){ } if(a/d){ } if(a%a){ } if(a%b){ } if(a%c){ } if(a%d){ } if(a==a){ } if(a==b){ } if(a==c){ } if(a==d){ } if(f4(a,b,c,d)){ } return d; }
pedromig/COMP-Project
tests/meta3/input/DecAndDefConflict.c
<reponame>pedromig/COMP-Project int func1(int a); int func1(double a){ } int func2(double a); int func2(int a){ }
pedromig/COMP-Project
tests/meta3/input/testes_anotacaoErro.c
int f1(void a){ int h; int a; if(h == 1){ a = f1(); } return h; }
pedromig/COMP-Project
src/codegen.c
<gh_stars>1-10 /** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #include "codegen.h" // Function Definition Auxiliary Variables static int llvm_var_counter; static const char *llvm_return_type; static bool llvm_has_return_keyword; static int current_label; static const char *result_type; void funcdef_code_generator(ast_node_t *func_def) { ast_node_t *typespec = func_def->first_child; ast_node_t *declarator = typespec->next_sibling; ast_node_t *param_list = declarator->next_sibling; ast_node_t *func_body = param_list->next_sibling; // Function definition return type if (!strcmp(typespec->id, "Void")) { printf("\ndefine void "); } else if (!strcmp(typespec->id, "Char") || !strcmp(typespec->id, "Short") || !strcmp(typespec->id, "Int")) { printf("\ndefine i32 "); } else if (!strcmp(typespec->id, "Double")) { printf("\ndefine double "); } // Reset LLVM Single Static Assignement variable counter llvm_var_counter = 0; // Function declaration (name && parameter list) printf("@%s(", declarator->token.value); ast_node_t *param = param_list->first_child; while (param != NULL) { if (!strcmp(param->first_child->id, "Char") || !strcmp(param->first_child->id, "Short") || !strcmp(param->first_child->id, "Int")) { printf("i32"); ++llvm_var_counter; } else if (!strcmp(param->first_child->id, "Double")) { printf("double"); ++llvm_var_counter; } if (param->next_sibling) printf(", "); param = param->next_sibling; } //to know the label we are in //current_label = llvm_var_counter; current_label = 0; // Keep one space between parameters and declared variables ++llvm_var_counter; printf(")"); // Open function definition body current_table = find_table(symtab_list, declarator->token.value); printf(" {\n"); // Initialize function parameters param = param_list->first_child; sym_t *sym; for (int i = 0; i < llvm_var_counter && param; ++i) { if (!strcmp(param->first_child->id, "Char") || !strcmp(param->first_child->id, "Short") || !strcmp(param->first_child->id, "Int")) { printf("\t%%%d = alloca i32\n", llvm_var_counter); printf("\tstore i32 %%%d, i32* %%%d\n", i, llvm_var_counter++); } else if (!strcmp(param->first_child->id, "Double")) { printf("\t%%%d = alloca double\n", llvm_var_counter); printf("\tstore double %%%d, double* %%%d\n", i, llvm_var_counter++); } //TODO atribuir na tabela de símbolos ao parametro atual o número que lhe corresponde dentro da função if (strcmp(param->first_child->id, "Void")) { sym = find_symbol(current_table->symlist, param->first_child->next_sibling->token.value); sym->llvm_var = llvm_var_counter - 1; } param = param->next_sibling; } // Return type settings llvm_return_type = type_to_llvm(typespec->id); llvm_has_return_keyword = false; // Generate function body itself code_generator(func_body->first_child, false); // Default return type insert_default_return(llvm_return_type, llvm_has_return_keyword); // Close Function Body printf("}\n"); current_table = symtab_list; } int load_variable_code_generator(ast_node_t *node) { bool global = false; sym_t *sym; sym = find_symbol(current_table->symlist, node->token.value); if (!sym) { sym = find_symbol(symtab_list->symlist, node->token.value); global = true; } if (global) { //op2 global printf("\t%%%d = load %s, %s* @%s\n", llvm_var_counter++, type_to_llvm(sym->type), type_to_llvm(sym->type), node->token.value); } else { //op2 local printf("\t%%%d = load %s, %s* %%%d\n", llvm_var_counter++, type_to_llvm(sym->type), type_to_llvm(sym->type), sym->llvm_var); } return llvm_var_counter - 1; } bool is_terminal(ast_node_t *node) { if (!strcmp(node->id, "Id") || !strcmp(node->id, "ChrLit") || !strcmp(node->id, "IntLit") || !strcmp(node->id, "Short") || !strcmp(node->id, "RealLit") || !strcmp(node->id, "Call")) return true; return false; } int call_code_generator(ast_node_t *node) { llvm_has_return_keyword = false; ast_node_t *call_id = node->first_child; int result = -1; if (!strcmp(call_id->token.value, "getchar")) { printf("\t%%%d = call i32 (...) @getchar()\n", llvm_var_counter); result_type = "i32"; result = llvm_var_counter++; } else if (!strcmp(call_id->token.value, "putchar")) { if (is_terminal(call_id->next_sibling)) { result = load_terminal(call_id->next_sibling); } else if (!strcmp(call_id->next_sibling->id, "Call")) { result = call_code_generator(call_id->next_sibling); } else if (!strcmp(call_id->next_sibling->id, "Store")) { store_code_generator(call_id->next_sibling); //dar load do que foi stored result = load_terminal(call_id->next_sibling->first_child); } else if (is_logical(call_id->next_sibling)) { result = logical_operator_code_generator(call_id->next_sibling); } else { result = operator_code_generator(call_id->next_sibling, false); } printf("\t%%%d = call i32 (i32, ...) bitcast (i32 (...)* @putchar to i32 (i32, ...)*)(i32 %%%d)\n", llvm_var_counter, result); result_type = "i32"; result = llvm_var_counter++; } else { symtab_t *table = find_table(symtab_list, call_id->token.value); ast_node_t *params_call = call_id->next_sibling; sym_t *params_table = table->symlist->next; bool is_double; //printf("%s\n", table -> symlist -> next ->id); int n = 0, i = 0; while (params_call) { n++; params_call = params_call->next_sibling; } params_call = call_id->next_sibling; int indexs[n]; while (params_call) { is_double = false; if (!strcmp(type_to_llvm(params_table->type), "double") && strcmp(type_to_llvm(params_call->annotation.type), "double")) is_double = true; //verificar se o params_call é um terminal, um call ou uma operação if (is_terminal(params_call)) { indexs[i] = load_terminal(params_call); if (is_double) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, indexs[i]); indexs[i] = llvm_var_counter - 1; } } else if (!strcmp(params_call->id, "Call")) { indexs[i] = call_code_generator(params_call); if (is_double) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, indexs[i]); indexs[i] = llvm_var_counter - 1; } } else if (is_logical(params_call)) { indexs[i] = logical_operator_code_generator(params_call); if (is_double) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, indexs[i]); indexs[i] = llvm_var_counter - 1; } } else { indexs[i] = operator_code_generator(params_call, false); if (is_double) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, indexs[i]); indexs[i] = llvm_var_counter - 1; } } i++; params_table = params_table->next; params_call = params_call->next_sibling; } params_table = table->symlist->next; const char *type = !strcmp(call_id->annotation.type, "void") ? "void" : type_to_llvm(call_id->annotation.type); if (!strcmp(call_id->annotation.type, "void")) { printf("\tcall %s @%s(", type, call_id->token.value); result_type = "void"; } else { printf("\t%%%d = call %s @%s(", llvm_var_counter++, type, call_id->token.value); result_type = type; } result = llvm_var_counter - 1; if (n > 0) { for (i = 0; i < n - 1; i++) { printf("%s %%%d, ", type_to_llvm(params_table->type), indexs[i]); params_table = params_table->next; } printf("%s %%%d", type_to_llvm(params_table->type), indexs[i]); } printf(")\n"); } return result; } int load_terminal(ast_node_t *node) { int number; if (!strcmp(node->id, "ChrLit")) { printf("\t%%%d = add i32 0, %d\n", llvm_var_counter++, ord(node->token.value)); number = llvm_var_counter - 1; } else if (!strcmp(node->id, "RealLit")) { printf("\t%%%d = fadd double 0.0, %e\n", llvm_var_counter++, strtod(node->token.value, NULL)); number = llvm_var_counter - 1; } else if (!strcmp(node->id, "Id")) { number = load_variable_code_generator(node); } else if (!strcmp(node->id, "Call")) { number = call_code_generator(node); } else { printf("\t%%%d = add i32 0, %d\n", llvm_var_counter++, intlit_to_int(node->token.value)); number = llvm_var_counter - 1; } return number; } int unary_operator_code_generator(ast_node_t *node, int op1_number_inter, const char *op1_type) { ast_node_t *unary_operator = node; int aux; if (!strcmp(unary_operator->id, "Not")) { if (is_terminal(unary_operator->first_child)) { aux = load_terminal(unary_operator->first_child); op1_type = get_type(unary_operator->first_child); } else { aux = op1_number_inter; } } else { if (is_terminal(unary_operator->first_child)) { aux = load_terminal(unary_operator->first_child); op1_type = get_type(unary_operator->first_child); } else { aux = op1_number_inter; } } if (!strcmp(unary_operator->id, "Minus")) { if (!strcmp(op1_type, "double")) { printf("\t%%%d = fsub double 0.0, %%%d\n", llvm_var_counter++, aux); } else { printf("\t%%%d = sub i32 0, %%%d\n", llvm_var_counter++, aux); } } else if (!strcmp(unary_operator->id, "Not")) { printf("\t%%%d = icmp ne i32 %%%d, %d\n", llvm_var_counter++, aux, 0); printf("\t%%%d = xor i1 %%%d, true\n", llvm_var_counter, llvm_var_counter - 1); llvm_var_counter++; printf("\t%%%d = zext i1 %%%d to i32\n", llvm_var_counter, llvm_var_counter - 1); llvm_var_counter++; // if (double_type) { // printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter, llvm_var_counter - 1); // llvm_var_counter++; // } } else if (!strcmp(unary_operator->id, "Plus")) { //! não faz nada, está aqui para saber que não me esqueci dele. } result_type = op1_type; return llvm_var_counter - 1; } void arithmetic_operator_code_generator(const char *operation, const char *type, int op1_number, int op2_number) { printf("\t%%%d = %s %s %%%d, %%%d\n", llvm_var_counter++, operation, type, op1_number, op2_number); result_type = type; } void relational_operator_code_generator(const char *operation, const char *type, int op1_number, int op2_number) { if (!strcmp(type, "double")) { //se for stored num double printf("\t%%%d = fcmp %s %s %%%d, %%%d\n", llvm_var_counter++, operation, type, op1_number, op2_number); printf("\t%%%d = zext i1 %%%d to i32\n", llvm_var_counter, llvm_var_counter - 1); llvm_var_counter++; } else { printf("\t%%%d = icmp %s %s %%%d, %%%d\n", llvm_var_counter++, operation, type, op1_number, op2_number); printf("\t%%%d = zext i1 %%%d to i32\n", llvm_var_counter, llvm_var_counter - 1); llvm_var_counter++; } result_type = "i32"; } const char *get_type(ast_node_t *node) { if (!strcmp(node->id, "Id")) { sym_t *sym; sym = find_symbol(current_table->symlist, node->token.value); if (!sym) { sym = find_symbol(symtab_list->symlist, node->token.value); } return type_to_llvm(sym->type); } else if (!strcmp(node->id, "Call")) { return type_to_llvm(node->annotation.type); } else if (!strcmp(node->id, "RealLit")) { return "double"; } else { return "i32"; } } //TODO separar os relational dos arithmetic int binary_operator_code_generator(ast_node_t *node, const char *operation, int op1_number_inter, int op2_number_inter, const char *op1_type, const char *op2_type, bool relational) { ast_node_t *operator= node; ast_node_t *op1 = operator->first_child; ast_node_t *op2 = op1->next_sibling; int op1_number = -1, op2_number = -1; const char *type; //ambos terminais if (is_terminal(op1) && is_terminal(op2)) { op1_number = load_terminal(op1); //função para dar set do type op1_type = get_type(op1); op2_number = load_terminal(op2); //função para dar set do type op2_type = get_type(op2); } //op2 terminal else if (!is_terminal(op1) && is_terminal(op2)) { op1_number = op1_number_inter; op2_number = load_terminal(op2); op2_type = get_type(op2); } //op1 terminal else if (is_terminal(op1) && !is_terminal(op2)) { op1_number = load_terminal(op1); op1_type = get_type(op1); op2_number = op2_number_inter; } //nenhum terminal else if (!is_terminal(op1) && !is_terminal(op2)) { op1_number = op1_number_inter; op2_number = op2_number_inter; } else { printf("ERRO binary_operator_code_generator\n"); } if (!strcmp(op1_type, "double") && strcmp(op2_type, "double")) { //sitofp do op2 printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, op2_number); op2_number = llvm_var_counter - 1; op2_type = "double"; } else if (strcmp(op1_type, "double") && !strcmp(op2_type, "double")) { //sitofp do op1 printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, op1_number); op1_number = llvm_var_counter - 1; op1_type = "double"; } type = op1_type; if (relational) relational_operator_code_generator(operation, type, op1_number, op2_number); else arithmetic_operator_code_generator(operation, type, op1_number, op2_number); return llvm_var_counter - 1; } int bitwise_operator_code_generator(ast_node_t *node, const char *operation, int op1_number_inter, int op2_number_inter, const char *op1_type, const char *op2_type) { ast_node_t *operator= node; ast_node_t *op1 = operator->first_child; ast_node_t *op2 = op1->next_sibling; int op1_number = -1, op2_number = -1; //ambos terminais if (is_terminal(op1) && is_terminal(op2)) { op1_number = load_terminal(op1); //função para dar set do type op1_type = get_type(op1); op2_number = load_terminal(op2); //função para dar set do type op2_type = get_type(op2); } //op2 terminal else if (!is_terminal(op1) && is_terminal(op2)) { op1_number = op1_number_inter; op2_number = load_terminal(op2); op2_type = get_type(op2); } //op1 terminal else if (is_terminal(op1) && !is_terminal(op2)) { op1_number = load_terminal(op1); op1_type = get_type(op1); op2_number = op2_number_inter; } //nenhum terminal else if (!is_terminal(op1) && !is_terminal(op2)) { op1_number = op1_number_inter; op2_number = op2_number_inter; } else { printf("ERRO bitwise_operator_code_generator\n"); } printf("\t%%%d = %s i32 %%%d, %%%d\n", llvm_var_counter++, operation, op1_number, op2_number); result_type = "i32"; return llvm_var_counter - 1; } bool is_logical(ast_node_t *node) { if (!strcmp(node->id, "And") || !strcmp(node->id, "Or")) return true; return false; } int logical_operator_code_generator(ast_node_t *node) { ast_node_t *operator= node; ast_node_t *op1 = operator->first_child; ast_node_t *op2 = op1->next_sibling; int op1_number = -1, op2_number = -1; const char *operation = !strcmp(operator->id, "And") ? "false" : "true"; int ini_label, first_label, second_label, temp_cmp; //? verificar se op1 é and ou or //? se op1 for terminal, call, store ou operador usar o op1_number retornado por estes //? caso contrário usar o retornado pelo logical operator if (is_logical(op1)) { op1_number = logical_operator_code_generator(op1); // printf("\tbr label %%label%d\n", ini_label); // printf("\nlabel%d:\n", ini_label); } if (is_logical(op2)) { op2_number = logical_operator_code_generator(op2); } ini_label = current_label++; printf("\tbr label %%label%d\n", ini_label); printf("\nlabel%d:\n", ini_label); if (is_terminal(op1)) { op1_number = load_terminal(op1); } else if (!strcmp(op1->id, "Call")) { op1_number = call_code_generator(op1); } // else if(!strcmp(op1 -> id, "Store")){ // store_code_generator(op1); // op1_number = llvm_var_counter - 1; // } else if (is_logical(op1)) { } else { op1_number = operator_code_generator(op1, false); } printf("\t%%%d = icmp ne i32 %%%d, 0\n", llvm_var_counter++, op1_number); //8 -> 9 first_label = current_label++; second_label = current_label++; if (!strcmp(operation, "false")) { printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, first_label, second_label); } else { printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, second_label, first_label); } //printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, first_label, second_label); printf("\nlabel%d:\n", first_label); //? load das cenas para o operador 2: if (is_terminal(op2)) { op2_number = load_terminal(op2); } else if (!strcmp(op2->id, "Call")) { op2_number = call_code_generator(op2); } // else if(!strcmp(op2 -> id, "Store")){ // store_code_generator(op2); // op2_number = llvm_var_counter - 1; // } else if (is_logical(op2)) { } else { op2_number = operator_code_generator(op2, false); } printf("\t%%%d = icmp ne i32 %%%d, 0\n", llvm_var_counter++, op2_number); //10 -> 11 temp_cmp = llvm_var_counter - 1; //10 printf("\tbr label %%label%d\n", second_label); printf("\nlabel%d:\n", second_label); printf("\t%%%d = phi i1 [ %s, %%label%d ], [ %%%d, %%label%d ]\n", llvm_var_counter++, operation, ini_label, temp_cmp, first_label); //12 -> 13 printf("\t%%%d = zext i1 %%%d to i32\n", llvm_var_counter, llvm_var_counter - 1); //13 -> 13 result_type = "i32"; return llvm_var_counter++; } int comma_operator_code_generator(ast_node_t *node) { ast_node_t *op1 = node->first_child; ast_node_t *op2 = op1->next_sibling; int result = -1; // if(!strcmp(op1 -> id, "Store")){ // store_code_generator(op1); // } // else if (!strcmp(op1->id, "Call")) { call_code_generator(op1); } else if (is_terminal(op1)) { load_terminal(op1); } else if (is_logical(op1)) { logical_operator_code_generator(op1); } else { operator_code_generator(op1, false); } // if(!strcmp(op2 -> id, "Store")){ // store_code_generator(op2); // result = load_terminal(op2 -> first_child); // } // else if (!strcmp(op2->id, "Call")) { result = call_code_generator(op2); } else if (is_terminal(op2)) { result = load_terminal(op2); result_type = get_type(op2); } else if (is_logical(op2)) { result = logical_operator_code_generator(op2); } else { result = operator_code_generator(op2, false); } return result; } int operator_code_generator(ast_node_t *node, bool logical) { llvm_has_return_keyword = false; ast_node_t *operator= node; ast_node_t *op1 = node->first_child; ast_node_t *op2 = op1->next_sibling; bool double_type; const char *operation; int result = -1, op1_number = -1, op2_number = -1; const char *op1_type_temp, *op2_type_temp; bool inside_comma = false; bool tmp_logical = logical; if (is_logical(operator) && !tmp_logical) { tmp_logical = true; } if (!strcmp(operator->id, "Comma")) { inside_comma = true; } if (strcmp(operator->id, "Comma")) { if (!is_terminal(op1)) { //TODO variável global para saber se esotu no operador 1 ou 2 para poder guardar o tipo da variável if (is_logical(op1)) { op1_number = logical_operator_code_generator(op1); } else { op1_number = operator_code_generator(op1, tmp_logical); } op1_type_temp = result_type; } if (op2 && !is_terminal(op2)) { if (is_logical(op2)) { op2_number = logical_operator_code_generator(op2); } else { op2_number = operator_code_generator(op2, tmp_logical); } op2_type_temp = result_type; } } //TODO acrescentar uma verificação do tipo de operandos, se um for double usa-se double //TODO uma especie de load terminal que retorne true se for double e false se for int, para saber a operação a usar //TODO se for terminal ir buscar o tipo //TODO se um for double e outro não, fazer cast para double do que não é if (is_terminal(op1)) { op1_type_temp = get_type(op1); } if (op2 && is_terminal(op2)) { op2_type_temp = get_type(op2); } //TODO para os relational passar sempre double_type como false, se o double type do operator_code_generator for true, então fazer o cast if (!strcmp(operator->id, "Add")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "fadd" : "add"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, false); } else if (!strcmp(operator->id, "Sub")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "fsub" : "sub"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, false); } else if (!strcmp(operator->id, "Mul")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "fmul" : "mul"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, false); } else if (!strcmp(operator->id, "Div")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "fdiv" : "sdiv"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, false); } else if (!strcmp(operator->id, "Mod")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "frem" : "srem"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, false); } else if (!strcmp(operator->id, "Eq")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "oeq" : "eq"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Ne")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "une" : "ne"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Le")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "ole" : "sle"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Ge")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "oge" : "sge"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Lt")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "olt" : "slt"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Gt")) { double_type = (!strcmp(op1_type_temp, "double") || !strcmp(op2_type_temp, "double")) ? true : false; operation = double_type ? "ogt" : "sgt"; result = binary_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp, true); } else if (!strcmp(operator->id, "Not")) { result = unary_operator_code_generator(operator, op1_number, op1_type_temp); } else if (!strcmp(operator->id, "Minus")) { result = unary_operator_code_generator(operator, op1_number, op1_type_temp); } else if (!strcmp(operator->id, "Plus")) { result = unary_operator_code_generator(operator, op1_number, op1_type_temp); } else if (!strcmp(operator->id, "BitWiseAnd")) { operation = "and"; result = bitwise_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp); } else if (!strcmp(operator->id, "BitWiseOr")) { operation = "or"; result = bitwise_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp); } else if (!strcmp(operator->id, "BitWiseXor")) { operation = "xor"; result = bitwise_operator_code_generator(operator, operation, op1_number, op2_number, op1_type_temp, op2_type_temp); } //comma? else if (!strcmp(operator->id, "Comma")) { //fazer load do operator -> first_child -> next_sibling; // if(is_terminal(operator -> first_child -> next_sibling)){ // result = load_terminal(operator -> first_child -> next_sibling); // result_type = get_type(operator -> first_child -> next_sibling); // } // else if(!strcmp(operator -> first_child -> next_sibling -> id, "Call")){ // result = call_code_generator(operator -> first_child -> next_sibling); // } // else if(!strcmp(operator -> first_child -> next_sibling -> id, "Store")){ // store_code_generator(operator -> first_child -> next_sibling); // result = load_terminal(operator -> first_child -> next_sibling -> first_child); // } // else{ // result = operator_code_generator(operator -> first_child -> next_sibling, false); // } result = comma_operator_code_generator(operator); } //and else if (!strcmp(operator->id, "And")) { result = logical_operator_code_generator(operator); } //não esquecer verificar cast //orß else if (!strcmp(operator->id, "Or")) { result = logical_operator_code_generator(operator); } else if (!strcmp(operator->id, "Store")) { store_code_generator(operator); //result = llvm_var_counter - 1; result = load_terminal(operator->first_child); result_type = type_to_llvm(operator->annotation.type); } return result; } //???????????????????????????????????????????????????????????????????????????????????????? //?coloquei isto a ir para operadores e call por aqui //!falar com o Pedro para esclarecer dúvida //???????????????????????????????????????????????????????????????????????????????????????? void return_code_generator(ast_node_t *node) { llvm_has_return_keyword = false; ast_node_t *return_value = node->first_child; if (!strcmp(return_value->id, "Id")) { sym_t *sym = find_symbol(current_table->symlist, return_value->token.value); if (!sym) { printf("\t%%%d = load %s, %s* @%s\n", llvm_var_counter++, llvm_return_type, llvm_return_type, return_value->token.value); printf("\tret %s %%%d\n", llvm_return_type, llvm_var_counter - 1); llvm_var_counter++; return; } printf("\t%%%d = load %s, %s* %%%d\n", llvm_var_counter++, llvm_return_type, llvm_return_type, sym->llvm_var); printf("\tret %s %%%d\n", llvm_return_type, llvm_var_counter - 1); } else if (!strcmp(llvm_return_type, "void")) { printf("\tret void\n"); } else if (!strcmp(llvm_return_type, "i32")) { if (!strcmp(return_value->id, "ChrLit")) { printf("\tret %s %d\n", llvm_return_type, ord(return_value->token.value)); llvm_var_counter++; return; } else if (!strcmp(return_value->id, "IntLit") || !strcmp(return_value->id, "Short")) { printf("\tret %s %d\n", llvm_return_type, intlit_to_int(return_value->token.value)); } else if (!strcmp(return_value->id, "Call")) { int result = call_code_generator(return_value); printf("\tret %s %%%d\n", llvm_return_type, result); } else if (!strcmp(return_value->id, "Comma")) { int result = comma_operator_code_generator(return_value); printf("\tret %s %%%d\n", llvm_return_type, result); } else { int result; if (is_logical(return_value)) { result = logical_operator_code_generator(return_value); } else { result = operator_code_generator(return_value, false); } printf("\tret %s %%%d\n", llvm_return_type, result); } } else if (!strcmp(llvm_return_type, "double")) { if (!strcmp(return_value->id, "ChrLit")) { printf("\tret %s %e\n", llvm_return_type, (double)ord(return_value->token.value)); llvm_var_counter++; return; } else if (!strcmp(return_value->id, "IntLit") || !strcmp(return_value->id, "Short")) { printf("\tret %s %e\n", llvm_return_type, (double)intlit_to_int(return_value->token.value)); } else if (!strcmp(return_value->id, "RealLit")) { printf("\tret %s %e\n", llvm_return_type, strtod(return_value->token.value, NULL)); } else if (!strcmp(return_value->id, "Call")) { int result = call_code_generator(return_value); //verificar se o resultype é int, se não for dar cast para double if (!strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } printf("\tret %s %%%d\n", llvm_return_type, result); } // else if(!strcmp(return_value -> id, "Comma")){ // //int result = comma_if_while_return_code_generator(return_value); // int result = comma_operator_code_generator(return_value); // if(!strcmp(result_type, "i32")){ // printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); // result = llvm_var_counter - 1; // } // printf("\tret %s %%%d\n", llvm_return_type, result); // } else { int result; if (is_logical(return_value)) { result = logical_operator_code_generator(return_value); } else { result = operator_code_generator(return_value, false); } //verificar se o resultype é int, se não for dar cast para double if (!strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } printf("\tret %s %%%d\n", llvm_return_type, result); } } else { //!este caso é para quê? code_generator(return_value, false); printf("\tret %s %%%d\n", llvm_return_type, llvm_var_counter - 1); } llvm_has_return_keyword = true; llvm_var_counter++; } void declaration_code_generator(ast_node_t *node) { llvm_has_return_keyword = false; //TODO Não sei como fazer quando isto acontece int a = 1 + 1;, sendo a global, no llvm ele soma o 1 + 1 e coloca 2, não sei fazer isso ast_node_t *typespec = node->first_child; ast_node_t *declarator_id = typespec->next_sibling; ast_node_t *expr = declarator_id->next_sibling; const char *value = expr == NULL ? "0" : expr->token.value; if (current_table == symtab_list) { if (!expr) { if (!strcmp(typespec->id, "Double")) { printf("@%s = global %s %e\n", declarator_id->token.value, type_to_llvm(typespec->id), strtod(value, NULL)); } else if (!strcmp(typespec->id, "Char")) { printf("@%s = global %s %d\n", declarator_id->token.value, type_to_llvm(typespec->id), ord(value)); } else { printf("@%s = global %s %s\n", declarator_id->token.value, type_to_llvm(typespec->id), value); } } else { if (!strcmp(typespec->id, "Double")) { if (!strcmp(expr->id, "ChrLit")) { printf("@%s = global %s %e\n", declarator_id->token.value, type_to_llvm(typespec->id), (double)ord(value)); } else if (!strcmp(expr->id, "RealLit")) { printf("@%s = global %s %e\n", declarator_id->token.value, type_to_llvm(typespec->id), strtod(value, NULL)); } else { printf("@%s = global %s %e\n", declarator_id->token.value, type_to_llvm(typespec->id), (double)intlit_to_int(value)); } } else { if (!strcmp(expr->id, "ChrLit")) { printf("@%s = global %s %d\n", declarator_id->token.value, type_to_llvm(typespec->id), ord(value)); } else { printf("@%s = global %s %d\n", declarator_id->token.value, type_to_llvm(typespec->id), intlit_to_int(value)); } } } return; } sym_t *sym = find_symbol(current_table->symlist, declarator_id->token.value); if (expr == NULL) { printf("\t%%%d = alloca %s\n", llvm_var_counter++, type_to_llvm(typespec->id)); sym->llvm_var = llvm_var_counter - 1; } else { //verificar se expr -> id == Id, se for temos de tratar de maneira diferente if (!strcmp(expr->id, "Id")) { //variável // //verificar se o lhs é double e o rhs não é printf("\t%%%d = alloca %s\n", llvm_var_counter++, type_to_llvm(typespec->id)); sym->llvm_var = llvm_var_counter - 1; //faz load para temporária //verificar se a variável é global sym_t *rhs_symbol = find_symbol(current_table->symlist, expr->token.value); if (rhs_symbol) { //local printf("\t%%%d = load %s, %s* %%%d\n", llvm_var_counter, type_to_llvm(rhs_symbol->type), type_to_llvm(rhs_symbol->type), rhs_symbol->llvm_var); llvm_var_counter++; } else { //global rhs_symbol = find_symbol(symtab_list->symlist, expr->token.value); printf("\t%%%d = load %s, %s* @%s\n", llvm_var_counter, type_to_llvm(rhs_symbol->type), type_to_llvm(rhs_symbol->type), expr->token.value); llvm_var_counter++; } const char *type = type_to_llvm(typespec->id); bool use_sitofp = false; if (!strcmp(typespec->id, "Double") && strcmp("double", rhs_symbol->type)) { type = "i32"; use_sitofp = true; } if (use_sitofp) { printf("\t%%%d = sitofp %s %%%d to %s\n", llvm_var_counter, type, llvm_var_counter - 1, "double"); llvm_var_counter++; printf("\tstore %s %%%d, %s* %%%d\n", "double", llvm_var_counter - 1, "double", llvm_var_counter - 3); } else { printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(typespec->id), llvm_var_counter - 1, type_to_llvm(typespec->id), llvm_var_counter - 2); } } else if (!strcmp(expr->id, "ChrLit") || !strcmp(expr->id, "RealLit") || !strcmp(expr->id, "IntLit") || !strcmp(expr->id, "Short")) { printf("\t%%%d = alloca %s\n", llvm_var_counter++, type_to_llvm(typespec->id)); sym->llvm_var = llvm_var_counter - 1; if (!strcmp(typespec->id, "Double")) { if (!strcmp(expr->id, "ChrLit")) { printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(typespec->id), (double)ord(value), type_to_llvm(typespec->id), llvm_var_counter - 1); } else if (!strcmp(expr->id, "RealLit")) { printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(typespec->id), strtod(value, NULL), type_to_llvm(typespec->id), llvm_var_counter - 1); } else { printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(typespec->id), (double)intlit_to_int(value), type_to_llvm(typespec->id), llvm_var_counter - 1); } } else { if (!strcmp(expr->id, "ChrLit")) { printf("\tstore %s %d, %s* %%%d\n", type_to_llvm(typespec->id), ord(value), type_to_llvm(typespec->id), llvm_var_counter - 1); } else { printf("\tstore %s %d, %s* %%%d\n", type_to_llvm(typespec->id), intlit_to_int(value), type_to_llvm(typespec->id), llvm_var_counter - 1); } } } else if (!strcmp(expr->id, "Call")) { //bool double_type = false; // if (!strcmp(type_to_llvm(typespec->id), "double") && strcmp(type_to_llvm(expr->annotation.type), "double")) // double_type = true; int result = call_code_generator(expr); if (!strcmp(type_to_llvm(typespec->id), "double") && !strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } printf("\t%%%d = alloca %s\n", llvm_var_counter++, type_to_llvm(typespec->id)); sym->llvm_var = llvm_var_counter - 1; printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(typespec->id), result, type_to_llvm(typespec->id), llvm_var_counter - 1); } else { int result; if (is_logical(expr)) { result = logical_operator_code_generator(expr); } else { result = operator_code_generator(expr, false); } if (!strcmp(type_to_llvm(typespec->id), "double") && !strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } printf("\t%%%d = alloca %s\n", llvm_var_counter++, type_to_llvm(typespec->id)); sym->llvm_var = llvm_var_counter - 1; //printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(typespec->id), llvm_var_counter - 2, type_to_llvm(typespec->id), llvm_var_counter - 1); printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(typespec->id), result, type_to_llvm(typespec->id), llvm_var_counter - 1); } } //sym->llvm_var = llvm_var_counter - 1; } void store_code_generator(ast_node_t *node) { llvm_has_return_keyword = false; ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (!strcmp(rhs->id, "Id")) { // Find symbol in the current function table (if there is no symbol then it means that it is globally declared) sym_t *lhs_sym = find_symbol(current_table->symlist, lhs->token.value); sym_t *rhs_sym = find_symbol(current_table->symlist, rhs->token.value); const char *type = type_to_llvm(node->annotation.type); bool use_sitofp = false; if (!strcmp(lhs->annotation.type, "double") && strcmp("double", rhs->annotation.type)) { type = "i32"; use_sitofp = true; } if (!rhs_sym) printf("\t%%%d = load %s, %s* @%s\n", llvm_var_counter++, type, type, rhs->token.value); else printf("\t%%%d = load %s, %s* %%%d\n", llvm_var_counter++, type, type, rhs_sym->llvm_var); if (use_sitofp) { printf("\t%%%d = sitofp %s %%%d to %s\n", llvm_var_counter, type, llvm_var_counter - 1, "double"); llvm_var_counter++; } if (!lhs_sym) printf("\tstore %s %%%d, %s* @%s\n", type_to_llvm(node->annotation.type), llvm_var_counter - 1, type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(node->annotation.type), llvm_var_counter - 1, type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } else if (!strcmp(rhs->id, "ChrLit") || !strcmp(rhs->id, "RealLit") || !strcmp(rhs->id, "IntLit") || !strcmp(rhs->id, "Short")) { // Find symbol in the current function table (if there is no symbol then it means that it is globally declared) const char *value = rhs->token.value; bool global = false; sym_t *lhs_sym = find_symbol(current_table->symlist, lhs->token.value); if (!lhs_sym) { lhs_sym = find_symbol(symtab_list->symlist, lhs->token.value); global = true; } if (!strcmp(lhs_sym->type, "double")) { //estamos a atribuir algum valor a double if (!strcmp(rhs->id, "ChrLit")) { if (global) printf("\tstore %s %e, %s* @%s\n", type_to_llvm(node->annotation.type), (double)ord(value), type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(node->annotation.type), (double)ord(value), type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } else if (!strcmp(rhs->id, "RealLit")) { if (global) printf("\tstore %s %e, %s* @%s\n", type_to_llvm(node->annotation.type), strtod(value, NULL), type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(node->annotation.type), strtod(value, NULL), type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } else { if (global) printf("\tstore %s %e, %s* @%s\n", type_to_llvm(node->annotation.type), (double)intlit_to_int(value), type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %e, %s* %%%d\n", type_to_llvm(node->annotation.type), (double)intlit_to_int(value), type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } } else { if (!strcmp(rhs->id, "ChrLit")) { if (global) printf("\tstore %s %d, %s* @%s\n", type_to_llvm(node->annotation.type), ord(value), type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %d, %s* %%%d\n", type_to_llvm(node->annotation.type), ord(value), type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } else { if (global) printf("\tstore %s %d, %s* @%s\n", type_to_llvm(node->annotation.type), intlit_to_int(value), type_to_llvm(node->annotation.type), lhs->token.value); else printf("\tstore %s %d, %s* %%%d\n", type_to_llvm(node->annotation.type), intlit_to_int(value), type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } } } else if (!strcmp(rhs->id, "Call")) { //bool double_type = false; // if (!strcmp(type_to_llvm(lhs->annotation.type), "double") && strcmp(type_to_llvm(rhs->annotation.type), "double")) // double_type = true; int result = call_code_generator(rhs); if (!strcmp(type_to_llvm(lhs->annotation.type), "double") && !strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } sym_t *lhs_sym = find_symbol(current_table->symlist, lhs->token.value); if (!lhs_sym) { //global printf("\tstore %s %%%d, %s* @%s\n", type_to_llvm(node->annotation.type), result, type_to_llvm(node->annotation.type), lhs->token.value); } else { //local printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(node->annotation.type), result, type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } } else { int result; if (is_logical(rhs)) { result = logical_operator_code_generator(rhs); } else { result = operator_code_generator(rhs, false); //passar o operador e o tipo da variável onde vai ficar guardado } if (!strcmp(type_to_llvm(lhs->annotation.type), "double") && !strcmp(result_type, "i32")) { printf("\t%%%d = sitofp i32 %%%d to double\n", llvm_var_counter++, result); result = llvm_var_counter - 1; } sym_t *lhs_sym = find_symbol(current_table->symlist, lhs->token.value); if (!lhs_sym) { //global //printf("\tstore %s %%%d, %s* @%s\n", type_to_llvm(node->annotation.type), llvm_var_counter - 1, type_to_llvm(node->annotation.type), lhs->token.value); printf("\tstore %s %%%d, %s* @%s\n", type_to_llvm(node->annotation.type), result, type_to_llvm(node->annotation.type), lhs->token.value); } else { //local //printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(node->annotation.type), llvm_var_counter - 1, type_to_llvm(node->annotation.type), lhs_sym -> llvm_var); printf("\tstore %s %%%d, %s* %%%d\n", type_to_llvm(node->annotation.type), result, type_to_llvm(node->annotation.type), lhs_sym->llvm_var); } } } void while_code_generator(ast_node_t *node) { //recebe o no do while llvm_has_return_keyword = false; ast_node_t *condition = node->first_child; ast_node_t *instructions = condition->next_sibling; int condition_result = -1; int first_label, second_label; //expression = node -> first_child -----> expression dentro do while //obter o valor da avaliação da condição do while if (is_terminal(condition)) { condition_result = load_terminal(condition); } else if (!strcmp(condition->id, "Call")) { condition_result = call_code_generator(condition); } else if (!strcmp(condition->id, "Store")) { store_code_generator(condition); condition_result = load_terminal(condition->first_child); } // else if(!strcmp(condition -> id, "Comma")){ // condition_result = comma_if_while_return_code_generator(condition); // } else if (is_logical(condition)) { condition_result = logical_operator_code_generator(condition); } else { condition_result = operator_code_generator(condition, false); } //ver se verifica a condição pelo menos a primeira vez printf("\t%%%d = icmp ne i32 %%%d, 0\n", llvm_var_counter++, condition_result); first_label = current_label++; second_label = current_label++; printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, first_label, second_label); printf("\nlabel%d:\n", first_label); code_generator(instructions, false); //avaliar a condição outra vez if (is_terminal(condition)) { condition_result = load_terminal(condition); } else if (!strcmp(condition->id, "Call")) { condition_result = call_code_generator(condition); } else if (!strcmp(condition->id, "Store")) { store_code_generator(condition); condition_result = load_terminal(condition->first_child); } // else if(!strcmp(condition -> id, "Comma")){ // condition_result = comma_if_while_return_code_generator(condition); // } else if (is_logical(condition)) { condition_result = logical_operator_code_generator(condition); } else { condition_result = operator_code_generator(condition, false); } printf("\t%%%d = icmp ne i32 %%%d, 0\n", llvm_var_counter++, condition_result); printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, first_label, second_label); //print second_label printf("\nlabel%d:\n", second_label); } void if_code_generator(ast_node_t *node) { //recebe o no do if llvm_has_return_keyword = false; ast_node_t *condition = node->first_child; ast_node_t *instructions_true = condition->next_sibling; ast_node_t *instructions_false = instructions_true->next_sibling; int condition_result = -1; int first_label, second_label, third_label; //expression_code_genrator(expression) //obter o valor da avaliação da condição do while if (is_terminal(condition)) { condition_result = load_terminal(condition); } else if (!strcmp(condition->id, "Call")) { condition_result = call_code_generator(condition); } else if (!strcmp(condition->id, "Store")) { store_code_generator(condition); condition_result = load_terminal(condition->first_child); } // else if(!strcmp(condition -> id, "Comma")){ // condition_result = comma_if_while_return_code_generator(condition); // } else if (is_logical(condition)) { condition_result = logical_operator_code_generator(condition); } else { condition_result = operator_code_generator(condition, false); } printf("\t%%%d = icmp ne i32 %%%d, 0\n", llvm_var_counter++, condition_result); first_label = current_label++; second_label = current_label++; third_label = current_label++; printf("\tbr i1 %%%d, label %%label%d, label %%label%d\n", llvm_var_counter - 1, first_label, second_label); // statlist_true = expression-> next_sibling ---------> statlist se for true //pode ser apenas um statement --> verificar se o id deste node é StatList ou não printf("\nlabel%d:\n", first_label); code_generator(instructions_true, true); printf("\tbr label %%label%d\n", third_label); printf("\nlabel%d:\n", second_label); code_generator(instructions_false, false); printf("\tbr label %%label%d\n", third_label); printf("\nlabel%d:\n", third_label); // statilist_false = statlist_true-> next_sibling --------> statlist se for false //pode ser apenas um statement --> verificar se o id deste node é StatList ou não } void code_generator(ast_node_t *node, bool is_if) { llvm_has_return_keyword = false; if (!node) return; if (!strcmp(node->id, "Program")) { printf("declare i32 @putchar(...)\n"); printf("declare i32 @getchar(...)\n\n"); code_generator(node->first_child, false); return; } if (!strcmp(node->id, "FuncDefinition")) { funcdef_code_generator(node); } if (!strcmp(node->id, "Declaration")) { declaration_code_generator(node); } if (!strcmp(node->id, "Store")) { store_code_generator(node); } // if(!strcmp(node -> id, "Comma")){ // ast_node_t* aux = node; // while(!strcmp(aux -> id, "Comma")){ // aux = aux -> first_child; // } // if(!strcmp(aux -> id, "Store"))//só quero que entre se for um store // code_generator(aux, false); // } if (!strcmp(node->id, "Return")) { return_code_generator(node); } //está aqui para o caso de se fazer uma call sem ser num store, numa declaration ou return if (!strcmp(node->id, "Call")) { call_code_generator(node); } if (!strcmp(node->id, "While")) { while_code_generator(node); } if (!strcmp(node->id, "If")) { if_code_generator(node); } if (!strcmp(node->id, "StatList")) { code_generator(node->first_child, false); } if (!strcmp(node->id, "Not") || !strcmp(node->id, "Minus") || !strcmp(node->id, "Plus") || !strcmp(node->id, "Add") || !strcmp(node->id, "Sub") || !strcmp(node->id, "Mul") || !strcmp(node->id, "Div") || !strcmp(node->id, "Mod") || !strcmp(node->id, "Eq") || !strcmp(node->id, "Ne") || !strcmp(node->id, "Le") || !strcmp(node->id, "Ge") || !strcmp(node->id, "Lt") || !strcmp(node->id, "Gt") || !strcmp(node->id, "BitWiseAnd") || !strcmp(node->id, "BitWiseOr") || !strcmp(node->id, "BitWiseXor") || !strcmp(node->id, "Comma")) { operator_code_generator(node, false); } if (!strcmp(node->id, "And") || !strcmp(node->id, "Or")) { //operator_code_generator(node, true); logical_operator_code_generator(node); } if (node->next_sibling != NULL && !is_if) { code_generator(node->next_sibling, false); } } void code_generation(ast_node_t *program) { code_generator(program, false); }
pedromig/COMP-Project
tests/meta4/input/plus.c
<gh_stars>1-10 void print_equality(double a, double b) { if (a == b) { putchar('y'); putchar('e'); putchar('s'); } else { putchar('n'); putchar('o'); } putchar('\n'); } int main(void){ print_equality(1.0, +1.0); print_equality(1.0, +(-(-1.0))); print_equality('A', +(+'A')); print_equality(-4.2, +(+(-(4.2 + 0.2 - 0.2)))); }
pedromig/COMP-Project
src/semantic_analysis.h
/** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #ifndef __SEMANTIC_ANALYSIS_H #define __SEMANTIC_ANALYSIS_H #include "structures.h" #include "symbol_table.h" #include "utils.h" extern symtab_t *symtab_list; extern symtab_t *current_table; void semantic_analysis(ast_node_t *program); #endif //__SEMANTIC_ANALYSIS_H
pedromig/COMP-Project
tests/meta3/input/redefinitionRedeclarationV2.c
int A(int); int A(int a){} int A(int); int A(int a){} int B(int); int B(int a){} int B(double); int B(int a){} int C(int a){} int C(int); int D(int a){} int D(double);
pedromig/COMP-Project
tests/meta4/input/sierpinski.c
int main(void) { int i = 0; int j; while (i < 32) { j = 0; while (j < 32) { if (i & j) putchar(' '); else putchar('+'); j = j + 1; } i = i + 1; putchar('\n'); } return 0; }
pedromig/COMP-Project
tests/meta1/input/unterminatedChar_linecomment.c
'ç' ' ' 'ç 'abc 456 '~' '^ //comentario EOF
pedromig/COMP-Project
tests/meta4/input/alphabet.c
int main(void) { int a; while ((a = 0)); while (0); int n = 0; while(n < 26) { putchar('a' + n); n = n + 1; } }
pedromig/COMP-Project
tests/meta3/input/testes.c
void f0_A(void); void f0_B(void,void); void f1(int a, double b); int f1(int a, double b); int f1(int a, double b){ return a; } int f2(int a, double b); int f2(int a, double b){ return b; } void f3(void){ //algo } void f4(int a, char b, short c, double d); int main(void){ void erro; int a; char b; short c; double d; int a; double b; if(!a){ } if(!b){ } if(!c){ } if(!d){ } if(!e){ } if(h){ } if(b = b){ } if(a){ } if(b){ } if(c){ } if(d){ } int coiso = f3(); f4(a,a,a,a); f4(b,b,b,b); f4(c,c,c,c); f4(d,d,d,d); }
pedromig/COMP-Project
tests/meta4/input/call_tests.c
int fabio = 80; // int renata = fabio +2; int a(void){ putchar(fabio +2); putchar('\n'); putchar(fabio); putchar('\n'); fabio = fabio + 5; return fabio; return 5; return 'a'; } int b(void){ putchar(fabio); putchar('\n'); } void c(void){ } void d(int a){ return; return; return; return; fabio = 20; } int e(int a){ putchar(a); putchar('\n'); a = a + 5; putchar(a); putchar('\n'); return a; } double f(int a){ } int main(void){ d(5); int var; double d_var; var = a(); var = b(); //var = c(); d(1); c(); d_var = e(100); d_var = f(2); //d_var = d(2); a(); b(); c(); d('a'); var = e(100); putchar(var); f('a'); }
pedromig/COMP-Project
src/symbol_table.h
<filename>src/symbol_table.h /** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #include <assert.h> #include <ctype.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef __SYMBOL_TABLE #define __SYMBOL_TABLE #include "structures.h" symtab_t *symbol_table(const char *id); sym_t *symbol(const char *id, type_t type, param_t *parameters); param_t *parameter(type_t type); symtab_t *add_table(symtab_t *list, const char *id); symtab_t *find_table(symtab_t *list, const char *id); void add_symbol(symtab_t *table, sym_t *symbol); sym_t *find_symbol(sym_t *list, const char *id); void print_table_list(symtab_t *list); void print_symbol_type(sym_t *symbol); void free_symbol(sym_t *symbol); void free_symbol_table_list(symtab_t *head); bool compare_symbol_types(sym_t *s1, sym_t *s2); void delete_undefined_tables(symtab_t *list); void print_annotation(annotation_t annotation); void print_parameter_list(param_t *head); #endif // __SYMBOL_TABLE
pedromig/COMP-Project
tests/meta4/input/declarations.c
<reponame>pedromig/COMP-Project char aa(char a); short bb(short b); int cc(int c); double dd(double d); int main(void) { putchar('A'); // getchar(); return 0; }
pedromig/COMP-Project
tests/meta3/input/alreadyDefinedAndVoid.c
<filename>tests/meta3/input/alreadyDefinedAndVoid.c double f7(short a, double b, int b); double f7(short a, double b){} double f8(short a, void b); double f8(short a){}
pedromig/COMP-Project
tests/meta4/input/charlits.c
int main(void) { char c; c = 0; putchar(c); c = 1; putchar(c); c = 2; putchar(c); c = 3; putchar(c); c = 4; putchar(c); c = 5; putchar(c); c = 6; putchar(c); c = 7; putchar(c); c = 8; putchar(c); c = 9; putchar(c); c = 10; putchar(c); c = 11; putchar(c); c = 12; putchar(c); c = 13; putchar(c); c = 14; putchar(c); c = 15; putchar(c); c = 16; putchar(c); c = 17; putchar(c); c = 18; putchar(c); c = 19; putchar(c); c = 20; putchar(c); c = 21; putchar(c); c = 22; putchar(c); c = 23; putchar(c); c = 24; putchar(c); c = 25; putchar(c); c = 26; putchar(c); c = 27; putchar(c); c = 28; putchar(c); c = 29; putchar(c); c = 30; putchar(c); c = 31; putchar(c); c = 32; putchar(c); c = 33; putchar(c); c = 34; putchar(c); c = 35; putchar(c); c = 36; putchar(c); c = 37; putchar(c); c = 38; putchar(c); c = 39; putchar(c); c = 40; putchar(c); c = 41; putchar(c); c = 42; putchar(c); c = 43; putchar(c); c = 44; putchar(c); c = 45; putchar(c); c = 46; putchar(c); c = 47; putchar(c); c = 48; putchar(c); c = 49; putchar(c); c = 50; putchar(c); c = 51; putchar(c); c = 52; putchar(c); c = 53; putchar(c); c = 54; putchar(c); c = 55; putchar(c); c = 56; putchar(c); c = 57; putchar(c); c = 58; putchar(c); c = 59; putchar(c); c = 60; putchar(c); c = 61; putchar(c); c = 62; putchar(c); c = 63; putchar(c); c = 64; putchar(c); c = 65; putchar(c); c = 66; putchar(c); c = 67; putchar(c); c = 68; putchar(c); c = 69; putchar(c); c = 70; putchar(c); c = 71; putchar(c); c = 72; putchar(c); c = 73; putchar(c); c = 74; putchar(c); c = 75; putchar(c); c = 76; putchar(c); c = 77; putchar(c); c = 78; putchar(c); c = 79; putchar(c); c = 80; putchar(c); c = 81; putchar(c); c = 82; putchar(c); c = 83; putchar(c); c = 84; putchar(c); c = 85; putchar(c); c = 86; putchar(c); c = 87; putchar(c); c = 88; putchar(c); c = 89; putchar(c); c = 90; putchar(c); c = 91; putchar(c); c = 92; putchar(c); c = 93; putchar(c); c = 94; putchar(c); c = 95; putchar(c); c = 96; putchar(c); c = 97; putchar(c); c = 98; putchar(c); c = 99; putchar(c); c = 100; putchar(c); c = 101; putchar(c); c = 102; putchar(c); c = 103; putchar(c); c = 104; putchar(c); c = 105; putchar(c); c = 106; putchar(c); c = 107; putchar(c); c = 108; putchar(c); c = 109; putchar(c); c = 110; putchar(c); c = 111; putchar(c); c = 112; putchar(c); c = 113; putchar(c); c = 114; putchar(c); c = 115; putchar(c); c = 116; putchar(c); c = 117; putchar(c); c = 118; putchar(c); c = 119; putchar(c); c = 120; putchar(c); c = 121; putchar(c); c = 122; putchar(c); c = 123; putchar(c); c = 124; putchar(c); c = 125; putchar(c); c = 126; putchar(c); c = 127; putchar(c); c = 128; putchar(c); c = 129; putchar(c); c = 130; putchar(c); c = 131; putchar(c); c = 132; putchar(c); c = 133; putchar(c); c = 134; putchar(c); c = 135; putchar(c); c = 136; putchar(c); c = 137; putchar(c); c = 138; putchar(c); c = 139; putchar(c); c = 140; putchar(c); c = 141; putchar(c); c = 142; putchar(c); c = 143; putchar(c); c = 144; putchar(c); c = 145; putchar(c); c = 146; putchar(c); c = 147; putchar(c); c = 148; putchar(c); c = 149; putchar(c); c = 150; putchar(c); c = 151; putchar(c); c = 152; putchar(c); c = 153; putchar(c); c = 154; putchar(c); c = 155; putchar(c); c = 156; putchar(c); c = 157; putchar(c); c = 158; putchar(c); c = 159; putchar(c); c = 160; putchar(c); c = 161; putchar(c); c = 162; putchar(c); c = 163; putchar(c); c = 164; putchar(c); c = 165; putchar(c); c = 166; putchar(c); c = 167; putchar(c); c = 168; putchar(c); c = 169; putchar(c); c = 170; putchar(c); c = 171; putchar(c); c = 172; putchar(c); c = 173; putchar(c); c = 174; putchar(c); c = 175; putchar(c); c = 176; putchar(c); c = 177; putchar(c); c = 178; putchar(c); c = 179; putchar(c); c = 180; putchar(c); c = 181; putchar(c); c = 182; putchar(c); c = 183; putchar(c); c = 184; putchar(c); c = 185; putchar(c); c = 186; putchar(c); c = 187; putchar(c); c = 188; putchar(c); c = 189; putchar(c); c = 190; putchar(c); c = 191; putchar(c); c = 192; putchar(c); c = 193; putchar(c); c = 194; putchar(c); c = 195; putchar(c); c = 196; putchar(c); c = 197; putchar(c); c = 198; putchar(c); c = 199; putchar(c); c = 200; putchar(c); c = 201; putchar(c); c = 202; putchar(c); c = 203; putchar(c); c = 204; putchar(c); c = 205; putchar(c); c = 206; putchar(c); c = 207; putchar(c); c = 208; putchar(c); c = 209; putchar(c); c = 210; putchar(c); c = 211; putchar(c); c = 212; putchar(c); c = 213; putchar(c); c = 214; putchar(c); c = 215; putchar(c); c = 216; putchar(c); c = 217; putchar(c); c = 218; putchar(c); c = 219; putchar(c); c = 220; putchar(c); c = 221; putchar(c); c = 222; putchar(c); c = 223; putchar(c); c = 224; putchar(c); c = 225; putchar(c); c = 226; putchar(c); c = 227; putchar(c); c = 228; putchar(c); c = 229; putchar(c); c = 230; putchar(c); c = 231; putchar(c); c = 232; putchar(c); c = 233; putchar(c); c = 234; putchar(c); c = 235; putchar(c); c = 236; putchar(c); c = 237; putchar(c); c = 238; putchar(c); c = 239; putchar(c); c = 240; putchar(c); c = 241; putchar(c); c = 242; putchar(c); c = 243; putchar(c); c = 244; putchar(c); c = 245; putchar(c); c = 246; putchar(c); c = 247; putchar(c); c = 248; putchar(c); c = 249; putchar(c); c = 250; putchar(c); c = 251; putchar(c); c = 252; putchar(c); c = 253; putchar(c); c = 254; putchar(c); c = '\0'; putchar(c); c = 00; putchar(c); c = '\00'; putchar(c); c = 000; putchar(c); c = '\000'; putchar(c); c = 0000; putchar(c); c = '\001'; putchar(c); c = 0001; putchar(c); c = '\002'; putchar(c); c = 0002; putchar(c); c = '\003'; putchar(c); c = 0003; putchar(c); c = '\004'; putchar(c); c = 0004; putchar(c); c = '\005'; putchar(c); c = 0005; putchar(c); c = '\006'; putchar(c); c = 0006; putchar(c); c = '\007'; putchar(c); c = 0007; putchar(c); c = '\01'; putchar(c); c = 001; putchar(c); c = '\010'; putchar(c); c = 0010; putchar(c); c = '\011'; putchar(c); c = 0011; putchar(c); c = '\012'; putchar(c); c = 0012; putchar(c); c = '\013'; putchar(c); c = 0013; putchar(c); c = '\014'; putchar(c); c = 0014; putchar(c); c = '\015'; putchar(c); c = 0015; putchar(c); c = '\016'; putchar(c); c = 0016; putchar(c); c = '\017'; putchar(c); c = 0017; putchar(c); c = '\02'; putchar(c); c = 002; putchar(c); c = '\020'; putchar(c); c = 0020; putchar(c); c = '\021'; putchar(c); c = 0021; putchar(c); c = '\022'; putchar(c); c = 0022; putchar(c); c = '\023'; putchar(c); c = 0023; putchar(c); c = '\024'; putchar(c); c = 0024; putchar(c); c = '\025'; putchar(c); c = 0025; putchar(c); c = '\026'; putchar(c); c = 0026; putchar(c); c = '\027'; putchar(c); c = 0027; putchar(c); c = '\03'; putchar(c); c = 003; putchar(c); c = '\030'; putchar(c); c = 0030; putchar(c); c = '\031'; putchar(c); c = 0031; putchar(c); c = '\032'; putchar(c); c = 0032; putchar(c); c = '\033'; putchar(c); c = 0033; putchar(c); c = '\034'; putchar(c); c = 0034; putchar(c); c = '\035'; putchar(c); c = 0035; putchar(c); c = '\036'; putchar(c); c = 0036; putchar(c); c = '\037'; putchar(c); c = 0037; putchar(c); c = '\04'; putchar(c); c = 004; putchar(c); c = '\040'; putchar(c); c = 0040; putchar(c); c = '\041'; putchar(c); c = 0041; putchar(c); c = '\042'; putchar(c); c = 0042; putchar(c); c = '\043'; putchar(c); c = 0043; putchar(c); c = '\044'; putchar(c); c = 0044; putchar(c); c = '\045'; putchar(c); c = 0045; putchar(c); c = '\046'; putchar(c); c = 0046; putchar(c); c = '\047'; putchar(c); c = 0047; putchar(c); c = '\05'; putchar(c); c = 005; putchar(c); c = '\050'; putchar(c); c = 0050; putchar(c); c = '\051'; putchar(c); c = 0051; putchar(c); c = '\052'; putchar(c); c = 0052; putchar(c); c = '\053'; putchar(c); c = 0053; putchar(c); c = '\054'; putchar(c); c = 0054; putchar(c); c = '\055'; putchar(c); c = 0055; putchar(c); c = '\056'; putchar(c); c = 0056; putchar(c); c = '\057'; putchar(c); c = 0057; putchar(c); c = '\06'; putchar(c); c = 006; putchar(c); c = '\060'; putchar(c); c = 0060; putchar(c); c = '\061'; putchar(c); c = 0061; putchar(c); c = '\062'; putchar(c); c = 0062; putchar(c); c = '\063'; putchar(c); c = 0063; putchar(c); c = '\064'; putchar(c); c = 0064; putchar(c); c = '\065'; putchar(c); c = 0065; putchar(c); c = '\066'; putchar(c); c = 0066; putchar(c); c = '\067'; putchar(c); c = 0067; putchar(c); c = '\07'; putchar(c); c = 007; putchar(c); c = '\070'; putchar(c); c = 0070; putchar(c); c = '\071'; putchar(c); c = 0071; putchar(c); c = '\072'; putchar(c); c = 0072; putchar(c); c = '\073'; putchar(c); c = 0073; putchar(c); c = '\074'; putchar(c); c = 0074; putchar(c); c = '\075'; putchar(c); c = 0075; putchar(c); c = '\076'; putchar(c); c = 0076; putchar(c); c = '\077'; putchar(c); c = 0077; putchar(c); c = '\1'; putchar(c); c = 01; putchar(c); c = '\10'; putchar(c); c = 010; putchar(c); c = '\100'; putchar(c); c = 0100; putchar(c); c = '\101'; putchar(c); c = 0101; putchar(c); c = '\102'; putchar(c); c = 0102; putchar(c); c = '\103'; putchar(c); c = 0103; putchar(c); c = '\104'; putchar(c); c = 0104; putchar(c); c = '\105'; putchar(c); c = 0105; putchar(c); c = '\106'; putchar(c); c = 0106; putchar(c); c = '\107'; putchar(c); c = 0107; putchar(c); c = '\11'; putchar(c); c = 011; putchar(c); c = '\110'; putchar(c); c = 0110; putchar(c); c = '\111'; putchar(c); c = 0111; putchar(c); c = '\112'; putchar(c); c = 0112; putchar(c); c = '\113'; putchar(c); c = 0113; putchar(c); c = '\114'; putchar(c); c = 0114; putchar(c); c = '\115'; putchar(c); c = 0115; putchar(c); c = '\116'; putchar(c); c = 0116; putchar(c); c = '\117'; putchar(c); c = 0117; putchar(c); c = '\12'; putchar(c); c = 012; putchar(c); c = '\120'; putchar(c); c = 0120; putchar(c); c = '\121'; putchar(c); c = 0121; putchar(c); c = '\122'; putchar(c); c = 0122; putchar(c); c = '\123'; putchar(c); c = 0123; putchar(c); c = '\124'; putchar(c); c = 0124; putchar(c); c = '\125'; putchar(c); c = 0125; putchar(c); c = '\126'; putchar(c); c = 0126; putchar(c); c = '\127'; putchar(c); c = 0127; putchar(c); c = '\13'; putchar(c); c = 013; putchar(c); c = '\130'; putchar(c); c = 0130; putchar(c); c = '\131'; putchar(c); c = 0131; putchar(c); c = '\132'; putchar(c); c = 0132; putchar(c); c = '\133'; putchar(c); c = 0133; putchar(c); c = '\134'; putchar(c); c = 0134; putchar(c); c = '\135'; putchar(c); c = 0135; putchar(c); c = '\136'; putchar(c); c = 0136; putchar(c); c = '\137'; putchar(c); c = 0137; putchar(c); c = '\14'; putchar(c); c = 014; putchar(c); c = '\140'; putchar(c); c = 0140; putchar(c); c = '\141'; putchar(c); c = 0141; putchar(c); c = '\142'; putchar(c); c = 0142; putchar(c); c = '\143'; putchar(c); c = 0143; putchar(c); c = '\144'; putchar(c); c = 0144; putchar(c); c = '\145'; putchar(c); c = 0145; putchar(c); c = '\146'; putchar(c); c = 0146; putchar(c); c = '\147'; putchar(c); c = 0147; putchar(c); c = '\15'; putchar(c); c = 015; putchar(c); c = '\150'; putchar(c); c = 0150; putchar(c); c = '\151'; putchar(c); c = 0151; putchar(c); c = '\152'; putchar(c); c = 0152; putchar(c); c = '\153'; putchar(c); c = 0153; putchar(c); c = '\154'; putchar(c); c = 0154; putchar(c); c = '\155'; putchar(c); c = 0155; putchar(c); c = '\156'; putchar(c); c = 0156; putchar(c); c = '\157'; putchar(c); c = 0157; putchar(c); c = '\16'; putchar(c); c = 016; putchar(c); c = '\160'; putchar(c); c = 0160; putchar(c); c = '\161'; putchar(c); c = 0161; putchar(c); c = '\162'; putchar(c); c = 0162; putchar(c); c = '\163'; putchar(c); c = 0163; putchar(c); c = '\164'; putchar(c); c = 0164; putchar(c); c = '\165'; putchar(c); c = 0165; putchar(c); c = '\166'; putchar(c); c = 0166; putchar(c); c = '\167'; putchar(c); c = 0167; putchar(c); c = '\17'; putchar(c); c = 017; putchar(c); c = '\170'; putchar(c); c = 0170; putchar(c); c = '\171'; putchar(c); c = 0171; putchar(c); c = '\172'; putchar(c); c = 0172; putchar(c); c = '\173'; putchar(c); c = 0173; putchar(c); c = '\174'; putchar(c); c = 0174; putchar(c); c = '\175'; putchar(c); c = 0175; putchar(c); c = '\176'; putchar(c); c = 0176; putchar(c); c = '\177'; putchar(c); c = 0177; putchar(c); c = '\2'; putchar(c); c = 02; putchar(c); c = '\20'; putchar(c); c = 020; putchar(c); c = '\200'; putchar(c); c = 0200; putchar(c); c = '\201'; putchar(c); c = 0201; putchar(c); c = '\202'; putchar(c); c = 0202; putchar(c); c = '\203'; putchar(c); c = 0203; putchar(c); c = '\204'; putchar(c); c = 0204; putchar(c); c = '\205'; putchar(c); c = 0205; putchar(c); c = '\206'; putchar(c); c = 0206; putchar(c); c = '\207'; putchar(c); c = 0207; putchar(c); c = '\21'; putchar(c); c = 021; putchar(c); c = '\210'; putchar(c); c = 0210; putchar(c); c = '\211'; putchar(c); c = 0211; putchar(c); c = '\212'; putchar(c); c = 0212; putchar(c); c = '\213'; putchar(c); c = 0213; putchar(c); c = '\214'; putchar(c); c = 0214; putchar(c); c = '\215'; putchar(c); c = 0215; putchar(c); c = '\216'; putchar(c); c = 0216; putchar(c); c = '\217'; putchar(c); c = 0217; putchar(c); c = '\22'; putchar(c); c = 022; putchar(c); c = '\220'; putchar(c); c = 0220; putchar(c); c = '\221'; putchar(c); c = 0221; putchar(c); c = '\222'; putchar(c); c = 0222; putchar(c); c = '\223'; putchar(c); c = 0223; putchar(c); c = '\224'; putchar(c); c = 0224; putchar(c); c = '\225'; putchar(c); c = 0225; putchar(c); c = '\226'; putchar(c); c = 0226; putchar(c); c = '\227'; putchar(c); c = 0227; putchar(c); c = '\23'; putchar(c); c = 023; putchar(c); c = '\230'; putchar(c); c = 0230; putchar(c); c = '\231'; putchar(c); c = 0231; putchar(c); c = '\232'; putchar(c); c = 0232; putchar(c); c = '\233'; putchar(c); c = 0233; putchar(c); c = '\234'; putchar(c); c = 0234; putchar(c); c = '\235'; putchar(c); c = 0235; putchar(c); c = '\236'; putchar(c); c = 0236; putchar(c); c = '\237'; putchar(c); c = 0237; putchar(c); c = '\24'; putchar(c); c = 024; putchar(c); c = '\240'; putchar(c); c = 0240; putchar(c); c = '\241'; putchar(c); c = 0241; putchar(c); c = '\242'; putchar(c); c = 0242; putchar(c); c = '\243'; putchar(c); c = 0243; putchar(c); c = '\244'; putchar(c); c = 0244; putchar(c); c = '\245'; putchar(c); c = 0245; putchar(c); c = '\246'; putchar(c); c = 0246; putchar(c); c = '\247'; putchar(c); c = 0247; putchar(c); c = '\25'; putchar(c); c = 025; putchar(c); c = '\250'; putchar(c); c = 0250; putchar(c); c = '\251'; putchar(c); c = 0251; putchar(c); c = '\252'; putchar(c); c = 0252; putchar(c); c = '\253'; putchar(c); c = 0253; putchar(c); c = '\254'; putchar(c); c = 0254; putchar(c); c = '\255'; putchar(c); c = 0255; putchar(c); c = '\256'; putchar(c); c = 0256; putchar(c); c = '\257'; putchar(c); c = 0257; putchar(c); c = '\26'; putchar(c); c = 026; putchar(c); c = '\260'; putchar(c); c = 0260; putchar(c); c = '\261'; putchar(c); c = 0261; putchar(c); c = '\262'; putchar(c); c = 0262; putchar(c); c = '\263'; putchar(c); c = 0263; putchar(c); c = '\264'; putchar(c); c = 0264; putchar(c); c = '\265'; putchar(c); c = 0265; putchar(c); c = '\266'; putchar(c); c = 0266; putchar(c); c = '\267'; putchar(c); c = 0267; putchar(c); c = '\27'; putchar(c); c = 027; putchar(c); c = '\270'; putchar(c); c = 0270; putchar(c); c = '\271'; putchar(c); c = 0271; putchar(c); c = '\272'; putchar(c); c = 0272; putchar(c); c = '\273'; putchar(c); c = 0273; putchar(c); c = '\274'; putchar(c); c = 0274; putchar(c); c = '\275'; putchar(c); c = 0275; putchar(c); c = '\276'; putchar(c); c = 0276; putchar(c); c = '\277'; putchar(c); c = 0277; putchar(c); c = '\3'; putchar(c); c = 03; putchar(c); c = '\30'; putchar(c); c = 030; putchar(c); c = '\300'; putchar(c); c = 0300; putchar(c); c = '\301'; putchar(c); c = 0301; putchar(c); c = '\302'; putchar(c); c = 0302; putchar(c); c = '\303'; putchar(c); c = 0303; putchar(c); c = '\304'; putchar(c); c = 0304; putchar(c); c = '\305'; putchar(c); c = 0305; putchar(c); c = '\306'; putchar(c); c = 0306; putchar(c); c = '\307'; putchar(c); c = 0307; putchar(c); c = '\31'; putchar(c); c = 031; putchar(c); c = '\310'; putchar(c); c = 0310; putchar(c); c = '\311'; putchar(c); c = 0311; putchar(c); c = '\312'; putchar(c); c = 0312; putchar(c); c = '\313'; putchar(c); c = 0313; putchar(c); c = '\314'; putchar(c); c = 0314; putchar(c); c = '\315'; putchar(c); c = 0315; putchar(c); c = '\316'; putchar(c); c = 0316; putchar(c); c = '\317'; putchar(c); c = 0317; putchar(c); c = '\32'; putchar(c); c = 032; putchar(c); c = '\320'; putchar(c); c = 0320; putchar(c); c = '\321'; putchar(c); c = 0321; putchar(c); c = '\322'; putchar(c); c = 0322; putchar(c); c = '\323'; putchar(c); c = 0323; putchar(c); c = '\324'; putchar(c); c = 0324; putchar(c); c = '\325'; putchar(c); c = 0325; putchar(c); c = '\326'; putchar(c); c = 0326; putchar(c); c = '\327'; putchar(c); c = 0327; putchar(c); c = '\33'; putchar(c); c = 033; putchar(c); c = '\330'; putchar(c); c = 0330; putchar(c); c = '\331'; putchar(c); c = 0331; putchar(c); c = '\332'; putchar(c); c = 0332; putchar(c); c = '\333'; putchar(c); c = 0333; putchar(c); c = '\334'; putchar(c); c = 0334; putchar(c); c = '\335'; putchar(c); c = 0335; putchar(c); c = '\336'; putchar(c); c = 0336; putchar(c); c = '\337'; putchar(c); c = 0337; putchar(c); c = '\34'; putchar(c); c = 034; putchar(c); c = '\340'; putchar(c); c = 0340; putchar(c); c = '\341'; putchar(c); c = 0341; putchar(c); c = '\342'; putchar(c); c = 0342; putchar(c); c = '\343'; putchar(c); c = 0343; putchar(c); c = '\344'; putchar(c); c = 0344; putchar(c); c = '\345'; putchar(c); c = 0345; putchar(c); c = '\346'; putchar(c); c = 0346; putchar(c); c = '\347'; putchar(c); c = 0347; putchar(c); c = '\35'; putchar(c); c = 035; putchar(c); c = '\350'; putchar(c); c = 0350; putchar(c); c = '\351'; putchar(c); c = 0351; putchar(c); c = '\352'; putchar(c); c = 0352; putchar(c); c = '\353'; putchar(c); c = 0353; putchar(c); c = '\354'; putchar(c); c = 0354; putchar(c); c = '\355'; putchar(c); c = 0355; putchar(c); c = '\356'; putchar(c); c = 0356; putchar(c); c = '\357'; putchar(c); c = 0357; putchar(c); c = '\36'; putchar(c); c = 036; putchar(c); c = '\360'; putchar(c); c = 0360; putchar(c); c = '\361'; putchar(c); c = 0361; putchar(c); c = '\362'; putchar(c); c = 0362; putchar(c); c = '\363'; putchar(c); c = 0363; putchar(c); c = '\364'; putchar(c); c = 0364; putchar(c); c = '\365'; putchar(c); c = 0365; putchar(c); c = '\366'; putchar(c); c = 0366; putchar(c); c = '\367'; putchar(c); c = 0367; putchar(c); c = '\37'; putchar(c); c = 037; putchar(c); c = '\370'; putchar(c); c = 0370; putchar(c); c = '\371'; putchar(c); c = 0371; putchar(c); c = '\372'; putchar(c); c = 0372; putchar(c); c = '\373'; putchar(c); c = 0373; putchar(c); c = '\374'; putchar(c); c = 0374; putchar(c); c = '\375'; putchar(c); c = 0375; putchar(c); c = '\376'; putchar(c); c = 0376; putchar(c); c = '\377'; putchar(c); c = 0377; putchar(c); c = '\4'; putchar(c); c = 04; putchar(c); c = '\40'; putchar(c); c = 040; putchar(c); c = '\41'; putchar(c); c = 041; putchar(c); c = '\42'; putchar(c); c = 042; putchar(c); c = '\43'; putchar(c); c = 043; putchar(c); c = '\44'; putchar(c); c = 044; putchar(c); c = '\45'; putchar(c); c = 045; putchar(c); c = '\46'; putchar(c); c = 046; putchar(c); c = '\47'; putchar(c); c = 047; putchar(c); c = '\5'; putchar(c); c = 05; putchar(c); c = '\50'; putchar(c); c = 050; putchar(c); c = '\51'; putchar(c); c = 051; putchar(c); c = '\52'; putchar(c); c = 052; putchar(c); c = '\53'; putchar(c); c = 053; putchar(c); c = '\54'; putchar(c); c = 054; putchar(c); c = '\55'; putchar(c); c = 055; putchar(c); c = '\56'; putchar(c); c = 056; putchar(c); c = '\57'; putchar(c); c = 057; putchar(c); c = '\6'; putchar(c); c = 06; putchar(c); c = '\60'; putchar(c); c = 060; putchar(c); c = '\61'; putchar(c); c = 061; putchar(c); c = '\62'; putchar(c); c = 062; putchar(c); c = '\63'; putchar(c); c = 063; putchar(c); c = '\64'; putchar(c); c = 064; putchar(c); c = '\65'; putchar(c); c = 065; putchar(c); c = '\66'; putchar(c); c = 066; putchar(c); c = '\67'; putchar(c); c = 067; putchar(c); c = '\7'; putchar(c); c = 07; putchar(c); c = '\70'; putchar(c); c = 070; putchar(c); c = '\71'; putchar(c); c = 071; putchar(c); c = '\72'; putchar(c); c = 072; putchar(c); c = '\73'; putchar(c); c = 073; putchar(c); c = '\74'; putchar(c); c = 074; putchar(c); c = '\75'; putchar(c); c = 075; putchar(c); c = '\76'; putchar(c); c = 076; putchar(c); c = '\77'; putchar(c); c = 077; putchar(c); return 0; }
pedromig/COMP-Project
tests/meta4/input/random_tests.c
<gh_stars>1-10 int oi(int x, int y) { char a; char b, c = 'd'; double d, e, f; e = 4; f = d + e; return 0; } int x(void) { int a, b, c, x; int d = 2, j; a = d != x; } int asd(int x) { int b = 2, v, d, c; char a = x, r = a - b; putchar(x = a); putchar(a + v); putchar(c - d); putchar(!b); putchar(+a); putchar(-b); return oi(1, 2), oi(2, 2), oi(192, 2); } int xddx(int xd, char l, double ups, short dx) { double v = 2.4; xd == dx; xd > dx; xd < dx; xd >= dx; xd <= dx; xd | dx; xd &dx; xd != dx; xd &&dx; xd || dx; xd ^ dx; xd = xd % dx; xd = xd * dx; xd = xd / dx; !xd; +xd; -xd; xd = dx; } int statements(void) { int x = 1; if (1) { } else { } if (x == 1 && x != 1) { if (x != 0 && x != statements() || (x % 2) && (x ^ 2)) { if (!x + !statements() != 'C') { if ((!!x * statements() && 2) & 1) { } else { return 5; } return 4; } return 3; } return 2; } return 1; } int m(char xx, int yy, int zz) { int x = 1, y = 2, z; int a, b, c, d, e; if (x > y && z > y || z != x) { return 1; } else { return 0; } if (2, 1, 2) { } } int main(void) { int xd = 0, dx = 0; putchar(xd = dx); if (xd = dx) { putchar(xd = dx); } else { putchar('A'); } return 0; }
pedromig/COMP-Project
tests/meta4/input/expressions2.c
int yaya = 52; void print_number(int n) { if (n == 0) putchar('0'); int u = 1; while (n / u) u = u * 10; while (u > 1) { putchar('0' + n / (u / 10) - n / u * 10); u = u / 10; } } int main(void) { int expr = 3 * 42 >= 84; print_number(expr); putchar('\n'); expr = (43 * 1 / 3) + 98 - 12 + (-(-(-(11)))); print_number(expr); print_number(expr); print_number(expr); putchar('\n'); print_number(expr); putchar('\n'); expr = expr % 2; expr = expr % 1; print_number(expr); putchar('\n'); expr = expr % 1; expr = 9999; print_number(expr != 12); print_number(expr < 111); print_number(expr <= 111); print_number(expr > 111); print_number(expr == 111); print_number(expr > 1 && expr >= 2 || 42); print_number(!(expr <= 111) || 1); putchar('\n'); print_number(expr & 1111); putchar('\n'); print_number(expr | 3242); putchar('\n'); print_number(expr ^ 010101); putchar('\n'); }
pedromig/COMP-Project
tests/meta4/input/testes_2.c
double a = 3; int main(void) { int a = 1; int b = 2; int c = 3; int d; d = a + b + c; return 0; } int f1(void) { int a = 1; int b = 2; int c = 3; double d; d = a + b + c; return 0; } int f2(void) { int a = 1; int b = 2; double c = 3; double d; d = a + b + c; return 0; } int f3(void) { double b = 10; double c = 9; double a = b == c < 2; return 0; } int f4(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c == d; return 0; } int f5(void) { int um = 1; double um_ponto = 1.0; int dez = 10; double dez_ponto = 10.0; int a = um != dez; double b = um_ponto != dez_ponto; int c = um <= dez; double d = um_ponto <= dez_ponto; int e = um >= dez; double f = um_ponto >= dez_ponto; int g = um < dez; double h = um_ponto < dez_ponto; int i = um > dez; double j = um_ponto > dez_ponto; return 0; } // // int f6(void){ // int a; // a = (1,2,3,4,5); // return a; // } int f7(void) { int a; a = -1; int b = 1 - -1; double c = -1 + 2; return 0; } int f8(void) { int t = 10; int b = !10; int a = !t; double c = !t; return 0; } int f9(void) { double t = 10; double a = !10; return 0; } int f10(void) { int a = 10; int b = +a; double c = 10.0; double d = +c; return 0; } // // int f11(void){ // int a = !4; // double b = !4.0; // return 0; // } int f12(void) { int a; a = -1; int b = -1 - -1; double c = -1 + 2; return 0; } int f13(void) { int d = 10; int u = 1; int a = u && d; return 0; } int f14(void) { int d = 10; int u = 1; if (u && d) { } return 0; } int f15(void) { double d = 10; double u = 1; // if (u && d) { // d = 2; // } return 0; } int f16(void) { int d = 10; int v = 20; int a = d & v; return 0; } int f17(void) { double d = 10; double v = 20; // double a = d & v; return 0; } int f18(int a, double b) { int i = 1; double d = 2; a = f18(i, d); b = 3; return 0; } int f20(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c == d == b; return 0; } int f21(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c == d == 2; return 0; } //ovelha negra.... int f22(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c == d > 2; return 0; } int f23(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c > d == 2; return 0; } int f24(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c > d > a; return 0; } int f25(void) { int a = 1 == 10; double b = 1 == 10; int c = 2; int d = 3; double e = c == d >= 2; return 0; } int f26(void) { char a = getchar(); int b = putchar(a); return 0; } int f27(void) { int d = 10; int v = 20; int a = d | v; return 0; } int f28(void) { int d = 10; int v = 20; double a = d & v; return 0; } int f29(void) { int d = 10; int v = 20; double a = d & 30; return 0; } int f30(void) { int d = 10; int v = 20; double a = d ^ 30; return 0; } int f31(void) { int a; int u = 1; int d = 10; if (u < d && d > 10) { a = 10; } else { a = 20; } return 0; } int f32(int v) { int u = 1; int d = 10; int a = u < d && d > 10; return 0; } int f33(int v) { int u = 1; int d = 10; int a = u < d && d > 10 && u > 10; return 0; } int f34(void) { int u = 1; int d = 10; int a = u < d || d > 10; return 0; } int f35(void) { int u = 1; int d = 10; int a = u < d || d > 10 || u > 10; return 0; } int f36(void) { int u = 1; int d = 10; int a = u < d && d > 10 || u > 10; return 0; } int f37(void) { int u = 1; int d = 10; double a = u < d && d > 10 || u > 10; return 0; } double aux(int i, double d) { double a = i + d; return 0; } int f38(void) { int i = 1; int d = 2; double l = aux(i, d); return 0; } int f19(int a, double b) { int i = 1; int d = 2; double l = aux(i, d); b = 3; return 0; } int aux1(int i, int d) { int a = i + d; return a; } int f39(void) { int i = 65; int d = 10; int l = aux1(i, d); putchar(l); return 0; } int f40(void) { char a = 'a'; return putchar(a); } int aux2(int i, int d) { return i + d; } int f41(void) { int i = 65; int d = 10; int l = aux2(i, d); putchar(l); return 0; } int aux3(int i, int d) { return i - d; } int f42(void) { int i = 65; int d = 10; aux3(i, d); return 0; } int aux4(void) { return 10; } int f43(void) { int i = 65; int l = aux4() + i + aux4(); putchar(l); return 0; } int f44(void) { int a = 1; int b = 2; if (a < b) { putchar('A'); } else { putchar('B'); } return 0; } int f45(void) { int a = 1; int b = 2; if (a < b) { putchar('A'); a = 'A'; } else { putchar('B'); b = 'B'; } return 0; } int f46(void) { int a = 1; int b = 2; if (a < b) { putchar('A'); } else { } return 0; } int f47(void) { int a = 1; int b = 2; if (a == b) { putchar('A'); } else { putchar('B'); } return 0; } int f48(void) { int i = 0; int aux = 0; while (i < 10) { aux = i % 2; if (aux == 0) { putchar('P'); } else { putchar('I'); } i = i + 1; } putchar('\n'); return 0; } int f49(void) { int i = 0, aux = 0; while (i < 10) { aux = i % 2; if (aux == 0) { putchar('P'); } else { putchar('I'); } i = i + 1; } putchar('\n'); return 0; } int f50(void) { int i = 0, e = 0, aux; while (i < 10) { while (e < 10) { aux = i + 65; putchar(aux); e = e + 1; } putchar('\n'); e = 0; i = i + 1; } } int f51(void) { int a = (10 < 1 && 1 > 10) || 1 == 10; return 0; } int f52(void) { int a = 10 < 1 && (1 > 10 || 1 == 10); return 0; }
pedromig/COMP-Project
src/symbol_table.c
/** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #include "symbol_table.h" #define free_parameter(parameter) free(parameter); symtab_t *symbol_table(const char *id) { symtab_t *table = (symtab_t *)malloc(sizeof(symtab_t)); assert(table != NULL); table->id = id; table->is_defined = false; table->symlist = NULL; table->next = NULL; return table; } sym_t *symbol(const char *id, type_t type, param_t *parameters) { sym_t *symbol = (sym_t *)malloc(sizeof(sym_t)); assert(symbol != NULL); symbol->id = id; symbol->type = type; symbol->parameters = parameters; symbol->is_param = false; symbol->is_defined = false; symbol->next = NULL; return symbol; } param_t *parameter(type_t type) { param_t *parameter = (param_t *)malloc(sizeof(param_t)); assert(parameter != NULL); parameter->type = type; parameter->next = NULL; return parameter; } symtab_t *add_table(symtab_t *list, const char *id) { assert(list != NULL); symtab_t *current = list; while (current->next) { current = current->next; } symtab_t *table = symbol_table(id); current->next = table; return table; } void add_symbol(symtab_t *table, sym_t *sym) { assert(table != NULL); if (!table->symlist) { table->symlist = sym; } else { sym_t *current = table->symlist; while (current->next) { current = current->next; } current->next = sym; } } bool compare_symbol_types(sym_t *s1, sym_t *s2) { if (!strcmp(s1->type, s2->type)) { param_t *param_s1 = s1->parameters, *param_s2 = s2->parameters; while (param_s1 && param_s2) { if (strcmp(param_s1->type, param_s2->type)) return false; param_s1 = param_s1->next; param_s2 = param_s2->next; } return !(param_s1 || param_s2); } return false; } symtab_t *find_table(symtab_t *list, const char *id) { for (symtab_t *current = list; current; current = current->next) { if (!strcmp(current->id, id)) { return current; } } return NULL; } sym_t *find_symbol(sym_t *list, const char *id) { for (sym_t *current = list; current; current = current->next) { if (!strcmp(current->id, id)) { return current; } } return NULL; } void free_symbol(sym_t *symbol) { assert(symbol != NULL); param_t *aux_param = NULL, *param = symbol->parameters; while (param != NULL) { aux_param = param; param = param->next; free_parameter(aux_param); } free(symbol); } void free_symbol_table_list(symtab_t *head) { if (head) { symtab_t *tab_aux = NULL, *tab = head; while (tab != NULL) { sym_t *sym_aux = NULL, *sym = tab->symlist; while (sym != NULL) { sym_aux = sym; sym = sym->next; free_symbol(sym_aux); } tab_aux = tab; tab = tab->next; free(tab_aux); } } } void free_table(symtab_t *head) { if (head) { sym_t *sym_aux = NULL, *sym = head->symlist; while (sym != NULL) { sym_aux = sym; sym = sym->next; free_symbol(sym_aux); } free(head); } } void delete_undefined_tables(symtab_t *list) { symtab_t *before = list, *current = list->next; while (current != NULL) { if (!current->is_defined) { before->next = current->next; free_table(current); current = before->next; } else { before = current; current = current->next; } } } void print_parameter_list(param_t *head) { if (head) { printf("("); printf("%s", head->type); for (param_t *current = head->next; current; current = current->next) { printf(",%s", current->type); } printf(")"); } } void print_symbol_list(sym_t *list) { for (sym_t *current = list; current; current = current->next) { printf("%s\t", current->id); print_symbol_type(current); printf("%s\n", current->is_param ? "\tparam" : ""); } } void print_symbol_type(sym_t *symbol) { printf("%s", symbol->type); print_parameter_list(symbol->parameters); } void print_annotation(annotation_t annotation) { printf("%s", annotation.type); print_parameter_list(annotation.parameters); } void print_table_list(symtab_t *list) { printf("===== %s Symbol Table =====\n", list->id); print_symbol_list(list->symlist); printf("\n"); for (symtab_t *current = list->next; current; current = current->next) { printf("===== Function %s Symbol Table =====\n", current->id); print_symbol_list(current->symlist); printf("\n"); } }
pedromig/COMP-Project
tests/meta4/input/numbers.c
<filename>tests/meta4/input/numbers.c void print_number(int n) { if (n == 0) { putchar('0'); return; } int u = 1; while (n / u) u = u * 10; while (u > 1) { putchar('0' + n / (u / 10) - n / u * 10); u = u / 10; } } int main(void) { int n = 1; while (n <= 100) { print_number(n); putchar('\n'); n = n + 1; } return 0; }
pedromig/COMP-Project
src/codegen.h
/** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #ifndef __CODEGEN_H #define __CODEGEN_H #include <stdio.h> #include <stdlib.h> #include "structures.h" #include "symbol_table.h" #include "utils.h" extern symtab_t *symtab_list; extern symtab_t *current_table; void code_generation(ast_node_t *program); void code_generator(ast_node_t *node, bool is_if); int operator_code_generator(ast_node_t *node, bool logical); void store_code_generator(ast_node_t *node); const char* get_type(ast_node_t* node); int load_terminal(ast_node_t *node); bool is_logical(ast_node_t *node); int logical_operator_code_generator(ast_node_t *node); #endif // __CODEGEN_H
pedromig/COMP-Project
tests/meta4/input/tests.c
int a(void) { int a = 2; return a; } int aa(void) { return 2; } short b(void) { short a; return a; } short bb(void) { return 3; } char c(void) { char a; return a; } char cc(void) { return 'A'; } void d(void) { return; } double e(void) { double d; return d; } double ee(void) { return 1.2; } void f(int a, short b, char c, int d, double e) { return; } char global_char = '\123'; short global_short = 10; int global_int = 14; double global_double = 1.4; char global_a; short global_b; int global_c; double global_d; void g(void) { char a; a = 'A'; short b; b = 2; int c; c = 1; double d; d = 1.2; } void h(void) { char e; e = global_char; short f_to_pay_respects; f_to_pay_respects = global_short; int g; g = global_int; double h; h = global_double; double i; i = global_double; return; } void i(void) { char a; short b; int c; double d; char j; j = a; short l; l = b; int m; m = c; double n; n = d; } void j(void) { global_char = 'B'; global_int = 10; global_short = 12; global_double = 1.3; } void l(void) { char a; short b; int c; double d; global_char = a; global_int = b; global_short = c; global_double = d; } void m(void) { global_char = global_a; global_int = global_b; global_short = global_c; global_double = global_d; } void downcast_store(void) { char a; short b; int c; double d; d = a; d = b; d = c; global_double = global_a; global_double = global_b; global_double = global_c; } int aaa = 12; void downcast_declaration(void) { char a; short b; int c; double d; double d1 = a; double d2 = b; double d3 = c; double d4 = d; } int main(void) { return 0; }
pedromig/COMP-Project
tests/meta4/input/function_calls.c
<reponame>pedromig/COMP-Project<gh_stars>1-10 char a(char x) { return x; } short b(short x) { return x; } int c(int x) { return x; } double d(double x) { return x; } int e(int x, short y) { return x + y + c(12); } double f(double x, char y) { return d(x) + a(y); } double g(double x, double y) { return x * y + b(10); } double h(void) { return g(g(c(1), d(1.7)), f(f(1.6, 'A'), a('X'))); } int main(void) { g(c(1), d(1.7)); g(g(c(1), d(1.7)), f(f(1.6, 'A'), a('X'))); return 0; }
pedromig/COMP-Project
src/semantic_analysis.c
<filename>src/semantic_analysis.c /** * Licenciatura em Engenharia Informática | Faculdade de Ciências e Tecnologia da Universidade de Coimbra * Projeto de Compiladores 2020/2021 * * 2018288117 <NAME> * 2018283166 <NAME> * */ #include "semantic_analysis.h" symtab_t *current_table = NULL; // Helper defines for semantic error print messages #define confliting_types_error(sym1, sym2, line, column) \ printf("Line %d, col %d: Conflicting types (got ", line, column); \ print_symbol_type(sym1); \ printf(", expected "); \ print_symbol_type(sym2); \ printf(")\n"); #define invalid_use_of_void_type_in_declaration(line, column) \ printf("Line %d, col %d: Invalid use of void type in declaration\n", line, column); #define lvalue_required(line, column) \ printf("Line %d, col %d: Lvalue required\n", line, column); #define operator_cannot_be_applied_to_type(token, opp, line, column) \ printf("Line %d, col %d: Operator %s cannot be applied to type ", line, column, token); \ print_annotation(opp); \ printf("\n"); #define operator_cannot_be_applied_to_types(token, lhs, rhs, line, column) \ printf("Line %d, col %d: Operator %s cannot be applied to types ", line, column, token); \ print_annotation(lhs); \ printf(", "); \ print_annotation(rhs); \ printf("\n"); #define symbol_already_defined(token, line, column) \ printf("Line %d, col %d: Symbol %s already defined\n", line, column, token); #define symbol_is_not_a_function(token, line, column) \ printf("Line %d, col %d: Symbol %s is not a function\n", line, column, token); #define unknown_symbol(token, line, column) \ printf("Line %d, col %d: Unknown symbol %s\n", line, column, token); #define wrong_number_of_arguments(token, expected, required, line, column) \ printf("Line %d, col %d: Wrong number of arguments to function %s (got %d, required %d)\n", line, column, token, expected, required); bool has_invalid_void(ast_node_t *param_list) { ast_node_t *current = param_list->first_child; if (!strcmp(current->first_child->id, "Void")) { if (current->first_child->next_sibling) { invalid_use_of_void_type_in_declaration(current->first_child->token.line, current->first_child->token.column); return true; } ast_node_t *last = current; if ((current = current->next_sibling)) { invalid_use_of_void_type_in_declaration(last->first_child->token.line, last->first_child->token.column); return true; } } for (ast_node_t *aux = current; aux; aux = aux->next_sibling) { if (!strcmp(aux->first_child->id, "Void")) { invalid_use_of_void_type_in_declaration(aux->first_child->token.line, aux->first_child->token.column); return true; } } return false; } param_t *parameter_list(ast_node_t *param_list) { param_t *list = NULL; if (has_invalid_void(param_list)) return NULL; int capacity = 10, size = 0; char **ids = (char **)malloc(sizeof(char *) * capacity); list = parameter(decapitalize(param_list->first_child->first_child->id)); if (param_list->first_child->first_child->next_sibling) { ids[size++] = param_list->first_child->first_child->next_sibling->token.value; } param_t *current = list; ast_node_t *node = param_list->first_child->next_sibling; for (ast_node_t *param_decl = node; param_decl; param_decl = param_decl->next_sibling) { if (param_decl->first_child->next_sibling) { bool found = false; if (size > capacity) { capacity += 10; ids = (char **)realloc(ids, sizeof(char *) * capacity); } for (int i = 0; i < size && !found; ++i) { if (!strcmp(ids[i], param_decl->first_child->next_sibling->token.value)) { symbol_already_defined(param_decl->first_child->next_sibling->token.value, param_decl->first_child->next_sibling->token.line, param_decl->first_child->next_sibling->token.column); found = true; } } if (!found) ids[size++] = param_decl->first_child->next_sibling->token.value; } current->next = parameter(decapitalize(param_decl->first_child->id)); current = current->next; } free(ids); return list; } void add_parameter_symbols(symtab_t *table, ast_node_t *param_list) { sym_t *existing = NULL; for (ast_node_t *param_decl = param_list->first_child; param_decl; param_decl = param_decl->next_sibling) { if (!strcmp(param_decl->first_child->id, "Void")) continue; if ((existing = find_symbol(table->symlist, param_decl->first_child->next_sibling->token.value))) continue; sym_t *new = symbol(param_decl->first_child->next_sibling->token.value, decapitalize(param_decl->first_child->id), NULL); new->is_param = true; add_symbol(table, new); } } void analyse_function_definition(ast_node_t *func_def) { ast_node_t *typespec = func_def->first_child; ast_node_t *declarator = typespec->next_sibling; param_t *param_list; if (!(param_list = parameter_list(declarator->next_sibling)) || has_parameters_omitted(declarator->next_sibling)) return; const char *type = decapitalize(typespec->id); sym_t *new_func_dec = symbol(declarator->token.value, type, param_list); symtab_t *table = find_table(symtab_list, declarator->token.value); if (table != NULL) { if (table->is_defined) { symbol_already_defined(declarator->token.value, declarator->token.line, declarator->token.column); free_symbol(new_func_dec); return; } sym_t *existing = find_symbol(symtab_list->symlist, declarator->token.value); if (!compare_symbol_types(existing, new_func_dec)) { confliting_types_error(new_func_dec, existing, declarator->token.line, declarator->token.column); free_symbol(new_func_dec); return; } free_symbol(new_func_dec); } else { sym_t *existing = find_symbol(symtab_list->symlist, declarator->token.value); if (existing) { confliting_types_error(new_func_dec, existing, declarator->token.line, declarator->token.column); free_symbol(new_func_dec); return; } add_symbol(symtab_list, new_func_dec); table = add_table(symtab_list, declarator->token.value); add_symbol(table, symbol("return", type, NULL)); } add_parameter_symbols(table, declarator->next_sibling); table->is_defined = true; // Analyse Function Body current_table = table; semantic_analysis(declarator->next_sibling->next_sibling->first_child); current_table = symtab_list; } void analyse_function_declaration(ast_node_t *func_dec) { ast_node_t *typespec = func_dec->first_child; ast_node_t *declarator = typespec->next_sibling; param_t *param_list; if (!(param_list = parameter_list(declarator->next_sibling))) return; const char *type = decapitalize(typespec->id); sym_t *new_dec = symbol(declarator->token.value, type, param_list); symtab_t *table = find_table(symtab_list, declarator->token.value); if (table != NULL) { sym_t *existing = find_symbol(symtab_list->symlist, declarator->token.value); if (!compare_symbol_types(existing, new_dec)) { confliting_types_error(new_dec, existing, declarator->token.line, declarator->token.column); } free_symbol(new_dec); return; } else { sym_t *existing = find_symbol(symtab_list->symlist, declarator->token.value); if (existing) { confliting_types_error(new_dec, existing, declarator->token.line, declarator->token.column); free_symbol(new_dec); return; } } add_symbol(symtab_list, new_dec); symtab_t *new_table = add_table(symtab_list, declarator->token.value); add_symbol(new_table, symbol("return", type, NULL)); } void analyse_declaration(ast_node_t *node) { ast_node_t *typespec = node->first_child; ast_node_t *declarator = typespec->next_sibling; const char *type = decapitalize(typespec->id); if (!strcmp(type, "void")) { invalid_use_of_void_type_in_declaration(declarator->token.line, declarator->token.column); return; } sym_t *existing = find_symbol(current_table->symlist, declarator->token.value); if (existing != NULL && current_table == symtab_list) { if (existing->is_defined && declarator->next_sibling != NULL) { symbol_already_defined(declarator->token.value, declarator->token.line, declarator->token.column); } else if (declarator->next_sibling != NULL) { semantic_analysis(declarator->next_sibling); if (declarator->next_sibling->annotation.parameters || invalid_assign(type, declarator->next_sibling->annotation.type)) { sym_t aux = (sym_t){.id = NULL, .type = declarator->next_sibling->annotation.type, .parameters = NULL}; confliting_types_error(&aux, existing, declarator->token.line, declarator->token.column); } existing->is_defined = true; } return; } if (existing != NULL) { symbol_already_defined(declarator->token.value, declarator->token.line, declarator->token.column); return; } sym_t *new_dec = symbol(declarator->token.value, type, NULL); add_symbol(current_table, new_dec); if (declarator->next_sibling != NULL) { semantic_analysis(declarator->next_sibling); if (declarator->next_sibling->annotation.parameters || invalid_assign(type, declarator->next_sibling->annotation.type)) { sym_t aux = (sym_t){.id = NULL, .type = declarator->next_sibling->annotation.type, .parameters = NULL}; confliting_types_error(&aux, new_dec, declarator->token.line, declarator->token.column); return; } new_dec->is_defined = true; } } void annotate_store(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (rhs->annotation.parameters) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (lhs->annotation.parameters) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (!strcmp(lhs->id, "Id")) { if (!strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (invalid_assign(lhs->annotation.type, rhs->annotation.type)) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); } node->annotation.type = lhs->annotation.type; } else { lvalue_required(lhs->token.line, lhs->token.column); node->annotation.type = lhs->annotation.type; } } void annotate_call(ast_node_t *node) { ast_node_t *func_id = node->first_child; sym_t *existing = find_symbol(current_table->symlist, func_id->token.value); if (!existing) { existing = (current_table != symtab_list) ? find_symbol(symtab_list->symlist, func_id->token.value) : NULL; if (!existing) { symbol_is_not_a_function(func_id->token.value, func_id->token.line, func_id->token.column); node->annotation.type = "undef"; return; } } if (!existing->parameters) { symbol_is_not_a_function(func_id->token.value, func_id->token.line, func_id->token.column); node->annotation.type = "undef"; return; } int func_params = 0; param_t *aux_1 = existing->parameters; while (aux_1 != NULL) { if (!strcmp(aux_1->type, "void")) break; ++func_params; aux_1 = aux_1->next; } int call_params = 0; ast_node_t *aux_2 = func_id->next_sibling; while (aux_2 != NULL) { ++call_params; aux_2 = aux_2->next_sibling; } if (call_params == func_params) { aux_1 = existing->parameters; aux_2 = func_id->next_sibling; while (aux_1 != NULL && aux_2 != NULL) { if (invalid_assign(aux_1->type, aux_2->annotation.type)) { sym_t aux1 = (sym_t){.id = NULL, .type = aux_1->type, .parameters = NULL}; sym_t aux2 = (sym_t){.id = NULL, .type = aux_2->annotation.type, .parameters = NULL}; confliting_types_error(&aux2, &aux1, aux_2->token.line, aux_2->token.column); } aux_1 = aux_1->next; aux_2 = aux_2->next_sibling; } } if (func_params != call_params || (!strcmp(existing->parameters->type, "void") && call_params != 0)) { wrong_number_of_arguments(func_id->token.value, call_params, func_params, func_id->token.line, func_id->token.column); } node->annotation.type = existing->type; } void annotate_statement_id(ast_node_t *node) { ast_node_t *expr = node->first_child; if (expr->annotation.parameters || !strcmp(expr->annotation.type, "undef") || !strcmp(expr->annotation.type, "void") || !strcmp(expr->annotation.type, "double")) { sym_t aux1 = (sym_t){.id = NULL, .type = expr->annotation.type, .parameters = expr->annotation.parameters}; sym_t aux2 = (sym_t){.id = NULL, .type = "int", .parameters = NULL}; confliting_types_error(&aux1, &aux2, expr->token.line, expr->token.column); } } void annotate_return(ast_node_t *node) { ast_node_t *expr_list = node->first_child; sym_t *function_return = current_table->symlist; if (!strcmp(function_return->type, "void")) { if (expr_list->annotation.parameters) { sym_t aux = (sym_t){.id = NULL, .type = expr_list->annotation.type, .parameters = expr_list->annotation.parameters}; confliting_types_error(&aux, function_return, node->token.line, node->token.column); return; } if (expr_list->annotation.type && !strcmp(expr_list->annotation.type, "void")) { return; } if (strcmp(expr_list->id, "Null")) { sym_t aux = (sym_t){.id = NULL, .type = expr_list->annotation.type, .parameters = expr_list->annotation.parameters}; confliting_types_error(&aux, function_return, node->token.line, node->token.column); return; } } else { if (!strcmp(expr_list->id, "Null")) { sym_t aux = (sym_t){.id = NULL, .type = "void", .parameters = expr_list->annotation.parameters}; confliting_types_error(&aux, function_return, node->token.line, node->token.column); return; } if (invalid_assign(current_table->symlist->type, expr_list->annotation.type)) { sym_t aux1 = (sym_t){.id = NULL, .type = expr_list->annotation.type, .parameters = expr_list->annotation.parameters}; confliting_types_error(&aux1, current_table->symlist, node->token.line, node->token.column); } } } void annotate_comma(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (lhs->annotation.parameters || rhs->annotation.parameters) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (!strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } node->annotation.type = rhs->annotation.type; } void annotate_id(ast_node_t *node) { sym_t *existing = find_symbol(current_table->symlist, node->token.value); if (!existing) { existing = (current_table != symtab_list) ? find_symbol(symtab_list->symlist, node->token.value) : NULL; if (!existing) { unknown_symbol(node->token.value, node->token.line, node->token.column); node->annotation.type = "undef"; return; } } node->annotation.type = existing->type; node->annotation.parameters = existing->parameters; } void annotate_arithmetic_operators(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; bool is_mod_operator = false; if (!strcmp(node->id, "Mod")) { is_mod_operator = true; if (!strcmp(lhs->annotation.type, "double") || !strcmp(rhs->annotation.type, "double") || !strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef") || !strcmp(lhs->annotation.type, "void") || !strcmp(rhs->annotation.type, "void")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); } node->annotation.type = "int"; return; } if (lhs->annotation.parameters || rhs->annotation.parameters) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (!strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef") || !strcmp(lhs->annotation.type, "void") || !strcmp(rhs->annotation.type, "void")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } node->annotation.type = !is_mod_operator ? implicit_conversion(lhs->annotation.type, rhs->annotation.type) : "int"; } void annotate_unary_operators(ast_node_t *node) { ast_node_t *operand = node->first_child; if (!strcmp(node->id, "Not")) { if (operand->annotation.parameters || !strcmp(operand->annotation.type, "double") || !strcmp(operand->annotation.type, "undef") || !strcmp(operand->annotation.type, "void")) { operator_cannot_be_applied_to_type(select_operator(node->id), operand->annotation, node->token.line, node->token.column); } node->annotation.type = "int"; return; } if (operand->annotation.parameters) { operator_cannot_be_applied_to_type(select_operator(node->id), operand->annotation, node->token.line, node->token.column); node->annotation.type = "undef"; return; } if (!strcmp(operand->annotation.type, "undef") || !strcmp(operand->annotation.type, "void")) { operator_cannot_be_applied_to_type(select_operator(node->id), operand->annotation, node->token.line, node->token.column); node->annotation.type = operand->annotation.type; return; } node->annotation.type = operand->annotation.type; } void annotate_bitwise_operators(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (lhs->annotation.parameters || rhs->annotation.parameters || !strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef") || !strcmp(lhs->annotation.type, "void") || !strcmp(rhs->annotation.type, "void") || !strcmp(lhs->annotation.type, "double") || !strcmp(rhs->annotation.type, "double")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); } node->annotation.type = "int"; } void annotate_relational_operators(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (lhs->annotation.parameters || rhs->annotation.parameters || !strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef") || !strcmp(lhs->annotation.type, "void") || !strcmp(rhs->annotation.type, "void")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); } node->annotation.type = "int"; } void annotate_logical_operators(ast_node_t *node) { ast_node_t *lhs = node->first_child; ast_node_t *rhs = lhs->next_sibling; if (lhs->annotation.parameters || rhs->annotation.parameters || !strcmp(lhs->annotation.type, "undef") || !strcmp(rhs->annotation.type, "undef") || !strcmp(lhs->annotation.type, "void") || !strcmp(rhs->annotation.type, "void") || !strcmp(lhs->annotation.type, "double") || !strcmp(rhs->annotation.type, "double")) { operator_cannot_be_applied_to_types(select_operator(node->id), lhs->annotation, rhs->annotation, node->token.line, node->token.column); } node->annotation.type = "int"; } void semantic_analysis(ast_node_t *node) { if (!node) return; // Symbol Table Construction Core Section if (!strcmp(node->id, "Program")) { current_table = symtab_list = symbol_table("Global"); symtab_list->is_defined = true; add_symbol(symtab_list, symbol("putchar", "int", parameter("int"))); add_symbol(symtab_list, symbol("getchar", "int", parameter("void"))); semantic_analysis(node->first_child); delete_undefined_tables(symtab_list); return; } if (!strcmp(node->id, "FuncDefinition")) { analyse_function_definition(node); } if (!strcmp(node->id, "FuncDeclaration")) { analyse_function_declaration(node); } if (!strcmp(node->id, "Declaration")) { analyse_declaration(node); } // Symbol/AST Annotations and Error Checking Section if (is_arithmetic_operator(node->id)) { semantic_analysis(node->first_child); annotate_arithmetic_operators(node); } if (is_unary_operator(node->id)) { semantic_analysis(node->first_child); annotate_unary_operators(node); } if (is_relational_operator(node->id)) { semantic_analysis(node->first_child); annotate_relational_operators(node); } if (is_bitwise_operator(node->id)) { semantic_analysis(node->first_child); annotate_bitwise_operators(node); } if (is_logical_operator(node->id)) { semantic_analysis(node->first_child); annotate_logical_operators(node); } if (is_statement_id(node->id)) { semantic_analysis(node->first_child); annotate_statement_id(node); } if (!strcmp(node->id, "Call")) { semantic_analysis(node->first_child); annotate_call(node); } if (!strcmp(node->id, "Store")) { semantic_analysis(node->first_child); annotate_store(node); } if (!strcmp(node->id, "Return")) { semantic_analysis(node->first_child); annotate_return(node); } if (!strcmp(node->id, "Comma")) { semantic_analysis(node->first_child); annotate_comma(node); } if (!strcmp(node->id, "StatList")) { semantic_analysis(node->first_child); } if (!strcmp(node->id, "IntLit")) { node->annotation.type = "int"; } if (!strcmp(node->id, "ChrLit")) { node->annotation.type = "int"; } if (!strcmp(node->id, "RealLit")) { node->annotation.type = "double"; } if (!strcmp(node->id, "Id")) { annotate_id(node); } if (node->next_sibling != NULL) { semantic_analysis(node->next_sibling); } }
pedromig/COMP-Project
tests/meta3/input/smallTestB.c
<filename>tests/meta3/input/smallTestB.c int func(int); int func(char); int funcA(int a); int funcA(void); int funcA(void); int funcB(void,int a);
pedromig/COMP-Project
tests/meta3/input/testes2.c
int f1(void, int a){ return 0; } void f2(void){ //algo } int a; int main(void){ if(a == f2()){ } if(a == f2(33)){ } }
pedromig/COMP-Project
tests/meta1/input/illegalchar.c
<>qwertyuiopásdfghjklç~\zxcvbnm,.-______j!"#$%&/(==?*´\~@ || |char elsewhileifshort inT intdoublereturnvoid^&&<=>= { [#}!=++-- int double return void short while else \tolelele /*lll kkk*/? wtf//gefggt #
pedromig/COMP-Project
tests/meta4/input/comma_expr.c
<reponame>pedromig/COMP-Project<filename>tests/meta4/input/comma_expr.c char f1(void) { return 'A'; } char f2(void) { return 'B'; } short f3(void) { return 1; } short f4(void) { return 2; } int f5(void) { return 1; } int f6(void) { return 2; } double f7(void) { return 1.0; } double f8(void) { return 2.0; } int comma_expr_tests(void) { int a = 1, b = 2, x = 3; if ((a = 1, x = 2)) ; if ((5, 10)) ; if ((f1(), f2())) ; if (a, x) ; if ((a = 2, b = 4)) ; if (((f1(), a = 2, x = f2(), b = 3, 1))) ; while ((a = 1, x = 2)) ; while ((5, 10)) ; while ((f1(), f2())) ; while (a, x) ; while ((a = 2, b = 4)) ; while (((f1(), a = 2, x = f2(), b = 3, 1))) ; return 0; } char comma_char_tests(void) { char a = 1, x = 2; putchar(a); putchar(x); char b = (5, 10); putchar(b); char c = (f1(), f2()); putchar(c); char d = (a, b); putchar(a); putchar(b); putchar(d); char e = (a = 2, b = 4); putchar(a); putchar(b); putchar(e); char f = (f1(), a = 2, x = f2(), b, 3); putchar(f); putchar(a); putchar(b); putchar(x); return (a, f1(), c, a = 2, 10); } short comma_short_tests(void) { short a = 1, x = 2; putchar(a); putchar(x); short b = (5, 10); putchar(b); short c = (f3(), f4()); putchar(c); short d = (a, b); putchar(a); putchar(b); putchar(d); short e = (a = 2, b = 4); putchar(a); putchar(b); putchar(e); short f = (f3(), a = 2, x = f4(), b, 3); putchar(f); putchar(a); putchar(b); putchar(x); return (a, f3(), c, a = 2, 10); } int comma_int_tests(void) { int a = 1, x = 2; putchar(a); putchar(x); int b = (5, 10); putchar(b); int c = (f5(), f6()); putchar(c); int d = (a, b); putchar(a); putchar(b); putchar(d); int e = (a = 2, b = 4); putchar(a); putchar(b); putchar(e); int f = (f5(), a = 2, x = f6(), b, 3); putchar(f); putchar(a); putchar(b); putchar(x); return (a, f5(), c, a = 2, 10); } double comma_double_tests(void) { double a = 1, x = 2; double b = (5.0, 10.0); double c = (f7(), f8()); double d = (a, b); double e = (a = 2.1, b = 4.0); double f = (f7(), a = 2, x = f8(), b, 3.2); return (a, f7(), c, a = 2.0, 10.102); } int main(void) { double a = 1.2e19; double x = 0.0e20; //putchar(comma_expr_tests()); putchar(comma_char_tests()); putchar(comma_short_tests()); putchar(comma_int_tests()); }
pedromig/COMP-Project
tests/meta4/input/operators.c
<gh_stars>1-10 char aa(char a) { return a; } short bb(short b) { return b; } int cc(int c) { return c; } double dd(double d) { return d; } int arithmetic(double a, double b, double c) { double d = 1.2; d = a + b; d = a - b; d = a / b; d = a * b; d = a + b + c; d = a - b - c; d = a / b / c; d = a * b * c; d = a - b + c; d = a + b - c; d = a * b / c; d = a / b * c; } int arithmetic1(int a, int b, int c) { double d = 1.3; d = a + b; d = a - b; d = a / b; d = a * b; d = a + b + c; d = a - b - c; d = a / b / c; d = a * b * c; d = a - b + c; d = a + b - c; d = a * b / c; d = a / b * c; } int arithmetic2(int a, int b, int c) { int d = 12; d = a + b; d = a - b; d = a / b; d = a * b; d = a + b + c; d = a - b - c; d = a / b / c; d = a * b * c; d = a - b + c; d = a + b - c; d = a * b / c; d = a / b * c; if (a + b) ; if (a - b) ; if (a / b) ; if (a * b) ; if (d = a + b) ; if (d = a - b) ; if (d = a * b) ; if (d = a / b) ; while (a + b) ; while (a - b) ; while (a / b) ; while (a * b) ; while (d = a + b) ; while (d = a - b) ; while (d = a * b) ; while (d = a / b) ; } int arithmetic3(void) { int a = 1, b = 2; double c = 1.41, d = 151.2; c = d + c; c = c + c; a = b + a; a = a + a; a = a + '\010'; a = b + '\'' + '\102'; double x = a + b + c + d; x = x + a; x = x * d * a; double y = c * c + a + c * d; if (a == (y = a)) { if (a + d != arithmetic3() + arithmetic3()) { } else { while (1) { } } } else { while (1) { if (1) { } else { } } } if (putchar('\00')) ; if (0 + b != 0 + d) { a = a + a; if (0 + b == 0 + d) { c = c + c; } else { c = c + c; } } else { a = a + 1; } return !!a; } int just_adds(char a, char b, short c, short d, int e, int f, double g, double h) { a = a + a; putchar(a); a = a + b; putchar(a); b = a + b; putchar(b); b = b + b; putchar(b); a = a + c; putchar(a); a = a + d; putchar(a); a = a + e; putchar(a); a = a + f; putchar(a); c = c + a; putchar(c); d = a + b; putchar(d); e = c + a; putchar(e); g = a + a; g = c + a; g = a + e; h = a + h; h = h + h; g = d + e; a = aa(a) + bb(b); putchar(a); b = cc(e) + aa(a); putchar(b); a = bb(c) + cc(e); putchar(a); a = aa(aa(a) + aa(a)) + bb(b) + cc(a); putchar(a); if (a + b) { if (b + c) { if (a + c) { if (a + d + e) { return aa(a); } return bb(b); } return cc(c); } return '\123'; } if ((a = (a + b))) ; putchar(a); if ((a = (e + c))) ; putchar(a); if ((a = ((a == b) + (e <= g)))) ; putchar(a); if ((b = (b != a + a))) ; putchar(b); if ((c = (a + b))) ; putchar(c); if ((e = (c + d))) ; putchar(e); while ((e = (g != h))) ; putchar(a); while ((a = (a + b))) ; putchar(a); while ((a = (e + c))) ; putchar(a); while ((a = ((a == b) + (e <= g)))) ; putchar(a); while ((b = (b != a + a))) ; putchar(b); while ((c = (a + b))) ; putchar(c); while ((e = (c + d))) ; return '\''; } int relational(double a, double b) { if (a == b) ; if (a > b) ; if (a < b) ; if (a >= b) ; if (a <= b) ; if (a != b) ; while (a == b) ; while (a > b) ; while (a < b) ; while (a >= b) ; while (a <= b) ; while (a != b) ; return 0; } int relational2(int a, int b) { if (a == b) ; if (a > b) ; if (a < b) ; if (a >= b) ; if (a <= b) ; if (a != b) ; while (a == b) ; while (a > b) ; while (a < b) ; while (a >= b) ; while (a <= b) ; while (a != b) ; return 0; } int relational3(double a, double b, double c) { if (a == b == c) ; if (a > b > c) ; if (a < b < c) ; if ((a >= b) >= c) ; if (a <= (b <= c)) ; if (a != (b != c)) ; while (a == b == c) ; while (a > b > c) ; while (a < b < c) ; while ((a >= b) >= c) ; while (a <= (b <= c)) ; while (a != (b != c)) ; return 0; } int relational4(int a, int b, int c) { if (a == b == c) ; if (a > b > c) ; if (a < b < c) ; if ((a >= b) >= c) ; if (a <= (b <= c)) ; if (a != (b != c)) ; while (a == b == c) ; while (a > b > c) ; while (a < b < c) ; while ((a >= b) >= c) ; while (a <= (b <= c)) ; while (a != (b != c)) ; return 0; } int relational5(int a, double b, int c) { if (a == b == c) ; if (a > b > c) ; if (a < b < c) ; if ((a >= b) >= c) ; if (a <= (b <= c)) ; if (a != (b != c)) ; while (a == b == c) ; while (a > b > c) ; while (a < b < c) ; while ((a >= b) >= c) ; while (a <= (b <= c)) ; while (a != (b != c)) ; return 0; } int relational6(double a, double b, double c) { if (a == b == c) ; if (a > b > c) ; if (a < b < c) ; if ((a >= b) >= c) ; if (a <= (b <= c)) ; if (a != (b != c)) ; while (a == b == c) ; while (a > b > c) ; while (a < b < c) ; while ((a >= b) >= c) ; while (a <= (b <= c)) ; while (a != (b != c)) ; return 0; } int main(void) { return 0; }
Andrew-Dev/SignInManager
SignInManager/ViewController.h
<reponame>Andrew-Dev/SignInManager // // ViewController.h // SignInManager // // Created by Andrew on 9/24/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "BCScanner/BCScannerViewController.h" #import "ClockViewController.h" #import "Student.h" #import "SessionReportViewController.h" @interface ViewController : UIViewController <BCScannerViewControllerDelegate, UIContentContainer,UIAlertViewDelegate,UITextFieldDelegate> { __weak IBOutlet UIView *CameraContainer; BOOL scanning; NSString * code; Session * sessionToReport; } @end
Andrew-Dev/SignInManager
SignInManager/ClockViewController.h
// // ClockViewController.h // SignInManager // // Created by Andrew on 9/28/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "Student.h" #import "Session.h" @interface ClockViewController : UIViewController { IBOutlet UILabel * welcomeLabel; IBOutlet UILabel * idLabel; IBOutlet UILabel * nameLabel; IBOutlet UILabel * timeLabel; } @property (weak) NSString * student; @end
Andrew-Dev/SignInManager
SignInManager/Session.h
// // Session.h // SignInManager // // Created by Andrew on 9/30/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <Foundation/Foundation.h> #import "StudentSession.h" @interface Session : NSObject { NSDate * startTime; NSDate * endTime; } -(NSMutableArray*)getAllSessionsForStudentAsData:(NSString*)studentId; +(NSMutableArray*)getAllSessionsForStudentAsData:(NSString*)studentId; -(NSMutableArray*)getAllStudentSessionsFromThisSessionAsDataObjectsAsData; +(NSMutableArray*)getAllStudentSessionsInAllSessionsForStudentAsDataInOneHugeAssArray:(NSString*)studentId; +(NSMutableArray*)getAllSessions; +(Session*)getSessionThatHasStudentSession:(StudentSession*)studentSession; -(NSMutableArray*)getUnclockedStudents; -(NSString*)getSessionTimeString; -(void)start; -(void)stop; @property NSMutableArray * studentSessions; @property NSString * title; @end
Andrew-Dev/SignInManager
SessionReportViewController.h
<reponame>Andrew-Dev/SignInManager<filename>SessionReportViewController.h // // SessionReportViewController.h // SignInManager // // Created by Andrew on 10/9/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "Session.h" #import "Student.h" @interface SessionReportViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> { IBOutlet UILabel * titleLabel; IBOutlet UILabel * timeLabel; IBOutlet UILabel * studentStatsLabel; IBOutlet UITableView * attendanceTable; } @property Session * session; @end
Andrew-Dev/SignInManager
SignInManager/SessionsViewController.h
// // SessionsViewController.h // SignInManager // // Created by Andrew on 10/21/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "Session.h" #import "SessionReportViewController.h" @interface SessionsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> { IBOutlet UITableView * sessionList; Session * sessionToView; } @end
Andrew-Dev/SignInManager
SignInManager/ConfigViewController.h
<reponame>Andrew-Dev/SignInManager<gh_stars>0 // // ConfigViewController.h // SignInManager // // Created by Andrew on 2/2/15. // Copyright (c) 2015 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface ConfigViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> @end
Andrew-Dev/SignInManager
SignInManager/Student.h
<gh_stars>0 // // Student.h // SignInManager // // Created by Andrew on 9/24/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <Foundation/Foundation.h> #import "Session.h" @interface Student : NSObject @property NSString * code; @property NSString * name; +(NSMutableArray*)getAllStudents; +(Student*)getStudentFromCode:(NSString*)code; -(NSString*)getStudentHoursTotalAsString; -(Session*)getLastSessionAttended; @end
Andrew-Dev/SignInManager
SignInManager/BCScanner/BCScannerViewController.h
<reponame>Andrew-Dev/SignInManager // // BCScannerViewController.h // BCScannerViewController // // Copyright 2013 bitecode, <NAME> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> #import "Session.h" extern NSString *const BCScannerQRCode; /// The code type used for QR codes. extern NSString *const BCScannerUPCECode; extern NSString *const BCScannerCode39Code; //extern NSString *const BCScannerCode39Mod43Code; extern NSString *const BCScannerEAN13Code; extern NSString *const BCScannerEAN8Code; //extern NSString *const BCScannerCode93Code; //extern NSString *const BCScannerCode128Code; //extern NSString *const BCScannerPDF417Code; //extern NSString *const BCScannerAztecCode; @protocol BCScannerViewControllerDelegate; /** * BCScannerViewController is a view controller that wrapps the scanning capabilities * of iOS7 into a simple to use drop-in view controller for easy integration into your app. * * It is build for the purpose of scanning a single or multiple codes in a deticated screen * and encapsules all the camera handling and metadata gathering. * * The view controller can be presented or pushed onto a navigation stack. It is up to you * to present and dismiss the view controller whenever you need it. */ @interface BCScannerViewController : UIViewController <UIAlertViewDelegate> @property BOOL scanningForNewStudents; /** * This method lets you check for the availability of the native scanner functionality * provided by AVFoundation. * * @note Do not instanciate this class if this method returns NO! * * @return YES if native scanning is available, NO otherwise. */ + (BOOL)scannerAvailable; /** * This is the delegate of the scanner. The delegate will get called to notify you about * codes that were found in the field of view of the camera. */ @property (nonatomic, weak, readwrite) id<BCScannerViewControllerDelegate> delegate; /** * This is an array of the codes the scanner should look for. The more code types you * specify, the longer the image analysis will take! * * @see BCScannerCode constants */ @property (nonatomic, strong, readwrite) NSArray *codeTypes; /** * This is the gesture recognizer that is used to let the user focus and expose to a * specific point in the field of view. You can access this property when you want to * more precisely control what taps should be recognized. */ @property (nonatomic, weak, readonly) UITapGestureRecognizer *focusAndExposeGestureRecognizer; /** * Defines the video preview torch mode. */ @property (nonatomic, assign, readwrite, getter = isTorchEnabled) BOOL torchEnabled; /** * Hides or displays the torch button in the navigation bar. * The default value is YES. */ @property (nonatomic, assign, readwrite, getter = isTorchButtonEnabled) BOOL torchButtonEnabled; /** * Indicates if the torch mode is available. Varies depending on the device. */ @property (nonatomic, assign, readonly, getter = isTorchModeAvailable) BOOL torchModeAvailable; @end @protocol BCScannerViewControllerDelegate <NSObject> @optional /** * This method is called whenever a new code enters the field of view. * * @param scanner The scanner that is calling this delegate * @param codes A list of all the codes that entered the FOV in this interval * * @note If you do a simple scan for the first code you find, you can get the code * from this method and close the scanner afterwards. */ - (void)scanner:(BCScannerViewController *)scanner codesDidEnterFOV:(NSSet *)codes; //- (void)scanner:(BCScannerViewController *)scanner codesDidUpdate:(NSSet *)codes; /** * This method is called whenever an existing code leaves the field of view. * * @param scanner The scanner that is calling this delegate * @param codes A list of all the codes that left the FOV in this interval */ - (void)scanner:(BCScannerViewController *)scanner codesDidLeaveFOV:(NSSet *)codes; /** * This method lets you specify an image that is shown as an overlay to give the user * some feedback about how to hold the camera. * * This method is called when the scanner configures its interface. * * @param scanner The scanner that is calling this delegate * @return The image you want to be used as HUD */ - (UIImage *)scannerHUDImage:(BCScannerViewController *)scanner; @end
Andrew-Dev/SignInManager
StudentReportsListViewController.h
// // StudentReportsListViewController.h // SignInManager // // Created by Andrew on 10/23/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "Student.h" #import "Session.h" #import "StudentReportViewController.h" @interface StudentReportsListViewController : UIViewController { IBOutlet UITableView * studentListView; Student * selectedStudent; } @end
Andrew-Dev/SignInManager
SignInManager/StudentReportViewController.h
// // StudentReportViewController.h // SignInManager // // Created by Andrew on 10/23/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <UIKit/UIKit.h> #import "Student.h" #import "Session.h" @interface StudentReportViewController : UIViewController { IBOutlet UILabel * studentLabel; IBOutlet UILabel * hoursLabel; IBOutlet UILabel * sessionStatsLabel; IBOutlet UITableView * sessionsTable; } @property Student * student; @end
Andrew-Dev/SignInManager
SignInManager/BCScanner/UIViewController+BCScanner.h
<reponame>Andrew-Dev/SignInManager // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class BCScannerViewController; @interface UIViewController (BCScanner) /** Present a scanner view controller. The scanner is dismissed as soon as the first code of one of the desired types is found. @note The completionHandler is only called if a code is found. If the user cancelled the scanner, no completion handler is called! @param codeTypes An array of all code types that should be scanned for @param completionHandler The completion handler that is called when a code is found @return The created view controller. You can configure this view controller. */ - (BCScannerViewController *)bcscanner_presentScannerWithCodeTypes:(NSArray *)codeTypes completionHandler:(void(^)(NSString *code))completionHandler; @end
Andrew-Dev/SignInManager
SignInManager/StudentSession.h
// // StudentSession.h // SignInManager // // Created by Andrew on 10/7/14. // Copyright (c) 2014 <NAME>. Licensed under the MIT license. // #import <Foundation/Foundation.h> @interface StudentSession : NSObject { } @property NSString * stucode; @property NSDate * inTime; @property NSDate * outTime; @end
matrixs/Utility
Example/HCBNetwork/matrixsAppDelegate.h
// // matrixsAppDelegate.h // HCBNetwork // // Created by matrixs on 12/20/2016. // Copyright (c) 2016 matrixs. All rights reserved. // @import UIKit; @interface matrixsAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
matrixs/Utility
Example/Pods/Target Support Files/Pods-HCBNetwork_Example/Pods-HCBNetwork_Example-umbrella.h
#ifdef __OBJC__ #import <UIKit/UIKit.h> #endif FOUNDATION_EXPORT double Pods_HCBNetwork_ExampleVersionNumber; FOUNDATION_EXPORT const unsigned char Pods_HCBNetwork_ExampleVersionString[];
matrixs/Utility
Example/HCBNetwork/matrixsViewController.h
<gh_stars>0 // // matrixsViewController.h // HCBNetwork // // Created by matrixs on 12/20/2016. // Copyright (c) 2016 matrixs. All rights reserved. // @import UIKit; @interface matrixsViewController : UIViewController @end
matrixs/Utility
Example/Pods/Target Support Files/HCBNetwork/HCBNetwork-umbrella.h
#ifdef __OBJC__ #import <UIKit/UIKit.h> #endif FOUNDATION_EXPORT double HCBNetworkVersionNumber; FOUNDATION_EXPORT const unsigned char HCBNetworkVersionString[];
matrixs/Utility
Example/Pods/Target Support Files/Pods-HCBNetwork_Tests/Pods-HCBNetwork_Tests-umbrella.h
<reponame>matrixs/Utility #ifdef __OBJC__ #import <UIKit/UIKit.h> #endif FOUNDATION_EXPORT double Pods_HCBNetwork_TestsVersionNumber; FOUNDATION_EXPORT const unsigned char Pods_HCBNetwork_TestsVersionString[];
davemers0160/Ouster
include/os1_991838000603.h
#ifndef _OS1_991838000603_H #define _OS1_991838000603_H #include <cstdint> #include <cmath> #include "os1_packet.h" const double beam_altitude_angles[ouster::OS1::pixels_per_column] = { 16.44860000, 15.86160000, 15.29380000, 14.75480000, 14.28190000, 13.70870000, 13.15370000, 12.59980000, 12.15560000, 11.57710000, 11.03090000, 10.48820000, 10.06170000, 9.49518000, 8.94306000, 8.41130000, 7.95626000, 7.41189000, 6.86564000, 6.31993000, 5.87780000, 5.32165000, 4.79088000, 4.24136000, 3.80334000, 3.25466000, 2.71504000, 2.17245000, 1.71299000, 1.17244000, 0.63153400, 0.09325730, -0.36198100, -0.90280000, -1.52134000, -1.99457000, -2.43217000, -2.97807000, -3.52476000, -4.07447000, -4.52890000, -5.06902000, -5.60688000, -6.16850000, -6.61741000, -7.15968000, -7.70244000, -8.26022000, -8.70824000, -9.25208000, -9.79432000, -10.35190000, -10.81520000, -11.35280000, -11.90410000, -12.47790000, -12.94010000, -13.48020000, -14.04180000, -14.62450000, -15.11550000, -15.65890000, -16.22400000, -16.82940000, }; const double beam_azimuth_angles[ouster::OS1::pixels_per_column] = { 3.06506000, 0.90587900, -1.24426000, -3.35551000, 3.04115000, 0.91443500, -1.20081000, -3.29919000, 3.04136000, 0.91682000, -1.18011000, -3.25555000, 3.03578000, 0.94344600, -1.14525000, -3.22680000, 3.04724000, 0.96425800, -1.10994000, -3.18478000, 3.07646000, 0.98644200, -1.08256000, -3.15037000, 3.08081000, 1.00996000, -1.06679000, -3.12131000, 3.09475000, 1.02968000, -1.02889000, -3.10155000, 3.11778000, 1.04717000, -1.07923000, -3.08057000, 3.14335000, 1.07253000, -0.99474300, -3.06283000, 3.18780000, 1.10767000, -0.96872200, -3.04399000, 3.21864000, 1.14071000, -0.94662500, -3.02730000, 3.24957000, 1.16120000, -0.91827900, -3.01797000, 3.29649000, 1.20036000, -0.90168500, -3.01612000, 3.35766000, 1.24051000, -0.87825700, -3.01890000, 3.42220000, 1.28708000, -0.85363600, -3.01873000, }; const int32_t beam_azimuth_index[ouster::OS1::pixels_per_column] = { 17, 5, -7, -19, 17, 5, -7, -19, 17, 5, -7, -19, 17, 5, -7, -18, 17, 5, -6, -18, 18, 6, -6, -18, 18, 6, -6, -18, 18, 6, -6, -18, 18, 6, -6, -18, 18, 6, -6, -17, 18, 6, -6, -17, 18, 6, -5, -17, 18, 7, -5, -17, 19, 7, -5, -17, 19, 7, -5, -17, 19, 7, -5, -17, }; const double lidar_intrinsics[] = {-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 36.18, 0, 0, 0, 1}; static bool init_trig_table(std::vector<ouster::OS1::trig_table_entry> &trig_table) { double m_pi_180 = (double)M_PI / 180.0; trig_table.clear(); for (uint32_t idx = 0; idx < ouster::OS1::pixels_per_column; ++idx) { trig_table.push_back({ sin(beam_altitude_angles[idx] * m_pi_180), cos(beam_altitude_angles[idx] * m_pi_180), beam_azimuth_angles[idx] * m_pi_180 }); } return true; } #endif //_OS1_991838000603_H
fifoforlifo/pynja
test2/code/a/a0/include/a0.h
<gh_stars>0 #pragma once int a0_0(); int a0_1();
fifoforlifo/pynja
test2/code/dllexport/include/dllexport.h
#pragma once #ifdef _WIN32 #define DLL_EXPORT_11 __declspec(dllexport) #define DLL_EXPORT_10 __declspec(dllimport) #define DLL_EXPORT_00 #define DLL_LOCAL_11 #define DLL_LOCAL_10 #define DLL_LOCAL_00 #else #define DLL_EXPORT_11 __attribute__((visibility("default"))) #define DLL_EXPORT_10 __attribute__((visibility("default"))) #define DLL_EXPORT_00 #define DLL_LOCAL_1 __attribute__((visibility("hidden"))) #define DLL_LOCAL_0 #endif #define DLL_EXPORT_SE_I(isLibShared_, isExport_) DLL_EXPORT_ ## isLibShared_ ## isExport_ #define DLL_EXPORT_SE(isLibShared_, isExport_) DLL_EXPORT_SE_I(isLibShared_, isExport_) #define DLL_EXPORT(name_) DLL_EXPORT_SE(name_ ## _SHARED, name_ ## _EXPORT) #define DLL_LOCAL_SE_I(isLibShared_) DLL_LOCAL_ ## isLibShared_ #define DLL_LOCAL_SE(isLibShared_) DLL_LOCAL_SE_I(isLibShared_) #define DLL_LOCAL(name) DLL_LOCAL_SE(name_ ## _SHARED)
fifoforlifo/pynja
test2/code/qt0/include/qbaz.h
<reponame>fifoforlifo/pynja #ifndef qbaz_h #define qbaz_h #include <QtCore/QObject> class QBaz : public QObject { Q_OBJECT public: QBaz(); }; #endif
fifoforlifo/pynja
test2/code/a/a1/include/a1.h
#pragma once #include <dllexport.h> DLL_EXPORT(a1) int a1_0();
fifoforlifo/pynja
test2/code/qt0/source/qfizzle.h
<filename>test2/code/qt0/source/qfizzle.h #ifndef qfizzle_h #define qfizzle_h #include <QtCore/QObject> class QFizzle : public QObject { Q_OBJECT public: QFizzle(); }; #endif
fifoforlifo/pynja
test2/code/a/a2/source/a2_client_pch.h
#pragma once #include "a2_0.h"
fifoforlifo/pynja
test2/code/a/a0/source/a0_pch.h
<gh_stars>0 #if defined(_WIN32) #include <Windows.h> #endif #if defined(__linux__) #include <sys/time.h> #endif #include "a2_0.h"
fifoforlifo/pynja
test2/code/a/a2/include/a2_0.h
<reponame>fifoforlifo/pynja #pragma once #include <dllexport.h> DLL_EXPORT(a2) int a2_0();
fifoforlifo/pynja
test2/code/qt0/include/qt0.h
<gh_stars>0 #pragma once int a2_0();
fifoforlifo/pynja
test2/code/a/a2/source/a2_pch.h
#ifndef __a2_pch_h__ #define __a2_pch_h__ #include "a2_0.h" #endif // file guard
fifoforlifo/pynja
test2/code/a/a0/includeSpecial/a0_special.h
<reponame>fifoforlifo/pynja #pragma once #include "a0.h" inline int a0_0_special() { return a0_0(); }
soule/AppAuth-iOS
Source/AppAuthTV/OIDTVServiceConfiguration.h
<reponame>soule/AppAuth-iOS /*! @file OIDTVServiceConfiguration.h @brief AppAuth iOS SDK @copyright Copyright 2016 Google Inc. @copydetails Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #import "OIDServiceConfiguration.h" NS_ASSUME_NONNULL_BEGIN /*! @brief Configuration for authorizing the user with the @c OIDTVAuthorizationService. */ @interface OIDTVServiceConfiguration : OIDServiceConfiguration /*! @brief The TV authorization endpoint URI. */ @property(nonatomic, readonly) NSURL *TVAuthorizationEndpoint; /*! @internal @brief Unavailable. Please use @c initWithTVAuthorizationEndpoint:tokenEndpoint: */ - (instancetype)init NS_UNAVAILABLE; /*! @internal @brief Unavailable. Please use @c initWithTVAuthorizationEndpoint:tokenEndpoint: */ - (instancetype)initWithAuthorizationEndpoint:(NSURL *)authorizationEndpoint tokenEndpoint:(NSURL *)tokenEndpoint NS_UNAVAILABLE; /*! @brief Designated initializer. @param discoveryDocument The discovery document from which to extract the required OAuth configuration. */ - (instancetype)initWithDiscoveryDocument:(OIDServiceDiscovery *)discoveryDocument NS_DESIGNATED_INITIALIZER; /*! @brief Designated initializer. @param TVAuthorizationEndpoint The TV authorization endpoint URI. @param tokenEndpoint The token exchange and refresh endpoint URI. */ - (instancetype)initWithTVAuthorizationEndpoint:(NSURL *)TVAuthorizationEndpoint tokenEndpoint:(NSURL *)tokenEndpoint NS_DESIGNATED_INITIALIZER; @end NS_ASSUME_NONNULL_END
zxc524580210/Simd
src/Simd/SimdSynetConvolution8iCommon.h
/* * Simd Library (http://ermig1979.github.io/Simd). * * Copyright (c) 2011-2020 <NAME>. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef __SimdSynetConvolution8iCommon_h__ #define __SimdSynetConvolution8iCommon_h__ #include "Simd/SimdMath.h" #include "Simd/SimdStore.h" #include "Simd/SimdSynet.h" #include "Simd/SimdExp.h" #include "Simd/SimdExtract.h" #include "Simd/SimdSynetConvolution8i.h" #include "Simd/SimdSynetConvolution32fCommon.h" namespace Simd { #if defined(SIMD_SSE41_ENABLE) namespace Sse41 { template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8i { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t * dst, int32_t * buf, __m128i sum, const __m128 * norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper); template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t * dst, int32_t * buf, __m128i sum, const __m128 * norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail); }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), norm[index]), bias[index]), params, index); __m128i i32 = _mm_cvtps_epi32(_mm_add_ps(_mm_mul_ps(f32, scale[index]), shift[index])); ((int32_t*)dst)[index] = _mm_cvtsi128_si32(_mm_min_epu8(_mm_packus_epi16(_mm_packs_epi32(i32, K_ZERO), K_ZERO), upper)); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { uint8_t tmp[F]; Term8i::Save<type, index>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), norm[index]), bias[index]), params, index); _mm_storeu_ps((float*)dst + index*F, f32); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iFirst> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { _mm_storeu_si128((__m128i*)buf + index, sum); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { int32_t tmp[F]; _mm_storeu_si128((__m128i*)tmp, sum); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iIterim> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { _mm_storeu_si128((__m128i*)buf + index, _mm_add_epi32(_mm_loadu_si128((__m128i*)buf + index), sum)); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { int32_t tmp[F]; _mm_storeu_si128((__m128i*)tmp, _mm_add_epi32(_mm_loadu_si128((__m128i*)buf + index), sum)); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast8u> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { sum = _mm_add_epi32(_mm_loadu_si128((__m128i*)buf + index), sum); __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), norm[index]), bias[index]), params, index); __m128i i32 = _mm_cvtps_epi32(_mm_add_ps(_mm_mul_ps(f32, scale[index]), shift[index])); ((int32_t*)dst)[index] = _mm_cvtsi128_si32(_mm_min_epu8(_mm_packus_epi16(_mm_packs_epi32(i32, K_ZERO), K_ZERO), upper)); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { uint8_t tmp[F]; Term8i::Save<type, index>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast32f> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { sum = _mm_add_epi32(_mm_loadu_si128((__m128i*)buf + index), sum); __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), norm[index]), bias[index]), params, index); _mm_storeu_ps((float*)dst + index * F, f32); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { Term8i<term>::template Save<type, 0>(dst, buf, sum, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, __m128i sum, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { Term8i<term>::template Save<type, 0>(dst, buf, sum, norm, bias, params, scale, shift, upper, tail); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, __m128i sum0, __m128i sum1, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper) { Term8i<term>::template Save<type, 0>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1>(dst, buf, sum1, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, __m128i sum0, __m128i sum1, const __m128* norm, const __m128* bias, const __m128* params, const __m128* scale, const __m128* shift, __m128i upper, size_t tail) { Term8i<term>::template Save<type, 0>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1>(dst, buf, sum1, norm, bias, params, scale, shift, upper, tail); } //--------------------------------------------------------------------- template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8iDepthwise { template<SimdConvolutionActivationType type> static SIMD_INLINE void Save(uint8_t* dst, __m128i sum, const float * norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset); }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type> static SIMD_INLINE void Save(uint8_t* dst, __m128i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset) { __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), _mm_loadu_ps(norm + offset)), _mm_loadu_ps(bias + offset)), params, offset); __m128i i32 = _mm_cvtps_epi32(_mm_add_ps(_mm_mul_ps(f32, _mm_loadu_ps(scale + offset)), _mm_loadu_ps(shift + offset))); ((int32_t*)(dst + offset))[0] = _mm_cvtsi128_si32(_mm_min_epu8(_mm_packus_epi16(_mm_packs_epi32(i32, K_ZERO), K_ZERO), upper)); } }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type> static SIMD_INLINE void Save(uint8_t* dst, __m128i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset) { __m128 f32 = Sse2::Activate<type>(_mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(sum), _mm_loadu_ps(norm + offset)), _mm_loadu_ps(bias + offset)), params, offset); _mm_storeu_ps((float*)dst + offset, f32); } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save(uint8_t* dst, __m128i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset) { Term8iDepthwise<term>::template Save<type>(dst, sum, norm, bias, params, scale, shift, upper, offset); } } #endif//SIMD_SSE41_ENABLE #if defined(SIMD_AVX2_ENABLE) namespace Avx2 { template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8i { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper); template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail); }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { __m256 f32 = Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), norm[index], bias[index]), params, index); __m256i i32 = _mm256_cvtps_epi32(Fmadd<nofma>(f32, scale[index], shift[index])); ((int64_t*)dst)[index] = Extract64i<0>(_mm256_min_epu8(PackI16ToU8(PackI32ToI16(i32, K_ZERO), K_ZERO), upper)); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { uint8_t tmp[F]; Term8i::Save<type, index, nofma>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { __m256 f32 = Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), norm[index], bias[index]), params, index); _mm256_storeu_ps((float*)dst + index * F, f32); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index, nofma>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iFirst> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { _mm256_storeu_si256((__m256i*)buf + index, sum); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { int32_t tmp[F]; _mm256_storeu_si256((__m256i*)tmp, sum); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iIterim> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { _mm256_storeu_si256((__m256i*)buf + index, _mm256_add_epi32(_mm256_loadu_si256((__m256i*)buf + index), sum)); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { int32_t tmp[F]; _mm256_storeu_si256((__m256i*)tmp, _mm256_add_epi32(_mm256_loadu_si256((__m256i*)buf + index), sum)); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast8u> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { sum = _mm256_add_epi32(_mm256_loadu_si256((__m256i*)buf + index), sum); __m256 f32 = Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), norm[index], bias[index]), params, index); __m256i i32 = _mm256_cvtps_epi32(Fmadd<nofma>(f32, scale[index], shift[index])); ((int64_t*)dst)[index] = Extract64i<0>(_mm256_min_epu8(PackI16ToU8(PackI32ToI16(i32, K_ZERO), K_ZERO), upper)); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { uint8_t tmp[F]; Save<type, index, nofma>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast32f> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { sum = _mm256_add_epi32(_mm256_loadu_si256((__m256i*)buf + index), sum); __m256 f32 = Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), norm[index], bias[index]), params, index); _mm256_storeu_ps((float*)dst + index * F, f32); } template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index, nofma>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, __m256i sum, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum, norm, bias, params, scale, shift, upper, tail); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, __m256i sum0, __m256i sum1, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1, nofma>(dst, buf, sum1, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, __m256i sum0, __m256i sum1, const __m256* norm, const __m256* bias, const __m256* params, const __m256* scale, const __m256* shift, __m256i upper, size_t tail) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1, nofma>(dst, buf, sum1, norm, bias, params, scale, shift, upper, tail); } //--------------------------------------------------------------------- template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8iDepthwise { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m256i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m256i upper, size_t offset); }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m256i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m256i upper, size_t offset) { __m256 f32 = Avx2::Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), _mm256_loadu_ps(norm + offset), _mm256_loadu_ps(bias + offset)), params, offset); __m256i i32 = _mm256_cvtps_epi32(Fmadd<nofma>(f32, _mm256_loadu_ps(scale + offset), _mm256_loadu_ps(shift + offset))); ((int64_t*)(dst + offset))[0] = Extract64i<0>(_mm256_min_epu8(PackI16ToU8(PackI32ToI16(i32, K_ZERO), K_ZERO), upper)); } }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m256i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m256i upper, size_t offset) { __m256 f32 = Avx2::Activate<type>(Fmadd<nofma>(_mm256_cvtepi32_ps(sum), _mm256_loadu_ps(norm + offset), _mm256_loadu_ps(bias + offset)), params, offset); _mm256_storeu_ps((float*)dst + offset, f32); } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save(uint8_t* dst, __m256i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m256i upper, size_t offset) { Term8iDepthwise<term>::template Save<type, nofma>(dst, sum, norm, bias, params, scale, shift, upper, offset); } } #endif//SIMD_AVX2_ENABLE #if defined(SIMD_AVX512BW_ENABLE) namespace Avx512bw { template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8i { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1); }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { __m512 f32 = Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), norm[index], bias[index]), params, index); __m512i i32 = _mm512_cvtps_epi32(Fmadd<nofma>(f32, scale[index], shift[index])); __m128i u8 = _mm256_castsi256_si128(Avx2::PackI16ToU8(_mm512_cvtepi32_epi16(i32), Avx2::K_ZERO)); _mm_mask_storeu_epi8(dst + index * F, tail, _mm_min_epu8(u8, upper)); } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { __m512 f32 = Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), norm[index], bias[index]), params, index); _mm512_mask_storeu_ps((float*)dst + index * F, tail, f32); } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iFirst> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { _mm512_mask_storeu_epi32(buf + index * F, tail, sum); } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iIterim> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { _mm512_mask_storeu_epi32(buf + index * F, tail, _mm512_add_epi32(_mm512_maskz_loadu_epi32(tail, buf + index * F), sum)); } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast8u> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { sum = _mm512_add_epi32(_mm512_maskz_loadu_epi32(tail, buf + index * F), sum); __m512 f32 = Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), norm[index], bias[index]), params, index); __m512i i32 = _mm512_cvtps_epi32(Fmadd<nofma>(f32, scale[index], shift[index])); __m128i u8 = _mm256_castsi256_si128(Avx2::PackI16ToU8(_mm512_cvtepi32_epi16(i32), Avx2::K_ZERO)); _mm_mask_storeu_epi8(dst + index * F, tail, _mm_min_epu8(u8, upper)); } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast32f> { template<SimdConvolutionActivationType type, int index, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { sum = _mm512_add_epi32(_mm512_maskz_loadu_epi32(tail, buf + index * F), sum); __m512 f32 = Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), norm[index], bias[index]), params, index); _mm512_mask_storeu_ps((float*)dst + index * F, tail, f32); } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, __m512i sum, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum, norm, bias, params, scale, shift, upper, tail); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, __m512i sum0, __m512i sum1, const __m512* norm, const __m512* bias, const __m512* params, const __m512* scale, const __m512* shift, __m128i upper, __mmask16 tail = -1) { Term8i<term>::template Save<type, 0, nofma>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1, nofma>(dst, buf, sum1, norm, bias, params, scale, shift, upper, tail); } //--------------------------------------------------------------------- template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8iDepthwise { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m512i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset, __mmask16 tail); }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m512i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset, __mmask16 tail) { __m512 _norm = _mm512_maskz_loadu_ps(tail, norm + offset); __m512 _bias = _mm512_maskz_loadu_ps(tail, bias + offset); __m512 f32 = Avx512f::Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), _norm, _bias), params, offset, tail); __m512 _scale = _mm512_maskz_loadu_ps(tail, scale + offset); __m512 _shift = _mm512_maskz_loadu_ps(tail, shift + offset); __m512i i32 = _mm512_cvtps_epi32(Fmadd<nofma>(f32, _scale, _shift)); __m128i u8 = _mm256_castsi256_si128(Avx2::PackI16ToU8(_mm512_cvtepi32_epi16(i32), Avx2::K_ZERO)); _mm_mask_storeu_epi8(dst + offset, tail, _mm_min_epu8(u8, upper)); } }; template <> struct Term8iDepthwise<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, bool nofma> static SIMD_INLINE void Save(uint8_t* dst, __m512i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset, __mmask16 tail) { __m512 _norm = _mm512_maskz_loadu_ps(tail, norm + offset); __m512 _bias = _mm512_maskz_loadu_ps(tail, bias + offset); __m512 f32 = Avx512f::Activate<type>(Fmadd<nofma>(_mm512_cvtepi32_ps(sum), _norm, _bias), params, offset, tail); _mm512_mask_storeu_ps((float*)dst + offset, tail, f32); } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type, bool nofma> SIMD_INLINE void Save(uint8_t* dst, __m512i sum, const float* norm, const float* bias, const float* params, const float* scale, const float* shift, __m128i upper, size_t offset, __mmask16 tail = -1) { Term8iDepthwise<term>::template Save<type, nofma>(dst, sum, norm, bias, params, scale, shift, upper, offset, tail); } } #endif//SIMD_AVX512BW_ENABLE #if defined(SIMD_NEON_ENABLE) namespace Neon { template <Base::SynetConvolution8iNhwcDirect::Term8iType term> struct Term8i { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t * scale, const float32x4_t* shift, uint8x8_t upper); template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail); }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle8u> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { float32x4_t f32 = Activate<type>(vaddq_f32(vmulq_f32(vcvtq_f32_s32(sum), norm[index]), bias[index]), params, index); int32x4_t i32 = Round(vaddq_f32(vmulq_f32(f32, scale[index]), shift[index])); uint8x8_t u8 = vmin_u8(vqmovun_s16(vcombine_s16(vmovn_s32(i32), vcreate_s16(0))), upper); ((int32_t*)dst)[index] = vget_lane_s32(vreinterpret_s32_u8(u8), 0); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { uint8_t tmp[F]; Term8i::Save<type, index>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iSingle32f> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { float32x4_t f32 = Activate<type>(vaddq_f32(vmulq_f32(vcvtq_f32_s32(sum), norm[index]), bias[index]), params, index); Store<false>((float*)dst + index * F, f32); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iFirst> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { Store<false>(buf + index * F, sum); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { int32_t tmp[F]; Store<false>(tmp, sum); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iIterim> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { Store<false>(buf + index * F, vaddq_s32(Load<false>(buf + index * F), sum)); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { int32_t tmp[F]; Store<false>(tmp, vaddq_s32(Load<false>(buf + index * F), sum)); for (size_t i = 0; i < tail; ++i) buf[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast8u> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { sum = vaddq_s32(Load<false>(buf + index * F), sum); float32x4_t f32 = Activate<type>(vaddq_f32(vmulq_f32(vcvtq_f32_s32(sum), norm[index]), bias[index]), params, index); int32x4_t i32 = Round(vaddq_f32(vmulq_f32(f32, scale[index]), shift[index])); uint8x8_t u8 = vmin_u8(vqmovun_s16(vcombine_s16(vmovn_s32(i32), vcreate_s16(0))), upper); ((int32_t*)dst)[index] = vget_lane_s32(vreinterpret_s32_u8(u8), 0); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { uint8_t tmp[F]; Term8i::Save<type, index>(tmp - index * F, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) dst[index * F + i] = tmp[i]; } }; template <> struct Term8i<Base::SynetConvolution8iNhwcDirect::Term8iLast32f> { template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { sum = vaddq_s32(Load<false>(buf + index * F), sum); float32x4_t f32 = Activate<type>(vaddq_f32(vmulq_f32(vcvtq_f32_s32(sum), norm[index]), bias[index]), params, index); Store<false>((float*)dst + index * F, f32); } template<SimdConvolutionActivationType type, int index> static SIMD_INLINE void Save(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { uint8_t tmp[A]; Term8i::Save<type, index>(tmp - index * A, buf, sum, norm, bias, params, scale, shift, upper); for (size_t i = 0; i < tail; ++i) ((float*)dst)[index * F + i] = ((float*)tmp)[i]; } }; template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { Term8i<term>::template Save<type, 0>(dst, buf, sum, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save1(uint8_t* dst, int32_t* buf, int32x4_t sum, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { Term8i<term>::template Save<type, 0>(dst, buf, sum, norm, bias, params, scale, shift, upper, tail); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, int32x4_t sum0, int32x4_t sum1, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper) { Term8i<term>::template Save<type, 0>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1>(dst, buf, sum1, norm, bias, params, scale, shift, upper); } template<Base::SynetConvolution8iNhwcDirect::Term8iType term, SimdConvolutionActivationType type> SIMD_INLINE void Save2(uint8_t* dst, int32_t* buf, int32x4_t sum0, int32x4_t sum1, const float32x4_t* norm, const float32x4_t* bias, const float32x4_t* params, const float32x4_t* scale, const float32x4_t* shift, uint8x8_t upper, size_t tail) { Term8i<term>::template Save<type, 0>(dst, buf, sum0, norm, bias, params, scale, shift, upper); Term8i<term>::template Save<type, 1>(dst, buf, sum1, norm, bias, params, scale, shift, upper, tail); } } #endif//SIMD_NEON_ENABLE } #endif//__SimdSynetConvolution8iCommon_h__
zxc524580210/Simd
src/Simd/SimdSynetMergedConvolution8i.h
/* * Simd Library (http://ermig1979.github.io/Simd). * * Copyright (c) 2011-2020 <NAME>. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef __SimdSynetMergedConvolution8i_h__ #define __SimdSynetMergedConvolution8i_h__ #include "Simd/SimdArray.h" #include "Simd/SimdPerformance.h" #include "Simd/SimdRuntime.h" #ifdef _N #undef _N #endif namespace Simd { struct MergConvParam8i { size_t batch, count; SimdSynetCompatibilityType compatibility; SimdConvolutionParameters conv[3]; MergConvParam8i(size_t batch, const SimdConvolutionParameters * convs, size_t count, SimdSynetCompatibilityType compatibility) { assert(count <= 3); this->batch = batch; this->count = count; this->compatibility = compatibility; for (size_t i = 0; i < count; ++i) this->conv[i] = convs[i]; } bool Valid() { if (count < 2 || count > 3) return false; for (size_t i = 0; i < count; ++i) { SimdConvolutionParameters & c = conv[i]; if ((c.srcT != SimdTensorData32f && c.srcT != SimdTensorData8u) || (c.dstT != SimdTensorData32f && c.dstT != SimdTensorData8u)) return false; if (c.srcF != SimdTensorFormatNhwc || c.dstF != SimdTensorFormatNhwc) return false; if (c.dstH != (c.srcH + c.padY + c.padH - (c.dilationY * (c.kernelY - 1) + 1)) / c.strideY + 1 || c.dstH == 0) return false; if (c.dstW != (c.srcW + c.padX + c.padW - (c.dilationY * (c.kernelX - 1) + 1)) / c.strideX + 1 || c.dstW == 0) return false; if (c.kernelY != c.kernelX || !(c.kernelY == 1 || c.kernelY == 3 || c.kernelY == 5 || c.kernelY == 7)) return false; if (c.strideY != c.strideX || !(c.strideY == 1 || c.strideY == 2 || c.strideY == 3)) return false; if (c.dilationY != 1 || c.dilationX != 1) return false; if (c.dstH == (c.srcH + c.padY + c.padH - (c.dilationY * (c.kernelY - 1) + 1) - 1) / c.strideY + 1) c.padH--; if (c.dstW == (c.srcW + c.padX + c.padW - (c.dilationY * (c.kernelX - 1) + 1) - 1) / c.strideX + 1) c.padW--; } if (count == 3) { if (conv[0].group != 1 || (conv[0].kernelY != 1 && conv[0].kernelY != 3)) return false; if (conv[1].group != conv[1].srcC || conv[1].group != conv[1].dstC || (conv[1].kernelY != 3 && conv[1].kernelY != 5 && conv[1].kernelY != 7)) return false; if (conv[2].group != 1 || conv[2].kernelY != 1 || conv[2].strideY != 1) return false; } else { if (conv[0].group == 1) { if (conv[0].kernelY != 1 && conv[0].kernelY != 3) return false; if (conv[1].group != conv[1].srcC || conv[1].group != conv[1].dstC || (conv[1].kernelY != 3 && conv[1].kernelY != 5 && conv[1].kernelY != 7)) return false; } else { if (conv[0].group != conv[0].srcC || conv[0].group != conv[0].dstC || (conv[0].kernelY != 3 && conv[0].kernelY != 5 && conv[0].kernelY != 7)) return false; if (conv[1].group != 1 || conv[1].kernelY != 1 || conv[1].strideY != 1) return false; } } return true; } SIMD_INLINE bool IsPad(size_t index, size_t value) const { return conv[index].padY == value && conv[index].padX == value && conv[index].padH == value && conv[index].padW == value; } #ifdef SIMD_PERFORMANCE_STATISTIC String Info() const { std::stringstream ss; ss << count << ":" << batch << "x" << conv[0].srcC << "x" << conv[0].srcH << "x" << conv[0].srcW; for (size_t i = 0; i < count; ++i) ss << "-" << (conv[i].group != 1 ? String("") : ToStr(conv[i].dstC) + "x") << conv[i].kernelY << "x" << conv[i].strideY; return ss.str(); } long long Flop(size_t i) const { return batch*conv[i].kernelY * conv[i].kernelX * conv[i].srcC * conv[i].dstH * conv[i].dstW * conv[i].dstC / conv[i].group * 2; } long long Flop() const { long long flop = 0; for (size_t i = 0; i < count; ++i) flop += Flop(i); return flop; } #endif }; class SynetMergedConvolution8i : public Deletable { public: virtual const MergConvParam8i & Param() const = 0; virtual size_t ExternalBufferSize() const = 0; virtual size_t InternalBufferSize() const = 0; virtual void SetParams(const float * const * weight, SimdBool * internal, const float * const * bias, const float * const * params, const float* const* stats) = 0; virtual void Forward(const uint8_t* src, uint8_t* buf, uint8_t* dst) = 0; #if defined(SIMD_PERFORMANCE_STATISTIC) virtual Base::PerformanceMeasurer* Perf(const String& func) = 0; #endif }; namespace Base { class SynetMergedConvolution8i : public Simd::SynetMergedConvolution8i { public: SynetMergedConvolution8i(const MergConvParam8i& p); virtual String Desc() const { return "Base"; } virtual const MergConvParam8i& Param() const { return _param; } virtual size_t ExternalBufferSize() const; virtual size_t InternalBufferSize() const; virtual void SetParams(const float * const * weight, SimdBool * internal, const float * const * bias, const float * const * params, const float* const* stats); virtual void Forward(const uint8_t* src, uint8_t* buf, uint8_t* dst); #if defined(SIMD_PERFORMANCE_STATISTIC) virtual Base::PerformanceMeasurer* Perf(const String& func); #endif protected: uint8_t* GetBuffer(uint8_t* buffer); MergConvParam8i _param; Array8u _buffer; private: #if defined(SIMD_PERFORMANCE_STATISTIC) Base::PerformanceMeasurer * _perf; #endif }; void * SynetMergedConvolution8iInit(size_t batch, const SimdConvolutionParameters * convs, size_t count, SimdSynetCompatibilityType compatibility); } #ifdef SIMD_SSE41_ENABLE namespace Sse41 { } #endif//SIMD_SSE41_ENABLE #ifdef SIMD_AVX2_ENABLE namespace Avx2 { } #endif//SIMD_AVX2_ENABLE #ifdef SIMD_AVX512BW_ENABLE namespace Avx512bw { } #endif//SIMD_AVX512BW_ENABLE #ifdef SIMD_AVX512VNNI_ENABLE namespace Avx512vnni { } #endif//SIMD_AVX512VNNI_ENABLE } #endif//__SimdSynetMergedConvolution8i_h__
zxc524580210/Simd
src/Test/TestUtils.h
<filename>src/Test/TestUtils.h /* * Tests for Simd Library (http://ermig1979.github.io/Simd). * * Copyright (c) 2011-2020 <NAME>. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef __TestUtils_h__ #define __TestUtils_h__ #include "Test/TestLog.h" namespace Test { void FillSequence(View & view); void FillPicture(View & view, uint64_t flag = 0x000000000000000F); SIMD_INLINE int Random(int range) { return ((::rand()&INT16_MAX)*range) / INT16_MAX; } SIMD_INLINE double Random() { return ((::rand()&INT16_MAX)*1.0) / INT16_MAX; } template<class T> inline void Fill(T * data, size_t size, T value) { for (size_t i = 0; i < size; ++i) data[i] = value; } void FillRandom(View & view, uint8_t lo = 0, uint8_t hi = 255); void FillRandom2(View & view, uint8_t lo = 0, uint8_t hi = 255, uint8_t step = 1); void FillRandomMask(View & view, uint8_t index); void FillRhombMask(View & mask, const Rect & rect, uint8_t index); void FillRandom32f(View & view, float lo = 0, float hi = 4096.0f); void FillRandom(Buffer32f & buffer, float lo = 0, float hi = 4096.0f); void FillRandom(float * data, size_t size, float lo = 0, float hi = 4096.0f); void FillRandom(Tensor32f & tensor, float lo = -10.0f, float hi = 10.0f); void FillRandom(uint8_t * data, size_t size, uint8_t lo = 0, uint8_t hi = 255); void FillRandom(Tensor8u& tensor, uint8_t lo = 0, uint8_t hi = 255); void FillRandom(Tensor8i& tensor, int8_t lo = -128, int8_t hi = 127); void FillRandom(Tensor32i& tensor, int32_t lo, int32_t hi); void FillRandom(Tensor32f& tensor, float* min, float* max, size_t channels, int negative, float upper = 1.0f, float range = 0.01f); void SetSrc32fTo8u(const Tensor32f& src, const float* min, const float* max, size_t channels, int negative, SimdSynetCompatibilityType compatibility, float* shift, float* scale, Tensor8u& dst); void SetDstStat(size_t channels, int negative, SimdSynetCompatibilityType compatibility, const Tensor32f& dst, float* min, float* max, float* scale, float* shift); bool Compare(const View & a, const View & b, int differenceMax = 0, bool printError = false, int errorCountMax = 0, int valueCycle = 0, const String & description = ""); bool Compare(const Histogram a, const Histogram b, int differenceMax = 0, bool printError = false, int errorCountMax = 0, const String & description = ""); bool Compare(const Sums & a, const Sums & b, int differenceMax = 0, bool printError = false, int errorCountMax = 0, const String & description = ""); bool Compare(const Sums64 & a, const Sums64 & b, int differenceMax = 0, bool printError = false, int errorCountMax = 0, const String & description = ""); bool Compare(const Rect & a, const Rect & b, bool printError = false); bool Compare(const Buffer32f & a, const Buffer32f & b, float differenceMax, bool printError, int errorCountMax, DifferenceType differenceType, const String & description = ""); bool Compare(const Buffer32f & a, const Buffer32f & b, float differenceMax = EPS, bool printError = false, int errorCountMax = 0, bool relative = true, const String & description = ""); bool CompareCycle(const Buffer32f & a, const Buffer32f & b, size_t cycle, float differenceMax = EPS, bool printError = false, int errorCountMax = 0, const String & description = ""); bool Compare(const View & a, const View & b, float differenceMax, bool printError, int errorCountMax, DifferenceType differenceType, const String & description = ""); bool Compare(const View & a, const View & b, float differenceMax = EPS, bool printError = false, int errorCountMax = 0, bool relative = true, const String & description = ""); bool Compare(const float & a, const float & b, float differenceMax = EPS, bool printError = false, DifferenceType differenceType = DifferenceRelative, const String & description = ""); String ColorDescription(View::Format format); String FormatDescription(View::Format format); String ScaleDescription(const Point & scale); String CompareTypeDescription(SimdCompareType type); String ExpandToLeft(const String & value, size_t count); String ExpandToRight(const String & value, size_t count); template <class T> SIMD_INLINE String ToString(const T & value) { std::stringstream ss; ss << value; return ss.str(); } template <> SIMD_INLINE String ToString<SimdBool>(const SimdBool & value) { std::stringstream ss; ss << (int)value; return ss.str(); } template <> SIMD_INLINE String ToString<View::Format>(const View::Format & value) { switch (value) { case View::None: return "None"; case View::Gray8: return "Gray8"; case View::Uv16: return "Uv16:"; case View::Bgr24: return "Bgr24"; case View::Bgra32: return "Bgra32"; case View::Int16: return "Int16"; case View::Int32: return "Int32"; case View::Int64: return "Int64"; case View::Float: return "Float"; case View::Double: return "Double"; case View::BayerGrbg: return "BayerGrbg"; case View::BayerGbrg: return "BayerGbrg"; case View::BayerRggb: return "BayerRggb"; case View::BayerBggr: return "BayerBggr"; case View::Hsv24: return "Hsv24"; case View::Hsl24: return "Hsl24"; case View::Rgb24: return "Rgb24"; default: assert(0); return ""; } } SIMD_INLINE String ToString(int value, int width) { std::stringstream ss; ss << std::setfill('0') << std::setw(width) << value; return ss.str(); } SIMD_INLINE String ToString(double value, int precision, bool zero) { std::stringstream ss; if(value || zero) ss << std::setprecision(precision) << std::fixed << value; return ss.str(); } template <class T> SIMD_INLINE T FromString(const String & str) { std::stringstream ss(str); T value; ss >> value; return value; } String ToString(double value, size_t iCount, size_t fCount); SIMD_INLINE String GetCurrentDateTimeString() { std::time_t t; std::time(&t); std::tm * tm = ::localtime(&t); std::stringstream ss; ss << ToString(tm->tm_year + 1900, 4) << "." << ToString(tm->tm_mon + 1, 2) << "." << ToString(tm->tm_mday, 2) << " " << ToString(tm->tm_hour, 2) << ":" << ToString(tm->tm_min, 2) << ":" << ToString(tm->tm_sec, 2); return ss.str(); } bool DirectoryExists(const String & path); String DirectoryByPath(const String & path); bool CreatePath(const String & path); bool CreatePathIfNotExist(const String & path); } #define TEST_CHECK_VALUE(name) \ if(name##1 != name##2) \ { \ TEST_LOG_SS(Error, "Error " << #name << ": (" << name##1 << " != " << name##2 << ")! "); \ return false; \ } #endif//__TestUtils_h__
TheRinger/Atlascoin
src/script/atlasconsensus.h
<filename>src/script/atlasconsensus.h // Copyright (c) 2009-2010 <NAME> // Copyright (c) 2009-2016 The Bitcoin Core developers // Copyright (c) 2017 The Atlas Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef ATLAS_ATLASCONSENSUS_H #define ATLAS_ATLASCONSENSUS_H #include <stdint.h> #if defined(BUILD_ATLAS_INTERNAL) && defined(HAVE_CONFIG_H) #include "config/atlas-config.h" #if defined(_WIN32) #if defined(DLL_EXPORT) #if defined(HAVE_FUNC_ATTRIBUTE_DLLEXPORT) #define EXPORT_SYMBOL __declspec(dllexport) #else #define EXPORT_SYMBOL #endif #endif #elif defined(HAVE_FUNC_ATTRIBUTE_VISIBILITY) #define EXPORT_SYMBOL __attribute__ ((visibility ("default"))) #endif #elif defined(MSC_VER) && !defined(STATIC_LIBATLASCONSENSUS) #define EXPORT_SYMBOL __declspec(dllimport) #endif #ifndef EXPORT_SYMBOL #define EXPORT_SYMBOL #endif #ifdef __cplusplus extern "C" { #endif #define ATLASCONSENSUS_API_VER 1 typedef enum atlasconsensus_error_t { atlasconsensus_ERR_OK = 0, atlasconsensus_ERR_TX_INDEX, atlasconsensus_ERR_TX_SIZE_MISMATCH, atlasconsensus_ERR_TX_DESERIALIZE, atlasconsensus_ERR_AMOUNT_REQUIRED, atlasconsensus_ERR_INVALID_FLAGS, } atlasconsensus_error; /** Script verification flags */ enum { atlasconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0, atlasconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts atlasconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance atlasconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY = (1U << 4), // enforce NULLDUMMY (BIP147) atlasconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65) atlasconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112) atlasconsensus_SCRIPT_FLAGS_VERIFY_WITNESS = (1U << 11), // enable WITNESS (BIP141) atlasconsensus_SCRIPT_FLAGS_VERIFY_ALL = atlasconsensus_SCRIPT_FLAGS_VERIFY_P2SH | atlasconsensus_SCRIPT_FLAGS_VERIFY_DERSIG | atlasconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY | atlasconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY | atlasconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY | atlasconsensus_SCRIPT_FLAGS_VERIFY_WITNESS }; /// Returns 1 if the input nIn of the serialized transaction pointed to by /// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under /// the additional constraints specified by flags. /// If not nullptr, err will contain an error/success code for the operation EXPORT_SYMBOL int atlasconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *txTo , unsigned int txToLen, unsigned int nIn, unsigned int flags, atlasconsensus_error* err); EXPORT_SYMBOL int atlasconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, const unsigned char *txTo , unsigned int txToLen, unsigned int nIn, unsigned int flags, atlasconsensus_error* err); EXPORT_SYMBOL unsigned int atlasconsensus_version(); #ifdef __cplusplus } // extern "C" #endif #undef EXPORT_SYMBOL #endif // ATLAS_ATLASCONSENSUS_H
TheRinger/Atlascoin
src/qt/assetrecord.h
// Copyright (c) 2011-2016 The Bitcoin Core developers // Copyright (c) 2017 The Atlas Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef ATLAS_QT_ASSETRECORD_H #define ATLAS_QT_ASSETRECORD_H #include "math.h" #include "amount.h" #include "tinyformat.h" /** UI model for unspent assets. */ class AssetRecord { public: AssetRecord(): name(""), quantity(0), units(0), fIsAdministrator(false) { } AssetRecord(const std::string _name, const CAmount& _quantity, const int _units, const bool _fIsAdministrator): name(_name), quantity(_quantity), units(_units), fIsAdministrator(_fIsAdministrator) { } std::string formattedQuantity() { bool sign = quantity < 0; int64_t n_abs = (sign ? -quantity : quantity); int64_t quotient = n_abs / COIN; int64_t remainder = n_abs % COIN; remainder = remainder / pow(10, 8 - units); if (units == 0 && remainder == 0) { return strprintf("%s%d", sign ? "-" : "", quotient); } else { return strprintf("%s%d.%0" + std::to_string(units) + "d", sign ? "-" : "", quotient, remainder); } } /** @name Immutable attributes @{*/ std::string name; CAmount quantity; int units; bool fIsAdministrator; /**@}*/ }; #endif // ATLAS_QT_ASSETRECORD_H
TheRinger/Atlascoin
src/qt/atlasaddressvalidator.h
<gh_stars>0 // Copyright (c) 2011-2014 The Bitcoin Core developers // Copyright (c) 2017 The Atlas Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef ATLAS_QT_ATLASADDRESSVALIDATOR_H #define ATLAS_QT_ATLASADDRESSVALIDATOR_H #include <QValidator> /** Base58 entry widget validator, checks for valid characters and * removes some whitespace. */ class AtlasAddressEntryValidator : public QValidator { Q_OBJECT public: explicit AtlasAddressEntryValidator(QObject *parent); State validate(QString &input, int &pos) const; }; /** Atlas address widget validator, checks for a valid atlas address. */ class AtlasAddressCheckValidator : public QValidator { Q_OBJECT public: explicit AtlasAddressCheckValidator(QObject *parent); State validate(QString &input, int &pos) const; }; #endif // ATLAS_QT_ATLASADDRESSVALIDATOR_H
TheRinger/Atlascoin
src/secp256k1/src/java/org_atlas_NativeSecp256k1.h
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> #include "include/secp256k1.h" /* Header for class org_atlas_NativeSecp256k1 */ #ifndef _Included_org_atlas_NativeSecp256k1 #define _Included_org_atlas_NativeSecp256k1 #ifdef __cplusplus extern "C" { #endif /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ctx_clone * Signature: (J)J */ SECP256K1_API jlong JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ctx_1clone (JNIEnv *, jclass, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_context_randomize * Signature: (Ljava/nio/ByteBuffer;J)I */ SECP256K1_API jint JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1context_1randomize (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_privkey_tweak_add * Signature: (Ljava/nio/ByteBuffer;J)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1privkey_1tweak_1add (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_privkey_tweak_mul * Signature: (Ljava/nio/ByteBuffer;J)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1privkey_1tweak_1mul (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_pubkey_tweak_add * Signature: (Ljava/nio/ByteBuffer;JI)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1pubkey_1tweak_1add (JNIEnv *, jclass, jobject, jlong, jint); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_pubkey_tweak_mul * Signature: (Ljava/nio/ByteBuffer;JI)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1pubkey_1tweak_1mul (JNIEnv *, jclass, jobject, jlong, jint); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_destroy_context * Signature: (J)V */ SECP256K1_API void JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1destroy_1context (JNIEnv *, jclass, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ecdsa_verify * Signature: (Ljava/nio/ByteBuffer;JII)I */ SECP256K1_API jint JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ecdsa_1verify (JNIEnv *, jclass, jobject, jlong, jint, jint); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ecdsa_sign * Signature: (Ljava/nio/ByteBuffer;J)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ecdsa_1sign (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ec_seckey_verify * Signature: (Ljava/nio/ByteBuffer;J)I */ SECP256K1_API jint JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ec_1seckey_1verify (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ec_pubkey_create * Signature: (Ljava/nio/ByteBuffer;J)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ec_1pubkey_1create (JNIEnv *, jclass, jobject, jlong); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ec_pubkey_parse * Signature: (Ljava/nio/ByteBuffer;JI)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ec_1pubkey_1parse (JNIEnv *, jclass, jobject, jlong, jint); /* * Class: org_atlas_NativeSecp256k1 * Method: secp256k1_ecdh * Signature: (Ljava/nio/ByteBuffer;JI)[[B */ SECP256K1_API jobjectArray JNICALL Java_org_atlas_NativeSecp256k1_secp256k1_1ecdh (JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen); #ifdef __cplusplus } #endif #endif
TheRinger/Atlascoin
src/rpc/safemode.h
// Copyright (c) 2017 The Bitcoin Core developers // Copyright (c) 2017 The Atlas Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef ATLAS_RPC_SAFEMODE_H #define ATLAS_RPC_SAFEMODE_H static const bool DEFAULT_DISABLE_SAFEMODE = true; void ObserveSafeMode(); #endif // ATLAS_RPC_SAFEMODE_H
feelc/blogs-share
0_multithread_server/src/tcp_server/query_thread.c
#include <stdio.h> #include <stdint.h> #include <string.h> #include <errno.h> #include <pthread.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <event.h> #include "query_thread.h" extern int32_t tlog[]; #define SAFE_RECV(sock, buf, buf_len, src_addr) \ do \ { \ socklen_t addr_len_ = sizeof(struct sockaddr); \ socklen_t *paddr_len_ = &addr_len_; \ if (src_addr == NULL) \ { \ paddr_len_ = NULL; \ } \ if (-1 == recv(sock, buf, buf_len, 0)) \ { \ printf("call recvfrom() failed, err: %s", strerror(errno)); \ if (errno == EINTR) \ { \ continue; \ } \ } \ } while (0) int32_t create_socket() { int32_t sock = -1; struct sockaddr_in local_addr; socklen_t addr_len = sizeof(local_addr); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { printf("call socket() failed, err: %s\n", strerror(errno)); goto ERR; } int32_t enable = 1; if (-1 == setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable))) { printf("call setsockopt() failed, set SO_REUSEADDR failed, err: %s\n", strerror(errno)); } if (-1 == setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable))) { printf("call setsockopt() failed, set SO_REUSEPORT failed, err: %s\n", strerror(errno)); } memset(&local_addr, sizeof(local_addr), 0); local_addr.sin_family = AF_INET; local_addr.sin_addr.s_addr = htonl(INADDR_ANY); //inet_addr("127.0.0.1"); local_addr.sin_port = htons(55555); if (-1 == bind(sock, (const struct sockaddr *)&local_addr, addr_len)) { printf("call bind() failed, err: %s\n", strerror(errno)); goto ERR; } if (-1 == listen(sock, 128)) { printf("call listen() failed, err: %s\n", strerror(errno)); goto ERR; } return sock; ERR: if (sock > 0) { close(sock); } return -1; } void listen_cb(evutil_socket_t sock, short events, void* arg) { uint32_t idx = *(uint32_t *)arg; while (1) { int conn_sock = accept(sock, NULL, NULL); char buf[1024]; struct sockaddr_in client_addr; SAFE_RECV(conn_sock, buf, sizeof(buf), &client_addr); close(conn_sock); tlog[idx] += 1; printf("read_cb, tid: %lu, client port: %u, buf: %s\n", pthread_self(), ntohs(client_addr.sin_port), buf); } } void *query_thread_cb(void *arg) { printf("tid: %lu\n", pthread_self()); int32_t sock = create_socket(); if (-1 == sock) { goto ERR; } struct event_base *pbase = NULL; struct event *pread_event = NULL; pbase = event_base_new(); if (NULL == pbase) { printf("call event_base_new() failed\n"); goto ERR; } pread_event = event_new(pbase, sock, EV_READ|EV_PERSIST, listen_cb, arg); if (NULL == pread_event) { printf("call event_read() failed\n"); goto ERR; } event_add(pread_event, NULL); printf("tid: %lu, enter event dispatch...\n", pthread_self()); if (-1 == event_base_dispatch(pbase)) { printf("call event_base_dispatch() failed\n"); goto ERR; } event_base_free(pbase); ERR: close(sock); return NULL; }
feelc/blogs-share
0_multithread_server/tests/tcp_client/client.c
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <stdio.h> int32_t main(int argc, char const *argv[]) { int32_t sock = -1; struct sockaddr_in server_addr;; socklen_t addr_len = sizeof(server_addr); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { printf("call socket() failed, err: %s\n", strerror(errno)); goto ERR; } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); server_addr.sin_port = htons(55555); if (-1 == connect(sock, (const struct sockaddr *)&server_addr, addr_len)) { printf("call connect() failed, err: %s\n", strerror(errno)); goto ERR; } if (-1 == send(sock, "XXXX", strlen("XXXX")+1, 0)) { printf("call send() failed, err: %s\n", strerror(errno)); goto ERR; } close(sock); return 0; ERR: if (sock > -1) { close(sock); } return -1; }
feelc/blogs-share
0_multithread_server/src/udp_server/main.c
<gh_stars>0 #include "query_thread.h" #include <stdio.h> #include <pthread.h> #include <stdint.h> #include <unistd.h> #include <signal.h> const static int32_t S_PORT = 55555; #define THREAD_NUM (5) int32_t tlog[THREAD_NUM]; pthread_t tid[THREAD_NUM]; int32_t tmp[THREAD_NUM]; void single_hander_cb(int s) { printf("\n"); for (int32_t i = 0; i < THREAD_NUM; ++i) { printf("tid: %d, cnt: %d\n", i, tlog[i]); } exit(0); } int main(int argc, char const *argv[]) { struct sigaction single_hander; single_hander.sa_handler = single_hander_cb; sigemptyset(&single_hander.sa_mask); single_hander.sa_flags = 0; sigaction(SIGINT, &single_hander, NULL); for (int32_t i = 0; i < THREAD_NUM; ++i) { tmp[i] = i; pthread_create(&tid[i], NULL, query_thread_cb, &tmp[i]); usleep(2000); } printf("please input Ctrl+C\n"); for (int i = 0; i < THREAD_NUM; ++i) { pthread_join(tid[i], NULL); } return 0; }
feelc/blogs-share
0_multithread_server/src/udp_server/query_thread.h
#ifndef __W_QUERY_THREAD_H__ #define __W_QUERY_THREAD_H__ void *query_thread_cb(void *arg); #endif
gisodal/highrestimer
include/timer.h
#ifndef TIMER_H #define TIMER_H #include <chrono> class Timer { public: typedef std::chrono::high_resolution_clock Clock; // alt. std::chrono::system_clock typedef std::chrono::time_point<Clock> TimePoint; typedef std::chrono::microseconds Microseconds; typedef std::chrono::nanoseconds Nanoseconds; typedef std::chrono::milliseconds Milliseconds; typedef std::chrono::seconds Seconds; typedef std::chrono::minutes Minutes; typedef std::chrono::hours Hours; typedef Nanoseconds Precision; private: Precision total_; TimePoint start_, end_; public: Timer() { Reset(); }; inline void Reset() { total_ = Precision::zero(); } inline void Start() { start_ = Clock::now(); } inline void Stop() { end_ = Clock::now(); } inline void Add() { total_ += std::chrono::duration_cast<Precision>(end_-start_); } template <class T> inline void Add(Precision::rep t) { total_ += std::chrono::duration<Precision::rep,typename T::period>(t); } template <class T> inline double GetDuration() const { return std::chrono::duration<double,typename T::period>(end_-start_).count(); } template <class T> inline double GetTotal() const { return std::chrono::duration<double,typename T::period>(total_).count(); } }; #endif
pmp-tool/PMP
src/qemu/src-pmp/target/riscv/insn_trans/trans_rvc.inc.c
<reponame>pmp-tool/PMP /* * RISC-V translation routines for the RVC Compressed Instruction Set. * * Copyright (c) 2016-2017 <NAME>, <EMAIL> * Copyright (c) 2018 <NAME>, <EMAIL> * <NAME>, <EMAIL> * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2 or later, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ static bool trans_c_addi4spn(DisasContext *ctx, arg_c_addi4spn *a) { if (a->nzuimm == 0) { /* Reserved in ISA */ return false; } arg_addi arg = { .rd = a->rd, .rs1 = 2, .imm = a->nzuimm }; return trans_addi(ctx, &arg); } static bool trans_c_fld(DisasContext *ctx, arg_c_fld *a) { arg_fld arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm }; return trans_fld(ctx, &arg); } static bool trans_c_lw(DisasContext *ctx, arg_c_lw *a) { arg_lw arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm }; return trans_lw(ctx, &arg); } static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a) { #ifdef TARGET_RISCV32 /* C.FLW ( RV32FC-only ) */ REQUIRE_FPU; REQUIRE_EXT(ctx, RVF); arg_c_lw tmp; decode_insn16_extract_cl_w(&tmp, ctx->opcode); arg_flw arg = { .rd = tmp.rd, .rs1 = tmp.rs1, .imm = tmp.uimm }; return trans_flw(ctx, &arg); #else /* C.LD ( RV64C/RV128C-only ) */ arg_c_fld tmp; decode_insn16_extract_cl_d(&tmp, ctx->opcode); arg_ld arg = { .rd = tmp.rd, .rs1 = tmp.rs1, .imm = tmp.uimm }; return trans_ld(ctx, &arg); #endif } static bool trans_c_fsd(DisasContext *ctx, arg_c_fsd *a) { arg_fsd arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm }; return trans_fsd(ctx, &arg); } static bool trans_c_sw(DisasContext *ctx, arg_c_sw *a) { arg_sw arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm }; return trans_sw(ctx, &arg); } static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a) { #ifdef TARGET_RISCV32 /* C.FSW ( RV32FC-only ) */ REQUIRE_FPU; REQUIRE_EXT(ctx, RVF); arg_c_sw tmp; decode_insn16_extract_cs_w(&tmp, ctx->opcode); arg_fsw arg = { .rs1 = tmp.rs1, .rs2 = tmp.rs2, .imm = tmp.uimm }; return trans_fsw(ctx, &arg); #else /* C.SD ( RV64C/RV128C-only ) */ arg_c_fsd tmp; decode_insn16_extract_cs_d(&tmp, ctx->opcode); arg_sd arg = { .rs1 = tmp.rs1, .rs2 = tmp.rs2, .imm = tmp.uimm }; return trans_sd(ctx, &arg); #endif } static bool trans_c_addi(DisasContext *ctx, arg_c_addi *a) { if (a->imm == 0) { /* Hint: insn is valid but does not affect state */ return true; } arg_addi arg = { .rd = a->rd, .rs1 = a->rd, .imm = a->imm }; return trans_addi(ctx, &arg); } static bool trans_c_jal_addiw(DisasContext *ctx, arg_c_jal_addiw *a) { #ifdef TARGET_RISCV32 /* C.JAL */ arg_c_j tmp; decode_insn16_extract_cj(&tmp, ctx->opcode); arg_jal arg = { .rd = 1, .imm = tmp.imm }; return trans_jal(ctx, &arg); #else /* C.ADDIW */ arg_addiw arg = { .rd = a->rd, .rs1 = a->rd, .imm = a->imm }; return trans_addiw(ctx, &arg); #endif } static bool trans_c_li(DisasContext *ctx, arg_c_li *a) { if (a->rd == 0) { /* Hint: insn is valid but does not affect state */ return true; } arg_addi arg = { .rd = a->rd, .rs1 = 0, .imm = a->imm }; return trans_addi(ctx, &arg); } static bool trans_c_addi16sp_lui(DisasContext *ctx, arg_c_addi16sp_lui *a) { if (a->rd == 2) { /* C.ADDI16SP */ arg_addi arg = { .rd = 2, .rs1 = 2, .imm = a->imm_addi16sp }; return trans_addi(ctx, &arg); } else if (a->imm_lui != 0) { /* C.LUI */ if (a->rd == 0) { /* Hint: insn is valid but does not affect state */ return true; } arg_lui arg = { .rd = a->rd, .imm = a->imm_lui }; return trans_lui(ctx, &arg); } return false; } static bool trans_c_srli(DisasContext *ctx, arg_c_srli *a) { int shamt = a->shamt; if (shamt == 0) { /* For RV128 a shamt of 0 means a shift by 64 */ shamt = 64; } /* Ensure, that shamt[5] is zero for RV32 */ if (shamt >= TARGET_LONG_BITS) { return false; } arg_srli arg = { .rd = a->rd, .rs1 = a->rd, .shamt = a->shamt }; return trans_srli(ctx, &arg); } static bool trans_c_srai(DisasContext *ctx, arg_c_srai *a) { int shamt = a->shamt; if (shamt == 0) { /* For RV128 a shamt of 0 means a shift by 64 */ shamt = 64; } /* Ensure, that shamt[5] is zero for RV32 */ if (shamt >= TARGET_LONG_BITS) { return false; } arg_srai arg = { .rd = a->rd, .rs1 = a->rd, .shamt = a->shamt }; return trans_srai(ctx, &arg); } static bool trans_c_andi(DisasContext *ctx, arg_c_andi *a) { arg_andi arg = { .rd = a->rd, .rs1 = a->rd, .imm = a->imm }; return trans_andi(ctx, &arg); } static bool trans_c_sub(DisasContext *ctx, arg_c_sub *a) { arg_sub arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_sub(ctx, &arg); } static bool trans_c_xor(DisasContext *ctx, arg_c_xor *a) { arg_xor arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_xor(ctx, &arg); } static bool trans_c_or(DisasContext *ctx, arg_c_or *a) { arg_or arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_or(ctx, &arg); } static bool trans_c_and(DisasContext *ctx, arg_c_and *a) { arg_and arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_and(ctx, &arg); } static bool trans_c_subw(DisasContext *ctx, arg_c_subw *a) { #ifdef TARGET_RISCV64 arg_subw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_subw(ctx, &arg); #else return false; #endif } static bool trans_c_addw(DisasContext *ctx, arg_c_addw *a) { #ifdef TARGET_RISCV64 arg_addw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_addw(ctx, &arg); #else return false; #endif } static bool trans_c_j(DisasContext *ctx, arg_c_j *a) { arg_jal arg = { .rd = 0, .imm = a->imm }; return trans_jal(ctx, &arg); } static bool trans_c_beqz(DisasContext *ctx, arg_c_beqz *a) { arg_beq arg = { .rs1 = a->rs1, .rs2 = 0, .imm = a->imm }; return trans_beq(ctx, &arg); } static bool trans_c_bnez(DisasContext *ctx, arg_c_bnez *a) { arg_bne arg = { .rs1 = a->rs1, .rs2 = 0, .imm = a->imm }; return trans_bne(ctx, &arg); } static bool trans_c_slli(DisasContext *ctx, arg_c_slli *a) { int shamt = a->shamt; if (shamt == 0) { /* For RV128 a shamt of 0 means a shift by 64 */ shamt = 64; } /* Ensure, that shamt[5] is zero for RV32 */ if (shamt >= TARGET_LONG_BITS) { return false; } arg_slli arg = { .rd = a->rd, .rs1 = a->rd, .shamt = a->shamt }; return trans_slli(ctx, &arg); } static bool trans_c_fldsp(DisasContext *ctx, arg_c_fldsp *a) { arg_fld arg = { .rd = a->rd, .rs1 = 2, .imm = a->uimm }; return trans_fld(ctx, &arg); } static bool trans_c_lwsp(DisasContext *ctx, arg_c_lwsp *a) { arg_lw arg = { .rd = a->rd, .rs1 = 2, .imm = a->uimm }; return trans_lw(ctx, &arg); } static bool trans_c_flwsp_ldsp(DisasContext *ctx, arg_c_flwsp_ldsp *a) { #ifdef TARGET_RISCV32 /* C.FLWSP */ arg_flw arg_flw = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_flwsp }; return trans_flw(ctx, &arg_flw); #else /* C.LDSP */ arg_ld arg_ld = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_ldsp }; return trans_ld(ctx, &arg_ld); #endif return false; } static bool trans_c_jr_mv(DisasContext *ctx, arg_c_jr_mv *a) { if (a->rd != 0 && a->rs2 == 0) { /* C.JR */ arg_jalr arg = { .rd = 0, .rs1 = a->rd, .imm = 0 }; return trans_jalr(ctx, &arg); } else if (a->rd != 0 && a->rs2 != 0) { /* C.MV */ arg_add arg = { .rd = a->rd, .rs1 = 0, .rs2 = a->rs2 }; return trans_add(ctx, &arg); } return false; } static bool trans_c_ebreak_jalr_add(DisasContext *ctx, arg_c_ebreak_jalr_add *a) { if (a->rd == 0 && a->rs2 == 0) { /* C.EBREAK */ arg_ebreak arg = { }; return trans_ebreak(ctx, &arg); } else if (a->rd != 0) { if (a->rs2 == 0) { /* C.JALR */ arg_jalr arg = { .rd = 1, .rs1 = a->rd, .imm = 0 }; return trans_jalr(ctx, &arg); } else { /* C.ADD */ arg_add arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 }; return trans_add(ctx, &arg); } } return false; } static bool trans_c_fsdsp(DisasContext *ctx, arg_c_fsdsp *a) { arg_fsd arg = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm }; return trans_fsd(ctx, &arg); } static bool trans_c_swsp(DisasContext *ctx, arg_c_swsp *a) { arg_sw arg = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm }; return trans_sw(ctx, &arg); } static bool trans_c_fswsp_sdsp(DisasContext *ctx, arg_c_fswsp_sdsp *a) { #ifdef TARGET_RISCV32 /* C.FSWSP */ arg_fsw a_fsw = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm_fswsp }; return trans_fsw(ctx, &a_fsw); #else /* C.SDSP */ arg_sd a_sd = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm_sdsp }; return trans_sd(ctx, &a_sd); #endif }
pmp-tool/PMP
src/qemu/src-pmp/tests/virtio-serial-test.c
<gh_stars>1-10 /* * QTest testcase for VirtIO Serial * * Copyright (c) 2014 SUSE LINUX Products GmbH * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" #include "libqtest.h" #include "libqos/virtio-serial.h" /* Tests only initialization so far. TODO: Replace with functional tests */ static void virtio_serial_nop(void *obj, void *data, QGuestAllocator *alloc) { /* no operation */ } static void serial_hotplug(void *obj, void *data, QGuestAllocator *alloc) { qtest_qmp_device_add("virtserialport", "hp-port", "{}"); qtest_qmp_device_del("hp-port"); } static void register_virtio_serial_test(void) { QOSGraphTestOptions opts = { }; opts.edge.before_cmd_line = "-device virtconsole,bus=vser0.0"; qos_add_test("console-nop", "virtio-serial", virtio_serial_nop, &opts); opts.edge.before_cmd_line = "-device virtserialport,bus=vser0.0"; qos_add_test("serialport-nop", "virtio-serial", virtio_serial_nop, &opts); qos_add_test("hotplug", "virtio-serial", serial_hotplug, NULL); } libqos_init(register_virtio_serial_test);
pmp-tool/PMP
src/qemu/src-pmp/include/qemu/cutils.h
#ifndef QEMU_CUTILS_H #define QEMU_CUTILS_H #include "qemu/fprintf-fn.h" /** * pstrcpy: * @buf: buffer to copy string into * @buf_size: size of @buf in bytes * @str: string to copy * * Copy @str into @buf, including the trailing NUL, but do not * write more than @buf_size bytes. The resulting buffer is * always NUL terminated (even if the source string was too long). * If @buf_size is zero or negative then no bytes are copied. * * This function is similar to strncpy(), but avoids two of that * function's problems: * * if @str fits in the buffer, pstrcpy() does not zero-fill the * remaining space at the end of @buf * * if @str is too long, pstrcpy() will copy the first @buf_size-1 * bytes and then add a NUL */ void pstrcpy(char *buf, int buf_size, const char *str); /** * strpadcpy: * @buf: buffer to copy string into * @buf_size: size of @buf in bytes * @str: string to copy * @pad: character to pad the remainder of @buf with * * Copy @str into @buf (but *not* its trailing NUL!), and then pad the * rest of the buffer with the @pad character. If @str is too large * for the buffer then it is truncated, so that @buf contains the * first @buf_size characters of @str, with no terminator. */ void strpadcpy(char *buf, int buf_size, const char *str, char pad); /** * pstrcat: * @buf: buffer containing existing string * @buf_size: size of @buf in bytes * @s: string to concatenate to @buf * * Append a copy of @s to the string already in @buf, but do not * allow the buffer to overflow. If the existing contents of @buf * plus @str would total more than @buf_size bytes, then write * as much of @str as will fit followed by a NUL terminator. * * @buf must already contain a NUL-terminated string, or the * behaviour is undefined. * * Returns: @buf. */ char *pstrcat(char *buf, int buf_size, const char *s); /** * strstart: * @str: string to test * @val: prefix string to look for * @ptr: NULL, or pointer to be written to indicate start of * the remainder of the string * * Test whether @str starts with the prefix @val. * If it does (including the degenerate case where @str and @val * are equal) then return true. If @ptr is not NULL then a * pointer to the first character following the prefix is written * to it. If @val is not a prefix of @str then return false (and * @ptr is not written to). * * Returns: true if @str starts with prefix @val, false otherwise. */ int strstart(const char *str, const char *val, const char **ptr); /** * stristart: * @str: string to test * @val: prefix string to look for * @ptr: NULL, or pointer to be written to indicate start of * the remainder of the string * * Test whether @str starts with the case-insensitive prefix @val. * This function behaves identically to strstart(), except that the * comparison is made after calling qemu_toupper() on each pair of * characters. * * Returns: true if @str starts with case-insensitive prefix @val, * false otherwise. */ int stristart(const char *str, const char *val, const char **ptr); /** * qemu_strnlen: * @s: string * @max_len: maximum number of bytes in @s to scan * * Return the length of the string @s, like strlen(), but do not * examine more than @max_len bytes of the memory pointed to by @s. * If no NUL terminator is found within @max_len bytes, then return * @max_len instead. * * This function has the same behaviour as the POSIX strnlen() * function. * * Returns: length of @s in bytes, or @max_len, whichever is smaller. */ int qemu_strnlen(const char *s, int max_len); /** * qemu_strsep: * @input: pointer to string to parse * @delim: string containing delimiter characters to search for * * Locate the first occurrence of any character in @delim within * the string referenced by @input, and replace it with a NUL. * The location of the next character after the delimiter character * is stored into @input. * If the end of the string was reached without finding a delimiter * character, then NULL is stored into @input. * If @input points to a NULL pointer on entry, return NULL. * The return value is always the original value of *@input (and * so now points to a NUL-terminated string corresponding to the * part of the input up to the first delimiter). * * This function has the same behaviour as the BSD strsep() function. * * Returns: the pointer originally in @input. */ char *qemu_strsep(char **input, const char *delim); #ifdef HAVE_STRCHRNUL static inline const char *qemu_strchrnul(const char *s, int c) { return strchrnul(s, c); } #else const char *qemu_strchrnul(const char *s, int c); #endif time_t mktimegm(struct tm *tm); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); int qemu_parse_fd(const char *param); int qemu_strtoi(const char *nptr, const char **endptr, int base, int *result); int qemu_strtoui(const char *nptr, const char **endptr, int base, unsigned int *result); int qemu_strtol(const char *nptr, const char **endptr, int base, long *result); int qemu_strtoul(const char *nptr, const char **endptr, int base, unsigned long *result); int qemu_strtoi64(const char *nptr, const char **endptr, int base, int64_t *result); int qemu_strtou64(const char *nptr, const char **endptr, int base, uint64_t *result); int qemu_strtod(const char *nptr, const char **endptr, double *result); int qemu_strtod_finite(const char *nptr, const char **endptr, double *result); int parse_uint(const char *s, unsigned long long *value, char **endptr, int base); int parse_uint_full(const char *s, unsigned long long *value, int base); int qemu_strtosz(const char *nptr, const char **end, uint64_t *result); int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result); int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *result); /* used to print char* safely */ #define STR_OR_NULL(str) ((str) ? (str) : "null") bool buffer_is_zero(const void *buf, size_t len); bool test_buffer_is_zero_next_accel(void); /* * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) * Input is limited to 14-bit numbers */ int uleb128_encode_small(uint8_t *out, uint32_t n); int uleb128_decode_small(const uint8_t *in, uint32_t *n); /** * qemu_pstrcmp0: * @str1: a non-NULL pointer to a C string (*str1 can be NULL) * @str2: a non-NULL pointer to a C string (*str2 can be NULL) * * Compares *str1 and *str2 with g_strcmp0(). * * Returns: an integer less than, equal to, or greater than zero, if * *str1 is <, == or > than *str2. */ int qemu_pstrcmp0(const char **str1, const char **str2); #endif
pmp-tool/PMP
src/qemu/src-pmp/hw/virtio/virtio-input-pci.c
<filename>src/qemu/src-pmp/hw/virtio/virtio-input-pci.c /* * Virtio input PCI Bindings * * This work is licensed under the terms of the GNU GPL, version 2 or * (at your option) any later version. See the COPYING file in the * top-level directory. */ #include "qemu/osdep.h" #include "virtio-pci.h" #include "hw/virtio/virtio-input.h" typedef struct VirtIOInputPCI VirtIOInputPCI; typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI; /* * virtio-input-pci: This extends VirtioPCIProxy. */ #define VIRTIO_INPUT_PCI(obj) \ OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI) struct VirtIOInputPCI { VirtIOPCIProxy parent_obj; VirtIOInput vdev; }; #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci" #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci" #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci" #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci" #define VIRTIO_INPUT_HID_PCI(obj) \ OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI) struct VirtIOInputHIDPCI { VirtIOPCIProxy parent_obj; VirtIOInputHID vdev; }; static Property virtio_input_pci_properties[] = { DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), DEFINE_PROP_END_OF_LIST(), }; static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) { VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev); DeviceState *vdev = DEVICE(&vinput->vdev); qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); virtio_pci_force_virtio_1(vpci_dev); object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_input_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); dc->props = virtio_input_pci_properties; k->realize = virtio_input_pci_realize; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); pcidev_k->class_id = PCI_CLASS_INPUT_OTHER; } static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); pcidev_k->class_id = PCI_CLASS_INPUT_KEYBOARD; } static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE; } static void virtio_keyboard_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_KEYBOARD); } static void virtio_mouse_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MOUSE); } static void virtio_tablet_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_TABLET); } static const TypeInfo virtio_input_pci_info = { .name = TYPE_VIRTIO_INPUT_PCI, .parent = TYPE_VIRTIO_PCI, .instance_size = sizeof(VirtIOInputPCI), .class_init = virtio_input_pci_class_init, .abstract = true, }; static const TypeInfo virtio_input_hid_pci_info = { .name = TYPE_VIRTIO_INPUT_HID_PCI, .parent = TYPE_VIRTIO_INPUT_PCI, .instance_size = sizeof(VirtIOInputHIDPCI), .abstract = true, }; static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info = { .generic_name = TYPE_VIRTIO_KEYBOARD_PCI, .parent = TYPE_VIRTIO_INPUT_HID_PCI, .class_init = virtio_input_hid_kbd_pci_class_init, .instance_size = sizeof(VirtIOInputHIDPCI), .instance_init = virtio_keyboard_initfn, }; static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info = { .generic_name = TYPE_VIRTIO_MOUSE_PCI, .parent = TYPE_VIRTIO_INPUT_HID_PCI, .class_init = virtio_input_hid_mouse_pci_class_init, .instance_size = sizeof(VirtIOInputHIDPCI), .instance_init = virtio_mouse_initfn, }; static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info = { .generic_name = TYPE_VIRTIO_TABLET_PCI, .parent = TYPE_VIRTIO_INPUT_HID_PCI, .instance_size = sizeof(VirtIOInputHIDPCI), .instance_init = virtio_tablet_initfn, }; static void virtio_pci_input_register(void) { /* Base types: */ type_register_static(&virtio_input_pci_info); type_register_static(&virtio_input_hid_pci_info); /* Implementations: */ virtio_pci_types_register(&virtio_keyboard_pci_info); virtio_pci_types_register(&virtio_mouse_pci_info); virtio_pci_types_register(&virtio_tablet_pci_info); } type_init(virtio_pci_input_register)
pmp-tool/PMP
src/qemu/src-pmp/tests/libqos/qgraph.c
<reponame>pmp-tool/PMP /* * libqos driver framework * * Copyright (c) 2018 <NAME> <<EMAIL>> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/> */ #include "qemu/osdep.h" #include "libqtest.h" #include "qemu/queue.h" #include "libqos/qgraph_internal.h" #include "libqos/qgraph.h" #define QGRAPH_PRINT_DEBUG 0 #define QOS_ROOT "" typedef struct QOSStackElement QOSStackElement; /* Graph Edge.*/ struct QOSGraphEdge { QOSEdgeType type; char *dest; void *arg; /* just for QEDGE_CONTAINS * and QEDGE_CONSUMED_BY */ char *extra_device_opts; /* added to -device option, "," is * automatically added */ char *before_cmd_line; /* added before node cmd_line */ char *after_cmd_line; /* added after -device options */ char *edge_name; /* used by QEDGE_CONTAINS */ QSLIST_ENTRY(QOSGraphEdge) edge_list; }; typedef QSLIST_HEAD(, QOSGraphEdge) QOSGraphEdgeList; /** * Stack used to keep track of the discovered path when using * the DFS algorithm */ struct QOSStackElement { QOSGraphNode *node; QOSStackElement *parent; QOSGraphEdge *parent_edge; int length; }; /* Each enty in these hash table will consist of <string, node/edge> pair. */ static GHashTable *edge_table; static GHashTable *node_table; /* stack used by the DFS algorithm to store the path from machine to test */ static QOSStackElement qos_node_stack[QOS_PATH_MAX_ELEMENT_SIZE]; static int qos_node_tos; /** * add_edge(): creates an edge of type @type * from @source to @dest node, and inserts it in the * edges hash table * * Nodes @source and @dest do not necessarily need to exist. * Possibility to add also options (see #QOSGraphEdgeOptions) * edge->edge_name is used as identifier for get_device relationships, * so by default is equal to @dest. */ static void add_edge(const char *source, const char *dest, QOSEdgeType type, QOSGraphEdgeOptions *opts) { char *key; QOSGraphEdgeList *list = g_hash_table_lookup(edge_table, source); if (!list) { list = g_new0(QOSGraphEdgeList, 1); key = g_strdup(source); g_hash_table_insert(edge_table, key, list); } if (!opts) { opts = &(QOSGraphEdgeOptions) { }; } QOSGraphEdge *edge = g_new0(QOSGraphEdge, 1); edge->type = type; edge->dest = g_strdup(dest); edge->edge_name = g_strdup(opts->edge_name ?: dest); edge->arg = g_memdup(opts->arg, opts->size_arg); edge->before_cmd_line = opts->before_cmd_line ? g_strconcat(" ", opts->before_cmd_line, NULL) : NULL; edge->extra_device_opts = opts->extra_device_opts ? g_strconcat(",", opts->extra_device_opts, NULL) : NULL; edge->after_cmd_line = opts->after_cmd_line ? g_strconcat(" ", opts->after_cmd_line, NULL) : NULL; QSLIST_INSERT_HEAD(list, edge, edge_list); } /* destroy_edges(): frees all edges inside a given @list */ static void destroy_edges(void *list) { QOSGraphEdge *temp; QOSGraphEdgeList *elist = list; while (!QSLIST_EMPTY(elist)) { temp = QSLIST_FIRST(elist); QSLIST_REMOVE_HEAD(elist, edge_list); g_free(temp->dest); g_free(temp->before_cmd_line); g_free(temp->after_cmd_line); g_free(temp->extra_device_opts); g_free(temp->edge_name); g_free(temp->arg); g_free(temp); } g_free(elist); } /** * create_node(): creates a node @name of type @type * and inserts it to the nodes hash table. * By default, node is not available. */ static QOSGraphNode *create_node(const char *name, QOSNodeType type) { if (g_hash_table_lookup(node_table, name)) { g_printerr("Node %s already created\n", name); abort(); } QOSGraphNode *node = g_new0(QOSGraphNode, 1); node->type = type; node->available = false; node->name = g_strdup(name); g_hash_table_insert(node_table, node->name, node); return node; } /** * destroy_node(): frees a node @val from the nodes hash table. * Note that node->name is not free'd since it will represent the * hash table key */ static void destroy_node(void *val) { QOSGraphNode *node = val; g_free(node->command_line); g_free(node); } /** * destroy_string(): frees @key from the nodes hash table. * Actually frees the node->name */ static void destroy_string(void *key) { g_free(key); } /** * search_node(): search for a node @key in the nodes hash table * Returns the QOSGraphNode if found, #NULL otherwise */ static QOSGraphNode *search_node(const char *key) { return g_hash_table_lookup(node_table, key); } /** * get_edgelist(): returns the edge list (value) assigned to * the @key in the edge hash table. * This list will contain all edges with source equal to @key * * Returns: on success: the %QOSGraphEdgeList * otherwise: abort() */ static QOSGraphEdgeList *get_edgelist(const char *key) { return g_hash_table_lookup(edge_table, key); } /** * search_list_edges(): search for an edge with destination @dest * in the given @edgelist. * * Returns: on success: the %QOSGraphEdge * otherwise: #NULL */ static QOSGraphEdge *search_list_edges(QOSGraphEdgeList *edgelist, const char *dest) { QOSGraphEdge *tmp, *next; if (!edgelist) { return NULL; } QSLIST_FOREACH_SAFE(tmp, edgelist, edge_list, next) { if (g_strcmp0(tmp->dest, dest) == 0) { break; } } return tmp; } /** * search_machine(): search for a machine @name in the node hash * table. A machine is the child of the root node. * This function forces the research in the childs of the root, * to check the node is a proper machine * * Returns: on success: the %QOSGraphNode * otherwise: #NULL */ static QOSGraphNode *search_machine(const char *name) { QOSGraphNode *n; QOSGraphEdgeList *root_list = get_edgelist(QOS_ROOT); QOSGraphEdge *e = search_list_edges(root_list, name); if (!e) { return NULL; } n = search_node(e->dest); if (n->type == QNODE_MACHINE) { return n; } return NULL; } /** * create_interface(): checks if there is already * a node @node in the node hash table, if not * creates a node @node of type #QNODE_INTERFACE * and inserts it. If there is one, check it's * a #QNODE_INTERFACE and abort() if it's not. */ static void create_interface(const char *node) { QOSGraphNode *interface; interface = search_node(node); if (!interface) { create_node(node, QNODE_INTERFACE); } else if (interface->type != QNODE_INTERFACE) { fprintf(stderr, "Error: Node %s is not an interface\n", node); abort(); } } /** * build_machine_cmd_line(): builds the command line for the machine * @node. The node name must be a valid qemu identifier, since it * will be used to build the command line. * * It is also possible to pass an optional @args that will be * concatenated to the command line. * * For machines, prepend -M to the machine name. ", @rgs" is added * after the -M <machine> command. */ static void build_machine_cmd_line(QOSGraphNode *node, const char *args) { char *machine = qos_get_machine_type(node->name); if (args) { node->command_line = g_strconcat("-M ", machine, ",", args, NULL); } else { node->command_line = g_strconcat("-M ", machine, " ", NULL); } } /** * build_driver_cmd_line(): builds the command line for the driver * @node. The node name must be a valid qemu identifier, since it * will be used to build the command line. * * Driver do not need additional command line, since it will be * provided by the edge options. * * For drivers, prepend -device to the node name. */ static void build_driver_cmd_line(QOSGraphNode *node) { node->command_line = g_strconcat(" -device ", node->name, NULL); } /* qos_print_cb(): callback prints all path found by the DFS algorithm. */ static void qos_print_cb(QOSGraphNode *path, int length) { #if QGRAPH_PRINT_DEBUG printf("%d elements\n", length); if (!path) { return; } while (path->path_edge) { printf("%s ", path->name); switch (path->path_edge->type) { case QEDGE_PRODUCES: printf("--PRODUCES--> "); break; case QEDGE_CONSUMED_BY: printf("--CONSUMED_BY--> "); break; case QEDGE_CONTAINS: printf("--CONTAINS--> "); break; } path = search_node(path->path_edge->dest); } printf("%s\n\n", path->name); #endif } /* qos_push(): push a node @el and edge @e in the qos_node_stack */ static void qos_push(QOSGraphNode *el, QOSStackElement *parent, QOSGraphEdge *e) { int len = 0; /* root is not counted */ if (qos_node_tos == QOS_PATH_MAX_ELEMENT_SIZE) { g_printerr("QOSStack: full stack, cannot push"); abort(); } if (parent) { len = parent->length + 1; } qos_node_stack[qos_node_tos++] = (QOSStackElement) { .node = el, .parent = parent, .parent_edge = e, .length = len, }; } /* qos_tos(): returns the top of stack, without popping */ static QOSStackElement *qos_tos(void) { return &qos_node_stack[qos_node_tos - 1]; } /* qos_pop(): pops an element from the tos, setting it unvisited*/ static QOSStackElement *qos_pop(void) { if (qos_node_tos == 0) { g_printerr("QOSStack: empty stack, cannot pop"); abort(); } QOSStackElement *e = qos_tos(); e->node->visited = false; qos_node_tos--; return e; } /** * qos_reverse_path(): reverses the found path, going from * test-to-machine to machine-to-test */ static QOSGraphNode *qos_reverse_path(QOSStackElement *el) { if (!el) { return NULL; } el->node->path_edge = NULL; while (el->parent) { el->parent->node->path_edge = el->parent_edge; el = el->parent; } return el->node; } /** * qos_traverse_graph(): graph-walking algorithm, using Depth First Search it * starts from the root @machine and walks all possible path until it * reaches a test node. * At that point, it reverses the path found and invokes the @callback. * * Being Depth First Search, time complexity is O(|V| + |E|), while * space is O(|V|). In this case, the maximum stack size is set by * QOS_PATH_MAX_ELEMENT_SIZE. */ static void qos_traverse_graph(QOSGraphNode *root, QOSTestCallback callback) { QOSGraphNode *v, *dest_node, *path; QOSStackElement *s_el; QOSGraphEdge *e, *next; QOSGraphEdgeList *list; qos_push(root, NULL, NULL); while (qos_node_tos > 0) { s_el = qos_tos(); v = s_el->node; if (v->visited) { qos_pop(); continue; } v->visited = true; list = get_edgelist(v->name); if (!list) { qos_pop(); if (v->type == QNODE_TEST) { v->visited = false; path = qos_reverse_path(s_el); callback(path, s_el->length); } } else { QSLIST_FOREACH_SAFE(e, list, edge_list, next) { dest_node = search_node(e->dest); if (!dest_node) { fprintf(stderr, "node %s in %s -> %s does not exist\n", e->dest, v->name, e->dest); abort(); } if (!dest_node->visited && dest_node->available) { qos_push(dest_node, s_el, e); } } } } } /* QGRAPH API*/ QOSGraphNode *qos_graph_get_node(const char *key) { return search_node(key); } bool qos_graph_has_node(const char *node) { QOSGraphNode *n = search_node(node); return n != NULL; } QOSNodeType qos_graph_get_node_type(const char *node) { QOSGraphNode *n = search_node(node); if (n) { return n->type; } return -1; } bool qos_graph_get_node_availability(const char *node) { QOSGraphNode *n = search_node(node); if (n) { return n->available; } return false; } QOSGraphEdge *qos_graph_get_edge(const char *node, const char *dest) { QOSGraphEdgeList *list = get_edgelist(node); return search_list_edges(list, dest); } QOSEdgeType qos_graph_edge_get_type(QOSGraphEdge *edge) { if (!edge) { return -1; } return edge->type;; } char *qos_graph_edge_get_dest(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->dest; } void *qos_graph_edge_get_arg(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->arg; } char *qos_graph_edge_get_after_cmd_line(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->after_cmd_line; } char *qos_graph_edge_get_before_cmd_line(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->before_cmd_line; } char *qos_graph_edge_get_extra_device_opts(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->extra_device_opts; } char *qos_graph_edge_get_name(QOSGraphEdge *edge) { if (!edge) { return NULL; } return edge->edge_name; } bool qos_graph_has_edge(const char *start, const char *dest) { QOSGraphEdgeList *list = get_edgelist(start); QOSGraphEdge *e = search_list_edges(list, dest); return e != NULL; } QOSGraphNode *qos_graph_get_machine(const char *node) { return search_machine(node); } bool qos_graph_has_machine(const char *node) { QOSGraphNode *m = search_machine(node); return m != NULL; } void qos_print_graph(void) { qos_graph_foreach_test_path(qos_print_cb); } void qos_graph_init(void) { if (!node_table) { node_table = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_string, destroy_node); create_node(QOS_ROOT, QNODE_DRIVER); } if (!edge_table) { edge_table = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_string, destroy_edges); } } void qos_graph_destroy(void) { if (node_table) { g_hash_table_destroy(node_table); } if (edge_table) { g_hash_table_destroy(edge_table); } node_table = NULL; edge_table = NULL; } void qos_node_destroy(void *key) { g_hash_table_remove(node_table, key); } void qos_edge_destroy(void *key) { g_hash_table_remove(edge_table, key); } void qos_add_test(const char *name, const char *interface, QOSTestFunc test_func, QOSGraphTestOptions *opts) { QOSGraphNode *node; char *test_name = g_strdup_printf("%s-tests/%s", interface, name);; if (!opts) { opts = &(QOSGraphTestOptions) { }; } node = create_node(test_name, QNODE_TEST); node->u.test.function = test_func; node->u.test.arg = opts->arg; assert(!opts->edge.arg); assert(!opts->edge.size_arg); node->u.test.before = opts->before; node->u.test.subprocess = opts->subprocess; node->available = true; add_edge(interface, test_name, QEDGE_CONSUMED_BY, &opts->edge); g_free(test_name); } void qos_node_create_machine(const char *name, QOSCreateMachineFunc function) { qos_node_create_machine_args(name, function, NULL); } void qos_node_create_machine_args(const char *name, QOSCreateMachineFunc function, const char *opts) { QOSGraphNode *node = create_node(name, QNODE_MACHINE); build_machine_cmd_line(node, opts); node->u.machine.constructor = function; add_edge(QOS_ROOT, name, QEDGE_CONTAINS, NULL); } void qos_node_create_driver(const char *name, QOSCreateDriverFunc function) { QOSGraphNode *node = create_node(name, QNODE_DRIVER); build_driver_cmd_line(node); node->u.driver.constructor = function; } void qos_node_contains(const char *container, const char *contained, ...) { va_list va; va_start(va, contained); QOSGraphEdgeOptions *opts; do { opts = va_arg(va, QOSGraphEdgeOptions *); add_edge(container, contained, QEDGE_CONTAINS, opts); } while (opts != NULL); va_end(va); } void qos_node_produces(const char *producer, const char *interface) { create_interface(interface); add_edge(producer, interface, QEDGE_PRODUCES, NULL); } void qos_node_consumes(const char *consumer, const char *interface, QOSGraphEdgeOptions *opts) { create_interface(interface); add_edge(interface, consumer, QEDGE_CONSUMED_BY, opts); } void qos_graph_node_set_availability(const char *node, bool av) { QOSGraphEdgeList *elist; QOSGraphNode *n = search_node(node); QOSGraphEdge *e, *next; if (!n) { return; } n->available = av; elist = get_edgelist(node); if (!elist) { return; } QSLIST_FOREACH_SAFE(e, elist, edge_list, next) { if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES) { qos_graph_node_set_availability(e->dest, av); } } } void qos_graph_foreach_test_path(QOSTestCallback fn) { QOSGraphNode *root = qos_graph_get_node(QOS_ROOT); qos_traverse_graph(root, fn); } QOSGraphObject *qos_machine_new(QOSGraphNode *node, QTestState *qts) { QOSGraphObject *obj; g_assert(node->type == QNODE_MACHINE); obj = node->u.machine.constructor(qts); obj->free = g_free; return obj; } QOSGraphObject *qos_driver_new(QOSGraphNode *node, QOSGraphObject *parent, QGuestAllocator *alloc, void *arg) { QOSGraphObject *obj; g_assert(node->type == QNODE_DRIVER); obj = node->u.driver.constructor(parent, alloc, arg); obj->free = g_free; return obj; } void qos_object_destroy(QOSGraphObject *obj) { if (!obj) { return; } if (obj->destructor) { obj->destructor(obj); } if (obj->free) { obj->free(obj); } } void qos_object_queue_destroy(QOSGraphObject *obj) { g_test_queue_destroy((GDestroyNotify) qos_object_destroy, obj); } void qos_object_start_hw(QOSGraphObject *obj) { if (obj->start_hw) { obj->start_hw(obj); } } char *qos_get_machine_type(char *name) { while (*name != '\0' && *name != '/') { name++; } if (!*name || !name[1]) { fprintf(stderr, "Machine name has to be of the form <arch>/<machine>\n"); abort(); } return name + 1; } void qos_delete_cmd_line(const char *name) { QOSGraphNode *node = search_node(name); if (node) { g_free(node->command_line); node->command_line = NULL; } }
pmp-tool/PMP
src/qemu/src-pmp/tests/libqos/arm-xilinx-zynq-a9-machine.c
/* * libqos driver framework * * Copyright (c) 2018 <NAME> <<EMAIL>> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/> */ #include "qemu/osdep.h" #include "libqtest.h" #include "libqos/malloc.h" #include "libqos/qgraph.h" #include "sdhci.h" typedef struct QXilinxZynqA9Machine QXilinxZynqA9Machine; struct QXilinxZynqA9Machine { QOSGraphObject obj; QGuestAllocator alloc; QSDHCI_MemoryMapped sdhci; }; #define ARM_PAGE_SIZE 4096 #define XILINX_ZYNQ_A9_RAM_ADDR 0 #define XILINX_ZYNQ_A9_RAM_SIZE 0x20000000 static void *xilinx_zynq_a9_get_driver(void *object, const char *interface) { QXilinxZynqA9Machine *machine = object; if (!g_strcmp0(interface, "memory")) { return &machine->alloc; } fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", interface); g_assert_not_reached(); } static QOSGraphObject *xilinx_zynq_a9_get_device(void *obj, const char *device) { QXilinxZynqA9Machine *machine = obj; if (!g_strcmp0(device, "generic-sdhci")) { return &machine->sdhci.obj; } fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", device); g_assert_not_reached(); } static void xilinx_zynq_a9_destructor(QOSGraphObject *obj) { QXilinxZynqA9Machine *machine = (QXilinxZynqA9Machine *) obj; alloc_destroy(&machine->alloc); } static void *qos_create_machine_arm_xilinx_zynq_a9(QTestState *qts) { QXilinxZynqA9Machine *machine = g_new0(QXilinxZynqA9Machine, 1); alloc_init(&machine->alloc, 0, XILINX_ZYNQ_A9_RAM_ADDR + (1 << 20), XILINX_ZYNQ_A9_RAM_ADDR + XILINX_ZYNQ_A9_RAM_SIZE, ARM_PAGE_SIZE); machine->obj.get_device = xilinx_zynq_a9_get_device; machine->obj.get_driver = xilinx_zynq_a9_get_driver; machine->obj.destructor = xilinx_zynq_a9_destructor; /* Datasheet: UG585 (v1.12.1) */ qos_init_sdhci_mm(&machine->sdhci, qts, 0xe0100000, &(QSDHCIProperties) { .version = 2, .baseclock = 0, .capab.sdma = true, .capab.reg = 0x69ec0080, }); return &machine->obj; } static void xilinx_zynq_a9_register_nodes(void) { qos_node_create_machine("arm/xilinx-zynq-a9", qos_create_machine_arm_xilinx_zynq_a9); qos_node_contains("arm/xilinx-zynq-a9", "generic-sdhci", NULL); } libqos_init(xilinx_zynq_a9_register_nodes);
pmp-tool/PMP
src/qemu/src-pmp/tests/libqos/e1000e.c
<reponame>pmp-tool/PMP /* * libqos driver framework * * Copyright (c) 2018 <NAME> <<EMAIL>> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/> */ #include "qemu/osdep.h" #include "libqtest.h" #include "qemu-common.h" #include "libqos/pci-pc.h" #include "qemu/sockets.h" #include "qemu/iov.h" #include "qemu/bitops.h" #include "libqos/malloc.h" #include "libqos/qgraph.h" #include "e1000e.h" #define E1000E_IMS (0x00d0) #define E1000E_STATUS (0x0008) #define E1000E_STATUS_LU BIT(1) #define E1000E_STATUS_ASDV1000 BIT(9) #define E1000E_CTRL (0x0000) #define E1000E_CTRL_RESET BIT(26) #define E1000E_RCTL (0x0100) #define E1000E_RCTL_EN BIT(1) #define E1000E_RCTL_UPE BIT(3) #define E1000E_RCTL_MPE BIT(4) #define E1000E_RFCTL (0x5008) #define E1000E_RFCTL_EXTEN BIT(15) #define E1000E_TCTL (0x0400) #define E1000E_TCTL_EN BIT(1) #define E1000E_CTRL_EXT (0x0018) #define E1000E_CTRL_EXT_DRV_LOAD BIT(28) #define E1000E_CTRL_EXT_TXLSFLOW BIT(22) #define E1000E_IVAR (0x00E4) #define E1000E_IVAR_TEST_CFG ((E1000E_RX0_MSG_ID << 0) | BIT(3) | \ (E1000E_TX0_MSG_ID << 8) | BIT(11) | \ (E1000E_OTHER_MSG_ID << 16) | BIT(19) | \ BIT(31)) #define E1000E_RING_LEN (0x1000) #define E1000E_TDBAL (0x3800) #define E1000E_TDBAH (0x3804) #define E1000E_TDH (0x3810) #define E1000E_RDBAL (0x2800) #define E1000E_RDBAH (0x2804) #define E1000E_RDH (0x2810) #define E1000E_TXD_LEN (16) #define E1000E_RXD_LEN (16) static void e1000e_macreg_write(QE1000E *d, uint32_t reg, uint32_t val) { QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); qpci_io_writel(&d_pci->pci_dev, d_pci->mac_regs, reg, val); } static uint32_t e1000e_macreg_read(QE1000E *d, uint32_t reg) { QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); return qpci_io_readl(&d_pci->pci_dev, d_pci->mac_regs, reg); } void e1000e_tx_ring_push(QE1000E *d, void *descr) { uint32_t tail = e1000e_macreg_read(d, E1000E_TDT); uint32_t len = e1000e_macreg_read(d, E1000E_TDLEN) / E1000E_TXD_LEN; memwrite(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); e1000e_macreg_write(d, E1000E_TDT, (tail + 1) % len); /* Read WB data for the packet transmitted */ memread(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); } void e1000e_rx_ring_push(QE1000E *d, void *descr) { uint32_t tail = e1000e_macreg_read(d, E1000E_RDT); uint32_t len = e1000e_macreg_read(d, E1000E_RDLEN) / E1000E_RXD_LEN; memwrite(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); e1000e_macreg_write(d, E1000E_RDT, (tail + 1) % len); /* Read WB data for the packet received */ memread(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); } static void e1000e_foreach_callback(QPCIDevice *dev, int devfn, void *data) { QPCIDevice *res = data; memcpy(res, dev, sizeof(QPCIDevice)); g_free(dev); } void e1000e_wait_isr(QE1000E *d, uint16_t msg_id) { QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; do { if (qpci_msix_pending(&d_pci->pci_dev, msg_id)) { return; } clock_step(10000); } while (g_get_monotonic_time() < end_time); g_error("Timeout expired"); } static void e1000e_pci_destructor(QOSGraphObject *obj) { QE1000E_PCI *epci = (QE1000E_PCI *) obj; qpci_iounmap(&epci->pci_dev, epci->mac_regs); qpci_msix_disable(&epci->pci_dev); } static void e1000e_pci_start_hw(QOSGraphObject *obj) { QE1000E_PCI *d = (QE1000E_PCI *) obj; uint32_t val; /* Enable the device */ qpci_device_enable(&d->pci_dev); /* Reset the device */ val = e1000e_macreg_read(&d->e1000e, E1000E_CTRL); e1000e_macreg_write(&d->e1000e, E1000E_CTRL, val | E1000E_CTRL_RESET); /* Enable and configure MSI-X */ qpci_msix_enable(&d->pci_dev); e1000e_macreg_write(&d->e1000e, E1000E_IVAR, E1000E_IVAR_TEST_CFG); /* Check the device status - link and speed */ val = e1000e_macreg_read(&d->e1000e, E1000E_STATUS); g_assert_cmphex(val & (E1000E_STATUS_LU | E1000E_STATUS_ASDV1000), ==, E1000E_STATUS_LU | E1000E_STATUS_ASDV1000); /* Initialize TX/RX logic */ e1000e_macreg_write(&d->e1000e, E1000E_RCTL, 0); e1000e_macreg_write(&d->e1000e, E1000E_TCTL, 0); /* Notify the device that the driver is ready */ val = e1000e_macreg_read(&d->e1000e, E1000E_CTRL_EXT); e1000e_macreg_write(&d->e1000e, E1000E_CTRL_EXT, val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW); e1000e_macreg_write(&d->e1000e, E1000E_TDBAL, (uint32_t) d->e1000e.tx_ring); e1000e_macreg_write(&d->e1000e, E1000E_TDBAH, (uint32_t) (d->e1000e.tx_ring >> 32)); e1000e_macreg_write(&d->e1000e, E1000E_TDLEN, E1000E_RING_LEN); e1000e_macreg_write(&d->e1000e, E1000E_TDT, 0); e1000e_macreg_write(&d->e1000e, E1000E_TDH, 0); /* Enable transmit */ e1000e_macreg_write(&d->e1000e, E1000E_TCTL, E1000E_TCTL_EN); e1000e_macreg_write(&d->e1000e, E1000E_RDBAL, (uint32_t)d->e1000e.rx_ring); e1000e_macreg_write(&d->e1000e, E1000E_RDBAH, (uint32_t)(d->e1000e.rx_ring >> 32)); e1000e_macreg_write(&d->e1000e, E1000E_RDLEN, E1000E_RING_LEN); e1000e_macreg_write(&d->e1000e, E1000E_RDT, 0); e1000e_macreg_write(&d->e1000e, E1000E_RDH, 0); /* Enable receive */ e1000e_macreg_write(&d->e1000e, E1000E_RFCTL, E1000E_RFCTL_EXTEN); e1000e_macreg_write(&d->e1000e, E1000E_RCTL, E1000E_RCTL_EN | E1000E_RCTL_UPE | E1000E_RCTL_MPE); /* Enable all interrupts */ e1000e_macreg_write(&d->e1000e, E1000E_IMS, 0xFFFFFFFF); } static void *e1000e_pci_get_driver(void *obj, const char *interface) { QE1000E_PCI *epci = obj; if (!g_strcmp0(interface, "e1000e-if")) { return &epci->e1000e; } /* implicit contains */ if (!g_strcmp0(interface, "pci-device")) { return &epci->pci_dev; } fprintf(stderr, "%s not present in e1000e\n", interface); g_assert_not_reached(); } static void *e1000e_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { QE1000E_PCI *d = g_new0(QE1000E_PCI, 1); QPCIBus *bus = pci_bus; QPCIAddress *address = addr; qpci_device_foreach(bus, address->vendor_id, address->device_id, e1000e_foreach_callback, &d->pci_dev); /* Map BAR0 (mac registers) */ d->mac_regs = qpci_iomap(&d->pci_dev, 0, NULL); /* Allocate and setup TX ring */ d->e1000e.tx_ring = guest_alloc(alloc, E1000E_RING_LEN); g_assert(d->e1000e.tx_ring != 0); /* Allocate and setup RX ring */ d->e1000e.rx_ring = guest_alloc(alloc, E1000E_RING_LEN); g_assert(d->e1000e.rx_ring != 0); d->obj.get_driver = e1000e_pci_get_driver; d->obj.start_hw = e1000e_pci_start_hw; d->obj.destructor = e1000e_pci_destructor; return &d->obj; } static void e1000e_register_nodes(void) { QPCIAddress addr = { .vendor_id = 0x8086, .device_id = 0x10D3, }; /* FIXME: every test using this node needs to setup a -netdev socket,id=hs0 * otherwise QEMU is not going to start */ QOSGraphEdgeOptions opts = { .extra_device_opts = "netdev=hs0", }; add_qpci_address(&opts, &addr); qos_node_create_driver("e1000e", e1000e_pci_create); qos_node_consumes("e1000e", "pci-bus", &opts); } libqos_init(e1000e_register_nodes);
pmp-tool/PMP
src/qemu/src-pmp/hw/tpm/tpm_crb.c
/* * tpm_crb.c - QEMU's TPM CRB interface emulator * * Copyright (c) 2018 Red Hat, Inc. * * Authors: * <NAME> <<EMAIL>> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. * * tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface * as defined in TCG PC Client Platform TPM Profile (PTP) Specification * Family “2.0” Level 00 Revision 01.03 v22 */ #include "qemu/osdep.h" #include "qemu-common.h" #include "qapi/error.h" #include "exec/address-spaces.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "hw/pci/pci_ids.h" #include "hw/acpi/tpm.h" #include "migration/vmstate.h" #include "sysemu/tpm_backend.h" #include "sysemu/reset.h" #include "tpm_int.h" #include "tpm_util.h" #include "tpm_ppi.h" #include "trace.h" typedef struct CRBState { DeviceState parent_obj; TPMBackend *tpmbe; TPMBackendCmd cmd; uint32_t regs[TPM_CRB_R_MAX]; MemoryRegion mmio; MemoryRegion cmdmem; size_t be_buffer_size; bool ppi_enabled; TPMPPI ppi; } CRBState; #define CRB(obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB) #define CRB_INTF_TYPE_CRB_ACTIVE 0b1 #define CRB_INTF_VERSION_CRB 0b1 #define CRB_INTF_CAP_LOCALITY_0_ONLY 0b0 #define CRB_INTF_CAP_IDLE_FAST 0b0 #define CRB_INTF_CAP_XFER_SIZE_64 0b11 #define CRB_INTF_CAP_FIFO_NOT_SUPPORTED 0b0 #define CRB_INTF_CAP_CRB_SUPPORTED 0b1 #define CRB_INTF_IF_SELECTOR_CRB 0b1 #define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - A_CRB_DATA_BUFFER) enum crb_loc_ctrl { CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0), CRB_LOC_CTRL_RELINQUISH = BIT(1), CRB_LOC_CTRL_SEIZE = BIT(2), CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT = BIT(3), }; enum crb_ctrl_req { CRB_CTRL_REQ_CMD_READY = BIT(0), CRB_CTRL_REQ_GO_IDLE = BIT(1), }; enum crb_start { CRB_START_INVOKE = BIT(0), }; enum crb_cancel { CRB_CANCEL_INVOKE = BIT(0), }; #define TPM_CRB_NO_LOCALITY 0xff static uint64_t tpm_crb_mmio_read(void *opaque, hwaddr addr, unsigned size) { CRBState *s = CRB(opaque); void *regs = (void *)&s->regs + (addr & ~3); unsigned offset = addr & 3; uint32_t val = *(uint32_t *)regs >> (8 * offset); switch (addr) { case A_CRB_LOC_STATE: val |= !tpm_backend_get_tpm_established_flag(s->tpmbe); break; } trace_tpm_crb_mmio_read(addr, size, val); return val; } static uint8_t tpm_crb_get_active_locty(CRBState *s) { if (!ARRAY_FIELD_EX32(s->regs, CRB_LOC_STATE, locAssigned)) { return TPM_CRB_NO_LOCALITY; } return ARRAY_FIELD_EX32(s->regs, CRB_LOC_STATE, activeLocality); } static void tpm_crb_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { CRBState *s = CRB(opaque); uint8_t locty = addr >> 12; trace_tpm_crb_mmio_write(addr, size, val); switch (addr) { case A_CRB_CTRL_REQ: switch (val) { case CRB_CTRL_REQ_CMD_READY: ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS, tpmIdle, 0); break; case CRB_CTRL_REQ_GO_IDLE: ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS, tpmIdle, 1); break; } break; case A_CRB_CTRL_CANCEL: if (val == CRB_CANCEL_INVOKE && s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) { tpm_backend_cancel_cmd(s->tpmbe); } break; case A_CRB_CTRL_START: if (val == CRB_START_INVOKE && !(s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) && tpm_crb_get_active_locty(s) == locty) { void *mem = memory_region_get_ram_ptr(&s->cmdmem); s->regs[R_CRB_CTRL_START] |= CRB_START_INVOKE; s->cmd = (TPMBackendCmd) { .in = mem, .in_len = MIN(tpm_cmd_get_size(mem), s->be_buffer_size), .out = mem, .out_len = s->be_buffer_size, }; tpm_backend_deliver_request(s->tpmbe, &s->cmd); } break; case A_CRB_LOC_CTRL: switch (val) { case CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT: /* not loc 3 or 4 */ break; case CRB_LOC_CTRL_RELINQUISH: ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE, locAssigned, 0); ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS, Granted, 0); break; case CRB_LOC_CTRL_REQUEST_ACCESS: ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS, Granted, 1); ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS, beenSeized, 0); ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE, locAssigned, 1); break; } break; } } static const MemoryRegionOps tpm_crb_memory_ops = { .read = tpm_crb_mmio_read, .write = tpm_crb_mmio_write, .endianness = DEVICE_LITTLE_ENDIAN, .valid = { .min_access_size = 1, .max_access_size = 4, }, }; static void tpm_crb_request_completed(TPMIf *ti, int ret) { CRBState *s = CRB(ti); s->regs[R_CRB_CTRL_START] &= ~CRB_START_INVOKE; if (ret != 0) { ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS, tpmSts, 1); /* fatal error */ } } static enum TPMVersion tpm_crb_get_version(TPMIf *ti) { CRBState *s = CRB(ti); return tpm_backend_get_tpm_version(s->tpmbe); } static int tpm_crb_pre_save(void *opaque) { CRBState *s = opaque; tpm_backend_finish_sync(s->tpmbe); return 0; } static const VMStateDescription vmstate_tpm_crb = { .name = "tpm-crb", .pre_save = tpm_crb_pre_save, .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, CRBState, TPM_CRB_R_MAX), VMSTATE_END_OF_LIST(), } }; static Property tpm_crb_properties[] = { DEFINE_PROP_TPMBE("tpmdev", CRBState, tpmbe), DEFINE_PROP_BOOL("ppi", CRBState, ppi_enabled, true), DEFINE_PROP_END_OF_LIST(), }; static void tpm_crb_reset(void *dev) { CRBState *s = CRB(dev); if (s->ppi_enabled) { tpm_ppi_reset(&s->ppi); } tpm_backend_reset(s->tpmbe); memset(s->regs, 0, sizeof(s->regs)); ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE, tpmRegValidSts, 1); ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS, tpmIdle, 1); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, InterfaceType, CRB_INTF_TYPE_CRB_ACTIVE); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, InterfaceVersion, CRB_INTF_VERSION_CRB); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, CapLocality, CRB_INTF_CAP_LOCALITY_0_ONLY); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, CapCRBIdleBypass, CRB_INTF_CAP_IDLE_FAST); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, CapDataXferSizeSupport, CRB_INTF_CAP_XFER_SIZE_64); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, CapFIFO, CRB_INTF_CAP_FIFO_NOT_SUPPORTED); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, CapCRB, CRB_INTF_CAP_CRB_SUPPORTED); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, InterfaceSelector, CRB_INTF_IF_SELECTOR_CRB); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID, RID, 0b0000); ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID2, VID, PCI_VENDOR_ID_IBM); s->regs[R_CRB_CTRL_CMD_SIZE] = CRB_CTRL_CMD_SIZE; s->regs[R_CRB_CTRL_CMD_LADDR] = TPM_CRB_ADDR_BASE + A_CRB_DATA_BUFFER; s->regs[R_CRB_CTRL_RSP_SIZE] = CRB_CTRL_CMD_SIZE; s->regs[R_CRB_CTRL_RSP_ADDR] = TPM_CRB_ADDR_BASE + A_CRB_DATA_BUFFER; s->be_buffer_size = MIN(tpm_backend_get_buffer_size(s->tpmbe), CRB_CTRL_CMD_SIZE); tpm_backend_startup_tpm(s->tpmbe, s->be_buffer_size); } static void tpm_crb_realize(DeviceState *dev, Error **errp) { CRBState *s = CRB(dev); if (!tpm_find()) { error_setg(errp, "at most one TPM device is permitted"); return; } if (!s->tpmbe) { error_setg(errp, "'tpmdev' property is required"); return; } memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s, "tpm-crb-mmio", sizeof(s->regs)); memory_region_init_ram(&s->cmdmem, OBJECT(s), "tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp); memory_region_add_subregion(get_system_memory(), TPM_CRB_ADDR_BASE, &s->mmio); memory_region_add_subregion(get_system_memory(), TPM_CRB_ADDR_BASE + sizeof(s->regs), &s->cmdmem); if (s->ppi_enabled) { tpm_ppi_init(&s->ppi, get_system_memory(), TPM_PPI_ADDR_BASE, OBJECT(s)); } qemu_register_reset(tpm_crb_reset, dev); } static void tpm_crb_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); TPMIfClass *tc = TPM_IF_CLASS(klass); dc->realize = tpm_crb_realize; dc->props = tpm_crb_properties; dc->vmsd = &vmstate_tpm_crb; dc->user_creatable = true; tc->model = TPM_MODEL_TPM_CRB; tc->get_version = tpm_crb_get_version; tc->request_completed = tpm_crb_request_completed; set_bit(DEVICE_CATEGORY_MISC, dc->categories); } static const TypeInfo tpm_crb_info = { .name = TYPE_TPM_CRB, /* could be TYPE_SYS_BUS_DEVICE (or LPC etc) */ .parent = TYPE_DEVICE, .instance_size = sizeof(CRBState), .class_init = tpm_crb_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_TPM_IF }, { } } }; static void tpm_crb_register(void) { type_register_static(&tpm_crb_info); } type_init(tpm_crb_register)
pmp-tool/PMP
src/qemu/src-pmp/include/hw/i386/pc.h
#ifndef HW_PC_H #define HW_PC_H #include "qemu-common.h" #include "exec/memory.h" #include "hw/boards.h" #include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/block/flash.h" #include "net/net.h" #include "hw/i386/ioapic.h" #include "qemu/range.h" #include "qemu/bitmap.h" #include "sysemu/sysemu.h" #include "hw/pci/pci.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" #include "hw/acpi/acpi_dev_interface.h" #define HPET_INTCAP "hpet-intcap" /** * PCMachineState: * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling * @boot_cpus: number of present VCPUs */ struct PCMachineState { /*< private >*/ MachineState parent_obj; /* <public> */ /* State for other subsystems/APIs: */ Notifier machine_done; /* Pointers to devices and objects: */ HotplugHandler *acpi_dev; ISADevice *rtc; PCIBus *bus; FWCfgState *fw_cfg; qemu_irq *gsi; PFlashCFI01 *flash[2]; /* Configuration options: */ uint64_t max_ram_below_4g; OnOffAuto vmport; OnOffAuto smm; bool acpi_build_enabled; bool smbus_enabled; bool sata_enabled; bool pit_enabled; /* RAM information (sizes, addresses, configuration): */ ram_addr_t below_4g_mem_size, above_4g_mem_size; /* CPU and apic information: */ bool apic_xrupt_override; unsigned apic_id_limit; uint16_t boot_cpus; /* NUMA information: */ uint64_t numa_nodes; uint64_t *node_mem; /* Address space used by IOAPIC device. All IOAPIC interrupts * will be translated to MSI messages in the address space. */ AddressSpace *ioapic_as; }; #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" #define PC_MACHINE_DEVMEM_REGION_SIZE "device-memory-region-size" #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" #define PC_MACHINE_VMPORT "vmport" #define PC_MACHINE_SMM "smm" #define PC_MACHINE_SMBUS "smbus" #define PC_MACHINE_SATA "sata" #define PC_MACHINE_PIT "pit" /** * PCMachineClass: * * Compat fields: * * @enforce_aligned_dimm: check that DIMM's address/size is aligned by * backend's alignment value if provided * @acpi_data_size: Size of the chunk of memory at the top of RAM * for the BIOS ACPI tables and other BIOS * datastructures. * @gigabyte_align: Make sure that guest addresses aligned at * 1Gbyte boundaries get mapped to host * addresses aligned at 1Gbyte boundaries. This * way we can use 1GByte pages in the host. * */ typedef struct PCMachineClass { /*< private >*/ MachineClass parent_class; /*< public >*/ /* Device configuration: */ bool pci_enabled; bool kvmclock_enabled; const char *default_nic_model; /* Compat options: */ /* ACPI compat: */ bool has_acpi_build; bool rsdp_in_ram; int legacy_acpi_table_size; unsigned acpi_data_size; /* SMBIOS compat: */ bool smbios_defaults; bool smbios_legacy_mode; bool smbios_uuid_encoded; /* RAM / address space compat: */ bool gigabyte_align; bool has_reserved_memory; bool enforce_aligned_dimm; bool broken_reserved_end; /* TSC rate migration: */ bool save_tsc_khz; /* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug; /* use DMA capable linuxboot option rom */ bool linuxboot_dma_enabled; /* use PVH to load kernels that support this feature */ bool pvh_enabled; } PCMachineClass; #define TYPE_PC_MACHINE "generic-pc-machine" #define PC_MACHINE(obj) \ OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE) #define PC_MACHINE_GET_CLASS(obj) \ OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE) #define PC_MACHINE_CLASS(klass) \ OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE) /* i8259.c */ extern DeviceState *isa_pic; qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); qemu_irq *kvm_i8259_init(ISABus *bus); int pic_read_irq(DeviceState *d); int pic_get_output(DeviceState *d); /* ioapic.c */ /* Global System Interrupts */ #define GSI_NUM_PINS IOAPIC_NUM_PINS typedef struct GSIState { qemu_irq i8259_irq[ISA_NUM_IRQS]; qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; } GSIState; void gsi_handler(void *opaque, int n, int level); /* vmport.c */ #define TYPE_VMPORT "vmport" typedef uint32_t (VMPortReadFunc)(void *opaque, uint32_t address); static inline void vmport_init(ISABus *bus) { isa_create_simple(bus, TYPE_VMPORT); } void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque); void vmmouse_get_data(uint32_t *data); void vmmouse_set_data(const uint32_t *data); /* pc.c */ extern int fd_bootchk; bool pc_machine_is_smm_enabled(PCMachineState *pcms); void pc_register_ferr_irq(qemu_irq irq); void pc_acpi_smi_interrupt(void *opaque, int irq, int level); void pc_cpus_init(PCMachineState *pcms); void pc_hot_add_cpu(const int64_t id, Error **errp); void pc_guest_info_init(PCMachineState *pcms); #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start" #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end" #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start" #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end" #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size" #define PCI_HOST_BELOW_4G_MEM_SIZE "below-4g-mem-size" #define PCI_HOST_ABOVE_4G_MEM_SIZE "above-4g-mem-size" void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory, MemoryRegion *pci_address_space); void xen_load_linux(PCMachineState *pcms); void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, MemoryRegion **ram_memory); uint64_t pc_pci_hole64_start(void); qemu_irq pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, ISADevice **rtc_state, bool create_fdctrl, bool no_vmport, bool has_pit, uint32_t hpet_irqs); void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd); void pc_cmos_init(PCMachineState *pcms, BusState *ide0, BusState *ide1, ISADevice *s); void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus); void pc_pci_device_init(PCIBus *pci_bus); typedef void (*cpu_set_smm_t)(int smm, void *arg); void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); ISADevice *pc_find_fdc0(void); int cmos_get_fd_drive_type(FloppyDriveType fd0); #define FW_CFG_IO_BASE 0x510 #define PORT92_A20_LINE "a20" /* acpi_piix.c */ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq, qemu_irq smi_irq, int smm_enabled, DeviceState **piix4_pm); /* hpet.c */ extern int no_hpet; /* piix_pci.c */ struct PCII440FXState; typedef struct PCII440FXState PCII440FXState; #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost" #define TYPE_I440FX_PCI_DEVICE "i440FX" #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" /* * Reset Control Register: PCI-accessible ISA-Compatible Register at address * 0xcf9, provided by the PCI/ISA bridge (PIIX3 PCI function 0, 8086:7000). */ #define RCR_IOPORT 0xcf9 PCIBus *i440fx_init(const char *host_type, const char *pci_type, PCII440FXState **pi440fx_state, int *piix_devfn, ISABus **isa_bus, qemu_irq *pic, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *pci_memory, MemoryRegion *ram_memory); PCIBus *find_i440fx(void); /* piix4.c */ extern PCIDevice *piix4_dev; int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn); /* pc_sysfw.c */ void pc_system_flash_create(PCMachineState *pcms); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory); /* acpi-build.c */ void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, const CPUArchIdList *apic_ids, GArray *entry); /* e820 types */ #define E820_RAM 1 #define E820_RESERVED 2 #define E820_ACPI 3 #define E820_NVS 4 #define E820_UNUSABLE 5 int e820_add_entry(uint64_t, uint64_t, uint32_t); int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); extern GlobalProperty pc_compat_3_1[]; extern const size_t pc_compat_3_1_len; extern GlobalProperty pc_compat_3_0[]; extern const size_t pc_compat_3_0_len; extern GlobalProperty pc_compat_2_12[]; extern const size_t pc_compat_2_12_len; extern GlobalProperty pc_compat_2_11[]; extern const size_t pc_compat_2_11_len; extern GlobalProperty pc_compat_2_10[]; extern const size_t pc_compat_2_10_len; extern GlobalProperty pc_compat_2_9[]; extern const size_t pc_compat_2_9_len; extern GlobalProperty pc_compat_2_8[]; extern const size_t pc_compat_2_8_len; extern GlobalProperty pc_compat_2_7[]; extern const size_t pc_compat_2_7_len; extern GlobalProperty pc_compat_2_6[]; extern const size_t pc_compat_2_6_len; extern GlobalProperty pc_compat_2_5[]; extern const size_t pc_compat_2_5_len; extern GlobalProperty pc_compat_2_4[]; extern const size_t pc_compat_2_4_len; extern GlobalProperty pc_compat_2_3[]; extern const size_t pc_compat_2_3_len; extern GlobalProperty pc_compat_2_2[]; extern const size_t pc_compat_2_2_len; extern GlobalProperty pc_compat_2_1[]; extern const size_t pc_compat_2_1_len; extern GlobalProperty pc_compat_2_0[]; extern const size_t pc_compat_2_0_len; extern GlobalProperty pc_compat_1_7[]; extern const size_t pc_compat_1_7_len; extern GlobalProperty pc_compat_1_6[]; extern const size_t pc_compat_1_6_len; extern GlobalProperty pc_compat_1_5[]; extern const size_t pc_compat_1_5_len; extern GlobalProperty pc_compat_1_4[]; extern const size_t pc_compat_1_4_len; /* Helper for setting model-id for CPU models that changed model-id * depending on QEMU versions up to QEMU 2.4. */ #define PC_CPU_MODEL_IDS(v) \ { "qemu32-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, },\ { "qemu64-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, },\ { "athlon-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }, #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \ static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \ { \ MachineClass *mc = MACHINE_CLASS(oc); \ optsfn(mc); \ mc->init = initfn; \ } \ static const TypeInfo pc_machine_type_##suffix = { \ .name = namestr TYPE_MACHINE_SUFFIX, \ .parent = TYPE_PC_MACHINE, \ .class_init = pc_machine_##suffix##_class_init, \ }; \ static void pc_machine_init_##suffix(void) \ { \ type_register(&pc_machine_type_##suffix); \ } \ type_init(pc_machine_init_##suffix) extern void igd_passthrough_isa_bridge_create(PCIBus *bus, uint16_t gpu_dev_id); #endif
pmp-tool/PMP
src/qemu/src-pmp/tests/tcg/mips/user/ase/msa/int-multiply/test_msa_mulv_b.c
<reponame>pmp-tool/PMP /* * Test program for MSA instruction MULV.B * * Copyright (C) 2018 Wave Computing, Inc. * Copyright (C) 2018 <NAME> <<EMAIL>> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include <sys/time.h> #include <stdint.h> #include "../../../../include/wrappers_msa.h" #include "../../../../include/test_inputs.h" #include "../../../../include/test_utils.h" #define TEST_COUNT_TOTAL ( \ (PATTERN_INPUTS_SHORT_COUNT) * (PATTERN_INPUTS_SHORT_COUNT) + \ (RANDOM_INPUTS_SHORT_COUNT) * (RANDOM_INPUTS_SHORT_COUNT)) int32_t main(void) { char *instruction_name = "MULV.B"; int32_t ret; uint32_t i, j; struct timeval start, end; double elapsed_time; uint64_t b128_result[TEST_COUNT_TOTAL][2]; uint64_t b128_expect[TEST_COUNT_TOTAL][2] = { { 0x0101010101010101ULL, 0x0101010101010101ULL, }, /* 0 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x5656565656565656ULL, 0x5656565656565656ULL, }, { 0xababababababababULL, 0xababababababababULL, }, { 0x3434343434343434ULL, 0x3434343434343434ULL, }, { 0xcdcdcdcdcdcdcdcdULL, 0xcdcdcdcdcdcdcdcdULL, }, { 0x1d72c81d72c81d72ULL, 0xc81d72c81d72c81dULL, }, { 0xe48f39e48f39e48fULL, 0x39e48f39e48f39e4ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, /* 8 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x5656565656565656ULL, 0x5656565656565656ULL, }, /* 16 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0xe4e4e4e4e4e4e4e4ULL, 0xe4e4e4e4e4e4e4e4ULL, }, { 0x7272727272727272ULL, 0x7272727272727272ULL, }, { 0x7878787878787878ULL, 0x7878787878787878ULL, }, { 0xdedededededededeULL, 0xdedededededededeULL, }, { 0xbe4c30be4c30be4cULL, 0x30be4c30be4c30beULL, }, { 0x980a26980a26980aULL, 0x26980a26980a2698ULL, }, { 0xababababababababULL, 0xababababababababULL, }, /* 24 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x7272727272727272ULL, 0x7272727272727272ULL, }, { 0x3939393939393939ULL, 0x3939393939393939ULL, }, { 0xbcbcbcbcbcbcbcbcULL, 0xbcbcbcbcbcbcbcbcULL, }, { 0xefefefefefefefefULL, 0xefefefefefefefefULL, }, { 0x5f26985f26985f26ULL, 0x985f26985f26985fULL, }, { 0x4c85134c85134c85ULL, 0x134c85134c85134cULL, }, { 0x3434343434343434ULL, 0x3434343434343434ULL, }, /* 32 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x7878787878787878ULL, 0x7878787878787878ULL, }, { 0xbcbcbcbcbcbcbcbcULL, 0xbcbcbcbcbcbcbcbcULL, }, { 0x9090909090909090ULL, 0x9090909090909090ULL, }, { 0xa4a4a4a4a4a4a4a4ULL, 0xa4a4a4a4a4a4a4a4ULL, }, { 0xe428a0e428a0e428ULL, 0xa0e428a0e428a0e4ULL, }, { 0x500c94500c94500cULL, 0x94500c94500c9450ULL, }, { 0xcdcdcdcdcdcdcdcdULL, 0xcdcdcdcdcdcdcdcdULL, }, /* 40 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0xdedededededededeULL, 0xdedededededededeULL, }, { 0xefefefefefefefefULL, 0xefefefefefefefefULL, }, { 0xa4a4a4a4a4a4a4a4ULL, 0xa4a4a4a4a4a4a4a4ULL, }, { 0x2929292929292929ULL, 0x2929292929292929ULL, }, { 0x394a28394a28394aULL, 0x28394a28394a2839ULL, }, { 0x9483a59483a59483ULL, 0xa59483a59483a594ULL, }, { 0x1d72c81d72c81d72ULL, 0xc81d72c81d72c81dULL, }, /* 48 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0xbe4c30be4c30be4cULL, 0x30be4c30be4c30beULL, }, { 0x5f26985f26985f26ULL, 0x985f26985f26985fULL, }, { 0xe428a0e428a0e428ULL, 0xa0e428a0e428a0e4ULL, }, { 0x394a28394a28394aULL, 0x28394a28394a2839ULL, }, { 0x49c44049c44049c4ULL, 0x4049c44049c44049ULL, }, { 0xd4ae88d4ae88d4aeULL, 0x88d4ae88d4ae88d4ULL, }, { 0xe48f39e48f39e48fULL, 0x39e48f39e48f39e4ULL, }, /* 56 */ { 0x0000000000000000ULL, 0x0000000000000000ULL, }, { 0x980a26980a26980aULL, 0x26980a26980a2698ULL, }, { 0x4c85134c85134c85ULL, 0x134c85134c85134cULL, }, { 0x500c94500c94500cULL, 0x94500c94500c9450ULL, }, { 0x9483a59483a59483ULL, 0xa59483a59483a594ULL, }, { 0xd4ae88d4ae88d4aeULL, 0x88d4ae88d4ae88d4ULL, }, { 0x10e1b110e1b110e1ULL, 0xb110e1b110e1b110ULL, }, { 0x40e4a49040843900ULL, 0xf971798404190090ULL, }, /* 64 */ { 0x58ac00e408461300ULL, 0x4661098cd64560d0ULL, }, { 0x60445478e83e2700ULL, 0x6de882a2aaa970f0ULL, }, { 0x80b6c45cb0c20a80ULL, 0x4ff7d850aeb66080ULL, }, { 0x58ac00e408461300ULL, 0x4661098cd64560d0ULL, }, { 0x190400492969b140ULL, 0x445199a4b9814410ULL, }, { 0xa4cc00bea5dd0d00ULL, 0xbe68a2e60795dab0ULL, }, { 0xd0a200c74623ae70ULL, 0xea8758f0dd3e6480ULL, }, { 0x60445478e83e2700ULL, 0x6de882a2aaa970f0ULL, }, /* 72 */ { 0xa4cc00bea5dd0d00ULL, 0xbe68a2e60795dab0ULL, }, { 0x90a444e4b1617900ULL, 0xf140240139395990ULL, }, { 0x40c6f422ee9fb600ULL, 0x7b583028e316aa80ULL, }, { 0x80b6c45cb0c20a80ULL, 0x4ff7d850aeb66080ULL, }, { 0xd0a200c74623ae70ULL, 0xea8758f0dd3e6480ULL, }, }; gettimeofday(&start, NULL); for (i = 0; i < PATTERN_INPUTS_SHORT_COUNT; i++) { for (j = 0; j < PATTERN_INPUTS_SHORT_COUNT; j++) { do_msa_MULV_B(b128_pattern[i], b128_pattern[j], b128_result[PATTERN_INPUTS_SHORT_COUNT * i + j]); } } for (i = 0; i < RANDOM_INPUTS_SHORT_COUNT; i++) { for (j = 0; j < RANDOM_INPUTS_SHORT_COUNT; j++) { do_msa_MULV_B(b128_random[i], b128_random[j], b128_result[((PATTERN_INPUTS_SHORT_COUNT) * (PATTERN_INPUTS_SHORT_COUNT)) + RANDOM_INPUTS_SHORT_COUNT * i + j]); } } gettimeofday(&end, NULL); elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0; elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0; ret = check_results(instruction_name, TEST_COUNT_TOTAL, elapsed_time, &b128_result[0][0], &b128_expect[0][0]); return ret; }
pmp-tool/PMP
src/qemu/src-pmp/migration/global_state.c
<gh_stars>1-10 /* * Global State configuration * * Copyright (c) 2014-2017 Red Hat Inc * * Authors: * <NAME> <<EMAIL>> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "migration.h" #include "migration/global_state.h" #include "migration/vmstate.h" #include "trace.h" typedef struct { uint32_t size; uint8_t runstate[100]; RunState state; bool received; } GlobalState; static GlobalState global_state; int global_state_store(void) { if (!runstate_store((char *)global_state.runstate, sizeof(global_state.runstate))) { error_report("runstate name too big: %s", global_state.runstate); trace_migrate_state_too_big(); return -EINVAL; } return 0; } void global_state_store_running(void) { const char *state = RunState_str(RUN_STATE_RUNNING); assert(strlen(state) < sizeof(global_state.runstate)); strncpy((char *)global_state.runstate, state, sizeof(global_state.runstate)); } bool global_state_received(void) { return global_state.received; } RunState global_state_get_runstate(void) { return global_state.state; } static bool global_state_needed(void *opaque) { GlobalState *s = opaque; char *runstate = (char *)s->runstate; /* If it is not optional, it is mandatory */ if (migrate_get_current()->store_global_state) { return true; } /* If state is running or paused, it is not needed */ if (strcmp(runstate, "running") == 0 || strcmp(runstate, "paused") == 0) { return false; } /* for any other state it is needed */ return true; } static int global_state_post_load(void *opaque, int version_id) { GlobalState *s = opaque; Error *local_err = NULL; int r; char *runstate = (char *)s->runstate; s->received = true; trace_migrate_global_state_post_load(runstate); if (strnlen((char *)s->runstate, sizeof(s->runstate)) == sizeof(s->runstate)) { /* * This condition should never happen during migration, because * all runstate names are shorter than 100 bytes (the size of * s->runstate). However, a malicious stream could overflow * the qapi_enum_parse() call, so we force the last character * to a NUL byte. */ s->runstate[sizeof(s->runstate) - 1] = '\0'; } r = qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err); if (r == -1) { if (local_err) { error_report_err(local_err); } return -EINVAL; } s->state = r; return 0; } static int global_state_pre_save(void *opaque) { GlobalState *s = opaque; trace_migrate_global_state_pre_save((char *)s->runstate); s->size = strnlen((char *)s->runstate, sizeof(s->runstate)) + 1; assert(s->size <= sizeof(s->runstate)); return 0; } static const VMStateDescription vmstate_globalstate = { .name = "globalstate", .version_id = 1, .minimum_version_id = 1, .post_load = global_state_post_load, .pre_save = global_state_pre_save, .needed = global_state_needed, .fields = (VMStateField[]) { VMSTATE_UINT32(size, GlobalState), VMSTATE_BUFFER(runstate, GlobalState), VMSTATE_END_OF_LIST() }, }; void register_global_state(void) { /* We would use it independently that we receive it */ strcpy((char *)&global_state.runstate, ""); global_state.received = false; vmstate_register(NULL, 0, &vmstate_globalstate, &global_state); }
pmp-tool/PMP
src/qemu/src-pmp/scsi/pr-manager.c
/* * Persistent reservation manager abstract class * * Copyright (c) 2017 Red Hat, Inc. * * Author: <NAME> <<EMAIL>> * * This code is licensed under the LGPL. * */ #include "qemu/osdep.h" #include <scsi/sg.h> #include "qapi/error.h" #include "block/aio.h" #include "block/thread-pool.h" #include "scsi/pr-manager.h" #include "trace.h" #include "qapi/qapi-types-block.h" #include "qapi/qapi-commands-block.h" #define PR_MANAGER_PATH "/objects" typedef struct PRManagerData { PRManager *pr_mgr; struct sg_io_hdr *hdr; int fd; } PRManagerData; static int pr_manager_worker(void *opaque) { PRManagerData *data = opaque; PRManager *pr_mgr = data->pr_mgr; PRManagerClass *pr_mgr_class = PR_MANAGER_GET_CLASS(pr_mgr); struct sg_io_hdr *hdr = data->hdr; int fd = data->fd; int r; g_free(data); trace_pr_manager_run(fd, hdr->cmdp[0], hdr->cmdp[1]); /* The reference was taken in pr_manager_execute. */ r = pr_mgr_class->run(pr_mgr, fd, hdr); object_unref(OBJECT(pr_mgr)); return r; } int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, struct sg_io_hdr *hdr) { ThreadPool *pool = aio_get_thread_pool(ctx); PRManagerData data = { .pr_mgr = pr_mgr, .fd = fd, .hdr = hdr, }; trace_pr_manager_execute(fd, hdr->cmdp[0], hdr->cmdp[1]); /* The matching object_unref is in pr_manager_worker. */ object_ref(OBJECT(pr_mgr)); return thread_pool_submit_co(pool, pr_manager_worker, &data); } bool pr_manager_is_connected(PRManager *pr_mgr) { PRManagerClass *pr_mgr_class = PR_MANAGER_GET_CLASS(pr_mgr); return !pr_mgr_class->is_connected || pr_mgr_class->is_connected(pr_mgr); } static const TypeInfo pr_manager_info = { .parent = TYPE_OBJECT, .name = TYPE_PR_MANAGER, .class_size = sizeof(PRManagerClass), .abstract = true, .interfaces = (InterfaceInfo[]) { { TYPE_USER_CREATABLE }, { } } }; PRManager *pr_manager_lookup(const char *id, Error **errp) { Object *obj; PRManager *pr_mgr; obj = object_resolve_path_component(object_get_objects_root(), id); if (!obj) { error_setg(errp, "No persistent reservation manager with id '%s'", id); return NULL; } pr_mgr = (PRManager *) object_dynamic_cast(obj, TYPE_PR_MANAGER); if (!pr_mgr) { error_setg(errp, "Object with id '%s' is not a persistent reservation manager", id); return NULL; } return pr_mgr; } static void pr_manager_register_types(void) { type_register_static(&pr_manager_info); } static int query_one_pr_manager(Object *object, void *opaque) { PRManagerInfoList ***prev = opaque; PRManagerInfoList *elem; PRManagerInfo *info; PRManager *pr_mgr; pr_mgr = (PRManager *)object_dynamic_cast(object, TYPE_PR_MANAGER); if (!pr_mgr) { return 0; } elem = g_new0(PRManagerInfoList, 1); info = g_new0(PRManagerInfo, 1); info->id = object_get_canonical_path_component(object); info->connected = pr_manager_is_connected(pr_mgr); elem->value = info; elem->next = NULL; **prev = elem; *prev = &elem->next; return 0; } PRManagerInfoList *qmp_query_pr_managers(Error **errp) { PRManagerInfoList *head = NULL; PRManagerInfoList **prev = &head; Object *container = container_get(object_get_root(), PR_MANAGER_PATH); object_child_foreach(container, query_one_pr_manager, &prev); return head; } type_init(pr_manager_register_types);
pmp-tool/PMP
src/qemu/src-pmp/target/xtensa/core-test_mmuhifi_c3/gdb-config.inc.c
/* Configuration for the Xtensa architecture for GDB, the GNU debugger. Copyright (C) 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* idx ofs bi sz al targno flags cp typ group name */ XTREG( 0, 0,32, 4, 4,0x0020,0x0006,-2, 9,0x0100,pc, 0,0,0,0,0,0) XTREG( 1, 4,32, 4, 4,0x0100,0x0006,-2, 1,0x0002,ar0, 0,0,0,0,0,0) XTREG( 2, 8,32, 4, 4,0x0101,0x0006,-2, 1,0x0002,ar1, 0,0,0,0,0,0) XTREG( 3, 12,32, 4, 4,0x0102,0x0006,-2, 1,0x0002,ar2, 0,0,0,0,0,0) XTREG( 4, 16,32, 4, 4,0x0103,0x0006,-2, 1,0x0002,ar3, 0,0,0,0,0,0) XTREG( 5, 20,32, 4, 4,0x0104,0x0006,-2, 1,0x0002,ar4, 0,0,0,0,0,0) XTREG( 6, 24,32, 4, 4,0x0105,0x0006,-2, 1,0x0002,ar5, 0,0,0,0,0,0) XTREG( 7, 28,32, 4, 4,0x0106,0x0006,-2, 1,0x0002,ar6, 0,0,0,0,0,0) XTREG( 8, 32,32, 4, 4,0x0107,0x0006,-2, 1,0x0002,ar7, 0,0,0,0,0,0) XTREG( 9, 36,32, 4, 4,0x0108,0x0006,-2, 1,0x0002,ar8, 0,0,0,0,0,0) XTREG( 10, 40,32, 4, 4,0x0109,0x0006,-2, 1,0x0002,ar9, 0,0,0,0,0,0) XTREG( 11, 44,32, 4, 4,0x010a,0x0006,-2, 1,0x0002,ar10, 0,0,0,0,0,0) XTREG( 12, 48,32, 4, 4,0x010b,0x0006,-2, 1,0x0002,ar11, 0,0,0,0,0,0) XTREG( 13, 52,32, 4, 4,0x010c,0x0006,-2, 1,0x0002,ar12, 0,0,0,0,0,0) XTREG( 14, 56,32, 4, 4,0x010d,0x0006,-2, 1,0x0002,ar13, 0,0,0,0,0,0) XTREG( 15, 60,32, 4, 4,0x010e,0x0006,-2, 1,0x0002,ar14, 0,0,0,0,0,0) XTREG( 16, 64,32, 4, 4,0x010f,0x0006,-2, 1,0x0002,ar15, 0,0,0,0,0,0) XTREG( 17, 68,32, 4, 4,0x0110,0x0006,-2, 1,0x0002,ar16, 0,0,0,0,0,0) XTREG( 18, 72,32, 4, 4,0x0111,0x0006,-2, 1,0x0002,ar17, 0,0,0,0,0,0) XTREG( 19, 76,32, 4, 4,0x0112,0x0006,-2, 1,0x0002,ar18, 0,0,0,0,0,0) XTREG( 20, 80,32, 4, 4,0x0113,0x0006,-2, 1,0x0002,ar19, 0,0,0,0,0,0) XTREG( 21, 84,32, 4, 4,0x0114,0x0006,-2, 1,0x0002,ar20, 0,0,0,0,0,0) XTREG( 22, 88,32, 4, 4,0x0115,0x0006,-2, 1,0x0002,ar21, 0,0,0,0,0,0) XTREG( 23, 92,32, 4, 4,0x0116,0x0006,-2, 1,0x0002,ar22, 0,0,0,0,0,0) XTREG( 24, 96,32, 4, 4,0x0117,0x0006,-2, 1,0x0002,ar23, 0,0,0,0,0,0) XTREG( 25,100,32, 4, 4,0x0118,0x0006,-2, 1,0x0002,ar24, 0,0,0,0,0,0) XTREG( 26,104,32, 4, 4,0x0119,0x0006,-2, 1,0x0002,ar25, 0,0,0,0,0,0) XTREG( 27,108,32, 4, 4,0x011a,0x0006,-2, 1,0x0002,ar26, 0,0,0,0,0,0) XTREG( 28,112,32, 4, 4,0x011b,0x0006,-2, 1,0x0002,ar27, 0,0,0,0,0,0) XTREG( 29,116,32, 4, 4,0x011c,0x0006,-2, 1,0x0002,ar28, 0,0,0,0,0,0) XTREG( 30,120,32, 4, 4,0x011d,0x0006,-2, 1,0x0002,ar29, 0,0,0,0,0,0) XTREG( 31,124,32, 4, 4,0x011e,0x0006,-2, 1,0x0002,ar30, 0,0,0,0,0,0) XTREG( 32,128,32, 4, 4,0x011f,0x0006,-2, 1,0x0002,ar31, 0,0,0,0,0,0) XTREG( 33,132,32, 4, 4,0x0200,0x0006,-2, 2,0x1100,lbeg, 0,0,0,0,0,0) XTREG( 34,136,32, 4, 4,0x0201,0x0006,-2, 2,0x1100,lend, 0,0,0,0,0,0) XTREG( 35,140,32, 4, 4,0x0202,0x0006,-2, 2,0x1100,lcount, 0,0,0,0,0,0) XTREG( 36,144, 6, 4, 4,0x0203,0x0006,-2, 2,0x1100,sar, 0,0,0,0,0,0) XTREG( 37,148,32, 4, 4,0x0205,0x0006,-2, 2,0x1100,litbase, 0,0,0,0,0,0) XTREG( 38,152, 3, 4, 4,0x0248,0x0006,-2, 2,0x1002,windowbase, 0,0,0,0,0,0) XTREG( 39,156, 8, 4, 4,0x0249,0x0006,-2, 2,0x1002,windowstart, 0,0,0,0,0,0) XTREG( 40,160,32, 4, 4,0x02b0,0x0002,-2, 2,0x1000,sr176, 0,0,0,0,0,0) XTREG( 41,164,32, 4, 4,0x02d0,0x0002,-2, 2,0x1000,sr208, 0,0,0,0,0,0) XTREG( 42,168,19, 4, 4,0x02e6,0x0006,-2, 2,0x1100,ps, 0,0,0,0,0,0) XTREG( 43,172,32, 4, 4,0x03e7,0x0006,-2, 3,0x0110,threadptr, 0,0,0,0,0,0) XTREG( 44,176,16, 4, 4,0x0204,0x0006,-1, 2,0x1100,br, 0,0,0,0,0,0) XTREG( 45,180,32, 4, 4,0x020c,0x0006,-1, 2,0x1100,scompare1, 0,0,0,0,0,0) XTREG( 46,184,48, 8, 8,0x0060,0x0006, 1, 4,0x0101,aep0, "03:04:84:b2","03:04:84:a7",0,0,0,0) XTREG( 47,192,48, 8, 8,0x0061,0x0006, 1, 4,0x0101,aep1, "03:04:94:b2","03:04:94:a7",0,0,0,0) XTREG( 48,200,48, 8, 8,0x0062,0x0006, 1, 4,0x0101,aep2, "03:04:a4:b2","03:04:a4:a7",0,0,0,0) XTREG( 49,208,48, 8, 8,0x0063,0x0006, 1, 4,0x0101,aep3, "03:04:b4:b2","03:04:b4:a7",0,0,0,0) XTREG( 50,216,48, 8, 8,0x0064,0x0006, 1, 4,0x0101,aep4, "03:04:c4:b2","03:04:c4:a7",0,0,0,0) XTREG( 51,224,48, 8, 8,0x0065,0x0006, 1, 4,0x0101,aep5, "03:04:d4:b2","03:04:d4:a7",0,0,0,0) XTREG( 52,232,48, 8, 8,0x0066,0x0006, 1, 4,0x0101,aep6, "03:04:e4:b2","03:04:e4:a7",0,0,0,0) XTREG( 53,240,48, 8, 8,0x0067,0x0006, 1, 4,0x0101,aep7, "03:04:f4:b2","03:04:f4:a7",0,0,0,0) XTREG( 54,248,56, 8, 8,0x0068,0x0006, 1, 4,0x0101,aeq0, "03:04:04:c3","03:04:04:c1",0,0,0,0) XTREG( 55,256,56, 8, 8,0x0069,0x0006, 1, 4,0x0101,aeq1, "03:04:14:c3","03:04:44:c1",0,0,0,0) XTREG( 56,264,56, 8, 8,0x006a,0x0006, 1, 4,0x0101,aeq2, "03:04:24:c3","03:04:84:c1",0,0,0,0) XTREG( 57,272,56, 8, 8,0x006b,0x0006, 1, 4,0x0101,aeq3, "03:04:34:c3","03:04:c4:c1",0,0,0,0) XTREG( 58,280, 7, 4, 4,0x03f0,0x0006, 1, 3,0x0100,ae_ovf_sar, 0,0,0,0,0,0) XTREG( 59,284,32, 4, 4,0x03f1,0x0006, 1, 3,0x0110,ae_bithead, 0,0,0,0,0,0) XTREG( 60,288,16, 4, 4,0x03f2,0x0006, 1, 3,0x0100,ae_ts_fts_bu_bp,0,0,0,0,0,0) XTREG( 61,292,28, 4, 4,0x03f3,0x0006, 1, 3,0x0100,ae_sd_no, 0,0,0,0,0,0) XTREG( 62,296,32, 4, 4,0x0253,0x0007,-2, 2,0x1000,ptevaddr, 0,0,0,0,0,0) XTREG( 63,300,32, 4, 4,0x025a,0x0007,-2, 2,0x1000,rasid, 0,0,0,0,0,0) XTREG( 64,304,18, 4, 4,0x025b,0x0007,-2, 2,0x1000,itlbcfg, 0,0,0,0,0,0) XTREG( 65,308,18, 4, 4,0x025c,0x0007,-2, 2,0x1000,dtlbcfg, 0,0,0,0,0,0) XTREG( 66,312, 6, 4, 4,0x0263,0x0007,-2, 2,0x1000,atomctl, 0,0,0,0,0,0) XTREG( 67,316,32, 4, 4,0x0268,0x0007,-2, 2,0x1000,ddr, 0,0,0,0,0,0) XTREG( 68,320,32, 4, 4,0x02b1,0x0007,-2, 2,0x1000,epc1, 0,0,0,0,0,0) XTREG( 69,324,32, 4, 4,0x02b2,0x0007,-2, 2,0x1000,epc2, 0,0,0,0,0,0) XTREG( 70,328,32, 4, 4,0x02c0,0x0007,-2, 2,0x1000,depc, 0,0,0,0,0,0) XTREG( 71,332,19, 4, 4,0x02c2,0x0007,-2, 2,0x1000,eps2, 0,0,0,0,0,0) XTREG( 72,336,32, 4, 4,0x02d1,0x0007,-2, 2,0x1000,excsave1, 0,0,0,0,0,0) XTREG( 73,340,32, 4, 4,0x02d2,0x0007,-2, 2,0x1000,excsave2, 0,0,0,0,0,0) XTREG( 74,344, 2, 4, 4,0x02e0,0x0007,-2, 2,0x1000,cpenable, 0,0,0,0,0,0) XTREG( 75,348,12, 4, 4,0x02e2,0x000b,-2, 2,0x1000,interrupt, 0,0,0,0,0,0) XTREG( 76,352,12, 4, 4,0x02e2,0x000d,-2, 2,0x1000,intset, 0,0,0,0,0,0) XTREG( 77,356,12, 4, 4,0x02e3,0x000d,-2, 2,0x1000,intclear, 0,0,0,0,0,0) XTREG( 78,360,12, 4, 4,0x02e4,0x0007,-2, 2,0x1000,intenable, 0,0,0,0,0,0) XTREG( 79,364,32, 4, 4,0x02e7,0x0007,-2, 2,0x1000,vecbase, 0,0,0,0,0,0) XTREG( 80,368, 6, 4, 4,0x02e8,0x0007,-2, 2,0x1000,exccause, 0,0,0,0,0,0) XTREG( 81,372,12, 4, 4,0x02e9,0x0003,-2, 2,0x1000,debugcause, 0,0,0,0,0,0) XTREG( 82,376,32, 4, 4,0x02ea,0x000f,-2, 2,0x1000,ccount, 0,0,0,0,0,0) XTREG( 83,380,32, 4, 4,0x02eb,0x0003,-2, 2,0x1000,prid, 0,0,0,0,0,0) XTREG( 84,384,32, 4, 4,0x02ec,0x000f,-2, 2,0x1000,icount, 0,0,0,0,0,0) XTREG( 85,388, 4, 4, 4,0x02ed,0x0007,-2, 2,0x1000,icountlevel, 0,0,0,0,0,0) XTREG( 86,392,32, 4, 4,0x02ee,0x0007,-2, 2,0x1000,excvaddr, 0,0,0,0,0,0) XTREG( 87,396,32, 4, 4,0x02f0,0x000f,-2, 2,0x1000,ccompare0, 0,0,0,0,0,0) XTREG( 88,400,32, 4, 4,0x02f1,0x000f,-2, 2,0x1000,ccompare1, 0,0,0,0,0,0) XTREG( 89,404,32, 4, 4,0x02f4,0x0007,-2, 2,0x1000,misc0, 0,0,0,0,0,0) XTREG( 90,408,32, 4, 4,0x02f5,0x0007,-2, 2,0x1000,misc1, 0,0,0,0,0,0) XTREG( 91,412,32, 4, 4,0x0000,0x0006,-2, 8,0x0100,a0, 0,0,0,0,0,0) XTREG( 92,416,32, 4, 4,0x0001,0x0006,-2, 8,0x0100,a1, 0,0,0,0,0,0) XTREG( 93,420,32, 4, 4,0x0002,0x0006,-2, 8,0x0100,a2, 0,0,0,0,0,0) XTREG( 94,424,32, 4, 4,0x0003,0x0006,-2, 8,0x0100,a3, 0,0,0,0,0,0) XTREG( 95,428,32, 4, 4,0x0004,0x0006,-2, 8,0x0100,a4, 0,0,0,0,0,0) XTREG( 96,432,32, 4, 4,0x0005,0x0006,-2, 8,0x0100,a5, 0,0,0,0,0,0) XTREG( 97,436,32, 4, 4,0x0006,0x0006,-2, 8,0x0100,a6, 0,0,0,0,0,0) XTREG( 98,440,32, 4, 4,0x0007,0x0006,-2, 8,0x0100,a7, 0,0,0,0,0,0) XTREG( 99,444,32, 4, 4,0x0008,0x0006,-2, 8,0x0100,a8, 0,0,0,0,0,0) XTREG(100,448,32, 4, 4,0x0009,0x0006,-2, 8,0x0100,a9, 0,0,0,0,0,0) XTREG(101,452,32, 4, 4,0x000a,0x0006,-2, 8,0x0100,a10, 0,0,0,0,0,0) XTREG(102,456,32, 4, 4,0x000b,0x0006,-2, 8,0x0100,a11, 0,0,0,0,0,0) XTREG(103,460,32, 4, 4,0x000c,0x0006,-2, 8,0x0100,a12, 0,0,0,0,0,0) XTREG(104,464,32, 4, 4,0x000d,0x0006,-2, 8,0x0100,a13, 0,0,0,0,0,0) XTREG(105,468,32, 4, 4,0x000e,0x0006,-2, 8,0x0100,a14, 0,0,0,0,0,0) XTREG(106,472,32, 4, 4,0x000f,0x0006,-2, 8,0x0100,a15, 0,0,0,0,0,0) XTREG_END
pmp-tool/PMP
src/qemu/src-pmp/tests/tcg/mips/user/isa/mips64r6/bit-swap/test_mips64r6_dbitswap.c
<filename>src/qemu/src-pmp/tests/tcg/mips/user/isa/mips64r6/bit-swap/test_mips64r6_dbitswap.c /* * Test program for MIPS64R6 instruction DBITSWAP * * Copyright (C) 2019 Wave Computing, Inc. * Copyright (C) 2019 <NAME> <<EMAIL>> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include <sys/time.h> #include <stdint.h> #include "../../../../include/wrappers_mips64r6.h" #include "../../../../include/test_inputs_64.h" #include "../../../../include/test_utils_64.h" #define TEST_COUNT_TOTAL (PATTERN_INPUTS_64_COUNT + RANDOM_INPUTS_64_COUNT) int32_t main(void) { char *instruction_name = "DBITSWAP"; int32_t ret; uint32_t i; struct timeval start, end; double elapsed_time; uint64_t b64_result[TEST_COUNT_TOTAL]; uint64_t b64_expect[TEST_COUNT_TOTAL] = { 0xffffffffffffffffULL, /* 0 */ 0x0000000000000000ULL, 0x5555555555555555ULL, 0xaaaaaaaaaaaaaaaaULL, 0x3333333333333333ULL, 0xccccccccccccccccULL, 0xc7711cc7711cc771ULL, 0x388ee3388ee3388eULL, 0x0f0f0f0f0f0f0f0fULL, /* 8 */ 0xf0f0f0f0f0f0f0f0ULL, 0x1f7cf0c1071f7cf0ULL, 0xe0830f3ef8e0830fULL, 0x3ff0033ff0033ff0ULL, 0xc00ffcc00ffcc00fULL, 0x7fc01ff007fc017fULL, 0x803fe00ff803fe80ULL, 0xff00ff00ff00ff00ULL, /* 16 */ 0x00ff00ff00ff00ffULL, 0xff01fc07f01fc07fULL, 0x00fe03f80fe03f80ULL, 0xff03f03f00ff03f0ULL, 0x00fc0fc0ff00fc0fULL, 0xff07c0ff01f07f00ULL, 0x00f83f00fe0f80ffULL, 0xff0f00ff0f00ff0fULL, /* 24 */ 0x00f0ff00f0ff00f0ULL, 0xff1f00fc7f00f0ffULL, 0x00e0ff0380ff0f00ULL, 0xff3f00f0ff0300ffULL, 0x00c0ff0f00fcff00ULL, 0xff7f00c0ff1f00f0ULL, 0x0080ff3f00e0ff0fULL, 0xffff0000ffff0000ULL, /* 32 */ 0x0000ffff0000ffffULL, 0xffff0100fcff0700ULL, 0x0000feff0300f8ffULL, 0xffff0300f0ff3f00ULL, 0x0000fcff0f00c0ffULL, 0xffff0700c0ffff01ULL, 0x0000f8ff3f0000feULL, 0xffff0f0000ffff0fULL, /* 40 */ 0x0000f0ffff0000f0ULL, 0xffff1f0000fcff7fULL, 0x0000e0ffff030080ULL, 0xffff3f0000f0ffffULL, 0x0000c0ffff0f0000ULL, 0xffff7f0000c0ffffULL, 0x000080ffff3f0000ULL, 0xffffff000000ffffULL, /* 48 */ 0x000000ffffff0000ULL, 0xffffff010000fcffULL, 0x000000feffff0300ULL, 0xffffff030000f0ffULL, 0x000000fcffff0f00ULL, 0xffffff070000c0ffULL, 0x000000f8ffff3f00ULL, 0xffffff0f000000ffULL, /* 56 */ 0x000000f0ffffff00ULL, 0xffffff1f000000fcULL, 0x000000e0ffffff03ULL, 0xffffff3f000000f0ULL, 0x000000c0ffffff0fULL, 0xffffff7f000000c0ULL, 0x00000080ffffff3fULL, 0x115667331446aa02ULL, /* 64 */ 0xdf7d00c6b2c9e310ULL, 0x355a75559df3d101ULL, 0x0ef268b27a8c4772ULL, 0x9d49d63ebef5421aULL, 0x0be47d91ff50749fULL, 0x1ddc1a60a6533d52ULL, 0x3ff1c40f5965ed41ULL, 0x047890b36a756792ULL, /* 72 */ 0xa53e9bc8a69ba7ebULL, 0x45176faf93d363d8ULL, 0x15394f8f8c152675ULL, 0x67281c97654a5750ULL, 0x2952acbf98c48615ULL, 0x620c42c6447def39ULL, 0xd15ae5454f9a7bb5ULL, }; gettimeofday(&start, NULL); for (i = 0; i < TEST_COUNT_TOTAL; i++) { if (i < PATTERN_INPUTS_64_COUNT) { do_mips64r6_DBITSWAP(b64_pattern + i, b64_result + i); } else { do_mips64r6_DBITSWAP(b64_random + (i - PATTERN_INPUTS_64_COUNT), b64_result + i); } } gettimeofday(&end, NULL); elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0; elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0; ret = check_results_64(instruction_name, TEST_COUNT_TOTAL, elapsed_time, b64_result, b64_expect); return ret; }
pmp-tool/PMP
src/qemu/src-pmp/include/hw/ppc/spapr_irq.h
<reponame>pmp-tool/PMP /* * QEMU PowerPC sPAPR IRQ backend definitions * * Copyright (c) 2018, IBM Corporation. * * This code is licensed under the GPL version 2 or later. See the * COPYING file in the top-level directory. */ #ifndef HW_SPAPR_IRQ_H #define HW_SPAPR_IRQ_H /* * IRQ range offsets per device type */ #define SPAPR_IRQ_IPI 0x0 #define SPAPR_IRQ_EPOW 0x1000 /* XICS_IRQ_BASE offset */ #define SPAPR_IRQ_HOTPLUG 0x1001 #define SPAPR_IRQ_VIO 0x1100 /* 256 VIO devices */ #define SPAPR_IRQ_PCI_LSI 0x1200 /* 32+ PHBs devices */ #define SPAPR_IRQ_MSI 0x1300 /* Offset of the dynamic range covered * by the bitmap allocator */ typedef struct SpaprMachineState SpaprMachineState; void spapr_irq_msi_init(SpaprMachineState *spapr, uint32_t nr_msis); int spapr_irq_msi_alloc(SpaprMachineState *spapr, uint32_t num, bool align, Error **errp); void spapr_irq_msi_free(SpaprMachineState *spapr, int irq, uint32_t num); void spapr_irq_msi_reset(SpaprMachineState *spapr); typedef struct SpaprIrq { uint32_t nr_irqs; uint32_t nr_msis; uint8_t ov5; void (*init)(SpaprMachineState *spapr, int nr_irqs, Error **errp); int (*claim)(SpaprMachineState *spapr, int irq, bool lsi, Error **errp); void (*free)(SpaprMachineState *spapr, int irq, int num); qemu_irq (*qirq)(SpaprMachineState *spapr, int irq); void (*print_info)(SpaprMachineState *spapr, Monitor *mon); void (*dt_populate)(SpaprMachineState *spapr, uint32_t nr_servers, void *fdt, uint32_t phandle); void (*cpu_intc_create)(SpaprMachineState *spapr, PowerPCCPU *cpu, Error **errp); int (*post_load)(SpaprMachineState *spapr, int version_id); void (*reset)(SpaprMachineState *spapr, Error **errp); void (*set_irq)(void *opaque, int srcno, int val); const char *(*get_nodename)(SpaprMachineState *spapr); } SpaprIrq; extern SpaprIrq spapr_irq_xics; extern SpaprIrq spapr_irq_xics_legacy; extern SpaprIrq spapr_irq_xive; extern SpaprIrq spapr_irq_dual; void spapr_irq_init(SpaprMachineState *spapr, Error **errp); int spapr_irq_claim(SpaprMachineState *spapr, int irq, bool lsi, Error **errp); void spapr_irq_free(SpaprMachineState *spapr, int irq, int num); qemu_irq spapr_qirq(SpaprMachineState *spapr, int irq); int spapr_irq_post_load(SpaprMachineState *spapr, int version_id); void spapr_irq_reset(SpaprMachineState *spapr, Error **errp); int spapr_irq_get_phandle(SpaprMachineState *spapr, void *fdt, Error **errp); /* * XICS legacy routines */ int spapr_irq_find(SpaprMachineState *spapr, int num, bool align, Error **errp); #define spapr_irq_findone(spapr, errp) spapr_irq_find(spapr, 1, false, errp) #endif