Beispiel #1
0
 public function gen()
 {
     $ir = "define i32 @{$this->obj->name}(";
     /* collect the arguments */
     if (!empty($this->obj->arguments)) {
         foreach ($this->obj->arguments as $arg) {
             $var = \Tables::getLocalVariable($this->obj->function, $this->obj->name);
             $type = "";
             /* get the correct type */
             for ($i = 0; $i <= $this->obj->line; $i++) {
                 if (isset($var->type[$i])) {
                     $type = $var->type[$i];
                 }
             }
             $ir .= \Misc::getType($type) . " %{$arg->name}, ";
         }
         $ir = substr($ir, 0, -2);
     }
     $ir .= ") {" . PHP_EOL;
     /* compile the code inside the function */
     foreach ($this->obj->content as $item) {
         $gen = new \Codegen\Gen(array($item));
         $ir .= $gen->gen();
     }
     $ir .= "}" . PHP_EOL . PHP_EOL;
     \Tables::addFunc($this->obj->name, "i32");
     return $ir;
 }