Resolve [4-3] linker platform dependency and [3-2] C-Fortran ABI dependency
This commit is contained in:
parent
2c84fe09d3
commit
4c732f3880
4 changed files with 85 additions and 84 deletions
74
code/code_gen/build_info_gen.py
Normal file
74
code/code_gen/build_info_gen.py
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import subprocess as sp
|
||||||
|
|
||||||
|
# Add the directory containing this script to sys.path for local imports
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
sys.path.insert(0, script_dir)
|
||||||
|
|
||||||
|
from lark import Lark
|
||||||
|
import code_gen
|
||||||
|
import post
|
||||||
|
|
||||||
|
def escape_fortran_string(s):
|
||||||
|
# Escape double quotes by doubling them
|
||||||
|
escaped = s.replace('"', '""')
|
||||||
|
# Split by newline and format as Fortran concatenation with char(10)
|
||||||
|
lines = escaped.splitlines()
|
||||||
|
if not lines:
|
||||||
|
return '""'
|
||||||
|
formatted_lines = [f'"{line}"' for line in lines]
|
||||||
|
return ' // char(10) // &\n '.join(formatted_lines)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("Usage: python3 build_info_gen.py <termspec_file>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
terms_file = sys.argv[1]
|
||||||
|
with open(terms_file, 'r', encoding='utf-8') as f:
|
||||||
|
terms_raw = f.read()
|
||||||
|
|
||||||
|
# Generate Version Info
|
||||||
|
vinfo = code_gen.VersionInfo(terms_raw)
|
||||||
|
build_info_str = vinfo.fparams()
|
||||||
|
|
||||||
|
# Generate LaTeX equations
|
||||||
|
parser = Lark(code_gen.calc_grammar,
|
||||||
|
parser='lalr',
|
||||||
|
lexer_callbacks={
|
||||||
|
'ESCAPED_STRING': code_gen.tok_to_str,
|
||||||
|
'INT': code_gen.tok_to_int,
|
||||||
|
'BOOL': code_gen.tok_to_bool
|
||||||
|
})
|
||||||
|
tree = parser.parse(terms_raw)
|
||||||
|
ir1 = post.Stage1(tree)
|
||||||
|
ir2 = post.Stage2(ir1)
|
||||||
|
ir3 = post.Stage3(ir2)
|
||||||
|
ir4 = post.Stage4(ir3)
|
||||||
|
|
||||||
|
latex_lines = ["{"]
|
||||||
|
for avg in ir4.averaged.values():
|
||||||
|
latex_lines.append(f' "{avg.name}" : r"${avg.latex}$",')
|
||||||
|
latex_lines.append("}")
|
||||||
|
latex_str = "\n".join(latex_lines)
|
||||||
|
|
||||||
|
# Format for Fortran
|
||||||
|
fortran_build_info = escape_fortran_string(build_info_str)
|
||||||
|
fortran_latex = escape_fortran_string(latex_str)
|
||||||
|
|
||||||
|
# Write m_build_info.f90
|
||||||
|
fortran_code = f"""module m_build_info
|
||||||
|
implicit none
|
||||||
|
character(len=*), parameter :: build_info_str = &
|
||||||
|
{fortran_build_info}
|
||||||
|
character(len=*), parameter :: latex_equations_str = &
|
||||||
|
{fortran_latex}
|
||||||
|
end module m_build_info
|
||||||
|
"""
|
||||||
|
# Print to stdout so it can be redirected
|
||||||
|
print(fortran_code)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
@ -28,18 +28,16 @@ MODULES += \
|
||||||
m_calculate.o\
|
m_calculate.o\
|
||||||
m_arrays.o\
|
m_arrays.o\
|
||||||
m_terms.o\
|
m_terms.o\
|
||||||
|
m_build_info.o\
|
||||||
post.o
|
post.o
|
||||||
|
|
||||||
# Objects
|
# Objects
|
||||||
OBJ = post_dns.o
|
OBJ = post_dns.o
|
||||||
|
|
||||||
# Data Objects
|
|
||||||
ODATA = build_info.odata latex_equations.odata
|
|
||||||
|
|
||||||
Post_Cbar_FSD_Incomp : x-edge-cold-bc-uPrime-hybrid
|
Post_Cbar_FSD_Incomp : x-edge-cold-bc-uPrime-hybrid
|
||||||
|
|
||||||
x-edge-cold-bc-uPrime-hybrid : ${MODULES} ${OBJ} print_build_info.o ${ODATA}
|
x-edge-cold-bc-uPrime-hybrid : ${MODULES} ${OBJ}
|
||||||
${FC} -o x-edge-cold-bc-uPrime-hybrid ${flags} ${MODULES} ${OBJ} print_build_info.o ${ODATA}
|
${FC} -o x-edge-cold-bc-uPrime-hybrid ${flags} ${MODULES} ${OBJ}
|
||||||
|
|
||||||
${OBJ} : ${MODULES}
|
${OBJ} : ${MODULES}
|
||||||
|
|
||||||
|
|
@ -50,7 +48,7 @@ m_terms.f90 : code_gen/code_gen.py ${TERMSPEC} code_gen/resources/m_template.py
|
||||||
${FC} -c ${flags} $<
|
${FC} -c ${flags} $<
|
||||||
|
|
||||||
cleanAll: clean
|
cleanAll: clean
|
||||||
rm -f m_terms.f90
|
rm -f m_terms.f90 m_build_info.f90
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.odata *.mod x-edge-cold-bc-uPrime-hybrid test_calculate test_compact build_info.txt latex_equations.txt
|
rm -f *.o *.odata *.mod x-edge-cold-bc-uPrime-hybrid test_calculate test_compact build_info.txt latex_equations.txt
|
||||||
|
|
@ -71,14 +69,5 @@ test_compact : Compact.o test_compact.o
|
||||||
|
|
||||||
test_compact.o : Compact.o
|
test_compact.o : Compact.o
|
||||||
|
|
||||||
print_build_info.o : print_build_info.c
|
m_build_info.f90 : code_gen/build_info_gen.py ${TERMSPEC} code_gen/code_gen.py code_gen/post.py
|
||||||
${CC} -c print_build_info.c
|
${PYTHON} code_gen/build_info_gen.py ${TERMSPEC} > $@
|
||||||
|
|
||||||
%.odata : %.txt
|
|
||||||
${LD} -r -b binary -o $@ $<
|
|
||||||
|
|
||||||
build_info.txt : ${TERMSPEC}
|
|
||||||
${PYTHON} code_gen/code_gen.py -b ${TERMSPEC} > $@
|
|
||||||
|
|
||||||
latex_equations.txt : ${TERMSPEC}
|
|
||||||
${PYTHON} code_gen/code_gen.py -x ${TERMSPEC} > $@
|
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,11 @@
|
||||||
USE m_openmpi
|
USE m_openmpi
|
||||||
USE post
|
USE post
|
||||||
USE Compact
|
USE Compact
|
||||||
|
USE m_build_info
|
||||||
interface
|
IMPLICIT NONE
|
||||||
|
|
||||||
function build_info_length()
|
|
||||||
integer :: build_info_length
|
|
||||||
end function build_info_length
|
|
||||||
|
|
||||||
function latex_length()
|
|
||||||
integer :: latex_length
|
|
||||||
end function latex_length
|
|
||||||
|
|
||||||
end interface
|
|
||||||
|
|
||||||
CHARACTER(100) :: num1char = ""
|
CHARACTER(100) :: num1char = ""
|
||||||
|
|
||||||
character (len=8000) :: input_string = ""
|
|
||||||
|
|
||||||
character (len=8000) :: latex_string = ""
|
|
||||||
|
|
||||||
call cstr(input_string)
|
|
||||||
|
|
||||||
call eqnstr(latex_string)
|
|
||||||
|
|
||||||
|
|
||||||
!First, make sure the right number of inputs have been provided
|
!First, make sure the right number of inputs have been provided
|
||||||
IF(COMMAND_ARGUMENT_COUNT() > 1) THEN
|
IF(COMMAND_ARGUMENT_COUNT() > 1) THEN
|
||||||
|
|
||||||
|
|
@ -48,9 +29,9 @@
|
||||||
WRITE(*,*) " -v print version information"
|
WRITE(*,*) " -v print version information"
|
||||||
WRITE(*,*) " -x print latex equations"
|
WRITE(*,*) " -x print latex equations"
|
||||||
ELSE IF(num1char=="-v") THEN
|
ELSE IF(num1char=="-v") THEN
|
||||||
WRITE(*,*) input_string(1:len_trim(input_string))
|
WRITE(*,*) trim(build_info_str)
|
||||||
ELSE IF(num1char=="-x") THEN
|
ELSE IF(num1char=="-x") THEN
|
||||||
WRITE(*,*) latex_string(1:len_trim(latex_string))
|
WRITE(*,*) trim(latex_equations_str)
|
||||||
ELSE
|
ELSE
|
||||||
WRITE(*,*) 'ERROR, OPTION NOT SUPPORTED ', num1char
|
WRITE(*,*) 'ERROR, OPTION NOT SUPPORTED ', num1char
|
||||||
END IF
|
END IF
|
||||||
|
|
@ -61,7 +42,7 @@
|
||||||
|
|
||||||
CALL m_openmpi_init
|
CALL m_openmpi_init
|
||||||
|
|
||||||
if (iammaster) write(*,*) input_string(1:len_trim(input_string))
|
if (iammaster) write(*,*) trim(build_info_str)
|
||||||
|
|
||||||
CALL main
|
CALL main
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
extern const char _binary_build_info_txt_start [];
|
|
||||||
extern const char _binary_build_info_txt_end [];
|
|
||||||
extern const char _binary_build_info_txt_size [];
|
|
||||||
|
|
||||||
extern const char _binary_latex_equations_txt_start [];
|
|
||||||
extern const char _binary_latex_equations_txt_end [];
|
|
||||||
extern const char _binary_latex_equations_txt_size [];
|
|
||||||
|
|
||||||
int build_info_length_()
|
|
||||||
{
|
|
||||||
return ((char*)_binary_build_info_txt_end - (char*)_binary_build_info_txt_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
int latex_length_()
|
|
||||||
{
|
|
||||||
return ((char*)_binary_latex_equations_txt_end - (char*)_binary_latex_equations_txt_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
void string_copy ( char *s, unsigned long b, const char *p_start , const char *p_end )
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
const char* p = p_start;
|
|
||||||
|
|
||||||
while ( p != p_end && count < b )
|
|
||||||
{
|
|
||||||
s[count++] = *p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( count < b )
|
|
||||||
{
|
|
||||||
s[count++] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cstr_( char *s, unsigned long b )
|
|
||||||
{
|
|
||||||
string_copy(s, b, _binary_build_info_txt_start, _binary_build_info_txt_end);
|
|
||||||
}
|
|
||||||
|
|
||||||
void eqnstr_( char *s, unsigned long b )
|
|
||||||
{
|
|
||||||
string_copy(s, b, _binary_latex_equations_txt_start, _binary_latex_equations_txt_end);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue