Commit Graph

592 Commits

Author SHA1 Message Date
Kacper Kołodziej 2445c5e740 MakeSegmentRefPass: emit cstringLiteral
This commit changes MakeSegmentRefPass so that it's now a ModulePass and
it uses the binary to detect integer constants that represent the
address of strings.
When it detects address of constant strings, instead of injecting calls
to SegmentRef, we now inject calls to cstringLiteral, so that we can
later emit them as inline string literals in C.

In segmentRef we use integer type meaning address in memory, so we
generate segmentRef function with non-pointer type. For cstringLiteral
function we need real pointer type of operand.

Save MetaAddress, size, offset and original type for every
cstringLiteral call in metadata as we do for segmentRef calls.

For cstringLiteral "revng.cstring_literal" metadata name is used.

StringLiteralPool needs tuple of address, size, offset and type to
keep distinct string decorator functions for each string. This tuple is
represented by StringLiteralPoolKey struct.

Pipe for MakeSegmentRefPass needs to be defined explicitly, because
additional wrapper passes are required in MakeSegmentRef:

 1. LoadModelWrapperPass
 2. LoadBinaryWrapperPass

MakeSegmentRefPass requires access to RawBinaryView to detect cstring
literals in binary.

Fix printed command in MakeSegmentRefPipe

This printed command might not work. @ale commented it will be replaced
with `revng pipe run-pipe` once we will have it.

Update IRHelpers to new revng API

Switch String and Namespace arguments in getUniqueString
2023-04-04 09:31:10 +02:00
Kacper Kołodziej f83cb94e1f Add StringLiteral tag and corresponding f. pool
StringLiteral tag will be used to mark cstring decorators in generated
IR.
2023-04-04 09:31:10 +02:00
Ivan Krysak c2f0fc19e5 ABI: FunctionType.h -> FunctionType/Layout.h 2023-03-15 10:28:24 +01:00
Alessandro Di Federico 9be304ece2 areMemOpCompatible: drop redundant check 2023-03-13 13:42:33 +01:00
Alessandro Di Federico e73bd95493 Improve handling of declarations
SegregateStackAccesses and PromoteStackPointer were not handling
functions declarated (but not defined) properly.

This commit fixes this, in part by adopting `TaggedFunctionPass`.
2023-03-13 13:42:33 +01:00
Pietro Fezzardi 66434db5f9 Don't use named metadata revng.segment_ref
Using a named metadata is simply wrong, because we need to have many of
these metadata alive at the same time with different values.
Using a named metadata has the unpleasant side effect of making all the
`SegmentRef` functions to refer to the same segment.
2023-02-07 18:03:34 +01:00
Kacper Kołodziej 5b94a5a649 HelpersToHeaders: skip unnecessary helpers 2023-02-07 17:43:05 +01:00
Andrea Gussoni 26a717a4ac Compute weight for untangle regions once
Compute the weight of collpased regions the first time it is requested
and cache it, and use the cached value for all successive queries.
This also prevents a bug which occurs when we query the weight two
times for the same collapsed node, whose related collapsed region object
has been in the meantime destroyed by the tiling process.
2023-02-01 09:56:36 +00:00
Andrea Gussoni ebe0729332 Improve debug graphs for collapsed nodes
Integrate the debug graph serialization for collapsed nodes in the
RegionCFG.
2023-01-31 17:25:27 +00:00
Pietro Fezzardi 5e12f66ffb Drop old logger, use CombLogger instead 2023-01-18 17:58:09 +01:00
Pietro Fezzardi 97b23935de Handle FunctionTags::Exceptional
This is necessary for e.g. the abort function.
2023-01-17 11:14:47 +01:00
Pietro Fezzardi 97883844d3 Fix initialization of FunctionTags 2023-01-17 11:11:46 +01:00
Kacper Kołodziej 568bd24900 Add UnaryMinus and BinaryNot 2023-01-09 15:01:16 +01:00
Pietro Fezzardi e9d84264ff Reduce the number of emitted local variables in C
This commit does various things oriented at reducing the number of local
variables emitted in C:
- MarkAssignments now know that @Copy and @Assign involving
  @LocalVariable only have side effects that affect the local variable
  itself; this enables to reduce the number of times we're forced to
  emit a local variable due to interfering side effects
- Drop the @AssignmentMarker FunctionTag; AddAssignmentMarkerPass now
  doesn't emit @AssignmentMarker anymore; instead it emits groups of
  @LocalVariable, @Copy, and @Assign, which benefit from the previous
  point
- Drop 2 MarkAssignments::Reasons: HasManyUses and HasUsesOutsideOfBB;
  both these have now been aggregated into the AlwaysAssign reason for
  simplicity, representing all reasons non involving side effects
- Update BeautifyGHAST and how it reasons about side effects when
  beautifying; before this commit it used @AssignmentMarker, now it
  looks at @Assign
- Simplify ExitSSA; before this commit it was trying hard to be smart on
  where it emitted the store instructions representing the incoming
  values of the PHI that was being destroyed; this seemed smart when we
  originally did it but it generated C code that was not really better
  to read, so this useless complexity is finally gone
2022-12-24 02:47:10 +01:00
Pietro Fezzardi c201990e5b Print stack variable at beginning of function body 2022-12-24 02:44:38 +01:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Massimo Fioravanti a54d1c9dcb fix includes 2022-12-12 11:19:14 +01:00
Kacper Kołodziej 83ab07d7fb Enable printing integers as bool, hex or char
This commit adds a new pass, PrettyIntFormatting, that injects calls to
decorator functions print_hex, print_char, and print_bool around
llvm::ConstantInt in various situations.

It also updates the rest of passes of the decompilation pipelin to
understand these new decorator functions and to properly emit decorated
integer literals in the decompiled C code.
2022-12-02 10:08:00 +01:00
Alessandro Di Federico 049b8657c3 Introduce RemoveStackAlignmentPass 2022-12-01 12:20:09 +01:00
Pietro Fezzardi e95f77aeb6 RegionCFG::isDAG: use llvm::scc_iterator::hasCycle 2022-12-01 12:15:12 +01:00
Pietro Fezzardi cadb71f2b2 RegionCFGTreeImpl.h: use std::erase_if 2022-12-01 12:15:12 +01:00
Pietro Fezzardi 3a329b0d95 MetaRegion: drop unused method getProbableEntry 2022-12-01 12:15:12 +01:00
Pietro Fezzardi c73b447c60 Use MFP in RegionCFG::inflate for reachable exits 2022-12-01 12:14:37 +01:00
Pietro Fezzardi ee0dc97464 Uniform printing return types of functions 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 7b66b9d7f6 TypeNames: fix redundant whitespaces in types 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 7f6735f212 ModelHelpers.h: add stripPointer helper
This assumes that the input QualifiedType has at least one Qualifier,
and that the first Qualifier is a pointer-qualifier.
2022-11-30 18:16:13 +01:00
Pietro Fezzardi 389a184fc2 Handle CABIFunctionTypes returning struct types 2022-11-30 18:16:13 +01:00
Alessandro Di Federico 537c1e7524 IRHelpers: introduce emitMessage 2022-11-30 18:16:13 +01:00
Ivan Krysak 033ccbe51a Adopt FunctionType::Layout to improve CABI support 2022-11-30 18:16:13 +01:00
Massimo Fioravanti a057ce54a7 Avoids missing outputs when empty
FileContainer should not be used when we wish to produce a empty output
file rather than no file at all.
2022-11-22 15:21:03 +01:00
Massimo Fioravanti 335d402245 Change signatures to forward metadata cache. 2022-11-22 12:27:02 +01:00
Pietro Fezzardi 8aaa3ca92e Refactor PTML generation for functions 2022-11-16 16:02:09 +01:00
Pietro Fezzardi e72a578743 Refactor PTML generation for local variables 2022-11-16 11:24:37 +01:00
Pietro Fezzardi 79a319cdeb PTML.h: sort ptml::c::tokens alphabetically 2022-11-16 07:48:43 +01:00
Pietro Fezzardi 0812989cb0 Drop unused ptml::c::tokens::Comparison 2022-11-16 07:47:18 +01:00
Pietro Fezzardi a23d4f8dcf Ranks.h: simplify ranks, delete unnecessary ranks 2022-11-15 15:54:20 +01:00
Pietro Fezzardi ff631c5364 PTMLC.h: switch to string-based return values 2022-11-15 15:54:20 +01:00
Pietro Fezzardi c93392fa3b Refactor PTML generation for helpers 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 38ce08edba PTMLC: add Const keyword 2022-11-15 15:54:20 +01:00
Pietro Fezzardi e1ded3a479 HelpersToHeader: refactor PTML Tags 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 2ec8b7e32c ModelToHeader: refactor creation of PTML Tags 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 6734494bad Move scopeTag helper function to revng 2022-11-15 14:03:07 +01:00
Giacomo Vercesi 6e8333ed62 Kinds: add new Location/definitionKind info 2022-11-10 17:27:53 +01:00
Pietro Fezzardi cf6be43571 Support void types in areMemOpCompatible 2022-11-09 17:00:14 +01:00
Pietro Fezzardi 0097af6dd0 Fix peelConstAndTypedefs for model::TypedefType
Before this commit typedefs were not unwrapped correctly, leading to
infinite loops.
2022-11-09 11:59:51 +01:00
Pietro Fezzardi bf83f40e3b Move SCEVBaseAddressExplorer.h from public headers 2022-10-21 10:00:23 +02:00
Pietro Fezzardi 25119c4377 Drop bugged addPointerQualifier for getPointerTo
This commit removes the bugged addPointerQualifier helper function,
that was wrongly pushing the pointer qualifier at the end.

Instead, we now use the correct model::Binary::getPointerTo method.
2022-10-21 09:45:28 +02:00
Massimo Fioravanti 5d730d1411 Upgrade to support starless revng 2022-10-20 16:06:13 +02:00
Giacomo Vercesi 062272a615 Fix mime types 2022-10-11 17:36:29 +02:00
Giacomo Vercesi 72050274e2 getNamedCInstance: drop declaration parameter
In all cases this is false
2022-10-11 17:36:29 +02:00