mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-24 04:09:47 +00:00
44bde8dadb
This is part 5 of llvm-rc serialization support. This allows DIALOG and DIALOGEX to serialize if dialog-specific optional statements are provided. These are (as of now): CAPTION, FONT, and STYLE. Notably, FONT statement can take more than two arguments when describing DIALOGEX resources (as in msdn.microsoft.com/en-us/library/windows/desktop/aa381013.aspx). I made some changes to the parser to reflect this fact. Patch by Marek Sokolowski Differential Revision: https://reviews.llvm.org/D37864 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315104 91177308-0d34-0410-b5e6-96231b3b80d8
129 lines
3.9 KiB
C++
129 lines
3.9 KiB
C++
//===-- ResourceSerializator.h ----------------------------------*- C++-*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===---------------------------------------------------------------------===//
|
|
//
|
|
// This defines a visitor serializing resources to a .res stream.
|
|
//
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_TOOLS_LLVMRC_RESOURCESERIALIZATOR_H
|
|
#define LLVM_TOOLS_LLVMRC_RESOURCESERIALIZATOR_H
|
|
|
|
#include "ResourceScriptStmt.h"
|
|
#include "ResourceVisitor.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
namespace llvm {
|
|
namespace rc {
|
|
|
|
class ResourceFileWriter : public Visitor {
|
|
public:
|
|
ResourceFileWriter(std::unique_ptr<raw_fd_ostream> Stream)
|
|
: FS(std::move(Stream)) {
|
|
assert(FS && "Output stream needs to be provided to the serializator");
|
|
}
|
|
|
|
Error visitNullResource(const RCResource *) override;
|
|
Error visitAcceleratorsResource(const RCResource *) override;
|
|
Error visitDialogResource(const RCResource *) override;
|
|
Error visitHTMLResource(const RCResource *) override;
|
|
Error visitMenuResource(const RCResource *) override;
|
|
|
|
Error visitCaptionStmt(const CaptionStmt *) override;
|
|
Error visitCharacteristicsStmt(const CharacteristicsStmt *) override;
|
|
Error visitFontStmt(const FontStmt *) override;
|
|
Error visitLanguageStmt(const LanguageResource *) override;
|
|
Error visitStyleStmt(const StyleStmt *) override;
|
|
Error visitVersionStmt(const VersionStmt *) override;
|
|
|
|
struct ObjectInfo {
|
|
uint16_t LanguageInfo;
|
|
uint32_t Characteristics;
|
|
uint32_t VersionInfo;
|
|
|
|
Optional<uint32_t> Style;
|
|
StringRef Caption;
|
|
struct FontInfo {
|
|
uint32_t Size;
|
|
StringRef Typeface;
|
|
uint32_t Weight;
|
|
bool IsItalic;
|
|
uint32_t Charset;
|
|
};
|
|
Optional<FontInfo> Font;
|
|
|
|
ObjectInfo() : LanguageInfo(0), Characteristics(0), VersionInfo(0) {}
|
|
} ObjectData;
|
|
|
|
private:
|
|
Error handleError(Error &&Err, const RCResource *Res);
|
|
|
|
Error
|
|
writeResource(const RCResource *Res,
|
|
Error (ResourceFileWriter::*BodyWriter)(const RCResource *));
|
|
|
|
// NullResource
|
|
Error writeNullBody(const RCResource *);
|
|
|
|
// AcceleratorsResource
|
|
Error writeSingleAccelerator(const AcceleratorsResource::Accelerator &,
|
|
bool IsLastItem);
|
|
Error writeAcceleratorsBody(const RCResource *);
|
|
|
|
// DialogResource
|
|
Error writeSingleDialogControl(const Control &, bool IsExtended);
|
|
Error writeDialogBody(const RCResource *);
|
|
|
|
// HTMLResource
|
|
Error writeHTMLBody(const RCResource *);
|
|
|
|
// MenuResource
|
|
Error writeMenuDefinition(const std::unique_ptr<MenuDefinition> &,
|
|
uint16_t Flags);
|
|
Error writeMenuDefinitionList(const MenuDefinitionList &List);
|
|
Error writeMenuBody(const RCResource *);
|
|
|
|
// Output stream handling.
|
|
std::unique_ptr<raw_fd_ostream> FS;
|
|
|
|
uint64_t tell() const { return FS->tell(); }
|
|
|
|
uint64_t writeObject(const ArrayRef<uint8_t> Data);
|
|
|
|
template <typename T> uint64_t writeInt(const T &Value) {
|
|
support::detail::packed_endian_specific_integral<T, support::little,
|
|
support::unaligned>
|
|
Object(Value);
|
|
return writeObject(Object);
|
|
}
|
|
|
|
template <typename T> uint64_t writeObject(const T &Value) {
|
|
return writeObject(ArrayRef<uint8_t>(
|
|
reinterpret_cast<const uint8_t *>(&Value), sizeof(T)));
|
|
}
|
|
|
|
template <typename T> void writeObjectAt(const T &Value, uint64_t Position) {
|
|
FS->pwrite((const char *)&Value, sizeof(T), Position);
|
|
}
|
|
|
|
Error writeCString(StringRef Str, bool WriteTerminator = true);
|
|
|
|
Error writeIdentifier(const IntOrString &Ident);
|
|
Error writeIntOrString(const IntOrString &Data);
|
|
|
|
Error appendFile(StringRef Filename);
|
|
|
|
void padStream(uint64_t Length);
|
|
};
|
|
|
|
} // namespace rc
|
|
} // namespace llvm
|
|
|
|
#endif
|