public function gen() { $ir = ""; if (\Tables::declaration($this->obj->name) || \Tables::func($this->obj->name)) { $gen = array(); $ir .= "\t; prepare the arguments" . PHP_EOL; for ($i = 0; $i < count($this->obj->content); $i++) { $arg = $this->obj->content[$i]; if (\Misc::baseClass($arg) == "Addition" || \Misc::baseClass($arg) == "Subtraction" || \Misc::baseClass($arg) == "Multiplication" || \Misc::baseClass($arg) == "Division" || \Misc::baseClass($arg) == "Call") { $name = "\\Codegen\\Generator\\" . \Misc::baseClass($arg); $obj = new $name($arg); $ir .= $obj->gen(); $gen[$i] = $obj; } } if (\Tables::declaration($this->obj->name)) { $dec = \Tables::getDeclaration($this->obj->name); } elseif (\Tables::func($this->obj->name)) { $dec = \Tables::getFunc($this->obj->name); } $reg = \Tables::alloc(); $this->result = $reg; $ir .= "\t; call {$dec->name}" . PHP_EOL; if (empty($dec->args)) { $ir .= "\t%{$reg} = call {$dec->return} @{$dec->name}"; } else { $ir .= "\t%{$reg} = call {$dec->return} {$dec->args}* @{$dec->name}"; } if (count($this->obj->content) > 0) { for ($i = 0; $i < count($this->obj->content); $i++) { $arg = $this->obj->content[$i]; if (isset($gen[$i]) && !empty($gen[$i])) { $obj = $gen[$i]; } else { $name = "\\Codegen\\Generator\\" . \Misc::baseClass($arg); $obj = new $name($arg); } $ir .= $obj->arg() . ", "; } $ir = substr($ir, 0, -2); } $ir .= ")" . PHP_EOL; $ir .= "\t; end of call to {$dec->name}" . PHP_EOL . PHP_EOL; } else { error("unknown function in line {$this->obj->line}"); } return $ir; }