Closed pramodk closed 3 years ago
nmodl::to_nmodl(node)
doesn't show full AST structure but just text. Note that to_nmodl
may not show certain nodes. In case of doubt, see <build>/src/visitors/nmodl_visitor.cpp
which transforms AST to NMODL i.e. txt form.
Better way to inspect AST is using nmodl::to_json(const nmodl::ast::Ast& node);
function. Using following change:
+++ b/src/codegen/llvm/codegen_llvm_helper_visitor.cpp
@@ -428,6 +428,8 @@ void CodegenLLVMHelperVisitor::visit_nrn_state_block(ast::NrnStateBlock& node) {
/// statements for new function to be generated
ast::StatementVector function_statements;
.......
- std::cout << nmodl::to_nmodl(function);
+ std::cout << "AFTER :: \n" << nmodl::to_nmodl(function) << "\n";
+ std::cout << "AFTER (json) :: \n" << nmodl::to_json(*function) << "\n";
}
and re-running nmodl on hh.mod will show:
$ ./bin/nmodl hh.mod llvm --ir
.....
AFTER ::
VOID nrn_state_hh(){
INTEGER id
for(id = 0; id<node_count; id = id+1) {
INTEGER node_id, ena_id, ek_id
DOUBLE v
node_id = node_index[id]
ena_id = ion_ena_index[id]
ek_id = ion_ek_index[id]
v = voltage[node_id]
ena[id] = ion_ena[ena_id]
ek[id] = ion_ek[ek_id]
m[id] = m[id]+(1.0-exp(dt*((((-1.0)))/mtau[id])))*(-(((minf[id]))/mtau[id])/((((-1.0)))/mtau[id])-m[id])
h[id] = h[id]+(1.0-exp(dt*((((-1.0)))/htau[id])))*(-(((hinf[id]))/htau[id])/((((-1.0)))/htau[id])-h[id])
n[id] = n[id]+(1.0-exp(dt*((((-1.0)))/ntau[id])))*(-(((ninf[id]))/ntau[id])/((((-1.0)))/ntau[id])-n[id])
}
}
AFTER (json) ::
{
"CodegenFunction": [
{
"CodegenVarType": [
{
"name": "VOID"
}
]
},
{
"Name": [
{
"String": [
{
"name": "nrn_state_hh"
}
]
}
]
},
{
"StatementBlock": [
{
"CodegenVarListStatement": [
{
"CodegenVarType": [
{
"name": "INTEGER"
}
]
},
{
"CodegenVar": [
{
"Name": [
{
"String": [
{
"name": "id"
}
....
The JSON form printed above represent every construct in the AST. This is quite helpful to inspect whole AST or debug issues.
@alkino : once this is done / you get an idea of overall visitor, please close this.
What are AST transformations? See #474 #475 #476
There will be some additional transformation needed but before jumping into this we should understand current implementations. Here is what we should do:
How to play with current implementation?
hh.mod
file provided above:See
BEFORE
andAFTER
output.What we are interested in is how
BEFORE
block gets translated intoAFTER
block. This transformation is done in https://github.com/BlueBrain/nmodl/blob/6c72107969c3a3196ee86cc3e2a082b6cad48c09/src/codegen/llvm/codegen_llvm_helper_visitor.cpp#L427What we have to see is:
ast::NrnStateBlock
is clonedcc: @alkino