// define fpga_instruction
#ifndef DEF_ZZZ
#error "Must define ZZZ first"
#endif
// DEF_ZZZ(FIELD,BITSIZE)
DEF_ZZZ(one,1)
DEF_ZZZ(two, 1)
DEF_ZZZ(three, 1)
DEF_ZZZ(four, 1)
struct ZZZ {
#define ZZZ(field, bitsize) \
unsigned int field : bitsize;
#include "zzz.md"
#undef DEF_ZZZ
}__attribute__((packed));
- ToString 方法 .cc 文件
zzz.cc
#include <iostream>
#include <string>
#include "zzz.h"
class ZZZ {
ZZZ(){};
ZZZ(){};
public:
string ToString(struct ZZZ *) {
#define DEF_ZZZ(field, bitsize) \
std::cout << (#field) << ":" << this->field << " bitsize " << std::to_string(bitsize) << std::endl;
#include "zzz.md"
#undef DEF_ZZZ
}
};
int main() {
ZZZ obj;
struct ZZZ *z;
obj.ToString(z);
}