Coverage for skema/program_analysis/CAST2FN/visitors/cast_to_air_function_map.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1""" 

2 Map to represent the grfn execution function and original implementation of 

3 builtin/library functions found in specific languages. Will have structure: 

4 { 

5 language: { 

6 func_name: { 

7 grfn_implementation: ... 

8 source_implementation: ... 

9 } 

10 } 

11 } 

12""" 

13func_map = { 

14 "c": {}, 

15 "fortran": { 

16 "__builtin_max": {"grfn_implementation": "max"}, 

17 "__builtin_sqrtf": {"grfn_implementation": "sqrt"}, 

18 "__builtin_iroundf": {"grfn_implementation": "round"}, 

19 "__builtin_expf": {"grfn_implementation": "exp"}, 

20 "__builtin_cosf": {"grfn_implementation": "cos"}, 

21 }, 

22 "unknown": {"max": {"grfn_implementation": "max"}}, 

23} 

24 

25 

26class UnsupportedLanguageExcepetion(Exception): 

27 pass 

28 

29 

30class UnknownLanguageBuiltinExcepetion(Exception): 

31 pass 

32 

33 

34def is_in_language_map(language): 

35 if language not in func_map: 

36 raise Exception(f"Error: Unknown language in builtins map: {language}") 

37 

38 

39def is_builtin_func(language, name): 

40 is_in_language_map(language) 

41 language_map = func_map[language] 

42 return name in language_map 

43 

44 

45def get_builtin_func_info(language, name): 

46 is_in_language_map(language) 

47 

48 language_map = func_map[language] 

49 if name not in language_map: 

50 raise UnknownLanguageBuiltinExcepetion( 

51 f'Error: Unknown builtin function for language "{language}": {name}' 

52 ) 

53 

54 return language_map[name]