[HH] c++ strings?

Greg London email at greglondon.com
Tue Nov 20 12:41:45 EST 2012


Hello,

First of all, if anyone is planning on killing anyone over how
they use a language construct, could they do me a favor and
change the subject heading so I don't feel like I have blood
on my hands? Thanks.

Second, I'm an ASIC engineer and my usual programming language
is verilog and systemverilog which is used for hardware design
and simulating that hardware. Or programming an FPGA. stuff like
that.

If I need to do something that is "software"ish, then I usually
use perl, mostly because I like the fact that in perl I can
focus on the application and the implementation is mostly handled
under the hood in perl's engine. garbage collection is automatic,
for example.

So, I'm working on a new project, and we're trying to write some
C++ code that will work in our simulations and will also work
on a real processor inthe lab. The C++ code will generate stimulus
for the device under test (one of our ASICs we're designing).

So, I decided to start this by taking a low level verilog block
and converting it to C++. The block is a "logger" which mostly
a bunch of subroutines that take in strings, fiddle with them,
and then pass the result ot another subroutine. At some point,
you get far enough down and some subroutine will decide whether
to send the string to STDOUT or send it to a serial port on an
FPGA which will then go to a terminal in the lab.

So, I need to write a LOT of little subroutines and pretty much
all they do is fiddle with strings and pass them to another subroutine.

In perl, it might look like this:

sub upper_subroutine{
  my ($string)=@_;
  lower_subroutine("prefix".$string."postfix".timestamp());
}

Could someone give me an example of how to do this in C++ so that
it looks as close to this perl code as possible?

clearly there will be differences, but for example, the perl code
didn't have to declare the lengths of the strings and as another example,
it could concatenate a bunch of different strings together and hand
it directly to a subroutine without declaring an intermediate string
variable first.

Since it is going to run in simulation and on a computer in the
lab, it probably needs to be somewhat... standard?
i.e. it ought to use commonly available libraries so that it will
compile in different environments.

I've been googling around, and found a few different examples, but
I seem to run into problems getting any of them to work.
Either I'm missing a step or something is missing in the examples.

I'm familiar with object oriented stuff. Mostly from perl,
doing classes, encapsulation, polymorphism, and other buzz words.
But I've done some C++ stuff for work stuff. But mostly what I
do with C++ is write hardware models. And they haven't needed
much string processing. It's just number crunching to calculate
what the hardware will do so it has something to compare against.

But the stuff I'm working on now has a lot of string stuff in it,
and the C++ examples for dealing with strings all seem really
klugey to this guy who is used to perl code.

I don't want or need to worry about memory efficiency.
It won't have to be the fastest code in the world.
Ease of coding (fewest extra characters) is actually my first goal.
This means I don't want to declare the size of character arrays.
I just want it to be dealt with by the class or library or whatever.

The only other important requirement is portability.
The same code will be simultaneously running in at least
two different environments, so I don't want to kluge it
much to handle differences in each environment.
So something fairly standard would be GREAT.

But, I'm just a dumb hardware engineer and if someone could give me a
concrete example of the above perl code converted into C++,
I would be most appreciative.

If this could happen without anyone having to die, that would
be even better.

;)


Thanks
Greg London



>
> _______________________________________________
> Hardwarehacking mailing list
> Hardwarehacking at blu.org
> http://lists.blu.org/mailman/listinfo/hardwarehacking
>






More information about the Hardwarehacking mailing list