mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	A series of FunC improvements (#378)
* Don't use IFJMP/IFNOTJMP in inline functions * Fix incorrect ifelse branch code generation https://github.com/ton-blockchain/ton/issues/374 * Make generate_code_all clearer * Don't replace IFJMP with IF in inner blocks in inline functions * Allow unbalance if/else by using RETALT * Fix wrong PUSHCONT * Bugfix in IF code generation for inline functions * Fix unbalanced if/else * Bugfix and improvements in code generation * Fix analyzing while(0) in func https://github.com/ton-blockchain/ton/issues/377 * FunC and Asm.fif: Fix inlining large functions https://github.com/ton-blockchain/ton/issues/375 Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
		
							parent
							
								
									9191be1546
								
							
						
					
					
						commit
						d46e4b3538
					
				
					 5 changed files with 144 additions and 81 deletions
				
			
		| 
						 | 
				
			
			@ -613,7 +613,7 @@ struct Op {
 | 
			
		|||
    return !(flags & _Impure);
 | 
			
		||||
  }
 | 
			
		||||
  bool generate_code_step(Stack& stack);
 | 
			
		||||
  bool generate_code_all(Stack& stack);
 | 
			
		||||
  void generate_code_all(Stack& stack);
 | 
			
		||||
  Op& last() {
 | 
			
		||||
    return next ? next->last() : *this;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -1121,6 +1121,7 @@ struct AsmOpList {
 | 
			
		|||
  int indent_{0};
 | 
			
		||||
  const std::vector<TmpVar>* var_names_{nullptr};
 | 
			
		||||
  std::vector<Const> constants_;
 | 
			
		||||
  bool retalt_{false};
 | 
			
		||||
  void out(std::ostream& os, int mode = 0) const;
 | 
			
		||||
  AsmOpList(int indent = 0, const std::vector<TmpVar>* var_names = nullptr) : indent_(indent), var_names_(var_names) {
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -1168,6 +1169,19 @@ struct AsmOpList {
 | 
			
		|||
  void set_indent(int new_indent) {
 | 
			
		||||
    indent_ = new_indent;
 | 
			
		||||
  }
 | 
			
		||||
  void insert(size_t pos, std::string str) {
 | 
			
		||||
    insert(pos, AsmOp(AsmOp::a_custom, 255, 255, str));
 | 
			
		||||
  }
 | 
			
		||||
  void insert(size_t pos, const AsmOp& op) {
 | 
			
		||||
    auto ip = list_.begin() + pos;
 | 
			
		||||
    ip = list_.insert(ip, op);
 | 
			
		||||
    ip->indent = (ip == list_.begin()) ? indent_ : (ip - 1)->indent;
 | 
			
		||||
  }
 | 
			
		||||
  void indent_all() {
 | 
			
		||||
    for (auto &op : list_) {
 | 
			
		||||
      ++op.indent;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
inline std::ostream& operator<<(std::ostream& os, const AsmOpList& op_list) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1498,7 +1512,12 @@ void optimize_code(AsmOpList& ops);
 | 
			
		|||
struct Stack {
 | 
			
		||||
  StackLayoutExt s;
 | 
			
		||||
  AsmOpList& o;
 | 
			
		||||
  enum { _StkCmt = 1, _CptStkCmt = 2, _DisableOpt = 4, _DisableOut = 128, _Shown = 256, _Garbage = -0x10000 };
 | 
			
		||||
  enum {
 | 
			
		||||
    _StkCmt = 1, _CptStkCmt = 2, _DisableOpt = 4, _DisableOut = 128, _Shown = 256,
 | 
			
		||||
    _InlineFunc = 512, _NeedRetAlt = 1024,
 | 
			
		||||
    _ModeSave = _InlineFunc | _NeedRetAlt,
 | 
			
		||||
    _Garbage = -0x10000
 | 
			
		||||
  };
 | 
			
		||||
  int mode;
 | 
			
		||||
  Stack(AsmOpList& _o, int _mode = 0) : o(_o), mode(_mode) {
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -1571,6 +1590,17 @@ struct Stack {
 | 
			
		|||
  bool operator==(const Stack& y) const & {
 | 
			
		||||
    return s == y.s;
 | 
			
		||||
  }
 | 
			
		||||
  void apply_wrappers() {
 | 
			
		||||
    if (o.retalt_) {
 | 
			
		||||
      o.insert(0, "SAMEALTSAVE");
 | 
			
		||||
      if (mode & _InlineFunc) {
 | 
			
		||||
        o.indent_all();
 | 
			
		||||
        o.insert(0, "CONT:<{");
 | 
			
		||||
        o << "}>";
 | 
			
		||||
        o << "EXECUTE";
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue