Sable / mclab-core

Core McLab features. McSAF, Tamer, Tamer+
http://www.sable.mcgill.ca/mclab/
Apache License 2.0
9 stars 9 forks source link

TamerPlus fails to handle a user defined function #7

Open wukefe opened 8 years ago

wukefe commented 8 years ago

Originally, I have two MATLAB files: main.m and myIfElse.m.

function z = main(x)
  n = x + 1;
  z = zeros(1,n);
  for i = 1:n
    z(i) = myIfElse(i,1);
  end
end

function z = myIfElse(a, b)
  z = a - 1;
  if(a > b)
    z = b + 1;
  end
end

After I get the TameIR of the two files and save it for each file as follows (mainIR.m and myIfElseIR.m).

function [z] = mainIR(x)
  mc_t9 = 1;
  [n] = plus(x, mc_t9);
  mc_t10 = 1;
  [z] = zeros(mc_t10, n);
  mc_t12 = 1;
  for i = (mc_t12 : n);
    mc_t11 = 1;
    mc_t8 = myIfElse(i, mc_t11);
    z(i) = mc_t8;
  end
end

function [z] = myIfElseIR(a, b)
  mc_t13 = 1;
  [z] = minus(a, mc_t13);
  [mc_t15] = gt(a, b);
  if mc_t15
    mc_t14 = 1;
    [z] = plus(b, mc_t14);
  else
  end
end

I feed the TamerPlus with mainIR.m and myIfElseIR.m that it is expected to produce the 'same' code as the original code. But the user defined function myIfElseIR disappears in the main function mainIR. Maybe I should not use the program which contains temporary variables (e.g. mc_10).

% After Tamer plus
function [z] = mainIR(x)
  [n] = plus(x, mc_t9);
  [z] = zeros(mc_t10, n);
  for i = (mc_t12 : n);
    z(i) = mc_t8; %one line is missing
  end
end

function [z] = myIfElse(a, b)
  [z] = minus(a, 1);
  if gt(a, b)
    [z] = plus(b, 1);
  else 
  end
end

The Java code I used to invoke TamerPlus is listed below.

for(StaticFunction f : localAnalysis.getFunctionCollection().getAllFunctions()){
            PrintMessage.See(TransformationEngine.forAST(f.getAst())
                             .getTIRToMcSAFIRWithoutTemp()
                             .getTransformedTree()
                             .getPrettyPrinted());
}