I have been trying to write a yaml parser using llvm’s yaml API, but ran into an error. Here is the code that I’m attempting to compile:
#include "llvm/Support/YAMLTraits.h"
#include "llvm/IR/Module.h"
using namespace llvm;
using llvm::yaml::MappingTraits;
using llvm::yaml::ScalarTraits;
using llvm::yaml::IO;
struct Foo {
unsigned x;
llvm::Value* v; // Lets assume that this would be constants only
};
// Yaml traits
template <>
struct yaml::ScalarTraits<llvm::Value*> {
static void output(const llvm::Value* &value, void*,
llvm::raw_ostream &out) {
value->print(out);
}
static StringRef input(StringRef scalar, void*, llvm::Value* &value) {
// Code that parses a string and converts it to llvm::Value*
return StringRef();
}
static QuotingType mustQuote(StringRef) { return QuotingType::None; }
};
template <>
struct yaml::MappingTraits<Foo> {
static void mapping(IO &io, Foo &f) {
io.mapRequired("x", f.x);
io.mapRequired("v", f.v);
}
};
int main() {
// Code to read-write from/to a yaml file.
return 0;
}
However, I get the following error when I try to compile it:
...include/llvm/Support/YAMLTraits.h:1172:42: error: invalid application of 'sizeof' to incomplete type 'llvm::yaml::MissingTrait<llvm::Value*>'
char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
As far as I understand, this error would be generated if I fail to give a trait definition for llvm::Value*. But I’ve done so. So I’m confused as to why this error is generated. Any help would be appreciated!