mirror of
https://github.com/Lore09/Tesi-Magistrale.git
synced 2025-12-19 12:24:31 +00:00
project refactor
This commit is contained in:
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
BIN
src/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
0
src/task_splitter/__init__.py
Normal file
0
src/task_splitter/__init__.py
Normal file
BIN
src/task_splitter/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/task_splitter/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/task_splitter/__pycache__/code_processor.cpython-310.pyc
Normal file
BIN
src/task_splitter/__pycache__/code_processor.cpython-310.pyc
Normal file
Binary file not shown.
102
src/task_splitter/code_processor.py
Normal file
102
src/task_splitter/code_processor.py
Normal file
@@ -0,0 +1,102 @@
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
|
||||
def __extract_functions(file_content):
|
||||
|
||||
# Regular expression to match C function definitions
|
||||
REGULAR_EXPRESSION_C = r"(^\w[\w\s\*]+)\s+(\w+)\s*\(([^)]*)\)\s*(\{[^{}]*\})"
|
||||
REGULAR_EXPRESSION_ANNOTATION = r"(^\@[A-Z]\w+){1}(\(.+\))*"
|
||||
|
||||
|
||||
function_pattern = re.compile(REGULAR_EXPRESSION_C, re.MULTILINE)
|
||||
function_matches = function_pattern.finditer(file_content)
|
||||
|
||||
annotation_pattern = re.compile(REGULAR_EXPRESSION_ANNOTATION, re.MULTILINE)
|
||||
|
||||
functions = []
|
||||
positions = []
|
||||
|
||||
for match in function_matches:
|
||||
positions.append(match.start())
|
||||
annotation_matches = annotation_pattern.finditer(file_content)
|
||||
prev = 0
|
||||
|
||||
if len(positions) > 1:
|
||||
prev = positions[-2]
|
||||
|
||||
annotations = []
|
||||
|
||||
for ann in annotation_matches:
|
||||
if ann.start() >= prev:
|
||||
|
||||
if ann.start() > match.start():
|
||||
break
|
||||
|
||||
ann_tag = ann.group(1).strip()
|
||||
ann_arg = ann.group(2)
|
||||
|
||||
if ann_arg is not None:
|
||||
ann_arg = ann_arg.replace("(","[").replace(")","]")
|
||||
|
||||
annotations.append(
|
||||
{
|
||||
"tag": ann_tag,
|
||||
"args": ann_arg
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func_return_type = match.group(1).strip()
|
||||
func_name = match.group(2)
|
||||
func_args = match.group(3).strip()
|
||||
func_content = match.group(4).strip()
|
||||
|
||||
# function_contents.append(
|
||||
# f"{func_return_type} {func_name}({func_args}) {match.group(4)}"
|
||||
# )
|
||||
functions.append({
|
||||
"name": func_name,
|
||||
"return_type": func_return_type,
|
||||
"args": func_args,
|
||||
"annotations": annotations,
|
||||
"content": func_content
|
||||
})
|
||||
|
||||
return functions
|
||||
|
||||
def create_independent_files(functions, output_dir):
|
||||
|
||||
for fun in functions:
|
||||
|
||||
function_content = f"{fun['return_type']} {fun['name']}({fun['args']}) {fun['content']}"
|
||||
|
||||
filename = f"{fun['name']}.c"
|
||||
with open(output_dir + filename, "w") as f:
|
||||
|
||||
# Write the original function
|
||||
f.write(function_content)
|
||||
f.write("\n")
|
||||
|
||||
# Add a main function to call the function
|
||||
main_function = f"""
|
||||
int main() {{
|
||||
// Assuming that the function has no return value
|
||||
{fun['name']}({', '.join(['0' for _ in fun['args'].split(',')])});
|
||||
return 0;
|
||||
}}
|
||||
"""
|
||||
f.write(main_function)
|
||||
|
||||
def extract_functions_from_file(input_file):
|
||||
|
||||
with open(input_file, "r") as file:
|
||||
file_content = file.read()
|
||||
|
||||
functions = __extract_functions(file_content)
|
||||
return functions
|
||||
|
||||
def save_functions_to_yaml(functions, output_file):
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
yaml.dump(functions, file, sort_keys=False)
|
||||
12
src/wasm_runtime_builder/Dockerfile
Normal file
12
src/wasm_runtime_builder/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Build phase
|
||||
FROM emscripten/emsdk AS build
|
||||
RUN mkdir -p /build
|
||||
WORKDIR /build
|
||||
COPY src ./src
|
||||
RUN emcc ./src/main.c -o ./main.wasm
|
||||
RUN chmod a+x ./main.wasm
|
||||
|
||||
# Run phase
|
||||
FROM scratch
|
||||
COPY --from=build /build/main.wasm /main.wasm
|
||||
ENTRYPOINT [ "/main.wasm" ]
|
||||
25
src/wasm_runtime_builder/readme.md
Normal file
25
src/wasm_runtime_builder/readme.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Build ed esecuzione
|
||||
|
||||
## Build a due fasi
|
||||
Creazione del file .wasm con l'immagine di emcc e creazione del container con supporto wasm.
|
||||
`docker build --platform wasi/wasm -t main-wasm .`
|
||||
|
||||
## Run
|
||||
Esecuzione container con platform wasm.
|
||||
`docker run --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm main-wasm`
|
||||
|
||||
# TODO
|
||||
## Studio
|
||||
|
||||
- studio wasm
|
||||
- compilare c++ con wasm
|
||||
- creazione container con wasm runtinme
|
||||
- definizione tag per codice
|
||||
|
||||
## Python module
|
||||
- divide il codice in diverse task
|
||||
- aggrega le task in base al target
|
||||
|
||||
## Build e run
|
||||
- container che builda tutti i task
|
||||
- run del container con wasm
|
||||
Reference in New Issue
Block a user