This is not really an answer, more like me sharing notes on studying the Blender source code. Various aspects of converting the node setups to shader code are all over the place, so it seems the most reasonable approach is to fork Blender and save to a file the code that is being sent to GPU…
Python
source/blender/python/gpu/gpu_py_shader_create_info.cc
source/blender/python/gpu/gpu_py_shader.c
GPU
GPU shader interface (C --> GLSL)
source/blender/gpu/opengl/gl_shader_interface.hh
source/blender/gpu/opengl/gl_shader_interface.cc
source/blender/gpu/intern/gpu_shader_interface.hh
source/blender/gpu/intern/gpu_shader_interface.cc
Structure detailing needed vertex inputs and resources for a specific shader.
A shader interface can be shared between two similar shaders.
GL shader
source/blender/gpu/opengl/gl_shader.hh
source/blender/gpu/opengl/gl_shader.cc
Implementation of shader compilation and uniforms handling using OpenGL.
GPU shader shared utils
source/blender/gpu/GPU_shader_shared_utils.h
Glue definition to make shared declaration of struct & functions work in both C / C++ and GLSL.
GPU material
source/blender/gpu/GPU_material.h
Functions to create GPU Materials nodes.
GPU platform
source/blender/gpu/intern/gpu_platform.cc
Wrap OpenGL features such as textures, shaders and GLSL with checks for drivers and GPU support.
GPU codegen
source/blender/gpu/intern/gpu_codegen.h
Generate shader code from the intermediate node graph.
source/blender/gpu/intern/gpu_codegen.cc
Convert material node-trees to GLSL.
GPU shader dependency
source/blender/gpu/intern/gpu_shader_dependency.cc
Shader source dependency builder that make possible to support #include directive inside the shader files.
GPU material library
source/blender/gpu/intern/gpu_material_library.h
Parsing of and code generation using GLSL shaders in gpu/shaders/material.
GPU capabilities
source/blender/gpu/intern/gpu_capabilities.cc
Wrap OpenGL features such as textures, shaders and GLSL with checks for drivers and GPU support.
GPU node graph
source/blender/gpu/intern/gpu_node_graph.h
source/blender/gpu/intern/gpu_node_graph.c
Intermediate node graph for generating GLSL shaders.
Color management
source/blender/imbuf/IMB_colormanagement.h
source/blender/imbuf/intern/colormanagement.c
Render internal
source/blender/editors/render/render_internal.cc
Nodes
source/blender/nodes/
- it looks like those files only describe the interface part of nodes and has nothing to do with the actual rendering part.
tbc…