public function genIR(Compiler $compiler)
{
$normalizedPath = str_replace(array(DIRECTORY_SEPARATOR, ":", '/'), '_', realpath($this->_filePath));
$compilePath = DIRECTORY_SEPARATOR . Compiler::getCurrentVersion() . DIRECTORY_SEPARATOR . $normalizedPath . ".js";
$zepRealPath = realpath($this->_filePath);
$changed = false;
$fileSystem = $compiler->getFileSystem();
if ($fileSystem->exists($compilePath)) {
$modificationTime = $fileSystem->modificationTime($compilePath);
if ($modificationTime < filemtime($zepRealPath)) {
$changed = true;
}
} else {
$changed = true;
}
$ir = null;
if ($changed) {
if (!function_exists('zephir_parse_file')) {
throw new Exception("Parser extension couldn't be loaded");
}
$ir = zephir_parse_file(file_get_contents($zepRealPath), $zepRealPath);
$fileSystem->write($compilePath, json_encode($ir, JSON_PRETTY_PRINT));
}
if ($changed || !$fileSystem->exists($compilePath . '.php')) {
if (!isset($ir)) {
$ir = json_decode($fileSystem->read($compilePath), true);
}
$data = '<?php return ' . var_export($ir, true) . ';';
$fileSystem->write($compilePath . '.php', $data);
}
return $fileSystem->requireFile($compilePath . '.php');
}