Skip to content

Commit

Permalink
[WebAssembly] Replace varargs debugPrint with standard log call
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D44441

llvm-svn: 327507
  • Loading branch information
NWilson committed Mar 14, 2018
1 parent 8883af6 commit a06a355
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
@@ -143,16 +143,6 @@ class Writer {

} // anonymous namespace

static void debugPrint(const char *fmt, ...) {
if (!errorHandler().Verbose)
return;
fprintf(stderr, "lld: ");
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}

void Writer::createImportSection() {
uint32_t NumImports = ImportedSymbols.size();
if (Config->ImportMemory)
@@ -568,7 +558,7 @@ void Writer::writeSections() {
void Writer::layoutMemory() {
uint32_t MemoryPtr = 0;
MemoryPtr = Config->GlobalBase;
debugPrint("mem: global base = %d\n", Config->GlobalBase);
log("mem: global base = " + Twine(Config->GlobalBase));

createOutputSegments();

@@ -580,38 +570,38 @@ void Writer::layoutMemory() {
for (OutputSegment *Seg : Segments) {
MemoryPtr = alignTo(MemoryPtr, Seg->Alignment);
Seg->StartVA = MemoryPtr;
debugPrint("mem: %-15s offset=%-8d size=%-8d align=%d\n",
Seg->Name.str().c_str(), MemoryPtr, Seg->Size, Seg->Alignment);
log(formatv("mem: {0,-15} offset={1,-8} size={2,-8} align={3}", Seg->Name,
MemoryPtr, Seg->Size, Seg->Alignment));
MemoryPtr += Seg->Size;
}

// TODO: Add .bss space here.
if (WasmSym::DataEnd)
WasmSym::DataEnd->setVirtualAddress(MemoryPtr);

debugPrint("mem: static data = %d\n", MemoryPtr - Config->GlobalBase);
log("mem: static data = " + Twine(MemoryPtr - Config->GlobalBase));

// Stack comes after static data and bss
if (!Config->Relocatable) {
MemoryPtr = alignTo(MemoryPtr, kStackAlignment);
if (Config->ZStackSize != alignTo(Config->ZStackSize, kStackAlignment))
error("stack size must be " + Twine(kStackAlignment) + "-byte aligned");
debugPrint("mem: stack size = %d\n", Config->ZStackSize);
debugPrint("mem: stack base = %d\n", MemoryPtr);
log("mem: stack size = " + Twine(Config->ZStackSize));
log("mem: stack base = " + Twine(MemoryPtr));
MemoryPtr += Config->ZStackSize;
WasmSym::StackPointer->Global->Global.InitExpr.Value.Int32 = MemoryPtr;
debugPrint("mem: stack top = %d\n", MemoryPtr);
log("mem: stack top = " + Twine(MemoryPtr));

// Set `__heap_base` to directly follow the end of the stack. We don't
// allocate any heap memory up front, but instead really on the malloc/brk
// implementation growing the memory at runtime.
WasmSym::HeapBase->setVirtualAddress(MemoryPtr);
debugPrint("mem: heap base = %d\n", MemoryPtr);
log("mem: heap base = " + Twine(MemoryPtr));
}

uint32_t MemSize = alignTo(MemoryPtr, WasmPageSize);
NumMemoryPages = MemSize / WasmPageSize;
debugPrint("mem: total pages = %d\n", NumMemoryPages);
log("mem: total pages = " + Twine(NumMemoryPages));
}

SyntheticSection *Writer::createSyntheticSection(uint32_t Type,

0 comments on commit a06a355

Please sign in to comment.