Is there any way to iterate in reverse on a LLVM Function. I've checked the docs
but can't seem to find any member typedef for iterating Basic blocks ( in a function ) in reverse.
Any help will be appreciated.
Thanks,
Malhar
for (BasicBlock::reverse_iterator i = BB->rbegin(), e = BB->rend(); i != e; ++i)
{
// your code
}
I think you can call Function::getBasicBlockList() and then use .rbegin() and rend() on that list.
Sharing the working code snippet based on #arrowd suggestions:
auto bbList = &(func_ptr->getBasicBlockList()); //fetch the pointer of the list
errs()<<"reverse \n";
for(auto bb = bbList->rbegin(); bb != bbList->rend(); bb++) {
b = &(*bb);
errs() << b->getName()<<", ";
}
What is the sequence of printing the basic block names , in case there are multiple predecessors and successors ?
opposite of Reverse Post Order i.e Post - order (while iterating in reverse fashion)
You can use llvm::reverse() from StlExtras.h to iterate containers in reverse order.
Related
I am trying to compile some old actionscript code (part of flash app) to JS using Jangaroo. Jangaroo does not support the E4X syntax and it fails at things like the double-dot operator .. or the brackets filters a.(CONDITION). So I need to rewrite those portions of code using plain ActionScript.
For the double-dot operator, I used the instead the method descendants() but I could not find alternative way to write the brackets filter.
Here is the original code I had:
B = xml..destination.(#id == someId)
I wrote it now:
B = xml.descendants("destination").(#id == someId)
But I still want to remove .(#id == someId).
I am thinking of something like:
if (xml.descendants("destination").attribute("id") == someId)
{
B = xml.descendants("destination")
}
Is this possible?
So here is how I proceeded. I have not tested its functionality, but the compiler passed it.
var destinations:XMLList = null;
for each (var elm in xml.descendants("destination") )
{
if ( elm.attribute("id") == someId )
{
destinations += elm;
}
}
Im trying to via a for-loop remove all the items that matches a condition in the state array. But it seems to only be removing the last items in the array and not the ones that matches. Am I using the .splice() incorrectly? Thanks in advance. Code is:
rmTravel() {
for(var i = 0; i < this.cards.length; i++){
if(this.cards[i].sg_categories.includes("travel")){
this.cards.splice(i, 1);
console.log('Removed following card:', this.cards[i].slug)
}
}
console.log('Cards in cards state: ', this.cards)
}
This is a bit of a classic problem; you're iterating forward and shrinking the array at the same time so you're going to end up skipping over records.
I suggest using Array.prototype.filter() instead
this.cards = this.cards.filter(({ sg_categories }) =>
!sg_categories.includes('travel'))
This will reduce the array to entries who's sg_categories property does not include "travel".
This code contains an AABB Tree which is build using a Polyhedron_3 mesh. It is possible to verify if an intersection occures but not what primitive the intersection hit. How can I retrieve the primitive?
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
const Polyhedron& mesh;
tree(faces(_mesh).first, faces(_mesh).second, _mesh);
boost::optional<Primitive_id> intersection = tree.first_intersected_primitive(ray);
if(intersection)
{
//how to get the primitive?
}
Edit:
faces(mesh, tree);
faces(*mesh, tree);
faces(hit, tree);
faces(*hit, tree);
Does not work too.
Edit2:
CGAL::internal::In_place_list_iterator<CGAL::HalfedgeDS_in_place_list_face<CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > > >, std::allocator<CGAL::HalfedgeDS_in_place_list_face<CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > > > > > it = *hit;
CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > >::Halfedge_around_facet_circulator ipfacet = it->facet_begin();
Gets you an iterrator and I_Polyhedron_facet.
Cgal is realy missing some documentation.
Here is the solution: Get the iterator around the face verticess primitive_id->facet_begin(); . And then do this.
Ray_intersection hit = tree.first_intersection(rays[this->transformCoordinates(y,x)]);
if(hit)
{
const Point& point = boost::get<Point>(hit->first);
const Primitive_id& primitive_id = boost::get<Primitive_id>(hit->second);
Polyhedron::Halfedge_around_facet_circulator facerunner = primitive_id->facet_begin();
Point p1;
Point p2;
Point p3;
p1 = facerunner->vertex()->point();
facerunner++;
p2 = facerunner->vertex()->point();
facerunner++;
p3 = facerunner->vertex()->point();
Vector v1(p1,p2);
Vector v2(p1,p3);
Vector n = CGAL::cross_product(v1,v2);
n = n/ std::sqrt(n.squared_length());
}
Answer from the cgal mailinglist:
what are you looking for that is not available here:
https://doc.cgal.org/latest/AABB_tree/index.html#title6
Also note that from here:
https://doc.cgal.org/latest/AABB_tree/classCGAL_1_1AABB__face__graph__triangle__primitive.html
you have:
typedef boost::graph_traits< FaceGraph >::face_descriptor Id
From that same page, you see that the graph type is model of FaceGraph:
https://doc.cgal.org/latest/BGL/classFaceGraph.html
Depending on the type of graph chosen, you have access to the precise
documentation of what face_descriptor corresponds to:
https://doc.cgal.org/latest/BGL/group__PkgBGLTraits.html
Then you can refer to the documentation of the class to know how to
iterate over the vertex of the face.
There is even a generic helper function to do it:
for ( boost::graph_traits<Graph>::vertex_descriptor v :
CGAL::vertices_around_face(halfedge(f, g), g))
{
Point_3 p = get(boost::vertex_index, v, g);
}
I'm not saying it is easy to get but reading the doc gives you the
information required. It's not like reading vtk doc where you have
to guess or read the source code to understand things.
Anyway, we are always looking to improve our doc and we'll be soon
having some cross-packages tutorials and one about manipulation of
surface meshes in CGAL will surely be added.
if intersection is not null, then *intersection should be the Primitive_id of the primitive you are looking for.
So I'm just getting to grips with node-red and I need to create a conditional global function.
I have two separate global.payloads set to a number value of either 0 or 1.
What I need to happen now is, if global.payload is equal to value 1 then follow this flow, if it is equal to value 0 then follow this one.
I'm just a little confused with the syntax for the function statement. Any help gratefully appreciated.
Since you haven't accepted the current answer, thought I'd give this a try.
I think this is what you need to handle inputs from two separate global contexts. I'm simulating them here with two separate inject nodes to demonstrate:
The checkconf inject node emits a 1 or a 0. Same for the meshstatus node. Substitute your real inputs for those inject nodes. The real work is done inside the function:
var c = context.get('c') || 0; // initialize variables
var m = context.get('m') || 0;
if (msg.topic == "checkconf") // update context based on topic of input
{
c = {payload: msg.payload};
context.set("c", c); // save last value in local context
}
if (msg.topic == 'meshstatus') // same here
{
m = {payload: msg.payload};
context.set('m', m); // save last value in local context
}
// now do the test to see if both inputs are triggered...
if (m.payload == 1) // check last value of meshstatus first
{
if (c.payload == 1) // now check last value of checkconf
return {topic:'value', payload: "YES"};
}
else
return {topic:'value', payload: "NO"};
Be sure to set the "topic" property of whatever you use as inputs so the if statements can discriminate between the two input. Good luck!
You can use the Switch node to do this, rather than a Function node.
Actually I've parsed a website using htmlparser and I would like to find a specific value inside the parsed object, for example, a string "$199", and keep tracking that element(by periodic parsing) to see the value is still "$199" or has changed.
And after some painful stupid searching using my eyes, I found the that string is located at somewhere like this:
price = handler.dom[3].children[3].children[3].children[5].children[1].
children[3].children[3].children[5].children[0].children[0].raw;
So I'd like to know whether there are methods which are less painful? Thanks!
A tree based recursive search would probably be easiest to get the node you're interested in.
I've not used htmlparser and the documentation seems a little thin, so this is just an example to get you started and is not tested:
function getElement(el,val) {
if (el.children && el.children.length > 0) {
for (var i = 0, l = el.children.length; i<l; i++) {
var r = getElement(el.children[i],val);
if (r) return r;
}
} else {
if (el.raw == val) {
return el;
}
}
return null;
}
Call getElement(handler.dom[3],'$199') and it'll go through all the children recursively until it finds an element without an children and then compares it's raw value with '$199'. Note this is a straight comparison, you might want to swap this for a regexp or similar?