An example is provided by the official Toy tutorial in Ch2. You'll just need to extract out the relevant parts to end up with the code. https://github.com/llvm/llvm-project/blob/main/mlir/examples/toy/Ch2/toyc.cpp
Commit snapshot with line numbers
https://github.com/llvm/llvm-project/blob/f87109f018faad5f3f1bf8a4668754c24e84e886/mlir/examples/toy/Ch2/toyc.cpp#L93-L111