PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/wrappers/llvm/library/values/llvm_basic_block.e

http://github.com/tybor/Liberty
Specman e | 143 lines | 80 code | 15 blank | 48 comment | 2 complexity | f9ad564bc293234ab78d6dd047c05060 MD5 | raw file
  1class LLVM_BASIC_BLOCK
  2	-- LLVM Basic Block Representation.
  3
  4	-- This represents a single basic block in LLVM. A basic
  5	-- block is simply a container of instructions that
  6	-- execute sequentially. Basic blocks are Values because
  7	-- they are referenced by instructions such as branches
  8	-- and switch tables.
  9
 10	-- The type of a BasicBlock is "Type::LabelTy" because
 11	-- the basic block represents a label to which a branch
 12	-- can jump.
 13
 14	-- well formed basic block is formed of a list of
 15	-- non-terminating instructions followed by a single
 16	-- TerminatorInst instruction. TerminatorInst's may not
 17	-- occur in the middle of basic blocks, and must
 18	-- terminate the blocks. The BasicBlock class allows
 19	-- malformed basic blocks to occur because it may be
 20	-- useful in the intermediate stage of constructing or
 21	-- modifying a program. However, the verifier will ensure
 22	-- that basic blocks are "well formed".
 23inherit LLVM_VALUE
 24insert 	LLVM_VALUE_WRAPPER_FACTORY 
 25create {WRAPPER, WRAPPER_HANDLER} from_external_pointer
 26create {ANY} appended_in_context, inserted_in_context, appended_to, inserted_before
 27feature {} -- Creation
 28	appended_in_context (a_context: LLVM_CONTEXT; a_function: LLVM_FUNCTION; a_name: ABSTRACT_STRING)
 29	-- TODO: documentation
 30	-- TODO: `a_function' may be an more general LLVM_VALUE but any actual
 31	-- usage of something other that an LLVM_FUNCTION is not clear to me. 
 32	require 
 33		a_context/=Void
 34		a_function/=Void
 35		a_name/=Void
 36	do
 37		handle:=llvmappend_basic_block_in_context
 38		(a_context.handle, a_function.handle, a_name.to_external)
 39	ensure name_not_changed: a_name.is_equal(old a_name)
 40	end
 41
 42	inserted_in_context (a_context: LLVM_CONTEXT; a_block: LLVM_BASIC_BLOCK; a_name: ABSTRACT_STRING)
 43		-- TODO: doc.
 44	require
 45		a_context/=Void
 46		a_block/=Void
 47		a_name/=Void
 48	do
 49		handle:=llvminsert_basic_block_in_context
 50		(a_context.handle, a_block.handle, a_name.to_external)
 51	ensure name_not_changed: a_name.is_equal(old a_name)
 52	end
 53
 54	appended_to (a_value: LLVM_VALUE; a_name: ABSTRACT_STRING)
 55		-- TODO: doc
 56	require 
 57		a_value/=Void
 58		a_name/=Void
 59	do
 60		handle:=llvmappend_basic_block(a_value.handle,a_name.to_external)
 61		ensure name_not_changed: a_name.is_equal(old a_name)
 62	end
 63	
 64	inserted_before (a_block: LLVM_BASIC_BLOCK; a_name: ABSTRACT_STRING)
 65		-- TODO: doc
 66	require
 67		a_block/=Void
 68		a_name/=Void
 69	do
 70		handle:=llvminsert_basic_block(a_block.handle,a_name.to_external)
 71	ensure name_not_changed: a_name.is_equal(old a_name)
 72	end
 73
 74feature	{ANY} -- queries
 75	-- TODO: the following feature may not be necessary "as_value: LLVM_VALUE
 76	-- is -- Current basic block as a value do LLVMValueRef
 77	-- LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);:w" and
 78
 79	parent: LLVM_VALUE
 80		--- The value that contains Current block
 81		do
 82			Result:=value_wrapper_or_void(llvmget_basic_block_parent(handle))
 83		end
 84
 85	next: LLVM_BASIC_BLOCK
 86		-- The block after Current. May be Void
 87	local p: POINTER
 88	do
 89		p:=llvmget_next_basic_block(handle)
 90		if p.is_not_null then 
 91			create Result.from_external_pointer(p)
 92		end
 93	end
 94
 95	previous: LLVM_BASIC_BLOCK
 96		-- The block before Current. May be Void
 97	local p: POINTER
 98	do
 99		p:= llvmget_previous_basic_block(handle)
100		if p.is_not_null then
101			create Result.from_external_pointer(p)
102		end
103	end
104
105	delete
106		-- Delete current block.
107	do
108		llvmdelete_basic_block(handle)
109		handle := default_pointer
110	ensure is_deleted
111	end
112
113	is_deleted: BOOLEAN
114		-- Has Current been deleted?
115	do
116		Result:=handle.is_null
117	end
118
119-- void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
120feature {ANY} -- Iterating over instructions
121	new_iterator: ITERATOR[LLVM_INSTRUCTION]
122		do
123			create {ITERATOR_OVER_INSTRUCTIONS} Result.from_block(Current)
124		ensure Result/=Void
125		end
126end -- class LLVM_BASIC_BLOCK
127
128-- Copyright (C) 2009-2017: Paolo Redaelli, partially derived from LLVM documentation
129-- This file is part of LLVM wrappers for Liberty Eiffel.
130--
131-- This library is free software: you can redistribute it and/or modify
132-- it under the terms of the GNU Lesser General Public License as published by
133-- the Free Software Foundation, version 3 of the License.
134--
135-- Liberty Eiffel is distributed in the hope that it will be useful,
136-- but WITHOUT ANY WARRANTY; without even the implied warranty of
137-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138-- GNU General Public License for more details.
139--
140-- You should have received a copy of the GNU General Public License
141-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
142--
143